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