Mercurial > pidgin
annotate src/protocols/msn/slpcall.c @ 11573:e3e21a3b2975
[gaim-migrate @ 13842]
This closes the file handle when the file transfer is done. As far as I can tell, everything else still works correctly.
committer: Tailor Script <tailor@pidgin.im>
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Wed, 28 Sep 2005 04:02:35 +0000 |
parents | fd6d96ef5c6d |
children | a1aa681f1448 |
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 | |
10773 | 30 /* #define MSN_DEBUG_SLPCALL */ |
31 | |
9193 | 32 /************************************************************************** |
33 * Util | |
34 **************************************************************************/ | |
35 | |
36 char * | |
37 rand_guid() | |
38 { | |
39 return g_strdup_printf("%4X%4X-%4X-%4X-%4X-%4X%4X%4X", | |
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 rand() % 0xAAFF + 0x1111, | |
47 rand() % 0xAAFF + 0x1111); | |
48 } | |
49 | |
50 /************************************************************************** | |
10602 | 51 * Main |
9193 | 52 **************************************************************************/ |
53 | |
54 MsnSlpCall * | |
55 msn_slp_call_new(MsnSlpLink *slplink) | |
56 { | |
57 MsnSlpCall *slpcall; | |
58 | |
59 g_return_val_if_fail(slplink != NULL, NULL); | |
60 | |
61 slpcall = g_new0(MsnSlpCall, 1); | |
62 | |
10773 | 63 #ifdef MSN_DEBUG_SLPCALL |
64 gaim_debug_info("msn", "slpcall_new: slpcall(%p)\n", slpcall); | |
65 #endif | |
66 | |
9193 | 67 slpcall->slplink = slplink; |
10602 | 68 |
69 msn_slplink_add_slpcall(slplink, slpcall); | |
9193 | 70 |
10225 | 71 slpcall->timer = gaim_timeout_add(MSN_SLPCALL_TIMEOUT, msn_slp_call_timeout, slpcall); |
72 | |
9193 | 73 return slpcall; |
74 } | |
75 | |
76 void | |
77 msn_slp_call_destroy(MsnSlpCall *slpcall) | |
78 { | |
79 GList *e; | |
80 | |
10773 | 81 #ifdef MSN_DEBUG_SLPCALL |
82 gaim_debug_info("msn", "slpcall_destroy: slpcall(%p)\n", slpcall); | |
83 #endif | |
84 | |
9193 | 85 g_return_if_fail(slpcall != NULL); |
86 | |
10225 | 87 if (slpcall->timer) |
88 gaim_timeout_remove(slpcall->timer); | |
89 | |
9193 | 90 if (slpcall->id != NULL) |
91 g_free(slpcall->id); | |
92 | |
93 if (slpcall->branch != NULL) | |
94 g_free(slpcall->branch); | |
95 | |
96 if (slpcall->data_info != NULL) | |
97 g_free(slpcall->data_info); | |
98 | |
99 for (e = slpcall->slplink->slp_msgs; e != NULL; ) | |
100 { | |
101 MsnSlpMessage *slpmsg = e->data; | |
102 e = e->next; | |
103 | |
10773 | 104 #ifdef MSN_DEBUG_SLPCALL_VERBOSE |
105 gaim_debug_info("msn", "slpcall_destroy: trying slpmsg(%p)\n", | |
10345 | 106 slpmsg); |
10481 | 107 #endif |
10345 | 108 |
9193 | 109 if (slpmsg->slpcall == slpcall) |
10481 | 110 { |
9193 | 111 msn_slpmsg_destroy(slpmsg); |
10481 | 112 } |
9193 | 113 } |
114 | |
10773 | 115 msn_slplink_remove_slpcall(slpcall->slplink, slpcall); |
116 | |
9259
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
117 if (slpcall->end_cb != NULL) |
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
118 slpcall->end_cb(slpcall); |
9193 | 119 |
120 g_free(slpcall); | |
121 } | |
122 | |
123 void | |
10345 | 124 msn_slp_call_init(MsnSlpCall *slpcall, MsnSlpCallType type) |
125 { | |
126 slpcall->session_id = rand() % 0xFFFFFF00 + 4; | |
127 slpcall->id = rand_guid(); | |
128 slpcall->type = type; | |
129 } | |
130 | |
131 void | |
132 msn_slp_call_session_init(MsnSlpCall *slpcall) | |
133 { | |
134 MsnSlpSession *slpsession; | |
135 | |
136 slpsession = msn_slp_session_new(slpcall); | |
137 | |
138 if (slpcall->session_init_cb) | |
139 slpcall->session_init_cb(slpsession); | |
140 | |
141 slpcall->started = TRUE; | |
142 } | |
143 | |
144 void | |
9193 | 145 msn_slp_call_invite(MsnSlpCall *slpcall, const char *euf_guid, |
146 int app_id, const char *context) | |
147 { | |
148 MsnSlpLink *slplink; | |
149 MsnSlpMessage *slpmsg; | |
150 char *header; | |
151 char *content; | |
152 | |
153 g_return_if_fail(slpcall != NULL); | |
154 g_return_if_fail(context != NULL); | |
155 | |
156 slplink = slpcall->slplink; | |
157 | |
10000 | 158 slpcall->branch = rand_guid(); |
9193 | 159 |
160 content = g_strdup_printf( | |
161 "EUF-GUID: {%s}\r\n" | |
162 "SessionID: %lu\r\n" | |
163 "AppID: %d\r\n" | |
164 "Context: %s\r\n\r\n", | |
165 euf_guid, | |
166 slpcall->session_id, | |
167 app_id, | |
168 context); | |
169 | |
170 header = g_strdup_printf("INVITE MSNMSGR:%s MSNSLP/1.0", | |
171 slplink->remote_user); | |
172 | |
10000 | 173 slpmsg = msn_slpmsg_sip_new(slpcall, 0, header, slpcall->branch, |
9193 | 174 "application/x-msnmsgr-sessionreqbody", content); |
10773 | 175 |
10345 | 176 #ifdef MSN_DEBUG_SLP |
9193 | 177 slpmsg->info = "SLP INVITE"; |
178 slpmsg->text_body = TRUE; | |
179 #endif | |
180 | |
181 msn_slplink_send_slpmsg(slplink, slpmsg); | |
182 | |
183 g_free(header); | |
184 g_free(content); | |
185 } | |
186 | |
187 void | |
188 msn_slp_call_close(MsnSlpCall *slpcall) | |
189 { | |
190 g_return_if_fail(slpcall != NULL); | |
191 g_return_if_fail(slpcall->slplink != NULL); | |
192 | |
193 send_bye(slpcall, "application/x-msnmsgr-sessionclosebody"); | |
194 msn_slplink_unleash(slpcall->slplink); | |
195 msn_slp_call_destroy(slpcall); | |
196 } | |
197 | |
10225 | 198 gboolean |
199 msn_slp_call_timeout(gpointer data) | |
200 { | |
10296 | 201 MsnSlpCall *slpcall; |
202 | |
10504 | 203 slpcall = data; |
10225 | 204 |
10773 | 205 #ifdef MSN_DEBUG_SLPCALL |
206 gaim_debug_info("msn", "slpcall_timeout: slpcall(%p)\n", slpcall); | |
207 #endif | |
10225 | 208 |
10296 | 209 if (!slpcall->pending && !slpcall->progress) |
210 { | |
211 msn_slp_call_destroy(slpcall); | |
212 return FALSE; | |
213 } | |
214 | |
215 slpcall->progress = FALSE; | |
216 | |
217 return TRUE; | |
10225 | 218 } |
219 | |
9193 | 220 MsnSlpCall * |
221 msn_slp_process_msg(MsnSlpLink *slplink, MsnSlpMessage *slpmsg) | |
222 { | |
223 MsnSlpCall *slpcall; | |
11164 | 224 const guchar *body; |
9193 | 225 gsize body_len; |
226 | |
227 slpcall = NULL; | |
228 body = slpmsg->buffer; | |
229 body_len = slpmsg->size; | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
230 |
9193 | 231 if (slpmsg->flags == 0x0) |
232 { | |
11236 | 233 char *body_str; |
234 | |
235 body_str = g_strndup((const char *)body, body_len); | |
236 slpcall = msn_slp_sip_recv(slplink, body_str); | |
237 g_free(body_str); | |
9193 | 238 } |
239 else if (slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) | |
240 { | |
241 slpcall = msn_slplink_find_slp_call_with_session_id(slplink, slpmsg->session_id); | |
242 | |
243 if (slpcall != NULL) | |
10225 | 244 { |
245 if (slpcall->timer) | |
246 gaim_timeout_remove(slpcall->timer); | |
247 | |
9193 | 248 slpcall->cb(slpcall, body, body_len); |
10225 | 249 |
250 slpcall->wasted = TRUE; | |
251 } | |
9193 | 252 } |
253 #if 0 | |
254 else if (slpmsg->flags == 0x100) | |
255 { | |
256 slpcall = slplink->directconn->initial_call; | |
257 | |
258 if (slpcall != NULL) | |
259 msn_slp_call_session_init(slpcall); | |
260 } | |
261 #endif | |
262 | |
263 return slpcall; | |
264 } |