1 | /********************************************************************\ |
---|
2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
3 | * * |
---|
4 | * Copyright 2002-2004 Wilmer van der Gaast and others * |
---|
5 | \********************************************************************/ |
---|
6 | |
---|
7 | /* MSN module - Notification server callbacks */ |
---|
8 | |
---|
9 | /* |
---|
10 | This program is free software; you can redistribute it and/or modify |
---|
11 | it under the terms of the GNU General Public License as published by |
---|
12 | the Free Software Foundation; either version 2 of the License, or |
---|
13 | (at your option) any later version. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, |
---|
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 | GNU General Public License for more details. |
---|
19 | |
---|
20 | You should have received a copy of the GNU General Public License with |
---|
21 | the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; |
---|
22 | if not, write to the Free Software Foundation, Inc., 59 Temple Place, |
---|
23 | Suite 330, Boston, MA 02111-1307 USA |
---|
24 | */ |
---|
25 | |
---|
26 | #include <ctype.h> |
---|
27 | #include "nogaim.h" |
---|
28 | #include "msn.h" |
---|
29 | #include "passport.h" |
---|
30 | #include "md5.h" |
---|
31 | |
---|
32 | static gboolean msn_ns_callback( gpointer data, gint source, b_input_condition cond ); |
---|
33 | static int msn_ns_command( gpointer data, char **cmd, int num_parts ); |
---|
34 | static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int num_parts ); |
---|
35 | |
---|
36 | static void msn_auth_got_passport_id( struct passport_reply *rep ); |
---|
37 | |
---|
38 | gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ) |
---|
39 | { |
---|
40 | struct im_connection *ic = data; |
---|
41 | struct msn_data *md; |
---|
42 | char s[1024]; |
---|
43 | |
---|
44 | if( !g_slist_find( msn_connections, ic ) ) |
---|
45 | return FALSE; |
---|
46 | |
---|
47 | if( source == -1 ) |
---|
48 | { |
---|
49 | imcb_error( ic, "Could not connect to server" ); |
---|
50 | imc_logout( ic, TRUE ); |
---|
51 | return FALSE; |
---|
52 | } |
---|
53 | |
---|
54 | md = ic->proto_data; |
---|
55 | |
---|
56 | if( !md->handler ) |
---|
57 | { |
---|
58 | md->handler = g_new0( struct msn_handler_data, 1 ); |
---|
59 | md->handler->data = ic; |
---|
60 | md->handler->exec_command = msn_ns_command; |
---|
61 | md->handler->exec_message = msn_ns_message; |
---|
62 | } |
---|
63 | else |
---|
64 | { |
---|
65 | if( md->handler->rxq ) |
---|
66 | g_free( md->handler->rxq ); |
---|
67 | |
---|
68 | md->handler->rxlen = 0; |
---|
69 | } |
---|
70 | |
---|
71 | md->handler->fd = md->fd; |
---|
72 | md->handler->rxq = g_new0( char, 1 ); |
---|
73 | |
---|
74 | g_snprintf( s, sizeof( s ), "VER %d MSNP8 CVR0\r\n", ++md->trId ); |
---|
75 | if( msn_write( ic, s, strlen( s ) ) ) |
---|
76 | { |
---|
77 | ic->inpa = b_input_add( md->fd, GAIM_INPUT_READ, msn_ns_callback, ic ); |
---|
78 | imcb_log( ic, "Connected to server, waiting for reply" ); |
---|
79 | } |
---|
80 | |
---|
81 | return FALSE; |
---|
82 | } |
---|
83 | |
---|
84 | static gboolean msn_ns_callback( gpointer data, gint source, b_input_condition cond ) |
---|
85 | { |
---|
86 | struct im_connection *ic = data; |
---|
87 | struct msn_data *md = ic->proto_data; |
---|
88 | |
---|
89 | if( msn_handler( md->handler ) == -1 ) /* Don't do this on ret == 0, it's already done then. */ |
---|
90 | { |
---|
91 | imcb_error( ic, "Error while reading from server" ); |
---|
92 | imc_logout( ic, TRUE ); |
---|
93 | |
---|
94 | return FALSE; |
---|
95 | } |
---|
96 | else |
---|
97 | return TRUE; |
---|
98 | } |
---|
99 | |
---|
100 | static int msn_ns_command( gpointer data, char **cmd, int num_parts ) |
---|
101 | { |
---|
102 | struct im_connection *ic = data; |
---|
103 | struct msn_data *md = ic->proto_data; |
---|
104 | char buf[1024]; |
---|
105 | |
---|
106 | if( num_parts == 0 ) |
---|
107 | { |
---|
108 | /* Hrrm... Empty command...? Ignore? */ |
---|
109 | return( 1 ); |
---|
110 | } |
---|
111 | |
---|
112 | if( strcmp( cmd[0], "VER" ) == 0 ) |
---|
113 | { |
---|
114 | if( cmd[2] && strncmp( cmd[2], "MSNP8", 5 ) != 0 ) |
---|
115 | { |
---|
116 | imcb_error( ic, "Unsupported protocol" ); |
---|
117 | imc_logout( ic, FALSE ); |
---|
118 | return( 0 ); |
---|
119 | } |
---|
120 | |
---|
121 | g_snprintf( buf, sizeof( buf ), "CVR %d 0x0409 mac 10.2.0 ppc macmsgs 3.5.1 macmsgs %s\r\n", |
---|
122 | ++md->trId, ic->acc->user ); |
---|
123 | return( msn_write( ic, buf, strlen( buf ) ) ); |
---|
124 | } |
---|
125 | else if( strcmp( cmd[0], "CVR" ) == 0 ) |
---|
126 | { |
---|
127 | /* We don't give a damn about the information we just received */ |
---|
128 | g_snprintf( buf, sizeof( buf ), "USR %d TWN I %s\r\n", ++md->trId, ic->acc->user ); |
---|
129 | return( msn_write( ic, buf, strlen( buf ) ) ); |
---|
130 | } |
---|
131 | else if( strcmp( cmd[0], "XFR" ) == 0 ) |
---|
132 | { |
---|
133 | char *server; |
---|
134 | int port; |
---|
135 | |
---|
136 | if( num_parts == 6 && strcmp( cmd[2], "NS" ) == 0 ) |
---|
137 | { |
---|
138 | b_event_remove( ic->inpa ); |
---|
139 | ic->inpa = 0; |
---|
140 | closesocket( md->fd ); |
---|
141 | |
---|
142 | server = strchr( cmd[3], ':' ); |
---|
143 | if( !server ) |
---|
144 | { |
---|
145 | imcb_error( ic, "Syntax error" ); |
---|
146 | imc_logout( ic, TRUE ); |
---|
147 | return( 0 ); |
---|
148 | } |
---|
149 | *server = 0; |
---|
150 | port = atoi( server + 1 ); |
---|
151 | server = cmd[3]; |
---|
152 | |
---|
153 | imcb_log( ic, "Transferring to other server" ); |
---|
154 | |
---|
155 | md->fd = proxy_connect( server, port, msn_ns_connected, ic ); |
---|
156 | } |
---|
157 | else if( num_parts == 6 && strcmp( cmd[2], "SB" ) == 0 ) |
---|
158 | { |
---|
159 | struct msn_switchboard *sb; |
---|
160 | |
---|
161 | server = strchr( cmd[3], ':' ); |
---|
162 | if( !server ) |
---|
163 | { |
---|
164 | imcb_error( ic, "Syntax error" ); |
---|
165 | imc_logout( ic, TRUE ); |
---|
166 | return( 0 ); |
---|
167 | } |
---|
168 | *server = 0; |
---|
169 | port = atoi( server + 1 ); |
---|
170 | server = cmd[3]; |
---|
171 | |
---|
172 | if( strcmp( cmd[4], "CKI" ) != 0 ) |
---|
173 | { |
---|
174 | imcb_error( ic, "Unknown authentication method for switchboard" ); |
---|
175 | imc_logout( ic, TRUE ); |
---|
176 | return( 0 ); |
---|
177 | } |
---|
178 | |
---|
179 | debug( "Connecting to a new switchboard with key %s", cmd[5] ); |
---|
180 | sb = msn_sb_create( ic, server, port, cmd[5], MSN_SB_NEW ); |
---|
181 | |
---|
182 | if( md->msgq ) |
---|
183 | { |
---|
184 | struct msn_message *m = md->msgq->data; |
---|
185 | GSList *l; |
---|
186 | |
---|
187 | sb->who = g_strdup( m->who ); |
---|
188 | |
---|
189 | /* Move all the messages to the first user in the message |
---|
190 | queue to the switchboard message queue. */ |
---|
191 | l = md->msgq; |
---|
192 | while( l ) |
---|
193 | { |
---|
194 | m = l->data; |
---|
195 | l = l->next; |
---|
196 | if( strcmp( m->who, sb->who ) == 0 ) |
---|
197 | { |
---|
198 | sb->msgq = g_slist_append( sb->msgq, m ); |
---|
199 | md->msgq = g_slist_remove( md->msgq, m ); |
---|
200 | } |
---|
201 | } |
---|
202 | } |
---|
203 | } |
---|
204 | else |
---|
205 | { |
---|
206 | imcb_error( ic, "Syntax error" ); |
---|
207 | imc_logout( ic, TRUE ); |
---|
208 | return( 0 ); |
---|
209 | } |
---|
210 | } |
---|
211 | else if( strcmp( cmd[0], "USR" ) == 0 ) |
---|
212 | { |
---|
213 | if( num_parts == 5 && strcmp( cmd[2], "TWN" ) == 0 && strcmp( cmd[3], "S" ) == 0 ) |
---|
214 | { |
---|
215 | /* Time for some Passport black magic... */ |
---|
216 | if( !passport_get_id( msn_auth_got_passport_id, ic, ic->acc->user, ic->acc->pass, cmd[4] ) ) |
---|
217 | { |
---|
218 | imcb_error( ic, "Error while contacting Passport server" ); |
---|
219 | imc_logout( ic, TRUE ); |
---|
220 | return( 0 ); |
---|
221 | } |
---|
222 | } |
---|
223 | else if( num_parts == 7 && strcmp( cmd[2], "OK" ) == 0 ) |
---|
224 | { |
---|
225 | set_t *s; |
---|
226 | |
---|
227 | http_decode( cmd[4] ); |
---|
228 | |
---|
229 | strncpy( ic->displayname, cmd[4], sizeof( ic->displayname ) ); |
---|
230 | ic->displayname[sizeof(ic->displayname)-1] = 0; |
---|
231 | |
---|
232 | if( ( s = set_find( &ic->acc->set, "display_name" ) ) ) |
---|
233 | { |
---|
234 | g_free( s->value ); |
---|
235 | s->value = g_strdup( cmd[4] ); |
---|
236 | } |
---|
237 | |
---|
238 | imcb_log( ic, "Authenticated, getting buddy list" ); |
---|
239 | |
---|
240 | g_snprintf( buf, sizeof( buf ), "SYN %d 0\r\n", ++md->trId ); |
---|
241 | return( msn_write( ic, buf, strlen( buf ) ) ); |
---|
242 | } |
---|
243 | else |
---|
244 | { |
---|
245 | imcb_error( ic, "Unknown authentication type" ); |
---|
246 | imc_logout( ic, FALSE ); |
---|
247 | return( 0 ); |
---|
248 | } |
---|
249 | } |
---|
250 | else if( strcmp( cmd[0], "MSG" ) == 0 ) |
---|
251 | { |
---|
252 | if( num_parts != 4 ) |
---|
253 | { |
---|
254 | imcb_error( ic, "Syntax error" ); |
---|
255 | imc_logout( ic, TRUE ); |
---|
256 | return( 0 ); |
---|
257 | } |
---|
258 | |
---|
259 | md->handler->msglen = atoi( cmd[3] ); |
---|
260 | |
---|
261 | if( md->handler->msglen <= 0 ) |
---|
262 | { |
---|
263 | imcb_error( ic, "Syntax error" ); |
---|
264 | imc_logout( ic, TRUE ); |
---|
265 | return( 0 ); |
---|
266 | } |
---|
267 | } |
---|
268 | else if( strcmp( cmd[0], "SYN" ) == 0 ) |
---|
269 | { |
---|
270 | if( num_parts == 5 ) |
---|
271 | { |
---|
272 | md->buddycount = atoi( cmd[3] ); |
---|
273 | md->groupcount = atoi( cmd[4] ); |
---|
274 | if( md->groupcount > 0 ) |
---|
275 | md->grouplist = g_new0( char *, md->groupcount ); |
---|
276 | |
---|
277 | if( !*cmd[3] || md->buddycount == 0 ) |
---|
278 | msn_logged_in( ic ); |
---|
279 | } |
---|
280 | else |
---|
281 | { |
---|
282 | /* Hrrm... This SYN reply doesn't really look like something we expected. |
---|
283 | Let's assume everything is okay. */ |
---|
284 | |
---|
285 | msn_logged_in( ic ); |
---|
286 | } |
---|
287 | } |
---|
288 | else if( strcmp( cmd[0], "LST" ) == 0 ) |
---|
289 | { |
---|
290 | int list; |
---|
291 | |
---|
292 | if( num_parts != 4 && num_parts != 5 ) |
---|
293 | { |
---|
294 | imcb_error( ic, "Syntax error" ); |
---|
295 | imc_logout( ic, TRUE ); |
---|
296 | return( 0 ); |
---|
297 | } |
---|
298 | |
---|
299 | http_decode( cmd[2] ); |
---|
300 | list = atoi( cmd[3] ); |
---|
301 | |
---|
302 | if( list & 1 ) /* FL */ |
---|
303 | { |
---|
304 | char *group = NULL; |
---|
305 | int num; |
---|
306 | |
---|
307 | if( cmd[4] != NULL && sscanf( cmd[4], "%d", &num ) == 1 ) |
---|
308 | group = md->grouplist[num]; |
---|
309 | |
---|
310 | add_buddy( ic, group, cmd[1], cmd[2] ); |
---|
311 | } |
---|
312 | if( list & 2 ) /* AL */ |
---|
313 | { |
---|
314 | ic->permit = g_slist_append( ic->permit, g_strdup( cmd[1] ) ); |
---|
315 | } |
---|
316 | if( list & 4 ) /* BL */ |
---|
317 | { |
---|
318 | ic->deny = g_slist_append( ic->deny, g_strdup( cmd[1] ) ); |
---|
319 | } |
---|
320 | if( list & 8 ) /* RL */ |
---|
321 | { |
---|
322 | if( ( list & 6 ) == 0 ) |
---|
323 | msn_buddy_ask( ic, cmd[1], cmd[2] ); |
---|
324 | } |
---|
325 | |
---|
326 | if( --md->buddycount == 0 ) |
---|
327 | { |
---|
328 | if( ic->flags & OPT_LOGGED_IN ) |
---|
329 | { |
---|
330 | imcb_log( ic, "Successfully transferred to different server" ); |
---|
331 | g_snprintf( buf, sizeof( buf ), "CHG %d %s %d\r\n", ++md->trId, md->away_state->code, 0 ); |
---|
332 | return( msn_write( ic, buf, strlen( buf ) ) ); |
---|
333 | } |
---|
334 | else |
---|
335 | { |
---|
336 | msn_logged_in( ic ); |
---|
337 | } |
---|
338 | } |
---|
339 | } |
---|
340 | else if( strcmp( cmd[0], "LSG" ) == 0 ) |
---|
341 | { |
---|
342 | int num; |
---|
343 | |
---|
344 | if( num_parts != 4 ) |
---|
345 | { |
---|
346 | imcb_error( ic, "Syntax error" ); |
---|
347 | imc_logout( ic, TRUE ); |
---|
348 | return( 0 ); |
---|
349 | } |
---|
350 | |
---|
351 | http_decode( cmd[2] ); |
---|
352 | num = atoi( cmd[1] ); |
---|
353 | |
---|
354 | if( num < md->groupcount ) |
---|
355 | md->grouplist[num] = g_strdup( cmd[2] ); |
---|
356 | } |
---|
357 | else if( strcmp( cmd[0], "CHL" ) == 0 ) |
---|
358 | { |
---|
359 | md5_state_t state; |
---|
360 | md5_byte_t digest[16]; |
---|
361 | int i; |
---|
362 | |
---|
363 | if( num_parts != 3 ) |
---|
364 | { |
---|
365 | imcb_error( ic, "Syntax error" ); |
---|
366 | imc_logout( ic, TRUE ); |
---|
367 | return( 0 ); |
---|
368 | } |
---|
369 | |
---|
370 | md5_init( &state ); |
---|
371 | md5_append( &state, (const md5_byte_t *) cmd[2], strlen( cmd[2] ) ); |
---|
372 | md5_append( &state, (const md5_byte_t *) QRY_CODE, strlen( QRY_CODE ) ); |
---|
373 | md5_finish( &state, digest ); |
---|
374 | |
---|
375 | g_snprintf( buf, sizeof( buf ), "QRY %d %s %d\r\n", ++md->trId, QRY_NAME, 32 ); |
---|
376 | for( i = 0; i < 16; i ++ ) |
---|
377 | g_snprintf( buf + strlen( buf ), 3, "%02x", digest[i] ); |
---|
378 | |
---|
379 | return( msn_write( ic, buf, strlen( buf ) ) ); |
---|
380 | } |
---|
381 | else if( strcmp( cmd[0], "ILN" ) == 0 ) |
---|
382 | { |
---|
383 | const struct msn_away_state *st; |
---|
384 | |
---|
385 | if( num_parts != 6 ) |
---|
386 | { |
---|
387 | imcb_error( ic, "Syntax error" ); |
---|
388 | imc_logout( ic, TRUE ); |
---|
389 | return( 0 ); |
---|
390 | } |
---|
391 | |
---|
392 | http_decode( cmd[4] ); |
---|
393 | serv_buddy_rename( ic, cmd[3], cmd[4] ); |
---|
394 | |
---|
395 | st = msn_away_state_by_code( cmd[2] ); |
---|
396 | if( !st ) |
---|
397 | { |
---|
398 | /* FIXME: Warn/Bomb about unknown away state? */ |
---|
399 | st = msn_away_state_list; |
---|
400 | } |
---|
401 | |
---|
402 | serv_got_update( ic, cmd[3], 1, 0, 0, 0, st->number, 0 ); |
---|
403 | } |
---|
404 | else if( strcmp( cmd[0], "FLN" ) == 0 ) |
---|
405 | { |
---|
406 | if( cmd[1] ) |
---|
407 | serv_got_update( ic, cmd[1], 0, 0, 0, 0, 0, 0 ); |
---|
408 | } |
---|
409 | else if( strcmp( cmd[0], "NLN" ) == 0 ) |
---|
410 | { |
---|
411 | const struct msn_away_state *st; |
---|
412 | |
---|
413 | if( num_parts != 5 ) |
---|
414 | { |
---|
415 | imcb_error( ic, "Syntax error" ); |
---|
416 | imc_logout( ic, TRUE ); |
---|
417 | return( 0 ); |
---|
418 | } |
---|
419 | |
---|
420 | http_decode( cmd[3] ); |
---|
421 | serv_buddy_rename( ic, cmd[2], cmd[3] ); |
---|
422 | |
---|
423 | st = msn_away_state_by_code( cmd[1] ); |
---|
424 | if( !st ) |
---|
425 | { |
---|
426 | /* FIXME: Warn/Bomb about unknown away state? */ |
---|
427 | st = msn_away_state_list; |
---|
428 | } |
---|
429 | |
---|
430 | serv_got_update( ic, cmd[2], 1, 0, 0, 0, st->number, 0 ); |
---|
431 | } |
---|
432 | else if( strcmp( cmd[0], "RNG" ) == 0 ) |
---|
433 | { |
---|
434 | struct msn_switchboard *sb; |
---|
435 | char *server; |
---|
436 | int session, port; |
---|
437 | |
---|
438 | if( num_parts != 7 ) |
---|
439 | { |
---|
440 | imcb_error( ic, "Syntax error" ); |
---|
441 | imc_logout( ic, TRUE ); |
---|
442 | return( 0 ); |
---|
443 | } |
---|
444 | |
---|
445 | session = atoi( cmd[1] ); |
---|
446 | |
---|
447 | server = strchr( cmd[2], ':' ); |
---|
448 | if( !server ) |
---|
449 | { |
---|
450 | imcb_error( ic, "Syntax error" ); |
---|
451 | imc_logout( ic, TRUE ); |
---|
452 | return( 0 ); |
---|
453 | } |
---|
454 | *server = 0; |
---|
455 | port = atoi( server + 1 ); |
---|
456 | server = cmd[2]; |
---|
457 | |
---|
458 | if( strcmp( cmd[3], "CKI" ) != 0 ) |
---|
459 | { |
---|
460 | imcb_error( ic, "Unknown authentication method for switchboard" ); |
---|
461 | imc_logout( ic, TRUE ); |
---|
462 | return( 0 ); |
---|
463 | } |
---|
464 | |
---|
465 | debug( "Got a call from %s (session %d). Key = %s", cmd[5], session, cmd[4] ); |
---|
466 | |
---|
467 | sb = msn_sb_create( ic, server, port, cmd[4], session ); |
---|
468 | sb->who = g_strdup( cmd[5] ); |
---|
469 | } |
---|
470 | else if( strcmp( cmd[0], "ADD" ) == 0 ) |
---|
471 | { |
---|
472 | if( num_parts == 6 && strcmp( cmd[2], "RL" ) == 0 ) |
---|
473 | { |
---|
474 | GSList *l; |
---|
475 | |
---|
476 | http_decode( cmd[5] ); |
---|
477 | |
---|
478 | if( strchr( cmd[4], '@' ) == NULL ) |
---|
479 | { |
---|
480 | imcb_error( ic, "Syntax error" ); |
---|
481 | imc_logout( ic, TRUE ); |
---|
482 | return( 0 ); |
---|
483 | } |
---|
484 | |
---|
485 | /* We got added by someone. If we don't have this person in permit/deny yet, inform the user. */ |
---|
486 | for( l = ic->permit; l; l = l->next ) |
---|
487 | if( g_strcasecmp( l->data, cmd[4] ) == 0 ) |
---|
488 | return( 1 ); |
---|
489 | |
---|
490 | for( l = ic->deny; l; l = l->next ) |
---|
491 | if( g_strcasecmp( l->data, cmd[4] ) == 0 ) |
---|
492 | return( 1 ); |
---|
493 | |
---|
494 | msn_buddy_ask( ic, cmd[4], cmd[5] ); |
---|
495 | } |
---|
496 | } |
---|
497 | else if( strcmp( cmd[0], "OUT" ) == 0 ) |
---|
498 | { |
---|
499 | int allow_reconnect = TRUE; |
---|
500 | |
---|
501 | if( cmd[1] && strcmp( cmd[1], "OTH" ) == 0 ) |
---|
502 | { |
---|
503 | imcb_error( ic, "Someone else logged in with your account" ); |
---|
504 | allow_reconnect = FALSE; |
---|
505 | } |
---|
506 | else if( cmd[1] && strcmp( cmd[1], "SSD" ) == 0 ) |
---|
507 | { |
---|
508 | imcb_error( ic, "Terminating session because of server shutdown" ); |
---|
509 | } |
---|
510 | else |
---|
511 | { |
---|
512 | imcb_error( ic, "Session terminated by remote server (reason unknown)" ); |
---|
513 | } |
---|
514 | |
---|
515 | imc_logout( ic, allow_reconnect ); |
---|
516 | return( 0 ); |
---|
517 | } |
---|
518 | else if( strcmp( cmd[0], "REA" ) == 0 ) |
---|
519 | { |
---|
520 | if( num_parts != 5 ) |
---|
521 | { |
---|
522 | imcb_error( ic, "Syntax error" ); |
---|
523 | imc_logout( ic, TRUE ); |
---|
524 | return( 0 ); |
---|
525 | } |
---|
526 | |
---|
527 | if( g_strcasecmp( cmd[3], ic->acc->user ) == 0 ) |
---|
528 | { |
---|
529 | set_t *s; |
---|
530 | |
---|
531 | http_decode( cmd[4] ); |
---|
532 | strncpy( ic->displayname, cmd[4], sizeof( ic->displayname ) ); |
---|
533 | ic->displayname[sizeof(ic->displayname)-1] = 0; |
---|
534 | |
---|
535 | if( ( s = set_find( &ic->acc->set, "display_name" ) ) ) |
---|
536 | { |
---|
537 | g_free( s->value ); |
---|
538 | s->value = g_strdup( cmd[4] ); |
---|
539 | } |
---|
540 | } |
---|
541 | else |
---|
542 | { |
---|
543 | /* This is not supposed to happen, but let's handle it anyway... */ |
---|
544 | http_decode( cmd[4] ); |
---|
545 | serv_buddy_rename( ic, cmd[3], cmd[4] ); |
---|
546 | } |
---|
547 | } |
---|
548 | else if( strcmp( cmd[0], "IPG" ) == 0 ) |
---|
549 | { |
---|
550 | imcb_error( ic, "Received IPG command, we don't handle them yet." ); |
---|
551 | |
---|
552 | md->handler->msglen = atoi( cmd[1] ); |
---|
553 | |
---|
554 | if( md->handler->msglen <= 0 ) |
---|
555 | { |
---|
556 | imcb_error( ic, "Syntax error" ); |
---|
557 | imc_logout( ic, TRUE ); |
---|
558 | return( 0 ); |
---|
559 | } |
---|
560 | } |
---|
561 | else if( isdigit( cmd[0][0] ) ) |
---|
562 | { |
---|
563 | int num = atoi( cmd[0] ); |
---|
564 | const struct msn_status_code *err = msn_status_by_number( num ); |
---|
565 | |
---|
566 | imcb_error( ic, "Error reported by MSN server: %s", err->text ); |
---|
567 | |
---|
568 | if( err->flags & STATUS_FATAL ) |
---|
569 | { |
---|
570 | imc_logout( ic, TRUE ); |
---|
571 | return( 0 ); |
---|
572 | } |
---|
573 | } |
---|
574 | else |
---|
575 | { |
---|
576 | debug( "Received unknown command from main server: %s", cmd[0] ); |
---|
577 | } |
---|
578 | |
---|
579 | return( 1 ); |
---|
580 | } |
---|
581 | |
---|
582 | static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int num_parts ) |
---|
583 | { |
---|
584 | struct im_connection *ic = data; |
---|
585 | char *body; |
---|
586 | int blen = 0; |
---|
587 | |
---|
588 | if( !num_parts ) |
---|
589 | return( 1 ); |
---|
590 | |
---|
591 | if( ( body = strstr( msg, "\r\n\r\n" ) ) ) |
---|
592 | { |
---|
593 | body += 4; |
---|
594 | blen = msglen - ( body - msg ); |
---|
595 | } |
---|
596 | |
---|
597 | if( strcmp( cmd[0], "MSG" ) == 0 ) |
---|
598 | { |
---|
599 | if( g_strcasecmp( cmd[1], "Hotmail" ) == 0 ) |
---|
600 | { |
---|
601 | char *ct = msn_findheader( msg, "Content-Type:", msglen ); |
---|
602 | |
---|
603 | if( !ct ) |
---|
604 | return( 1 ); |
---|
605 | |
---|
606 | if( g_strncasecmp( ct, "application/x-msmsgssystemmessage", 33 ) == 0 ) |
---|
607 | { |
---|
608 | char *mtype; |
---|
609 | char *arg1; |
---|
610 | |
---|
611 | if( !body ) |
---|
612 | return( 1 ); |
---|
613 | |
---|
614 | mtype = msn_findheader( body, "Type:", blen ); |
---|
615 | arg1 = msn_findheader( body, "Arg1:", blen ); |
---|
616 | |
---|
617 | if( mtype && strcmp( mtype, "1" ) == 0 ) |
---|
618 | { |
---|
619 | if( arg1 ) |
---|
620 | imcb_log( ic, "The server is going down for maintenance in %s minutes.", arg1 ); |
---|
621 | } |
---|
622 | |
---|
623 | if( arg1 ) g_free( arg1 ); |
---|
624 | if( mtype ) g_free( mtype ); |
---|
625 | } |
---|
626 | else if( g_strncasecmp( ct, "text/x-msmsgsprofile", 20 ) == 0 ) |
---|
627 | { |
---|
628 | /* We don't care about this profile for now... */ |
---|
629 | } |
---|
630 | else if( g_strncasecmp( ct, "text/x-msmsgsinitialemailnotification", 37 ) == 0 ) |
---|
631 | { |
---|
632 | char *inbox = msn_findheader( body, "Inbox-Unread:", blen ); |
---|
633 | char *folders = msn_findheader( body, "Folders-Unread:", blen ); |
---|
634 | |
---|
635 | if( inbox && folders ) |
---|
636 | { |
---|
637 | imcb_log( ic, "INBOX contains %s new messages, plus %s messages in other folders.", inbox, folders ); |
---|
638 | } |
---|
639 | } |
---|
640 | else if( g_strncasecmp( ct, "text/x-msmsgsemailnotification", 30 ) == 0 ) |
---|
641 | { |
---|
642 | char *from = msn_findheader( body, "From-Addr:", blen ); |
---|
643 | char *fromname = msn_findheader( body, "From:", blen ); |
---|
644 | |
---|
645 | if( from && fromname ) |
---|
646 | { |
---|
647 | imcb_log( ic, "Received an e-mail message from %s <%s>.", fromname, from ); |
---|
648 | } |
---|
649 | } |
---|
650 | else if( g_strncasecmp( ct, "text/x-msmsgsactivemailnotification", 35 ) == 0 ) |
---|
651 | { |
---|
652 | /* Sorry, but this one really is *USELESS* */ |
---|
653 | } |
---|
654 | else |
---|
655 | { |
---|
656 | debug( "Can't handle %s packet from notification server", ct ); |
---|
657 | } |
---|
658 | |
---|
659 | g_free( ct ); |
---|
660 | } |
---|
661 | } |
---|
662 | |
---|
663 | return( 1 ); |
---|
664 | } |
---|
665 | |
---|
666 | static void msn_auth_got_passport_id( struct passport_reply *rep ) |
---|
667 | { |
---|
668 | struct im_connection *ic = rep->data; |
---|
669 | struct msn_data *md = ic->proto_data; |
---|
670 | char *key = rep->result; |
---|
671 | char buf[1024]; |
---|
672 | |
---|
673 | if( key == NULL ) |
---|
674 | { |
---|
675 | imcb_error( ic, "Error during Passport authentication (%s)", |
---|
676 | rep->error_string ? rep->error_string : "Unknown error" ); |
---|
677 | imc_logout( ic, TRUE ); |
---|
678 | } |
---|
679 | else |
---|
680 | { |
---|
681 | g_snprintf( buf, sizeof( buf ), "USR %d TWN S %s\r\n", ++md->trId, key ); |
---|
682 | msn_write( ic, buf, strlen( buf ) ); |
---|
683 | } |
---|
684 | } |
---|