1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
/**
* @file slpcall.c SLP Call Functions
*
* purple
*
* Purple is the legal property of its developers, whose names are too numerous
* to list here. Please refer to the COPYRIGHT file distributed with this
* source distribution.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "msn.h"
#include "slpcall.h"
#include "slpsession.h"
#include "slp.h"
/* #define MSN_DEBUG_SLPCALL */
/**************************************************************************
* Util
**************************************************************************/
static char *
rand_guid()
{
return g_strdup_printf("%4X%4X-%4X-%4X-%4X-%4X%4X%4X",
rand() % 0xAAFF + 0x1111,
rand() % 0xAAFF + 0x1111,
rand() % 0xAAFF + 0x1111,
rand() % 0xAAFF + 0x1111,
rand() % 0xAAFF + 0x1111,
rand() % 0xAAFF + 0x1111,
rand() % 0xAAFF + 0x1111,
rand() % 0xAAFF + 0x1111);
}
/**************************************************************************
* Main
**************************************************************************/
MsnSlpCall *
msn_slp_call_new(MsnSlpLink *slplink)
{
MsnSlpCall *slpcall;
g_return_val_if_fail(slplink != NULL, NULL);
slpcall = g_new0(MsnSlpCall, 1);
#ifdef MSN_DEBUG_SLPCALL
purple_debug_info("msn", "slpcall_new: slpcall(%p)\n", slpcall);
#endif
slpcall->slplink = slplink;
msn_slplink_add_slpcall(slplink, slpcall);
slpcall->timer = purple_timeout_add(MSN_SLPCALL_TIMEOUT, msn_slp_call_timeout, slpcall);
return slpcall;
}
void
msn_slp_call_destroy(MsnSlpCall *slpcall)
{
GList *e;
MsnSession *session;
#ifdef MSN_DEBUG_SLPCALL
purple_debug_info("msn", "slpcall_destroy: slpcall(%p)\n", slpcall);
#endif
g_return_if_fail(slpcall != NULL);
if (slpcall->timer)
purple_timeout_remove(slpcall->timer);
if (slpcall->id != NULL)
g_free(slpcall->id);
if (slpcall->branch != NULL)
g_free(slpcall->branch);
if (slpcall->data_info != NULL)
g_free(slpcall->data_info);
for (e = slpcall->slplink->slp_msgs; e != NULL; )
{
MsnSlpMessage *slpmsg = e->data;
e = e->next;
#ifdef MSN_DEBUG_SLPCALL_VERBOSE
purple_debug_info("msn", "slpcall_destroy: trying slpmsg(%p)\n",
slpmsg);
#endif
if (slpmsg->slpcall == slpcall)
{
msn_slpmsg_destroy(slpmsg);
}
}
session = slpcall->slplink->session;
msn_slplink_remove_slpcall(slpcall->slplink, slpcall);
if (slpcall->end_cb != NULL)
slpcall->end_cb(slpcall, session);
if (slpcall->xfer != NULL)
purple_xfer_unref(slpcall->xfer);
g_free(slpcall);
}
void
msn_slp_call_init(MsnSlpCall *slpcall, MsnSlpCallType type)
{
slpcall->session_id = rand() % 0xFFFFFF00 + 4;
slpcall->id = rand_guid();
slpcall->type = type;
}
void
msn_slp_call_session_init(MsnSlpCall *slpcall)
{
MsnSlpSession *slpsession;
slpsession = msn_slp_session_new(slpcall);
if (slpcall->session_init_cb)
slpcall->session_init_cb(slpsession);
slpcall->started = TRUE;
}
void
msn_slp_call_invite(MsnSlpCall *slpcall, const char *euf_guid,
int app_id, const char *context)
{
MsnSlpLink *slplink;
MsnSlpMessage *slpmsg;
char *header;
char *content;
g_return_if_fail(slpcall != NULL);
g_return_if_fail(context != NULL);
slplink = slpcall->slplink;
slpcall->branch = rand_guid();
content = g_strdup_printf(
"EUF-GUID: {%s}\r\n"
"SessionID: %lu\r\n"
"AppID: %d\r\n"
"Context: %s\r\n\r\n",
euf_guid,
slpcall->session_id,
app_id,
context);
header = g_strdup_printf("INVITE MSNMSGR:%s MSNSLP/1.0",
slplink->remote_user);
slpmsg = msn_slpmsg_sip_new(slpcall, 0, header, slpcall->branch,
"application/x-msnmsgr-sessionreqbody", content);
#ifdef MSN_DEBUG_SLP
slpmsg->info = "SLP INVITE";
slpmsg->text_body = TRUE;
#endif
msn_slplink_send_slpmsg(slplink, slpmsg);
g_free(header);
g_free(content);
}
void
msn_slp_call_close(MsnSlpCall *slpcall)
{
g_return_if_fail(slpcall != NULL);
g_return_if_fail(slpcall->slplink != NULL);
send_bye(slpcall, "application/x-msnmsgr-sessionclosebody");
msn_slplink_unleash(slpcall->slplink);
msn_slp_call_destroy(slpcall);
}
gboolean
msn_slp_call_timeout(gpointer data)
{
MsnSlpCall *slpcall;
slpcall = data;
#ifdef MSN_DEBUG_SLPCALL
purple_debug_info("msn", "slpcall_timeout: slpcall(%p)\n", slpcall);
#endif
if (!slpcall->pending && !slpcall->progress)
{
msn_slp_call_destroy(slpcall);
return FALSE;
}
slpcall->progress = FALSE;
return TRUE;
}
MsnSlpCall *
msn_slp_process_msg(MsnSlpLink *slplink, MsnSlpMessage *slpmsg)
{
MsnSlpCall *slpcall;
const guchar *body;
gsize body_len;
slpcall = NULL;
body = slpmsg->buffer;
body_len = slpmsg->size;
if (slpmsg->flags == 0x0)
{
char *body_str;
body_str = g_strndup((const char *)body, body_len);
slpcall = msn_slp_sip_recv(slplink, body_str);
g_free(body_str);
}
else if (slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030)
{
slpcall = msn_slplink_find_slp_call_with_session_id(slplink, slpmsg->session_id);
if (slpcall != NULL)
{
if (slpcall->timer)
purple_timeout_remove(slpcall->timer);
slpcall->cb(slpcall, body, body_len);
slpcall->wasted = TRUE;
}
}
#if 0
else if (slpmsg->flags == 0x100)
{
slpcall = slplink->directconn->initial_call;
if (slpcall != NULL)
msn_slp_call_session_init(slpcall);
}
#endif
return slpcall;
}
|