diff options
author | Geert Mulders <g.c.w.m.mulders@gmail.com> | 2010-04-06 19:25:51 +0200 |
---|---|---|
committer | Geert Mulders <g.c.w.m.mulders@gmail.com> | 2010-04-06 19:25:51 +0200 |
commit | 2abceca711403e8e3308213954b4477ceecd4282 (patch) | |
tree | b4b86d6e1b199afd3ac96d2c6c5c8d8211202c80 /protocols/twitter/twitter_http.c | |
parent | 62d2cfb0b7b5e7f3eda9ca13b1877d3ad74fcd5e (diff) |
Updates made as a result to the comments on the review.
Diffstat (limited to 'protocols/twitter/twitter_http.c')
-rw-r--r-- | protocols/twitter/twitter_http.c | 49 |
1 files changed, 8 insertions, 41 deletions
diff --git a/protocols/twitter/twitter_http.c b/protocols/twitter/twitter_http.c index 4385475c..34b9408d 100644 --- a/protocols/twitter/twitter_http.c +++ b/protocols/twitter/twitter_http.c @@ -38,9 +38,7 @@ #include <errno.h> -char *twitter_urlencode(const char *instr); char *twitter_url_append(char *url, char *key, char* value); -static int isurlchar(unsigned char c); /** * Do a request. @@ -106,9 +104,9 @@ void *twitter_http(char *url_string, http_input_function func, gpointer data, in // Make the request. request = g_strdup_printf( "%s %s HTTP/1.0\r\n" - "Host: %s\r\n" - "User-Agent: BitlBee " BITLBEE_VERSION " " ARCH "/" CPU "\r\n", - is_post ? "POST" : "GET", url->file, url->host ); + "Host: %s\r\n" + "User-Agent: BitlBee " BITLBEE_VERSION " " ARCH "/" CPU "\r\n", + is_post ? "POST" : "GET", url->file, url->host ); // If a pass and user are given we append them to the request. if (userpass_base64) @@ -145,8 +143,11 @@ void *twitter_http(char *url_string, http_input_function func, gpointer data, in char *twitter_url_append(char *url, char *key, char* value) { - char *key_encoded = twitter_urlencode(key); - char *value_encoded = twitter_urlencode(value); + char *key_encoded = g_strndup(key, 3 * strlen(key)); + http_encode(key_encoded); + char *value_encoded = g_strndup(value, 3 * strlen(value)); + http_encode(value_encoded); + char *retval; if (strlen(url) != 0) retval = g_strdup_printf("%s&%s=%s", url, key_encoded, value_encoded); @@ -159,35 +160,6 @@ char *twitter_url_append(char *url, char *key, char* value) return retval; } -char *twitter_urlencode(const char *instr) -{ - int ipos=0, bpos=0; - char *str = NULL; - int len = strlen(instr); - - if(!(str = g_new(char, 3*len + 1) )) - return ""; - - while(instr[ipos]) { - while(isurlchar(instr[ipos])) - str[bpos++] = instr[ipos++]; - if(!instr[ipos]) - break; - - g_snprintf(&str[bpos], 4, "%%%.2x", instr[ipos]); - bpos+=3; - ipos++; - } - str[bpos]='\0'; - - /* free extra alloc'ed mem. */ - len = strlen(str); - str = g_renew(char, str, len+1); - - return (str); -} - - char *twitter_urldecode(const char *instr) { int ipos=0, bpos=0; @@ -228,8 +200,3 @@ char *twitter_urldecode(const char *instr) return (str); } -static int isurlchar(unsigned char c) -{ - return (isalnum(c) || '-' == c || '_' == c); -} - |