Changeset 178e2f8 for protocols/jabber/jabber_util.c
- Timestamp:
- 2008-06-28T17:32:41Z (16 years ago)
- Branches:
- master
- Children:
- 47b571d
- Parents:
- 2e0f24d (diff), e0f9170 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/jabber_util.c
r2e0f24d r178e2f8 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; … … 134 136 struct jabber_data *jd = ic->proto_data; 135 137 struct jabber_cache_entry *entry = g_new0( struct jabber_cache_entry, 1 ); 136 char *id; 137 138 id = g_strdup_printf( "%s%05x", jd->cached_id_prefix, ( next_id++ ) & 0xfffff ); 138 md5_state_t id_hash; 139 md5_byte_t id_sum[16]; 140 char *id, *asc_hash; 141 142 next_id ++; 143 144 id_hash = jd->cached_id_prefix; 145 md5_append( &id_hash, (md5_byte_t*) &next_id, sizeof( next_id ) ); 146 md5_finish( &id_hash, id_sum ); 147 asc_hash = base64_encode( id_sum, 12 ); 148 149 id = g_strdup_printf( "%s%s", JABBER_CACHED_ID, asc_hash ); 139 150 xt_add_attr( node, "id", id ); 140 151 g_free( id ); 152 g_free( asc_hash ); 141 153 142 154 entry->node = node; … … 184 196 185 197 if( ( s = xt_find_attr( node, "id" ) ) == NULL || 186 strncmp( s, jd->cached_id_prefix, strlen( jd->cached_id_prefix) ) != 0 )198 strncmp( s, JABBER_CACHED_ID, strlen( JABBER_CACHED_ID ) ) != 0 ) 187 199 { 188 200 /* Silently ignore it, without an ID (or a non-cache … … 196 208 if( entry == NULL ) 197 209 { 210 /* 211 There's no longer an easy way to see if we generated this 212 one or someone else, and there's a ten-minute timeout anyway, 213 so meh. 214 198 215 imcb_log( ic, "Warning: Received %s-%s packet with unknown/expired ID %s!", 199 216 node->name, xt_find_attr( node, "type" ) ? : "(no type)", s ); 217 */ 200 218 } 201 219 else if( entry->func ) … … 290 308 len = strlen( orig ); 291 309 new = g_new( char, len + 1 ); 292 for( i = 0; i < len; i ++ ) 310 311 /* So it turns out the /resource part is case sensitive. Yeah, and 312 it's Unicode but feck Unicode. :-P So stop once we see a slash. */ 313 for( i = 0; i < len && orig[i] != '/' ; i ++ ) 293 314 new[i] = tolower( orig[i] ); 315 for( ; orig[i]; i ++ ) 316 new[i] = orig[i]; 294 317 295 318 new[i] = 0; … … 334 357 { 335 358 /* Check for dupes. */ 336 if( g_strcasecmp( bi->resource, s + 1 ) == 0 )359 if( strcmp( bi->resource, s + 1 ) == 0 ) 337 360 { 338 361 *s = '/'; … … 387 410 if( ( s = strchr( jid, '/' ) ) ) 388 411 { 389 int none_found= 0;412 int bare_exists = 0; 390 413 391 414 *s = 0; … … 410 433 /* See if there's an exact match. */ 411 434 for( ; bud; bud = bud->next ) 412 if( g_strcasecmp( bud->resource, s + 1 ) == 0 )435 if( strcmp( bud->resource, s + 1 ) == 0 ) 413 436 break; 414 437 } 415 438 else 416 439 { 417 /* This hack is there to make sure that O_CREAT will 418 work if there's already another resouce present 419 for this JID, even if it's an unknown buddy. This 420 is done to handle conferences properly. */ 421 none_found = 1; 422 /* TODO(wilmer): Find out what I was thinking when I 423 wrote this??? And then fix it. This makes me sad... */ 424 } 425 426 if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && ( imcb_find_buddy( ic, jid ) || !none_found ) ) 440 /* This variable tells the if down here that the bare 441 JID already exists and we should feel free to add 442 more resources, if the caller asked for that. */ 443 bare_exists = 1; 444 } 445 446 if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && 447 ( !bare_exists || imcb_find_buddy( ic, jid ) ) ) 427 448 { 428 449 *s = '/'; … … 449 470 /* We want an exact match, so in thise case there shouldn't be a /resource. */ 450 471 return NULL; 451 else if( ( bud->resource == NULL || bud->next == NULL ))472 else if( bud->resource == NULL || bud->next == NULL ) 452 473 /* No need for selection if there's only one option. */ 453 474 return bud; … … 525 546 matches), removing it is simple. (And the hash reference 526 547 should be removed too!) */ 527 if( bud->next == NULL && ( ( s == NULL || bud->resource == NULL ) || g_strcasecmp( bud->resource, s + 1 ) == 0 ) ) 548 if( bud->next == NULL && 549 ( ( s == NULL && bud->resource == NULL ) || 550 ( bud->resource && s && strcmp( bud->resource, s + 1 ) == 0 ) ) ) 528 551 { 529 552 g_hash_table_remove( jd->buddies, bud->bare_jid ); … … 548 571 { 549 572 for( bi = bud, prev = NULL; bi; bi = (prev=bi)->next ) 550 if( g_strcasecmp( bi->resource, s + 1 ) == 0 )573 if( strcmp( bi->resource, s + 1 ) == 0 ) 551 574 break; 552 575
Note: See TracChangeset
for help on using the changeset viewer.