Changeset 2288705 for lib


Ignore:
Timestamp:
2009-12-07T21:54:19Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
1c3008a
Parents:
aac4017 (diff), 36cf9fd (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merging head.

Location:
lib
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • lib/events_libevent.c

    raac4017 r2288705  
    3737
    3838static void b_main_restart();
    39 static guint id_next = 1;
     39static guint id_next = 1; /* Next ID to be allocated to an event handler. */
     40static guint id_cur = 0; /* Event ID that we're currently handling. */
     41static guint id_dead; /* Set to 1 if b_event_remove removes id_cur. */
    4042static GHashTable *id_hash;
    41 static int quitting = 0;
     43static int quitting = 0; /* Prepare to quit, stop handling events. */
    4244
    4345/* Since libevent doesn't handle two event handlers for one fd-condition
     
    119121        struct b_event_data *b_ev = data;
    120122        b_input_condition cond = 0;
    121         int id;
     123        gboolean st;
    122124       
    123125        if( fd >= 0 )
     
    133135        /* Since the called function might cancel this handler already
    134136           (which free()s b_ev), we have to remember the ID here. */
    135         id = b_ev->id;
     137        id_cur = b_ev->id;
     138        id_dead = 0;
    136139       
    137140        if( quitting )
    138141        {
    139                 b_event_remove( id );
     142                b_event_remove( id_cur );
    140143                return;
    141144        }
    142145       
    143         if( !b_ev->function( b_ev->data, fd, cond ) )
     146        st = b_ev->function( b_ev->data, fd, cond );
     147        if( id_dead )
     148        {
     149                /* This event was killed already, don't touch it! */
     150                return;
     151        }
     152        else if( !st )
    144153        {
    145154                event_debug( "Handler returned FALSE: " );
    146                 b_event_remove( id );
     155                b_event_remove( id_cur );
    147156        }
    148157        else if( fd == -1 )
    149158        {
     159                /* fd == -1 means it was a timer. These can't be auto-repeated
     160                   so it has to be recreated every time. */
    150161                struct timeval tv;
    151162               
     
    236247        if( b_ev )
    237248        {
     249                if( id == id_cur )
     250                        id_dead = TRUE;
     251               
    238252                g_hash_table_remove( id_hash, &b_ev->id );
    239253                if( b_ev->evinfo.ev_fd >= 0 )
  • lib/http_client.c

    raac4017 r2288705  
    5959        if( error )
    6060        {
    61                 g_free( req );
    62                 return( NULL );
     61                http_free( req );
     62                return NULL;
    6363        }
    6464       
     
    160160       
    161161        req->func( req );
    162        
    163         g_free( req->request );
    164         g_free( req );
    165        
     162        http_free( req );
    166163        return FALSE;
    167164}
     
    444441       
    445442        req->func( req );
    446        
     443        http_free( req );
     444        return FALSE;
     445}
     446
     447void http_free( struct http_request *req )
     448{
    447449        g_free( req->request );
    448450        g_free( req->reply_headers );
    449451        g_free( req->status_string );
    450452        g_free( req );
    451        
    452         return FALSE;
    453 }
     453}
     454
  • lib/http_client.h

    raac4017 r2288705  
    8181void *http_dorequest( char *host, int port, int ssl, char *request, http_input_function func, gpointer data );
    8282void *http_dorequest_url( char *url_string, http_input_function func, gpointer data );
     83
     84void http_free( struct http_request *req );
  • lib/ini.c

    raac4017 r2288705  
    22  * BitlBee -- An IRC to other IM-networks gateway                     *
    33  *                                                                    *
    4   * Copyright 2002-2005 Wilmer van der Gaast and others                *
     4  * Copyright 2002-2008 Wilmer van der Gaast and others                *
    55  \********************************************************************/
    66
     
    2828ini_t *ini_open( char *file )
    2929{
    30         ini_t *ini = g_new0( ini_t, 1 );
     30        int fd;
     31        ini_t *ini = NULL;
     32        struct stat fi;
    3133       
    32         if( ( ini->fp = fopen( file, "r" ) ) == NULL )
     34        if( ( fd = open( file, O_RDONLY ) ) != -1 &&
     35            fstat( fd, &fi ) == 0 &&
     36            fi.st_size <= 16384 &&
     37            ( ini = g_malloc( sizeof( ini_t ) + fi.st_size + 1 ) ) &&
     38            read( fd, ini->file, fi.st_size ) == fi.st_size )
    3339        {
    34                 g_free( ini );
    35                 return( NULL );
     40                memset( ini, 0, sizeof( ini_t ) );
     41                ini->size = fi.st_size;
     42                ini->file[ini->size] = 0;
     43                ini->cur = ini->file;
     44                ini->c_section = "";
     45               
     46                close( fd );
     47               
     48                return ini;
    3649        }
     50
     51        if( fd >= 0 )
     52                close( fd );
    3753       
    38         return( ini );
     54        ini_close( ini );
     55
     56        return NULL;
     57}
     58
     59/* Strips leading and trailing whitespace and returns a pointer to the first
     60   non-ws character of the given string. */
     61static char *ini_strip_whitespace( char *in )
     62{
     63        char *e;
     64
     65        while( isspace( *in ) )
     66                in++;
     67
     68        e = in + strlen( in ) - 1;
     69        while( e > in && isspace( *e ) )
     70                e--;
     71        e[1] = 0;
     72       
     73        return in;
    3974}
    4075
    4176int ini_read( ini_t *file )
    4277{
    43         char key[MAX_STRING], s[MAX_STRING], *t;
    44         int i;
     78        char *s;
    4579       
    46         while( !feof( file->fp ) )
     80        while( file->cur && file->cur < file->file + file->size )
    4781        {
    48                 *s = 0;
    49                 fscanf( file->fp, "%127[^\n#]s", s );
    50                 fscanf( file->fp, "%*[^\n]s" );
    51                 fgetc( file->fp );              /* Skip newline         */
    52                 file->line ++;
    53                 if( strchr( s, '=' ) )
     82                char *e, *next;
     83               
     84                file->line++;
     85
     86                /* Find the end of line */
     87                if( ( e = strchr( file->cur, '\n' ) ) != NULL )
    5488                {
    55                         sscanf( s, "%[^ =]s", key );
    56                         if( ( t = strchr( key, '.' ) ) )
     89                        *e = 0;
     90                        next = e + 1;
     91                }
     92                else
     93                {
     94                        /* No more lines. */
     95                        e = file->cur + strlen( file->cur );
     96                        next = NULL;
     97                }
     98               
     99                /* Comment? */
     100                if( ( s = strchr( file->cur, '#' ) ) != NULL )
     101                        *s = 0;
     102               
     103                file->cur = ini_strip_whitespace( file->cur );
     104               
     105                if( *file->cur == '[' )
     106                {
     107                        file->cur++;
     108                        if( ( s = strchr( file->cur, ']' ) ) != NULL )
    57109                        {
    58                                 *t = 0;
    59                                 strcpy( file->section, key );
    60                                 t ++;
     110                                *s = 0;
     111                                file->c_section = file->cur;
     112                        }
     113                }
     114                else if( ( s = strchr( file->cur, '=' ) ) != NULL )
     115                {
     116                        *s = 0;
     117                        file->key = ini_strip_whitespace( file->cur );
     118                        file->value = ini_strip_whitespace( s + 1 );
     119                       
     120                        if( ( s = strchr( file->key, '.' ) ) != NULL )
     121                        {
     122                                *s = 0;
     123                                file->section = file->key;
     124                                file->key = s + 1;
    61125                        }
    62126                        else
    63127                        {
    64                                 strcpy( file->section, file->c_section );
    65                                 t = key;
     128                                file->section = file->c_section;
    66129                        }
    67                         sscanf( t, "%s", file->key );
    68                         t = strchr( s, '=' ) + 1;
    69                         for( i = 0; t[i] == ' '; i ++ );
    70                         strcpy( file->value, &t[i] );
    71                         for( i = strlen( file->value ) - 1; file->value[i] == 32; i -- )
    72                                 file->value[i] = 0;
    73130                       
    74                         return( 1 );
     131                        file->cur = next;
     132                        return 1;
    75133                }
    76                 else if( ( t = strchr( s, '[' ) ) )
    77                 {
    78                         strcpy( file->c_section, t + 1 );
    79                         t = strchr( file->c_section, ']' );
    80                         *t = 0;
    81                 }
     134                /* else: noise/comment/etc, let's just ignore it. */
     135
     136                file->cur = next;
    82137        }
    83         return( 0 );
     138       
     139        return 0;
    84140}
    85141
    86142void ini_close( ini_t *file )
    87143{
    88         fclose( file->fp );
    89144        g_free( file );
    90145}
  • lib/ini.h

    raac4017 r2288705  
    2929typedef struct
    3030{
    31         FILE *fp;
    3231        int line;
    33         char c_section[MAX_STRING];
    34         char section[MAX_STRING];
    35         char key[MAX_STRING];
    36         char value[MAX_STRING];
     32        char *c_section;
     33        char *section;
     34        char *key;
     35        char *value;
     36        int size;
     37        char *cur, *tok;
     38        char file[];
    3739} ini_t;
    3840
  • lib/misc.c

    raac4017 r2288705  
    4646#endif
    4747
     48#include "md5.h"
    4849#include "ssl_client.h"
    4950
  • lib/proxy.c

    raac4017 r2288705  
    558558                return proxy_connect_socks5(host, port, phb);
    559559       
    560         if (phb->host) g_free(phb);
    561560        g_free(phb);
    562561        return -1;
  • lib/xmltree.c

    raac4017 r2288705  
    472472}
    473473
    474 struct xt_node *xt_new_node( char *name, char *text, struct xt_node *children )
     474struct xt_node *xt_new_node( char *name, const char *text, struct xt_node *children )
    475475{
    476476        struct xt_node *node, *c;
  • lib/xmltree.h

    raac4017 r2288705  
    9090char *xt_find_attr( struct xt_node *node, const char *key );
    9191
    92 struct xt_node *xt_new_node( char *name, char *text, struct xt_node *children );
     92struct xt_node *xt_new_node( char *name, const char *text, struct xt_node *children );
    9393void xt_add_child( struct xt_node *parent, struct xt_node *child );
    9494void xt_add_attr( struct xt_node *node, const char *key, const char *value );
Note: See TracChangeset for help on using the changeset viewer.