- Timestamp:
- 2006-09-24T11:57:45Z (18 years ago)
- Branches:
- master
- Children:
- e101506
- Parents:
- 172a73f1
- Location:
- protocols/jabber
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/io.c
r172a73f1 r42127dc 23 23 24 24 #include "jabber.h" 25 #include "ssl_client.h" 25 26 26 27 static gboolean jabber_write_callback( gpointer data, gint fd, b_input_condition cond ); … … 76 77 return FALSE; 77 78 78 st = write( jd->fd, jd->txq, jd->tx_len ); 79 if( jd->ssl ) 80 st = ssl_write( jd->ssl, jd->txq, jd->tx_len ); 81 else 82 st = write( jd->fd, jd->txq, jd->tx_len ); 83 84 // if( st > 0 ) write( 1, jd->txq, st ); 79 85 80 86 if( st == jd->tx_len ) … … 126 132 return FALSE; 127 133 128 st = read( fd, buf, sizeof( buf ) ); 134 if( jd->ssl ) 135 st = ssl_read( jd->ssl, buf, sizeof( buf ) ); 136 else 137 st = read( jd->fd, buf, sizeof( buf ) ); 138 139 // if( st > 0 ) write( 1, buf, st ); 129 140 130 141 if( st > 0 ) … … 210 221 } 211 222 223 gboolean jabber_connected_ssl( gpointer data, void *source, b_input_condition cond ) 224 { 225 struct gaim_connection *gc = data; 226 227 if( source == NULL ) 228 { 229 hide_login_progress( gc, "Could not connect to server" ); 230 signoff( gc ); 231 return FALSE; 232 } 233 234 set_login_progress( gc, 1, "Connected to server, logging in" ); 235 236 return jabber_start_stream( gc ); 237 } 238 212 239 static xt_status jabber_end_of_stream( struct xt_node *node, gpointer data ) 213 240 { … … 222 249 223 250 c = xt_find_node( node->children, "starttls" ); 224 if( c ) 225 { 226 /* 227 jd->flags |= JFLAG_SUPPORTS_TLS; 228 if( xt_find_node( c->children, "required" ) ) 229 jd->flags |= JFLAG_REQUIRES_TLS; 230 */ 231 } 251 if( c && !jd->ssl ) 252 { 253 /* If the server advertises the STARTTLS feature and if we're 254 not in a secure connection already: */ 255 256 int try; 257 258 try = g_strcasecmp( set_getstr( &gc->acc->set, "tls" ), "try" ) == 0; 259 c = xt_find_node( c->children, "required" ); 260 261 /* Only run this if the tls setting is set to true or try: */ 262 if( ( try | set_getbool( &gc->acc->set, "tls" ) ) ) 263 { 264 reply = xt_new_node( "starttls", NULL, NULL ); 265 xt_add_attr( reply, "xmlns", "urn:ietf:params:xml:ns:xmpp-tls" ); 266 if( !jabber_write_packet( gc, reply ) ) 267 { 268 xt_free_node( reply ); 269 return XT_ABORT; 270 } 271 xt_free_node( reply ); 272 273 return XT_HANDLED; 274 } 275 } 276 else 277 { 278 /* TODO: Abort if TLS is required by the user. */ 279 } 280 281 /* This one used to be in jabber_handlers[], but it has to be done 282 from here to make sure the TLS session will be initialized 283 properly before we attempt SASL authentication. */ 284 if( ( c = xt_find_node( node->children, "mechanisms" ) ) ) 285 if( sasl_pkt_mechanisms( c, data ) == XT_ABORT ) 286 return XT_ABORT; 232 287 233 288 if( ( c = xt_find_node( node->children, "bind" ) ) ) … … 265 320 return XT_ABORT; 266 321 } 322 323 return XT_HANDLED; 324 } 325 326 static xt_status jabber_pkt_proceed_tls( struct xt_node *node, gpointer data ) 327 { 328 struct gaim_connection *gc = data; 329 struct jabber_data *jd = gc->proto_data; 330 char *xmlns; 331 332 xmlns = xt_find_attr( node, "xmlns" ); 333 334 /* Just ignore it when it doesn't seem to be TLS-related (is that at 335 all possible??). */ 336 if( !xmlns || strcmp( xmlns, "urn:ietf:params:xml:ns:xmpp-tls" ) != 0 ) 337 return XT_HANDLED; 338 339 /* We don't want event handlers to touch our TLS session while it's 340 still initializing! */ 341 b_event_remove( jd->r_inpa ); 342 if( jd->tx_len > 0 ) 343 { 344 /* Actually the write queue should be empty here, but just 345 to be sure... */ 346 b_event_remove( jd->w_inpa ); 347 g_free( jd->txq ); 348 jd->txq = NULL; 349 jd->tx_len = 0; 350 } 351 jd->w_inpa = jd->r_inpa = 0; 352 353 set_login_progress( gc, 1, "Converting stream to TLS" ); 354 355 jd->ssl = ssl_starttls( jd->fd, jabber_connected_ssl, gc ); 267 356 268 357 return XT_HANDLED; … … 283 372 { "iq", "stream:stream", jabber_pkt_iq }, 284 373 { "stream:features", "stream:stream", jabber_pkt_features }, 285 { " mechanisms", "stream:features", sasl_pkt_mechanisms },374 { "proceed", "stream:stream", jabber_pkt_proceed_tls }, 286 375 { "challenge", "stream:stream", sasl_pkt_challenge }, 287 376 { "success", "stream:stream", sasl_pkt_result }, -
protocols/jabber/jabber.c
r172a73f1 r42127dc 80 80 if( set_getbool( &acc->set, "ssl" ) ) 81 81 { 82 signoff(gc );83 /* TODO! */82 jd->ssl = ssl_connect( jd->server, set_getint( &acc->set, "port" ), jabber_connected_ssl, gc ); 83 jd->fd = ssl_getfd( jd->ssl ); 84 84 } 85 85 else -
protocols/jabber/jabber.h
r172a73f1 r42127dc 95 95 int jabber_write( struct gaim_connection *gc, char *buf, int len ); 96 96 gboolean jabber_connected_plain( gpointer data, gint source, b_input_condition cond ); 97 gboolean jabber_connected_ssl( gpointer data, void *source, b_input_condition cond ); 97 98 gboolean jabber_start_stream( struct gaim_connection *gc ); 98 99 void jabber_end_stream( struct gaim_connection *gc );
Note: See TracChangeset
for help on using the changeset viewer.