Changes in protocols/msn/msn_util.c [4255320:4452e69]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/msn/msn_util.c
r4255320 r4452e69 2 2 * BitlBee -- An IRC to other IM-networks gateway * 3 3 * * 4 * Copyright 2002-20 04Wilmer van der Gaast and others *4 * Copyright 2002-2010 Wilmer van der Gaast and others * 5 5 \********************************************************************/ 6 6 … … 26 26 #include "nogaim.h" 27 27 #include "msn.h" 28 #include "md5.h" 28 29 #include <ctype.h> 29 30 … … 32 33 struct msn_data *md = ic->proto_data; 33 34 int st; 35 36 if( getenv( "BITLBEE_DEBUG" ) ) 37 { 38 write( 2, "->NS:", 5 ); 39 write( 2, s, len ); 40 } 34 41 35 42 st = write( md->fd, s, len ); … … 54 61 { 55 62 struct msn_data *md = ic->proto_data; 56 char buf[1024], *realname, groupid[8];63 char buf[1024], realname[strlen(realname_)*3+1], groupid[8]; 57 64 58 65 *groupid = '\0'; … … 87 94 if( l == NULL ) 88 95 { 89 char *groupname = msn_http_encode( group ); 96 char groupname[strlen(group)+1]; 97 strcpy( groupname, group ); 98 http_encode( groupname ); 90 99 g_snprintf( buf, sizeof( buf ), "ADG %d %s %d\r\n", ++md->trId, groupname, 0 ); 91 g_free( groupname );92 100 return msn_write( ic, buf, strlen( buf ) ); 93 101 } … … 102 110 } 103 111 104 realname = msn_http_encode( realname_ ); 112 strcpy( realname, realname_ ); 113 http_encode( realname ); 105 114 g_snprintf( buf, sizeof( buf ), "ADD %d %s %s %s%s\r\n", ++md->trId, list, who, realname, groupid ); 106 g_free( realname );107 115 108 116 return msn_write( ic, buf, strlen( buf ) ); … … 279 287 if( st <= 0 ) 280 288 return( -1 ); 289 290 if( getenv( "BITLBEE_DEBUG" ) ) 291 { 292 write( 2, "->C:", 4 ); 293 write( 2, h->rxq + h->rxlen - st, st ); 294 } 281 295 282 296 while( st ) … … 367 381 } 368 382 369 /* The difference between this function and the normal http_encode() function370 is that this one escapes every 7-bit ASCII character because this is said371 to avoid some lame server-side checks when setting a real-name. Also,372 non-ASCII characters are not escaped because MSN servers don't seem to373 appreciate that! */374 char *msn_http_encode( const char *input )375 {376 char *ret, *s;377 int i;378 379 ret = s = g_new0( char, strlen( input ) * 3 + 1 );380 for( i = 0; input[i]; i ++ )381 if( input[i] & 128 )382 {383 *s = input[i];384 s ++;385 }386 else387 {388 g_snprintf( s, 4, "%%%02X", input[i] );389 s += 3;390 }391 392 return ret;393 }394 395 383 void msn_msgq_purge( struct im_connection *ic, GSList **list ) 396 384 { … … 433 421 } 434 422 435 gboolean msn_set_display_name( struct im_connection *ic, const char *rawname ) 436 { 437 char *fn = msn_http_encode( rawname ); 438 struct msn_data *md = ic->proto_data; 439 char buf[1024]; 440 441 g_snprintf( buf, sizeof( buf ), "REA %d %s %s\r\n", ++md->trId, ic->acc->user, fn ); 442 g_free( fn ); 443 444 return msn_write( ic, buf, strlen( buf ) ) != 0; 445 } 423 /* Copied and heavily modified from http://tmsnc.sourceforge.net/chl.c */ 424 char *msn_p11_challenge( char *challenge ) 425 { 426 char *output, buf[256]; 427 md5_state_t md5c; 428 unsigned char md5Hash[16], *newHash; 429 unsigned int *md5Parts, *chlStringParts, newHashParts[5]; 430 long long nHigh = 0, nLow = 0; 431 int i, n; 432 433 /* Create the MD5 hash */ 434 md5_init(&md5c); 435 md5_append(&md5c, (unsigned char*) challenge, strlen(challenge)); 436 md5_append(&md5c, (unsigned char*) MSNP11_PROD_KEY, strlen(MSNP11_PROD_KEY)); 437 md5_finish(&md5c, md5Hash); 438 439 /* Split it into four integers */ 440 md5Parts = (unsigned int *)md5Hash; 441 for (i = 0; i < 4; i ++) 442 { 443 md5Parts[i] = GUINT32_TO_LE(md5Parts[i]); 444 445 /* & each integer with 0x7FFFFFFF */ 446 /* and save one unmodified array for later */ 447 newHashParts[i] = md5Parts[i]; 448 md5Parts[i] &= 0x7FFFFFFF; 449 } 450 451 /* make a new string and pad with '0' */ 452 n = g_snprintf(buf, sizeof(buf)-5, "%s%s00000000", challenge, MSNP11_PROD_ID); 453 /* truncate at an 8-byte boundary */ 454 buf[n&=~7] = '\0'; 455 456 /* split into integers */ 457 chlStringParts = (unsigned int *)buf; 458 459 /* this is magic */ 460 for (i = 0; i < (n / 4) - 1; i += 2) 461 { 462 long long temp; 463 464 chlStringParts[i] = GUINT32_TO_LE(chlStringParts[i]); 465 chlStringParts[i+1] = GUINT32_TO_LE(chlStringParts[i+1]); 466 467 temp = (md5Parts[0] * (((0x0E79A9C1 * (long long)chlStringParts[i]) % 0x7FFFFFFF)+nHigh) + md5Parts[1])%0x7FFFFFFF; 468 nHigh = (md5Parts[2] * (((long long)chlStringParts[i+1]+temp) % 0x7FFFFFFF) + md5Parts[3]) % 0x7FFFFFFF; 469 nLow = nLow + nHigh + temp; 470 } 471 nHigh = (nHigh+md5Parts[1]) % 0x7FFFFFFF; 472 nLow = (nLow+md5Parts[3]) % 0x7FFFFFFF; 473 474 newHashParts[0] ^= nHigh; 475 newHashParts[1] ^= nLow; 476 newHashParts[2] ^= nHigh; 477 newHashParts[3] ^= nLow; 478 479 /* swap more bytes if big endian */ 480 for (i = 0; i < 4; i ++) 481 newHashParts[i] = GUINT32_TO_LE(newHashParts[i]); 482 483 /* make a string of the parts */ 484 newHash = (unsigned char *)newHashParts; 485 486 /* convert to hexadecimal */ 487 output = g_new(char, 33); 488 for (i = 0; i < 16; i ++) 489 sprintf(output + i * 2, "%02x", newHash[i]); 490 491 return output; 492 } 493 494 gint msn_domaintree_cmp( gconstpointer a_, gconstpointer b_ ) 495 { 496 const char *a = a_, *b = b_; 497 gint ret; 498 499 if( !( a = strchr( a, '@' ) ) || !( b = strchr( b, '@' ) ) || 500 ( ret = strcmp( a, b ) ) == 0 ) 501 ret = strcmp( a_, b_ ); 502 503 return ret; 504 }
Note: See TracChangeset
for help on using the changeset viewer.