Changeset 0fbda193
- Timestamp:
- 2008-02-02T21:48:09Z (17 years ago)
- Branches:
- master
- Children:
- 979cfb4
- Parents:
- f774e01
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
help.c
rf774e01 r0fbda193 71 71 { 72 72 /* FIXME: Clean up */ 73 // help_close( *help ); 74 *help = NULL; 73 help_free( help ); 75 74 g_free( s ); 76 return ( NULL );75 return NULL; 77 76 } 78 77 i = strchr( s, '\n' ) - s; 79 78 80 if( h-> string)79 if( h->title ) 81 80 { 82 81 h = h->next = g_new0( help_t, 1 ); 83 82 } 84 h-> string= g_new ( char, i );83 h->title = g_new ( char, i ); 85 84 86 strncpy( h-> string, s + 1, i - 1 );87 h-> string[i-1] = 0;85 strncpy( h->title, s + 1, i - 1 ); 86 h->title[i-1] = 0; 88 87 h->fd = (*help)->fd; 89 88 h->offset.file_offset = lseek( h->fd, 0, SEEK_CUR ) - buflen + i + 1; … … 103 102 } 104 103 105 char *help_get( help_t **help, char *string ) 104 void help_free( help_t **help ) 105 { 106 help_t *h, *oh; 107 int last_fd = -1; /* Weak de-dupe */ 108 109 if( help == NULL || *help == NULL ) 110 return; 111 112 h = *help; 113 while( h ) 114 { 115 if( h->fd != last_fd ) 116 { 117 close( h->fd ); 118 last_fd = h->fd; 119 } 120 g_free( h->title ); 121 h = (oh=h)->next; 122 g_free( oh ); 123 } 124 125 *help = NULL; 126 } 127 128 char *help_get( help_t **help, char *title ) 106 129 { 107 130 time_t mtime; … … 111 134 for( h = *help; h; h = h->next ) 112 135 { 113 if( h->string != NULL && 114 g_strcasecmp( h->string, string ) == 0 ) 136 if( h->title != NULL && g_strcasecmp( h->title, title ) == 0 ) 115 137 break; 116 138 } … … 119 141 char *s = g_new( char, h->length + 1 ); 120 142 121 if( fstat( h->fd, stat ) != 0 )122 {123 g_free( h );124 *help = NULL;125 return NULL;126 }127 mtime = stat->st_mtime;128 129 if( mtime > h->mtime )130 return NULL;131 132 143 s[h->length] = 0; 133 144 if( h->fd >= 0 ) 134 145 { 146 if( fstat( h->fd, stat ) != 0 ) 147 { 148 g_free( s ); 149 return NULL; 150 } 151 mtime = stat->st_mtime; 152 153 if( mtime > h->mtime ) 154 { 155 g_free( s ); 156 return NULL; 157 } 158 135 159 lseek( h->fd, h->offset.file_offset, SEEK_SET ); 136 160 read( h->fd, s, h->length ); -
help.h
rf774e01 r0fbda193 37 37 int fd; 38 38 time_t mtime; 39 char * string;39 char *title; 40 40 help_off_t offset; 41 41 int length; … … 44 44 45 45 G_GNUC_MALLOC help_t *help_init( help_t **help, const char *helpfile ); 46 char *help_get( help_t **help, char *string ); 46 void help_free( help_t **help ); 47 char *help_get( help_t **help, char *title ); 47 48 48 49 #endif -
irc.c
rf774e01 r0fbda193 189 189 account_t *account; 190 190 user_t *user, *usertmp; 191 help_t *helpnode, *helpnodetmp;192 191 193 192 log_message( LOGLVL_INFO, "Destroying connection with fd %d", irc->fd ); … … 266 265 g_hash_table_destroy(irc->watches); 267 266 268 if (irc->help != NULL) {269 helpnode = irc->help;270 while (helpnode != NULL) {271 g_free(helpnode->string);272 273 helpnodetmp = helpnode;274 helpnode = helpnode->next;275 g_free(helpnodetmp);276 }277 }278 267 g_free(irc); 279 268 -
irc.h
rf774e01 r0fbda193 89 89 GHashTable *watches; 90 90 struct __NICK *nicks; 91 struct help *help;92 91 struct set *set; 93 92 -
irc_commands.c
rf774e01 r0fbda193 556 556 557 557 for( h = global.help; h; h = h->next ) 558 irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS help ", h-> string);558 irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS help ", h->title ); 559 559 560 560 for( s = irc->set; s; s = s->next ) -
unix.c
rf774e01 r0fbda193 124 124 if( !getuid() || !geteuid() ) 125 125 log_message( LOGLVL_WARNING, "BitlBee is running with root privileges. Why?" ); 126 if( help_init( & (global.help), global.helpfile ) == NULL )126 if( help_init( &global.help, global.helpfile ) == NULL ) 127 127 log_message( LOGLVL_WARNING, "Error opening helpfile %s.", HELP_FILE ); 128 128 129 129 b_main_run(); 130 131 /* Mainly good for restarting, to make sure we close the help.txt fd. */ 132 help_free( &global.help ); 130 133 131 134 if( global.restart )
Note: See TracChangeset
for help on using the changeset viewer.