Ignore:
Timestamp:
2015-02-20T22:50:54Z (9 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
0b9daac, 3d45471, 7733b8c
Parents:
af359b4
git-author:
Indent <please@…> (19-02-15 05:47:20)
git-committer:
dequis <dx@…> (20-02-15 22:50:54)
Message:

Reindent everything to K&R style with tabs

Used uncrustify, with the configuration file in ./doc/uncrustify.cfg

Commit author set to "Indent <please@…>" so that it's easier to
skip while doing git blame.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/yahoo/yahoo_httplib.c

    raf359b4 r5ebff60  
    3232char *strchr(), *strrchr();
    3333# if !HAVE_MEMCPY
    34 #  define memcpy(d, s, n) bcopy ((s), (d), (n))
    35 #  define memmove(d, s, n) bcopy ((s), (d), (n))
     34#  define memcpy(d, s, n) bcopy((s), (d), (n))
     35#  define memmove(d, s, n) bcopy((s), (d), (n))
    3636# endif
    3737#endif
     
    5353#ifdef USE_STRUCT_CALLBACKS
    5454extern struct yahoo_callbacks *yc;
    55 #define YAHOO_CALLBACK(x)       yc->x
     55#define YAHOO_CALLBACK(x)       yc->x
    5656#else
    57 #define YAHOO_CALLBACK(x)       x
     57#define YAHOO_CALLBACK(x)       x
    5858#endif
    5959
     
    6969
    7070                do {
    71                         rc = YAHOO_CALLBACK(ext_yahoo_read) (fd, &c, 1);
    72                 } while (rc == -1 && (errno == EINTR || errno == EAGAIN));      /* this is bad - it should be done asynchronously */
     71                        rc = YAHOO_CALLBACK (ext_yahoo_read) (fd, &c, 1);
     72                } while (rc == -1 && (errno == EINTR || errno == EAGAIN));      /* this is bad - it should be done asynchronously */
    7373
    7474                if (rc == 1) {
    75                         if (c == '\r')  /* get rid of \r */
     75                        if (c == '\r') { /* get rid of \r */
    7676                                continue;
     77                        }
    7778                        *ptr = c;
    78                         if (c == '\n')
     79                        if (c == '\n') {
    7980                                break;
     81                        }
    8082                        ptr++;
    8183                } else if (rc == 0) {
    82                         if (n == 1)
    83                                 return (0);     /* EOF, no data */
    84                         else
    85                                 break;  /* EOF, w/ data */
     84                        if (n == 1) {
     85                                return (0);     /* EOF, no data */
     86                        } else {
     87                                break;  /* EOF, w/ data */
     88                        }
    8689                } else {
    8790                        return -1;
     
    9598
    9699static int url_to_host_port_path(const char *url,
    97         char *host, int *port, char *path, int *ssl)
     100                                 char *host, int *port, char *path, int *ssl)
    98101{
    99102        char *urlcopy = NULL;
     
    127130
    128131        if (!colon || (slash && slash < colon)) {
    129                 if (*ssl)
     132                if (*ssl) {
    130133                        *port = 443;
    131                 else
     134                } else {
    132135                        *port = 80;
     136                }
    133137        } else {
    134138                *colon = 0;
     
    161165        int len = strlen(instr);
    162166
    163         if (!(str = y_new(char, 3 *len + 1)))
    164                  return "";
     167        if (!(str = y_new(char, 3 * len + 1))) {
     168                return "";
     169        }
    165170
    166171        while (instr[ipos]) {
    167                 while (isurlchar(instr[ipos]))
     172                while (isurlchar(instr[ipos])) {
    168173                        str[bpos++] = instr[ipos++];
    169                 if (!instr[ipos])
     174                }
     175                if (!instr[ipos]) {
    170176                        break;
     177                }
    171178
    172179                snprintf(&str[bpos], 4, "%%%02x", instr[ipos] & 0xff);
     
    192199        int len = strlen(instr);
    193200
    194         if (!(str = y_new(char, len + 1)))
    195                  return "";
     201        if (!(str = y_new(char, len + 1))) {
     202                return "";
     203        }
    196204
    197205        while (instr[ipos]) {
    198                 while (instr[ipos] && instr[ipos] != '%')
     206                while (instr[ipos] && instr[ipos] != '%') {
    199207                        if (instr[ipos] == '+') {
    200208                                str[bpos++] = ' ';
    201209                                ipos++;
    202                         } else
     210                        } else {
    203211                                str[bpos++] = instr[ipos++];
    204                 if (!instr[ipos])
     212                        }
     213                }
     214                if (!instr[ipos]) {
    205215                        break;
     216                }
    206217
    207218                if (instr[ipos + 1] && instr[ipos + 2]) {
     
    210221                        entity[1] = instr[ipos++];
    211222                        sscanf(entity, "%2x", &dec);
    212                         str[bpos++] = (char)dec;
     223                        str[bpos++] = (char) dec;
    213224                } else {
    214225                        str[bpos++] = instr[ipos++];
     
    230241        char entity[4] = { 0, 0, 0, 0 };
    231242        char *entitymap[5][2] = {
    232                 {"amp;", "&"},
    233                 {"quot;", "\""},
    234                 {"lt;", "<"},
    235                 {"gt;", "<"},
    236                 {"nbsp;", " "}
     243                { "amp;", "&" },
     244                { "quot;", "\"" },
     245                { "lt;", "<" },
     246                { "gt;", "<" },
     247                { "nbsp;", " " }
    237248        };
    238249        unsigned dec;
    239250        int len = strlen(instr);
    240251
    241         if (!(str = y_new(char, len + 1)))
    242                  return "";
     252        if (!(str = y_new(char, len + 1))) {
     253                return "";
     254        }
    243255
    244256        while (instr[ipos]) {
    245                 while (instr[ipos] && instr[ipos] != '&')
     257                while (instr[ipos] && instr[ipos] != '&') {
    246258                        if (instr[ipos] == '+') {
    247259                                str[bpos++] = ' ';
    248260                                ipos++;
    249                         } else
     261                        } else {
    250262                                str[bpos++] = instr[ipos++];
    251                 if (!instr[ipos] || !instr[ipos + 1])
     263                        }
     264                }
     265                if (!instr[ipos] || !instr[ipos + 1]) {
    252266                        break;
     267                }
    253268                ipos++;
    254269
     
    256271                        ipos++;
    257272                        epos = 0;
    258                         while (instr[ipos] != ';')
     273                        while (instr[ipos] != ';') {
    259274                                entity[epos++] = instr[ipos++];
     275                        }
    260276                        sscanf(entity, "%u", &dec);
    261                         str[bpos++] = (char)dec;
     277                        str[bpos++] = (char) dec;
    262278                        ipos++;
    263279                } else {
    264280                        int i;
    265                         for (i = 0; i < 5; i++)
     281                        for (i = 0; i < 5; i++) {
    266282                                if (!strncmp(instr + ipos, entitymap[i][0],
    267                                                 strlen(entitymap[i][0]))) {
     283                                             strlen(entitymap[i][0]))) {
    268284                                        str[bpos++] = entitymap[i][1][0];
    269285                                        ipos += strlen(entitymap[i][0]);
    270286                                        break;
    271287                                }
     288                        }
    272289                }
    273290        }
     
    294311{
    295312        struct callback_data *ccd = data;
    296         if (error == 0)
    297                 YAHOO_CALLBACK(ext_yahoo_write) (fd, ccd->request,
    298                         strlen(ccd->request));
     313
     314        if (error == 0) {
     315                YAHOO_CALLBACK (ext_yahoo_write) (fd, ccd->request,
     316                                                  strlen(ccd->request));
     317        }
    299318        free(ccd->request);
    300319        ccd->callback(ccd->id, fd, error, ccd->user_data);
     
    303322
    304323static void yahoo_send_http_request(int id, char *host, int port, char *request,
    305         yahoo_get_fd_callback callback, void *data, int use_ssl)
     324                                    yahoo_get_fd_callback callback, void *data, int use_ssl)
    306325{
    307326        struct callback_data *ccd = y_new0(struct callback_data, 1);
     327
    308328        ccd->callback = callback;
    309329        ccd->id = id;
     
    311331        ccd->user_data = data;
    312332
    313         YAHOO_CALLBACK(ext_yahoo_connect_async) (id, host, port,
    314                 connect_complete, ccd, use_ssl);
     333        YAHOO_CALLBACK (ext_yahoo_connect_async) (id, host, port,
     334                                                  connect_complete, ccd, use_ssl);
    315335}
    316336
    317337void yahoo_http_post(int id, const char *url, const char *cookies,
    318         long content_length, yahoo_get_fd_callback callback, void *data)
     338                     long content_length, yahoo_get_fd_callback callback, void *data)
    319339{
    320340        char host[255];
     
    324344        int ssl = 0;
    325345
    326         if (!url_to_host_port_path(url, host, &port, path, &ssl))
     346        if (!url_to_host_port_path(url, host, &port, path, &ssl)) {
    327347                return;
     348        }
    328349
    329350        /* thanks to kopete dumpcap */
    330351        snprintf(buff, sizeof(buff),
    331                 "POST %s HTTP/1.1\r\n"
    332                 "Cookie: %s\r\n"
    333                 "User-Agent: Mozilla/5.0\r\n"
    334                 "Host: %s\r\n"
    335                 "Content-Length: %ld\r\n"
    336                 "Cache-Control: no-cache\r\n"
    337                 "\r\n", path, cookies, host, content_length);
     352                 "POST %s HTTP/1.1\r\n"
     353                 "Cookie: %s\r\n"
     354                 "User-Agent: Mozilla/5.0\r\n"
     355                 "Host: %s\r\n"
     356                 "Content-Length: %ld\r\n"
     357                 "Cache-Control: no-cache\r\n"
     358                 "\r\n", path, cookies, host, content_length);
    338359
    339360        yahoo_send_http_request(id, host, port, buff, callback, data, ssl);
     
    341362
    342363void yahoo_http_get(int id, const char *url, const char *cookies, int http11,
    343         int keepalive, yahoo_get_fd_callback callback, void *data)
     364                    int keepalive, yahoo_get_fd_callback callback, void *data)
    344365{
    345366        char host[255];
     
    350371        int ssl = 0;
    351372
    352         if (!url_to_host_port_path(url, host, &port, path, &ssl))
     373        if (!url_to_host_port_path(url, host, &port, path, &ssl)) {
    353374                return;
     375        }
    354376
    355377        /* Allow cases when we don't need to send a cookie */
    356         if (cookies)
     378        if (cookies) {
    357379                snprintf(cookiebuff, sizeof(cookiebuff), "Cookie: %s\r\n",
    358                         cookies);
    359         else
     380                         cookies);
     381        } else {
    360382                cookiebuff[0] = '\0';
     383        }
    361384
    362385        snprintf(buff, sizeof(buff),
    363                 "GET %s HTTP/1.%s\r\n"
    364                 "%sHost: %s\r\n"
    365                 "User-Agent: Mozilla/4.5 [en] (" PACKAGE "/" VERSION ")\r\n"
    366                 "Accept: */*\r\n"
    367                 "%s" "\r\n", path, http11?"1":"0", cookiebuff, host,
    368                 keepalive? "Connection: Keep-Alive\r\n":"Connection: close\r\n");
     386                 "GET %s HTTP/1.%s\r\n"
     387                 "%sHost: %s\r\n"
     388                 "User-Agent: Mozilla/4.5 [en] (" PACKAGE "/" VERSION ")\r\n"
     389                 "Accept: */*\r\n"
     390                 "%s" "\r\n", path, http11 ? "1" : "0", cookiebuff, host,
     391                 keepalive ? "Connection: Keep-Alive\r\n" : "Connection: close\r\n");
    369392
    370393        yahoo_send_http_request(id, host, port, buff, callback, data, ssl);
     
    372395
    373396void yahoo_http_head(int id, const char *url, const char *cookies, int len,
    374         char *payload, yahoo_get_fd_callback callback, void *data)
     397                     char *payload, yahoo_get_fd_callback callback, void *data)
    375398{
    376399        char host[255];
     
    381404        int ssl = 0;
    382405
    383         if (!url_to_host_port_path(url, host, &port, path, &ssl))
     406        if (!url_to_host_port_path(url, host, &port, path, &ssl)) {
    384407                return;
     408        }
    385409
    386410        /* Allow cases when we don't need to send a cookie */
    387         if (cookies)
     411        if (cookies) {
    388412                snprintf(cookiebuff, sizeof(cookiebuff), "Cookie: %s\r\n",
    389                         cookies);
    390         else
     413                         cookies);
     414        } else {
    391415                cookiebuff[0] = '\0';
     416        }
    392417
    393418        snprintf(buff, sizeof(buff),
    394                 "HEAD %s HTTP/1.0\r\n"
    395                 "Accept: */*\r\n"
    396                 "Host: %s:%d\r\n"
    397                 "User-Agent: Mozilla/4.5 [en] (" PACKAGE "/" VERSION ")\r\n"
    398                 "%s"
    399                 "Content-Length: %d\r\n"
    400                 "Cache-Control: no-cache\r\n"
    401                 "\r\n%s", path, host, port, cookiebuff, len,
    402                 payload?payload:"");
     419                 "HEAD %s HTTP/1.0\r\n"
     420                 "Accept: */*\r\n"
     421                 "Host: %s:%d\r\n"
     422                 "User-Agent: Mozilla/4.5 [en] (" PACKAGE "/" VERSION ")\r\n"
     423                 "%s"
     424                 "Content-Length: %d\r\n"
     425                 "Cache-Control: no-cache\r\n"
     426                 "\r\n%s", path, host, port, cookiebuff, len,
     427                 payload ? payload : "");
    403428
    404429        yahoo_send_http_request(id, host, port, buff, callback, data, ssl);
Note: See TracChangeset for help on using the changeset viewer.