[b7d3cc34] | 1 | /********************************************************************\ |
---|
| 2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
| 3 | * * |
---|
[f9258ae] | 4 | * Copyright 2002-2012 Wilmer van der Gaast and others * |
---|
[b7d3cc34] | 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> |
---|
[f9258ae] | 27 | #include <sys/utsname.h> |
---|
[b7d3cc34] | 28 | #include "nogaim.h" |
---|
| 29 | #include "msn.h" |
---|
| 30 | #include "md5.h" |
---|
[f9258ae] | 31 | #include "sha1.h" |
---|
[7db65b7] | 32 | #include "soap.h" |
---|
[ca7de3a] | 33 | #include "xmltree.h" |
---|
[b7d3cc34] | 34 | |
---|
[bae0617] | 35 | static gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ); |
---|
[ba9edaa] | 36 | static gboolean msn_ns_callback( gpointer data, gint source, b_input_condition cond ); |
---|
[bae0617] | 37 | static int msn_ns_command( struct msn_handler_data *handler, char **cmd, int num_parts ); |
---|
| 38 | static int msn_ns_message( struct msn_handler_data *handler, char *msg, int msglen, char **cmd, int num_parts ); |
---|
[b7d3cc34] | 39 | |
---|
[5a7af1b] | 40 | static void msn_ns_send_adl_start( struct im_connection *ic ); |
---|
[ca7de3a] | 41 | static void msn_ns_send_adl( struct im_connection *ic ); |
---|
[b7d3cc34] | 42 | |
---|
[64768d4] | 43 | int msn_ns_write( struct im_connection *ic, int fd, const char *fmt, ... ) |
---|
| 44 | { |
---|
| 45 | struct msn_data *md = ic->proto_data; |
---|
| 46 | va_list params; |
---|
| 47 | char *out; |
---|
| 48 | size_t len; |
---|
| 49 | int st; |
---|
| 50 | |
---|
| 51 | va_start( params, fmt ); |
---|
| 52 | out = g_strdup_vprintf( fmt, params ); |
---|
| 53 | va_end( params ); |
---|
| 54 | |
---|
| 55 | if( fd < 0 ) |
---|
[bae0617] | 56 | fd = md->ns->fd; |
---|
[64768d4] | 57 | |
---|
| 58 | if( getenv( "BITLBEE_DEBUG" ) ) |
---|
[eb54f56] | 59 | fprintf( stderr, "->NS%d:%s\n", fd, out ); |
---|
[64768d4] | 60 | |
---|
| 61 | len = strlen( out ); |
---|
| 62 | st = write( fd, out, len ); |
---|
| 63 | g_free( out ); |
---|
| 64 | if( st != len ) |
---|
| 65 | { |
---|
| 66 | imcb_error( ic, "Short write() to main server" ); |
---|
| 67 | imc_logout( ic, TRUE ); |
---|
| 68 | return 0; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | return 1; |
---|
| 72 | } |
---|
| 73 | |
---|
[bae0617] | 74 | gboolean msn_ns_connect( struct im_connection *ic, struct msn_handler_data *handler, const char *host, int port ) |
---|
[b7d3cc34] | 75 | { |
---|
[bae0617] | 76 | if( handler->fd >= 0 ) |
---|
| 77 | closesocket( handler->fd ); |
---|
[b7d3cc34] | 78 | |
---|
[bae0617] | 79 | handler->exec_command = msn_ns_command; |
---|
| 80 | handler->exec_message = msn_ns_message; |
---|
| 81 | handler->data = ic; |
---|
| 82 | handler->fd = proxy_connect( host, port, msn_ns_connected, handler ); |
---|
| 83 | if( handler->fd < 0 ) |
---|
[b7d3cc34] | 84 | { |
---|
[84b045d] | 85 | imcb_error( ic, "Could not connect to server" ); |
---|
[c2fb3809] | 86 | imc_logout( ic, TRUE ); |
---|
[ba9edaa] | 87 | return FALSE; |
---|
[b7d3cc34] | 88 | } |
---|
| 89 | |
---|
[bae0617] | 90 | return TRUE; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | static gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ) |
---|
| 94 | { |
---|
| 95 | struct msn_handler_data *handler = data; |
---|
| 96 | struct im_connection *ic = handler->data; |
---|
| 97 | struct msn_data *md; |
---|
| 98 | |
---|
| 99 | if( !g_slist_find( msn_connections, ic ) ) |
---|
| 100 | return FALSE; |
---|
| 101 | |
---|
[0da65d5] | 102 | md = ic->proto_data; |
---|
[b7d3cc34] | 103 | |
---|
[bae0617] | 104 | if( source == -1 ) |
---|
[b7d3cc34] | 105 | { |
---|
[bae0617] | 106 | imcb_error( ic, "Could not connect to server" ); |
---|
| 107 | imc_logout( ic, TRUE ); |
---|
| 108 | return FALSE; |
---|
[b7d3cc34] | 109 | } |
---|
| 110 | |
---|
[bae0617] | 111 | g_free( handler->rxq ); |
---|
| 112 | handler->rxlen = 0; |
---|
| 113 | handler->rxq = g_new0( char, 1 ); |
---|
[b7d3cc34] | 114 | |
---|
[f9258ae] | 115 | if( md->uuid == NULL ) |
---|
| 116 | { |
---|
| 117 | struct utsname name; |
---|
| 118 | sha1_state_t sha[1]; |
---|
| 119 | |
---|
| 120 | /* UUID == SHA1("BitlBee" + my hostname + MSN username) */ |
---|
| 121 | sha1_init( sha ); |
---|
| 122 | sha1_append( sha, (void*) "BitlBee", 7 ); |
---|
| 123 | if( uname( &name ) == 0 ) |
---|
| 124 | { |
---|
| 125 | sha1_append( sha, (void*) name.nodename, strlen( name.nodename ) ); |
---|
| 126 | } |
---|
| 127 | sha1_append( sha, (void*) ic->acc->user, strlen( ic->acc->user ) ); |
---|
| 128 | md->uuid = sha1_random_uuid( sha ); |
---|
| 129 | memcpy( md->uuid, "b171be3e", 8 ); /* :-P */ |
---|
| 130 | } |
---|
| 131 | |
---|
[4aa8a04] | 132 | if( msn_ns_write( ic, source, "VER %d %s CVR0\r\n", ++md->trId, MSNP_VER ) ) |
---|
[b7d3cc34] | 133 | { |
---|
[bae0617] | 134 | handler->inpa = b_input_add( handler->fd, B_EV_IO_READ, msn_ns_callback, handler ); |
---|
[84b045d] | 135 | imcb_log( ic, "Connected to server, waiting for reply" ); |
---|
[b7d3cc34] | 136 | } |
---|
[ba9edaa] | 137 | |
---|
| 138 | return FALSE; |
---|
[b7d3cc34] | 139 | } |
---|
| 140 | |
---|
[bae0617] | 141 | void msn_ns_close( struct msn_handler_data *handler ) |
---|
| 142 | { |
---|
| 143 | if( handler->fd >= 0 ) |
---|
| 144 | { |
---|
| 145 | closesocket( handler->fd ); |
---|
| 146 | b_event_remove( handler->inpa ); |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | handler->fd = handler->inpa = -1; |
---|
| 150 | g_free( handler->rxq ); |
---|
| 151 | g_free( handler->cmd_text ); |
---|
| 152 | |
---|
| 153 | handler->rxlen = 0; |
---|
| 154 | handler->rxq = NULL; |
---|
| 155 | handler->cmd_text = NULL; |
---|
| 156 | } |
---|
| 157 | |
---|
[ba9edaa] | 158 | static gboolean msn_ns_callback( gpointer data, gint source, b_input_condition cond ) |
---|
[b7d3cc34] | 159 | { |
---|
[bae0617] | 160 | struct msn_handler_data *handler = data; |
---|
| 161 | struct im_connection *ic = handler->data; |
---|
[b7d3cc34] | 162 | |
---|
[bae0617] | 163 | if( msn_handler( handler ) == -1 ) /* Don't do this on ret == 0, it's already done then. */ |
---|
[b7d3cc34] | 164 | { |
---|
[84b045d] | 165 | imcb_error( ic, "Error while reading from server" ); |
---|
[c2fb3809] | 166 | imc_logout( ic, TRUE ); |
---|
[ba9edaa] | 167 | |
---|
| 168 | return FALSE; |
---|
[b7d3cc34] | 169 | } |
---|
[ba9edaa] | 170 | else |
---|
| 171 | return TRUE; |
---|
[b7d3cc34] | 172 | } |
---|
| 173 | |
---|
[bae0617] | 174 | static int msn_ns_command( struct msn_handler_data *handler, char **cmd, int num_parts ) |
---|
[b7d3cc34] | 175 | { |
---|
[bae0617] | 176 | struct im_connection *ic = handler->data; |
---|
[0da65d5] | 177 | struct msn_data *md = ic->proto_data; |
---|
[b7d3cc34] | 178 | |
---|
| 179 | if( num_parts == 0 ) |
---|
| 180 | { |
---|
| 181 | /* Hrrm... Empty command...? Ignore? */ |
---|
| 182 | return( 1 ); |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | if( strcmp( cmd[0], "VER" ) == 0 ) |
---|
| 186 | { |
---|
[91d6e91] | 187 | if( cmd[2] && strncmp( cmd[2], MSNP_VER, 5 ) != 0 ) |
---|
[b7d3cc34] | 188 | { |
---|
[84b045d] | 189 | imcb_error( ic, "Unsupported protocol" ); |
---|
[c2fb3809] | 190 | imc_logout( ic, FALSE ); |
---|
[b7d3cc34] | 191 | return( 0 ); |
---|
| 192 | } |
---|
| 193 | |
---|
[4aa8a04] | 194 | return( msn_ns_write( ic, handler->fd, "CVR %d 0x0409 mac 10.2.0 ppc macmsgs 3.5.1 macmsgs %s\r\n", |
---|
[64768d4] | 195 | ++md->trId, ic->acc->user ) ); |
---|
[b7d3cc34] | 196 | } |
---|
| 197 | else if( strcmp( cmd[0], "CVR" ) == 0 ) |
---|
| 198 | { |
---|
| 199 | /* We don't give a damn about the information we just received */ |
---|
[4aa8a04] | 200 | return msn_ns_write( ic, handler->fd, "USR %d SSO I %s\r\n", ++md->trId, ic->acc->user ); |
---|
[b7d3cc34] | 201 | } |
---|
| 202 | else if( strcmp( cmd[0], "XFR" ) == 0 ) |
---|
| 203 | { |
---|
| 204 | char *server; |
---|
| 205 | int port; |
---|
| 206 | |
---|
[ca7de3a] | 207 | if( num_parts >= 6 && strcmp( cmd[2], "NS" ) == 0 ) |
---|
[b7d3cc34] | 208 | { |
---|
[bae0617] | 209 | b_event_remove( handler->inpa ); |
---|
| 210 | handler->inpa = -1; |
---|
[b7d3cc34] | 211 | |
---|
| 212 | server = strchr( cmd[3], ':' ); |
---|
| 213 | if( !server ) |
---|
| 214 | { |
---|
[84b045d] | 215 | imcb_error( ic, "Syntax error" ); |
---|
[c2fb3809] | 216 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 217 | return( 0 ); |
---|
| 218 | } |
---|
| 219 | *server = 0; |
---|
| 220 | port = atoi( server + 1 ); |
---|
| 221 | server = cmd[3]; |
---|
| 222 | |
---|
[84b045d] | 223 | imcb_log( ic, "Transferring to other server" ); |
---|
[bae0617] | 224 | return msn_ns_connect( ic, handler, server, port ); |
---|
[b7d3cc34] | 225 | } |
---|
[ca7de3a] | 226 | else if( num_parts >= 6 && strcmp( cmd[2], "SB" ) == 0 ) |
---|
[b7d3cc34] | 227 | { |
---|
| 228 | struct msn_switchboard *sb; |
---|
| 229 | |
---|
| 230 | server = strchr( cmd[3], ':' ); |
---|
| 231 | if( !server ) |
---|
| 232 | { |
---|
[84b045d] | 233 | imcb_error( ic, "Syntax error" ); |
---|
[c2fb3809] | 234 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 235 | return( 0 ); |
---|
| 236 | } |
---|
| 237 | *server = 0; |
---|
| 238 | port = atoi( server + 1 ); |
---|
| 239 | server = cmd[3]; |
---|
| 240 | |
---|
| 241 | if( strcmp( cmd[4], "CKI" ) != 0 ) |
---|
| 242 | { |
---|
[84b045d] | 243 | imcb_error( ic, "Unknown authentication method for switchboard" ); |
---|
[c2fb3809] | 244 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 245 | return( 0 ); |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | debug( "Connecting to a new switchboard with key %s", cmd[5] ); |
---|
[99f929c] | 249 | |
---|
| 250 | if( ( sb = msn_sb_create( ic, server, port, cmd[5], MSN_SB_NEW ) ) == NULL ) |
---|
| 251 | { |
---|
| 252 | /* Although this isn't strictly fatal for the NS connection, it's |
---|
| 253 | definitely something serious (we ran out of file descriptors?). */ |
---|
| 254 | imcb_error( ic, "Could not create new switchboard" ); |
---|
| 255 | imc_logout( ic, TRUE ); |
---|
| 256 | return( 0 ); |
---|
| 257 | } |
---|
[b7d3cc34] | 258 | |
---|
| 259 | if( md->msgq ) |
---|
| 260 | { |
---|
| 261 | struct msn_message *m = md->msgq->data; |
---|
| 262 | GSList *l; |
---|
| 263 | |
---|
| 264 | sb->who = g_strdup( m->who ); |
---|
| 265 | |
---|
| 266 | /* Move all the messages to the first user in the message |
---|
| 267 | queue to the switchboard message queue. */ |
---|
| 268 | l = md->msgq; |
---|
| 269 | while( l ) |
---|
| 270 | { |
---|
| 271 | m = l->data; |
---|
| 272 | l = l->next; |
---|
| 273 | if( strcmp( m->who, sb->who ) == 0 ) |
---|
| 274 | { |
---|
| 275 | sb->msgq = g_slist_append( sb->msgq, m ); |
---|
| 276 | md->msgq = g_slist_remove( md->msgq, m ); |
---|
| 277 | } |
---|
| 278 | } |
---|
| 279 | } |
---|
| 280 | } |
---|
| 281 | else |
---|
| 282 | { |
---|
[84b045d] | 283 | imcb_error( ic, "Syntax error" ); |
---|
[c2fb3809] | 284 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 285 | return( 0 ); |
---|
| 286 | } |
---|
| 287 | } |
---|
| 288 | else if( strcmp( cmd[0], "USR" ) == 0 ) |
---|
| 289 | { |
---|
[523fb23] | 290 | if( num_parts >= 6 && strcmp( cmd[2], "SSO" ) == 0 && |
---|
| 291 | strcmp( cmd[3], "S" ) == 0 ) |
---|
[b7d3cc34] | 292 | { |
---|
[4aa8a04] | 293 | g_free( md->pp_policy ); |
---|
| 294 | md->pp_policy = g_strdup( cmd[4] ); |
---|
| 295 | msn_soap_passport_sso_request( ic, cmd[5] ); |
---|
[b7d3cc34] | 296 | } |
---|
[5fecede] | 297 | else if( strcmp( cmd[2], "OK" ) == 0 ) |
---|
[b7d3cc34] | 298 | { |
---|
[ed0589c] | 299 | /* If the number after the handle is 0, the e-mail |
---|
| 300 | address is unverified, which means we can't change |
---|
| 301 | the display name. */ |
---|
| 302 | if( cmd[4][0] == '0' ) |
---|
| 303 | md->flags |= MSN_EMAIL_UNVERIFIED; |
---|
| 304 | |
---|
[84b045d] | 305 | imcb_log( ic, "Authenticated, getting buddy list" ); |
---|
[7db65b7] | 306 | msn_soap_memlist_request( ic ); |
---|
[b7d3cc34] | 307 | } |
---|
| 308 | else |
---|
| 309 | { |
---|
[84b045d] | 310 | imcb_error( ic, "Unknown authentication type" ); |
---|
[c2fb3809] | 311 | imc_logout( ic, FALSE ); |
---|
[b7d3cc34] | 312 | return( 0 ); |
---|
| 313 | } |
---|
| 314 | } |
---|
| 315 | else if( strcmp( cmd[0], "MSG" ) == 0 ) |
---|
| 316 | { |
---|
[b46769d] | 317 | if( num_parts < 4 ) |
---|
[b7d3cc34] | 318 | { |
---|
[84b045d] | 319 | imcb_error( ic, "Syntax error" ); |
---|
[c2fb3809] | 320 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 321 | return( 0 ); |
---|
| 322 | } |
---|
| 323 | |
---|
[bae0617] | 324 | handler->msglen = atoi( cmd[3] ); |
---|
[b7d3cc34] | 325 | |
---|
[bae0617] | 326 | if( handler->msglen <= 0 ) |
---|
[b7d3cc34] | 327 | { |
---|
[84b045d] | 328 | imcb_error( ic, "Syntax error" ); |
---|
[c2fb3809] | 329 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 330 | return( 0 ); |
---|
| 331 | } |
---|
| 332 | } |
---|
[ca7de3a] | 333 | else if( strcmp( cmd[0], "BLP" ) == 0 ) |
---|
[b7d3cc34] | 334 | { |
---|
[5a7af1b] | 335 | msn_ns_send_adl_start( ic ); |
---|
[80175a1] | 336 | return msn_ns_finish_login( ic ); |
---|
[b7d3cc34] | 337 | } |
---|
[ca7de3a] | 338 | else if( strcmp( cmd[0], "ADL" ) == 0 ) |
---|
[b7d3cc34] | 339 | { |
---|
[ca7de3a] | 340 | if( num_parts >= 3 && strcmp( cmd[2], "OK" ) == 0 ) |
---|
[b7d3cc34] | 341 | { |
---|
[5a7af1b] | 342 | msn_ns_send_adl( ic ); |
---|
[80175a1] | 343 | return msn_ns_finish_login( ic ); |
---|
[b7d3cc34] | 344 | } |
---|
[e5854a8] | 345 | else if( num_parts >= 3 ) |
---|
| 346 | { |
---|
[bae0617] | 347 | handler->msglen = atoi( cmd[2] ); |
---|
[e5854a8] | 348 | } |
---|
[b7d3cc34] | 349 | } |
---|
[ca7de3a] | 350 | else if( strcmp( cmd[0], "PRP" ) == 0 ) |
---|
[b7d3cc34] | 351 | { |
---|
[ca7de3a] | 352 | imcb_connected( ic ); |
---|
[b7d3cc34] | 353 | } |
---|
| 354 | else if( strcmp( cmd[0], "CHL" ) == 0 ) |
---|
| 355 | { |
---|
[be7a180] | 356 | char *resp; |
---|
[64768d4] | 357 | int st; |
---|
[b7d3cc34] | 358 | |
---|
[be7a180] | 359 | if( num_parts < 3 ) |
---|
[b7d3cc34] | 360 | { |
---|
[84b045d] | 361 | imcb_error( ic, "Syntax error" ); |
---|
[c2fb3809] | 362 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 363 | return( 0 ); |
---|
| 364 | } |
---|
| 365 | |
---|
[be7a180] | 366 | resp = msn_p11_challenge( cmd[2] ); |
---|
[b7d3cc34] | 367 | |
---|
[64768d4] | 368 | st = msn_ns_write( ic, -1, "QRY %d %s %zd\r\n%s", |
---|
| 369 | ++md->trId, MSNP11_PROD_ID, |
---|
| 370 | strlen( resp ), resp ); |
---|
| 371 | g_free( resp ); |
---|
| 372 | return st; |
---|
[b7d3cc34] | 373 | } |
---|
[79bb7e4] | 374 | else if( strcmp( cmd[0], "ILN" ) == 0 || strcmp( cmd[0], "NLN" ) == 0 ) |
---|
[b7d3cc34] | 375 | { |
---|
[08995b0] | 376 | const struct msn_away_state *st; |
---|
[79bb7e4] | 377 | const char *handle; |
---|
| 378 | int cap = 0; |
---|
[b7d3cc34] | 379 | |
---|
[ca7de3a] | 380 | if( num_parts < 6 ) |
---|
[b7d3cc34] | 381 | { |
---|
[84b045d] | 382 | imcb_error( ic, "Syntax error" ); |
---|
[c2fb3809] | 383 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 384 | return( 0 ); |
---|
| 385 | } |
---|
[79bb7e4] | 386 | /* ILN and NLN are more or less the same, except ILN has a trId |
---|
| 387 | at the start, and NLN has a capability field at the end. |
---|
| 388 | Does ILN still exist BTW? */ |
---|
| 389 | if( cmd[0][1] == 'I' ) |
---|
| 390 | cmd ++; |
---|
| 391 | else |
---|
| 392 | cap = atoi( cmd[4] ); |
---|
| 393 | |
---|
| 394 | handle = msn_normalize_handle( cmd[2] ); |
---|
| 395 | if( strcmp( handle, ic->acc->user ) == 0 ) |
---|
| 396 | return 1; /* That's me! */ |
---|
[b7d3cc34] | 397 | |
---|
[79bb7e4] | 398 | http_decode( cmd[3] ); |
---|
| 399 | imcb_rename_buddy( ic, handle, cmd[3] ); |
---|
[b7d3cc34] | 400 | |
---|
[79bb7e4] | 401 | st = msn_away_state_by_code( cmd[1] ); |
---|
[b7d3cc34] | 402 | if( !st ) |
---|
| 403 | { |
---|
| 404 | /* FIXME: Warn/Bomb about unknown away state? */ |
---|
[b051d39] | 405 | st = msn_away_state_list + 1; |
---|
[b7d3cc34] | 406 | } |
---|
| 407 | |
---|
[79bb7e4] | 408 | imcb_buddy_status( ic, handle, OPT_LOGGED_IN | |
---|
| 409 | ( st != msn_away_state_list ? OPT_AWAY : 0 ) | |
---|
| 410 | ( cap & 1 ? OPT_MOBILE : 0 ), |
---|
[b051d39] | 411 | st->name, NULL ); |
---|
[79bb7e4] | 412 | |
---|
| 413 | msn_sb_stop_keepalives( msn_sb_by_handle( ic, handle ) ); |
---|
[b7d3cc34] | 414 | } |
---|
| 415 | else if( strcmp( cmd[0], "FLN" ) == 0 ) |
---|
| 416 | { |
---|
[79bb7e4] | 417 | const char *handle; |
---|
| 418 | |
---|
[9bf2481] | 419 | if( cmd[1] == NULL ) |
---|
| 420 | return 1; |
---|
| 421 | |
---|
[79bb7e4] | 422 | handle = msn_normalize_handle( cmd[1] ); |
---|
| 423 | imcb_buddy_status( ic, handle, 0, NULL, NULL ); |
---|
| 424 | msn_sb_start_keepalives( msn_sb_by_handle( ic, handle ), TRUE ); |
---|
[b7d3cc34] | 425 | } |
---|
| 426 | else if( strcmp( cmd[0], "RNG" ) == 0 ) |
---|
| 427 | { |
---|
| 428 | struct msn_switchboard *sb; |
---|
| 429 | char *server; |
---|
| 430 | int session, port; |
---|
| 431 | |
---|
[b46769d] | 432 | if( num_parts < 7 ) |
---|
[b7d3cc34] | 433 | { |
---|
[84b045d] | 434 | imcb_error( ic, "Syntax error" ); |
---|
[c2fb3809] | 435 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 436 | return( 0 ); |
---|
| 437 | } |
---|
| 438 | |
---|
| 439 | session = atoi( cmd[1] ); |
---|
| 440 | |
---|
| 441 | server = strchr( cmd[2], ':' ); |
---|
| 442 | if( !server ) |
---|
| 443 | { |
---|
[84b045d] | 444 | imcb_error( ic, "Syntax error" ); |
---|
[c2fb3809] | 445 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 446 | return( 0 ); |
---|
| 447 | } |
---|
| 448 | *server = 0; |
---|
| 449 | port = atoi( server + 1 ); |
---|
| 450 | server = cmd[2]; |
---|
| 451 | |
---|
| 452 | if( strcmp( cmd[3], "CKI" ) != 0 ) |
---|
| 453 | { |
---|
[84b045d] | 454 | imcb_error( ic, "Unknown authentication method for switchboard" ); |
---|
[c2fb3809] | 455 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 456 | return( 0 ); |
---|
| 457 | } |
---|
| 458 | |
---|
| 459 | debug( "Got a call from %s (session %d). Key = %s", cmd[5], session, cmd[4] ); |
---|
| 460 | |
---|
[99f929c] | 461 | if( ( sb = msn_sb_create( ic, server, port, cmd[4], session ) ) == NULL ) |
---|
| 462 | { |
---|
| 463 | /* Although this isn't strictly fatal for the NS connection, it's |
---|
| 464 | definitely something serious (we ran out of file descriptors?). */ |
---|
| 465 | imcb_error( ic, "Could not create new switchboard" ); |
---|
| 466 | imc_logout( ic, TRUE ); |
---|
| 467 | return( 0 ); |
---|
| 468 | } |
---|
| 469 | else |
---|
| 470 | { |
---|
[79bb7e4] | 471 | sb->who = g_strdup( msn_normalize_handle( cmd[5] ) ); |
---|
[99f929c] | 472 | } |
---|
[b7d3cc34] | 473 | } |
---|
| 474 | else if( strcmp( cmd[0], "OUT" ) == 0 ) |
---|
| 475 | { |
---|
[c2fb3809] | 476 | int allow_reconnect = TRUE; |
---|
| 477 | |
---|
[b7d3cc34] | 478 | if( cmd[1] && strcmp( cmd[1], "OTH" ) == 0 ) |
---|
| 479 | { |
---|
[84b045d] | 480 | imcb_error( ic, "Someone else logged in with your account" ); |
---|
[c2fb3809] | 481 | allow_reconnect = FALSE; |
---|
[b7d3cc34] | 482 | } |
---|
| 483 | else if( cmd[1] && strcmp( cmd[1], "SSD" ) == 0 ) |
---|
| 484 | { |
---|
[84b045d] | 485 | imcb_error( ic, "Terminating session because of server shutdown" ); |
---|
[b7d3cc34] | 486 | } |
---|
| 487 | else |
---|
| 488 | { |
---|
[c77406a] | 489 | imcb_error( ic, "Session terminated by remote server (%s)", |
---|
| 490 | cmd[1] ? cmd[1] : "reason unknown)" ); |
---|
[b7d3cc34] | 491 | } |
---|
| 492 | |
---|
[c2fb3809] | 493 | imc_logout( ic, allow_reconnect ); |
---|
[b7d3cc34] | 494 | return( 0 ); |
---|
| 495 | } |
---|
| 496 | else if( strcmp( cmd[0], "IPG" ) == 0 ) |
---|
| 497 | { |
---|
[84b045d] | 498 | imcb_error( ic, "Received IPG command, we don't handle them yet." ); |
---|
[b7d3cc34] | 499 | |
---|
[bae0617] | 500 | handler->msglen = atoi( cmd[1] ); |
---|
[b7d3cc34] | 501 | |
---|
[bae0617] | 502 | if( handler->msglen <= 0 ) |
---|
[b7d3cc34] | 503 | { |
---|
[84b045d] | 504 | imcb_error( ic, "Syntax error" ); |
---|
[c2fb3809] | 505 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 506 | return( 0 ); |
---|
| 507 | } |
---|
| 508 | } |
---|
[e5854a8] | 509 | #if 0 |
---|
[70ac477] | 510 | else if( strcmp( cmd[0], "ADG" ) == 0 ) |
---|
| 511 | { |
---|
| 512 | char *group = g_strdup( cmd[3] ); |
---|
| 513 | int groupnum, i; |
---|
| 514 | GSList *l, *next; |
---|
| 515 | |
---|
| 516 | http_decode( group ); |
---|
| 517 | if( sscanf( cmd[4], "%d", &groupnum ) == 1 ) |
---|
| 518 | { |
---|
| 519 | if( groupnum >= md->groupcount ) |
---|
| 520 | { |
---|
| 521 | md->grouplist = g_renew( char *, md->grouplist, groupnum + 1 ); |
---|
| 522 | for( i = md->groupcount; i <= groupnum; i ++ ) |
---|
| 523 | md->grouplist[i] = NULL; |
---|
| 524 | md->groupcount = groupnum + 1; |
---|
| 525 | } |
---|
| 526 | g_free( md->grouplist[groupnum] ); |
---|
| 527 | md->grouplist[groupnum] = group; |
---|
| 528 | } |
---|
| 529 | else |
---|
| 530 | { |
---|
| 531 | /* Shouldn't happen, but if it does, give up on the group. */ |
---|
| 532 | g_free( group ); |
---|
| 533 | imcb_error( ic, "Syntax error" ); |
---|
| 534 | imc_logout( ic, TRUE ); |
---|
| 535 | return 0; |
---|
| 536 | } |
---|
| 537 | |
---|
| 538 | for( l = md->grpq; l; l = next ) |
---|
| 539 | { |
---|
| 540 | struct msn_groupadd *ga = l->data; |
---|
| 541 | next = l->next; |
---|
| 542 | if( g_strcasecmp( ga->group, group ) == 0 ) |
---|
| 543 | { |
---|
| 544 | if( !msn_buddy_list_add( ic, "FL", ga->who, ga->who, group ) ) |
---|
| 545 | return 0; |
---|
| 546 | |
---|
| 547 | g_free( ga->group ); |
---|
| 548 | g_free( ga->who ); |
---|
| 549 | g_free( ga ); |
---|
| 550 | md->grpq = g_slist_remove( md->grpq, ga ); |
---|
| 551 | } |
---|
| 552 | } |
---|
| 553 | } |
---|
[e5854a8] | 554 | #endif |
---|
[5fecede] | 555 | else if( strcmp( cmd[0], "GCF" ) == 0 ) |
---|
| 556 | { |
---|
| 557 | /* Coming up is cmd[2] bytes of stuff we're supposed to |
---|
| 558 | censore. Meh. */ |
---|
[bae0617] | 559 | handler->msglen = atoi( cmd[2] ); |
---|
[5fecede] | 560 | } |
---|
[be7a180] | 561 | else if( strcmp( cmd[0], "UBX" ) == 0 ) |
---|
| 562 | { |
---|
[e5854a8] | 563 | /* Status message. */ |
---|
[080c43a] | 564 | if( num_parts >= 3 ) |
---|
| 565 | handler->msglen = atoi( cmd[2] ); |
---|
[be7a180] | 566 | } |
---|
[d93c0eb9] | 567 | else if( strcmp( cmd[0], "NOT" ) == 0 ) |
---|
| 568 | { |
---|
[e5854a8] | 569 | /* Some kind of notification, poorly documented but |
---|
| 570 | apparently used to announce address book changes. */ |
---|
| 571 | if( num_parts >= 2 ) |
---|
[bae0617] | 572 | handler->msglen = atoi( cmd[1] ); |
---|
[d93c0eb9] | 573 | } |
---|
[3901b5d] | 574 | else if( strcmp( cmd[0], "UBM" ) == 0 ) |
---|
| 575 | { |
---|
| 576 | if( num_parts >= 7 ) |
---|
| 577 | handler->msglen = atoi( cmd[6] ); |
---|
| 578 | } |
---|
[e132b60] | 579 | else if( strcmp( cmd[0], "QNG" ) == 0 ) |
---|
| 580 | { |
---|
| 581 | ic->flags |= OPT_PONGED; |
---|
| 582 | } |
---|
[b7d3cc34] | 583 | else if( isdigit( cmd[0][0] ) ) |
---|
| 584 | { |
---|
| 585 | int num = atoi( cmd[0] ); |
---|
[08995b0] | 586 | const struct msn_status_code *err = msn_status_by_number( num ); |
---|
[b7d3cc34] | 587 | |
---|
[84b045d] | 588 | imcb_error( ic, "Error reported by MSN server: %s", err->text ); |
---|
[b7d3cc34] | 589 | |
---|
| 590 | if( err->flags & STATUS_FATAL ) |
---|
| 591 | { |
---|
[c2fb3809] | 592 | imc_logout( ic, TRUE ); |
---|
[b7d3cc34] | 593 | return( 0 ); |
---|
| 594 | } |
---|
[02bb9db] | 595 | |
---|
| 596 | /* Oh yes, errors can have payloads too now. Discard them for now. */ |
---|
| 597 | if( num_parts >= 3 ) |
---|
[bae0617] | 598 | handler->msglen = atoi( cmd[2] ); |
---|
[b7d3cc34] | 599 | } |
---|
| 600 | else |
---|
| 601 | { |
---|
[8ff0a61] | 602 | /* debug( "Received unknown command from main server: %s", cmd[0] ); */ |
---|
[b7d3cc34] | 603 | } |
---|
| 604 | |
---|
| 605 | return( 1 ); |
---|
| 606 | } |
---|
| 607 | |
---|
[bae0617] | 608 | static int msn_ns_message( struct msn_handler_data *handler, char *msg, int msglen, char **cmd, int num_parts ) |
---|
[b7d3cc34] | 609 | { |
---|
[bae0617] | 610 | struct im_connection *ic = handler->data; |
---|
[b7d3cc34] | 611 | char *body; |
---|
| 612 | int blen = 0; |
---|
| 613 | |
---|
| 614 | if( !num_parts ) |
---|
| 615 | return( 1 ); |
---|
| 616 | |
---|
| 617 | if( ( body = strstr( msg, "\r\n\r\n" ) ) ) |
---|
| 618 | { |
---|
| 619 | body += 4; |
---|
| 620 | blen = msglen - ( body - msg ); |
---|
| 621 | } |
---|
| 622 | |
---|
| 623 | if( strcmp( cmd[0], "MSG" ) == 0 ) |
---|
| 624 | { |
---|
| 625 | if( g_strcasecmp( cmd[1], "Hotmail" ) == 0 ) |
---|
| 626 | { |
---|
[9b0ad7e] | 627 | char *ct = get_rfc822_header( msg, "Content-Type:", msglen ); |
---|
[b7d3cc34] | 628 | |
---|
| 629 | if( !ct ) |
---|
| 630 | return( 1 ); |
---|
| 631 | |
---|
| 632 | if( g_strncasecmp( ct, "application/x-msmsgssystemmessage", 33 ) == 0 ) |
---|
| 633 | { |
---|
| 634 | char *mtype; |
---|
| 635 | char *arg1; |
---|
| 636 | |
---|
| 637 | if( !body ) |
---|
| 638 | return( 1 ); |
---|
| 639 | |
---|
[9b0ad7e] | 640 | mtype = get_rfc822_header( body, "Type:", blen ); |
---|
| 641 | arg1 = get_rfc822_header( body, "Arg1:", blen ); |
---|
[b7d3cc34] | 642 | |
---|
| 643 | if( mtype && strcmp( mtype, "1" ) == 0 ) |
---|
| 644 | { |
---|
| 645 | if( arg1 ) |
---|
[84b045d] | 646 | imcb_log( ic, "The server is going down for maintenance in %s minutes.", arg1 ); |
---|
[b7d3cc34] | 647 | } |
---|
| 648 | |
---|
[ec29351] | 649 | g_free( arg1 ); |
---|
| 650 | g_free( mtype ); |
---|
[b7d3cc34] | 651 | } |
---|
| 652 | else if( g_strncasecmp( ct, "text/x-msmsgsprofile", 20 ) == 0 ) |
---|
| 653 | { |
---|
| 654 | /* We don't care about this profile for now... */ |
---|
| 655 | } |
---|
| 656 | else if( g_strncasecmp( ct, "text/x-msmsgsinitialemailnotification", 37 ) == 0 ) |
---|
| 657 | { |
---|
[ec29351] | 658 | if( set_getbool( &ic->acc->set, "mail_notifications" ) ) |
---|
[b7d3cc34] | 659 | { |
---|
[9b0ad7e] | 660 | char *inbox = get_rfc822_header( body, "Inbox-Unread:", blen ); |
---|
| 661 | char *folders = get_rfc822_header( body, "Folders-Unread:", blen ); |
---|
[ec29351] | 662 | |
---|
| 663 | if( inbox && folders ) |
---|
| 664 | imcb_log( ic, "INBOX contains %s new messages, plus %s messages in other folders.", inbox, folders ); |
---|
| 665 | |
---|
| 666 | g_free( inbox ); |
---|
| 667 | g_free( folders ); |
---|
[b7d3cc34] | 668 | } |
---|
| 669 | } |
---|
| 670 | else if( g_strncasecmp( ct, "text/x-msmsgsemailnotification", 30 ) == 0 ) |
---|
| 671 | { |
---|
[ec29351] | 672 | if( set_getbool( &ic->acc->set, "mail_notifications" ) ) |
---|
[b7d3cc34] | 673 | { |
---|
[9b0ad7e] | 674 | char *from = get_rfc822_header( body, "From-Addr:", blen ); |
---|
| 675 | char *fromname = get_rfc822_header( body, "From:", blen ); |
---|
[ec29351] | 676 | |
---|
| 677 | if( from && fromname ) |
---|
| 678 | imcb_log( ic, "Received an e-mail message from %s <%s>.", fromname, from ); |
---|
| 679 | |
---|
| 680 | g_free( from ); |
---|
| 681 | g_free( fromname ); |
---|
[b7d3cc34] | 682 | } |
---|
| 683 | } |
---|
| 684 | else if( g_strncasecmp( ct, "text/x-msmsgsactivemailnotification", 35 ) == 0 ) |
---|
| 685 | { |
---|
[a325ebd] | 686 | } |
---|
| 687 | else if( g_strncasecmp( ct, "text/x-msmsgsinitialmdatanotification", 37 ) == 0 || |
---|
| 688 | g_strncasecmp( ct, "text/x-msmsgsoimnotification", 28 ) == 0 ) |
---|
| 689 | { |
---|
| 690 | /* We received an offline message. Or at least notification |
---|
| 691 | that there is one waiting for us. Fetching the message(s) |
---|
| 692 | and purging them from the server is a lot of SOAPy work |
---|
| 693 | not worth doing IMHO. Also I thought it was possible to |
---|
| 694 | have the notification server send them directly, I was |
---|
| 695 | pretty sure I saw Pidgin do it.. |
---|
| 696 | |
---|
| 697 | At least give a notification for now, seems like a |
---|
| 698 | reasonable thing to do. Only problem is, they'll keep |
---|
| 699 | coming back at login time until you read them using a |
---|
| 700 | different client. :-( */ |
---|
| 701 | |
---|
| 702 | char *xml = get_rfc822_header( body, "Mail-Data:", blen ); |
---|
| 703 | struct xt_node *md, *m; |
---|
| 704 | |
---|
| 705 | if( !xml ) |
---|
| 706 | return 1; |
---|
[6bef211] | 707 | md = xt_from_string( xml, 0 ); |
---|
[a325ebd] | 708 | if( !md ) |
---|
| 709 | return 1; |
---|
| 710 | |
---|
| 711 | for( m = md->children; ( m = xt_find_node( m, "M" ) ); m = m->next ) |
---|
| 712 | { |
---|
| 713 | struct xt_node *e = xt_find_node( m->children, "E" ); |
---|
| 714 | struct xt_node *rt = xt_find_node( m->children, "RT" ); |
---|
| 715 | struct tm tp; |
---|
| 716 | time_t msgtime = 0; |
---|
| 717 | |
---|
| 718 | if( !e || !e->text ) |
---|
| 719 | continue; |
---|
| 720 | |
---|
| 721 | memset( &tp, 0, sizeof( tp ) ); |
---|
| 722 | if( rt && rt->text && |
---|
| 723 | sscanf( rt->text, "%4d-%2d-%2dT%2d:%2d:%2d.", |
---|
| 724 | &tp.tm_year, &tp.tm_mon, &tp.tm_mday, |
---|
| 725 | &tp.tm_hour, &tp.tm_min, &tp.tm_sec ) == 6 ) |
---|
| 726 | { |
---|
| 727 | tp.tm_year -= 1900; |
---|
| 728 | tp.tm_mon --; |
---|
| 729 | msgtime = mktime_utc( &tp ); |
---|
| 730 | |
---|
| 731 | } |
---|
| 732 | imcb_buddy_msg( ic, e->text, "<< \002BitlBee\002 - Received offline message. BitlBee can't show these. >>", 0, msgtime ); |
---|
| 733 | } |
---|
| 734 | |
---|
| 735 | g_free( xml ); |
---|
| 736 | xt_free_node( md ); |
---|
[b7d3cc34] | 737 | } |
---|
| 738 | else |
---|
| 739 | { |
---|
| 740 | debug( "Can't handle %s packet from notification server", ct ); |
---|
| 741 | } |
---|
| 742 | |
---|
| 743 | g_free( ct ); |
---|
| 744 | } |
---|
| 745 | } |
---|
[d93c0eb9] | 746 | else if( strcmp( cmd[0], "UBX" ) == 0 ) |
---|
| 747 | { |
---|
[9066974] | 748 | struct xt_node *ubx, *psm; |
---|
[d93c0eb9] | 749 | char *psm_text = NULL; |
---|
| 750 | |
---|
[d0752e8] | 751 | ubx = xt_from_string( msg, msglen ); |
---|
[9066974] | 752 | if( ubx && strcmp( ubx->name, "Data" ) == 0 && |
---|
| 753 | ( psm = xt_find_node( ubx->children, "PSM" ) ) ) |
---|
[d93c0eb9] | 754 | psm_text = psm->text; |
---|
| 755 | |
---|
[79bb7e4] | 756 | imcb_buddy_status_msg( ic, msn_normalize_handle( cmd[1] ), psm_text ); |
---|
[9066974] | 757 | xt_free_node( ubx ); |
---|
[d93c0eb9] | 758 | } |
---|
[e5854a8] | 759 | else if( strcmp( cmd[0], "ADL" ) == 0 ) |
---|
| 760 | { |
---|
| 761 | struct xt_node *adl, *d, *c; |
---|
| 762 | |
---|
[d0752e8] | 763 | if( !( adl = xt_from_string( msg, msglen ) ) ) |
---|
[e5854a8] | 764 | return 1; |
---|
| 765 | |
---|
| 766 | for( d = adl->children; d; d = d->next ) |
---|
| 767 | { |
---|
| 768 | char *dn; |
---|
| 769 | if( strcmp( d->name, "d" ) != 0 || |
---|
| 770 | ( dn = xt_find_attr( d, "n" ) ) == NULL ) |
---|
| 771 | continue; |
---|
| 772 | for( c = d->children; c; c = c->next ) |
---|
| 773 | { |
---|
| 774 | bee_user_t *bu; |
---|
| 775 | struct msn_buddy_data *bd; |
---|
| 776 | char *cn, *handle, *f, *l; |
---|
| 777 | int flags; |
---|
| 778 | |
---|
| 779 | if( strcmp( c->name, "c" ) != 0 || |
---|
| 780 | ( l = xt_find_attr( c, "l" ) ) == NULL || |
---|
| 781 | ( cn = xt_find_attr( c, "n" ) ) == NULL ) |
---|
| 782 | continue; |
---|
| 783 | |
---|
[3901b5d] | 784 | /* FIXME: Use "t" here, guess I should just add it |
---|
| 785 | as a prefix like elsewhere in the protocol. */ |
---|
[e5854a8] | 786 | handle = g_strdup_printf( "%s@%s", cn, dn ); |
---|
| 787 | if( !( ( bu = bee_user_by_handle( ic->bee, ic, handle ) ) || |
---|
| 788 | ( bu = bee_user_new( ic->bee, ic, handle, 0 ) ) ) ) |
---|
| 789 | { |
---|
| 790 | g_free( handle ); |
---|
| 791 | continue; |
---|
| 792 | } |
---|
| 793 | g_free( handle ); |
---|
| 794 | bd = bu->data; |
---|
| 795 | |
---|
| 796 | if( ( f = xt_find_attr( c, "f" ) ) ) |
---|
| 797 | { |
---|
| 798 | http_decode( f ); |
---|
| 799 | imcb_rename_buddy( ic, bu->handle, f ); |
---|
| 800 | } |
---|
| 801 | |
---|
| 802 | flags = atoi( l ) & 15; |
---|
| 803 | if( bd->flags != flags ) |
---|
| 804 | { |
---|
| 805 | bd->flags = flags; |
---|
| 806 | msn_buddy_ask( bu ); |
---|
| 807 | } |
---|
| 808 | } |
---|
| 809 | } |
---|
| 810 | } |
---|
[3901b5d] | 811 | else if( strcmp( cmd[0], "UBM" ) == 0 ) |
---|
| 812 | { |
---|
[4c9d377] | 813 | /* This one will give us msgs from federated networks. Technically |
---|
| 814 | it should also get us offline messages, but I don't know how |
---|
| 815 | I can signal MSN servers to use it. */ |
---|
| 816 | char *ct, *handle; |
---|
[3901b5d] | 817 | |
---|
[4c9d377] | 818 | if( strcmp( cmd[1], ic->acc->user ) == 0 ) |
---|
| 819 | { |
---|
| 820 | /* With MPOP, you'll get copies of your own msgs from other |
---|
| 821 | sessions. Discard those at least for now. */ |
---|
| 822 | return 1; |
---|
| 823 | } |
---|
| 824 | |
---|
| 825 | ct = get_rfc822_header( msg, "Content-Type", msglen ); |
---|
[3901b5d] | 826 | if( strncmp( ct, "text/plain", 10 ) != 0 ) |
---|
| 827 | { |
---|
[4c9d377] | 828 | /* Typing notification or something? */ |
---|
[3901b5d] | 829 | g_free( ct ); |
---|
| 830 | return 1; |
---|
| 831 | } |
---|
| 832 | if( strcmp( cmd[2], "1" ) != 0 ) |
---|
| 833 | handle = g_strdup_printf( "%s:%s", cmd[2], cmd[1] ); |
---|
| 834 | else |
---|
| 835 | handle = g_strdup( cmd[1] ); |
---|
| 836 | |
---|
| 837 | imcb_buddy_msg( ic, handle, body, 0, 0 ); |
---|
| 838 | g_free( handle ); |
---|
| 839 | } |
---|
[b7d3cc34] | 840 | |
---|
[3901b5d] | 841 | return 1; |
---|
[b7d3cc34] | 842 | } |
---|
| 843 | |
---|
[660cb00] | 844 | void msn_auth_got_passport_token( struct im_connection *ic, const char *token, const char *error ) |
---|
[b7d3cc34] | 845 | { |
---|
[d84e2a9] | 846 | struct msn_data *md; |
---|
[e6648bf] | 847 | |
---|
[d84e2a9] | 848 | /* Dead connection? */ |
---|
| 849 | if( g_slist_find( msn_connections, ic ) == NULL ) |
---|
| 850 | return; |
---|
| 851 | |
---|
| 852 | md = ic->proto_data; |
---|
[523fb23] | 853 | |
---|
[660cb00] | 854 | if( token ) |
---|
[b7d3cc34] | 855 | { |
---|
[f9258ae] | 856 | msn_ns_write( ic, -1, "USR %d SSO S %s %s {%s}\r\n", ++md->trId, md->tokens[0], token, md->uuid ); |
---|
[b7d3cc34] | 857 | } |
---|
[660cb00] | 858 | else |
---|
| 859 | { |
---|
| 860 | imcb_error( ic, "Error during Passport authentication: %s", error ); |
---|
| 861 | imc_logout( ic, TRUE ); |
---|
| 862 | } |
---|
[b7d3cc34] | 863 | } |
---|
[e3413cc] | 864 | |
---|
[ca7de3a] | 865 | void msn_auth_got_contact_list( struct im_connection *ic ) |
---|
| 866 | { |
---|
| 867 | struct msn_data *md; |
---|
| 868 | |
---|
| 869 | /* Dead connection? */ |
---|
| 870 | if( g_slist_find( msn_connections, ic ) == NULL ) |
---|
| 871 | return; |
---|
| 872 | |
---|
| 873 | md = ic->proto_data; |
---|
[64768d4] | 874 | msn_ns_write( ic, -1, "BLP %d %s\r\n", ++md->trId, "BL" ); |
---|
[ca7de3a] | 875 | } |
---|
| 876 | |
---|
| 877 | static gboolean msn_ns_send_adl_1( gpointer key, gpointer value, gpointer data ) |
---|
| 878 | { |
---|
| 879 | struct xt_node *adl = data, *d, *c; |
---|
| 880 | struct bee_user *bu = value; |
---|
| 881 | struct msn_buddy_data *bd = bu->data; |
---|
[5a7af1b] | 882 | struct msn_data *md = bu->ic->proto_data; |
---|
[ca7de3a] | 883 | char handle[strlen(bu->handle)]; |
---|
| 884 | char *domain; |
---|
| 885 | char l[4]; |
---|
| 886 | |
---|
[5a7af1b] | 887 | if( ( bd->flags & 7 ) == 0 || ( bd->flags & MSN_BUDDY_ADL_SYNCED ) ) |
---|
[e5854a8] | 888 | return FALSE; |
---|
| 889 | |
---|
[ca7de3a] | 890 | strcpy( handle, bu->handle ); |
---|
| 891 | if( ( domain = strchr( handle, '@' ) ) == NULL ) /* WTF */ |
---|
| 892 | return FALSE; |
---|
| 893 | *domain = '\0'; |
---|
| 894 | domain ++; |
---|
| 895 | |
---|
| 896 | if( ( d = adl->children ) == NULL || |
---|
| 897 | g_strcasecmp( xt_find_attr( d, "n" ), domain ) != 0 ) |
---|
| 898 | { |
---|
| 899 | d = xt_new_node( "d", NULL, NULL ); |
---|
| 900 | xt_add_attr( d, "n", domain ); |
---|
| 901 | xt_insert_child( adl, d ); |
---|
| 902 | } |
---|
| 903 | |
---|
| 904 | g_snprintf( l, sizeof( l ), "%d", bd->flags & 7 ); |
---|
| 905 | c = xt_new_node( "c", NULL, NULL ); |
---|
| 906 | xt_add_attr( c, "n", handle ); |
---|
| 907 | xt_add_attr( c, "l", l ); |
---|
[3901b5d] | 908 | xt_add_attr( c, "t", "1" ); /* FIXME: Network type, i.e. 32 for Y!MSG */ |
---|
[ca7de3a] | 909 | xt_insert_child( d, c ); |
---|
| 910 | |
---|
[5a7af1b] | 911 | /* Do this in batches of 100. */ |
---|
| 912 | bd->flags |= MSN_BUDDY_ADL_SYNCED; |
---|
| 913 | return (--md->adl_todo % 140) == 0; |
---|
[ca7de3a] | 914 | } |
---|
| 915 | |
---|
| 916 | static void msn_ns_send_adl( struct im_connection *ic ) |
---|
| 917 | { |
---|
| 918 | struct xt_node *adl; |
---|
[5a7af1b] | 919 | struct msn_data *md = ic->proto_data; |
---|
[64768d4] | 920 | char *adls; |
---|
[ca7de3a] | 921 | |
---|
| 922 | adl = xt_new_node( "ml", NULL, NULL ); |
---|
| 923 | xt_add_attr( adl, "l", "1" ); |
---|
| 924 | g_tree_foreach( md->domaintree, msn_ns_send_adl_1, adl ); |
---|
[5a7af1b] | 925 | if( adl->children == NULL ) |
---|
| 926 | { |
---|
| 927 | /* This tells the caller that we're done now. */ |
---|
| 928 | md->adl_todo = -1; |
---|
| 929 | xt_free_node( adl ); |
---|
| 930 | return; |
---|
| 931 | } |
---|
[ca7de3a] | 932 | |
---|
[64768d4] | 933 | adls = xt_to_string( adl ); |
---|
[c1d40e7] | 934 | xt_free_node( adl ); |
---|
[64768d4] | 935 | msn_ns_write( ic, -1, "ADL %d %zd\r\n%s", ++md->trId, strlen( adls ), adls ); |
---|
[ca7de3a] | 936 | g_free( adls ); |
---|
[5a7af1b] | 937 | } |
---|
| 938 | |
---|
| 939 | static void msn_ns_send_adl_start( struct im_connection *ic ) |
---|
| 940 | { |
---|
| 941 | struct msn_data *md; |
---|
| 942 | GSList *l; |
---|
| 943 | |
---|
| 944 | /* Dead connection? */ |
---|
| 945 | if( g_slist_find( msn_connections, ic ) == NULL ) |
---|
| 946 | return; |
---|
| 947 | |
---|
| 948 | md = ic->proto_data; |
---|
| 949 | md->adl_todo = 0; |
---|
| 950 | for( l = ic->bee->users; l; l = l->next ) |
---|
| 951 | { |
---|
| 952 | bee_user_t *bu = l->data; |
---|
| 953 | struct msn_buddy_data *bd = bu->data; |
---|
| 954 | |
---|
| 955 | if( bu->ic != ic || ( bd->flags & 7 ) == 0 ) |
---|
| 956 | continue; |
---|
| 957 | |
---|
| 958 | bd->flags &= ~MSN_BUDDY_ADL_SYNCED; |
---|
| 959 | md->adl_todo++; |
---|
| 960 | } |
---|
| 961 | |
---|
| 962 | msn_ns_send_adl( ic ); |
---|
[ca7de3a] | 963 | } |
---|
[80175a1] | 964 | |
---|
| 965 | int msn_ns_finish_login( struct im_connection *ic ) |
---|
| 966 | { |
---|
| 967 | struct msn_data *md = ic->proto_data; |
---|
| 968 | |
---|
| 969 | if( ic->flags & OPT_LOGGED_IN ) |
---|
| 970 | return 1; |
---|
| 971 | |
---|
| 972 | if( md->adl_todo < 0 ) |
---|
| 973 | md->flags |= MSN_DONE_ADL; |
---|
| 974 | |
---|
| 975 | if( ( md->flags & MSN_DONE_ADL ) && ( md->flags & MSN_GOT_PROFILE ) ) |
---|
[ed0589c] | 976 | { |
---|
| 977 | if( md->flags & MSN_EMAIL_UNVERIFIED ) |
---|
| 978 | imcb_connected( ic ); |
---|
| 979 | else |
---|
| 980 | return msn_ns_set_display_name( ic, set_getstr( &ic->acc->set, "display_name" ) ); |
---|
| 981 | } |
---|
| 982 | |
---|
| 983 | return 1; |
---|
[80175a1] | 984 | } |
---|
[bc676ac] | 985 | |
---|
| 986 | int msn_ns_sendmessage( struct im_connection *ic, bee_user_t *bu, const char *text ) |
---|
| 987 | { |
---|
| 988 | struct msn_data *md = ic->proto_data; |
---|
[208db4b] | 989 | int type = 0; |
---|
| 990 | char *buf, *handle; |
---|
[bc676ac] | 991 | |
---|
| 992 | if( strncmp( text, "\r\r\r", 3 ) == 0 ) |
---|
| 993 | /* Err. Shouldn't happen but I guess it can. Don't send others |
---|
| 994 | any of the "SHAKE THAT THING" messages. :-D */ |
---|
| 995 | return 1; |
---|
| 996 | |
---|
[208db4b] | 997 | /* This might be a federated contact. Get its network number, |
---|
| 998 | prefixed to bu->handle with a colon. Default is 1. */ |
---|
| 999 | for( handle = bu->handle; isdigit( *handle ); handle ++ ) |
---|
| 1000 | type = type * 10 + *handle - '0'; |
---|
| 1001 | if( *handle == ':' ) |
---|
| 1002 | handle ++; |
---|
| 1003 | else |
---|
| 1004 | type = 1; |
---|
| 1005 | |
---|
[bc676ac] | 1006 | buf = g_strdup_printf( "%s%s", MSN_MESSAGE_HEADERS, text ); |
---|
| 1007 | |
---|
| 1008 | if( msn_ns_write( ic, -1, "UUM %d %s %d %d %zd\r\n%s", |
---|
[208db4b] | 1009 | ++md->trId, handle, type, |
---|
[bc676ac] | 1010 | 1, /* type == IM (not nudge/typing) */ |
---|
| 1011 | strlen( buf ), buf ) ) |
---|
| 1012 | return 1; |
---|
| 1013 | else |
---|
| 1014 | return 0; |
---|
| 1015 | } |
---|
| 1016 | |
---|
| 1017 | void msn_ns_oim_send_queue( struct im_connection *ic, GSList **msgq ) |
---|
| 1018 | { |
---|
| 1019 | GSList *l; |
---|
| 1020 | |
---|
| 1021 | for( l = *msgq; l; l = l->next ) |
---|
| 1022 | { |
---|
| 1023 | struct msn_message *m = l->data; |
---|
| 1024 | bee_user_t *bu = bee_user_by_handle( ic->bee, ic, m->who ); |
---|
| 1025 | |
---|
| 1026 | if( bu ) |
---|
| 1027 | if( !msn_ns_sendmessage( ic, bu, m->text ) ) |
---|
| 1028 | return; |
---|
| 1029 | } |
---|
| 1030 | |
---|
| 1031 | while( *msgq != NULL ) |
---|
| 1032 | { |
---|
| 1033 | struct msn_message *m = (*msgq)->data; |
---|
| 1034 | |
---|
| 1035 | g_free( m->who ); |
---|
| 1036 | g_free( m->text ); |
---|
| 1037 | g_free( m ); |
---|
| 1038 | |
---|
| 1039 | *msgq = g_slist_remove( *msgq, m ); |
---|
| 1040 | } |
---|
| 1041 | } |
---|