Mercurial > pidgin
comparison src/protocols/msn/slpcall.c @ 9193:502707ca1836
[gaim-migrate @ 9988]
Patch by Felipe Contreras to add MSN file transfer and buddy icons. Please
test and report any bugs!
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Sun, 06 Jun 2004 02:39:08 +0000 |
parents | |
children | ab6636c5a136 |
comparison
equal
deleted
inserted
replaced
9192:5655dcd94d0f | 9193:502707ca1836 |
---|---|
1 /** | |
2 * @file slpcall.c SLP Call Functions | |
3 * | |
4 * gaim | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 */ | |
20 #include "msn.h" | |
21 #include "slpcall.h" | |
22 #include "slpsession.h" | |
23 | |
24 #include "slp.h" | |
25 | |
26 /************************************************************************** | |
27 * Util | |
28 **************************************************************************/ | |
29 | |
30 char * | |
31 rand_guid() | |
32 { | |
33 return g_strdup_printf("%4X%4X-%4X-%4X-%4X-%4X%4X%4X", | |
34 rand() % 0xAAFF + 0x1111, | |
35 rand() % 0xAAFF + 0x1111, | |
36 rand() % 0xAAFF + 0x1111, | |
37 rand() % 0xAAFF + 0x1111, | |
38 rand() % 0xAAFF + 0x1111, | |
39 rand() % 0xAAFF + 0x1111, | |
40 rand() % 0xAAFF + 0x1111, | |
41 rand() % 0xAAFF + 0x1111); | |
42 } | |
43 | |
44 /************************************************************************** | |
45 * SLP Call | |
46 **************************************************************************/ | |
47 | |
48 MsnSlpCall * | |
49 msn_slp_call_new(MsnSlpLink *slplink) | |
50 { | |
51 MsnSlpCall *slpcall; | |
52 | |
53 g_return_val_if_fail(slplink != NULL, NULL); | |
54 | |
55 slpcall = g_new0(MsnSlpCall, 1); | |
56 | |
57 slpcall->slplink = slplink; | |
58 slplink->slp_calls = | |
59 g_list_append(slplink->slp_calls, slpcall); | |
60 | |
61 return slpcall; | |
62 } | |
63 | |
64 void | |
65 msn_slp_call_init(MsnSlpCall *slpcall, MsnSlpCallType type) | |
66 { | |
67 slpcall->session_id = rand() % 0xFFFFFF00 + 4; | |
68 slpcall->id = rand_guid(); | |
69 slpcall->type = type; | |
70 } | |
71 | |
72 void | |
73 msn_slp_call_session_init(MsnSlpCall *slpcall) | |
74 { | |
75 MsnSlpSession *slpsession; | |
76 | |
77 slpsession = msn_slp_session_new(slpcall); | |
78 | |
79 if (slpcall->session_init_cb) | |
80 slpcall->session_init_cb(slpsession); | |
81 | |
82 slpcall->started = TRUE; | |
83 } | |
84 | |
85 void | |
86 msn_slp_call_destroy(MsnSlpCall *slpcall) | |
87 { | |
88 GList *e; | |
89 | |
90 g_return_if_fail(slpcall != NULL); | |
91 | |
92 if (slpcall->id != NULL) | |
93 g_free(slpcall->id); | |
94 | |
95 if (slpcall->branch != NULL) | |
96 g_free(slpcall->branch); | |
97 | |
98 if (slpcall->data_info != NULL) | |
99 g_free(slpcall->data_info); | |
100 | |
101 slpcall->slplink->slp_calls = | |
102 g_list_remove(slpcall->slplink->slp_calls, slpcall); | |
103 | |
104 for (e = slpcall->slplink->slp_msgs; e != NULL; ) | |
105 { | |
106 MsnSlpMessage *slpmsg = e->data; | |
107 e = e->next; | |
108 | |
109 g_return_if_fail(slpmsg != NULL); | |
110 | |
111 if (slpmsg->slpcall == slpcall) | |
112 { | |
113 #if 1 | |
114 msn_slpmsg_destroy(slpmsg); | |
115 #else | |
116 slpmsg->wasted = TRUE; | |
117 #endif | |
118 } | |
119 } | |
120 | |
121 if (slpcall->cb != NULL) | |
122 slpcall->cb(slpcall, NULL, -1); | |
123 | |
124 g_free(slpcall); | |
125 } | |
126 | |
127 void | |
128 msn_slp_call_invite(MsnSlpCall *slpcall, const char *euf_guid, | |
129 int app_id, const char *context) | |
130 { | |
131 MsnSlpLink *slplink; | |
132 MsnSlpMessage *slpmsg; | |
133 char *header; | |
134 char *content; | |
135 char *branch; | |
136 | |
137 g_return_if_fail(slpcall != NULL); | |
138 g_return_if_fail(context != NULL); | |
139 | |
140 slplink = slpcall->slplink; | |
141 | |
142 branch = rand_guid(); | |
143 | |
144 content = g_strdup_printf( | |
145 "EUF-GUID: {%s}\r\n" | |
146 "SessionID: %lu\r\n" | |
147 "AppID: %d\r\n" | |
148 "Context: %s\r\n\r\n", | |
149 euf_guid, | |
150 slpcall->session_id, | |
151 app_id, | |
152 context); | |
153 | |
154 header = g_strdup_printf("INVITE MSNMSGR:%s MSNSLP/1.0", | |
155 slplink->remote_user); | |
156 | |
157 slpmsg = msn_slpmsg_sip_new(slpcall, 0, header, branch, | |
158 "application/x-msnmsgr-sessionreqbody", content); | |
159 #ifdef DEBUG_SLP | |
160 slpmsg->info = "SLP INVITE"; | |
161 slpmsg->text_body = TRUE; | |
162 #endif | |
163 | |
164 msn_slplink_send_slpmsg(slplink, slpmsg); | |
165 | |
166 g_free(header); | |
167 g_free(content); | |
168 | |
169 g_free(branch); | |
170 } | |
171 | |
172 void | |
173 msn_slp_call_close(MsnSlpCall *slpcall) | |
174 { | |
175 g_return_if_fail(slpcall != NULL); | |
176 g_return_if_fail(slpcall->slplink != NULL); | |
177 | |
178 send_bye(slpcall, "application/x-msnmsgr-sessionclosebody"); | |
179 msn_slplink_unleash(slpcall->slplink); | |
180 msn_slp_call_destroy(slpcall); | |
181 } | |
182 | |
183 MsnSlpCall * | |
184 msn_slp_process_msg(MsnSlpLink *slplink, MsnSlpMessage *slpmsg) | |
185 { | |
186 MsnSlpCall *slpcall; | |
187 const char *body; | |
188 gsize body_len; | |
189 | |
190 slpcall = NULL; | |
191 body = slpmsg->buffer; | |
192 body_len = slpmsg->size; | |
193 | |
194 if (slpmsg->flags == 0x0) | |
195 { | |
196 slpcall = msn_slp_sip_recv(slplink, body, body_len); | |
197 } | |
198 else if (slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) | |
199 { | |
200 slpcall = msn_slplink_find_slp_call_with_session_id(slplink, slpmsg->session_id); | |
201 | |
202 if (slpcall != NULL) | |
203 slpcall->cb(slpcall, body, body_len); | |
204 } | |
205 #if 0 | |
206 else if (slpmsg->flags == 0x100) | |
207 { | |
208 slpcall = slplink->directconn->initial_call; | |
209 | |
210 if (slpcall != NULL) | |
211 msn_slp_call_session_init(slpcall); | |
212 } | |
213 #endif | |
214 | |
215 return slpcall; | |
216 } |