- Timestamp:
- 2011-12-26T10:51:19Z (13 years ago)
- Branches:
- master
- Children:
- 199fea6
- Parents:
- 96f954d (diff), 644b808 (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
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/Makefile
r96f954d r5f40da7 13 13 14 14 # [SH] Program variables 15 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.o15 objects = arc.o base64.o $(DES) $(EVENT_HANDLER) ftutil.o http_client.o ini.o md5.o misc.o oauth.o oauth2.o proxy.o sha1.o $(SSL_CLIENT) url.o xmltree.o 16 16 17 17 LFLAGS += -r -
lib/arc.c
r96f954d r5f40da7 200 200 { 201 201 *clear = g_strdup( "" ); 202 return 0;202 return -1; 203 203 } 204 204 -
lib/md5.c
r96f954d r5f40da7 24 24 #include <sys/types.h> 25 25 #include <string.h> /* for memcpy() */ 26 #include <stdio.h> 26 27 #include "md5.h" 27 28 … … 160 161 memcpy(digest, ctx->buf, 16); 161 162 memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */ 163 } 164 165 void md5_finish_ascii(struct MD5Context *context, char *ascii) 166 { 167 md5_byte_t bin[16]; 168 int i; 169 170 md5_finish(context, bin); 171 for (i = 0; i < 16; i ++) 172 sprintf(ascii + i * 2, "%02x", bin[i]); 162 173 } 163 174 -
lib/md5.h
r96f954d r5f40da7 43 43 G_MODULE_EXPORT void md5_append(struct MD5Context *context, const md5_byte_t *buf, unsigned int len); 44 44 G_MODULE_EXPORT void md5_finish(struct MD5Context *context, md5_byte_t digest[16]); 45 G_MODULE_EXPORT void md5_finish_ascii(struct MD5Context *context, char *ascii); 45 46 46 47 #endif -
lib/misc.c
r96f954d r5f40da7 729 729 return cmd; 730 730 } 731 732 char *get_rfc822_header( char *text, char *header, int len ) 733 { 734 int hlen = strlen( header ), i; 735 char *ret; 736 737 if( text == NULL ) 738 return NULL; 739 740 if( len == 0 ) 741 len = strlen( text ); 742 743 i = 0; 744 while( ( i + hlen ) < len ) 745 { 746 /* Maybe this is a bit over-commented, but I just hate this part... */ 747 if( g_strncasecmp( text + i, header, hlen ) == 0 ) 748 { 749 /* Skip to the (probable) end of the header */ 750 i += hlen; 751 752 /* Find the first non-[: \t] character */ 753 while( i < len && ( text[i] == ':' || text[i] == ' ' || text[i] == '\t' ) ) i ++; 754 755 /* Make sure we're still inside the string */ 756 if( i >= len ) return( NULL ); 757 758 /* Save the position */ 759 ret = text + i; 760 761 /* Search for the end of this line */ 762 while( i < len && text[i] != '\r' && text[i] != '\n' ) i ++; 763 764 /* Make sure we're still inside the string */ 765 if( i >= len ) return( NULL ); 766 767 /* Copy the found data */ 768 return( g_strndup( ret, text + i - ret ) ); 769 } 770 771 /* This wasn't the header we were looking for, skip to the next line. */ 772 while( i < len && ( text[i] != '\r' && text[i] != '\n' ) ) i ++; 773 while( i < len && ( text[i] == '\r' || text[i] == '\n' ) ) i ++; 774 775 /* End of headers? */ 776 if( ( i >= 4 && strncmp( text + i - 4, "\r\n\r\n", 4 ) == 0 ) || 777 ( i >= 2 && ( strncmp( text + i - 2, "\n\n", 2 ) == 0 || 778 strncmp( text + i - 2, "\r\r", 2 ) == 0 ) ) ) 779 { 780 break; 781 } 782 } 783 784 return NULL; 785 } -
lib/misc.h
r96f954d r5f40da7 65 65 66 66 G_MODULE_EXPORT char *word_wrap( const char *msg, int line_len ); 67 68 67 G_MODULE_EXPORT gboolean ssl_sockerr_again( void *ssl ); 69 70 68 G_MODULE_EXPORT int md5_verify_password( char *password, char *hash ); 71 72 69 G_MODULE_EXPORT char **split_command_parts( char *command ); 70 G_MODULE_EXPORT char *get_rfc822_header( char *text, char *header, int len ); 73 71 74 72 #endif -
lib/oauth.c
r96f954d r5f40da7 38 38 const char *params, struct oauth_info *oi ) 39 39 { 40 sha1_state_t sha1;41 40 uint8_t hash[sha1_hash_size]; 42 uint8_t key[HMAC_BLOCK_SIZE+1]; 41 GString *payload = g_string_new( "" ); 42 char *key; 43 43 char *s; 44 int i; 45 46 /* Create K. If our current key is >64 chars we have to hash it, 47 otherwise just pad. */ 48 memset( key, 0, HMAC_BLOCK_SIZE ); 49 i = strlen( oi->sp->consumer_secret ) + 1 + ( oi->token_secret ? strlen( oi->token_secret ) : 0 ); 50 if( i > HMAC_BLOCK_SIZE ) 51 { 52 sha1_init( &sha1 ); 53 sha1_append( &sha1, (uint8_t*) oi->sp->consumer_secret, strlen( oi->sp->consumer_secret ) ); 54 sha1_append( &sha1, (uint8_t*) "&", 1 ); 55 if( oi->token_secret ) 56 sha1_append( &sha1, (uint8_t*) oi->token_secret, strlen( oi->token_secret ) ); 57 sha1_finish( &sha1, key ); 58 } 59 else 60 { 61 g_snprintf( (gchar*) key, HMAC_BLOCK_SIZE + 1, "%s&%s", 62 oi->sp->consumer_secret, oi->token_secret ? oi->token_secret : "" ); 63 } 64 65 /* Inner part: H(K XOR 0x36, text) */ 66 sha1_init( &sha1 ); 67 68 for( i = 0; i < HMAC_BLOCK_SIZE; i ++ ) 69 key[i] ^= 0x36; 70 sha1_append( &sha1, key, HMAC_BLOCK_SIZE ); 71 72 /* OAuth: text = method&url¶ms, all http_encoded. */ 73 sha1_append( &sha1, (const uint8_t*) method, strlen( method ) ); 74 sha1_append( &sha1, (const uint8_t*) "&", 1 ); 44 45 key = g_strdup_printf( "%s&%s", oi->sp->consumer_secret, oi->token_secret ? oi->token_secret : "" ); 46 47 g_string_append_printf( payload, "%s&", method ); 75 48 76 49 s = g_new0( char, strlen( url ) * 3 + 1 ); 77 50 strcpy( s, url ); 78 51 http_encode( s ); 79 sha1_append( &sha1, (const uint8_t*) s, strlen( s ) ); 80 sha1_append( &sha1, (const uint8_t*) "&", 1 ); 52 g_string_append_printf( payload, "%s&", s ); 81 53 g_free( s ); 82 54 … … 84 56 strcpy( s, params ); 85 57 http_encode( s ); 86 sha1_append( &sha1, (const uint8_t*) s, strlen( s ) ); 87 g_free( s ); 88 89 sha1_finish( &sha1, hash ); 90 91 /* Final result: H(K XOR 0x5C, inner stuff) */ 92 sha1_init( &sha1 ); 93 for( i = 0; i < HMAC_BLOCK_SIZE; i ++ ) 94 key[i] ^= 0x36 ^ 0x5c; 95 sha1_append( &sha1, key, HMAC_BLOCK_SIZE ); 96 sha1_append( &sha1, hash, sha1_hash_size ); 97 sha1_finish( &sha1, hash ); 58 g_string_append( payload, s ); 59 g_free( s ); 60 61 sha1_hmac( key, 0, payload->str, 0, hash ); 62 63 g_free( key ); 64 g_string_free( payload, TRUE ); 98 65 99 66 /* base64_encode + HTTP escape it (both consumers … … 122 89 char *item; 123 90 91 if( !key || !value ) 92 return; 93 124 94 item = g_strdup_printf( "%s=%s", key, value ); 125 95 *params = g_slist_insert_sorted( *params, item, (GCompareFunc) strcmp ); … … 130 100 int key_len = strlen( key ); 131 101 GSList *l, *n; 102 103 if( params == NULL ) 104 return; 132 105 133 106 for( l = *params; l; l = n ) … … 155 128 GSList *l; 156 129 130 if( params == NULL ) 131 return NULL; 132 157 133 for( l = *params; l; l = l->next ) 158 134 { … … 165 141 } 166 142 167 staticvoid oauth_params_parse( GSList **params, char *in )143 void oauth_params_parse( GSList **params, char *in ) 168 144 { 169 145 char *amp, *eq, *s; … … 333 309 oauth_params_parse( ¶ms, req->reply_body ); 334 310 st->request_token = g_strdup( oauth_params_get( ¶ms, "oauth_token" ) ); 311 st->token_secret = g_strdup( oauth_params_get( ¶ms, "oauth_token_secret" ) ); 335 312 oauth_params_free( ¶ms ); 336 313 } … … 362 339 oauth_params_parse( &st->params, req->reply_body ); 363 340 st->token = g_strdup( oauth_params_get( &st->params, "oauth_token" ) ); 341 g_free( st->token_secret ); 364 342 st->token_secret = g_strdup( oauth_params_get( &st->params, "oauth_token_secret" ) ); 365 343 } -
lib/oauth.h
r96f954d r5f40da7 92 92 93 93 /* For reading misc. data. */ 94 void oauth_params_add( GSList **params, const char *key, const char *value ); 95 void oauth_params_parse( GSList **params, char *in ); 96 void oauth_params_free( GSList **params ); 97 char *oauth_params_string( GSList *params ); 98 void oauth_params_set( GSList **params, const char *key, const char *value ); 94 99 const char *oauth_params_get( GSList **params, const char *key );
Note: See TracChangeset
for help on using the changeset viewer.