aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bitlbee.c2
-rw-r--r--ipc.c10
-rw-r--r--irc.c12
-rw-r--r--irc.h8
-rw-r--r--irc_commands.c6
-rw-r--r--protocols/msn/msn.c51
-rw-r--r--root_commands.c6
-rw-r--r--storage_text.c4
-rw-r--r--storage_xml.c123
9 files changed, 157 insertions, 65 deletions
diff --git a/bitlbee.c b/bitlbee.c
index 748b7bba..1d4e2b34 100644
--- a/bitlbee.c
+++ b/bitlbee.c
@@ -227,7 +227,7 @@ gboolean bitlbee_io_current_client_write( gpointer data, gint fd, b_input_condit
irc->sendbuffer = NULL;
irc->w_watch_source_id = 0;
- if( irc->status == USTATUS_SHUTDOWN )
+ if( irc->status & USTATUS_SHUTDOWN )
irc_free( irc );
return FALSE;
diff --git a/ipc.c b/ipc.c
index be9bda0b..28aa07cb 100644
--- a/ipc.c
+++ b/ipc.c
@@ -114,7 +114,7 @@ static void ipc_child_cmd_die( irc_t *irc, char **cmd )
static void ipc_child_cmd_wallops( irc_t *irc, char **cmd )
{
- if( irc->status < USTATUS_LOGGED_IN )
+ if( !( irc->status & USTATUS_LOGGED_IN ) )
return;
if( strchr( irc->umode, 'w' ) )
@@ -123,7 +123,7 @@ static void ipc_child_cmd_wallops( irc_t *irc, char **cmd )
static void ipc_child_cmd_lilo( irc_t *irc, char **cmd )
{
- if( irc->status < USTATUS_LOGGED_IN )
+ if( !( irc->status & USTATUS_LOGGED_IN ) )
return;
if( strchr( irc->umode, 's' ) )
@@ -132,7 +132,7 @@ static void ipc_child_cmd_lilo( irc_t *irc, char **cmd )
static void ipc_child_cmd_opermsg( irc_t *irc, char **cmd )
{
- if( irc->status < USTATUS_LOGGED_IN )
+ if( !( irc->status & USTATUS_LOGGED_IN ) )
return;
if( strchr( irc->umode, 'o' ) )
@@ -153,7 +153,7 @@ static void ipc_child_cmd_rehash( irc_t *irc, char **cmd )
static void ipc_child_cmd_kill( irc_t *irc, char **cmd )
{
- if( irc->status < USTATUS_LOGGED_IN )
+ if( !( irc->status & USTATUS_LOGGED_IN ) )
return;
if( nick_cmp( cmd[1], irc->nick ) != 0 )
@@ -165,7 +165,7 @@ static void ipc_child_cmd_kill( irc_t *irc, char **cmd )
static void ipc_child_cmd_hello( irc_t *irc, char **cmd )
{
- if( irc->status < USTATUS_LOGGED_IN )
+ if( !( irc->status & USTATUS_LOGGED_IN ) )
ipc_to_master_str( "HELLO\r\n" );
else
ipc_to_master_str( "HELLO %s %s :%s\r\n", irc->host, irc->nick, irc->realname );
diff --git a/irc.c b/irc.c
index 45a1940d..c045d12b 100644
--- a/irc.c
+++ b/irc.c
@@ -176,7 +176,7 @@ void irc_abort( irc_t *irc, int immed, char *format, ... )
irc->nick ? irc->nick : "(NONE)", irc->host, "No reason given" );
}
- irc->status = USTATUS_SHUTDOWN;
+ irc->status |= USTATUS_SHUTDOWN;
if( irc->sendbuffer && !immed )
{
/* We won't read from this socket anymore. Instead, we'll connect a timer
@@ -210,7 +210,7 @@ void irc_free(irc_t * irc)
log_message( LOGLVL_INFO, "Destroying connection with fd %d", irc->fd );
- if( irc->status >= USTATUS_IDENTIFIED && set_getint( irc, "save_on_quit" ) )
+ if( irc->status & USTATUS_IDENTIFIED && set_getint( irc, "save_on_quit" ) )
if( storage_save( irc, TRUE ) != STORAGE_OK )
irc_usermsg( irc, "Error while saving settings!" );
@@ -576,7 +576,7 @@ void irc_vawrite( irc_t *irc, char *format, va_list params )
char line[IRC_MAX_LINE+1], *cs;
/* Don't try to write anything new anymore when shutting down. */
- if( irc->status == USTATUS_SHUTDOWN )
+ if( irc->status & USTATUS_SHUTDOWN )
return;
line[IRC_MAX_LINE] = 0;
@@ -706,7 +706,7 @@ int irc_check_login( irc_t *irc )
{
if( irc->user && irc->nick )
{
- if( global.conf->authmode == AUTHMODE_CLOSED && irc->status < USTATUS_AUTHORIZED )
+ if( global.conf->authmode == AUTHMODE_CLOSED && !( irc->status & USTATUS_AUTHORIZED ) )
{
irc_reply( irc, 464, ":This server is password-protected." );
return 0;
@@ -763,7 +763,7 @@ void irc_login( irc_t *irc )
if( global.conf->runmode == RUNMODE_FORKDAEMON || global.conf->runmode == RUNMODE_DAEMON )
ipc_to_master_str( "CLIENT %s %s :%s\r\n", irc->host, irc->nick, irc->realname );
- irc->status = USTATUS_LOGGED_IN;
+ irc->status |= USTATUS_LOGGED_IN;
}
void irc_motd( irc_t *irc )
@@ -1186,7 +1186,7 @@ static gboolean irc_userping( gpointer _irc, gint fd, b_input_condition cond )
irc_t *irc = _irc;
int rv = 0;
- if( irc->status < USTATUS_LOGGED_IN )
+ if( !( irc->status & USTATUS_LOGGED_IN ) )
{
if( gettime() > ( irc->last_pong + IRC_LOGIN_TIMEOUT ) )
rv = gettime() - irc->last_pong;
diff --git a/irc.h b/irc.h
index e702a864..ad52f42f 100644
--- a/irc.h
+++ b/irc.h
@@ -41,10 +41,10 @@
typedef enum
{
USTATUS_OFFLINE = 0,
- USTATUS_AUTHORIZED,
- USTATUS_LOGGED_IN,
- USTATUS_IDENTIFIED,
- USTATUS_SHUTDOWN = -1
+ USTATUS_AUTHORIZED = 1,
+ USTATUS_LOGGED_IN = 2,
+ USTATUS_IDENTIFIED = 4,
+ USTATUS_SHUTDOWN = 8
} irc_status_t;
typedef struct channel
diff --git a/irc_commands.c b/irc_commands.c
index dc59f7ee..f410bb52 100644
--- a/irc_commands.c
+++ b/irc_commands.c
@@ -31,7 +31,7 @@ static void irc_cmd_pass( irc_t *irc, char **cmd )
{
if( global.conf->auth_pass && strcmp( cmd[1], global.conf->auth_pass ) == 0 )
{
- irc->status = USTATUS_AUTHORIZED;
+ irc->status |= USTATUS_AUTHORIZED;
irc_check_login( irc );
}
else
@@ -609,11 +609,11 @@ void irc_exec( irc_t *irc, char *cmd[] )
/* There should be no typo in the next line: */
for( n_arg = 0; cmd[n_arg]; n_arg ++ ); n_arg --;
- if( irc_commands[i].flags & IRC_CMD_PRE_LOGIN && irc->status >= USTATUS_LOGGED_IN )
+ if( irc_commands[i].flags & IRC_CMD_PRE_LOGIN && irc->status & USTATUS_LOGGED_IN )
{
irc_reply( irc, 462, ":Only allowed before logging in" );
}
- else if( irc_commands[i].flags & IRC_CMD_LOGGED_IN && irc->status < USTATUS_LOGGED_IN )
+ else if( irc_commands[i].flags & IRC_CMD_LOGGED_IN && !( irc->status & USTATUS_LOGGED_IN ) )
{
irc_reply( irc, 451, ":Register first" );
}
diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c
index 3c7064f8..bac9c427 100644
--- a/protocols/msn/msn.c
+++ b/protocols/msn/msn.c
@@ -63,33 +63,38 @@ static void msn_close( struct gaim_connection *gc )
struct msn_data *md = gc->proto_data;
GSList *l;
- if( md->fd >= 0 )
- closesocket( md->fd );
-
- if( md->handler )
- {
- if( md->handler->rxq ) g_free( md->handler->rxq );
- if( md->handler->cmd_text ) g_free( md->handler->cmd_text );
- g_free( md->handler );
- }
-
- while( md->switchboards )
- msn_sb_destroy( md->switchboards->data );
-
- if( md->msgq )
+ if( md )
{
- struct msn_message *m;
+ if( md->fd >= 0 )
+ closesocket( md->fd );
- for( l = md->msgq; l; l = l->next )
+ if( md->handler )
{
- m = l->data;
+ if( md->handler->rxq ) g_free( md->handler->rxq );
+ if( md->handler->cmd_text ) g_free( md->handler->cmd_text );
+ g_free( md->handler );
+ }
- serv_got_crap( gc, "Warning: Closing down MSN connection with unsent message to %s, you'll have to resend it.", m->who );
- g_free( m->who );
- g_free( m->text );
- g_free( m );
+ while( md->switchboards )
+ msn_sb_destroy( md->switchboards->data );
+
+ if( md->msgq )
+ {
+ struct msn_message *m;
+
+ for( l = md->msgq; l; l = l->next )
+ {
+ m = l->data;
+
+ serv_got_crap( gc, "Warning: Closing down MSN connection with unsent message to %s, you'll have to resend it.", m->who );
+ g_free( m->who );
+ g_free( m->text );
+ g_free( m );
+ }
+ g_slist_free( md->msgq );
}
- g_slist_free( md->msgq );
+
+ g_free( md );
}
for( l = gc->permit; l; l = l->next )
@@ -100,8 +105,6 @@ static void msn_close( struct gaim_connection *gc )
g_free( l->data );
g_slist_free( gc->deny );
- g_free( md );
-
msn_connections = g_slist_remove( msn_connections, gc );
}
diff --git a/root_commands.c b/root_commands.c
index d44a36b7..225912b7 100644
--- a/root_commands.c
+++ b/root_commands.c
@@ -163,7 +163,7 @@ static void cmd_register( irc_t *irc, char **cmd )
break;
case STORAGE_OK:
- irc->status = USTATUS_IDENTIFIED;
+ irc->status |= USTATUS_IDENTIFIED;
irc_umode_set( irc, "+R", 1 );
break;
@@ -187,7 +187,7 @@ static void cmd_drop( irc_t *irc, char **cmd )
break;
case STORAGE_OK:
irc_setpass( irc, NULL );
- irc->status = USTATUS_LOGGED_IN;
+ irc->status &= ~USTATUS_IDENTIFIED;
irc_umode_set( irc, "-R", 1 );
irc_usermsg( irc, "Account `%s' removed", irc->nick );
break;
@@ -201,7 +201,7 @@ static void cmd_account( irc_t *irc, char **cmd )
{
account_t *a;
- if( global.conf->authmode == AUTHMODE_REGISTERED && irc->status < USTATUS_IDENTIFIED )
+ if( global.conf->authmode == AUTHMODE_REGISTERED && !( irc->status & USTATUS_IDENTIFIED ) )
{
irc_usermsg( irc, "This server only accepts registered users" );
return;
diff --git a/storage_text.c b/storage_text.c
index f807cb3e..506c9f03 100644
--- a/storage_text.c
+++ b/storage_text.c
@@ -70,7 +70,7 @@ static storage_status_t text_load ( const char *my_nick, const char* password, i
FILE *fp;
user_t *ru = user_find( irc, ROOT_NICK );
- if( irc->status >= USTATUS_IDENTIFIED )
+ if( irc->status & USTATUS_IDENTIFIED )
return( 1 );
g_snprintf( s, 511, "%s%s%s", global.conf->configdir, my_nick, ".accounts" );
@@ -87,7 +87,7 @@ static storage_status_t text_load ( const char *my_nick, const char* password, i
/* Do this now. If the user runs with AuthMode = Registered, the
account command will not work otherwise. */
- irc->status = USTATUS_IDENTIFIED;
+ irc->status |= USTATUS_IDENTIFIED;
while( fscanf( fp, "%511[^\n]s", s ) > 0 )
{
diff --git a/storage_xml.c b/storage_xml.c
index 29c01e07..5eda46cc 100644
--- a/storage_xml.c
+++ b/storage_xml.c
@@ -168,6 +168,18 @@ static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_na
static void xml_end_element( GMarkupParseContext *ctx, const gchar *element_name, gpointer data, GError **error )
{
+ struct xml_parsedata *xd = data;
+ // irc_t *irc = xd->irc;
+
+ if( g_strcasecmp( element_name, "setting" ) == 0 && xd->current_setting )
+ {
+ g_free( xd->current_setting );
+ xd->current_setting = NULL;
+ }
+ else if( g_strcasecmp( element_name, "account" ) == 0 )
+ {
+ xd->current_account = NULL;
+ }
}
static void xml_text( GMarkupParseContext *ctx, const gchar *text, gsize text_len, gpointer data, GError **error )
@@ -189,17 +201,13 @@ static void xml_text( GMarkupParseContext *ctx, const gchar *text, gsize text_le
}
}
-static void xml_error( GMarkupParseContext *ctx, GError *error, gpointer data )
-{
-}
-
GMarkupParser xml_parser =
{
xml_start_element,
xml_end_element,
xml_text,
NULL,
- xml_error
+ NULL
};
static void xml_init( void )
@@ -218,7 +226,7 @@ static storage_status_t xml_load( const char *my_nick, const char *password, irc
GError *gerr = NULL;
int fd, st;
- if( irc->status >= USTATUS_IDENTIFIED )
+ if( irc->status & USTATUS_IDENTIFIED )
return( 1 );
xd = g_new0( struct xml_parsedata, 1 );
@@ -243,19 +251,25 @@ static storage_status_t xml_load( const char *my_nick, const char *password, irc
if( !g_markup_parse_context_parse( ctx, buf, st, &gerr ) || gerr )
{
g_markup_parse_context_free( ctx );
+ close( fd );
- /* TODO: Display useful error msg */
-
+ /* Slightly dirty... */
if( gerr && strcmp( gerr->message, XML_PASS_ERRORMSG ) == 0 )
return STORAGE_INVALID_PASSWORD;
else
+ {
+ if( gerr )
+ irc_usermsg( irc, "Error from XML-parser: %s", gerr->message );
+
return STORAGE_OTHER_ERROR;
+ }
}
}
g_markup_parse_context_free( ctx );
+ close( fd );
- irc->status = USTATUS_IDENTIFIED;
+ irc->status |= USTATUS_IDENTIFIED;
if( set_getint( irc, "auto_connect" ) )
{
@@ -267,19 +281,94 @@ static storage_status_t xml_load( const char *my_nick, const char *password, irc
return STORAGE_OK;
}
+static int xml_printf( int fd, char *fmt, ... )
+{
+ va_list params;
+ char *out;
+ int len;
+
+ va_start( params, fmt );
+ out = g_markup_vprintf_escaped( fmt, params );
+ va_end( params );
+
+ len = strlen( out );
+ len -= write( fd, out, len );
+ g_free( out );
+
+ return len == 0;
+}
+
static storage_status_t xml_save( irc_t *irc, int overwrite )
{
-/* if (!overwrite) {
- g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" );
- if (access( path, F_OK ) != -1)
- return STORAGE_ALREADY_EXISTS;
+ char path[512], *path2;
+ set_t *set;
+ nick_t *nick;
+ account_t *acc;
+ int fd;
- g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".nicks" );
- if (access( path, F_OK ) != -1)
- return STORAGE_ALREADY_EXISTS;
+ g_snprintf( path, sizeof( path ) - 2, "%s%s%s", global.conf->configdir, irc->nick, ".xml" );
+
+ if( !overwrite && access( path, F_OK ) != -1 )
+ return STORAGE_ALREADY_EXISTS;
+
+ strcat( path, "~" );
+ if( ( fd = open( path, O_WRONLY | O_CREAT, 0600 ) ) < 0 )
+ {
+ irc_usermsg( irc, "Error while opening configuration file." );
+ return STORAGE_OTHER_ERROR;
}
-*/
+
+ if( !xml_printf( fd, "<user nick=\"%s\" password=\"%s\">\n", irc->nick, irc->password ) )
+ goto write_error;
+
+ for( set = irc->set; set; set = set->next )
+ if( set->value && set->def )
+ if( !xml_printf( fd, "\t<setting name=\"%s\">%s</setting>\n", set->key, set->value ) )
+ goto write_error;
+
+ for( acc = irc->accounts; acc; acc = acc->next )
+ {
+ if( !xml_printf( fd, "\t<account protocol=\"%s\" handle=\"%s\" password=\"%s\" autoconnect=\"%s\"", acc->prpl->name, acc->user, acc->pass, "yes" ) )
+ goto write_error;
+ if( acc->server && acc->server[0] && !xml_printf( fd, " server=\"%s\"", acc->server ) )
+ goto write_error;
+ if( !xml_printf( fd, ">\n" ) )
+ goto write_error;
+
+ for( nick = irc->nicks; nick; nick = nick->next )
+ if( nick->proto == acc->prpl )
+ if( !xml_printf( fd, "\t\t<buddy handle=\"%s\" nick=\"%s\" />\n", nick->handle, nick->nick ) )
+ goto write_error;
+
+ if( !xml_printf( fd, "\t</account>\n" ) )
+ goto write_error;
+ }
+
+ if( !xml_printf( fd, "</user>\n" ) )
+ goto write_error;
+
+ close( fd );
+
+ path2 = g_strndup( path, strlen( path ) - 1 );
+ if( rename( path, path2 ) != 0 )
+ {
+ irc_usermsg( irc, "Error while renaming temporary configuration file." );
+
+ g_free( path2 );
+ unlink( path );
+
+ return STORAGE_OTHER_ERROR;
+ }
+
+ g_free( path2 );
+
return STORAGE_OK;
+
+write_error:
+ irc_usermsg( irc, "Write error. Disk full?" );
+ close( fd );
+
+ return STORAGE_OTHER_ERROR;
}
storage_t storage_xml = {