Changeset 2abceca for protocols/twitter/twitter_http.c
- Timestamp:
- 2010-04-06T17:25:51Z (15 years ago)
- Branches:
- master
- Children:
- 0519b0a
- Parents:
- 62d2cfb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/twitter/twitter_http.c
r62d2cfb r2abceca 39 39 40 40 41 char *twitter_urlencode(const char *instr);42 41 char *twitter_url_append(char *url, char *key, char* value); 43 static int isurlchar(unsigned char c);44 42 45 43 /** … … 107 105 // Make the request. 108 106 request = g_strdup_printf( "%s %s HTTP/1.0\r\n" 109 110 111 107 "Host: %s\r\n" 108 "User-Agent: BitlBee " BITLBEE_VERSION " " ARCH "/" CPU "\r\n", 109 is_post ? "POST" : "GET", url->file, url->host ); 112 110 113 111 // If a pass and user are given we append them to the request. … … 146 144 char *twitter_url_append(char *url, char *key, char* value) 147 145 { 148 char *key_encoded = twitter_urlencode(key); 149 char *value_encoded = twitter_urlencode(value); 146 char *key_encoded = g_strndup(key, 3 * strlen(key)); 147 http_encode(key_encoded); 148 char *value_encoded = g_strndup(value, 3 * strlen(value)); 149 http_encode(value_encoded); 150 150 151 char *retval; 151 152 if (strlen(url) != 0) … … 159 160 return retval; 160 161 } 161 162 char *twitter_urlencode(const char *instr)163 {164 int ipos=0, bpos=0;165 char *str = NULL;166 int len = strlen(instr);167 168 if(!(str = g_new(char, 3*len + 1) ))169 return "";170 171 while(instr[ipos]) {172 while(isurlchar(instr[ipos]))173 str[bpos++] = instr[ipos++];174 if(!instr[ipos])175 break;176 177 g_snprintf(&str[bpos], 4, "%%%.2x", instr[ipos]);178 bpos+=3;179 ipos++;180 }181 str[bpos]='\0';182 183 /* free extra alloc'ed mem. */184 len = strlen(str);185 str = g_renew(char, str, len+1);186 187 return (str);188 }189 190 162 191 163 char *twitter_urldecode(const char *instr) … … 229 201 } 230 202 231 static int isurlchar(unsigned char c)232 {233 return (isalnum(c) || '-' == c || '_' == c);234 }235
Note: See TracChangeset
for help on using the changeset viewer.