- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/twitter/twitter_http.c
rbb5ce4d1 r5983eca 27 27 * BitlBee. * 28 28 * * 29 ****************************************************************************/ 29 ****************************************************************************/ 30 30 31 31 #include "twitter.h" … … 41 41 42 42 43 static char *twitter_url_append(char *url, char *key, char *value);43 static char *twitter_url_append(char *url, char *key, char *value); 44 44 45 45 /** … … 47 47 * This is actually pretty generic function... Perhaps it should move to the lib/http_client.c 48 48 */ 49 void *twitter_http(struct im_connection *ic, char *url_string, http_input_function func, gpointer data, int is_post, char** arguments, int arguments_len) 49 void *twitter_http(struct im_connection *ic, char *url_string, http_input_function func, 50 gpointer data, int is_post, char **arguments, int arguments_len) 50 51 { 51 52 struct twitter_data *td = ic->proto_data; … … 58 59 59 60 // Construct the url arguments. 60 if (arguments_len != 0) 61 { 61 if (arguments_len != 0) { 62 62 int i; 63 for (i=0; i<arguments_len; i+=2) 64 { 65 tmp = twitter_url_append(url_arguments, arguments[i], arguments[i+1]); 63 for (i = 0; i < arguments_len; i += 2) { 64 tmp = twitter_url_append(url_arguments, arguments[i], arguments[i + 1]); 66 65 g_free(url_arguments); 67 66 url_arguments = tmp; 68 67 } 69 68 } 70 71 69 // Make the request. 72 70 g_string_printf(request, "%s %s%s%s%s HTTP/1.0\r\n" 73 "Host: %s\r\n" 74 "User-Agent: BitlBee " BITLBEE_VERSION " " ARCH "/" CPU "\r\n", 75 is_post ? "POST" : "GET", 76 td->url_path, url_string, 77 is_post ? "" : "?", is_post ? "" : url_arguments, 78 td->url_host); 71 "Host: %s\r\n" 72 "User-Agent: BitlBee " BITLBEE_VERSION " " ARCH "/" CPU "\r\n", 73 is_post ? "POST" : "GET", 74 td->url_path, url_string, 75 is_post ? "" : "?", is_post ? "" : url_arguments, td->url_host); 79 76 80 77 // If a pass and user are given we append them to the request. 81 if (td->oauth_info) 82 { 78 if (td->oauth_info) { 83 79 char *full_header; 84 80 char *full_url; 85 86 full_url = g_strconcat(set_getstr(&ic->acc->set, "base_url" 81 82 full_url = g_strconcat(set_getstr(&ic->acc->set, "base_url"), url_string, NULL); 87 83 full_header = oauth_http_header(td->oauth_info, is_post ? "POST" : "GET", 88 89 84 full_url, url_arguments); 85 90 86 g_string_append_printf(request, "Authorization: %s\r\n", full_header); 91 87 g_free(full_header); 92 88 g_free(full_url); 93 } 94 else 95 { 96 char userpass[strlen(ic->acc->user)+2+strlen(ic->acc->pass)]; 89 } else { 90 char userpass[strlen(ic->acc->user) + 2 + strlen(ic->acc->pass)]; 97 91 char *userpass_base64; 98 92 99 93 g_snprintf(userpass, sizeof(userpass), "%s:%s", ic->acc->user, ic->acc->pass); 100 userpass_base64 = base64_encode((unsigned char *)userpass, strlen(userpass));94 userpass_base64 = base64_encode((unsigned char *) userpass, strlen(userpass)); 101 95 g_string_append_printf(request, "Authorization: Basic %s\r\n", userpass_base64); 102 g_free( userpass_base64);96 g_free(userpass_base64); 103 97 } 104 98 105 99 // Do POST stuff.. 106 if (is_post) 107 { 100 if (is_post) { 108 101 // Append the Content-Type and url-encoded arguments. 109 102 g_string_append_printf(request, 110 111 112 103 "Content-Type: application/x-www-form-urlencoded\r\n" 104 "Content-Length: %zd\r\n\r\n%s", 105 strlen(url_arguments), url_arguments); 113 106 } else { 114 107 // Append an extra \r\n to end the request... … … 118 111 ret = http_dorequest(td->url_host, td->url_port, td->url_ssl, request->str, func, data); 119 112 120 g_free( url_arguments);121 g_string_free( request, TRUE);113 g_free(url_arguments); 114 g_string_free(request, TRUE); 122 115 return ret; 123 116 } 124 117 125 static char *twitter_url_append(char *url, char *key, char *value)118 static char *twitter_url_append(char *url, char *key, char *value) 126 119 { 127 120 char *key_encoded = g_strndup(key, 3 * strlen(key));
Note: See TracChangeset
for help on using the changeset viewer.