Changeset bae0617 for protocols/msn
- Timestamp:
- 2010-09-03T21:24:58Z (14 years ago)
- Branches:
- master
- Children:
- 4aa8a04
- Parents:
- 64768d4
- Location:
- protocols/msn
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/msn/msn.c
r64768d4 rbae0617 53 53 54 54 ic->proto_data = md; 55 md->fd = -1;56 55 57 56 if( strchr( acc->user, '@' ) == NULL ) … … 62 61 } 63 62 64 imcb_log( ic, "Connecting" );65 66 md->fd = proxy_connect( "messenger.hotmail.com", 1863, msn_ns_connected, ic );67 if( md->fd < 0 )68 {69 imcb_error( ic, "Could not connect to server" );70 imc_logout( ic, TRUE );71 return;72 }73 74 63 md->ic = ic; 75 64 md->away_state = msn_away_state_list; 76 65 md->domaintree = g_tree_new( msn_domaintree_cmp ); 77 66 78 msn_connections = g_slist_append( msn_connections, ic ); 67 msn_connections = g_slist_prepend( msn_connections, ic ); 68 69 imcb_log( ic, "Connecting" ); 70 msn_ns_connect( ic, md->ns, MSN_NS_HOST, MSN_NS_PORT ); 79 71 } 80 72 … … 93 85 */ 94 86 95 if( md->fd >= 0 ) 96 closesocket( md->fd ); 97 98 if( md->handler ) 99 { 100 if( md->handler->rxq ) g_free( md->handler->rxq ); 101 if( md->handler->cmd_text ) g_free( md->handler->cmd_text ); 102 g_free( md->handler ); 103 } 87 msn_ns_close( md->ns ); 88 msn_ns_close( md->auth ); 104 89 105 90 while( md->switchboards ) -
protocols/msn/msn.h
r64768d4 rbae0617 44 44 */ 45 45 46 #define MSN_NS_HOST "messenger.hotmail.com" 47 #define MSN_NS_PORT 1863 48 46 49 /* Some other version. 47 50 #define MSNP11_PROD_KEY "O4BG@C7BWLYQX?5G" … … 80 83 } msn_flags_t; 81 84 85 struct msn_handler_data 86 { 87 int fd, inpa; 88 int rxlen; 89 char *rxq; 90 91 int msglen; 92 char *cmd_text; 93 94 /* Either ic or sb */ 95 gpointer data; 96 97 int (*exec_command) ( struct msn_handler_data *handler, char **cmd, int count ); 98 int (*exec_message) ( struct msn_handler_data *handler, char *msg, int msglen, char **cmd, int count ); 99 }; 100 82 101 struct msn_data 83 102 { 84 103 struct im_connection *ic; 85 104 86 int fd; 87 struct msn_handler_data *handler; 105 struct msn_handler_data ns[1], auth[1]; 88 106 msn_flags_t flags; 89 107 … … 111 129 struct im_connection *ic; 112 130 131 /* The following two are also in the handler. TODO: Clean up. */ 113 132 int fd; 114 133 gint inp; … … 150 169 char *who; 151 170 char *group; 152 };153 154 struct msn_handler_data155 {156 int fd;157 int rxlen;158 char *rxq;159 160 int msglen;161 char *cmd_text;162 163 gpointer data;164 165 int (*exec_command) ( gpointer data, char **cmd, int count );166 int (*exec_message) ( gpointer data, char *msg, int msglen, char **cmd, int count );167 171 }; 168 172 … … 209 213 /* ns.c */ 210 214 int msn_ns_write( struct im_connection *ic, int fd, const char *fmt, ... ); 211 gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ); 215 gboolean msn_ns_connect( struct im_connection *ic, struct msn_handler_data *handler, const char *host, int port ); 216 void msn_ns_close( struct msn_handler_data *handler ); 212 217 void msn_auth_got_passport_token( struct im_connection *ic, const char *token, const char *error ); 213 218 void msn_auth_got_contact_list( struct im_connection *ic ); -
protocols/msn/msn_util.c
r64768d4 rbae0617 351 351 cmd = msn_linesplit( cmd_text ); 352 352 for( count = 0; cmd[count]; count ++ ); 353 st = h->exec_command( h ->data, cmd, count );353 st = h->exec_command( h, cmd, count ); 354 354 g_free( cmd_text ); 355 355 … … 386 386 for( count = 0; cmd[count]; count ++ ); 387 387 388 st = h->exec_message( h ->data, msg, h->msglen, cmd, count );388 st = h->exec_message( h, msg, h->msglen, cmd, count ); 389 389 g_free( msg ); 390 390 g_free( h->cmd_text ); -
protocols/msn/ns.c
r64768d4 rbae0617 31 31 #include "xmltree.h" 32 32 33 static gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ); 33 34 static gboolean msn_ns_callback( gpointer data, gint source, b_input_condition cond ); 34 static int msn_ns_command( gpointer data, char **cmd, int num_parts );35 static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int num_parts );35 static int msn_ns_command( struct msn_handler_data *handler, char **cmd, int num_parts ); 36 static int msn_ns_message( struct msn_handler_data *handler, char *msg, int msglen, char **cmd, int num_parts ); 36 37 37 38 static void msn_ns_send_adl_start( struct im_connection *ic ); … … 51 52 52 53 if( fd < 0 ) 53 fd = md-> fd;54 fd = md->ns->fd; 54 55 55 56 if( getenv( "BITLBEE_DEBUG" ) ) … … 69 70 } 70 71 71 gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ) 72 { 73 struct im_connection *ic = data; 74 struct msn_data *md; 75 76 if( !g_slist_find( msn_connections, ic ) ) 77 return FALSE; 78 79 if( source == -1 ) 72 gboolean msn_ns_connect( struct im_connection *ic, struct msn_handler_data *handler, const char *host, int port ) 73 { 74 if( handler->fd >= 0 ) 75 closesocket( handler->fd ); 76 77 handler->exec_command = msn_ns_command; 78 handler->exec_message = msn_ns_message; 79 handler->data = ic; 80 handler->fd = proxy_connect( host, port, msn_ns_connected, handler ); 81 if( handler->fd < 0 ) 80 82 { 81 83 imcb_error( ic, "Could not connect to server" ); … … 84 86 } 85 87 88 return TRUE; 89 } 90 91 static gboolean msn_ns_connected( gpointer data, gint source, b_input_condition cond ) 92 { 93 struct msn_handler_data *handler = data; 94 struct im_connection *ic = handler->data; 95 struct msn_data *md; 96 97 if( !g_slist_find( msn_connections, ic ) ) 98 return FALSE; 99 86 100 md = ic->proto_data; 87 101 88 if( !md->handler ) 89 { 90 md->handler = g_new0( struct msn_handler_data, 1 ); 91 md->handler->data = ic; 92 md->handler->exec_command = msn_ns_command; 93 md->handler->exec_message = msn_ns_message; 94 } 95 else 96 { 97 if( md->handler->rxq ) 98 g_free( md->handler->rxq ); 99 100 md->handler->rxlen = 0; 101 } 102 103 md->handler->fd = md->fd; 104 md->handler->rxq = g_new0( char, 1 ); 102 if( source == -1 ) 103 { 104 imcb_error( ic, "Could not connect to server" ); 105 imc_logout( ic, TRUE ); 106 return FALSE; 107 } 108 109 g_free( handler->rxq ); 110 handler->rxlen = 0; 111 handler->rxq = g_new0( char, 1 ); 105 112 106 113 if( msn_ns_write( ic, -1, "VER %d %s CVR0\r\n", ++md->trId, MSNP_VER ) ) 107 114 { 108 ic->inpa = b_input_add( md->fd, B_EV_IO_READ, msn_ns_callback, ic);115 handler->inpa = b_input_add( handler->fd, B_EV_IO_READ, msn_ns_callback, handler ); 109 116 imcb_log( ic, "Connected to server, waiting for reply" ); 110 117 } … … 113 120 } 114 121 122 void msn_ns_close( struct msn_handler_data *handler ) 123 { 124 if( handler->fd >= 0 ) 125 { 126 closesocket( handler->fd ); 127 b_event_remove( handler->inpa ); 128 } 129 130 handler->fd = handler->inpa = -1; 131 g_free( handler->rxq ); 132 g_free( handler->cmd_text ); 133 134 handler->rxlen = 0; 135 handler->rxq = NULL; 136 handler->cmd_text = NULL; 137 } 138 115 139 static gboolean msn_ns_callback( gpointer data, gint source, b_input_condition cond ) 116 140 { 117 struct im_connection *ic= data;118 struct msn_data *md = ic->proto_data;119 120 if( msn_handler( md->handler ) == -1 ) /* Don't do this on ret == 0, it's already done then. */141 struct msn_handler_data *handler = data; 142 struct im_connection *ic = handler->data; 143 144 if( msn_handler( handler ) == -1 ) /* Don't do this on ret == 0, it's already done then. */ 121 145 { 122 146 imcb_error( ic, "Error while reading from server" ); … … 129 153 } 130 154 131 static int msn_ns_command( gpointer data, char **cmd, int num_parts )132 { 133 struct im_connection *ic = data;155 static int msn_ns_command( struct msn_handler_data *handler, char **cmd, int num_parts ) 156 { 157 struct im_connection *ic = handler->data; 134 158 struct msn_data *md = ic->proto_data; 135 159 … … 164 188 if( num_parts >= 6 && strcmp( cmd[2], "NS" ) == 0 ) 165 189 { 166 b_event_remove( ic->inpa ); 167 ic->inpa = 0; 168 closesocket( md->fd ); 190 b_event_remove( handler->inpa ); 191 handler->inpa = -1; 169 192 170 193 server = strchr( cmd[3], ':' ); … … 180 203 181 204 imcb_log( ic, "Transferring to other server" ); 182 183 md->fd = proxy_connect( server, port, msn_ns_connected, ic ); 205 return msn_ns_connect( ic, handler, server, port ); 184 206 } 185 207 else if( num_parts >= 6 && strcmp( cmd[2], "SB" ) == 0 ) … … 273 295 } 274 296 275 md->handler->msglen = atoi( cmd[3] );276 277 if( md->handler->msglen <= 0 )297 handler->msglen = atoi( cmd[3] ); 298 299 if( handler->msglen <= 0 ) 278 300 { 279 301 imcb_error( ic, "Syntax error" ); … … 296 318 else if( num_parts >= 3 ) 297 319 { 298 md->handler->msglen = atoi( cmd[2] );320 handler->msglen = atoi( cmd[2] ); 299 321 } 300 322 } … … 460 482 imcb_error( ic, "Received IPG command, we don't handle them yet." ); 461 483 462 md->handler->msglen = atoi( cmd[1] );463 464 if( md->handler->msglen <= 0 )484 handler->msglen = atoi( cmd[1] ); 485 486 if( handler->msglen <= 0 ) 465 487 { 466 488 imcb_error( ic, "Syntax error" ); … … 519 541 /* Coming up is cmd[2] bytes of stuff we're supposed to 520 542 censore. Meh. */ 521 md->handler->msglen = atoi( cmd[2] );543 handler->msglen = atoi( cmd[2] ); 522 544 } 523 545 else if( strcmp( cmd[0], "UBX" ) == 0 ) … … 525 547 /* Status message. */ 526 548 if( num_parts >= 4 ) 527 md->handler->msglen = atoi( cmd[3] );549 handler->msglen = atoi( cmd[3] ); 528 550 } 529 551 else if( strcmp( cmd[0], "NOT" ) == 0 ) … … 532 554 apparently used to announce address book changes. */ 533 555 if( num_parts >= 2 ) 534 md->handler->msglen = atoi( cmd[1] );556 handler->msglen = atoi( cmd[1] ); 535 557 } 536 558 else if( isdigit( cmd[0][0] ) ) … … 549 571 /* Oh yes, errors can have payloads too now. Discard them for now. */ 550 572 if( num_parts >= 3 ) 551 md->handler->msglen = atoi( cmd[2] );573 handler->msglen = atoi( cmd[2] ); 552 574 } 553 575 else … … 559 581 } 560 582 561 static int msn_ns_message( gpointer data, char *msg, int msglen, char **cmd, int num_parts )562 { 563 struct im_connection *ic = data;583 static int msn_ns_message( struct msn_handler_data *handler, char *msg, int msglen, char **cmd, int num_parts ) 584 { 585 struct im_connection *ic = handler->data; 564 586 char *body; 565 587 int blen = 0; -
protocols/msn/sb.c
r64768d4 rbae0617 32 32 33 33 static gboolean msn_sb_callback( gpointer data, gint source, b_input_condition cond ); 34 static int msn_sb_command( gpointer data, char **cmd, int num_parts );35 static int msn_sb_message( gpointer data, char *msg, int msglen, char **cmd, int num_parts );34 static int msn_sb_command( struct msn_handler_data *handler, char **cmd, int num_parts ); 35 static int msn_sb_message( struct msn_handler_data *handler, char *msg, int msglen, char **cmd, int num_parts ); 36 36 37 37 int msn_sb_write( struct msn_switchboard *sb, const char *fmt, ... ) … … 392 392 } 393 393 394 static int msn_sb_command( gpointer data, char **cmd, int num_parts )395 { 396 struct msn_switchboard *sb = data;394 static int msn_sb_command( struct msn_handler_data *handler, char **cmd, int num_parts ) 395 { 396 struct msn_switchboard *sb = handler->data; 397 397 struct im_connection *ic = sb->ic; 398 398 … … 665 665 } 666 666 667 static int msn_sb_message( gpointer data, char *msg, int msglen, char **cmd, int num_parts )668 { 669 struct msn_switchboard *sb = data;667 static int msn_sb_message( struct msn_handler_data *handler, char *msg, int msglen, char **cmd, int num_parts ) 668 { 669 struct msn_switchboard *sb = handler->data; 670 670 struct im_connection *ic = sb->ic; 671 671 char *body;
Note: See TracChangeset
for help on using the changeset viewer.