Changeset ba9edaa for protocols/proxy.c


Ignore:
Timestamp:
2006-05-10T17:34:46Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
13cc96c
Parents:
67b6766
Message:

Moved everything to the BitlBee event handling API.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/proxy.c

    r67b6766 rba9edaa  
    4949
    5050struct PHB {
    51         GaimInputFunction func, proxy_func;
     51        b_event_handler func, proxy_func;
    5252        gpointer data, proxy_data;
    5353        char *host;
     
    7878}
    7979
    80 static void gaim_io_connected(gpointer data, gint source, GaimInputCondition cond)
     80static gboolean gaim_io_connected(gpointer data, gint source, b_input_condition cond)
    8181{
    8282        struct PHB *phb = data;
     
    8888        if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
    8989                closesocket(source);
    90                 gaim_input_remove(phb->inpa);
     90                b_event_remove(phb->inpa);
    9191                if( phb->proxy_func )
    9292                        phb->proxy_func(phb->proxy_data, -1, GAIM_INPUT_READ);
     
    9595                        g_free(phb);
    9696                }
    97                 return;
     97                return FALSE;
    9898        }
    9999#endif
    100100        sock_make_blocking(source);
    101         gaim_input_remove(phb->inpa);
     101        b_event_remove(phb->inpa);
    102102        if( phb->proxy_func )
    103103                phb->proxy_func(phb->proxy_data, source, GAIM_INPUT_READ);
     
    106106                g_free(phb);
    107107        }
     108       
     109        return FALSE;
    108110}
    109111
     
    127129        if (connect(fd, (struct sockaddr *)sin, sizeof(*sin)) < 0) {
    128130                if (sockerr_again()) {
    129                         phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE, gaim_io_connected, phb);
     131                        phb->inpa = b_input_add(fd, GAIM_INPUT_WRITE, gaim_io_connected, phb);
    130132                        phb->fd = fd;
    131133                } else {
     
    145147#define HTTP_GOODSTRING2 "HTTP/1.1 200 Connection established"
    146148
    147 static void http_canread(gpointer data, gint source, GaimInputCondition cond)
     149static gboolean http_canread(gpointer data, gint source, b_input_condition cond)
    148150{
    149151        int nlc = 0;
     
    152154        char inputline[8192];
    153155
    154         gaim_input_remove(phb->inpa);
     156        b_event_remove(phb->inpa);
    155157
    156158        while ((pos < sizeof(inputline)-1) && (nlc != 2) && (read(source, &inputline[pos++], 1) == 1)) {
     
    167169                g_free(phb->host);
    168170                g_free(phb);
    169                 return;
     171                return FALSE;
    170172        }
    171173
     
    174176        g_free(phb->host);
    175177        g_free(phb);
    176         return;
    177 }
    178 
    179 static void http_canwrite(gpointer data, gint source, GaimInputCondition cond)
     178       
     179        return FALSE;
     180}
     181
     182static gboolean http_canwrite(gpointer data, gint source, b_input_condition cond)
    180183{
    181184        char cmd[384];
     
    184187        int error = ETIMEDOUT;
    185188        if (phb->inpa > 0)
    186                 gaim_input_remove(phb->inpa);
     189                b_event_remove(phb->inpa);
    187190        len = sizeof(error);
    188191        if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
     
    191194                g_free(phb->host);
    192195                g_free(phb);
    193                 return;
     196                return FALSE;
    194197        }
    195198        sock_make_blocking(source);
     
    202205                g_free(phb->host);
    203206                g_free(phb);
    204                 return;
     207                return FALSE;
    205208        }
    206209
     
    217220                        g_free(phb->host);
    218221                        g_free(phb);
    219                         return;
     222                        return FALSE;
    220223                }
    221224        }
     
    227230                g_free(phb->host);
    228231                g_free(phb);
    229                 return;
    230         }
    231 
    232         phb->inpa = gaim_input_add(source, GAIM_INPUT_READ, http_canread, phb);
     232                return FALSE;
     233        }
     234
     235        phb->inpa = b_input_add(source, GAIM_INPUT_READ, http_canread, phb);
     236       
     237        return FALSE;
    233238}
    234239
     
    246251/* Connecting to SOCKS4 proxies */
    247252
    248 static void s4_canread(gpointer data, gint source, GaimInputCondition cond)
     253static gboolean s4_canread(gpointer data, gint source, b_input_condition cond)
    249254{
    250255        unsigned char packet[12];
    251256        struct PHB *phb = data;
    252257
    253         gaim_input_remove(phb->inpa);
     258        b_event_remove(phb->inpa);
    254259
    255260        memset(packet, 0, sizeof(packet));
     
    258263                g_free(phb->host);
    259264                g_free(phb);
    260                 return;
     265                return FALSE;
    261266        }
    262267
     
    265270        g_free(phb->host);
    266271        g_free(phb);
    267 }
    268 
    269 static void s4_canwrite(gpointer data, gint source, GaimInputCondition cond)
     272       
     273        return FALSE;
     274}
     275
     276static gboolean s4_canwrite(gpointer data, gint source, b_input_condition cond)
    270277{
    271278        unsigned char packet[12];
     
    275282        int error = ETIMEDOUT;
    276283        if (phb->inpa > 0)
    277                 gaim_input_remove(phb->inpa);
     284                b_event_remove(phb->inpa);
    278285        len = sizeof(error);
    279286        if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
     
    282289                g_free(phb->host);
    283290                g_free(phb);
    284                 return;
     291                return FALSE;
    285292        }
    286293        sock_make_blocking(source);
     
    292299                g_free(phb->host);
    293300                g_free(phb);
    294                 return;
     301                return FALSE;
    295302        }
    296303
     
    309316                g_free(phb->host);
    310317                g_free(phb);
    311                 return;
    312         }
    313 
    314         phb->inpa = gaim_input_add(source, GAIM_INPUT_READ, s4_canread, phb);
     318                return FALSE;
     319        }
     320
     321        phb->inpa = b_input_add(source, GAIM_INPUT_READ, s4_canread, phb);
     322       
     323        return FALSE;
    315324}
    316325
     
    328337/* Connecting to SOCKS5 proxies */
    329338
    330 static void s5_canread_again(gpointer data, gint source, GaimInputCondition cond)
     339static gboolean s5_canread_again(gpointer data, gint source, b_input_condition cond)
    331340{
    332341        unsigned char buf[512];
    333342        struct PHB *phb = data;
    334343
    335         gaim_input_remove(phb->inpa);
     344        b_event_remove(phb->inpa);
    336345
    337346        if (read(source, buf, 10) < 10) {
     
    340349                g_free(phb->host);
    341350                g_free(phb);
    342                 return;
     351                return FALSE;
    343352        }
    344353        if ((buf[0] != 0x05) || (buf[1] != 0x00)) {
     
    347356                g_free(phb->host);
    348357                g_free(phb);
    349                 return;
     358                return FALSE;
    350359        }
    351360
     
    353362        g_free(phb->host);
    354363        g_free(phb);
    355         return;
     364       
     365        return FALSE;
    356366}
    357367
     
    361371        struct PHB *phb = data;
    362372        int hlen = strlen(phb->host);
    363 
     373       
    364374        buf[0] = 0x05;
    365375        buf[1] = 0x01;          /* CONNECT */
     
    379389        }
    380390
    381         phb->inpa = gaim_input_add(source, GAIM_INPUT_READ, s5_canread_again, phb);
    382 }
    383 
    384 static void s5_readauth(gpointer data, gint source, GaimInputCondition cond)
     391        phb->inpa = b_input_add(source, GAIM_INPUT_READ, s5_canread_again, phb);
     392}
     393
     394static gboolean s5_readauth(gpointer data, gint source, b_input_condition cond)
    385395{
    386396        unsigned char buf[512];
    387397        struct PHB *phb = data;
    388398
    389         gaim_input_remove(phb->inpa);
     399        b_event_remove(phb->inpa);
    390400
    391401        if (read(source, buf, 2) < 2) {
     
    394404                g_free(phb->host);
    395405                g_free(phb);
    396                 return;
     406                return FALSE;
    397407        }
    398408
     
    402412                g_free(phb->host);
    403413                g_free(phb);
    404                 return;
     414                return FALSE;
    405415        }
    406416
    407417        s5_sendconnect(phb, source);
    408 }
    409 
    410 static void s5_canread(gpointer data, gint source, GaimInputCondition cond)
     418       
     419        return FALSE;
     420}
     421
     422static gboolean s5_canread(gpointer data, gint source, b_input_condition cond)
    411423{
    412424        unsigned char buf[512];
    413425        struct PHB *phb = data;
    414426
    415         gaim_input_remove(phb->inpa);
     427        b_event_remove(phb->inpa);
    416428
    417429        if (read(source, buf, 2) < 2) {
     
    420432                g_free(phb->host);
    421433                g_free(phb);
    422                 return;
     434                return FALSE;
    423435        }
    424436
     
    428440                g_free(phb->host);
    429441                g_free(phb);
    430                 return;
     442                return FALSE;
    431443        }
    432444
     
    443455                        g_free(phb->host);
    444456                        g_free(phb);
    445                         return;
     457                        return FALSE;
    446458                }
    447459
    448                 phb->inpa = gaim_input_add(source, GAIM_INPUT_READ, s5_readauth, phb);
     460                phb->inpa = b_input_add(source, GAIM_INPUT_READ, s5_readauth, phb);
    449461        } else {
    450462                s5_sendconnect(phb, source);
    451463        }
    452 }
    453 
    454 static void s5_canwrite(gpointer data, gint source, GaimInputCondition cond)
     464       
     465        return FALSE;
     466}
     467
     468static gboolean s5_canwrite(gpointer data, gint source, b_input_condition cond)
    455469{
    456470        unsigned char buf[512];
     
    460474        int error = ETIMEDOUT;
    461475        if (phb->inpa > 0)
    462                 gaim_input_remove(phb->inpa);
     476                b_event_remove(phb->inpa);
    463477        len = sizeof(error);
    464478        if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
     
    467481                g_free(phb->host);
    468482                g_free(phb);
    469                 return;
     483                return FALSE;
    470484        }
    471485        sock_make_blocking(source);
     
    489503                g_free(phb->host);
    490504                g_free(phb);
    491                 return;
    492         }
    493 
    494         phb->inpa = gaim_input_add(source, GAIM_INPUT_READ, s5_canread, phb);
     505                return FALSE;
     506        }
     507
     508        phb->inpa = b_input_add(source, GAIM_INPUT_READ, s5_canread, phb);
     509       
     510        return FALSE;
    495511}
    496512
     
    508524/* Export functions */
    509525
    510 int proxy_connect(const char *host, int port, GaimInputFunction func, gpointer data)
     526int proxy_connect(const char *host, int port, b_event_handler func, gpointer data)
    511527{
    512528        struct PHB *phb;
Note: See TracChangeset for help on using the changeset viewer.