Changes in protocols/msn/msn_util.c [4452e69:4255320]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/msn/msn_util.c
r4452e69 r4255320 2 2 * BitlBee -- An IRC to other IM-networks gateway * 3 3 * * 4 * Copyright 2002-20 10Wilmer van der Gaast and others *4 * Copyright 2002-2004 Wilmer van der Gaast and others * 5 5 \********************************************************************/ 6 6 … … 26 26 #include "nogaim.h" 27 27 #include "msn.h" 28 #include "md5.h"29 28 #include <ctype.h> 30 29 … … 33 32 struct msn_data *md = ic->proto_data; 34 33 int st; 35 36 if( getenv( "BITLBEE_DEBUG" ) )37 {38 write( 2, "->NS:", 5 );39 write( 2, s, len );40 }41 34 42 35 st = write( md->fd, s, len ); … … 61 54 { 62 55 struct msn_data *md = ic->proto_data; 63 char buf[1024], realname[strlen(realname_)*3+1], groupid[8];56 char buf[1024], *realname, groupid[8]; 64 57 65 58 *groupid = '\0'; … … 94 87 if( l == NULL ) 95 88 { 96 char groupname[strlen(group)+1]; 97 strcpy( groupname, group ); 98 http_encode( groupname ); 89 char *groupname = msn_http_encode( group ); 99 90 g_snprintf( buf, sizeof( buf ), "ADG %d %s %d\r\n", ++md->trId, groupname, 0 ); 91 g_free( groupname ); 100 92 return msn_write( ic, buf, strlen( buf ) ); 101 93 } … … 110 102 } 111 103 112 strcpy( realname, realname_ ); 113 http_encode( realname ); 104 realname = msn_http_encode( realname_ ); 114 105 g_snprintf( buf, sizeof( buf ), "ADD %d %s %s %s%s\r\n", ++md->trId, list, who, realname, groupid ); 106 g_free( realname ); 115 107 116 108 return msn_write( ic, buf, strlen( buf ) ); … … 287 279 if( st <= 0 ) 288 280 return( -1 ); 289 290 if( getenv( "BITLBEE_DEBUG" ) )291 {292 write( 2, "->C:", 4 );293 write( 2, h->rxq + h->rxlen - st, st );294 }295 281 296 282 while( st ) … … 381 367 } 382 368 369 /* The difference between this function and the normal http_encode() function 370 is that this one escapes every 7-bit ASCII character because this is said 371 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 to 373 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 else 387 { 388 g_snprintf( s, 4, "%%%02X", input[i] ); 389 s += 3; 390 } 391 392 return ret; 393 } 394 383 395 void msn_msgq_purge( struct im_connection *ic, GSList **list ) 384 396 { … … 421 433 } 422 434 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 } 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 }
Note: See TracChangeset
for help on using the changeset viewer.