- Timestamp:
- 2009-03-12T19:33:28Z (16 years ago)
- Branches:
- master
- Children:
- fc34fb5
- Parents:
- 823de9d (diff), 9e768da (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. - Location:
- lib
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/events_libevent.c
r823de9d r673a54c 37 37 38 38 static void b_main_restart(); 39 static guint id_next = 1; 39 static guint id_next = 1; /* Next ID to be allocated to an event handler. */ 40 static guint id_cur = 0; /* Event ID that we're currently handling. */ 41 static guint id_dead; /* Set to 1 if b_event_remove removes id_cur. */ 40 42 static GHashTable *id_hash; 41 static int quitting = 0; 43 static int quitting = 0; /* Prepare to quit, stop handling events. */ 42 44 43 45 /* Since libevent doesn't handle two event handlers for one fd-condition … … 119 121 struct b_event_data *b_ev = data; 120 122 b_input_condition cond = 0; 121 int id;123 gboolean st; 122 124 123 125 if( fd >= 0 ) … … 133 135 /* Since the called function might cancel this handler already 134 136 (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; 136 139 137 140 if( quitting ) 138 141 { 139 b_event_remove( id );142 b_event_remove( id_cur ); 140 143 return; 141 144 } 142 145 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 ) 144 153 { 145 154 event_debug( "Handler returned FALSE: " ); 146 b_event_remove( id );155 b_event_remove( id_cur ); 147 156 } 148 157 else if( fd == -1 ) 149 158 { 159 /* fd == -1 means it was a timer. These can't be auto-repeated 160 so it has to be recreated every time. */ 150 161 struct timeval tv; 151 162 … … 236 247 if( b_ev ) 237 248 { 249 if( id == id_cur ) 250 id_dead = TRUE; 251 238 252 g_hash_table_remove( id_hash, &b_ev->id ); 239 253 if( b_ev->evinfo.ev_fd >= 0 ) -
lib/http_client.c
r823de9d r673a54c 59 59 if( error ) 60 60 { 61 g_free( req );62 return ( NULL );61 http_free( req ); 62 return NULL; 63 63 } 64 64 … … 160 160 161 161 req->func( req ); 162 163 g_free( req->request ); 164 g_free( req ); 165 162 http_free( req ); 166 163 return FALSE; 167 164 } … … 444 441 445 442 req->func( req ); 446 443 http_free( req ); 444 return FALSE; 445 } 446 447 void http_free( struct http_request *req ) 448 { 447 449 g_free( req->request ); 448 450 g_free( req->reply_headers ); 449 451 g_free( req->status_string ); 450 452 g_free( req ); 451 452 return FALSE; 453 } 453 } 454 -
lib/http_client.h
r823de9d r673a54c 81 81 void *http_dorequest( char *host, int port, int ssl, char *request, http_input_function func, gpointer data ); 82 82 void *http_dorequest_url( char *url_string, http_input_function func, gpointer data ); 83 84 void http_free( struct http_request *req ); -
lib/ini.c
r823de9d r673a54c 2 2 * BitlBee -- An IRC to other IM-networks gateway * 3 3 * * 4 * Copyright 2002-200 5Wilmer van der Gaast and others *4 * Copyright 2002-2008 Wilmer van der Gaast and others * 5 5 \********************************************************************/ 6 6 … … 28 28 ini_t *ini_open( char *file ) 29 29 { 30 ini_t *ini = g_new0( ini_t, 1 ); 30 int fd; 31 ini_t *ini = NULL; 32 struct stat fi; 31 33 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 ) 33 39 { 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 return ini; 36 46 } 37 47 38 return( ini ); 48 g_free( ini ); 49 if( fd >= 0 ) 50 close( fd ); 51 52 return NULL; 53 } 54 55 /* Strips leading and trailing whitespace and returns a pointer to the first 56 non-ws character of the given string. */ 57 static char *ini_strip_whitespace( char *in ) 58 { 59 char *e; 60 61 while( isspace( *in ) ) 62 in++; 63 64 e = in + strlen( in ) - 1; 65 while( e > in && isspace( *e ) ) 66 e--; 67 e[1] = 0; 68 69 return in; 39 70 } 40 71 41 72 int ini_read( ini_t *file ) 42 73 { 43 char key[MAX_STRING], s[MAX_STRING], *t; 44 int i; 74 char *s; 45 75 46 while( !feof( file->fp ))76 while( file->cur && file->cur < file->file + file->size ) 47 77 { 48 *s = 0;49 fscanf( file->fp, "%127[^\n#]s", s );50 f scanf( file->fp, "%*[^\n]s" );51 fgetc( file->fp ); /* Skip newline */ 52 file->line ++;53 if( strchr( s, '=' ))78 char *e, *next; 79 80 file->line++; 81 82 /* Find the end of line */ 83 if( ( e = strchr( file->cur, '\n' ) ) != NULL ) 54 84 { 55 sscanf( s, "%[^ =]s", key ); 56 if( ( t = strchr( key, '.' ) ) ) 85 *e = 0; 86 next = e + 1; 87 } 88 else 89 { 90 /* No more lines. */ 91 e = file->cur + strlen( file->cur ); 92 next = NULL; 93 } 94 95 /* Comment? */ 96 if( ( s = strchr( file->cur, '#' ) ) != NULL ) 97 *s = 0; 98 99 file->cur = ini_strip_whitespace( file->cur ); 100 101 if( *file->cur == '[' ) 102 { 103 file->cur++; 104 if( ( s = strchr( file->cur, ']' ) ) != NULL ) 57 105 { 58 *t = 0; 59 strcpy( file->section, key ); 60 t ++; 106 *s = 0; 107 file->c_section = file->cur; 108 } 109 } 110 else if( ( s = strchr( file->cur, '=' ) ) != NULL ) 111 { 112 *s = 0; 113 file->key = ini_strip_whitespace( file->cur ); 114 file->value = ini_strip_whitespace( s + 1 ); 115 116 if( ( s = strchr( file->key, '.' ) ) != NULL ) 117 { 118 *s = 0; 119 file->section = file->key; 120 file->key = s + 1; 61 121 } 62 122 else 63 123 { 64 strcpy( file->section, file->c_section ); 65 t = key; 124 file->section = file->c_section; 66 125 } 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;73 126 74 return( 1 ); 127 file->cur = next; 128 return 1; 75 129 } 76 else if( ( t = strchr( s, '[' ) ) ) 77 { 78 strcpy( file->c_section, t + 1 ); 79 t = strchr( file->c_section, ']' ); 80 *t = 0; 81 } 130 /* else: noise/comment/etc, let's just ignore it. */ 131 132 file->cur = next; 82 133 } 83 return( 0 ); 134 135 return 0; 84 136 } 85 137 86 138 void ini_close( ini_t *file ) 87 139 { 88 fclose( file->fp );89 140 g_free( file ); 90 141 } -
lib/ini.h
r823de9d r673a54c 29 29 typedef struct 30 30 { 31 FILE *fp;32 31 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[]; 37 39 } ini_t; 38 40 -
lib/proxy.c
r823de9d r673a54c 558 558 return proxy_connect_socks5(host, port, phb); 559 559 560 if (phb->host) g_free(phb);561 560 g_free(phb); 562 561 return -1; -
lib/xmltree.c
r823de9d r673a54c 472 472 } 473 473 474 struct xt_node *xt_new_node( char *name, c har *text, struct xt_node *children )474 struct xt_node *xt_new_node( char *name, const char *text, struct xt_node *children ) 475 475 { 476 476 struct xt_node *node, *c; -
lib/xmltree.h
r823de9d r673a54c 90 90 char *xt_find_attr( struct xt_node *node, const char *key ); 91 91 92 struct xt_node *xt_new_node( char *name, c har *text, struct xt_node *children );92 struct xt_node *xt_new_node( char *name, const char *text, struct xt_node *children ); 93 93 void xt_add_child( struct xt_node *parent, struct xt_node *child ); 94 94 void xt_add_attr( struct xt_node *node, const char *key, const char *value );
Note: See TracChangeset
for help on using the changeset viewer.