Changeset 8661caa for protocols/jabber
- Timestamp:
- 2008-08-04T14:45:24Z (16 years ago)
- Branches:
- master
- Children:
- 87f525e
- Parents:
- 4ac647d (diff), 718e05f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- protocols/jabber
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/jabber.c
r4ac647d r8661caa 33 33 #include "jabber.h" 34 34 #include "md5.h" 35 #include "base64.h"36 35 37 36 GSList *jabber_connections; 38 37 38 /* First enty is the default */ 39 static const int jabber_port_list[] = { 40 5222, 41 5223, 42 5220, 43 5221, 44 5224, 45 5225, 46 5226, 47 5227, 48 5228, 49 5229, 50 80, 51 443, 52 0 53 }; 54 39 55 static void jabber_init( account_t *acc ) 40 56 { 41 57 set_t *s; 42 43 s = set_add( &acc->set, "port", JABBER_PORT_DEFAULT, set_eval_int, acc ); 58 char str[16]; 59 60 g_snprintf( str, sizeof( str ), "%d", jabber_port_list[0] ); 61 s = set_add( &acc->set, "port", str, set_eval_int, acc ); 44 62 s->flags |= ACC_SET_OFFLINE_ONLY; 45 63 … … 74 92 struct ns_srv_reply *srv = NULL; 75 93 char *connect_to, *s; 94 int i; 76 95 77 96 /* For now this is needed in the _connected() handlers if using … … 179 198 imcb_log( ic, "Connecting" ); 180 199 181 if( set_getint( &acc->set, "port" ) < JABBER_PORT_MIN || 182 set_getint( &acc->set, "port" ) > JABBER_PORT_MAX ) 183 { 184 imcb_log( ic, "Incorrect port number, must be in the %d-%d range", 185 JABBER_PORT_MIN, JABBER_PORT_MAX ); 200 for( i = 0; jabber_port_list[i] > 0; i ++ ) 201 if( set_getint( &acc->set, "port" ) == jabber_port_list[i] ) 202 break; 203 204 if( jabber_port_list[i] == 0 ) 205 { 206 imcb_log( ic, "Illegal port number" ); 186 207 imc_logout( ic, FALSE ); 187 208 return; … … 221 242 } 222 243 244 /* This generates an unfinished md5_state_t variable. Every time we generate 245 an ID, we finish the state by adding a sequence number and take the hash. */ 223 246 static void jabber_generate_id_hash( struct jabber_data *jd ) 224 247 { 225 md5_state_t id_hash; 226 md5_byte_t binbuf[16]; 248 md5_byte_t binbuf[4]; 227 249 char *s; 228 250 229 md5_init( & id_hash);230 md5_append( & id_hash, (unsigned char *) jd->username, strlen( jd->username ) );231 md5_append( & id_hash, (unsigned char *) jd->server, strlen( jd->server ) );251 md5_init( &jd->cached_id_prefix ); 252 md5_append( &jd->cached_id_prefix, (unsigned char *) jd->username, strlen( jd->username ) ); 253 md5_append( &jd->cached_id_prefix, (unsigned char *) jd->server, strlen( jd->server ) ); 232 254 s = set_getstr( &jd->ic->acc->set, "resource" ); 233 md5_append( &id_hash, (unsigned char *) s, strlen( s ) ); 234 random_bytes( binbuf, 16 ); 235 md5_append( &id_hash, binbuf, 16 ); 236 md5_finish( &id_hash, binbuf ); 237 238 s = base64_encode( binbuf, 9 ); 239 jd->cached_id_prefix = g_strdup_printf( "%s%s", JABBER_CACHED_ID, s ); 240 g_free( s ); 255 md5_append( &jd->cached_id_prefix, (unsigned char *) s, strlen( s ) ); 256 random_bytes( binbuf, 4 ); 257 md5_append( &jd->cached_id_prefix, binbuf, 4 ); 241 258 } 242 259 … … 281 298 xt_free( jd->xt ); 282 299 283 g_free( jd->cached_id_prefix );284 300 g_free( jd->away_message ); 285 301 g_free( jd->username ); -
protocols/jabber/jabber.h
r4ac647d r8661caa 94 94 char *away_message; 95 95 96 char *cached_id_prefix;96 md5_state_t cached_id_prefix; 97 97 GHashTable *node_cache; 98 98 GHashTable *buddies; … … 177 177 178 178 #define JABBER_XMLCONSOLE_HANDLE "xmlconsole" 179 180 #define JABBER_PORT_DEFAULT "5222"181 #define JABBER_PORT_MIN 5220182 #define JABBER_PORT_MAX 5229183 179 184 180 /* Prefixes to use for packet IDs (mainly for IQ packets ATM). Usually the -
protocols/jabber/jabber_util.c
r4ac647d r8661caa 23 23 24 24 #include "jabber.h" 25 #include "md5.h" 26 #include "base64.h" 25 27 26 28 static unsigned int next_id = 1; … … 138 140 struct jabber_data *jd = ic->proto_data; 139 141 struct jabber_cache_entry *entry = g_new0( struct jabber_cache_entry, 1 ); 140 char *id; 141 142 id = g_strdup_printf( "%s%05x", jd->cached_id_prefix, ( next_id++ ) & 0xfffff ); 142 md5_state_t id_hash; 143 md5_byte_t id_sum[16]; 144 char *id, *asc_hash; 145 146 next_id ++; 147 148 id_hash = jd->cached_id_prefix; 149 md5_append( &id_hash, (md5_byte_t*) &next_id, sizeof( next_id ) ); 150 md5_finish( &id_hash, id_sum ); 151 asc_hash = base64_encode( id_sum, 12 ); 152 153 id = g_strdup_printf( "%s%s", JABBER_CACHED_ID, asc_hash ); 143 154 xt_add_attr( node, "id", id ); 144 155 g_free( id ); 156 g_free( asc_hash ); 145 157 146 158 entry->node = node; … … 188 200 189 201 if( ( s = xt_find_attr( node, "id" ) ) == NULL || 190 strncmp( s, jd->cached_id_prefix, strlen( jd->cached_id_prefix) ) != 0 )202 strncmp( s, JABBER_CACHED_ID, strlen( JABBER_CACHED_ID ) ) != 0 ) 191 203 { 192 204 /* Silently ignore it, without an ID (or a non-cache … … 200 212 if( entry == NULL ) 201 213 { 214 /* 215 There's no longer an easy way to see if we generated this 216 one or someone else, and there's a ten-minute timeout anyway, 217 so meh. 218 202 219 imcb_log( ic, "Warning: Received %s-%s packet with unknown/expired ID %s!", 203 220 node->name, xt_find_attr( node, "type" ) ? : "(no type)", s ); 221 */ 204 222 } 205 223 else if( entry->func ) … … 294 312 len = strlen( orig ); 295 313 new = g_new( char, len + 1 ); 296 for( i = 0; i < len; i ++ ) 297 { 298 /* don't normalize the resource */ 299 if( orig[i] == '/' ) 300 break; 314 315 /* So it turns out the /resource part is case sensitive. Yeah, and 316 it's Unicode but feck Unicode. :-P So stop once we see a slash. */ 317 for( i = 0; i < len && orig[i] != '/' ; i ++ ) 301 318 new[i] = tolower( orig[i] ); 302 } 303 for( ; i < len; i ++ ) 319 for( ; orig[i]; i ++ ) 304 320 new[i] = orig[i]; 305 321 … … 345 361 { 346 362 /* Check for dupes. */ 347 if( g_strcasecmp( bi->resource, s + 1 ) == 0 )363 if( strcmp( bi->resource, s + 1 ) == 0 ) 348 364 { 349 365 *s = '/'; … … 398 414 if( ( s = strchr( jid, '/' ) ) ) 399 415 { 400 int none_found= 0;416 int bare_exists = 0; 401 417 402 418 *s = 0; … … 421 437 /* See if there's an exact match. */ 422 438 for( ; bud; bud = bud->next ) 423 if( g_strcasecmp( bud->resource, s + 1 ) == 0 )439 if( strcmp( bud->resource, s + 1 ) == 0 ) 424 440 break; 425 441 } 426 442 else 427 443 { 428 /* This hack is there to make sure that O_CREAT will 429 work if there's already another resouce present 430 for this JID, even if it's an unknown buddy. This 431 is done to handle conferences properly. */ 432 none_found = 1; 433 /* TODO(wilmer): Find out what I was thinking when I 434 wrote this??? And then fix it. This makes me sad... */ 435 } 436 437 if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && ( imcb_find_buddy( ic, jid ) || !none_found ) ) 444 /* This variable tells the if down here that the bare 445 JID already exists and we should feel free to add 446 more resources, if the caller asked for that. */ 447 bare_exists = 1; 448 } 449 450 if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && 451 ( !bare_exists || imcb_find_buddy( ic, jid ) ) ) 438 452 { 439 453 *s = '/'; … … 460 474 /* We want an exact match, so in thise case there shouldn't be a /resource. */ 461 475 return NULL; 462 else if( ( bud->resource == NULL || bud->next == NULL ))476 else if( bud->resource == NULL || bud->next == NULL ) 463 477 /* No need for selection if there's only one option. */ 464 478 return bud; … … 536 550 matches), removing it is simple. (And the hash reference 537 551 should be removed too!) */ 538 if( bud->next == NULL && ( ( s == NULL || bud->resource == NULL ) || g_strcasecmp( bud->resource, s + 1 ) == 0 ) ) 552 if( bud->next == NULL && 553 ( ( s == NULL && bud->resource == NULL ) || 554 ( bud->resource && s && strcmp( bud->resource, s + 1 ) == 0 ) ) ) 539 555 { 540 556 g_hash_table_remove( jd->buddies, bud->bare_jid ); … … 559 575 { 560 576 for( bi = bud, prev = NULL; bi; bi = (prev=bi)->next ) 561 if( g_strcasecmp( bi->resource, s + 1 ) == 0 )577 if( strcmp( bi->resource, s + 1 ) == 0 ) 562 578 break; 563 579 -
protocols/jabber/message.c
r4ac647d r8661caa 49 49 { 50 50 GString *fullmsg = g_string_new( "" ); 51 52 for( c = node->children; ( c = xt_find_node( c, "x" ) ); c = c->next ) 53 { 54 char *ns = xt_find_attr( c, "xmlns" ), *room; 55 struct xt_node *inv, *reason; 56 57 if( strcmp( ns, XMLNS_MUC_USER ) == 0 && 58 ( inv = xt_find_node( c->children, "invite" ) ) ) 59 { 60 room = from; 61 from = xt_find_attr( inv, "from" ) ? : from; 62 63 g_string_append_printf( fullmsg, "<< \002BitlBee\002 - Invitation to chatroom %s >>\n", room ); 64 if( ( reason = xt_find_node( inv->children, "reason" ) ) && reason->text_len > 0 ) 65 g_string_append( fullmsg, reason->text ); 66 } 67 } 51 68 52 69 if( ( s = strchr( from, '/' ) ) )
Note: See TracChangeset
for help on using the changeset viewer.