Mercurial > pidgin.yaz
annotate src/protocols/msn/notification.c @ 5323:29754a7d94e5
[gaim-migrate @ 5695]
Convert the MSN default '~' group to "Buddies"
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Wed, 07 May 2003 01:59:22 +0000 |
parents | a4d017bee1de |
children | 9737d5ce9dcd |
rev | line source |
---|---|
5309 | 1 /** |
2 * @file notification.c Notification server functions | |
3 * | |
4 * gaim | |
5 * | |
6 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 */ | |
22 #include "msn.h" | |
23 #include "notification.h" | |
24 #include "away.h" | |
25 #include "error.h" | |
26 #include "utils.h" | |
27 | |
28 typedef struct | |
29 { | |
30 struct gaim_connection *gc; | |
31 MsnUser *user; | |
32 | |
33 } MsnPermitAdd; | |
34 | |
35 static GHashTable *notification_commands = NULL; | |
36 static GHashTable *notification_msg_types = NULL; | |
5312
89948fedf782
[gaim-migrate @ 5684]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
37 G_MODULE_IMPORT GSList *connections; |
5309 | 38 |
39 /************************************************************************** | |
40 * Callbacks | |
41 **************************************************************************/ | |
42 static void | |
43 msn_accept_add_cb(MsnPermitAdd *pa) | |
44 { | |
45 if (g_slist_find(connections, pa->gc) != NULL) { | |
46 MsnSession *session = pa->gc->proto_data; | |
47 char outparams[MSN_BUF_LEN]; | |
48 | |
49 g_snprintf(outparams, sizeof(outparams), "AL %s %s", | |
50 msn_user_get_passport(pa->user), | |
51 msn_url_encode(msn_user_get_name(pa->user))); | |
52 | |
53 if (msn_servconn_send_command(session->notification_conn, | |
54 "ADD", outparams) <= 0) { | |
55 hide_login_progress(pa->gc, _("Write error")); | |
56 signoff(pa->gc); | |
57 return; | |
58 } | |
59 | |
60 gaim_privacy_permit_add(pa->gc->account, | |
61 msn_user_get_passport(pa->user)); | |
62 build_allow_list(); | |
63 | |
64 show_got_added(pa->gc, NULL, msn_user_get_passport(pa->user), | |
65 msn_user_get_name(pa->user), NULL); | |
66 } | |
67 | |
68 msn_user_destroy(pa->user); | |
69 g_free(pa); | |
70 } | |
71 | |
72 static void | |
73 msn_cancel_add_cb(MsnPermitAdd *pa) | |
74 { | |
75 if (g_slist_find(connections, pa->gc) != NULL) { | |
76 MsnSession *session = pa->gc->proto_data; | |
77 char outparams[MSN_BUF_LEN]; | |
78 | |
79 g_snprintf(outparams, sizeof(outparams), "BL %s %s", | |
80 msn_user_get_passport(pa->user), | |
81 msn_url_encode(msn_user_get_name(pa->user))); | |
82 | |
83 if (msn_servconn_send_command(session->notification_conn, | |
84 "ADD", outparams) <= 0) { | |
85 hide_login_progress(pa->gc, _("Write error")); | |
86 signoff(pa->gc); | |
87 return; | |
88 } | |
89 | |
90 gaim_privacy_deny_add(pa->gc->account, | |
91 msn_user_get_passport(pa->user)); | |
92 build_block_list(); | |
93 } | |
94 | |
95 msn_user_destroy(pa->user); | |
96 g_free(pa); | |
97 } | |
98 | |
99 /************************************************************************** | |
100 * Catch-all commands | |
101 **************************************************************************/ | |
102 static gboolean | |
103 __blank_cmd(MsnServConn *servconn, const char *command, const char **params, | |
104 size_t param_count) | |
105 { | |
106 return TRUE; | |
107 } | |
108 | |
109 static gboolean | |
110 __unknown_cmd(MsnServConn *servconn, const char *command, const char **params, | |
111 size_t param_count) | |
112 { | |
5318
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
113 char buf[MSN_BUF_LEN]; |
5309 | 114 |
5318
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
115 g_snprintf(buf, sizeof(buf), "MSN Error: %s\n", |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
116 (isdigit(*command) |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
117 ? msn_error_get_text(atoi(command)) |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
118 : "Unable to parse message.")); |
5309 | 119 |
5318
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
120 do_error_dialog(buf, NULL, GAIM_ERROR); |
5309 | 121 |
5318
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
122 return TRUE; |
5309 | 123 } |
124 | |
125 | |
126 /************************************************************************** | |
127 * Login | |
128 **************************************************************************/ | |
129 static gboolean | |
130 __ver_cmd(MsnServConn *servconn, const char *command, const char **params, | |
131 size_t param_count) | |
132 { | |
133 struct gaim_connection *gc = servconn->session->account->gc; | |
134 size_t i; | |
135 gboolean msnp5_found = FALSE; | |
136 | |
137 for (i = 1; i < param_count; i++) { | |
138 if (!strcmp(params[i], "MSNP5")) { | |
139 msnp5_found = TRUE; | |
140 break; | |
141 } | |
142 } | |
143 | |
144 if (!msnp5_found) { | |
145 hide_login_progress(gc, _("Protocol not supported")); | |
146 signoff(gc); | |
147 | |
148 return FALSE; | |
149 } | |
150 | |
151 if (!msn_servconn_send_command(servconn, "INF", NULL)) { | |
152 hide_login_progress(gc, _("Unable to request INF")); | |
153 signoff(gc); | |
154 | |
155 return FALSE; | |
156 } | |
157 | |
158 return TRUE; | |
159 } | |
160 | |
161 static gboolean | |
162 __inf_cmd(MsnServConn *servconn, const char *command, const char **params, | |
163 size_t param_count) | |
164 { | |
165 struct gaim_connection *gc = servconn->session->account->gc; | |
166 char outparams[MSN_BUF_LEN]; | |
167 | |
168 if (strcmp(params[1], "MD5")) { | |
169 hide_login_progress(gc, _("Unable to login using MD5")); | |
170 signoff(gc); | |
171 | |
172 return FALSE; | |
173 } | |
174 | |
175 g_snprintf(outparams, sizeof(outparams), "MD5 I %s", gc->username); | |
176 | |
177 if (!msn_servconn_send_command(servconn, "USR", outparams)) { | |
178 hide_login_progress(gc, _("Unable to send USR")); | |
179 signoff(gc); | |
180 | |
181 return FALSE; | |
182 } | |
183 | |
184 set_login_progress(gc, 3, _("Requesting to send password")); | |
185 | |
186 return TRUE; | |
187 } | |
188 | |
189 static gboolean | |
190 __usr_cmd(MsnServConn *servconn, const char *command, const char **params, | |
191 size_t param_count) | |
192 { | |
193 struct gaim_connection *gc = servconn->session->account->gc; | |
194 char outparams[MSN_BUF_LEN]; | |
195 | |
196 /* We're either getting the challenge or the OK. Let's find out. */ | |
197 if (!g_ascii_strcasecmp(params[1], "OK")) { | |
198 /* OK */ | |
199 | |
200 if (!msn_servconn_send_command(servconn, "SYN", "0")) { | |
201 hide_login_progress(gc, _("Unable to write")); | |
202 signoff(gc); | |
203 | |
204 return FALSE; | |
205 } | |
206 } | |
207 else { | |
208 /* Challenge */ | |
209 const char *challenge = params[3]; | |
210 char buf[MSN_BUF_LEN]; | |
211 md5_state_t st; | |
212 md5_byte_t di[16]; | |
213 int i; | |
214 | |
215 g_snprintf(buf, sizeof(buf), "%s%s", challenge, gc->password); | |
216 | |
217 md5_init(&st); | |
218 md5_append(&st, (const md5_byte_t *)buf, strlen(buf)); | |
219 md5_finish(&st, di); | |
220 | |
221 g_snprintf(outparams, sizeof(outparams), "MD5 S "); | |
222 | |
223 for (i = 0; i < 16; i++) { | |
224 g_snprintf(buf, sizeof(buf), "%02x", di[i]); | |
225 strcat(outparams, buf); | |
226 } | |
227 | |
228 if (!msn_servconn_send_command(servconn, "USR", outparams)) { | |
229 hide_login_progress(gc, _("Unable to send password")); | |
230 signoff(gc); | |
231 | |
232 return FALSE; | |
233 } | |
234 | |
235 set_login_progress(gc, 4, _("Password sent")); | |
236 } | |
237 | |
238 return TRUE; | |
239 } | |
240 | |
241 /************************************************************************** | |
242 * Log out | |
243 **************************************************************************/ | |
244 static gboolean | |
245 __out_cmd(MsnServConn *servconn, const char *command, const char **params, | |
246 size_t param_count) | |
247 { | |
248 struct gaim_connection *gc = servconn->session->account->gc; | |
249 | |
250 if (!g_ascii_strcasecmp(params[0], "OTH")) { | |
251 hide_login_progress(gc, | |
252 _("You have been disconnected. You have " | |
253 "signed on from another location.")); | |
254 signoff(gc); | |
255 } | |
256 else if (!g_ascii_strcasecmp(params[0], "SSD")) { | |
257 hide_login_progress(gc, | |
258 _("You have been disconnected. The MSN servers " | |
259 "are going down temporarily.")); | |
260 signoff(gc); | |
261 } | |
262 | |
263 return FALSE; | |
264 } | |
265 | |
266 /************************************************************************** | |
267 * Messages | |
268 **************************************************************************/ | |
269 static gboolean | |
270 __msg_cmd(MsnServConn *servconn, const char *command, const char **params, | |
271 size_t param_count) | |
272 { | |
273 gaim_debug(GAIM_DEBUG_INFO, "msn", "Found message. Parsing.\n"); | |
274 | |
275 servconn->parsing_msg = TRUE; | |
276 servconn->msg_passport = g_strdup(params[0]); | |
277 servconn->msg_friendly = g_strdup(params[1]); | |
278 servconn->msg_len = atoi(params[2]); | |
279 | |
280 return TRUE; | |
281 } | |
282 | |
283 /************************************************************************** | |
284 * Challenges | |
285 **************************************************************************/ | |
286 static gboolean | |
287 __chl_cmd(MsnServConn *servconn, const char *command, const char **params, | |
288 size_t param_count) | |
289 { | |
290 struct gaim_connection *gc = servconn->session->account->gc; | |
291 char buf[MSN_BUF_LEN]; | |
292 char buf2[3]; | |
293 md5_state_t st; | |
294 md5_byte_t di[16]; | |
295 int i; | |
296 | |
297 md5_init(&st); | |
298 md5_append(&st, (const md5_byte_t *)params[1], strlen(params[1])); | |
299 md5_append(&st, (const md5_byte_t *)"Q1P7W2E4J9R8U3S5", | |
300 strlen("Q1P7W2E4J9R8U3S5")); | |
301 md5_finish(&st, di); | |
302 | |
303 g_snprintf(buf, sizeof(buf), | |
304 "QRY %u msmsgs@msnmsgr.com 32\r\n", | |
305 servconn->session->trId++); | |
306 | |
307 for (i = 0; i < 16; i++) { | |
308 g_snprintf(buf2, sizeof(buf2), "%02x", di[i]); | |
309 strcat(buf, buf2); | |
310 } | |
311 | |
312 if (msn_servconn_write(servconn, buf, strlen(buf)) <= 0) { | |
313 hide_login_progress(gc, _("Unable to write to server")); | |
314 signoff(gc); | |
315 } | |
316 | |
317 return TRUE; | |
318 } | |
319 | |
320 /************************************************************************** | |
321 * Buddy Lists | |
322 **************************************************************************/ | |
323 static gboolean | |
324 __add_cmd(MsnServConn *servconn, const char *command, const char **params, | |
325 size_t param_count) | |
326 { | |
327 MsnSession *session = servconn->session; | |
328 struct gaim_connection *gc = session->account->gc; | |
329 MsnPermitAdd *pa; | |
330 GSList *sl; | |
331 const char *list, *passport; | |
332 char *friend; | |
333 char msg[MSN_BUF_LEN]; | |
334 | |
335 list = params[1]; | |
336 passport = params[3]; | |
337 | |
338 friend = msn_url_decode(params[4]); | |
339 | |
340 if (g_ascii_strcasecmp(list, "RL")) | |
341 return TRUE; | |
342 | |
343 for (sl = gc->account->permit; sl != NULL; sl = sl->next) { | |
344 if (!gaim_utf8_strcasecmp(sl->data, passport)) | |
345 return TRUE; | |
346 } | |
347 | |
348 pa = g_new0(MsnPermitAdd, 1); | |
349 pa->user = msn_user_new(session, passport, friend); | |
350 pa->gc = gc; | |
351 | |
352 g_snprintf(msg, sizeof(msg), | |
353 _("The user %s (%s) wants to add %s to his or her buddy list."), | |
354 passport, friend, gc->username); | |
355 | |
356 do_ask_dialog(msg, NULL, pa, | |
357 _("Authorize"), msn_accept_add_cb, | |
358 _("Deny"), msn_cancel_add_cb, | |
359 session->prpl->handle, FALSE); | |
360 | |
361 return TRUE; | |
362 } | |
363 | |
364 static gboolean | |
5322
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
365 __adg_cmd(MsnServConn *servconn, const char *command, const char **params, |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
366 size_t param_count) |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
367 { |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
368 MsnSession *session = servconn->session; |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
369 gint *group_id; |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
370 char *group_name; |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
371 |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
372 group_id = g_new(gint, 1); |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
373 *group_id = atoi(params[3]); |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
374 |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
375 group_name = msn_url_decode(params[2]); |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
376 |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
377 gaim_debug(GAIM_DEBUG_INFO, "msn", "Added group %s (id %d)\n", |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
378 group_name, group_id); |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
379 |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
380 g_hash_table_insert(session->group_ids, group_name, group_id); |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
381 g_hash_table_insert(session->group_names, group_id, g_strdup(group_name)); |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
382 |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
383 return TRUE; |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
384 } |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
385 |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
386 static gboolean |
5309 | 387 __blp_cmd(MsnServConn *servconn, const char *command, const char **params, |
388 size_t param_count) | |
389 { | |
390 struct gaim_connection *gc = servconn->session->account->gc; | |
391 | |
392 if (!g_ascii_strcasecmp(params[2], "AL")) { | |
393 /* | |
394 * If the current setting is AL, messages from users who | |
395 * are not in BL will be delivered. | |
396 * | |
397 * In other words, deny some. | |
398 */ | |
399 gc->account->permdeny = DENY_SOME; | |
400 } | |
401 else { | |
402 /* If the current setting is BL, only messages from people | |
403 * who are in the AL will be delivered. | |
404 * | |
405 * In other words, permit some. | |
406 */ | |
407 gc->account->permdeny = PERMIT_SOME; | |
408 } | |
409 | |
410 return TRUE; | |
411 } | |
412 | |
413 static gboolean | |
414 __fln_cmd(MsnServConn *servconn, const char *command, const char **params, | |
415 size_t param_count) | |
416 { | |
417 struct gaim_connection *gc = servconn->session->account->gc; | |
418 | |
419 serv_got_update(gc, (char *)params[0], 0, 0, 0, 0, 0); | |
420 | |
421 return TRUE; | |
422 } | |
423 | |
424 static gboolean | |
425 __iln_cmd(MsnServConn *servconn, const char *command, const char **params, | |
426 size_t param_count) | |
427 { | |
428 struct gaim_connection *gc = servconn->session->account->gc; | |
429 int status = 0; | |
430 const char *state, *passport, *friend; | |
431 | |
432 state = params[1]; | |
433 passport = params[2]; | |
434 friend = msn_url_decode(params[3]); | |
435 | |
436 serv_got_alias(gc, (char *)passport, (char *)friend); | |
437 | |
438 if (!g_ascii_strcasecmp(state, "BSY")) | |
439 status |= UC_UNAVAILABLE | (MSN_BUSY << 1); | |
440 else if (!g_ascii_strcasecmp(state, "IDL")) | |
441 status |= UC_UNAVAILABLE | (MSN_IDLE << 1); | |
442 else if (!g_ascii_strcasecmp(state, "BRB")) | |
443 status |= UC_UNAVAILABLE | (MSN_BRB << 1); | |
444 else if (!g_ascii_strcasecmp(state, "AWY")) | |
445 status |= UC_UNAVAILABLE | (MSN_AWAY << 1); | |
446 else if (!g_ascii_strcasecmp(state, "PHN")) | |
447 status |= UC_UNAVAILABLE | (MSN_PHONE << 1); | |
448 else if (!g_ascii_strcasecmp(state, "LUN")) | |
449 status |= UC_UNAVAILABLE | (MSN_LUNCH << 1); | |
450 | |
451 serv_got_update(gc, (char *)passport, 1, 0, 0, 0, status); | |
452 | |
453 return TRUE; | |
454 } | |
455 | |
456 static gboolean | |
457 __lsg_cmd(MsnServConn *servconn, const char *command, const char **params, | |
458 size_t param_count) | |
459 { | |
460 MsnSession *session = servconn->session; | |
461 struct group *g; | |
462 const char *name; | |
463 int group_num, num_groups, group_id; | |
5318
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
464 gint *group_id_1, *group_id_2; |
5309 | 465 |
466 group_num = atoi(params[2]); | |
467 num_groups = atoi(params[3]); | |
468 group_id = atoi(params[4]); | |
469 name = msn_url_decode(params[5]); | |
470 | |
5318
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
471 if (num_groups == 0) |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
472 return TRUE; |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
473 |
5309 | 474 if (group_num == 1) { |
5318
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
475 session->group_names = g_hash_table_new_full(g_int_hash, g_int_equal, |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
476 g_free, g_free); |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
477 session->group_ids = g_hash_table_new_full(g_str_hash, g_str_equal, |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
478 g_free, g_free); |
5309 | 479 } |
480 | |
5318
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
481 group_id_1 = g_new(gint, 1); |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
482 group_id_2 = g_new(gint, 1); |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
483 |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
484 *group_id_1 = group_id; |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
485 *group_id_2 = group_id; |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
486 |
5323
29754a7d94e5
[gaim-migrate @ 5695]
Christian Hammond <chipx86@chipx86.com>
parents:
5322
diff
changeset
|
487 if (!strcmp(name, "~")) |
29754a7d94e5
[gaim-migrate @ 5695]
Christian Hammond <chipx86@chipx86.com>
parents:
5322
diff
changeset
|
488 name = _("Buddies"); |
29754a7d94e5
[gaim-migrate @ 5695]
Christian Hammond <chipx86@chipx86.com>
parents:
5322
diff
changeset
|
489 |
5318
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
490 g_hash_table_insert(session->group_names, group_id_1, g_strdup(name)); |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
491 g_hash_table_insert(session->group_ids, g_strdup(name), group_id_2); |
5309 | 492 |
493 if ((g = gaim_find_group(name)) == NULL) { | |
494 g = gaim_group_new(name); | |
495 gaim_blist_add_group(g, NULL); | |
496 } | |
497 | |
498 return TRUE; | |
499 } | |
500 | |
501 static gboolean | |
502 __lst_cmd(MsnServConn *servconn, const char *command, const char **params, | |
503 size_t param_count) | |
504 { | |
505 MsnSession *session = servconn->session; | |
506 struct gaim_connection *gc = session->account->gc; | |
507 int user_num; | |
508 int num_users; | |
509 const char *type; | |
510 const char *passport; | |
511 const char *friend; | |
512 | |
513 user_num = atoi(params[3]); | |
514 num_users = atoi(params[4]); | |
515 | |
516 if (user_num == 0 && num_users == 0) | |
517 return TRUE; /* There are no users on this list. */ | |
518 | |
519 type = params[1]; | |
520 passport = params[5]; | |
521 friend = msn_url_decode(params[6]); | |
522 | |
523 if (!g_ascii_strcasecmp(type, "FL") && user_num != 0) { | |
524 /* These are users on our contact list. */ | |
525 MsnUser *user; | |
526 | |
527 user = msn_user_new(session, passport, friend); | |
528 | |
529 if (param_count == 8) | |
530 msn_user_set_group_id(user, atoi(params[7])); | |
531 | |
532 session->lists.forward = g_slist_append(session->lists.forward, user); | |
533 } | |
534 else if (!g_ascii_strcasecmp(type, "AL") && user_num != 0) { | |
535 /* These are users who are allowed to see our status. */ | |
536 if (g_slist_find_custom(gc->account->deny, passport, | |
537 (GCompareFunc)strcmp)) { | |
538 | |
539 gaim_debug(GAIM_DEBUG_INFO, "msn", | |
540 "Moving user from deny list to permit: %s (%s)\n", | |
541 passport, friend); | |
542 | |
543 gaim_privacy_deny_remove(gc->account, passport); | |
544 } | |
545 | |
546 gaim_privacy_permit_add(gc->account, passport); | |
547 } | |
548 else if (!g_ascii_strcasecmp(type, "BL") && user_num != 0) { | |
549 /* These are users who are not allowed to see our status. */ | |
550 gaim_privacy_deny_add(gc->account, passport); | |
551 } | |
552 else if (!g_ascii_strcasecmp(type, "RL")) { | |
553 /* These are users who have us on their contact list. */ | |
554 if (user_num > 0) { | |
555 gboolean new_entry = TRUE; | |
556 | |
557 if (g_slist_find_custom(gc->account->permit, passport, | |
558 (GCompareFunc)g_ascii_strcasecmp)) { | |
559 new_entry = FALSE; | |
560 } | |
561 | |
562 if (g_slist_find_custom(gc->account->deny, passport, | |
563 (GCompareFunc)g_ascii_strcasecmp)) { | |
564 new_entry = FALSE; | |
565 } | |
566 | |
567 if (new_entry) { | |
568 MsnPermitAdd *pa; | |
569 char msg[MSN_BUF_LEN]; | |
570 | |
571 gaim_debug(GAIM_DEBUG_WARNING, "msn", | |
572 "Unresolved MSN RL entry: %s\n", passport); | |
573 | |
574 pa = g_new0(MsnPermitAdd, 1); | |
575 pa->user = msn_user_new(session, passport, friend); | |
576 pa->gc = gc; | |
577 | |
578 g_snprintf(msg, sizeof(msg), | |
579 _("The user %s (%s) wants to add you to their " | |
580 "buddy list."), | |
581 msn_user_get_passport(pa->user), | |
582 msn_user_get_name(pa->user)); | |
583 | |
584 do_ask_dialog(msg, NULL, pa, | |
585 _("Authorize"), msn_accept_add_cb, | |
586 _("Deny"), msn_cancel_add_cb, | |
587 session->prpl->handle, FALSE); | |
588 } | |
589 } | |
590 | |
591 if (user_num != num_users) | |
592 return TRUE; /* This isn't the last one in the RL. */ | |
593 | |
594 if (!msn_servconn_send_command(servconn, "CHG", "NLN")) { | |
595 hide_login_progress(gc, _("Unable to write")); | |
596 signoff(gc); | |
597 | |
598 return FALSE; | |
599 } | |
600 | |
601 account_online(gc); | |
602 serv_finish_login(gc); | |
603 | |
604 session->lists.allow = g_slist_copy(gc->account->permit); | |
605 session->lists.block = g_slist_copy(gc->account->deny); | |
606 | |
607 while (session->lists.forward != NULL) { | |
608 MsnUser *user = session->lists.forward->data; | |
609 struct buddy *b; | |
610 | |
611 b = gaim_find_buddy(gc->account, msn_user_get_passport(user)); | |
612 | |
613 session->lists.forward = g_slist_remove(session->lists.forward, | |
614 user); | |
615 | |
616 if (b == NULL) { | |
617 struct group *g = NULL; | |
618 const char *group_name = NULL; | |
619 int group_id; | |
620 | |
621 group_id = msn_user_get_group_id(user); | |
622 | |
623 if (group_id > -1) { | |
5318
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
624 group_name = g_hash_table_lookup(session->group_names, |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
625 &group_id); |
5309 | 626 } |
627 | |
628 if (group_name == NULL) { | |
629 gaim_debug(GAIM_DEBUG_WARNING, "msn", | |
630 "Group ID %d for user %s was not defined.\n", | |
631 group_id, passport); | |
632 } | |
633 else if ((g = gaim_find_group(group_name)) == NULL) { | |
634 gaim_debug(GAIM_DEBUG_ERROR, "msn", | |
635 "Group '%s' appears in server-side " | |
636 "buddy list, but not here!", | |
637 group_name); | |
638 } | |
639 | |
640 if (g == NULL) { | |
641 if ((g = gaim_find_group(_("Buddies"))) == NULL) { | |
642 g = gaim_group_new(_("Buddies")); | |
643 gaim_blist_add_group(g, NULL); | |
644 } | |
645 } | |
646 | |
647 b = gaim_buddy_new(gc->account, | |
648 msn_user_get_passport(user), NULL); | |
649 | |
650 gaim_blist_add_buddy(b, g, NULL); | |
651 } | |
652 | |
653 serv_got_alias(gc, (char *)msn_user_get_passport(user), | |
654 (char *)msn_user_get_name(user)); | |
655 | |
656 msn_user_destroy(user); | |
657 } | |
658 } | |
659 | |
660 return TRUE; | |
661 } | |
662 | |
663 static gboolean | |
664 __nln_cmd(MsnServConn *servconn, const char *command, const char **params, | |
665 size_t param_count) | |
666 { | |
667 MsnSession *session = servconn->session; | |
668 struct gaim_connection *gc = session->account->gc; | |
669 const char *state; | |
670 const char *passport; | |
671 const char *friend; | |
672 int status = 0; | |
673 | |
674 state = params[0]; | |
675 passport = params[1]; | |
676 friend = msn_url_decode(params[2]); | |
677 | |
678 serv_got_alias(gc, (char *)passport, (char *)friend); | |
679 | |
680 if (!g_ascii_strcasecmp(state, "BSY")) | |
681 status |= UC_UNAVAILABLE | (MSN_BUSY << 1); | |
682 else if (!g_ascii_strcasecmp(state, "IDL")) | |
683 status |= UC_UNAVAILABLE | (MSN_IDLE << 1); | |
684 else if (!g_ascii_strcasecmp(state, "BRB")) | |
685 status |= UC_UNAVAILABLE | (MSN_BRB << 1); | |
686 else if (!g_ascii_strcasecmp(state, "AWY")) | |
687 status |= UC_UNAVAILABLE | (MSN_AWAY << 1); | |
688 else if (!g_ascii_strcasecmp(state, "PHN")) | |
689 status |= UC_UNAVAILABLE | (MSN_PHONE << 1); | |
690 else if (!g_ascii_strcasecmp(state, "LUN")) | |
691 status |= UC_UNAVAILABLE | (MSN_LUNCH << 1); | |
692 | |
693 serv_got_update(gc, (char *)passport, 1, 0, 0, 0, status); | |
694 | |
695 return TRUE; | |
696 } | |
697 | |
698 static gboolean | |
699 __rea_cmd(MsnServConn *servconn, const char *command, const char **params, | |
700 size_t param_count) | |
701 { | |
702 MsnSession *session = servconn->session; | |
703 struct gaim_connection *gc = session->account->gc; | |
704 char *friend; | |
705 | |
706 friend = msn_url_decode(params[2]); | |
707 | |
708 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", friend); | |
709 | |
710 return TRUE; | |
711 } | |
712 | |
5318
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
713 static gboolean |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
714 __reg_cmd(MsnServConn *servconn, const char *command, const char **params, |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
715 size_t param_count) |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
716 { |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
717 MsnSession *session = servconn->session; |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
718 gint *group_id; |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
719 char *group_name; |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
720 |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
721 group_id = g_new(gint, 1); |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
722 *group_id = atoi(params[2]); |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
723 |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
724 group_name = msn_url_decode(params[3]); |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
725 |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
726 gaim_debug(GAIM_DEBUG_INFO, "msn", "Renamed group %s to %s\n", |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
727 g_hash_table_lookup(session->group_names, group_id), |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
728 group_name); |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
729 |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
730 g_hash_table_replace(session->group_names, group_id, g_strdup(group_name)); |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
731 |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
732 g_hash_table_remove(session->group_ids, group_name); |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
733 g_hash_table_insert(session->group_ids, group_name, group_id); |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
734 |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
735 return TRUE; |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
736 } |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
737 |
5322
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
738 static gboolean |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
739 __rem_cmd(MsnServConn *servconn, const char *command, const char **params, |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
740 size_t param_count) |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
741 { |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
742 MsnSession *session = servconn->session; |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
743 |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
744 /* I hate this. */ |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
745 if (session->moving_buddy) { |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
746 struct gaim_connection *gc = session->account->gc; |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
747 const char *passport = params[3]; |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
748 char outparams[MSN_BUF_LEN]; |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
749 |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
750 g_snprintf(outparams, sizeof(outparams), "FL %s %s %d", |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
751 passport, passport, session->dest_group_id); |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
752 |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
753 session->moving_buddy = FALSE; |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
754 session->dest_group_id = 0; |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
755 |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
756 if (!msn_servconn_send_command(session->notification_conn, |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
757 "ADD", outparams)) { |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
758 hide_login_progress(gc, _("Write error")); |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
759 signoff(gc); |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
760 } |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
761 } |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
762 |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
763 return TRUE; |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
764 } |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
765 |
5309 | 766 /************************************************************************** |
767 * Misc commands | |
768 **************************************************************************/ | |
769 static gboolean | |
770 __url_cmd(MsnServConn *servconn, const char *command, const char **params, | |
771 size_t param_count) | |
772 { | |
773 MsnSession *session = servconn->session; | |
774 struct gaim_connection *gc = session->account->gc; | |
775 const char *rru; | |
776 const char *url; | |
777 md5_state_t st; | |
778 md5_byte_t di[16]; | |
779 FILE *fd; | |
780 char buf[2048]; | |
781 char buf2[3]; | |
782 char sendbuf[64]; | |
783 int i; | |
784 | |
785 rru = params[1]; | |
786 url = params[2]; | |
787 | |
788 g_snprintf(buf, sizeof(buf), "%s%lu%s", | |
789 session->passport_info.mspauth, | |
790 time(NULL) - session->passport_info.sl, gc->password); | |
791 | |
792 md5_init(&st); | |
793 md5_append(&st, (const md5_byte_t *)buf, strlen(buf)); | |
794 md5_finish(&st, di); | |
795 | |
796 memset(sendbuf, 0, sizeof(sendbuf)); | |
797 | |
798 for (i = 0; i < 16; i++) { | |
799 g_snprintf(buf2, sizeof(buf2), "%02x", di[i]); | |
800 strcat(sendbuf, buf2); | |
801 } | |
802 | |
803 if (session->passport_info.file != NULL) { | |
804 unlink(session->passport_info.file); | |
805 g_free(session->passport_info.file); | |
806 } | |
807 | |
808 if ((fd = gaim_mkstemp(&session->passport_info.file)) == NULL) { | |
809 gaim_debug(GAIM_DEBUG_ERROR, "msn", | |
810 "Error opening temp passport file: %s\n", | |
811 strerror(errno)); | |
812 } | |
813 else { | |
814 fputs("<html>\n" | |
815 "<head>\n" | |
816 "<noscript>\n" | |
817 "<meta http-equiv=\"Refresh\" content=\"0; " | |
818 "url=http://www.hotmail.com\">\n" | |
819 "</noscript>\n" | |
820 "</head>\n\n", | |
821 fd); | |
822 | |
823 fprintf(fd, "<body onload=\"document.pform.submit(); \">\n"); | |
824 fprintf(fd, "<form name=\"pform\" action=\"%s\" method=\"POST\">\n\n", | |
825 url); | |
826 fprintf(fd, "<input type=\"hidden\" name=\"mode\" value=\"ttl\">\n"); | |
827 fprintf(fd, "<input type=\"hidden\" name=\"login\" value=\"%s\">\n", | |
828 gc->username); | |
829 fprintf(fd, "<input type=\"hidden\" name=\"username\" value=\"%s\">\n", | |
830 gc->username); | |
831 fprintf(fd, "<input type=\"hidden\" name=\"sid\" value=\"%s\">\n", | |
832 session->passport_info.sid); | |
833 fprintf(fd, "<input type=\"hidden\" name=\"kv\" value=\"%s\">\n", | |
834 session->passport_info.kv); | |
835 fprintf(fd, "<input type=\"hidden\" name=\"id\" value=\"2\">\n"); | |
836 fprintf(fd, "<input type=\"hidden\" name=\"sl\" value=\"%ld\">\n", | |
837 time(NULL) - session->passport_info.sl); | |
838 fprintf(fd, "<input type=\"hidden\" name=\"rru\" value=\"%s\">\n", | |
839 rru); | |
840 fprintf(fd, "<input type=\"hidden\" name=\"auth\" value=\"%s\">\n", | |
841 session->passport_info.mspauth); | |
842 fprintf(fd, "<input type=\"hidden\" name=\"creds\" value=\"%s\">\n", | |
843 sendbuf); /* TODO Digest me (huh? -- ChipX86) */ | |
844 fprintf(fd, "<input type=\"hidden\" name=\"svc\" value=\"mail\">\n"); | |
845 fprintf(fd, "<input type=\"hiden\" name=\"js\" value=\"yes\">\n"); | |
846 fprintf(fd, "</form></body>\n"); | |
847 fprintf(fd, "</html>\n"); | |
848 | |
849 if (fclose(fd)) { | |
850 gaim_debug(GAIM_DEBUG_ERROR, "msn", | |
851 "Error closing temp passport file: %s\n", | |
852 strerror(errno)); | |
853 | |
854 unlink(session->passport_info.file); | |
855 g_free(session->passport_info.file); | |
856 } | |
857 else { | |
858 /* | |
859 * Renaming file with .html extension, so that the | |
860 * win32 open_url will work. | |
861 */ | |
862 char *tmp; | |
863 | |
864 if ((tmp = g_strdup_printf("%s.html", | |
865 session->passport_info.file)) != NULL) { | |
866 | |
867 if (rename(session->passport_info.file, tmp) == 0) { | |
868 g_free(session->passport_info.file); | |
869 session->passport_info.file = tmp; | |
870 } | |
871 else | |
872 g_free(tmp); | |
873 } | |
874 } | |
875 } | |
876 | |
877 return TRUE; | |
878 } | |
879 /************************************************************************** | |
880 * Switchboards | |
881 **************************************************************************/ | |
882 static gboolean | |
883 __rng_cmd(MsnServConn *servconn, const char *command, const char **params, | |
884 size_t param_count) | |
885 { | |
886 MsnSession *session = servconn->session; | |
887 MsnSwitchBoard *swboard; | |
888 MsnUser *user; | |
889 const char *session_id; | |
890 char *host, *c; | |
891 int port; | |
892 | |
893 session_id = params[0]; | |
894 | |
895 host = g_strdup(params[1]); | |
896 | |
897 if ((c = strchr(host, ':')) != NULL) { | |
898 *c = '\0'; | |
899 port = atoi(c + 1); | |
900 } | |
901 else | |
902 port = 1863; | |
903 | |
904 swboard = msn_switchboard_new(session); | |
905 | |
906 user = msn_user_new(session, params[4], NULL); | |
907 | |
908 msn_switchboard_set_invited(swboard, TRUE); | |
909 msn_switchboard_set_session_id(swboard, params[0]); | |
910 msn_switchboard_set_auth_key(swboard, params[3]); | |
911 msn_switchboard_set_user(swboard, user); | |
912 | |
913 if (!msn_switchboard_connect(swboard, host, port)) { | |
914 gaim_debug(GAIM_DEBUG_ERROR, "msn", | |
915 "Unable to connect to switchboard on %s, port %d\n", | |
916 host, port); | |
917 | |
918 g_free(host); | |
919 | |
920 return FALSE; | |
921 } | |
922 | |
923 g_free(host); | |
924 | |
925 return TRUE; | |
926 } | |
927 | |
928 static gboolean | |
929 __xfr_cmd(MsnServConn *servconn, const char *command, const char **params, | |
930 size_t param_count) | |
931 { | |
932 MsnSession *session = servconn->session; | |
933 MsnSwitchBoard *swboard; | |
934 struct gaim_connection *gc = session->account->gc; | |
935 char *host; | |
936 char *c; | |
937 int port; | |
938 | |
939 if (strcmp(params[1], "SB")) { | |
940 hide_login_progress(gc, _("Got invalid XFR")); | |
941 signoff(gc); | |
942 | |
943 return FALSE; | |
944 } | |
945 | |
946 host = g_strdup(params[2]); | |
947 | |
948 if ((c = strchr(host, ':')) != NULL) { | |
949 *c = '\0'; | |
950 port = atoi(c + 1); | |
951 } | |
952 else | |
953 port = 1863; | |
954 | |
955 swboard = msn_session_find_unused_switch(session); | |
956 | |
957 if (swboard == NULL) { | |
958 gaim_debug(GAIM_DEBUG_ERROR, "msn", | |
959 "Received an XFR SB request when there's no unused " | |
960 "switchboards!\n"); | |
961 } | |
962 | |
963 msn_switchboard_set_auth_key(swboard, params[4]); | |
964 | |
965 if (!msn_switchboard_connect(swboard, host, port)) { | |
966 gaim_debug(GAIM_DEBUG_ERROR, "msn", | |
967 "Unable to connect to switchboard on %s, port %d\n", | |
968 host, port); | |
969 | |
970 g_free(host); | |
971 | |
972 return FALSE; | |
973 } | |
974 | |
975 g_free(host); | |
976 | |
977 return TRUE; | |
978 } | |
979 | |
980 /************************************************************************** | |
981 * Message Types | |
982 **************************************************************************/ | |
983 static gboolean | |
984 __profile_msg(MsnServConn *servconn, const MsnMessage *msg) | |
985 { | |
986 MsnSession *session = servconn->session; | |
987 const char *value; | |
988 | |
989 if ((value = msn_message_get_attr(msg, "kv")) != NULL) | |
990 session->passport_info.kv = g_strdup(value); | |
991 | |
992 if ((value = msn_message_get_attr(msg, "sid")) != NULL) | |
993 session->passport_info.sid = g_strdup(value); | |
994 | |
995 if ((value = msn_message_get_attr(msg, "MSPAuth")) != NULL) | |
996 session->passport_info.mspauth = g_strdup(value); | |
997 | |
998 return TRUE; | |
999 } | |
1000 | |
1001 static gboolean | |
1002 __initial_email_msg(MsnServConn *servconn, const MsnMessage *msg) | |
1003 { | |
1004 MsnSession *session = servconn->session; | |
1005 struct gaim_connection *gc = session->account->gc; | |
1006 GHashTable *table; | |
1007 const char *unread; | |
1008 | |
1009 table = msn_message_get_hashtable_from_body(msg); | |
1010 | |
1011 unread = g_hash_table_lookup(table, "Inbox-Unread"); | |
1012 | |
1013 if (unread != NULL) | |
1014 connection_has_mail(gc, atoi(unread), NULL, NULL, | |
1015 session->passport_info.file); | |
1016 | |
1017 g_hash_table_destroy(table); | |
1018 | |
1019 return TRUE; | |
1020 } | |
1021 | |
1022 static gboolean | |
1023 __email_msg(MsnServConn *servconn, const MsnMessage *msg) | |
1024 { | |
1025 MsnSession *session = servconn->session; | |
1026 struct gaim_connection *gc = session->account->gc; | |
1027 GHashTable *table; | |
1028 const char *from, *subject; | |
1029 | |
1030 table = msn_message_get_hashtable_from_body(msg); | |
1031 | |
1032 from = g_hash_table_lookup(table, "From"); | |
1033 subject = g_hash_table_lookup(table, "Subject"); | |
1034 | |
1035 if (from == NULL || subject == NULL) { | |
1036 connection_has_mail(gc, 1, NULL, NULL, session->passport_info.file); | |
1037 } | |
1038 else { | |
1039 connection_has_mail(gc, -1, from, subject, | |
1040 session->passport_info.file); | |
1041 } | |
1042 | |
1043 g_hash_table_destroy(table); | |
1044 | |
1045 return TRUE; | |
1046 } | |
1047 | |
1048 static gboolean | |
1049 __connect_cb(gpointer data, gint source, GaimInputCondition cond) | |
1050 { | |
1051 MsnServConn *notification = data; | |
1052 MsnSession *session = notification->session; | |
1053 struct gaim_connection *gc = session->account->gc; | |
1054 | |
1055 if (source == -1) { | |
1056 hide_login_progress(session->account->gc, _("Unable to connect")); | |
1057 signoff(session->account->gc); | |
1058 return FALSE; | |
1059 } | |
1060 | |
1061 if (notification->fd != source) | |
1062 notification->fd = source; | |
1063 | |
1064 if (!msn_servconn_send_command(notification, "VER", | |
5318
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
1065 "MSNP7 MSNP6 MSNP5 MSNP4 CVR0")) { |
5309 | 1066 hide_login_progress(gc, _("Unable to write to server")); |
1067 signoff(gc); | |
1068 return FALSE; | |
1069 } | |
1070 | |
1071 set_login_progress(session->account->gc, 2, _("Syncing with server")); | |
1072 | |
1073 return TRUE; | |
1074 } | |
1075 | |
1076 static void | |
1077 __failed_read_cb(gpointer data, gint source, GaimInputCondition cond) | |
1078 { | |
1079 MsnServConn *notification = data; | |
1080 struct gaim_connection *gc; | |
1081 | |
1082 gc = notification->session->account->gc; | |
1083 | |
1084 hide_login_progress(gc, _("Error reading from server")); | |
1085 signoff(gc); | |
1086 } | |
1087 | |
1088 MsnServConn * | |
1089 msn_notification_new(MsnSession *session, const char *server, int port) | |
1090 { | |
1091 MsnServConn *notification; | |
1092 | |
1093 notification = msn_servconn_new(session); | |
1094 | |
1095 msn_servconn_set_server(notification, server, port); | |
1096 msn_servconn_set_connect_cb(notification, __connect_cb); | |
1097 msn_servconn_set_failed_read_cb(notification, __failed_read_cb); | |
1098 | |
1099 if (notification_commands == NULL) { | |
1100 /* Register the command callbacks. */ | |
1101 msn_servconn_register_command(notification, "ADD", __add_cmd); | |
5322
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
1102 msn_servconn_register_command(notification, "ADG", __adg_cmd); |
5309 | 1103 msn_servconn_register_command(notification, "BLP", __blp_cmd); |
1104 msn_servconn_register_command(notification, "BPR", __blank_cmd); | |
1105 msn_servconn_register_command(notification, "CHG", __blank_cmd); | |
1106 msn_servconn_register_command(notification, "CHL", __chl_cmd); | |
1107 msn_servconn_register_command(notification, "FLN", __fln_cmd); | |
1108 msn_servconn_register_command(notification, "GTC", __blank_cmd); | |
1109 msn_servconn_register_command(notification, "ILN", __iln_cmd); | |
1110 msn_servconn_register_command(notification, "INF", __inf_cmd); | |
1111 msn_servconn_register_command(notification, "LSG", __lsg_cmd); | |
1112 msn_servconn_register_command(notification, "LST", __lst_cmd); | |
1113 msn_servconn_register_command(notification, "MSG", __msg_cmd); | |
1114 msn_servconn_register_command(notification, "NLN", __nln_cmd); | |
1115 msn_servconn_register_command(notification, "OUT", __out_cmd); | |
1116 msn_servconn_register_command(notification, "PRP", __blank_cmd); | |
1117 msn_servconn_register_command(notification, "QNG", __blank_cmd); | |
1118 msn_servconn_register_command(notification, "QRY", __blank_cmd); | |
1119 msn_servconn_register_command(notification, "REA", __rea_cmd); | |
5318
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5312
diff
changeset
|
1120 msn_servconn_register_command(notification, "REG", __reg_cmd); |
5322
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
1121 msn_servconn_register_command(notification, "REM", __rem_cmd); |
a4d017bee1de
[gaim-migrate @ 5694]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
1122 msn_servconn_register_command(notification, "RMG", __blank_cmd); |
5309 | 1123 msn_servconn_register_command(notification, "RNG", __rng_cmd); |
1124 msn_servconn_register_command(notification, "SYN", __blank_cmd); | |
1125 msn_servconn_register_command(notification, "URL", __url_cmd); | |
1126 msn_servconn_register_command(notification, "USR", __usr_cmd); | |
1127 msn_servconn_register_command(notification, "VER", __ver_cmd); | |
1128 msn_servconn_register_command(notification, "XFR", __xfr_cmd); | |
1129 msn_servconn_register_command(notification, "_unknown_", __unknown_cmd); | |
1130 | |
1131 /* Register the message type callbacks. */ | |
1132 msn_servconn_register_msg_type(notification, "text/x-msmsgsprofile", | |
1133 __profile_msg); | |
1134 msn_servconn_register_msg_type(notification, | |
1135 "text/x-msmsgsinitialemailnotification", | |
1136 __initial_email_msg); | |
1137 msn_servconn_register_msg_type(notification, | |
1138 "text/x-msmsgsemailnotification", | |
1139 __email_msg); | |
1140 | |
1141 /* Save these for future use. */ | |
1142 notification_commands = notification->commands; | |
1143 notification_msg_types = notification->msg_types; | |
1144 } | |
1145 else { | |
1146 g_hash_table_destroy(notification->commands); | |
1147 g_hash_table_destroy(notification->msg_types); | |
1148 | |
1149 notification->commands = notification_commands; | |
1150 notification->msg_types = notification_msg_types; | |
1151 } | |
1152 | |
1153 return notification; | |
1154 } |