Changeset 0fbda193


Ignore:
Timestamp:
2008-02-02T21:48:09Z (16 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
979cfb4
Parents:
f774e01
Message:

Added help_free() and cleaned up some very stale help-related stuff I
wasn't even aware of. This closes bug #352.

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • help.c

    rf774e01 r0fbda193  
    7171                {
    7272                        /* FIXME: Clean up */
    73 //                      help_close( *help );
    74                         *help = NULL;
     73                        help_free( help );
    7574                        g_free( s );
    76                         return( NULL );
     75                        return NULL;
    7776                }
    7877                i = strchr( s, '\n' ) - s;
    7978               
    80                 if( h->string )
     79                if( h->title )
    8180                {
    8281                        h = h->next = g_new0( help_t, 1 );
    8382                }
    84                 h->string = g_new ( char, i );
     83                h->title = g_new ( char, i );
    8584               
    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;
    8887                h->fd = (*help)->fd;
    8988                h->offset.file_offset = lseek( h->fd, 0, SEEK_CUR ) - buflen + i + 1;
     
    103102}
    104103
    105 char *help_get( help_t **help, char *string )
     104void 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
     128char *help_get( help_t **help, char *title )
    106129{
    107130        time_t mtime;
     
    111134        for( h = *help; h; h = h->next )
    112135        {
    113                 if( h->string != NULL &&
    114                         g_strcasecmp( h->string, string ) == 0 )
     136                if( h->title != NULL && g_strcasecmp( h->title, title ) == 0 )
    115137                        break;
    116138        }
     
    119141                char *s = g_new( char, h->length + 1 );
    120142               
    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                
    132143                s[h->length] = 0;
    133144                if( h->fd >= 0 )
    134145                {
     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                       
    135159                        lseek( h->fd, h->offset.file_offset, SEEK_SET );
    136160                        read( h->fd, s, h->length );
  • help.h

    rf774e01 r0fbda193  
    3737        int fd;
    3838        time_t mtime;
    39         char *string;
     39        char *title;
    4040        help_off_t offset;
    4141        int length;
     
    4444
    4545G_GNUC_MALLOC help_t *help_init( help_t **help, const char *helpfile );
    46 char *help_get( help_t **help, char *string );
     46void help_free( help_t **help );
     47char *help_get( help_t **help, char *title );
    4748
    4849#endif
  • irc.c

    rf774e01 r0fbda193  
    189189        account_t *account;
    190190        user_t *user, *usertmp;
    191         help_t *helpnode, *helpnodetmp;
    192191       
    193192        log_message( LOGLVL_INFO, "Destroying connection with fd %d", irc->fd );
     
    266265        g_hash_table_destroy(irc->watches);
    267266       
    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         }
    278267        g_free(irc);
    279268       
  • irc.h

    rf774e01 r0fbda193  
    8989        GHashTable *watches;
    9090        struct __NICK *nicks;
    91         struct help *help;
    9291        struct set *set;
    9392
  • irc_commands.c

    rf774e01 r0fbda193  
    556556       
    557557        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 );
    559559       
    560560        for( s = irc->set; s; s = s->next )
  • unix.c

    rf774e01 r0fbda193  
    124124        if( !getuid() || !geteuid() )
    125125                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 )
    127127                log_message( LOGLVL_WARNING, "Error opening helpfile %s.", HELP_FILE );
    128128       
    129129        b_main_run();
     130       
     131        /* Mainly good for restarting, to make sure we close the help.txt fd. */
     132        help_free( &global.help );
    130133       
    131134        if( global.restart )
Note: See TracChangeset for help on using the changeset viewer.