aboutsummaryrefslogtreecommitdiffstats
path: root/storage.c
diff options
context:
space:
mode:
Diffstat (limited to 'storage.c')
-rw-r--r--storage.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/storage.c b/storage.c
index f011ade2..2788ba2a 100644
--- a/storage.c
+++ b/storage.c
@@ -28,6 +28,7 @@
#define BITLBEE_CORE
#include "bitlbee.h"
#include "crypting.h"
+#include "otr.h"
extern storage_t storage_text;
extern storage_t storage_xml;
@@ -115,9 +116,10 @@ storage_status_t storage_load (irc_t * irc, const char *password)
storage_status_t status;
status = st->load(irc, password);
- if (status == STORAGE_OK)
+ if (status == STORAGE_OK) {
+ otr_load(irc);
return status;
-
+ }
if (status != STORAGE_NO_SUCH_USER)
return status;
}
@@ -138,7 +140,8 @@ storage_status_t storage_save (irc_t *irc, char *password, int overwrite)
} else if ((irc->status & USTATUS_IDENTIFIED) == 0) {
return STORAGE_NO_SUCH_USER;
}
-
+
+ otr_save(irc);
st = ((storage_t *)global.storage->data)->save(irc, overwrite);
if (password != NULL) {
@@ -164,6 +167,9 @@ storage_status_t storage_remove (const char *nick, const char *password)
if (status != STORAGE_NO_SUCH_USER && status != STORAGE_OK)
ret = status;
}
+ if (ret == STORAGE_OK) {
+ otr_remove(nick);
+ }
return ret;
}
@@ -177,12 +183,14 @@ storage_status_t storage_rename (const char *onick, const char *nnick, const cha
GList *gl = global.storage;
storage_t *primary_storage = gl->data;
irc_t *irc;
-
+
/* First, try to rename in the current write backend, assuming onick
* is stored there */
status = primary_storage->rename(onick, nnick, password);
- if (status != STORAGE_NO_SUCH_USER)
+ if (status != STORAGE_NO_SUCH_USER) {
+ otr_rename(onick, nnick);
return status;
+ }
/* Try to load from a migration backend and save to the current backend.
* Explicitly remove the account from the migration backend as otherwise
@@ -206,6 +214,7 @@ storage_status_t storage_rename (const char *onick, const char *nnick, const cha
irc_free(irc);
storage_remove(onick, password);
+ otr_rename(onick, nnick);
return STORAGE_OK;
}
ht .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
  /********************************************************************\
  * BitlBee -- An IRC to other IM-networks gateway                     *
  *                                                                    *
  * Copyright 2002-2010 Wilmer van der Gaast and others                *
  \********************************************************************/

/* Some stuff that doesn't belong anywhere else.                        */

/*
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License with
  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
  if not, write to the Free Software Foundation, Inc., 59 Temple Place,
  Suite 330, Boston, MA  02111-1307  USA
*/

#include "bitlbee.h"

char *set_eval_timezone( set_t *set, char *value )
{
	char *s;
	
	if( strcmp( value, "local" ) == 0 ||
	    strcmp( value, "gmt" ) == 0 || strcmp( value, "utc" ) == 0 )
		return value;
	
	/* Otherwise: +/- at the beginning optional, then one or more numbers,
	   possibly followed by a colon and more numbers. Don't bother bound-
	   checking them since users are free to shoot themselves in the foot. */
	s = value;
	if( *s == '+' || *s == '-' )
		s ++;
	
	/* \d+ */
	if( !isdigit( *s ) )
		return SET_INVALID;
	while( *s && isdigit( *s ) ) s ++;
	
	/* EOS? */
	if( *s == '\0' )
		return value;
	
	/* Otherwise, colon */
	if( *s != ':' )
		return SET_INVALID;
	s ++;
	
	/* \d+ */
	if( !isdigit( *s ) )
		return SET_INVALID;
	while( *s && isdigit( *s ) ) s ++;
	
	/* EOS */
	return *s == '\0' ? value : SET_INVALID;
}

char *irc_format_timestamp( irc_t *irc, time_t msg_ts )
{
	time_t now_ts = time( NULL );
	struct tm now, msg;
	char *set;
	
	/* If the timestamp is <= 0 or less than a minute ago, discard it as
	   it doesn't seem to add to much useful info and/or might be noise. */
	if( msg_ts <= 0 || msg_ts > now_ts - 60 )
		return NULL;
	
	set = set_getstr( &irc->b->set, "timezone" );
	if( strcmp( set, "local" ) == 0 )
	{
		localtime_r( &now_ts, &now );
		localtime_r( &msg_ts, &msg );
	}
	else
	{
		int hr, min = 0, sign = 60;
		
		if( set[0] == '-' )
		{
			sign *= -1;
			set ++;
		}
		else if( set[0] == '+' )
		{
			set ++;
		}
		
		if( sscanf( set, "%d:%d", &hr, &min ) >= 1 )
		{
			msg_ts += sign * ( hr * 60 + min );
			now_ts += sign * ( hr * 60 + min );
		}
		
		gmtime_r( &now_ts, &now );
		gmtime_r( &msg_ts, &msg );
	}
	
	if( msg.tm_year == now.tm_year && msg.tm_yday == now.tm_yday )
		return g_strdup_printf( "\x02[\x02\x02\x02%02d:%02d:%02d\x02]\x02 ",
		                        msg.tm_hour, msg.tm_min, msg.tm_sec );
	else
		return g_strdup_printf( "\x02[\x02\x02\x02%04d-%02d-%02d "
		                        "%02d:%02d:%02d\x02]\x02 ",
		                        msg.tm_year + 1900, msg.tm_mon, msg.tm_mday,
		                        msg.tm_hour, msg.tm_min, msg.tm_sec );
}