Mercurial > pidgin.yaz
annotate src/protocols/msn/slpmsg.c @ 10306:56cc5d49472b
[gaim-migrate @ 11492]
" Well, I found a bug, and even though I had code to
prevent that crash it seems it did not. So now here is
in a different way, which by the way is more efficient." --Felipe Contreras
(19:35:44) shx: LSchiere: there's a bugfix patch for msn in the tracker if
it interest you ;)
(19:35:59) LSchiere: the one i assigned to nosnilmot just a little bit ago?
(19:36:24) shx: LSchiere: probably
(19:38:25) LSchiere: i just remembered to day is release day
(19:38:51) shx: yeap... so I tought it was important to commit it
also, i rather like being able to compile
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Fri, 03 Dec 2004 00:57:21 +0000 |
parents | f776e117c17b |
children | 2e01c503aa4f |
rev | line source |
---|---|
9193 | 1 /** |
2 * @file slpmsg.h SLP Message functions | |
3 * | |
4 * gaim | |
5 * | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
6 * Gaim is the legal property of its developers, whose names are too numerous |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
7 * to list here. Please refer to the COPYRIGHT file distributed with this |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
8 * source distribution. |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
9 * |
9193 | 10 * This program is free software; you can redistribute it and/or modify |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 */ | |
24 #include "msn.h" | |
25 #include "slpmsg.h" | |
26 #include "slplink.h" | |
27 | |
28 /************************************************************************** | |
29 * SLP Message | |
30 **************************************************************************/ | |
31 | |
32 MsnSlpMessage * | |
33 msn_slpmsg_new(MsnSlpLink *slplink) | |
34 { | |
35 MsnSlpMessage *slpmsg; | |
36 slpmsg = g_new0(MsnSlpMessage, 1); | |
37 | |
38 slpmsg->slplink = slplink; | |
39 | |
40 slplink->slp_msgs = | |
41 g_list_append(slplink->slp_msgs, slpmsg); | |
42 | |
43 return slpmsg; | |
44 } | |
45 | |
46 void | |
47 msn_slpmsg_destroy(MsnSlpMessage *slpmsg) | |
48 { | |
49 MsnSlpLink *slplink; | |
50 | |
51 slplink = slpmsg->slplink; | |
52 | |
53 if (slpmsg->fp != NULL) | |
54 fclose(slpmsg->fp); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
55 |
9193 | 56 if (slpmsg->buffer != NULL) |
57 g_free(slpmsg->buffer); | |
58 | |
59 #ifdef DEBUG_SLP | |
60 /* | |
61 if (slpmsg->info != NULL) | |
62 g_free(slpmsg->info); | |
63 */ | |
64 #endif | |
65 | |
66 if (slpmsg->msg != NULL) | |
67 { | |
10306
56cc5d49472b
[gaim-migrate @ 11492]
Luke Schierer <lschiere@pidgin.im>
parents:
10284
diff
changeset
|
68 /* Something is pointing to this slpmsg, so we should remove that |
56cc5d49472b
[gaim-migrate @ 11492]
Luke Schierer <lschiere@pidgin.im>
parents:
10284
diff
changeset
|
69 * pointer to prevent a crash. */ |
56cc5d49472b
[gaim-migrate @ 11492]
Luke Schierer <lschiere@pidgin.im>
parents:
10284
diff
changeset
|
70 /* Ex: a user goes offline and after that we receive an ACK */ |
56cc5d49472b
[gaim-migrate @ 11492]
Luke Schierer <lschiere@pidgin.im>
parents:
10284
diff
changeset
|
71 |
56cc5d49472b
[gaim-migrate @ 11492]
Luke Schierer <lschiere@pidgin.im>
parents:
10284
diff
changeset
|
72 gaim_debug_info("msn", "Unlink slpmsg callbacks.\n"); |
56cc5d49472b
[gaim-migrate @ 11492]
Luke Schierer <lschiere@pidgin.im>
parents:
10284
diff
changeset
|
73 |
56cc5d49472b
[gaim-migrate @ 11492]
Luke Schierer <lschiere@pidgin.im>
parents:
10284
diff
changeset
|
74 slpmsg->msg->ack_cb = NULL; |
56cc5d49472b
[gaim-migrate @ 11492]
Luke Schierer <lschiere@pidgin.im>
parents:
10284
diff
changeset
|
75 slpmsg->msg->ack_data = NULL; |
56cc5d49472b
[gaim-migrate @ 11492]
Luke Schierer <lschiere@pidgin.im>
parents:
10284
diff
changeset
|
76 |
56cc5d49472b
[gaim-migrate @ 11492]
Luke Schierer <lschiere@pidgin.im>
parents:
10284
diff
changeset
|
77 #if 0 |
10284 | 78 MsnTransaction *trans; |
79 | |
80 trans = slpmsg->msg->trans; | |
81 | |
82 if (trans != NULL) | |
9193 | 83 { |
10284 | 84 if (trans->callbacks != NULL && trans->has_custom_callbacks) |
85 g_hash_table_destroy(trans->callbacks); | |
86 | |
87 trans->callbacks = NULL; | |
88 trans->data = NULL; | |
9193 | 89 } |
10306
56cc5d49472b
[gaim-migrate @ 11492]
Luke Schierer <lschiere@pidgin.im>
parents:
10284
diff
changeset
|
90 #endif |
9193 | 91 } |
92 | |
93 slplink->slp_msgs = | |
94 g_list_remove(slplink->slp_msgs, slpmsg); | |
95 | |
96 g_free(slpmsg); | |
97 } | |
98 | |
99 void | |
100 msn_slpmsg_set_body(MsnSlpMessage *slpmsg, const char *body, | |
101 long long size) | |
102 { | |
103 if (body != NULL) | |
104 slpmsg->buffer = g_memdup(body, size); | |
105 else | |
106 slpmsg->buffer = g_new0(char, size); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
107 |
9193 | 108 slpmsg->size = size; |
109 } | |
110 | |
111 void | |
112 msn_slpmsg_open_file(MsnSlpMessage *slpmsg, const char *file_name) | |
113 { | |
114 struct stat st; | |
115 | |
9219 | 116 slpmsg->fp = fopen(file_name, "rb"); |
9193 | 117 |
118 if (stat(file_name, &st) == 0) | |
119 slpmsg->size = st.st_size; | |
120 } | |
121 | |
122 #ifdef DEBUG_SLP | |
123 const void | |
124 msn_slpmsg_show(MsnMessage *msg) | |
125 { | |
126 const char *info; | |
127 gboolean text; | |
128 guint32 flags; | |
129 | |
130 text = FALSE; | |
131 | |
9775 | 132 flags = GUINT32_TO_LE(msg->msnslp_header.flags); |
9193 | 133 |
134 switch (flags) | |
135 { | |
136 case 0x0: | |
137 info = "SLP CONTROL"; | |
138 text = TRUE; | |
139 break; | |
140 case 0x2: | |
141 info = "SLP ACK"; break; | |
142 case 0x20: | |
10225 | 143 case 0x1000030: |
9193 | 144 info = "SLP DATA"; break; |
145 default: | |
146 info = "SLP UNKNOWN"; break; | |
147 } | |
148 | |
149 msn_message_show_readable(msg, info, text); | |
150 } | |
151 #endif | |
152 | |
153 MsnSlpMessage * | |
154 msn_slpmsg_sip_new(MsnSlpCall *slpcall, int cseq, | |
155 const char *header, const char *branch, | |
156 const char *content_type, const char *content) | |
157 { | |
158 MsnSlpLink *slplink; | |
159 MsnSlpMessage *slpmsg; | |
160 char *body; | |
161 gsize body_len; | |
162 gsize content_len; | |
163 | |
164 g_return_val_if_fail(slpcall != NULL, NULL); | |
165 g_return_val_if_fail(header != NULL, NULL); | |
166 | |
167 slplink = slpcall->slplink; | |
168 | |
169 /* Let's remember that "content" should end with a 0x00 */ | |
170 | |
171 content_len = (content != NULL) ? strlen(content) + 1 : 0; | |
172 | |
173 body = g_strdup_printf( | |
174 "%s\r\n" | |
175 "To: <msnmsgr:%s>\r\n" | |
176 "From: <msnmsgr:%s>\r\n" | |
177 "Via: MSNSLP/1.0/TLP ;branch={%s}\r\n" | |
178 "CSeq: %d\r\n" | |
179 "Call-ID: {%s}\r\n" | |
180 "Max-Forwards: 0\r\n" | |
181 "Content-Type: %s\r\n" | |
10112 | 182 "Content-Length: %" G_GSIZE_FORMAT "\r\n" |
9193 | 183 "\r\n", |
184 header, | |
185 slplink->remote_user, | |
186 slplink->local_user, | |
187 branch, | |
188 cseq, | |
189 slpcall->id, | |
190 content_type, | |
191 content_len); | |
192 | |
193 body_len = strlen(body); | |
194 | |
195 if (content_len > 0) | |
196 { | |
197 body_len += content_len; | |
198 body = g_realloc(body, body_len); | |
199 g_strlcat(body, content, body_len); | |
200 } | |
201 | |
202 slpmsg = msn_slpmsg_new(slplink); | |
203 msn_slpmsg_set_body(slpmsg, body, body_len); | |
204 | |
205 slpmsg->sip = TRUE; | |
206 | |
207 g_free(body); | |
208 | |
209 return slpmsg; | |
210 } |