Changeset 0da65d5 for protocols/jabber/io.c
- Timestamp:
- 2007-03-31T05:40:45Z (17 years ago)
- Branches:
- master
- Children:
- aef4828
- Parents:
- fa29d093
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/io.c
rfa29d093 r0da65d5 26 26 27 27 static gboolean jabber_write_callback( gpointer data, gint fd, b_input_condition cond ); 28 static gboolean jabber_write_queue( struct gaim_connection *gc );29 30 int jabber_write_packet( struct gaim_connection *gc, struct xt_node *node )28 static gboolean jabber_write_queue( struct im_connection *ic ); 29 30 int jabber_write_packet( struct im_connection *ic, struct xt_node *node ) 31 31 { 32 32 char *buf; … … 34 34 35 35 buf = xt_to_string( node ); 36 st = jabber_write( gc, buf, strlen( buf ) );36 st = jabber_write( ic, buf, strlen( buf ) ); 37 37 g_free( buf ); 38 38 … … 40 40 } 41 41 42 int jabber_write( struct gaim_connection *gc, char *buf, int len )43 { 44 struct jabber_data *jd = gc->proto_data;42 int jabber_write( struct im_connection *ic, char *buf, int len ) 43 { 44 struct jabber_data *jd = ic->proto_data; 45 45 gboolean ret; 46 46 … … 54 54 it via the event handler. If not, add the handler. (In 55 55 most cases it probably won't be necessary.) */ 56 if( ( ret = jabber_write_queue( gc ) ) && jd->tx_len > 0 )57 jd->w_inpa = b_input_add( jd->fd, GAIM_INPUT_WRITE, jabber_write_callback, gc );56 if( ( ret = jabber_write_queue( ic ) ) && jd->tx_len > 0 ) 57 jd->w_inpa = b_input_add( jd->fd, GAIM_INPUT_WRITE, jabber_write_callback, ic ); 58 58 } 59 59 else … … 85 85 static gboolean jabber_write_callback( gpointer data, gint fd, b_input_condition cond ) 86 86 { 87 struct jabber_data *jd = ((struct gaim_connection *)data)->proto_data;87 struct jabber_data *jd = ((struct im_connection *)data)->proto_data; 88 88 89 89 return jd->fd != -1 && … … 92 92 } 93 93 94 static gboolean jabber_write_queue( struct gaim_connection *gc )95 { 96 struct jabber_data *jd = gc->proto_data;94 static gboolean jabber_write_queue( struct im_connection *ic ) 95 { 96 struct jabber_data *jd = ic->proto_data; 97 97 int st; 98 98 … … 117 117 jd->fd = -1; 118 118 119 hide_login_progress_error( gc, "Short write() to server" );120 signoff( gc );119 hide_login_progress_error( ic, "Short write() to server" ); 120 signoff( ic ); 121 121 return FALSE; 122 122 } … … 142 142 static gboolean jabber_read_callback( gpointer data, gint fd, b_input_condition cond ) 143 143 { 144 struct gaim_connection *gc = data;145 struct jabber_data *jd = gc->proto_data;144 struct im_connection *ic = data; 145 struct jabber_data *jd = ic->proto_data; 146 146 char buf[512]; 147 147 int st; … … 160 160 if( xt_feed( jd->xt, buf, st ) < 0 ) 161 161 { 162 hide_login_progress_error( gc, "XML stream error" );163 signoff( gc );162 hide_login_progress_error( ic, "XML stream error" ); 163 signoff( ic ); 164 164 return FALSE; 165 165 } … … 176 176 { 177 177 jd->flags &= ~JFLAG_STREAM_RESTART; 178 jabber_start_stream( gc );178 jabber_start_stream( ic ); 179 179 } 180 180 … … 196 196 this is an old server that can't do SASL 197 197 authentication. */ 198 if( !sasl_supported( gc ) )198 if( !sasl_supported( ic ) ) 199 199 { 200 200 /* If there's no version= tag, we suppose 201 201 this server does NOT implement: XMPP 1.0, 202 202 SASL and TLS. */ 203 if( set_getbool( & gc->acc->set, "tls" ) )203 if( set_getbool( &ic->acc->set, "tls" ) ) 204 204 { 205 hide_login_progress( gc, "TLS is turned on for this "205 hide_login_progress( ic, "TLS is turned on for this " 206 206 "account, but is not supported by this server" ); 207 signoff( gc );207 signoff( ic ); 208 208 return FALSE; 209 209 } 210 210 else 211 211 { 212 return jabber_init_iq_auth( gc );212 return jabber_init_iq_auth( ic ); 213 213 } 214 214 } … … 216 216 else 217 217 { 218 hide_login_progress( gc, "XML stream error" );219 signoff( gc );218 hide_login_progress( ic, "XML stream error" ); 219 signoff( ic ); 220 220 return FALSE; 221 221 } … … 227 227 jd->fd = -1; 228 228 229 hide_login_progress_error( gc, "Error while reading from server" );230 signoff( gc );229 hide_login_progress_error( ic, "Error while reading from server" ); 230 signoff( ic ); 231 231 return FALSE; 232 232 } … … 238 238 gboolean jabber_connected_plain( gpointer data, gint source, b_input_condition cond ) 239 239 { 240 struct gaim_connection *gc = data;240 struct im_connection *ic = data; 241 241 242 242 if( source == -1 ) 243 243 { 244 hide_login_progress( gc, "Could not connect to server" );245 signoff( gc );244 hide_login_progress( ic, "Could not connect to server" ); 245 signoff( ic ); 246 246 return FALSE; 247 247 } 248 248 249 set_login_progress( gc, 1, "Connected to server, logging in" );250 251 return jabber_start_stream( gc );249 set_login_progress( ic, 1, "Connected to server, logging in" ); 250 251 return jabber_start_stream( ic ); 252 252 } 253 253 254 254 gboolean jabber_connected_ssl( gpointer data, void *source, b_input_condition cond ) 255 255 { 256 struct gaim_connection *gc = data;257 struct jabber_data *jd = gc->proto_data;256 struct im_connection *ic = data; 257 struct jabber_data *jd = ic->proto_data; 258 258 259 259 if( source == NULL ) … … 263 263 jd->ssl = NULL; 264 264 265 hide_login_progress( gc, "Could not connect to server" );266 signoff( gc );265 hide_login_progress( ic, "Could not connect to server" ); 266 signoff( ic ); 267 267 return FALSE; 268 268 } 269 269 270 set_login_progress( gc, 1, "Connected to server, logging in" );271 272 return jabber_start_stream( gc );270 set_login_progress( ic, 1, "Connected to server, logging in" ); 271 272 return jabber_start_stream( ic ); 273 273 } 274 274 … … 281 281 static xt_status jabber_pkt_features( struct xt_node *node, gpointer data ) 282 282 { 283 struct gaim_connection *gc = data;284 struct jabber_data *jd = gc->proto_data;283 struct im_connection *ic = data; 284 struct jabber_data *jd = ic->proto_data; 285 285 struct xt_node *c, *reply; 286 286 int trytls; 287 287 288 trytls = g_strcasecmp( set_getstr( & gc->acc->set, "tls" ), "try" ) == 0;288 trytls = g_strcasecmp( set_getstr( &ic->acc->set, "tls" ), "try" ) == 0; 289 289 c = xt_find_node( node->children, "starttls" ); 290 290 if( c && !jd->ssl ) … … 295 295 c = xt_find_node( c->children, "required" ); 296 296 297 if( c && ( !trytls && !set_getbool( & gc->acc->set, "tls" ) ) )298 { 299 hide_login_progress( gc, "Server requires TLS connections, but TLS is turned off for this account" );300 signoff( gc );297 if( c && ( !trytls && !set_getbool( &ic->acc->set, "tls" ) ) ) 298 { 299 hide_login_progress( ic, "Server requires TLS connections, but TLS is turned off for this account" ); 300 signoff( ic ); 301 301 302 302 return XT_ABORT; … … 304 304 305 305 /* Only run this if the tls setting is set to true or try: */ 306 if( ( trytls || set_getbool( & gc->acc->set, "tls" ) ) )306 if( ( trytls || set_getbool( &ic->acc->set, "tls" ) ) ) 307 307 { 308 308 reply = xt_new_node( "starttls", NULL, NULL ); 309 309 xt_add_attr( reply, "xmlns", XMLNS_TLS ); 310 if( !jabber_write_packet( gc, reply ) )310 if( !jabber_write_packet( ic, reply ) ) 311 311 { 312 312 xt_free_node( reply ); … … 325 325 using SSL/TLS. */ 326 326 327 if( !trytls && set_getbool( & gc->acc->set, "tls" ) )328 { 329 hide_login_progress( gc, "TLS is turned on for this account, but is not supported by this server" );330 signoff( gc );327 if( !trytls && set_getbool( &ic->acc->set, "tls" ) ) 328 { 329 hide_login_progress( ic, "TLS is turned on for this account, but is not supported by this server" ); 330 signoff( ic ); 331 331 332 332 return XT_ABORT; … … 346 346 other way. jabber.com doesn't seem to do SASL while it pretends 347 347 to be XMPP 1.0 compliant! */ 348 else if( !( jd->flags & JFLAG_AUTHENTICATED ) && sasl_supported( gc ) )349 { 350 if( !jabber_init_iq_auth( gc ) )348 else if( !( jd->flags & JFLAG_AUTHENTICATED ) && sasl_supported( ic ) ) 349 { 350 if( !jabber_init_iq_auth( ic ) ) 351 351 return XT_ABORT; 352 352 } … … 354 354 if( ( c = xt_find_node( node->children, "bind" ) ) ) 355 355 { 356 reply = xt_new_node( "bind", NULL, xt_new_node( "resource", set_getstr( & gc->acc->set, "resource" ), NULL ) );356 reply = xt_new_node( "bind", NULL, xt_new_node( "resource", set_getstr( &ic->acc->set, "resource" ), NULL ) ); 357 357 xt_add_attr( reply, "xmlns", XMLNS_BIND ); 358 358 reply = jabber_make_packet( "iq", "set", NULL, reply ); 359 jabber_cache_add( gc, reply, jabber_pkt_bind_sess );360 361 if( !jabber_write_packet( gc, reply ) )359 jabber_cache_add( ic, reply, jabber_pkt_bind_sess ); 360 361 if( !jabber_write_packet( ic, reply ) ) 362 362 return XT_ABORT; 363 363 … … 370 370 xt_add_attr( reply, "xmlns", XMLNS_SESSION ); 371 371 reply = jabber_make_packet( "iq", "set", NULL, reply ); 372 jabber_cache_add( gc, reply, jabber_pkt_bind_sess );373 374 if( !jabber_write_packet( gc, reply ) )372 jabber_cache_add( ic, reply, jabber_pkt_bind_sess ); 373 374 if( !jabber_write_packet( ic, reply ) ) 375 375 return XT_ABORT; 376 376 … … 383 383 if( jd->flags & JFLAG_AUTHENTICATED && ( jd->flags & ( JFLAG_WAIT_BIND | JFLAG_WAIT_SESSION ) ) == 0 ) 384 384 { 385 if( !jabber_get_roster( gc ) )385 if( !jabber_get_roster( ic ) ) 386 386 return XT_ABORT; 387 387 } … … 392 392 static xt_status jabber_pkt_proceed_tls( struct xt_node *node, gpointer data ) 393 393 { 394 struct gaim_connection *gc = data;395 struct jabber_data *jd = gc->proto_data;394 struct im_connection *ic = data; 395 struct jabber_data *jd = ic->proto_data; 396 396 char *xmlns; 397 397 … … 417 417 jd->w_inpa = jd->r_inpa = 0; 418 418 419 set_login_progress( gc, 1, "Converting stream to TLS" );420 421 jd->ssl = ssl_starttls( jd->fd, jabber_connected_ssl, gc );419 set_login_progress( ic, 1, "Converting stream to TLS" ); 420 421 jd->ssl = ssl_starttls( jd->fd, jabber_connected_ssl, ic ); 422 422 423 423 return XT_HANDLED; … … 426 426 static xt_status jabber_pkt_stream_error( struct xt_node *node, gpointer data ) 427 427 { 428 struct gaim_connection *gc = data;428 struct im_connection *ic = data; 429 429 struct xt_node *c; 430 430 char *s, *type = NULL, *text = NULL; … … 452 452 if( type == NULL ) 453 453 { 454 hide_login_progress_error( gc, "Unknown stream error reported by server" );455 signoff( gc );454 hide_login_progress_error( ic, "Unknown stream error reported by server" ); 455 signoff( ic ); 456 456 return XT_ABORT; 457 457 } … … 462 462 if( strcmp( type, "conflict" ) == 0 ) 463 463 { 464 hide_login_progress( gc, "Account and resource used from a different location" );465 gc->wants_to_die = TRUE;464 hide_login_progress( ic, "Account and resource used from a different location" ); 465 ic->wants_to_die = TRUE; 466 466 } 467 467 else 468 468 { 469 469 s = g_strdup_printf( "Stream error: %s%s%s", type, text ? ": " : "", text ? text : "" ); 470 hide_login_progress_error( gc, s );470 hide_login_progress_error( ic, s ); 471 471 g_free( s ); 472 472 } 473 473 474 signoff( gc );474 signoff( ic ); 475 475 476 476 return XT_ABORT; … … 500 500 }; 501 501 502 gboolean jabber_start_stream( struct gaim_connection *gc )503 { 504 struct jabber_data *jd = gc->proto_data;502 gboolean jabber_start_stream( struct im_connection *ic ) 503 { 504 struct jabber_data *jd = ic->proto_data; 505 505 int st; 506 506 char *greet; … … 509 509 from the server too. */ 510 510 xt_free( jd->xt ); /* In case we're RE-starting. */ 511 jd->xt = xt_new( gc );511 jd->xt = xt_new( ic ); 512 512 jd->xt->handlers = (struct xt_handler_entry*) jabber_handlers; 513 513 514 514 if( jd->r_inpa <= 0 ) 515 jd->r_inpa = b_input_add( jd->fd, GAIM_INPUT_READ, jabber_read_callback, gc );515 jd->r_inpa = b_input_add( jd->fd, GAIM_INPUT_READ, jabber_read_callback, ic ); 516 516 517 517 greet = g_strdup_printf( "<?xml version='1.0' ?>" … … 519 519 "xmlns:stream=\"http://etherx.jabber.org/streams\" version=\"1.0\">", jd->server ); 520 520 521 st = jabber_write( gc, greet, strlen( greet ) );521 st = jabber_write( ic, greet, strlen( greet ) ); 522 522 523 523 g_free( greet ); … … 526 526 } 527 527 528 void jabber_end_stream( struct gaim_connection *gc )529 { 530 struct jabber_data *jd = gc->proto_data;528 void jabber_end_stream( struct im_connection *ic ) 529 { 530 struct jabber_data *jd = ic->proto_data; 531 531 532 532 /* Let's only do this if the queue is currently empty, otherwise it'd … … 538 538 int st = 1; 539 539 540 if( gc->flags & OPT_LOGGED_IN )540 if( ic->flags & OPT_LOGGED_IN ) 541 541 { 542 542 node = jabber_make_packet( "presence", "unavailable", NULL, NULL ); 543 st = jabber_write_packet( gc, node );543 st = jabber_write_packet( ic, node ); 544 544 xt_free_node( node ); 545 545 } 546 546 547 547 if( st ) 548 jabber_write( gc, eos, strlen( eos ) );549 } 550 } 548 jabber_write( ic, eos, strlen( eos ) ); 549 } 550 }
Note: See TracChangeset
for help on using the changeset viewer.