- Timestamp:
- 2010-10-03T02:45:26Z (14 years ago)
- Branches:
- master
- Children:
- 04f0c10
- Parents:
- 88de0c9 (diff), 2af3e23 (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:
- lib
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/Makefile
r88de0c9 r8e9e2b7 13 13 14 14 # [SH] Program variables 15 objects = arc.o base64.o $( EVENT_HANDLER) ftutil.o http_client.o ini.o md5.o misc.o oauth.o proxy.o sha1.o $(SSL_CLIENT) url.o xmltree.o15 objects = arc.o base64.o $(DES) $(EVENT_HANDLER) ftutil.o http_client.o ini.o md5.o misc.o oauth.o proxy.o sha1.o $(SSL_CLIENT) url.o xmltree.o 16 16 17 17 LFLAGS += -r -
lib/misc.c
r88de0c9 r8e9e2b7 308 308 void http_encode( char *s ) 309 309 { 310 char *t;310 char t[strlen(s)+1]; 311 311 int i, j; 312 312 313 t = g_strdup( s ); 314 313 strcpy( t, s ); 315 314 for( i = j = 0; t[i]; i ++, j ++ ) 316 315 { … … 330 329 } 331 330 s[j] = 0; 332 333 g_free( t );334 331 } 335 332 -
lib/sha1.c
r88de0c9 r8e9e2b7 36 36 */ 37 37 38 #include <string.h> 38 39 #include "sha1.h" 39 40 … … 374 375 sha1_process_block(context); 375 376 } 377 378 #define HMAC_BLOCK_SIZE 64 379 380 /* BitlBee addition: */ 381 void sha1_hmac(const char *key_, size_t key_len, const char *payload, size_t payload_len, uint8_t Message_Digest[sha1_hash_size]) 382 { 383 sha1_state_t sha1; 384 uint8_t hash[sha1_hash_size]; 385 uint8_t key[HMAC_BLOCK_SIZE+1]; 386 int i; 387 388 if( key_len == 0 ) 389 key_len = strlen( key_ ); 390 if( payload_len == 0 ) 391 payload_len = strlen( payload ); 392 393 /* Create K. If our current key is >64 chars we have to hash it, 394 otherwise just pad. */ 395 memset( key, 0, HMAC_BLOCK_SIZE + 1 ); 396 if( key_len > HMAC_BLOCK_SIZE ) 397 { 398 sha1_init( &sha1 ); 399 sha1_append( &sha1, (uint8_t*) key_, key_len ); 400 sha1_finish( &sha1, key ); 401 } 402 else 403 { 404 memcpy( key, key_, key_len ); 405 } 406 407 /* Inner part: H(K XOR 0x36, text) */ 408 sha1_init( &sha1 ); 409 for( i = 0; i < HMAC_BLOCK_SIZE; i ++ ) 410 key[i] ^= 0x36; 411 sha1_append( &sha1, key, HMAC_BLOCK_SIZE ); 412 sha1_append( &sha1, (const uint8_t*) payload, payload_len ); 413 sha1_finish( &sha1, hash ); 414 415 /* Final result: H(K XOR 0x5C, inner stuff) */ 416 sha1_init( &sha1 ); 417 for( i = 0; i < HMAC_BLOCK_SIZE; i ++ ) 418 key[i] ^= 0x36 ^ 0x5c; 419 sha1_append( &sha1, key, HMAC_BLOCK_SIZE ); 420 sha1_append( &sha1, hash, sha1_hash_size ); 421 sha1_finish( &sha1, Message_Digest ); 422 } -
lib/sha1.h
r88de0c9 r8e9e2b7 67 67 G_MODULE_EXPORT int sha1_append(sha1_state_t *, const uint8_t *, unsigned int); 68 68 G_MODULE_EXPORT int sha1_finish(sha1_state_t *, uint8_t Message_Digest[sha1_hash_size]); 69 G_MODULE_EXPORT void sha1_hmac(const char *key_, size_t key_len, const char *payload, size_t payload_len, uint8_t Message_Digest[sha1_hash_size]); 69 70 70 71 #endif -
lib/ssl_client.h
r88de0c9 r8e9e2b7 81 81 the same action as the handler that just received the SSL_AGAIN.) */ 82 82 G_MODULE_EXPORT b_input_condition ssl_getdirection( void *conn ); 83 84 G_MODULE_EXPORT size_t ssl_des3_encrypt(const unsigned char *key, size_t key_len, const unsigned char *input, size_t input_len, const unsigned char *iv, unsigned char **res); -
lib/ssl_gnutls.c
r88de0c9 r8e9e2b7 194 194 ssl_errno = SSL_AGAIN; 195 195 196 if( 0 && getenv( "BITLBEE_DEBUG" ) && st > 0 ) write( 1, buf, st ); 197 196 198 return st; 197 199 } … … 212 214 if( st == GNUTLS_E_AGAIN || st == GNUTLS_E_INTERRUPTED ) 213 215 ssl_errno = SSL_AGAIN; 216 217 if( 0 && getenv( "BITLBEE_DEBUG" ) && st > 0 ) write( 1, buf, st ); 214 218 215 219 return st; -
lib/ssl_openssl.c
r88de0c9 r8e9e2b7 60 60 { 61 61 initialized = TRUE; 62 SSLeay_add_ssl_algorithms(); 62 SSL_library_init(); 63 // SSLeay_add_ssl_algorithms(); 63 64 } 64 65 … … 210 211 } 211 212 213 if( 0 && getenv( "BITLBEE_DEBUG" ) && st > 0 ) write( 1, buf, st ); 214 212 215 return st; 213 216 } … … 224 227 225 228 st = SSL_write( ((struct scd*)conn)->ssl, buf, len ); 229 230 if( 0 && getenv( "BITLBEE_DEBUG" ) && st > 0 ) write( 1, buf, st ); 226 231 227 232 ssl_errno = SSL_OK; … … 277 282 return( ((struct scd*)conn)->lasterr == SSL_ERROR_WANT_WRITE ? B_EV_IO_WRITE : B_EV_IO_READ ); 278 283 } 284 285 size_t ssl_des3_encrypt(const unsigned char *key, size_t key_len, const unsigned char *input, size_t input_len, const unsigned char *iv, unsigned char **res) 286 { 287 int output_length = 0; 288 EVP_CIPHER_CTX ctx; 289 290 *res = g_new0(unsigned char, 72); 291 292 /* Don't set key or IV because we will modify the parameters */ 293 EVP_CIPHER_CTX_init(&ctx); 294 EVP_CipherInit_ex(&ctx, EVP_des_ede3_cbc(), NULL, NULL, NULL, 1); 295 EVP_CIPHER_CTX_set_key_length(&ctx, key_len); 296 EVP_CIPHER_CTX_set_padding(&ctx, 0); 297 /* We finished modifying parameters so now we can set key and IV */ 298 EVP_CipherInit_ex(&ctx, NULL, NULL, key, iv, 1); 299 EVP_CipherUpdate(&ctx, *res, &output_length, input, input_len); 300 EVP_CipherFinal_ex(&ctx, *res, &output_length); 301 EVP_CIPHER_CTX_cleanup(&ctx); 302 //EVP_cleanup(); 303 304 return output_length; 305 } -
lib/xmltree.c
r88de0c9 r8e9e2b7 141 141 /* Feed the parser, don't execute any handler. Returns -1 on errors, 0 on 142 142 end-of-stream and 1 otherwise. */ 143 int xt_feed( struct xt_parser *xt, c har *text, int text_len )143 int xt_feed( struct xt_parser *xt, const char *text, int text_len ) 144 144 { 145 145 if( !g_markup_parse_context_parse( xt->parser, text, text_len, &xt->gerr ) ) … … 174 174 if( node->flags & XT_COMPLETE && !( node->flags & XT_SEEN ) ) 175 175 { 176 for( i = 0; xt->handlers[i].func; i ++ )176 if( xt->handlers ) for( i = 0; xt->handlers[i].func; i ++ ) 177 177 { 178 178 /* This one is fun! \o/ */ 179 179 180 180 /* If handler.name == NULL it means it should always match. */ 181 181 if( ( xt->handlers[i].name == NULL || 182 182 /* If it's not, compare. There should always be a name. */ 183 183 g_strcasecmp( xt->handlers[i].name, node->name ) == 0 ) && 184 184 /* If handler.parent == NULL, it's a match. */ 185 185 ( xt->handlers[i].parent == NULL || 186 186 /* If there's a parent node, see if the name matches. */ 187 187 ( node->parent ? g_strcasecmp( xt->handlers[i].parent, node->parent->name ) == 0 : 188 189 g_strcasecmp( xt->handlers[i].parent, "<root>" ) == 0 ) ) )188 /* If there's no parent, the handler should mention <root> as a parent. */ 189 strcmp( xt->handlers[i].parent, "<root>" ) == 0 ) ) ) 190 190 { 191 191 st = xt->handlers[i].func( node, xt->data ); … … 260 260 } 261 261 262 struct xt_node *xt_from_string( const char *in ) 263 { 264 struct xt_parser *parser; 265 struct xt_node *ret; 266 267 parser = xt_new( NULL, NULL ); 268 xt_feed( parser, in, strlen( in ) ); 269 ret = parser->root; 270 parser->root = NULL; 271 xt_free( parser ); 272 273 return ret; 274 } 275 262 276 static void xt_to_string_real( struct xt_node *node, GString *str ) 263 277 { … … 317 331 /* Indentation */ 318 332 for( c = node; c->parent; c = c->parent ) 319 printf( " \t" );333 printf( " " ); 320 334 321 335 /* Start the tag */ … … 324 338 /* Print the attributes */ 325 339 for( i = 0; node->attr[i].key; i ++ ) 326 printf( " %s=\"%s\"", node->attr[i].key, g_markup_escape_text( node->attr[i].value, -1 ) ); 340 { 341 char *v = g_markup_escape_text( node->attr[i].value, -1 ); 342 printf( " %s=\"%s\"", node->attr[i].key, v ); 343 g_free( v ); 344 } 327 345 328 346 /* /> in case there's really *nothing* inside this tag, otherwise … … 344 362 for( i = 0; node->text[i] && isspace( node->text[i] ); i ++ ); 345 363 if( node->text[i] ) 346 printf( "%s", g_markup_escape_text( node->text, -1 ) ); 364 { 365 char *v = g_markup_escape_text( node->text, -1 ); 366 printf( "%s", v ); 367 g_free( v ); 368 } 347 369 } 348 370 … … 355 377 if( node->children ) 356 378 for( c = node; c->parent; c = c->parent ) 357 printf( " \t" );379 printf( " " ); 358 380 359 381 /* Non-empty tag is now finished. */ … … 460 482 461 483 node = node->next; 484 } 485 486 return node; 487 } 488 489 /* More advanced than the one above, understands something like 490 ../foo/bar to find a subnode bar of a node foo which is a child 491 of node's parent. Pass the node directly, not its list of children. */ 492 struct xt_node *xt_find_path( struct xt_node *node, const char *name ) 493 { 494 while( name && *name && node ) 495 { 496 char *colon, *slash; 497 int n; 498 499 if( ( slash = strchr( name, '/' ) ) ) 500 n = slash - name; 501 else 502 n = strlen( name ); 503 504 if( strncmp( name, "..", n ) == 0 ) 505 { 506 node = node->parent; 507 } 508 else 509 { 510 node = node->children; 511 512 while( node ) 513 { 514 if( g_strncasecmp( node->name, name, n ) == 0 || 515 ( ( colon = strchr( node->name, ':' ) ) && 516 g_strncasecmp( colon + 1, name, n ) == 0 ) ) 517 break; 518 519 node = node->next; 520 } 521 } 522 523 name = slash ? slash + 1 : NULL; 462 524 } 463 525 … … 550 612 } 551 613 614 /* Same, but at the beginning. */ 615 void xt_insert_child( struct xt_node *parent, struct xt_node *child ) 616 { 617 struct xt_node *node, *last; 618 619 for( node = child; node; node = node->next ) 620 { 621 if( node->parent != NULL ) 622 { 623 /* ERROR CONDITION: They seem to have a parent already??? */ 624 } 625 626 node->parent = parent; 627 last = node; 628 } 629 630 last->next = parent->children; 631 parent->children = child; 632 } 633 552 634 void xt_add_attr( struct xt_node *node, const char *key, const char *value ) 553 635 { -
lib/xmltree.h
r88de0c9 r8e9e2b7 79 79 struct xt_parser *xt_new( const struct xt_handler_entry *handlers, gpointer data ); 80 80 void xt_reset( struct xt_parser *xt ); 81 int xt_feed( struct xt_parser *xt, c har *text, int text_len );81 int xt_feed( struct xt_parser *xt, const char *text, int text_len ); 82 82 int xt_handle( struct xt_parser *xt, struct xt_node *node, int depth ); 83 83 void xt_cleanup( struct xt_parser *xt, struct xt_node *node, int depth ); 84 struct xt_node *xt_from_string( const char *in ); 84 85 char *xt_to_string( struct xt_node *node ); 85 86 void xt_print( struct xt_node *node ); … … 88 89 void xt_free( struct xt_parser *xt ); 89 90 struct xt_node *xt_find_node( struct xt_node *node, const char *name ); 91 struct xt_node *xt_find_path( struct xt_node *node, const char *name ); 90 92 char *xt_find_attr( struct xt_node *node, const char *key ); 91 93 92 94 struct xt_node *xt_new_node( char *name, const char *text, struct xt_node *children ); 93 95 void xt_add_child( struct xt_node *parent, struct xt_node *child ); 96 void xt_insert_child( struct xt_node *parent, struct xt_node *child ); 94 97 void xt_add_attr( struct xt_node *node, const char *key, const char *value ); 95 98 int xt_remove_attr( struct xt_node *node, const char *key );
Note: See TracChangeset
for help on using the changeset viewer.