Mercurial > pidgin.yaz
annotate src/protocols/msn/slpcall.c @ 10345:2e01c503aa4f
[gaim-migrate @ 11556]
Patch 1078151 from Felipe Contreras to fix some more MSN bugs:
"User Dislpay messages, and other less used, did not set
an slpcall, so the callback that should not be called,
was called (in some very special cases)."
...
"Here it goes the real real one, as far as I can tell.
Cleaning + organizing + documentation + hard bug fix = big
patch." -- Felipe Contreras
I also fixed drag-and-drop to conversation window file transfers (which
I had broken when I fixed some other dnd thing), made the debug output
of the autoreconnect plugin more useful, and stopped the message
notification plugin notifying you for messages sent by ignored users.
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Sat, 11 Dec 2004 20:01:58 +0000 |
parents | a7b2fd5efcf2 |
children | 92d4a25fd33c |
rev | line source |
---|---|
9193 | 1 /** |
2 * @file slpcall.c SLP Call 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 "slpcall.h" | |
26 #include "slpsession.h" | |
27 | |
28 #include "slp.h" | |
29 | |
30 /************************************************************************** | |
31 * Util | |
32 **************************************************************************/ | |
33 | |
34 char * | |
35 rand_guid() | |
36 { | |
37 return g_strdup_printf("%4X%4X-%4X-%4X-%4X-%4X%4X%4X", | |
38 rand() % 0xAAFF + 0x1111, | |
39 rand() % 0xAAFF + 0x1111, | |
40 rand() % 0xAAFF + 0x1111, | |
41 rand() % 0xAAFF + 0x1111, | |
42 rand() % 0xAAFF + 0x1111, | |
43 rand() % 0xAAFF + 0x1111, | |
44 rand() % 0xAAFF + 0x1111, | |
45 rand() % 0xAAFF + 0x1111); | |
46 } | |
47 | |
48 /************************************************************************** | |
49 * SLP Call | |
50 **************************************************************************/ | |
51 | |
52 MsnSlpCall * | |
53 msn_slp_call_new(MsnSlpLink *slplink) | |
54 { | |
55 MsnSlpCall *slpcall; | |
56 | |
57 g_return_val_if_fail(slplink != NULL, NULL); | |
58 | |
59 slpcall = g_new0(MsnSlpCall, 1); | |
60 | |
61 slpcall->slplink = slplink; | |
62 slplink->slp_calls = | |
63 g_list_append(slplink->slp_calls, slpcall); | |
64 | |
10225 | 65 slpcall->timer = gaim_timeout_add(MSN_SLPCALL_TIMEOUT, msn_slp_call_timeout, slpcall); |
66 | |
9193 | 67 return slpcall; |
68 } | |
69 | |
70 void | |
71 msn_slp_call_destroy(MsnSlpCall *slpcall) | |
72 { | |
73 GList *e; | |
74 | |
75 g_return_if_fail(slpcall != NULL); | |
76 | |
10225 | 77 if (slpcall->timer) |
78 gaim_timeout_remove(slpcall->timer); | |
79 | |
9193 | 80 if (slpcall->id != NULL) |
81 g_free(slpcall->id); | |
82 | |
83 if (slpcall->branch != NULL) | |
84 g_free(slpcall->branch); | |
85 | |
86 if (slpcall->data_info != NULL) | |
87 g_free(slpcall->data_info); | |
88 | |
89 slpcall->slplink->slp_calls = | |
90 g_list_remove(slpcall->slplink->slp_calls, slpcall); | |
91 | |
92 for (e = slpcall->slplink->slp_msgs; e != NULL; ) | |
93 { | |
94 MsnSlpMessage *slpmsg = e->data; | |
95 e = e->next; | |
96 | |
97 g_return_if_fail(slpmsg != NULL); | |
98 | |
10345 | 99 gaim_debug_info("msn", "slpcall destroy: tryping slp_msg (%p)\n", |
100 slpmsg); | |
101 | |
9193 | 102 if (slpmsg->slpcall == slpcall) |
103 msn_slpmsg_destroy(slpmsg); | |
104 } | |
105 | |
9259
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
106 if (slpcall->end_cb != NULL) |
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
107 slpcall->end_cb(slpcall); |
9193 | 108 |
109 g_free(slpcall); | |
110 } | |
111 | |
112 void | |
10345 | 113 msn_slp_call_init(MsnSlpCall *slpcall, MsnSlpCallType type) |
114 { | |
115 slpcall->session_id = rand() % 0xFFFFFF00 + 4; | |
116 slpcall->id = rand_guid(); | |
117 slpcall->type = type; | |
118 } | |
119 | |
120 void | |
121 msn_slp_call_session_init(MsnSlpCall *slpcall) | |
122 { | |
123 MsnSlpSession *slpsession; | |
124 | |
125 slpsession = msn_slp_session_new(slpcall); | |
126 | |
127 if (slpcall->session_init_cb) | |
128 slpcall->session_init_cb(slpsession); | |
129 | |
130 slpcall->started = TRUE; | |
131 } | |
132 | |
133 void | |
9193 | 134 msn_slp_call_invite(MsnSlpCall *slpcall, const char *euf_guid, |
135 int app_id, const char *context) | |
136 { | |
137 MsnSlpLink *slplink; | |
138 MsnSlpMessage *slpmsg; | |
139 char *header; | |
140 char *content; | |
141 | |
142 g_return_if_fail(slpcall != NULL); | |
143 g_return_if_fail(context != NULL); | |
144 | |
145 slplink = slpcall->slplink; | |
146 | |
10000 | 147 slpcall->branch = rand_guid(); |
9193 | 148 |
149 content = g_strdup_printf( | |
150 "EUF-GUID: {%s}\r\n" | |
151 "SessionID: %lu\r\n" | |
152 "AppID: %d\r\n" | |
153 "Context: %s\r\n\r\n", | |
154 euf_guid, | |
155 slpcall->session_id, | |
156 app_id, | |
157 context); | |
158 | |
159 header = g_strdup_printf("INVITE MSNMSGR:%s MSNSLP/1.0", | |
160 slplink->remote_user); | |
161 | |
10000 | 162 slpmsg = msn_slpmsg_sip_new(slpcall, 0, header, slpcall->branch, |
9193 | 163 "application/x-msnmsgr-sessionreqbody", content); |
10345 | 164 #ifdef MSN_DEBUG_SLP |
9193 | 165 slpmsg->info = "SLP INVITE"; |
166 slpmsg->text_body = TRUE; | |
167 #endif | |
168 | |
169 msn_slplink_send_slpmsg(slplink, slpmsg); | |
170 | |
171 g_free(header); | |
172 g_free(content); | |
173 } | |
174 | |
175 void | |
176 msn_slp_call_close(MsnSlpCall *slpcall) | |
177 { | |
178 g_return_if_fail(slpcall != NULL); | |
179 g_return_if_fail(slpcall->slplink != NULL); | |
180 | |
181 send_bye(slpcall, "application/x-msnmsgr-sessionclosebody"); | |
182 msn_slplink_unleash(slpcall->slplink); | |
183 msn_slp_call_destroy(slpcall); | |
184 } | |
185 | |
10225 | 186 gboolean |
187 msn_slp_call_timeout(gpointer data) | |
188 { | |
10296 | 189 MsnSlpCall *slpcall; |
190 | |
10225 | 191 gaim_debug_info("msn", "slpcall timeout\n"); |
192 | |
10296 | 193 slpcall = data; |
10225 | 194 |
10296 | 195 if (!slpcall->pending && !slpcall->progress) |
196 { | |
197 msn_slp_call_destroy(slpcall); | |
198 return FALSE; | |
199 } | |
200 | |
201 slpcall->progress = FALSE; | |
202 | |
203 return TRUE; | |
10225 | 204 } |
205 | |
9193 | 206 MsnSlpCall * |
207 msn_slp_process_msg(MsnSlpLink *slplink, MsnSlpMessage *slpmsg) | |
208 { | |
209 MsnSlpCall *slpcall; | |
210 const char *body; | |
211 gsize body_len; | |
212 | |
213 slpcall = NULL; | |
214 body = slpmsg->buffer; | |
215 body_len = slpmsg->size; | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
216 |
9193 | 217 if (slpmsg->flags == 0x0) |
218 { | |
219 slpcall = msn_slp_sip_recv(slplink, body, body_len); | |
220 } | |
221 else if (slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) | |
222 { | |
223 slpcall = msn_slplink_find_slp_call_with_session_id(slplink, slpmsg->session_id); | |
224 | |
225 if (slpcall != NULL) | |
10225 | 226 { |
227 if (slpcall->timer) | |
228 gaim_timeout_remove(slpcall->timer); | |
229 | |
9193 | 230 slpcall->cb(slpcall, body, body_len); |
10225 | 231 |
232 /* TODO: Shall we send a BYE? I don't think so*/ | |
233 #if 0 | |
234 send_bye(slpcall, "application/x-msnmsgr-sessionclosebody"); | |
235 msn_slplink_unleash(slpcall->slplink); | |
236 #endif | |
237 | |
238 slpcall->wasted = TRUE; | |
239 } | |
9193 | 240 } |
241 #if 0 | |
242 else if (slpmsg->flags == 0x100) | |
243 { | |
244 slpcall = slplink->directconn->initial_call; | |
245 | |
246 if (slpcall != NULL) | |
247 msn_slp_call_session_init(slpcall); | |
248 } | |
249 #endif | |
250 | |
251 return slpcall; | |
252 } |