- Timestamp:
- 2006-09-20T19:42:27Z (18 years ago)
- Branches:
- master
- Children:
- 70f6aab8
- Parents:
- f06894d
- Location:
- protocols/jabber
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/Makefile
rf06894d r21167d2 10 10 11 11 # [SH] Program variables 12 objects = i q.o jabber.o jabber_util.o message.o presence.o xmltree.o12 objects = io.o iq.o jabber.o jabber_util.o message.o presence.o xmltree.o 13 13 14 14 CFLAGS += -Wall -
protocols/jabber/iq.c
rf06894d r21167d2 24 24 #include "jabber.h" 25 25 26 /* 27 <iq xmlns="jabber:client" id="BeeX00000001" type="result"><query 28 xmlns="jabber:iq:auth"><username>wilmer</username><resource/><password/><digest/> 29 <sequence>499</sequence><token>450D1FFD</token></query></iq> 30 */ 31 26 32 xt_status jabber_pkt_iq( struct xt_node *node, gpointer data ) 27 33 { 28 char *from = xt_find_attr( node, "from" ); 34 struct gaim_connection *gc = data; 35 struct jabber_data *jd = gc->proto_data; 36 struct xt_node *query, *reply = NULL; 37 char *s; 38 int st; 29 39 30 printf( "Received IQ from %s:\n", from ); 31 xt_print( node ); 40 query = xt_find_node( node->children, "query" ); 41 42 if( !query ) 43 return XT_HANDLED; /* Ignore it for now, don't know what's best... */ 44 45 if( ( s = xt_find_attr( query, "xmlns" ) ) && strcmp( s, "jabber:iq:auth" ) == 0 ) 46 { 47 /* Time to authenticate ourselves! */ 48 reply = xt_new_node( "query", NULL, NULL ); 49 xt_add_attr( reply, "xmlns", "jabber:iq:auth" ); 50 xt_add_child( reply, xt_new_node( "username", jd->username, NULL ) ); 51 xt_add_child( reply, xt_new_node( "resource", set_getstr( &gc->acc->set, "resource" ), NULL ) ); 52 53 if( xt_find_node( query->children, "digest" ) && ( s = xt_find_attr( jd->xt->root, "id" ) ) ) 54 { 55 /* We can do digest authentication, it seems, and of 56 course we prefer that. */ 57 SHA_CTX sha; 58 char hash_hex[40]; 59 unsigned char hash[20]; 60 int i; 61 62 shaInit( &sha ); 63 shaUpdate( &sha, (unsigned char*) s, strlen( s ) ); 64 shaUpdate( &sha, (unsigned char*) gc->acc->pass, strlen( gc->acc->pass ) ); 65 shaFinal( &sha, hash ); 66 67 for( i = 0; i < 20; i ++ ) 68 sprintf( hash_hex + i * 2, "%02x", hash[i] ); 69 70 xt_add_child( reply, xt_new_node( "digest", hash_hex, NULL ) ); 71 } 72 else if( xt_find_node( query->children, "password" ) ) 73 { 74 /* We'll have to stick with plaintext. Let's hope we're using SSL/TLS... */ 75 xt_add_child( reply, xt_new_node( "password", gc->acc->pass, NULL ) ); 76 } 77 else 78 { 79 xt_free_node( reply ); 80 81 hide_login_progress_error( gc, "Can't find suitable authentication method" ); 82 signoff( gc ); 83 return XT_ABORT; 84 } 85 86 reply = jabber_make_packet( "iq", "set", NULL, reply ); 87 st = jabber_write_packet( gc, reply ); 88 xt_free_node( reply ); 89 90 return st ? XT_HANDLED : XT_ABORT; 91 } 32 92 33 93 return XT_HANDLED; 34 94 } 35 95 96 int jabber_start_auth( struct gaim_connection *gc ) 97 { 98 struct jabber_data *jd = gc->proto_data; 99 struct xt_node *node; 100 int st; 101 102 node = xt_new_node( "query", NULL, xt_new_node( "username", jd->username, NULL ) ); 103 xt_add_attr( node, "xmlns", "jabber:iq:auth" ); 104 node = jabber_make_packet( "iq", "get", NULL, node ); 105 106 st = jabber_write_packet( gc, node ); 107 108 xt_free_node( node ); 109 return st; 110 } -
protocols/jabber/jabber.c
rf06894d r21167d2 28 28 #include <stdio.h> 29 29 30 #include "ssl_client.h" 30 31 #include "xmltree.h" 31 32 #include "bitlbee.h" … … 55 56 static void jabber_login( account_t *acc ) 56 57 { 58 struct gaim_connection *gc = new_gaim_conn( acc ); 59 struct jabber_data *jd = g_new0( struct jabber_data, 1 ); 60 61 jd->gc = gc; 62 gc->proto_data = jd; 63 64 jd->username = g_strdup( acc->user ); 65 jd->server = strchr( jd->username, '@' ); 66 67 if( jd->server == NULL ) 68 { 69 hide_login_progress( gc, "Incomplete account name (format it like <username@jabberserver.name>)" ); 70 signoff( gc ); 71 return; 72 } 73 74 /* So don't think of free()ing jd->server.. :-) */ 75 *jd->server = 0; 76 jd->server ++; 77 78 if( set_getbool( &acc->set, "ssl" ) ) 79 { 80 signoff( gc ); 81 /* TODO! */ 82 } 83 else 84 { 85 jd->fd = proxy_connect( jd->server, set_getint( &acc->set, "port" ), jabber_connected_plain, gc ); 86 } 57 87 } 58 88 59 89 static void jabber_close( struct gaim_connection *gc ) 60 90 { 91 struct jabber_data *jd = gc->proto_data; 92 93 if( jd->r_inpa >= 0 ) 94 b_event_remove( jd->r_inpa ); 95 if( jd->w_inpa >= 0 ) 96 b_event_remove( jd->w_inpa ); 97 98 if( jd->ssl ) 99 ssl_disconnect( jd->ssl ); 100 if( jd->fd >= 0 ) 101 closesocket( jd->fd ); 102 103 g_free( jd->username ); 104 g_free( jd ); 61 105 } 62 106 63 107 static int jabber_send_im( struct gaim_connection *gc, char *who, char *message, int len, int away ) 64 108 { 109 return 0; 65 110 } 66 111 … … 96 141 } 97 142 98 static xt_status jabber_end_of_stream( struct xt_node *node, gpointer data )99 {100 return XT_ABORT;101 }102 103 static xt_status jabber_pkt_misc( struct xt_node *node, gpointer data )104 {105 printf( "Received unknown packet:\n" );106 xt_print( node );107 108 return XT_HANDLED;109 }110 111 static const struct xt_handler_entry jabber_handlers[] = {112 { "stream:stream", "<root>", jabber_end_of_stream },113 { "iq", "stream:stream", jabber_pkt_iq },114 { "message", "stream:stream", jabber_pkt_message },115 { "presence", "stream:stream", jabber_pkt_presence },116 { NULL, "stream:stream", jabber_pkt_misc },117 { NULL, NULL, NULL }118 };119 120 143 #if 0 121 144 int main( int argc, char *argv[] ) -
protocols/jabber/jabber.h
rf06894d r21167d2 30 30 #include "bitlbee.h" 31 31 32 typedef enum 33 { 34 JFLAG_STREAM_STARTED = 1, 35 JFLAG_AUTHENTICATED = 2, 36 } jabber_flags_t; 37 38 /* iq.c */ 32 39 xt_status jabber_pkt_iq( struct xt_node *node, gpointer data ); 40 int jabber_start_auth( struct gaim_connection *gc ); 41 33 42 xt_status jabber_pkt_message( struct xt_node *node, gpointer data ); 34 43 xt_status jabber_pkt_presence( struct xt_node *node, gpointer data ); 35 44 45 /* jabber_util.c */ 36 46 char *set_eval_resprio( set_t *set, char *value ); 37 47 char *set_eval_tls( set_t *set, char *value ); 48 struct xt_node *jabber_make_packet( char *name, char *type, char *to, struct xt_node *children ); 49 50 /* io.c */ 51 int jabber_write_packet( struct gaim_connection *gc, struct xt_node *node ); 52 int jabber_write( struct gaim_connection *gc, char *buf, int len ); 53 gboolean jabber_connected_plain( gpointer data, gint source, b_input_condition cond ); 54 55 struct jabber_data 56 { 57 struct gaim_connection *gc; 58 59 int fd; 60 void *ssl; 61 char *txq; 62 int tx_len; 63 int r_inpa, w_inpa; 64 65 struct xt_parser *xt; 66 jabber_flags_t flags; 67 68 char *username; /* USERNAME@server */ 69 char *server; /* username@SERVER -=> server/domain, not hostname */ 70 }; 38 71 39 72 #endif -
protocols/jabber/jabber_util.c
rf06894d r21167d2 2 2 * * 3 3 * BitlBee - An IRC to IM gateway * 4 * Jabber module - M ain file*4 * Jabber module - Misc. stuff * 5 5 * * 6 6 * Copyright 2006 Wilmer van der Gaast <wilmer@gaast.net> * … … 23 23 24 24 #include "jabber.h" 25 26 static int next_id = 1; 25 27 26 28 char *set_eval_resprio( set_t *set, char *value ) … … 47 49 return set_eval_bool( set, value ); 48 50 } 51 52 struct xt_node *jabber_make_packet( char *name, char *type, char *to, struct xt_node *children ) 53 { 54 char *id = g_strdup_printf( "BeeX%04x", next_id++ ); 55 struct xt_node *node; 56 57 node = xt_new_node( name, NULL, children ); 58 59 xt_add_attr( node, "id", id ); 60 if( type ) 61 xt_add_attr( node, "type", type ); 62 if( to ) 63 xt_add_attr( node, "to", to ); 64 65 g_free( id ); 66 67 return node; 68 } -
protocols/jabber/message.c
rf06894d r21167d2 2 2 * * 3 3 * BitlBee - An IRC to IM gateway * 4 * Jabber module - Main file*4 * Jabber module - Handling of message(s) (tags), etc * 5 5 * * 6 6 * Copyright 2006 Wilmer van der Gaast <wilmer@gaast.net> * -
protocols/jabber/presence.c
rf06894d r21167d2 2 2 * * 3 3 * BitlBee - An IRC to IM gateway * 4 * Jabber module - Main file*4 * Jabber module - Handling of presence (tags), etc * 5 5 * * 6 6 * Copyright 2006 Wilmer van der Gaast <wilmer@gaast.net> * -
protocols/jabber/xmltree.c
rf06894d r21167d2 206 206 struct xt_node *c, *prev; 207 207 208 /* Let's just hope xt->root isn't NULL! */ 208 if( !xt || !xt->root ) 209 return; 210 209 211 if( node == NULL ) 210 212 return xt_cleanup( xt, xt->root ); … … 357 359 int i; 358 360 361 if( !node ) 362 return; 363 359 364 g_free( node->name ); 360 365 g_free( node->text ); … … 380 385 void xt_free( struct xt_parser *xt ) 381 386 { 387 if( !xt ) 388 return; 389 382 390 if( xt->root ) 383 391 xt_free_node( xt->root ); … … 407 415 { 408 416 int i; 417 418 if( !node ) 419 return NULL; 409 420 410 421 for( i = 0; node->attr[i].key; i ++ )
Note: See TracChangeset
for help on using the changeset viewer.