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