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"
|
|
25 #include "slpcall.h"
|
|
26 #include "slpsession.h"
|
|
27
|
|
28 #include "slp.h"
|
|
29
|
|
30 /* #define MSN_DEBUG_SLPCALL */
|
|
31
|
|
32 /**************************************************************************
|
|
33 * Util
|
|
34 **************************************************************************/
|
|
35
|
|
36 static 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 /**************************************************************************
|
|
51 * Main
|
|
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
|
|
63 #ifdef MSN_DEBUG_SLPCALL
|
|
64 gaim_debug_info("msn", "slpcall_new: slpcall(%p)\n", slpcall);
|
|
65 #endif
|
|
66
|
|
67 slpcall->slplink = slplink;
|
|
68
|
|
69 msn_slplink_add_slpcall(slplink, slpcall);
|
|
70
|
|
71 slpcall->timer = gaim_timeout_add(MSN_SLPCALL_TIMEOUT, msn_slp_call_timeout, slpcall);
|
|
72
|
|
73 return slpcall;
|
|
74 }
|
|
75
|
|
76 void
|
|
77 msn_slp_call_destroy(MsnSlpCall *slpcall)
|
|
78 {
|
|
79 GList *e;
|
|
80 MsnSession *session;
|
|
81
|
|
82 #ifdef MSN_DEBUG_SLPCALL
|
|
83 gaim_debug_info("msn", "slpcall_destroy: slpcall(%p)\n", slpcall);
|
|
84 #endif
|
|
85
|
|
86 g_return_if_fail(slpcall != NULL);
|
|
87
|
|
88 if (slpcall->timer)
|
|
89 gaim_timeout_remove(slpcall->timer);
|
|
90
|
|
91 if (slpcall->id != NULL)
|
|
92 g_free(slpcall->id);
|
|
93
|
|
94 if (slpcall->branch != NULL)
|
|
95 g_free(slpcall->branch);
|
|
96
|
|
97 if (slpcall->data_info != NULL)
|
|
98 g_free(slpcall->data_info);
|
|
99
|
|
100 for (e = slpcall->slplink->slp_msgs; e != NULL; )
|
|
101 {
|
|
102 MsnSlpMessage *slpmsg = e->data;
|
|
103 e = e->next;
|
|
104
|
|
105 #ifdef MSN_DEBUG_SLPCALL_VERBOSE
|
|
106 gaim_debug_info("msn", "slpcall_destroy: trying slpmsg(%p)\n",
|
|
107 slpmsg);
|
|
108 #endif
|
|
109
|
|
110 if (slpmsg->slpcall == slpcall)
|
|
111 {
|
|
112 msn_slpmsg_destroy(slpmsg);
|
|
113 }
|
|
114 }
|
|
115
|
|
116 session = slpcall->slplink->session;
|
|
117
|
|
118 msn_slplink_remove_slpcall(slpcall->slplink, slpcall);
|
|
119
|
|
120 if (slpcall->end_cb != NULL)
|
|
121 slpcall->end_cb(slpcall, session);
|
|
122
|
|
123 g_free(slpcall);
|
|
124 }
|
|
125
|
|
126 void
|
|
127 msn_slp_call_init(MsnSlpCall *slpcall, MsnSlpCallType type)
|
|
128 {
|
|
129 slpcall->session_id = rand() % 0xFFFFFF00 + 4;
|
|
130 slpcall->id = rand_guid();
|
|
131 slpcall->type = type;
|
|
132 }
|
|
133
|
|
134 void
|
|
135 msn_slp_call_session_init(MsnSlpCall *slpcall)
|
|
136 {
|
|
137 MsnSlpSession *slpsession;
|
|
138
|
|
139 slpsession = msn_slp_session_new(slpcall);
|
|
140
|
|
141 if (slpcall->session_init_cb)
|
|
142 slpcall->session_init_cb(slpsession);
|
|
143
|
|
144 slpcall->started = TRUE;
|
|
145 }
|
|
146
|
|
147 void
|
|
148 msn_slp_call_invite(MsnSlpCall *slpcall, const char *euf_guid,
|
|
149 int app_id, const char *context)
|
|
150 {
|
|
151 MsnSlpLink *slplink;
|
|
152 MsnSlpMessage *slpmsg;
|
|
153 char *header;
|
|
154 char *content;
|
|
155
|
|
156 g_return_if_fail(slpcall != NULL);
|
|
157 g_return_if_fail(context != NULL);
|
|
158
|
|
159 slplink = slpcall->slplink;
|
|
160
|
|
161 slpcall->branch = rand_guid();
|
|
162
|
|
163 content = g_strdup_printf(
|
|
164 "EUF-GUID: {%s}\r\n"
|
|
165 "SessionID: %lu\r\n"
|
|
166 "AppID: %d\r\n"
|
|
167 "Context: %s\r\n\r\n",
|
|
168 euf_guid,
|
|
169 slpcall->session_id,
|
|
170 app_id,
|
|
171 context);
|
|
172
|
|
173 header = g_strdup_printf("INVITE MSNMSGR:%s MSNSLP/1.0",
|
|
174 slplink->remote_user);
|
|
175
|
|
176 slpmsg = msn_slpmsg_sip_new(slpcall, 0, header, slpcall->branch,
|
|
177 "application/x-msnmsgr-sessionreqbody", content);
|
|
178
|
|
179 #ifdef MSN_DEBUG_SLP
|
|
180 slpmsg->info = "SLP INVITE";
|
|
181 slpmsg->text_body = TRUE;
|
|
182 #endif
|
|
183
|
|
184 msn_slplink_send_slpmsg(slplink, slpmsg);
|
|
185
|
|
186 g_free(header);
|
|
187 g_free(content);
|
|
188 }
|
|
189
|
|
190 void
|
|
191 msn_slp_call_close(MsnSlpCall *slpcall)
|
|
192 {
|
|
193 g_return_if_fail(slpcall != NULL);
|
|
194 g_return_if_fail(slpcall->slplink != NULL);
|
|
195
|
|
196 send_bye(slpcall, "application/x-msnmsgr-sessionclosebody");
|
|
197 msn_slplink_unleash(slpcall->slplink);
|
|
198 msn_slp_call_destroy(slpcall);
|
|
199 }
|
|
200
|
|
201 gboolean
|
|
202 msn_slp_call_timeout(gpointer data)
|
|
203 {
|
|
204 MsnSlpCall *slpcall;
|
|
205
|
|
206 slpcall = data;
|
|
207
|
|
208 #ifdef MSN_DEBUG_SLPCALL
|
|
209 gaim_debug_info("msn", "slpcall_timeout: slpcall(%p)\n", slpcall);
|
|
210 #endif
|
|
211
|
|
212 if (!slpcall->pending && !slpcall->progress)
|
|
213 {
|
|
214 msn_slp_call_destroy(slpcall);
|
|
215 return FALSE;
|
|
216 }
|
|
217
|
|
218 slpcall->progress = FALSE;
|
|
219
|
|
220 return TRUE;
|
|
221 }
|
|
222
|
|
223 MsnSlpCall *
|
|
224 msn_slp_process_msg(MsnSlpLink *slplink, MsnSlpMessage *slpmsg)
|
|
225 {
|
|
226 MsnSlpCall *slpcall;
|
|
227 const guchar *body;
|
|
228 gsize body_len;
|
|
229
|
|
230 slpcall = NULL;
|
|
231 body = slpmsg->buffer;
|
|
232 body_len = slpmsg->size;
|
|
233
|
|
234 if (slpmsg->flags == 0x0)
|
|
235 {
|
|
236 char *body_str;
|
|
237
|
|
238 body_str = g_strndup((const char *)body, body_len);
|
|
239 slpcall = msn_slp_sip_recv(slplink, body_str);
|
|
240 g_free(body_str);
|
|
241 }
|
|
242 else if (slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030)
|
|
243 {
|
|
244 slpcall = msn_slplink_find_slp_call_with_session_id(slplink, slpmsg->session_id);
|
|
245
|
|
246 if (slpcall != NULL)
|
|
247 {
|
|
248 if (slpcall->timer)
|
|
249 gaim_timeout_remove(slpcall->timer);
|
|
250
|
|
251 slpcall->cb(slpcall, body, body_len);
|
|
252
|
|
253 slpcall->wasted = TRUE;
|
|
254 }
|
|
255 }
|
|
256 #if 0
|
|
257 else if (slpmsg->flags == 0x100)
|
|
258 {
|
|
259 slpcall = slplink->directconn->initial_call;
|
|
260
|
|
261 if (slpcall != NULL)
|
|
262 msn_slp_call_session_init(slpcall);
|
|
263 }
|
|
264 #endif
|
|
265
|
|
266 return slpcall;
|
|
267 }
|