[b7d3cc34] | 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 | |
---|
[ba9edaa] | 32 | static gboolean msn_ns_callback( gpointer data, gint source, b_input_condition cond ); |
---|
[b7d3cc34] | 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 | |
---|
[e6648bf] | 36 | static void msn_auth_got_passport_token( struct msn_auth_data *mad ); |
---|
[b7d3cc34] | 37 | |
---|
[ba9edaa] | 38 | gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ) |
---|
[b7d3cc34] | 39 | { |
---|
[0da65d5] | 40 | struct im_connection *ic = data; |
---|
[b7d3cc34] | 41 | struct msn_data *md; |
---|
| 42 | char s[1024]; |
---|
| 43 | |
---|
[0da65d5] | 44 | if( !g_slist_find( msn_connections, ic ) ) |
---|
[ba9edaa] | 45 | return FALSE; |
---|
[b7d3cc34] | 46 | |
---|
| 47 | if( source == -1 ) |
---|
| 48 | { |
---|
[84b045d] | 49 | imcb_error( ic, "Could not connect to server" ); |
---|
[c2fb3809] | 50 | imc_logout( ic, TRUE ); |
---|
[ba9edaa] | 51 | return FALSE; |
---|
[b7d3cc34] | 52 | } |
---|
| 53 | |
---|
[0da65d5] | 54 | md = ic->proto_data; |
---|
[b7d3cc34] | 55 | |
---|
| 56 | if( !md->handler ) |
---|
| 57 | { |
---|
| 58 | md->handler = g_new0( struct msn_handler_data, 1 ); |
---|
[0da65d5] | 59 | md->handler->data = ic; |
---|
[b7d3cc34] | 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 ); |
---|
[0da65d5] | 75 | if( msn_write( ic, s, strlen( s ) ) ) |
---|
[b7d3cc34] | 76 | { |
---|
[0da65d5] | 77 | ic->inpa = b_input_add( md->fd, GAIM_INPUT_READ, msn_ns_callback, ic ); |
---|
[84b045d] | 78 | imcb_log( ic, "Connected to server, waiting for reply" ); |
---|
[b7d3cc34] | 79 | } |
---|
[ba9edaa] | 80 | |
---|
| 81 | return FALSE; |
---|
[b7d3cc34] | 82 | } |
---|
| 83 | |
---|
[ba9edaa] | 84 | static gboolean msn_ns_callback( gpointer data, gint source, b_input_condition cond ) |
---|
[b7d3cc34] | 85 | { |
---|
[0da65d5] | 86 | struct im_connection *ic = data; |
---|
| 87 | struct msn_data *md = ic->proto_data; |
---|
[b7d3cc34] | 88 | |
---|
| 89 | if( msn_handler( md->handler ) == -1 ) /* Don't do this on ret == 0, it's already done then. */ |
---|
| 90 | { |
---|
[84b045d] | 91 | imcb_error( ic, "Error while reading from server" ); |
---|
[c2fb3809] | 92 | imc_logout( ic, TRUE ); |
---|
[ba9edaa] | 93 | |
---|
| 94 | return FALSE; |
---|
[b7d3cc34] | 95 | } |
---|
[ba9edaa] | 96 | else |
---|
| 97 | return TRUE; |
---|
[b7d3cc34] | 98 | } |
---|
| 99 | |
---|
| 100 | static int msn_ns_command( gpointer data, char **cmd, int num_parts ) |
---|
| 101 | { |
---|
[0da65d5] | 102 | struct im_connection *ic = data; |
---|
| 103 | struct msn_data *md = ic->proto_data; |
---|
[b7d3cc34] | 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 | { |
---|
[84b045d] | 116 | imcb_error( ic, "Unsupported protocol" ); |
---|
[c2fb3809] | 117 | imc_logout( ic, FALSE ); |
---|
[b7d3cc34] | 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", |
---|
[c2fb3809] | 122 | ++md->trId, ic->acc->user ); |
---|
[0da65d5] | 123 | return( msn_write( ic, buf, strlen( buf ) ) ); |
---|
[b7d3cc34] | 124 | } |
---|
| 125 | else if( strcmp( cmd[0], "CVR" ) == 0 ) |
---|
| 126 | { |
---|
| 127 | /* We don't give a damn about the information we just received */ |
---|
[c2fb3809] | 128 | g_snprintf( buf, sizeof( buf ), "USR %d TWN I %s\r\n", ++md->trId, ic->acc->user ); |
---|
[0da65d5] | 129 | return( msn_write( ic, buf, strlen( buf ) ) ); |
---|
[b7d3cc34] | 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 | { |
---|
[0da65d5] | 138 | b_event_remove( ic->inpa ); |
---|
| 139 | ic->inpa = 0; |
---|
[b7d3cc34] | 140 | closesocket( md->fd ); |
---|
| 141 | |
---|
| 142 | server = strchr( cmd[3], ':' ); |
---|
| 143 | if( !server ) |
---|
| 144 | { |
---|
[84b045d] | 145 | imcb_error( ic, "Syntax error" ); |
---|
[c2fb3809] | 146 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 147 | return( 0 ); |
---|
| 148 | } |
---|
| 149 | *server = 0; |
---|
| 150 | port = atoi( server + 1 ); |
---|
| 151 | server = cmd[3]; |
---|
| 152 | |
---|
[84b045d] | 153 | imcb_log( ic, "Transferring to other server" ); |
---|
[b7d3cc34] | 154 | |
---|
[0da65d5] | 155 | md->fd = proxy_connect( server, port, msn_ns_connected, ic ); |
---|
[b7d3cc34] | 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 | { |
---|
[84b045d] | 164 | imcb_error( ic, "Syntax error" ); |
---|
[c2fb3809] | 165 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 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 | { |
---|
[84b045d] | 174 | imcb_error( ic, "Unknown authentication method for switchboard" ); |
---|
[c2fb3809] | 175 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 176 | return( 0 ); |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | debug( "Connecting to a new switchboard with key %s", cmd[5] ); |
---|
[0da65d5] | 180 | sb = msn_sb_create( ic, server, port, cmd[5], MSN_SB_NEW ); |
---|
[b7d3cc34] | 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 | { |
---|
[84b045d] | 206 | imcb_error( ic, "Syntax error" ); |
---|
[c2fb3809] | 207 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 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... */ |
---|
[e6648bf] | 216 | if( !passport_get_token( msn_auth_got_passport_token, ic, ic->acc->user, ic->acc->pass, cmd[4] ) ) |
---|
[b7d3cc34] | 217 | { |
---|
[84b045d] | 218 | imcb_error( ic, "Error while contacting Passport server" ); |
---|
[c2fb3809] | 219 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 220 | return( 0 ); |
---|
| 221 | } |
---|
| 222 | } |
---|
| 223 | else if( num_parts == 7 && strcmp( cmd[2], "OK" ) == 0 ) |
---|
| 224 | { |
---|
[911f2eb] | 225 | set_t *s; |
---|
| 226 | |
---|
[b7d3cc34] | 227 | http_decode( cmd[4] ); |
---|
| 228 | |
---|
[0da65d5] | 229 | strncpy( ic->displayname, cmd[4], sizeof( ic->displayname ) ); |
---|
| 230 | ic->displayname[sizeof(ic->displayname)-1] = 0; |
---|
[b7d3cc34] | 231 | |
---|
[0da65d5] | 232 | if( ( s = set_find( &ic->acc->set, "display_name" ) ) ) |
---|
[911f2eb] | 233 | { |
---|
| 234 | g_free( s->value ); |
---|
| 235 | s->value = g_strdup( cmd[4] ); |
---|
| 236 | } |
---|
| 237 | |
---|
[84b045d] | 238 | imcb_log( ic, "Authenticated, getting buddy list" ); |
---|
[b7d3cc34] | 239 | |
---|
| 240 | g_snprintf( buf, sizeof( buf ), "SYN %d 0\r\n", ++md->trId ); |
---|
[0da65d5] | 241 | return( msn_write( ic, buf, strlen( buf ) ) ); |
---|
[b7d3cc34] | 242 | } |
---|
| 243 | else |
---|
| 244 | { |
---|
[84b045d] | 245 | imcb_error( ic, "Unknown authentication type" ); |
---|
[c2fb3809] | 246 | imc_logout( ic, FALSE ); |
---|
[b7d3cc34] | 247 | return( 0 ); |
---|
| 248 | } |
---|
| 249 | } |
---|
| 250 | else if( strcmp( cmd[0], "MSG" ) == 0 ) |
---|
| 251 | { |
---|
| 252 | if( num_parts != 4 ) |
---|
| 253 | { |
---|
[84b045d] | 254 | imcb_error( ic, "Syntax error" ); |
---|
[c2fb3809] | 255 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 256 | return( 0 ); |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | md->handler->msglen = atoi( cmd[3] ); |
---|
| 260 | |
---|
| 261 | if( md->handler->msglen <= 0 ) |
---|
| 262 | { |
---|
[84b045d] | 263 | imcb_error( ic, "Syntax error" ); |
---|
[c2fb3809] | 264 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 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] ); |
---|
[bc736cfa] | 273 | md->groupcount = atoi( cmd[4] ); |
---|
| 274 | if( md->groupcount > 0 ) |
---|
| 275 | md->grouplist = g_new0( char *, md->groupcount ); |
---|
[b7d3cc34] | 276 | |
---|
| 277 | if( !*cmd[3] || md->buddycount == 0 ) |
---|
[0da65d5] | 278 | msn_logged_in( ic ); |
---|
[b7d3cc34] | 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 | |
---|
[0da65d5] | 285 | msn_logged_in( ic ); |
---|
[b7d3cc34] | 286 | } |
---|
| 287 | } |
---|
| 288 | else if( strcmp( cmd[0], "LST" ) == 0 ) |
---|
| 289 | { |
---|
| 290 | int list; |
---|
| 291 | |
---|
| 292 | if( num_parts != 4 && num_parts != 5 ) |
---|
| 293 | { |
---|
[84b045d] | 294 | imcb_error( ic, "Syntax error" ); |
---|
[c2fb3809] | 295 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 296 | return( 0 ); |
---|
| 297 | } |
---|
| 298 | |
---|
| 299 | http_decode( cmd[2] ); |
---|
| 300 | list = atoi( cmd[3] ); |
---|
| 301 | |
---|
| 302 | if( list & 1 ) /* FL */ |
---|
| 303 | { |
---|
[1ad104a] | 304 | char *group = NULL; |
---|
| 305 | int num; |
---|
| 306 | |
---|
[f0cb961] | 307 | if( cmd[4] != NULL && sscanf( cmd[4], "%d", &num ) == 1 && num < md->groupcount ) |
---|
[1ad104a] | 308 | group = md->grouplist[num]; |
---|
| 309 | |
---|
[f0cb961] | 310 | imcb_add_buddy( ic, cmd[1], group ); |
---|
| 311 | imcb_rename_buddy( ic, cmd[1], cmd[2] ); |
---|
[b7d3cc34] | 312 | } |
---|
| 313 | if( list & 2 ) /* AL */ |
---|
| 314 | { |
---|
[0da65d5] | 315 | ic->permit = g_slist_append( ic->permit, g_strdup( cmd[1] ) ); |
---|
[b7d3cc34] | 316 | } |
---|
| 317 | if( list & 4 ) /* BL */ |
---|
| 318 | { |
---|
[0da65d5] | 319 | ic->deny = g_slist_append( ic->deny, g_strdup( cmd[1] ) ); |
---|
[b7d3cc34] | 320 | } |
---|
| 321 | if( list & 8 ) /* RL */ |
---|
| 322 | { |
---|
| 323 | if( ( list & 6 ) == 0 ) |
---|
[0da65d5] | 324 | msn_buddy_ask( ic, cmd[1], cmd[2] ); |
---|
[b7d3cc34] | 325 | } |
---|
| 326 | |
---|
| 327 | if( --md->buddycount == 0 ) |
---|
| 328 | { |
---|
[0da65d5] | 329 | if( ic->flags & OPT_LOGGED_IN ) |
---|
[b7d3cc34] | 330 | { |
---|
[84b045d] | 331 | imcb_log( ic, "Successfully transferred to different server" ); |
---|
[b7d3cc34] | 332 | g_snprintf( buf, sizeof( buf ), "CHG %d %s %d\r\n", ++md->trId, md->away_state->code, 0 ); |
---|
[0da65d5] | 333 | return( msn_write( ic, buf, strlen( buf ) ) ); |
---|
[b7d3cc34] | 334 | } |
---|
| 335 | else |
---|
| 336 | { |
---|
[0da65d5] | 337 | msn_logged_in( ic ); |
---|
[b7d3cc34] | 338 | } |
---|
| 339 | } |
---|
| 340 | } |
---|
[bc736cfa] | 341 | else if( strcmp( cmd[0], "LSG" ) == 0 ) |
---|
[b7d3cc34] | 342 | { |
---|
[bc736cfa] | 343 | int num; |
---|
| 344 | |
---|
| 345 | if( num_parts != 4 ) |
---|
| 346 | { |
---|
[84b045d] | 347 | imcb_error( ic, "Syntax error" ); |
---|
[c2fb3809] | 348 | imc_logout( ic, TRUE ); |
---|
[bc736cfa] | 349 | return( 0 ); |
---|
| 350 | } |
---|
| 351 | |
---|
| 352 | http_decode( cmd[2] ); |
---|
| 353 | num = atoi( cmd[1] ); |
---|
| 354 | |
---|
| 355 | if( num < md->groupcount ) |
---|
| 356 | md->grouplist[num] = g_strdup( cmd[2] ); |
---|
[b7d3cc34] | 357 | } |
---|
| 358 | else if( strcmp( cmd[0], "CHL" ) == 0 ) |
---|
| 359 | { |
---|
| 360 | md5_state_t state; |
---|
| 361 | md5_byte_t digest[16]; |
---|
| 362 | int i; |
---|
| 363 | |
---|
| 364 | if( num_parts != 3 ) |
---|
| 365 | { |
---|
[84b045d] | 366 | imcb_error( ic, "Syntax error" ); |
---|
[c2fb3809] | 367 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 368 | return( 0 ); |
---|
| 369 | } |
---|
| 370 | |
---|
| 371 | md5_init( &state ); |
---|
| 372 | md5_append( &state, (const md5_byte_t *) cmd[2], strlen( cmd[2] ) ); |
---|
| 373 | md5_append( &state, (const md5_byte_t *) QRY_CODE, strlen( QRY_CODE ) ); |
---|
| 374 | md5_finish( &state, digest ); |
---|
| 375 | |
---|
| 376 | g_snprintf( buf, sizeof( buf ), "QRY %d %s %d\r\n", ++md->trId, QRY_NAME, 32 ); |
---|
| 377 | for( i = 0; i < 16; i ++ ) |
---|
| 378 | g_snprintf( buf + strlen( buf ), 3, "%02x", digest[i] ); |
---|
| 379 | |
---|
[0da65d5] | 380 | return( msn_write( ic, buf, strlen( buf ) ) ); |
---|
[b7d3cc34] | 381 | } |
---|
| 382 | else if( strcmp( cmd[0], "ILN" ) == 0 ) |
---|
| 383 | { |
---|
[08995b0] | 384 | const struct msn_away_state *st; |
---|
[b7d3cc34] | 385 | |
---|
| 386 | if( num_parts != 6 ) |
---|
| 387 | { |
---|
[84b045d] | 388 | imcb_error( ic, "Syntax error" ); |
---|
[c2fb3809] | 389 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 390 | return( 0 ); |
---|
| 391 | } |
---|
| 392 | |
---|
| 393 | http_decode( cmd[4] ); |
---|
[f0cb961] | 394 | imcb_rename_buddy( ic, cmd[3], cmd[4] ); |
---|
[b7d3cc34] | 395 | |
---|
| 396 | st = msn_away_state_by_code( cmd[2] ); |
---|
| 397 | if( !st ) |
---|
| 398 | { |
---|
| 399 | /* FIXME: Warn/Bomb about unknown away state? */ |
---|
| 400 | st = msn_away_state_list; |
---|
| 401 | } |
---|
| 402 | |
---|
[6bbb939] | 403 | imcb_buddy_status( ic, cmd[3], OPT_LOGGED_IN | |
---|
| 404 | ( st->number ? OPT_AWAY : 0 ), st->name, NULL ); |
---|
[b7d3cc34] | 405 | } |
---|
| 406 | else if( strcmp( cmd[0], "FLN" ) == 0 ) |
---|
| 407 | { |
---|
| 408 | if( cmd[1] ) |
---|
[6bbb939] | 409 | imcb_buddy_status( ic, cmd[1], 0, NULL, NULL ); |
---|
[b7d3cc34] | 410 | } |
---|
| 411 | else if( strcmp( cmd[0], "NLN" ) == 0 ) |
---|
| 412 | { |
---|
[08995b0] | 413 | const struct msn_away_state *st; |
---|
[b7d3cc34] | 414 | |
---|
| 415 | if( num_parts != 5 ) |
---|
| 416 | { |
---|
[84b045d] | 417 | imcb_error( ic, "Syntax error" ); |
---|
[c2fb3809] | 418 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 419 | return( 0 ); |
---|
| 420 | } |
---|
| 421 | |
---|
| 422 | http_decode( cmd[3] ); |
---|
[f0cb961] | 423 | imcb_rename_buddy( ic, cmd[2], cmd[3] ); |
---|
[b7d3cc34] | 424 | |
---|
| 425 | st = msn_away_state_by_code( cmd[1] ); |
---|
| 426 | if( !st ) |
---|
| 427 | { |
---|
| 428 | /* FIXME: Warn/Bomb about unknown away state? */ |
---|
| 429 | st = msn_away_state_list; |
---|
| 430 | } |
---|
| 431 | |
---|
[6bbb939] | 432 | imcb_buddy_status( ic, cmd[2], OPT_LOGGED_IN | |
---|
| 433 | ( st->number ? OPT_AWAY : 0 ), st->name, NULL ); |
---|
[b7d3cc34] | 434 | } |
---|
| 435 | else if( strcmp( cmd[0], "RNG" ) == 0 ) |
---|
| 436 | { |
---|
| 437 | struct msn_switchboard *sb; |
---|
| 438 | char *server; |
---|
| 439 | int session, port; |
---|
| 440 | |
---|
| 441 | if( num_parts != 7 ) |
---|
| 442 | { |
---|
[84b045d] | 443 | imcb_error( ic, "Syntax error" ); |
---|
[c2fb3809] | 444 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 445 | return( 0 ); |
---|
| 446 | } |
---|
| 447 | |
---|
| 448 | session = atoi( cmd[1] ); |
---|
| 449 | |
---|
| 450 | server = strchr( cmd[2], ':' ); |
---|
| 451 | if( !server ) |
---|
| 452 | { |
---|
[84b045d] | 453 | imcb_error( ic, "Syntax error" ); |
---|
[c2fb3809] | 454 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 455 | return( 0 ); |
---|
| 456 | } |
---|
| 457 | *server = 0; |
---|
| 458 | port = atoi( server + 1 ); |
---|
| 459 | server = cmd[2]; |
---|
| 460 | |
---|
| 461 | if( strcmp( cmd[3], "CKI" ) != 0 ) |
---|
| 462 | { |
---|
[84b045d] | 463 | imcb_error( ic, "Unknown authentication method for switchboard" ); |
---|
[c2fb3809] | 464 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 465 | return( 0 ); |
---|
| 466 | } |
---|
| 467 | |
---|
| 468 | debug( "Got a call from %s (session %d). Key = %s", cmd[5], session, cmd[4] ); |
---|
| 469 | |
---|
[0da65d5] | 470 | sb = msn_sb_create( ic, server, port, cmd[4], session ); |
---|
[b7d3cc34] | 471 | sb->who = g_strdup( cmd[5] ); |
---|
| 472 | } |
---|
| 473 | else if( strcmp( cmd[0], "ADD" ) == 0 ) |
---|
| 474 | { |
---|
| 475 | if( num_parts == 6 && strcmp( cmd[2], "RL" ) == 0 ) |
---|
| 476 | { |
---|
| 477 | GSList *l; |
---|
| 478 | |
---|
| 479 | http_decode( cmd[5] ); |
---|
| 480 | |
---|
| 481 | if( strchr( cmd[4], '@' ) == NULL ) |
---|
| 482 | { |
---|
[84b045d] | 483 | imcb_error( ic, "Syntax error" ); |
---|
[c2fb3809] | 484 | imc_logout( ic, TRUE ); |
---|
[f0cb961] | 485 | return 0; |
---|
[b7d3cc34] | 486 | } |
---|
| 487 | |
---|
[f0cb961] | 488 | /* We got added by someone. If we don't have this |
---|
| 489 | person in permit/deny yet, inform the user. */ |
---|
[0da65d5] | 490 | for( l = ic->permit; l; l = l->next ) |
---|
[b7d3cc34] | 491 | if( g_strcasecmp( l->data, cmd[4] ) == 0 ) |
---|
[f0cb961] | 492 | return 1; |
---|
[b7d3cc34] | 493 | |
---|
[0da65d5] | 494 | for( l = ic->deny; l; l = l->next ) |
---|
[b7d3cc34] | 495 | if( g_strcasecmp( l->data, cmd[4] ) == 0 ) |
---|
[f0cb961] | 496 | return 1; |
---|
[b7d3cc34] | 497 | |
---|
[0da65d5] | 498 | msn_buddy_ask( ic, cmd[4], cmd[5] ); |
---|
[b7d3cc34] | 499 | } |
---|
[f0cb961] | 500 | else if( num_parts >= 6 && strcmp( cmd[2], "FL" ) == 0 ) |
---|
| 501 | { |
---|
| 502 | http_decode( cmd[5] ); |
---|
| 503 | imcb_add_buddy( ic, cmd[4], NULL ); |
---|
| 504 | imcb_rename_buddy( ic, cmd[4], cmd[5] ); |
---|
| 505 | } |
---|
[b7d3cc34] | 506 | } |
---|
| 507 | else if( strcmp( cmd[0], "OUT" ) == 0 ) |
---|
| 508 | { |
---|
[c2fb3809] | 509 | int allow_reconnect = TRUE; |
---|
| 510 | |
---|
[b7d3cc34] | 511 | if( cmd[1] && strcmp( cmd[1], "OTH" ) == 0 ) |
---|
| 512 | { |
---|
[84b045d] | 513 | imcb_error( ic, "Someone else logged in with your account" ); |
---|
[c2fb3809] | 514 | allow_reconnect = FALSE; |
---|
[b7d3cc34] | 515 | } |
---|
| 516 | else if( cmd[1] && strcmp( cmd[1], "SSD" ) == 0 ) |
---|
| 517 | { |
---|
[84b045d] | 518 | imcb_error( ic, "Terminating session because of server shutdown" ); |
---|
[b7d3cc34] | 519 | } |
---|
| 520 | else |
---|
| 521 | { |
---|
[84b045d] | 522 | imcb_error( ic, "Session terminated by remote server (reason unknown)" ); |
---|
[b7d3cc34] | 523 | } |
---|
| 524 | |
---|
[c2fb3809] | 525 | imc_logout( ic, allow_reconnect ); |
---|
[b7d3cc34] | 526 | return( 0 ); |
---|
| 527 | } |
---|
| 528 | else if( strcmp( cmd[0], "REA" ) == 0 ) |
---|
| 529 | { |
---|
| 530 | if( num_parts != 5 ) |
---|
| 531 | { |
---|
[84b045d] | 532 | imcb_error( ic, "Syntax error" ); |
---|
[c2fb3809] | 533 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 534 | return( 0 ); |
---|
| 535 | } |
---|
| 536 | |
---|
[c2fb3809] | 537 | if( g_strcasecmp( cmd[3], ic->acc->user ) == 0 ) |
---|
[b7d3cc34] | 538 | { |
---|
[911f2eb] | 539 | set_t *s; |
---|
| 540 | |
---|
[b7d3cc34] | 541 | http_decode( cmd[4] ); |
---|
[0da65d5] | 542 | strncpy( ic->displayname, cmd[4], sizeof( ic->displayname ) ); |
---|
| 543 | ic->displayname[sizeof(ic->displayname)-1] = 0; |
---|
[911f2eb] | 544 | |
---|
[0da65d5] | 545 | if( ( s = set_find( &ic->acc->set, "display_name" ) ) ) |
---|
[911f2eb] | 546 | { |
---|
| 547 | g_free( s->value ); |
---|
| 548 | s->value = g_strdup( cmd[4] ); |
---|
| 549 | } |
---|
[b7d3cc34] | 550 | } |
---|
| 551 | else |
---|
| 552 | { |
---|
| 553 | /* This is not supposed to happen, but let's handle it anyway... */ |
---|
| 554 | http_decode( cmd[4] ); |
---|
[f0cb961] | 555 | imcb_rename_buddy( ic, cmd[3], cmd[4] ); |
---|
[b7d3cc34] | 556 | } |
---|
| 557 | } |
---|
| 558 | else if( strcmp( cmd[0], "IPG" ) == 0 ) |
---|
| 559 | { |
---|
[84b045d] | 560 | imcb_error( ic, "Received IPG command, we don't handle them yet." ); |
---|
[b7d3cc34] | 561 | |
---|
| 562 | md->handler->msglen = atoi( cmd[1] ); |
---|
| 563 | |
---|
| 564 | if( md->handler->msglen <= 0 ) |
---|
| 565 | { |
---|
[84b045d] | 566 | imcb_error( ic, "Syntax error" ); |
---|
[c2fb3809] | 567 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 568 | return( 0 ); |
---|
| 569 | } |
---|
| 570 | } |
---|
| 571 | else if( isdigit( cmd[0][0] ) ) |
---|
| 572 | { |
---|
| 573 | int num = atoi( cmd[0] ); |
---|
[08995b0] | 574 | const struct msn_status_code *err = msn_status_by_number( num ); |
---|
[b7d3cc34] | 575 | |
---|
[84b045d] | 576 | imcb_error( ic, "Error reported by MSN server: %s", err->text ); |
---|
[b7d3cc34] | 577 | |
---|
| 578 | if( err->flags & STATUS_FATAL ) |
---|
| 579 | { |
---|
[c2fb3809] | 580 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 581 | return( 0 ); |
---|
| 582 | } |
---|
| 583 | } |
---|
| 584 | else |
---|
| 585 | { |
---|
[8ff0a61] | 586 | /* debug( "Received unknown command from main server: %s", cmd[0] ); */ |
---|
[b7d3cc34] | 587 | } |
---|
| 588 | |
---|
| 589 | return( 1 ); |
---|
| 590 | } |
---|
| 591 | |
---|
| 592 | static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int num_parts ) |
---|
| 593 | { |
---|
[0da65d5] | 594 | struct im_connection *ic = data; |
---|
[b7d3cc34] | 595 | char *body; |
---|
| 596 | int blen = 0; |
---|
| 597 | |
---|
| 598 | if( !num_parts ) |
---|
| 599 | return( 1 ); |
---|
| 600 | |
---|
| 601 | if( ( body = strstr( msg, "\r\n\r\n" ) ) ) |
---|
| 602 | { |
---|
| 603 | body += 4; |
---|
| 604 | blen = msglen - ( body - msg ); |
---|
| 605 | } |
---|
| 606 | |
---|
| 607 | if( strcmp( cmd[0], "MSG" ) == 0 ) |
---|
| 608 | { |
---|
| 609 | if( g_strcasecmp( cmd[1], "Hotmail" ) == 0 ) |
---|
| 610 | { |
---|
| 611 | char *ct = msn_findheader( msg, "Content-Type:", msglen ); |
---|
| 612 | |
---|
| 613 | if( !ct ) |
---|
| 614 | return( 1 ); |
---|
| 615 | |
---|
| 616 | if( g_strncasecmp( ct, "application/x-msmsgssystemmessage", 33 ) == 0 ) |
---|
| 617 | { |
---|
| 618 | char *mtype; |
---|
| 619 | char *arg1; |
---|
| 620 | |
---|
| 621 | if( !body ) |
---|
| 622 | return( 1 ); |
---|
| 623 | |
---|
| 624 | mtype = msn_findheader( body, "Type:", blen ); |
---|
| 625 | arg1 = msn_findheader( body, "Arg1:", blen ); |
---|
| 626 | |
---|
| 627 | if( mtype && strcmp( mtype, "1" ) == 0 ) |
---|
| 628 | { |
---|
| 629 | if( arg1 ) |
---|
[84b045d] | 630 | imcb_log( ic, "The server is going down for maintenance in %s minutes.", arg1 ); |
---|
[b7d3cc34] | 631 | } |
---|
| 632 | |
---|
| 633 | if( arg1 ) g_free( arg1 ); |
---|
| 634 | if( mtype ) g_free( mtype ); |
---|
| 635 | } |
---|
| 636 | else if( g_strncasecmp( ct, "text/x-msmsgsprofile", 20 ) == 0 ) |
---|
| 637 | { |
---|
| 638 | /* We don't care about this profile for now... */ |
---|
| 639 | } |
---|
| 640 | else if( g_strncasecmp( ct, "text/x-msmsgsinitialemailnotification", 37 ) == 0 ) |
---|
| 641 | { |
---|
| 642 | char *inbox = msn_findheader( body, "Inbox-Unread:", blen ); |
---|
| 643 | char *folders = msn_findheader( body, "Folders-Unread:", blen ); |
---|
| 644 | |
---|
[1febf5c] | 645 | if( inbox && folders && set_getbool( &ic->acc->set, "mail_notifications" ) ) |
---|
[b7d3cc34] | 646 | { |
---|
[84b045d] | 647 | imcb_log( ic, "INBOX contains %s new messages, plus %s messages in other folders.", inbox, folders ); |
---|
[b7d3cc34] | 648 | } |
---|
| 649 | } |
---|
| 650 | else if( g_strncasecmp( ct, "text/x-msmsgsemailnotification", 30 ) == 0 ) |
---|
| 651 | { |
---|
| 652 | char *from = msn_findheader( body, "From-Addr:", blen ); |
---|
| 653 | char *fromname = msn_findheader( body, "From:", blen ); |
---|
| 654 | |
---|
[1febf5c] | 655 | if( from && fromname && set_getbool( &ic->acc->set, "mail_notifications" ) ) |
---|
[b7d3cc34] | 656 | { |
---|
[84b045d] | 657 | imcb_log( ic, "Received an e-mail message from %s <%s>.", fromname, from ); |
---|
[b7d3cc34] | 658 | } |
---|
| 659 | } |
---|
| 660 | else if( g_strncasecmp( ct, "text/x-msmsgsactivemailnotification", 35 ) == 0 ) |
---|
| 661 | { |
---|
| 662 | /* Sorry, but this one really is *USELESS* */ |
---|
| 663 | } |
---|
| 664 | else |
---|
| 665 | { |
---|
| 666 | debug( "Can't handle %s packet from notification server", ct ); |
---|
| 667 | } |
---|
| 668 | |
---|
| 669 | g_free( ct ); |
---|
| 670 | } |
---|
| 671 | } |
---|
| 672 | |
---|
| 673 | return( 1 ); |
---|
| 674 | } |
---|
| 675 | |
---|
[e6648bf] | 676 | static void msn_auth_got_passport_token( struct msn_auth_data *mad ) |
---|
[b7d3cc34] | 677 | { |
---|
[e6648bf] | 678 | struct im_connection *ic = mad->data; |
---|
| 679 | struct msn_data *md; |
---|
[b7d3cc34] | 680 | |
---|
[e6648bf] | 681 | /* Dead connection? */ |
---|
| 682 | if( g_slist_find( msn_connections, ic ) == NULL ) |
---|
| 683 | return; |
---|
| 684 | |
---|
| 685 | md = ic->proto_data; |
---|
| 686 | if( mad->token ) |
---|
[b7d3cc34] | 687 | { |
---|
[e6648bf] | 688 | char buf[1024]; |
---|
| 689 | |
---|
| 690 | g_snprintf( buf, sizeof( buf ), "USR %d TWN S %s\r\n", ++md->trId, mad->token ); |
---|
| 691 | msn_write( ic, buf, strlen( buf ) ); |
---|
[b7d3cc34] | 692 | } |
---|
| 693 | else |
---|
| 694 | { |
---|
[e6648bf] | 695 | imcb_error( ic, "Error during Passport authentication: %s", mad->error ); |
---|
| 696 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 697 | } |
---|
| 698 | } |
---|