Mercurial > pidgin
annotate libgaim/protocols/msn/slpcall.c @ 20392:9ba7dee775e1
The first msn-p13-merge-head.diff.gz from SF Patch #1621854 from Ka-Hing Cheung.
"uploaded a diff, this diff is unchanged from the last tarball that I
previously uploaded, except that it's against HEAD. This should be a little
easier for most people."
(This was apparently msn-p13-merge-head.diff, which SourceForge didn't allow to
be uploaded.)
PLUS
"Updated the diff with basically no change, except with simom's icon fix.
The previous diff was broken because some of the files were not added"
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Sun, 15 Apr 2007 03:01:41 +0000 |
parents | e354528c4163 |
children |
rev | line source |
---|---|
14192 | 1 /** |
2 * @file slpcall.c SLP Call Functions | |
3 * | |
4 * gaim | |
5 * | |
6 * Gaim is the legal property of its developers, whose names are too numerous | |
7 * to list here. Please refer to the COPYRIGHT file distributed with this | |
8 * source distribution. | |
9 * | |
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" | |
20392
9ba7dee775e1
The first msn-p13-merge-head.diff.gz from SF Patch #1621854 from Ka-Hing Cheung.
Richard Laager <rlaager@wiktel.com>
parents:
20389
diff
changeset
|
25 #include "msnutils.h" |
14192 | 26 #include "slpcall.h" |
27 #include "slpsession.h" | |
28 | |
29 #include "slp.h" | |
30 | |
31 /* #define MSN_DEBUG_SLPCALL */ | |
32 | |
33 /************************************************************************** | |
34 * Main | |
35 **************************************************************************/ | |
36 | |
37 MsnSlpCall * | |
38 msn_slp_call_new(MsnSlpLink *slplink) | |
39 { | |
40 MsnSlpCall *slpcall; | |
41 | |
42 g_return_val_if_fail(slplink != NULL, NULL); | |
43 | |
44 slpcall = g_new0(MsnSlpCall, 1); | |
45 | |
46 #ifdef MSN_DEBUG_SLPCALL | |
47 gaim_debug_info("msn", "slpcall_new: slpcall(%p)\n", slpcall); | |
48 #endif | |
49 | |
50 slpcall->slplink = slplink; | |
51 | |
52 msn_slplink_add_slpcall(slplink, slpcall); | |
53 | |
54 slpcall->timer = gaim_timeout_add(MSN_SLPCALL_TIMEOUT, msn_slp_call_timeout, slpcall); | |
55 | |
56 return slpcall; | |
57 } | |
58 | |
59 void | |
60 msn_slp_call_destroy(MsnSlpCall *slpcall) | |
61 { | |
62 GList *e; | |
63 MsnSession *session; | |
64 | |
65 #ifdef MSN_DEBUG_SLPCALL | |
66 gaim_debug_info("msn", "slpcall_destroy: slpcall(%p)\n", slpcall); | |
67 #endif | |
68 | |
69 g_return_if_fail(slpcall != NULL); | |
70 | |
71 if (slpcall->timer) | |
72 gaim_timeout_remove(slpcall->timer); | |
73 | |
74 if (slpcall->id != NULL) | |
75 g_free(slpcall->id); | |
76 | |
77 if (slpcall->branch != NULL) | |
78 g_free(slpcall->branch); | |
79 | |
80 if (slpcall->data_info != NULL) | |
81 g_free(slpcall->data_info); | |
82 | |
83 for (e = slpcall->slplink->slp_msgs; e != NULL; ) | |
84 { | |
85 MsnSlpMessage *slpmsg = e->data; | |
86 e = e->next; | |
87 | |
88 #ifdef MSN_DEBUG_SLPCALL_VERBOSE | |
89 gaim_debug_info("msn", "slpcall_destroy: trying slpmsg(%p)\n", | |
90 slpmsg); | |
91 #endif | |
92 | |
93 if (slpmsg->slpcall == slpcall) | |
94 { | |
95 msn_slpmsg_destroy(slpmsg); | |
96 } | |
97 } | |
98 | |
99 session = slpcall->slplink->session; | |
100 | |
101 msn_slplink_remove_slpcall(slpcall->slplink, slpcall); | |
102 | |
103 if (slpcall->end_cb != NULL) | |
104 slpcall->end_cb(slpcall, session); | |
105 | |
106 g_free(slpcall); | |
107 } | |
108 | |
109 void | |
110 msn_slp_call_init(MsnSlpCall *slpcall, MsnSlpCallType type) | |
111 { | |
112 slpcall->session_id = rand() % 0xFFFFFF00 + 4; | |
113 slpcall->id = rand_guid(); | |
114 slpcall->type = type; | |
115 } | |
116 | |
117 void | |
118 msn_slp_call_session_init(MsnSlpCall *slpcall) | |
119 { | |
120 MsnSlpSession *slpsession; | |
121 | |
122 slpsession = msn_slp_session_new(slpcall); | |
123 | |
124 if (slpcall->session_init_cb) | |
125 slpcall->session_init_cb(slpsession); | |
126 | |
127 slpcall->started = TRUE; | |
128 } | |
129 | |
130 void | |
131 msn_slp_call_invite(MsnSlpCall *slpcall, const char *euf_guid, | |
132 int app_id, const char *context) | |
133 { | |
134 MsnSlpLink *slplink; | |
135 MsnSlpMessage *slpmsg; | |
136 char *header; | |
137 char *content; | |
138 | |
139 g_return_if_fail(slpcall != NULL); | |
140 g_return_if_fail(context != NULL); | |
141 | |
142 slplink = slpcall->slplink; | |
143 | |
144 slpcall->branch = rand_guid(); | |
145 | |
146 content = g_strdup_printf( | |
147 "EUF-GUID: {%s}\r\n" | |
148 "SessionID: %lu\r\n" | |
149 "AppID: %d\r\n" | |
150 "Context: %s\r\n\r\n", | |
151 euf_guid, | |
152 slpcall->session_id, | |
153 app_id, | |
154 context); | |
155 | |
156 header = g_strdup_printf("INVITE MSNMSGR:%s MSNSLP/1.0", | |
157 slplink->remote_user); | |
158 | |
159 slpmsg = msn_slpmsg_sip_new(slpcall, 0, header, slpcall->branch, | |
160 "application/x-msnmsgr-sessionreqbody", content); | |
161 | |
162 #ifdef MSN_DEBUG_SLP | |
163 slpmsg->info = "SLP INVITE"; | |
164 slpmsg->text_body = TRUE; | |
165 #endif | |
166 | |
167 msn_slplink_send_slpmsg(slplink, slpmsg); | |
168 | |
169 g_free(header); | |
170 g_free(content); | |
171 } | |
172 | |
173 void | |
174 msn_slp_call_close(MsnSlpCall *slpcall) | |
175 { | |
176 g_return_if_fail(slpcall != NULL); | |
177 g_return_if_fail(slpcall->slplink != NULL); | |
178 | |
179 send_bye(slpcall, "application/x-msnmsgr-sessionclosebody"); | |
180 msn_slplink_unleash(slpcall->slplink); | |
181 msn_slp_call_destroy(slpcall); | |
182 } | |
183 | |
184 gboolean | |
185 msn_slp_call_timeout(gpointer data) | |
186 { | |
187 MsnSlpCall *slpcall; | |
188 | |
189 slpcall = data; | |
190 | |
191 #ifdef MSN_DEBUG_SLPCALL | |
192 gaim_debug_info("msn", "slpcall_timeout: slpcall(%p)\n", slpcall); | |
193 #endif | |
194 | |
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; | |
204 } | |
205 | |
206 MsnSlpCall * | |
207 msn_slp_process_msg(MsnSlpLink *slplink, MsnSlpMessage *slpmsg) | |
208 { | |
209 MsnSlpCall *slpcall; | |
210 const guchar *body; | |
211 gsize body_len; | |
212 | |
213 slpcall = NULL; | |
214 body = slpmsg->buffer; | |
215 body_len = slpmsg->size; | |
216 | |
217 if (slpmsg->flags == 0x0) | |
218 { | |
219 char *body_str; | |
220 | |
221 body_str = g_strndup((const char *)body, body_len); | |
222 slpcall = msn_slp_sip_recv(slplink, body_str); | |
223 g_free(body_str); | |
224 } | |
225 else if (slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) | |
226 { | |
227 slpcall = msn_slplink_find_slp_call_with_session_id(slplink, slpmsg->session_id); | |
228 | |
229 if (slpcall != NULL) | |
230 { | |
231 if (slpcall->timer) | |
232 gaim_timeout_remove(slpcall->timer); | |
233 | |
234 slpcall->cb(slpcall, body, body_len); | |
235 | |
236 slpcall->wasted = TRUE; | |
237 } | |
238 } | |
239 #if 0 | |
240 else if (slpmsg->flags == 0x100) | |
241 { | |
242 slpcall = slplink->directconn->initial_call; | |
243 | |
244 if (slpcall != NULL) | |
245 msn_slp_call_session_init(slpcall); | |
246 } | |
247 #endif | |
248 | |
249 return slpcall; | |
250 } |