aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2010-09-01 23:35:06 +0100
committerWilmer van der Gaast <wilmer@gaast.net>2010-09-01 23:35:06 +0100
commit2dcaf9a0fabdb92a191e64759d116f316de7dfc2 (patch)
tree1de0cc9ef4fe5ca5afb4c9e951ab1b193f0390f1
parent934db064a58ebec2edea83df4fa07e2c83220344 (diff)
Load/save code. It'd be better if the OTR module would just save its info
in BitlBee settings that automatically end up in the existing .xml files (or whatever storage is used), but I realise this is non-trivial.
-rw-r--r--irc.h7
-rw-r--r--otr.c4
-rw-r--r--storage.c29
3 files changed, 40 insertions, 0 deletions
diff --git a/irc.h b/irc.h
index 0c8d2981..e8def513 100644
--- a/irc.h
+++ b/irc.h
@@ -239,6 +239,13 @@ typedef struct irc_plugin
/* Called by bee_irc_user_msg(). Return NULL if you swallowed the
message and don't want anything to go to the user. */
char* (*filter_msg_in)( irc_user_t *iu, char *msg, int flags );
+
+ /* From storage.c functions. Ideally these should not be used
+ and instead data should be stored in settings which will get
+ saved automatically. Consider these deprecated! */
+ void (*storage_load)( irc_t *irc );
+ void (*storage_save)( irc_t *irc );
+ void (*storage_remove)( const char *nick );
} irc_plugin_t;
extern GSList *irc_plugins; /* struct irc_plugin */
diff --git a/otr.c b/otr.c
index 11abab63..ad59d5b0 100644
--- a/otr.c
+++ b/otr.c
@@ -447,6 +447,9 @@ static const struct irc_plugin otr_plugin =
otr_irc_free,
otr_filter_msg_out,
otr_filter_msg_in,
+ otr_load,
+ otr_save,
+ otr_remove,
};
static void cmd_otr(irc_t *irc, char **args)
@@ -1662,6 +1665,7 @@ gboolean keygen_finish_handler(gpointer data, gint fd, b_input_condition cond)
/* okay, the slave is idle now, so kill him */
fclose(irc->otr->from);
fclose(irc->otr->to);
+ irc->otr->from = irc->otr->to = NULL;
kill(irc->otr->keygen, SIGTERM);
waitpid(irc->otr->keygen, NULL, 0);
irc->otr->keygen = 0;
diff --git a/storage.c b/storage.c
index ad1833fc..d64d9cda 100644
--- a/storage.c
+++ b/storage.c
@@ -114,7 +114,16 @@ storage_status_t storage_load (irc_t * irc, const char *password)
status = st->load(irc, password);
if (status == STORAGE_OK)
+ {
+ GSList *l;
+ for( l = irc_plugins; l; l = l->next )
+ {
+ irc_plugin_t *p = l->data;
+ if( p->storage_load )
+ p->storage_load( irc );
+ }
return status;
+ }
if (status != STORAGE_NO_SUCH_USER)
return status;
@@ -126,6 +135,7 @@ storage_status_t storage_load (irc_t * irc, const char *password)
storage_status_t storage_save (irc_t *irc, char *password, int overwrite)
{
storage_status_t st;
+ GSList *l;
if (password != NULL) {
/* Should only use this in the "register" command. */
@@ -139,6 +149,13 @@ storage_status_t storage_save (irc_t *irc, char *password, int overwrite)
st = ((storage_t *)global.storage->data)->save(irc, overwrite);
+ for( l = irc_plugins; l; l = l->next )
+ {
+ irc_plugin_t *p = l->data;
+ if( p->storage_save )
+ p->storage_save( irc );
+ }
+
if (password != NULL) {
irc_setpass(irc, NULL);
}
@@ -150,6 +167,8 @@ storage_status_t storage_remove (const char *nick, const char *password)
{
GList *gl;
storage_status_t ret = STORAGE_OK;
+ gboolean ok = FALSE;
+ GSList *l;
/* Remove this account from all storage backends. If this isn't
* done, the account will still be usable, it'd just be
@@ -159,10 +178,20 @@ storage_status_t storage_remove (const char *nick, const char *password)
storage_status_t status;
status = st->remove(nick, password);
+ ok |= status == STORAGE_OK;
if (status != STORAGE_NO_SUCH_USER && status != STORAGE_OK)
ret = status;
}
+ /* If at least one succeeded, remove plugin data. */
+ if( ok )
+ for( l = irc_plugins; l; l = l->next )
+ {
+ irc_plugin_t *p = l->data;
+ if( p->storage_remove )
+ p->storage_remove( nick );
+ }
+
return ret;
}