Mercurial > pidgin.yaz
annotate src/protocols/msn/slpcall.c @ 10621:fe919915fceb
[gaim-migrate @ 12090]
This should fix the MSN problems with having multiple
switchboards associated with the same conversation / buddy.
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Tue, 22 Feb 2005 15:16:38 +0000 |
parents | f52ab405f1ab |
children | 888d4c328be5 |
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 /************************************************************************** | |
10602 | 49 * Main |
9193 | 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; | |
10602 | 62 |
63 msn_slplink_add_slpcall(slplink, slpcall); | |
9193 | 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 | |
10602 | 89 msn_slplink_remove_slpcall(slpcall->slplink, slpcall); |
9193 | 90 |
91 for (e = slpcall->slplink->slp_msgs; e != NULL; ) | |
92 { | |
93 MsnSlpMessage *slpmsg = e->data; | |
94 e = e->next; | |
95 | |
96 g_return_if_fail(slpmsg != NULL); | |
97 | |
10481 | 98 #if 0 |
10451 | 99 gaim_debug_info("msn", "slpcall destroy: trying slp_msg (%p)\n", |
10345 | 100 slpmsg); |
10481 | 101 #endif |
10345 | 102 |
9193 | 103 if (slpmsg->slpcall == slpcall) |
10481 | 104 { |
9193 | 105 msn_slpmsg_destroy(slpmsg); |
10481 | 106 } |
9193 | 107 } |
108 | |
9259
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
109 if (slpcall->end_cb != NULL) |
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
110 slpcall->end_cb(slpcall); |
9193 | 111 |
112 g_free(slpcall); | |
113 } | |
114 | |
115 void | |
10345 | 116 msn_slp_call_init(MsnSlpCall *slpcall, MsnSlpCallType type) |
117 { | |
118 slpcall->session_id = rand() % 0xFFFFFF00 + 4; | |
119 slpcall->id = rand_guid(); | |
120 slpcall->type = type; | |
121 } | |
122 | |
123 void | |
124 msn_slp_call_session_init(MsnSlpCall *slpcall) | |
125 { | |
126 MsnSlpSession *slpsession; | |
127 | |
128 slpsession = msn_slp_session_new(slpcall); | |
129 | |
130 if (slpcall->session_init_cb) | |
131 slpcall->session_init_cb(slpsession); | |
132 | |
133 slpcall->started = TRUE; | |
134 } | |
135 | |
136 void | |
9193 | 137 msn_slp_call_invite(MsnSlpCall *slpcall, const char *euf_guid, |
138 int app_id, const char *context) | |
139 { | |
140 MsnSlpLink *slplink; | |
141 MsnSlpMessage *slpmsg; | |
142 char *header; | |
143 char *content; | |
144 | |
145 g_return_if_fail(slpcall != NULL); | |
146 g_return_if_fail(context != NULL); | |
147 | |
148 slplink = slpcall->slplink; | |
149 | |
10000 | 150 slpcall->branch = rand_guid(); |
9193 | 151 |
152 content = g_strdup_printf( | |
153 "EUF-GUID: {%s}\r\n" | |
154 "SessionID: %lu\r\n" | |
155 "AppID: %d\r\n" | |
156 "Context: %s\r\n\r\n", | |
157 euf_guid, | |
158 slpcall->session_id, | |
159 app_id, | |
160 context); | |
161 | |
162 header = g_strdup_printf("INVITE MSNMSGR:%s MSNSLP/1.0", | |
163 slplink->remote_user); | |
164 | |
10000 | 165 slpmsg = msn_slpmsg_sip_new(slpcall, 0, header, slpcall->branch, |
9193 | 166 "application/x-msnmsgr-sessionreqbody", content); |
10345 | 167 #ifdef MSN_DEBUG_SLP |
9193 | 168 slpmsg->info = "SLP INVITE"; |
169 slpmsg->text_body = TRUE; | |
170 #endif | |
171 | |
172 msn_slplink_send_slpmsg(slplink, slpmsg); | |
173 | |
174 g_free(header); | |
175 g_free(content); | |
176 } | |
177 | |
178 void | |
179 msn_slp_call_close(MsnSlpCall *slpcall) | |
180 { | |
181 g_return_if_fail(slpcall != NULL); | |
182 g_return_if_fail(slpcall->slplink != NULL); | |
183 | |
184 send_bye(slpcall, "application/x-msnmsgr-sessionclosebody"); | |
185 msn_slplink_unleash(slpcall->slplink); | |
186 msn_slp_call_destroy(slpcall); | |
187 } | |
188 | |
10225 | 189 gboolean |
190 msn_slp_call_timeout(gpointer data) | |
191 { | |
10296 | 192 MsnSlpCall *slpcall; |
193 | |
10504 | 194 slpcall = data; |
10225 | 195 |
10504 | 196 gaim_debug_info("msn", "slpcall timeout (%p)\n", slpcall); |
10225 | 197 |
10296 | 198 if (!slpcall->pending && !slpcall->progress) |
199 { | |
200 msn_slp_call_destroy(slpcall); | |
201 return FALSE; | |
202 } | |
203 | |
204 slpcall->progress = FALSE; | |
205 | |
206 return TRUE; | |
10225 | 207 } |
208 | |
9193 | 209 MsnSlpCall * |
210 msn_slp_process_msg(MsnSlpLink *slplink, MsnSlpMessage *slpmsg) | |
211 { | |
212 MsnSlpCall *slpcall; | |
213 const char *body; | |
214 gsize body_len; | |
215 | |
216 slpcall = NULL; | |
217 body = slpmsg->buffer; | |
218 body_len = slpmsg->size; | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
219 |
9193 | 220 if (slpmsg->flags == 0x0) |
221 { | |
222 slpcall = msn_slp_sip_recv(slplink, body, body_len); | |
223 } | |
224 else if (slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) | |
225 { | |
226 slpcall = msn_slplink_find_slp_call_with_session_id(slplink, slpmsg->session_id); | |
227 | |
228 if (slpcall != NULL) | |
10225 | 229 { |
230 if (slpcall->timer) | |
231 gaim_timeout_remove(slpcall->timer); | |
232 | |
9193 | 233 slpcall->cb(slpcall, body, body_len); |
10225 | 234 |
235 /* TODO: Shall we send a BYE? I don't think so*/ | |
236 #if 0 | |
237 send_bye(slpcall, "application/x-msnmsgr-sessionclosebody"); | |
238 msn_slplink_unleash(slpcall->slplink); | |
239 #endif | |
240 | |
241 slpcall->wasted = TRUE; | |
242 } | |
9193 | 243 } |
244 #if 0 | |
245 else if (slpmsg->flags == 0x100) | |
246 { | |
247 slpcall = slplink->directconn->initial_call; | |
248 | |
249 if (slpcall != NULL) | |
250 msn_slp_call_session_init(slpcall); | |
251 } | |
252 #endif | |
253 | |
254 return slpcall; | |
255 } |