aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2010-04-10 03:27:50 +0100
committerWilmer van der Gaast <wilmer@gaast.net>2010-04-10 03:27:50 +0100
commit1f92a5851e0e3b1730e940980f2b0122c506c724 (patch)
tree0a2f099cb0c24c36eb56fb9f79c5a8dd640abac2
parent57c96f7be2511a0a50015512dc03a30ba0923862 (diff)
Restore the storage module.
-rw-r--r--Makefile2
-rw-r--r--irc.c13
-rw-r--r--irc.h1
-rw-r--r--root_commands.c66
-rw-r--r--storage_xml.c18
-rw-r--r--unix.c2
6 files changed, 40 insertions, 62 deletions
diff --git a/Makefile b/Makefile
index 5e91b93b..1ea3deec 100644
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@
# Program variables
#objects = bitlbee.o chat.o dcc.o help.o ipc.o irc.o irc_commands.o nick.o query.o root_commands.o set.o storage.o $(STORAGE_OBJS)
-objects = bitlbee.o help.o ipc.o irc.o irc_im.o irc_channel.o irc_commands.o irc_send.o irc_user.o nick.o root_commands.o set.o
+objects = bitlbee.o help.o ipc.o irc.o irc_im.o irc_channel.o irc_commands.o irc_send.o irc_user.o nick.o root_commands.o set.o storage.o $(STORAGE_OBJS)
headers = account.h bitlbee.h commands.h conf.h config.h help.h ipc.h irc.h log.h nick.h query.h set.h sock.h storage.h user.h lib/events.h lib/ftutil.h lib/http_client.h lib/ini.h lib/md5.h lib/misc.h lib/proxy.h lib/sha1.h lib/ssl_client.h lib/url.h protocols/ft.h protocols/nogaim.h
subdirs = lib protocols
diff --git a/irc.c b/irc.c
index 5173dd9b..4824d0ac 100644
--- a/irc.c
+++ b/irc.c
@@ -260,6 +260,19 @@ static gboolean irc_free_hashkey( gpointer key, gpointer value, gpointer data )
return( TRUE );
}
+/* USE WITH CAUTION!
+ Sets pass without checking */
+void irc_setpass (irc_t *irc, const char *pass)
+{
+ g_free (irc->password);
+
+ if (pass) {
+ irc->password = g_strdup (pass);
+ } else {
+ irc->password = NULL;
+ }
+}
+
static char **irc_splitlines( char *buffer );
void irc_process( irc_t *irc )
diff --git a/irc.h b/irc.h
index d9cc422a..8a40541c 100644
--- a/irc.h
+++ b/irc.h
@@ -159,6 +159,7 @@ extern GSList *irc_connection_list;
irc_t *irc_new( int fd );
void irc_abort( irc_t *irc, int immed, char *format, ... ) G_GNUC_PRINTF( 3, 4 );
void irc_free( irc_t *irc );
+void irc_setpass (irc_t *irc, const char *pass);
void irc_process( irc_t *irc );
char **irc_parse_line( char *line );
diff --git a/root_commands.c b/root_commands.c
index 7e0b16d3..73670d3a 100644
--- a/root_commands.c
+++ b/root_commands.c
@@ -135,7 +135,6 @@ static void cmd_help( irc_t *irc, char **cmd )
}
}
-#if 0
static void cmd_account( irc_t *irc, char **cmd );
static void cmd_identify( irc_t *irc, char **cmd )
@@ -161,7 +160,7 @@ static void cmd_identify( irc_t *irc, char **cmd )
irc_setpass( irc, cmd[1] );
irc->status |= USTATUS_IDENTIFIED;
irc_umode_set( irc, "+R", 1 );
- if( set_getbool( &irc->set, "auto_connect" ) )
+ if( set_getbool( &irc->b->set, "auto_connect" ) )
cmd_account( irc, account_on );
break;
case STORAGE_OTHER_ERROR:
@@ -201,7 +200,7 @@ static void cmd_drop( irc_t *irc, char **cmd )
{
storage_status_t status;
- status = storage_remove (irc->nick, cmd[1]);
+ status = storage_remove (irc->user->nick, cmd[1]);
switch (status) {
case STORAGE_NO_SUCH_USER:
irc_usermsg( irc, "That account does not exist" );
@@ -213,14 +212,23 @@ static void cmd_drop( irc_t *irc, char **cmd )
irc_setpass( irc, NULL );
irc->status &= ~USTATUS_IDENTIFIED;
irc_umode_set( irc, "-R", 1 );
- irc_usermsg( irc, "Account `%s' removed", irc->nick );
+ irc_usermsg( irc, "Account `%s' removed", irc->user->nick );
break;
default:
irc_usermsg( irc, "Error: `%d'", status );
break;
}
}
-#endif
+
+static void cmd_save( irc_t *irc, char **cmd )
+{
+ if( ( irc->status & USTATUS_IDENTIFIED ) == 0 )
+ irc_usermsg( irc, "Please create an account first" );
+ else if( storage_save( irc, NULL, TRUE ) == STORAGE_OK )
+ irc_usermsg( irc, "Configuration saved" );
+ else
+ irc_usermsg( irc, "Configuration could not be saved!" );
+}
struct cmd_account_del_data
{
@@ -908,16 +916,6 @@ static void cmd_set( irc_t *irc, char **cmd )
cmd_set_real( irc, cmd, NULL, NULL );
}
-static void cmd_save( irc_t *irc, char **cmd )
-{
- if( ( irc->status & USTATUS_IDENTIFIED ) == 0 )
- irc_usermsg( irc, "Please create an account first" );
- else if( storage_save( irc, NULL, TRUE ) == STORAGE_OK )
- irc_usermsg( irc, "Configuration saved" );
- else
- irc_usermsg( irc, "Configuration could not be saved!" );
-}
-
static void cmd_blist( irc_t *irc, char **cmd )
{
int online = 0, away = 0, offline = 0;
@@ -983,34 +981,6 @@ static void cmd_blist( irc_t *irc, char **cmd )
irc_usermsg( irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline );
}
-static void cmd_nick( irc_t *irc, char **cmd )
-{
- account_t *a;
-
- if( !cmd[1] || !( a = account_get( irc, cmd[1] ) ) )
- {
- irc_usermsg( irc, "Invalid account");
- }
- else if( !( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) )
- {
- irc_usermsg( irc, "That account is not on-line" );
- }
- else if ( !cmd[2] )
- {
- irc_usermsg( irc, "Your name is `%s'" , a->ic->displayname ? a->ic->displayname : "NULL" );
- }
- else if ( !a->prpl->set_my_name )
- {
- irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] );
- }
- else
- {
- irc_usermsg( irc, "Setting your name to `%s'", cmd[2] );
-
- a->prpl->set_my_name( a->ic, cmd[2] );
- }
-}
-
static void cmd_qlist( irc_t *irc, char **cmd )
{
query_t *q = irc->queries;
@@ -1031,12 +1001,6 @@ static void cmd_qlist( irc_t *irc, char **cmd )
irc_usermsg( irc, "%d, BitlBee: %s", num, q->question );
}
-static void cmd_join_chat( irc_t *irc, char **cmd )
-{
- irc_usermsg( irc, "This command is now obsolete. "
- "Please try the `chat' command instead." );
-}
-
static set_t **cmd_chat_set_findhead( irc_t *irc, char *id )
{
struct chat *c;
@@ -1215,10 +1179,11 @@ static void cmd_transfer( irc_t *irc, char **cmd )
const command_t commands[] = {
{ "help", 0, cmd_help, 0 },
{ "account", 1, cmd_account, 0 },
-#if 0
{ "identify", 1, cmd_identify, 0 },
{ "register", 1, cmd_register, 0 },
{ "drop", 1, cmd_drop, 0 },
+ { "save", 0, cmd_save, 0 },
+#if 0
{ "add", 2, cmd_add, 0 },
{ "info", 1, cmd_info, 0 },
#endif
@@ -1227,7 +1192,6 @@ const command_t commands[] = {
{ "remove", 1, cmd_remove, 0 },
{ "block", 1, cmd_block, 0 },
{ "allow", 1, cmd_allow, 0 },
- { "save", 0, cmd_save, 0 },
{ "set", 0, cmd_set, 0 },
{ "yes", 0, cmd_yesno, 0 },
{ "no", 0, cmd_yesno, 0 },
diff --git a/storage_xml.c b/storage_xml.c
index b6745c75..b81e1d0c 100644
--- a/storage_xml.c
+++ b/storage_xml.c
@@ -146,7 +146,7 @@ static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_na
else if( ( pass_len = base64_decode( pass_b64, (unsigned char**) &pass_cr ) ) &&
arc_decode( pass_cr, pass_len, &password, xd->given_pass ) )
{
- xd->current_account = account_add( irc, prpl, handle, password );
+ xd->current_account = account_add( irc->b, prpl, handle, password );
if( server )
set_setstr( &xd->current_account->set, "server", server );
if( autoconnect )
@@ -180,7 +180,7 @@ static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_na
else if( xd->current_account != NULL )
xd->current_set_head = &xd->current_account->set;
else
- xd->current_set_head = &xd->irc->set;
+ xd->current_set_head = &xd->irc->b->set;
xd->current_setting = g_strdup( setting );
}
@@ -214,7 +214,7 @@ static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_na
if( xd->current_account && handle && channel )
{
- xd->current_chat = chat_add( xd->irc, xd->current_account, handle, channel );
+ //xd->current_chat = chat_add( xd->irc, xd->current_account, handle, channel );
}
else
{
@@ -352,7 +352,7 @@ static storage_status_t xml_load_real( irc_t *irc, const char *my_nick, const ch
static storage_status_t xml_load( irc_t *irc, const char *password )
{
- return xml_load_real( irc, irc->nick, password, XML_PASS_UNKNOWN );
+ return xml_load_real( irc, irc->user->nick, password, XML_PASS_UNKNOWN );
}
static storage_status_t xml_check_pass( const char *my_nick, const char *password )
@@ -395,7 +395,7 @@ static storage_status_t xml_save( irc_t *irc, int overwrite )
md5_byte_t pass_md5[21];
md5_state_t md5_state;
- path2 = g_strdup( irc->nick );
+ path2 = g_strdup( irc->user->nick );
nick_lc( path2 );
g_snprintf( path, sizeof( path ) - 2, "%s%s%s", global.conf->configdir, path2, ".xml" );
g_free( path2 );
@@ -421,17 +421,17 @@ static storage_status_t xml_save( irc_t *irc, int overwrite )
/* Save the hash in base64-encoded form. */
pass_buf = base64_encode( pass_md5, 21 );
- if( !xml_printf( fd, 0, "<user nick=\"%s\" password=\"%s\" version=\"%d\">\n", irc->nick, pass_buf, XML_FORMAT_VERSION ) )
+ if( !xml_printf( fd, 0, "<user nick=\"%s\" password=\"%s\" version=\"%d\">\n", irc->user->nick, pass_buf, XML_FORMAT_VERSION ) )
goto write_error;
g_free( pass_buf );
- for( set = irc->set; set; set = set->next )
+ for( set = irc->b->set; set; set = set->next )
if( set->value )
if( !xml_printf( fd, 1, "<setting name=\"%s\">%s</setting>\n", set->key, set->value ) )
goto write_error;
- for( acc = irc->accounts; acc; acc = acc->next )
+ for( acc = irc->b->accounts; acc; acc = acc->next )
{
unsigned char *pass_cr;
char *pass_b64;
@@ -469,6 +469,7 @@ static storage_status_t xml_save( irc_t *irc, int overwrite )
if( g_hash_table_find( acc->nicks, xml_save_nick, & fd ) )
goto write_error;
+#if 0
for( c = irc->chatrooms; c; c = c->next )
{
if( c->acc != acc )
@@ -487,6 +488,7 @@ static storage_status_t xml_save( irc_t *irc, int overwrite )
if( !xml_printf( fd, 2, "</chat>\n" ) )
goto write_error;
}
+#endif
if( !xml_printf( fd, 1, "</account>\n" ) )
goto write_error;
diff --git a/unix.c b/unix.c
index b916a4cc..7088d0f8 100644
--- a/unix.c
+++ b/unix.c
@@ -114,14 +114,12 @@ int main( int argc, char *argv[] )
}
}
- /*
global.storage = storage_init( global.conf->primary_storage, global.conf->migrate_storage );
if( global.storage == NULL )
{
log_message( LOGLVL_ERROR, "Unable to load storage backend '%s'", global.conf->primary_storage );
return( 1 );
}
- */
/* Catch some signals to tell the user what's happening before quitting */
memset( &sig, 0, sizeof( sig ) );