Changeset 84e9cea


Ignore:
Timestamp:
2006-06-20T21:36:53Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
2befb95
Parents:
d028a77
Message:

Added xml_remove() and xml_check_pass().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • storage_xml.c

    rd028a77 r84e9cea  
    3535} xml_pass_st;
    3636
     37/* This isn't very clean, probably making a separate error class + code for
     38   BitlBee would be a better solution. But this will work for now... */
    3739#define XML_PASS_ERRORMSG "Wrong username or password"
    3840
     
    194196{
    195197        struct xml_parsedata *xd = data;
    196         // irc_t *irc = xd->irc;
    197198       
    198199        if( g_strcasecmp( element_name, "setting" ) == 0 && xd->current_setting )
     
    215216        {
    216217                /* Let's not parse anything else if we only have to check
    217                    the password. */
     218                   the password, or if we didn't get the chance to check it
     219                   yet. */
    218220        }
    219221        else if( g_strcasecmp( g_markup_parse_context_get_element( ctx ), "setting" ) == 0 &&
     
    243245}
    244246
    245 static storage_status_t xml_load( const char *my_nick, const char *password, irc_t *irc )
     247static storage_status_t xml_load_real( const char *my_nick, const char *password, irc_t *irc, xml_pass_st action )
    246248{
    247249        GMarkupParseContext *ctx;
     
    251253        int fd, st;
    252254       
    253         if( irc->status & USTATUS_IDENTIFIED )
     255        if( irc && irc->status & USTATUS_IDENTIFIED )
    254256                return( 1 );
    255257       
     
    258260        xd->given_nick = g_strdup( my_nick );
    259261        xd->given_pass = g_strdup( password );
     262        xd->pass_st = action;
    260263        nick_lc( xd->given_nick );
    261264       
     
    283286                        else
    284287                        {
    285                                 if( gerr )
     288                                if( gerr && irc )
    286289                                        irc_usermsg( irc, "Error from XML-parser: %s", gerr->message );
    287290                               
     
    294297        close( fd );
    295298       
     299        if( action == XML_PASS_CHECK_ONLY )
     300                return STORAGE_OK;
     301       
    296302        irc->status |= USTATUS_IDENTIFIED;
    297303       
     
    304310       
    305311        return STORAGE_OK;
     312}
     313
     314static storage_status_t xml_load( const char *my_nick, const char *password, irc_t *irc )
     315{
     316        return xml_load_real( my_nick, password, irc, XML_PASS_UNKNOWN );
     317}
     318
     319static storage_status_t xml_check_pass( const char *my_nick, const char *password )
     320{
     321        /* This is a little bit risky because we have to pass NULL for the
     322           irc_t argument. This *should* be fine, if I didn't miss anything... */
     323        return xml_load_real( my_nick, password, NULL, XML_PASS_CHECK_ONLY );
    306324}
    307325
     
    396414}
    397415
     416static storage_status_t xml_remove( const char *nick, const char *password )
     417{
     418        char s[512];
     419        storage_status_t status;
     420
     421        status = xml_check_pass( nick, password );
     422        if( status != STORAGE_OK )
     423                return status;
     424
     425        g_snprintf( s, 511, "%s%s%s", global.conf->configdir, nick, ".xml" );
     426        if( unlink( s ) == -1 )
     427                return STORAGE_OTHER_ERROR;
     428       
     429        return STORAGE_OK;
     430}
     431
    398432storage_t storage_xml = {
    399433        .name = "xml",
    400434        .init = xml_init,
    401 //      .check_pass = xml_check_pass,
    402 //      .remove = xml_remove,
     435        .check_pass = xml_check_pass,
     436        .remove = xml_remove,
    403437        .load = xml_load,
    404438        .save = xml_save
Note: See TracChangeset for help on using the changeset viewer.