Changeset 5ebff60 for lib/proxy.c


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
  • lib/proxy.c

    raf359b4 r5ebff60  
    6868        socklen_t len;
    6969        int error = ETIMEDOUT;
     70
    7071        len = sizeof(error);
    71        
     72
    7273        if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0 || error) {
    7374                if ((phb->gai_cur = phb->gai_cur->ai_next)) {
     
    8788                b_event_remove(phb->inpa);
    8889                phb->inpa = 0;
    89                 if( phb->proxy_func )
     90                if (phb->proxy_func) {
    9091                        phb->proxy_func(phb->proxy_data, -1, B_EV_IO_READ);
    91                 else {
     92                } else {
    9293                        phb->func(phb->data, -1, B_EV_IO_READ);
    9394                        g_free(phb);
     
    99100        b_event_remove(phb->inpa);
    100101        phb->inpa = 0;
    101         if( phb->proxy_func )
     102        if (phb->proxy_func) {
    102103                phb->proxy_func(phb->proxy_data, source, B_EV_IO_READ);
    103         else {
     104        } else {
    104105                phb->func(phb->data, source, B_EV_IO_READ);
    105106                g_free(phb);
    106107        }
    107        
     108
    108109        return FALSE;
    109110}
     
    113114        struct sockaddr_in me;
    114115        int fd = -1;
    115        
    116         if (phb->gai_cur == NULL)
    117         {
     116
     117        if (phb->gai_cur == NULL) {
    118118                int ret;
    119119                char port[6];
    120120                struct addrinfo hints;
    121        
     121
    122122                g_snprintf(port, sizeof(port), "%d", port_);
    123        
     123
    124124                memset(&hints, 0, sizeof(struct addrinfo));
    125125                hints.ai_family = AF_UNSPEC;
    126126                hints.ai_socktype = SOCK_STREAM;
    127127                hints.ai_flags = AI_ADDRCONFIG | AI_NUMERICSERV;
    128        
    129                 if (!(ret = getaddrinfo(host, port, &hints, &phb->gai)))
     128
     129                if (!(ret = getaddrinfo(host, port, &hints, &phb->gai))) {
    130130                        phb->gai_cur = phb->gai;
    131                 else
     131                } else {
    132132                        event_debug("gai(): %s\n", gai_strerror(ret));
    133         }
    134        
    135         for (; phb->gai_cur; phb->gai_cur = phb->gai_cur->ai_next)
    136         {
     133                }
     134        }
     135
     136        for (; phb->gai_cur; phb->gai_cur = phb->gai_cur->ai_next) {
    137137                if ((fd = socket(phb->gai_cur->ai_family, phb->gai_cur->ai_socktype, phb->gai_cur->ai_protocol)) < 0) {
    138                         event_debug( "socket failed: %d\n", errno);
     138                        event_debug("socket failed: %d\n", errno);
    139139                        continue;
    140140                }
     
    142142                sock_make_nonblocking(fd);
    143143
    144                 if (global.conf->iface_out)
    145                 {
     144                if (global.conf->iface_out) {
    146145                        me.sin_family = AF_INET;
    147146                        me.sin_port = 0;
    148                         me.sin_addr.s_addr = inet_addr( global.conf->iface_out );
    149                                
    150                         if (bind(fd, (struct sockaddr *) &me, sizeof(me)) != 0)
     147                        me.sin_addr.s_addr = inet_addr(global.conf->iface_out);
     148
     149                        if (bind(fd, (struct sockaddr *) &me, sizeof(me)) != 0) {
    151150                                event_debug("bind( %d, \"%s\" ) failure\n", fd, global.conf->iface_out);
     151                        }
    152152                }
    153153
    154154                event_debug("proxy_connect_none( \"%s\", %d ) = %d\n", host, port_, fd);
    155        
     155
    156156                if (connect(fd, phb->gai_cur->ai_addr, phb->gai_cur->ai_addrlen) < 0 && !sockerr_again()) {
    157                         event_debug( "connect failed: %s\n", strerror(errno));
     157                        event_debug("connect failed: %s\n", strerror(errno));
    158158                        closesocket(fd);
    159159                        fd = -1;
     
    162162                        phb->inpa = b_input_add(fd, B_EV_IO_WRITE, gaim_io_connected, phb);
    163163                        phb->fd = fd;
    164                        
     164
    165165                        break;
    166166                }
    167167        }
    168        
    169         if(fd < 0 && host)
    170                 g_free(phb);
     168
     169        if (fd < 0 && host) {
     170                g_free(phb);
     171        }
    171172
    172173        return fd;
     
    188189        b_event_remove(phb->inpa);
    189190
    190         while ((pos < sizeof(inputline)-1) && (nlc != 2) && (read(source, &inputline[pos++], 1) == 1)) {
    191                 if (inputline[pos - 1] == '\n')
     191        while ((pos < sizeof(inputline) - 1) && (nlc != 2) && (read(source, &inputline[pos++], 1) == 1)) {
     192                if (inputline[pos - 1] == '\n') {
    192193                        nlc++;
    193                 else if (inputline[pos - 1] != '\r')
     194                } else if (inputline[pos - 1] != '\r') {
    194195                        nlc = 0;
     196                }
    195197        }
    196198        inputline[pos] = '\0';
     
    208210        g_free(phb->host);
    209211        g_free(phb);
    210        
     212
    211213        return FALSE;
    212214}
     
    218220        socklen_t len;
    219221        int error = ETIMEDOUT;
    220         if (phb->inpa > 0)
     222
     223        if (phb->inpa > 0) {
    221224                b_event_remove(phb->inpa);
     225        }
    222226        len = sizeof(error);
    223227        if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
     
    231235
    232236        g_snprintf(cmd, sizeof(cmd), "CONNECT %s:%d HTTP/1.1\r\nHost: %s:%d\r\n", phb->host, phb->port,
    233                    phb->host, phb->port);
     237                   phb->host, phb->port);
    234238        if (send(source, cmd, strlen(cmd), 0) < 0) {
    235239                close(source);
     
    266270
    267271        phb->inpa = b_input_add(source, B_EV_IO_READ, http_canread, phb);
    268        
     272
    269273        return FALSE;
    270274}
     
    276280        phb->proxy_func = http_canwrite;
    277281        phb->proxy_data = phb;
    278        
    279         return( proxy_connect_none( proxyhost, proxyport, phb ) );
     282
     283        return(proxy_connect_none(proxyhost, proxyport, phb));
    280284}
    281285
     
    302306        g_free(phb->host);
    303307        g_free(phb);
    304        
     308
    305309        return FALSE;
    306310}
     
    313317        socklen_t len;
    314318        int error = ETIMEDOUT;
    315         if (phb->inpa > 0)
     319
     320        if (phb->inpa > 0) {
    316321                b_event_remove(phb->inpa);
     322        }
    317323        len = sizeof(error);
    318324        if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
     
    338344        packet[2] = phb->port >> 8;
    339345        packet[3] = phb->port & 0xff;
    340         packet[4] = (unsigned char)(hp->h_addr_list[0])[0];
    341         packet[5] = (unsigned char)(hp->h_addr_list[0])[1];
    342         packet[6] = (unsigned char)(hp->h_addr_list[0])[2];
    343         packet[7] = (unsigned char)(hp->h_addr_list[0])[3];
     346        packet[4] = (unsigned char) (hp->h_addr_list[0])[0];
     347        packet[5] = (unsigned char) (hp->h_addr_list[0])[1];
     348        packet[6] = (unsigned char) (hp->h_addr_list[0])[2];
     349        packet[7] = (unsigned char) (hp->h_addr_list[0])[3];
    344350        packet[8] = 0;
    345351        if (write(source, packet, 9) != 9) {
     
    352358
    353359        phb->inpa = b_input_add(source, B_EV_IO_READ, s4_canread, phb);
    354        
     360
    355361        return FALSE;
    356362}
     
    362368        phb->proxy_func = s4_canwrite;
    363369        phb->proxy_data = phb;
    364        
    365         return( proxy_connect_none( proxyhost, proxyport, phb ) );
     370
     371        return(proxy_connect_none(proxyhost, proxyport, phb));
    366372}
    367373
     
    394400        g_free(phb->host);
    395401        g_free(phb);
    396        
     402
    397403        return FALSE;
    398404}
     
    403409        struct PHB *phb = data;
    404410        int hlen = strlen(phb->host);
    405        
     411
    406412        buf[0] = 0x05;
    407         buf[1] = 0x01;          /* CONNECT */
    408         buf[2] = 0x00;          /* reserved */
    409         buf[3] = 0x03;          /* address type -- host name */
     413        buf[1] = 0x01;          /* CONNECT */
     414        buf[2] = 0x00;          /* reserved */
     415        buf[3] = 0x03;          /* address type -- host name */
    410416        buf[4] = hlen;
    411417        memcpy(buf + 5, phb->host, hlen);
     
    448454
    449455        s5_sendconnect(phb, source);
    450        
     456
    451457        return FALSE;
    452458}
     
    477483        if (buf[1] == 0x02) {
    478484                unsigned int i = strlen(proxyuser), j = strlen(proxypass);
    479                 buf[0] = 0x01;  /* version 1 */
     485                buf[0] = 0x01;  /* version 1 */
    480486                buf[1] = i;
    481487                memcpy(buf + 2, proxyuser, i);
     
    494500                s5_sendconnect(phb, source);
    495501        }
    496        
     502
    497503        return FALSE;
    498504}
     
    505511        socklen_t len;
    506512        int error = ETIMEDOUT;
    507         if (phb->inpa > 0)
     513
     514        if (phb->inpa > 0) {
    508515                b_event_remove(phb->inpa);
     516        }
    509517        len = sizeof(error);
    510518        if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
     
    518526
    519527        i = 0;
    520         buf[0] = 0x05;          /* SOCKS version 5 */
     528        buf[0] = 0x05;          /* SOCKS version 5 */
    521529        if (proxyuser[0]) {
    522                 buf[1] = 0x02;  /* two methods */
    523                 buf[2] = 0x00;  /* no authentication */
    524                 buf[3] = 0x02;  /* username/password authentication */
     530                buf[1] = 0x02;  /* two methods */
     531                buf[2] = 0x00;  /* no authentication */
     532                buf[3] = 0x02;  /* username/password authentication */
    525533                i = 4;
    526534        } else {
     
    539547
    540548        phb->inpa = b_input_add(source, B_EV_IO_READ, s5_canread, phb);
    541        
     549
    542550        return FALSE;
    543551}
     
    549557        phb->proxy_func = s5_canwrite;
    550558        phb->proxy_data = phb;
    551        
    552         return( proxy_connect_none( proxyhost, proxyport, phb ) );
     559
     560        return(proxy_connect_none(proxyhost, proxyport, phb));
    553561}
    554562
     
    559567{
    560568        struct PHB *phb;
    561        
     569
    562570        if (!host || port <= 0 || !func || strlen(host) > 128) {
    563571                return -1;
    564572        }
    565        
     573
    566574        phb = g_new0(struct PHB, 1);
    567575        phb->func = func;
    568576        phb->data = data;
    569        
    570         if (proxytype == PROXY_NONE || !proxyhost[0] || proxyport <= 0)
     577
     578        if (proxytype == PROXY_NONE || !proxyhost[0] || proxyport <= 0) {
    571579                return proxy_connect_none(host, port, phb);
    572         else if (proxytype == PROXY_HTTP)
     580        } else if (proxytype == PROXY_HTTP) {
    573581                return proxy_connect_http(host, port, phb);
    574         else if (proxytype == PROXY_SOCKS4)
     582        } else if (proxytype == PROXY_SOCKS4) {
    575583                return proxy_connect_socks4(host, port, phb);
    576         else if (proxytype == PROXY_SOCKS5)
     584        } else if (proxytype == PROXY_SOCKS5) {
    577585                return proxy_connect_socks5(host, port, phb);
    578        
     586        }
     587
    579588        g_free(phb);
    580589        return -1;
Note: See TracChangeset for help on using the changeset viewer.