Ignore:
Timestamp:
2011-06-11T11:28:01Z (13 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
5f74987
Parents:
27ad50b
Message:

Re-indent Twitter code. It just lacks *any* kind of consistency. Flags used:
-i8 -kr -ts8 -ut -l100 Because K&R isn't so bad after all but spaces are
definitely evil. (Not that GNU indent understands how to use tabs, oh well.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter_http.c

    r27ad50b r5983eca  
    2727*  BitlBee.                                                                 *
    2828*                                                                           *
    29 ****************************************************************************/ 
     29****************************************************************************/
    3030
    3131#include "twitter.h"
     
    4141
    4242
    43 static char *twitter_url_append(char *url, char *key, char* value);
     43static char *twitter_url_append(char *url, char *key, char *value);
    4444
    4545/**
     
    4747 * This is actually pretty generic function... Perhaps it should move to the lib/http_client.c
    4848 */
    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)
     49void *twitter_http(struct im_connection *ic, char *url_string, http_input_function func,
     50                   gpointer data, int is_post, char **arguments, int arguments_len)
    5051{
    5152        struct twitter_data *td = ic->proto_data;
     
    5859
    5960        // Construct the url arguments.
    60         if (arguments_len != 0)
    61         {
     61        if (arguments_len != 0) {
    6262                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]);
    6665                        g_free(url_arguments);
    6766                        url_arguments = tmp;
    6867                }
    6968        }
    70 
    7169        // Make the request.
    7270        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);
    7976
    8077        // If a pass and user are given we append them to the request.
    81         if (td->oauth_info)
    82         {
     78        if (td->oauth_info) {
    8379                char *full_header;
    8480                char *full_url;
    85                
    86                 full_url = g_strconcat(set_getstr(&ic->acc->set, "base_url" ), url_string, NULL);
     81
     82                full_url = g_strconcat(set_getstr(&ic->acc->set, "base_url"), url_string, NULL);
    8783                full_header = oauth_http_header(td->oauth_info, is_post ? "POST" : "GET",
    88                                                 full_url, url_arguments);
    89                
     84                                                full_url, url_arguments);
     85
    9086                g_string_append_printf(request, "Authorization: %s\r\n", full_header);
    9187                g_free(full_header);
    9288                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)];
    9791                char *userpass_base64;
    98                
     92
    9993                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));
    10195                g_string_append_printf(request, "Authorization: Basic %s\r\n", userpass_base64);
    102                 g_free( userpass_base64 );
     96                g_free(userpass_base64);
    10397        }
    10498
    10599        // Do POST stuff..
    106         if (is_post)
    107         {
     100        if (is_post) {
    108101                // Append the Content-Type and url-encoded arguments.
    109102                g_string_append_printf(request,
    110                                        "Content-Type: application/x-www-form-urlencoded\r\n"
    111                                        "Content-Length: %zd\r\n\r\n%s",
    112                                        strlen(url_arguments), url_arguments);
     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);
    113106        } else {
    114107                // Append an extra \r\n to end the request...
     
    118111        ret = http_dorequest(td->url_host, td->url_port, td->url_ssl, request->str, func, data);
    119112
    120         g_free( url_arguments );
    121         g_string_free( request, TRUE );
     113        g_free(url_arguments);
     114        g_string_free(request, TRUE);
    122115        return ret;
    123116}
    124117
    125 static char *twitter_url_append(char *url, char *key, char* value)
     118static char *twitter_url_append(char *url, char *key, char *value)
    126119{
    127120        char *key_encoded = g_strndup(key, 3 * strlen(key));
Note: See TracChangeset for help on using the changeset viewer.