aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile22
-rw-r--r--bitlbee.c21
-rw-r--r--bitlbee.h2
-rw-r--r--conf.c41
-rw-r--r--conf.h7
-rwxr-xr-xconfigure22
-rw-r--r--irc.c33
-rw-r--r--irc.h39
-rw-r--r--irc_cap.c1
-rw-r--r--irc_channel.c103
-rw-r--r--irc_commands.c13
-rw-r--r--irc_im.c33
-rw-r--r--irc_send.c78
-rw-r--r--lib/ssl_client.h6
-rw-r--r--lib/ssl_gnutls.c73
-rw-r--r--protocols/account.c92
-rw-r--r--protocols/purple/purple.c22
-rw-r--r--protocols/twitter/twitter.c46
-rw-r--r--protocols/twitter/twitter.h10
-rw-r--r--protocols/twitter/twitter_lib.c71
-rw-r--r--protocols/twitter/twitter_lib.h4
-rw-r--r--root_commands.c27
22 files changed, 686 insertions, 80 deletions
diff --git a/Makefile b/Makefile
index 3d930f97..95706534 100644
--- a/Makefile
+++ b/Makefile
@@ -25,10 +25,14 @@ ifdef DOC
$(MAKE) -C doc
endif
-uninstall: uninstall-bin uninstall-doc
+ifdef DEVEL
+INSTALL_DEV = install-dev
+UNINSTALL_DEV = uninstall-dev
+endif
+uninstall: uninstall-bin uninstall-doc $(UNINSTALL_DEV)
@echo -e '\nmake uninstall does not remove files in '$(DESTDIR)$(ETCDIR)', you can use make uninstall-etc to do that.\n'
-install: install-bin install-doc install-plugins
+install: install-bin install-doc install-plugins install-etc $(INSTALL_DEV)
@echo
@echo Installed successfully
@echo
@@ -37,7 +41,9 @@ install: install-bin install-doc install-plugins
ifdef SYSTEMDSYSTEMUNITDIR
@echo If you want to start BitlBee using systemd, try \"make install-systemd\".
endif
+ifndef DEVEL
@echo To be able to compile third party plugins, run \"make install-dev\"
+endif
@echo
.PHONY: install install-bin install-etc install-doc install-plugins install-systemd install-dev \
@@ -111,12 +117,20 @@ uninstall-dev:
install-etc:
mkdir -p $(DESTDIR)$(ETCDIR)
- $(INSTALL) -m 0644 $(_SRCDIR_)motd.txt $(DESTDIR)$(ETCDIR)/motd.txt
- $(INSTALL) -m 0644 $(_SRCDIR_)bitlbee.conf $(DESTDIR)$(ETCDIR)/bitlbee.conf
+ $(INSTALL) -m 0644 $(_SRCDIR_)motd.txt $(DESTDIR)$(ETCDIR)/motd.txt.sample
+ $(INSTALL) -m 0644 $(_SRCDIR_)bitlbee.conf $(DESTDIR)$(ETCDIR)/bitlbee.conf.sample
+ @if ! [ -e $(DESTDIR)$(ETCDIR)/motd.txt ]; then \
+ $(INSTALL) -m 0644 $(_SRCDIR_)motd.txt $(DESTDIR)$(ETCDIR)/motd.txt; \
+ fi
+ @if ! [ -e $(DESTDIR)$(ETCDIR)/bitlbee.conf ]; then \
+ $(INSTALL) -m 0644 $(_SRCDIR_)bitlbee.conf $(DESTDIR)$(ETCDIR)/bitlbee.conf; \
+ fi
uninstall-etc:
rm -f $(DESTDIR)$(ETCDIR)/motd.txt
+ rm -f $(DESTDIR)$(ETCDIR)/motd.txt.sample
rm -f $(DESTDIR)$(ETCDIR)/bitlbee.conf
+ rm -f $(DESTDIR)$(ETCDIR)/bitlbee.conf.sample
-rmdir $(DESTDIR)$(ETCDIR)
install-plugins: install-plugin-otr install-plugin-skype
diff --git a/bitlbee.c b/bitlbee.c
index fa8c6795..c725ff0c 100644
--- a/bitlbee.c
+++ b/bitlbee.c
@@ -29,6 +29,7 @@
#include "protocols/nogaim.h"
#include "help.h"
#include "ipc.h"
+#include "lib/ssl_client.h"
#include <signal.h>
#include <stdio.h>
#include <errno.h>
@@ -169,6 +170,10 @@ int bitlbee_daemon_init()
log_link(LOGLVL_WARNING, LOGOUTPUT_SYSLOG);
}
+ if (global.conf->ssl) {
+ ssl_setup_server();
+ }
+
return(0);
}
@@ -187,7 +192,11 @@ gboolean bitlbee_io_current_client_read(gpointer data, gint fd, b_input_conditio
char line[513];
int st;
- st = read(irc->fd, line, sizeof(line) - 1);
+ if (global.conf->ssl) {
+ st = ssl_server_read(irc, line, sizeof(line) - 1);
+ } else {
+ st = read(irc->fd, line, sizeof(line) - 1);
+ }
if (st == 0) {
irc_abort(irc, 1, "Connection reset by peer");
return FALSE;
@@ -236,7 +245,11 @@ gboolean bitlbee_io_current_client_write(gpointer data, gint fd, b_input_conditi
}
size = strlen(irc->sendbuffer);
- st = write(irc->fd, irc->sendbuffer, size);
+ if (global.conf->ssl) {
+ st = ssl_server_write(irc, irc->sendbuffer, size);
+ } else {
+ st = write(irc->fd, irc->sendbuffer, size);
+ }
if (st == 0 || (st < 0 && !sockerr_again())) {
irc_abort(irc, 1, "Write error: %s", strerror(errno));
@@ -316,6 +329,10 @@ static gboolean bitlbee_io_new_client(gpointer data, gint fd, b_input_condition
/* Make the connection. */
irc = irc_new(new_socket);
+ if (global.conf->ssl) {
+ ssl_accept(irc);
+ }
+
/* We can store the IPC fd there now. */
global.listen_socket = fds[1];
global.listen_watch_source_id = b_input_add(fds[1], B_EV_IO_READ, ipc_child_read, irc);
diff --git a/bitlbee.h b/bitlbee.h
index 26a1c982..14ca68d2 100644
--- a/bitlbee.h
+++ b/bitlbee.h
@@ -35,7 +35,9 @@ extern "C" {
#endif
#define PACKAGE "BitlBee"
+#ifndef BITLBEE_VERSION
#define BITLBEE_VERSION "3.4.2"
+#endif
#define VERSION BITLBEE_VERSION
#define BITLBEE_VER(a, b, c) (((a) << 16) + ((b) << 8) + (c))
#define BITLBEE_VERSION_CODE BITLBEE_VER(3, 4, 2)
diff --git a/conf.c b/conf.c
index 8c2439e7..83495d15 100644
--- a/conf.c
+++ b/conf.c
@@ -70,6 +70,11 @@ conf_t *conf_load(int argc, char *argv[])
conf->ft_listen = NULL;
conf->protocols = NULL;
conf->cafile = NULL;
+#ifdef WITH_GNUTLS
+ conf->ssl = FALSE;
+ conf->ssl_cert = NULL;
+ conf->ssl_key = NULL;
+#endif /* WITH_GNUTLS */
proxytype = 0;
i = conf_loadini(conf, global.conf_file);
@@ -171,6 +176,23 @@ conf_t *conf_load(int argc, char *argv[])
return NULL;
}
+#ifdef WITH_GNUTLS
+ if (conf->ssl && (!conf->ssl_cert || !conf->ssl_key)) {
+ fprintf(stderr, "Error: SSL enabled but cert or key is missing\n");
+ return NULL;
+ }
+
+ if (conf->ssl && conf->ssl_cert && access(conf->ssl_cert, R_OK) != 0) {
+ fprintf(stderr, "Error: Could not read SSL Cert %s: %s\n", conf->ssl_cert, strerror(errno));
+ return NULL;
+ }
+
+ if (conf->ssl && conf->ssl_key && access(conf->ssl_key, R_OK) != 0) {
+ fprintf(stderr, "Error: Could not read SSL Key %s: %s\n", conf->ssl_key, strerror(errno));
+ return NULL;
+ }
+#endif /* WITH_GNUTLS */
+
return conf;
}
@@ -238,6 +260,8 @@ static int conf_loadini(conf_t *conf, char *file)
conf->authmode = AUTHMODE_REGISTERED;
} else if (g_strcasecmp(ini->value, "closed") == 0) {
conf->authmode = AUTHMODE_CLOSED;
+ } else if (g_strcasecmp(ini->value, "sasl") == 0) {
+ conf->authmode = AUTHMODE_SASL;
} else {
conf->authmode = AUTHMODE_OPEN;
}
@@ -343,6 +367,23 @@ static int conf_loadini(conf_t *conf, char *file)
} else if (g_strcasecmp(ini->key, "cafile") == 0) {
g_free(conf->cafile);
conf->cafile = g_strdup(ini->value);
+#ifdef WITH_GNUTLS
+ } else if (g_strcasecmp(ini->key, "ssl") == 0) {
+ if (g_strcasecmp(ini->value, "true") == 0) {
+ conf->ssl = TRUE;
+ } else if (g_strcasecmp(ini->value, "false") == 0) {
+ conf->ssl = FALSE;
+ } else {
+ fprintf(stderr, "Invalid %s value: %s\n", ini->key, ini->value);
+ return 0;
+ }
+ } else if (g_strcasecmp(ini->key, "ssl_cert") == 0) {
+ g_free(conf->ssl_cert);
+ conf->ssl_cert = g_strdup(ini->value);
+ } else if (g_strcasecmp(ini->key, "ssl_key") == 0) {
+ g_free(conf->ssl_key);
+ conf->ssl_key = g_strdup(ini->value);
+#endif /* WITH_GNUTLS */
} else {
fprintf(stderr, "Error: Unknown setting `%s` in configuration file (line %d).\n",
ini->key, ini->line);
diff --git a/conf.h b/conf.h
index cd600775..3305844a 100644
--- a/conf.h
+++ b/conf.h
@@ -27,7 +27,7 @@
#define __CONF_H
typedef enum runmode { RUNMODE_DAEMON, RUNMODE_FORKDAEMON, RUNMODE_INETD } runmode_t;
-typedef enum authmode { AUTHMODE_OPEN, AUTHMODE_CLOSED, AUTHMODE_REGISTERED } authmode_t;
+typedef enum authmode { AUTHMODE_OPEN, AUTHMODE_CLOSED, AUTHMODE_REGISTERED, AUTHMODE_SASL } authmode_t;
typedef struct conf {
char *iface_in, *iface_out;
@@ -55,6 +55,11 @@ typedef struct conf {
char *ft_listen;
char **protocols;
char *cafile;
+#ifdef WITH_GNUTLS
+ int ssl;
+ char *ssl_cert;
+ char *ssl_key;
+#endif
} conf_t;
G_GNUC_MALLOC conf_t *conf_load(int argc, char *argv[]);
diff --git a/configure b/configure
index d566484b..48ba506e 100755
--- a/configure
+++ b/configure
@@ -47,6 +47,7 @@ asan=0
plugins=1
otr=0
skype=0
+devel=0
events=glib
ssl=auto
@@ -147,6 +148,7 @@ Option Description Default
Disable/enable OTR encryption support $otr
--skype=0/1/plugin
Disable/enable Skype support $skype
+--devel=0/1 Disable/enable header install $devel
--events=... Event handler (glib, libevent) $events
--ssl=... SSL library to use (gnutls, nss, openssl, auto)
@@ -289,6 +291,10 @@ else
[ -z "$CFLAGS" ] && CFLAGS="-O2 -fno-strict-aliasing"
fi
+if [ "$devel" = "1" ]; then
+ echo 'DEVEL=1' >> Makefile.settings
+fi
+
if [ "$pie" = "1" ]; then
echo 'CFLAGS_BITLBEE=-fPIE' >> Makefile.settings
echo 'LDFLAGS_BITLBEE=-pie' >> Makefile.settings
@@ -605,6 +611,10 @@ if [ "$ret" = "0" ]; then
exit 1
fi;
+if [ "$ssl" = "gnutls" ]; then
+ echo '#define WITH_GNUTLS' >> config.h
+fi
+
echo 'SSL_CLIENT=ssl_'$ssl'.o' >> Makefile.settings
if detect_nameser_has_ns_types; then
@@ -805,13 +815,13 @@ EOF
protoobjs=$protoobjs'purple_mod.o '
# only disable these if the user didn't enable them explicitly
- [ "$msn" = "default-on" ] && msn=0
- [ "$jabber" = "default-on" ] && jabber=0
- [ "$oscar" = "default-on" ] && oscar=0
- [ "$yahoo" = "default-on" ] && yahoo=0
+ #[ "$msn" = "default-on" ] && msn=0
+ #[ "$jabber" = "default-on" ] && jabber=0
+ #[ "$oscar" = "default-on" ] && oscar=0
+ #[ "$yahoo" = "default-on" ] && yahoo=0
- echo '#undef PACKAGE' >> config.h
- echo '#define PACKAGE "BitlBee-LIBPURPLE"' >> config.h
+ #echo '#undef PACKAGE' >> config.h
+ #echo '#define PACKAGE "BitlBee-LIBPURPLE"' >> config.h
if [ "$events" = "libevent" ]; then
echo 'Warning: Some libpurple modules (including msn-pecan) do their event handling'
diff --git a/irc.c b/irc.c
index 835bffa0..d0685887 100644
--- a/irc.c
+++ b/irc.c
@@ -36,6 +36,7 @@ static char *set_eval_charset(set_t *set, char *value);
static char *set_eval_password(set_t *set, char *value);
static char *set_eval_bw_compat(set_t *set, char *value);
static char *set_eval_utf8_nicks(set_t *set, char *value);
+static char *set_eval_certfp(set_t *set, char *value);
irc_t *irc_new(int fd)
{
@@ -116,6 +117,7 @@ irc_t *irc_new(int fd)
s = set_add(&b->set, "nick_format", "%-@nick", NULL, irc);
s = set_add(&b->set, "offline_user_quits", "true", set_eval_bool, irc);
s = set_add(&b->set, "ops", "both", set_eval_irc_channel_ops, irc);
+ s = set_add(&b->set, "ops_mode", "@", set_eval_irc_channel_ops_mode, irc);
s = set_add(&b->set, "paste_buffer", "false", set_eval_bool, irc);
s->old_key = g_strdup("buddy_sendbuffer");
s = set_add(&b->set, "paste_buffer_delay", "200", set_eval_int, irc);
@@ -134,6 +136,13 @@ irc_t *irc_new(int fd)
s = set_add(&b->set, "to_char", ": ", set_eval_to_char, irc);
s = set_add(&b->set, "typing_notice", "false", set_eval_bool, irc);
s = set_add(&b->set, "utf8_nicks", "false", set_eval_utf8_nicks, irc);
+ s = set_add(&b->set, "strict_away", "false", set_eval_bool, irc);
+#ifdef WITH_GNUTLS
+ if (global.conf->ssl) {
+ s = set_add(&b->set, "_certfp", NULL, set_eval_certfp, irc);
+ s->flags = SET_NULL_OK | SET_HIDDEN;
+ }
+#endif
irc->root = iu = irc_user_new(irc, ROOT_NICK);
iu->host = g_strdup(myhost);
@@ -272,8 +281,14 @@ void irc_free(irc_t * irc)
b_event_remove(irc->w_watch_source_id);
}
+ if (global.conf->ssl) {
+ gnutls_bye(irc->ssl_session, GNUTLS_SHUT_WR);
+ }
closesocket(irc->fd);
irc->fd = -1;
+ if (global.conf->ssl) {
+ gnutls_deinit(irc->ssl_session);
+ }
g_hash_table_foreach_remove(irc->nick_user_hash, irc_free_hashkey, NULL);
g_hash_table_destroy(irc->nick_user_hash);
@@ -656,7 +671,12 @@ void irc_flush(irc_t *irc)
}
len = strlen(irc->sendbuffer);
- if ((n = send(irc->fd, irc->sendbuffer, len, 0)) == len) {
+ if (global.conf->ssl) {
+ n = ssl_server_write(irc, irc->sendbuffer, len);
+ } else {
+ n = send(irc->fd, irc->sendbuffer, len, 0);
+ }
+ if (n == len) {
g_free(irc->sendbuffer);
irc->sendbuffer = NULL;
@@ -731,6 +751,11 @@ int irc_check_login(irc_t *irc)
if (global.conf->authmode == AUTHMODE_CLOSED && !(irc->status & USTATUS_AUTHORIZED)) {
irc_send_num(irc, 464, ":This server is password-protected.");
return 0;
+ } else if (global.conf->authmode == AUTHMODE_SASL &&
+ (!(irc->caps & CAP_SASL) ||
+ !(irc->status & USTATUS_SASL_AUTHENTICATED))) {
+ irc_send_num(irc, 464, ":This server requires sasl.");
+ return 0;
} else {
irc_channel_t *ic;
irc_user_t *iu = irc->user;
@@ -972,6 +997,12 @@ static char *set_eval_utf8_nicks(set_t *set, char *value)
return set_eval_bool(set, value);
}
+static char *set_eval_certfp(set_t *set, char *value)
+{
+ /* XXX: What should we do here? */
+ return value;
+}
+
void register_irc_plugin(const struct irc_plugin *p)
{
irc_plugins = g_slist_prepend(irc_plugins, (gpointer) p);
diff --git a/irc.h b/irc.h
index 2e0cc3d5..deb11edf 100644
--- a/irc.h
+++ b/irc.h
@@ -26,6 +26,14 @@
#ifndef _IRC_H
#define _IRC_H
+#ifndef CONFIG
+#include "config.h"
+#endif
+
+#ifdef WITH_GNUTLS
+# include <gnutls/gnutls.h>
+#endif
+
#define IRC_MAX_LINE 512
#define IRC_MAX_ARGS 16
@@ -50,6 +58,7 @@ typedef enum {
Currently just blocks irc_vawrite(). */
USTATUS_CAP_PENDING = 16,
USTATUS_SASL_PLAIN_PENDING = 32,
+ USTATUS_SASL_AUTHENTICATED = 64,
/* Not really status stuff, but other kinds of flags: For slightly
better password security, since the only way to send passwords
@@ -72,6 +81,7 @@ typedef enum {
CAP_EXTENDED_JOIN = (1 << 2),
CAP_AWAY_NOTIFY = (1 << 3),
CAP_USERHOST_IN_NAMES = (1 << 4),
+ CAP_SERVER_TIME = (1 << 5),
} irc_cap_flag_t;
struct irc_user;
@@ -88,6 +98,13 @@ typedef struct irc {
struct irc_user *root;
struct irc_user *user;
+#ifdef WITH_GNUTLS
+ int ssl;
+ char *certfp;
+
+ gnutls_session_t ssl_session;
+#endif
+
char *password; /* HACK: Used to save the user's password, but before
logging in, this may contain a password we should
send to identify after USER/NICK are received. */
@@ -198,10 +215,12 @@ struct irc_channel_funcs {
};
typedef enum {
- IRC_CHANNEL_USER_OP = 1,
- IRC_CHANNEL_USER_HALFOP = 2,
- IRC_CHANNEL_USER_VOICE = 4,
- IRC_CHANNEL_USER_NONE = 8,
+ IRC_CHANNEL_USER_OWNER = 1,
+ IRC_CHANNEL_USER_ADMIN = 2,
+ IRC_CHANNEL_USER_OP = 4,
+ IRC_CHANNEL_USER_HALFOP = 8,
+ IRC_CHANNEL_USER_VOICE = 16,
+ IRC_CHANNEL_USER_NONE = 32,
} irc_channel_user_flags_t;
typedef struct irc_channel_user {
@@ -222,7 +241,7 @@ typedef enum {
struct irc_control_channel {
irc_control_channel_type_t type;
struct bee_group *group;
- struct account *account;
+ GSList *account;
struct prpl *protocol;
char modes[5];
};
@@ -305,6 +324,7 @@ struct irc_channel *irc_channel_with_user(irc_t *irc, irc_user_t *iu);
int irc_channel_set_topic(irc_channel_t *ic, const char *topic, const irc_user_t *who);
void irc_channel_user_set_mode(irc_channel_t *ic, irc_user_t *iu, irc_channel_user_flags_t flags);
void irc_channel_set_mode(irc_channel_t *ic, const char *s);
+struct account;
void irc_channel_auto_joins(irc_t *irc, struct account *acc);
void irc_channel_printf(irc_channel_t *ic, char *format, ...);
gboolean irc_channel_name_ok(const char *name);
@@ -312,9 +332,10 @@ void irc_channel_name_strip(char *name);
int irc_channel_name_cmp(const char *a_, const char *b_);
char *irc_channel_name_gen(irc_t *irc, const char *name);
gboolean irc_channel_name_hint(irc_channel_t *ic, const char *name);
-void irc_channel_update_ops(irc_channel_t *ic, char *value);
+void irc_channel_update_ops(irc_channel_t *ic, char *ops, char *ops_mode);
char irc_channel_user_get_prefix(irc_channel_user_t *icu);
char *set_eval_irc_channel_ops(struct set *set, char *value);
+char *set_eval_irc_channel_ops_mode(struct set *set, char *value);
gboolean irc_channel_wants_user(irc_channel_t *ic, irc_user_t *iu);
/* irc_commands.c */
@@ -339,6 +360,12 @@ void irc_send_who(irc_t *irc, GSList *l, const char *channel);
void irc_send_msg(irc_user_t *iu, const char *type, const char *dst, const char *msg, const char *prefix);
void irc_send_msg_raw(irc_user_t *iu, const char *type, const char *dst, const char *msg);
void irc_send_msg_f(irc_user_t *iu, const char *type, const char *dst, const char *format, ...) G_GNUC_PRINTF(4, 5);
+
+void irc_send_tagged_msg(irc_user_t *iu, const char *type, const char *dst, const char *msg, const char *prefix, const char *tags);
+void irc_send_tagged_msg_raw(irc_user_t *iu, const char *type, const char *dst, const char *msg, const char *tags);
+void irc_send_tagged_msg_f(irc_user_t *iu, const char *type, const char *dst, const char *tags, const char *format, ...) G_GNUC_PRINTF(5, 6);
+void irc_send_tagged_msg_vf(irc_user_t *iu, const char *type, const char *dst, const char *tags, const char *format, va_list params);
+
void irc_send_nick(irc_user_t *iu, const char *new_nick);
void irc_send_channel_user_mode_diff(irc_channel_t *ic, irc_user_t *iu,
irc_channel_user_flags_t old_flags, irc_channel_user_flags_t new_flags);
diff --git a/irc_cap.c b/irc_cap.c
index af1215e0..79f39256 100644
--- a/irc_cap.c
+++ b/irc_cap.c
@@ -42,6 +42,7 @@ static const cap_info_t supported_caps[] = {
{"extended-join", CAP_EXTENDED_JOIN},
{"away-notify", CAP_AWAY_NOTIFY},
{"userhost-in-names", CAP_USERHOST_IN_NAMES},
+ {"server-time", CAP_SERVER_TIME},
{NULL},
};
diff --git a/irc_channel.c b/irc_channel.c
index 3ccbce55..7adc1893 100644
--- a/irc_channel.c
+++ b/irc_channel.c
@@ -245,7 +245,8 @@ int irc_channel_add_user(irc_channel_t *ic, irc_user_t *iu)
ic->users = g_slist_insert_sorted(ic->users, icu, irc_channel_user_cmp);
if (iu == ic->irc->user || iu == ic->irc->root) {
- irc_channel_update_ops(ic, set_getstr(&ic->irc->b->set, "ops"));
+ irc_channel_update_ops(ic, set_getstr(&ic->irc->b->set, "ops"),
+ set_getstr(&ic->irc->b->set, "ops_mode"));
}
if (iu == ic->irc->user || ic->flags & IRC_CHANNEL_JOINED) {
@@ -441,7 +442,11 @@ void irc_channel_set_mode(irc_channel_t *ic, const char *s)
char irc_channel_user_get_prefix(irc_channel_user_t *icu)
{
- if (icu->flags & IRC_CHANNEL_USER_OP) {
+ if (icu->flags & IRC_CHANNEL_USER_OWNER) {
+ return '~';
+ } else if (icu->flags & IRC_CHANNEL_USER_ADMIN) {
+ return '&';
+ } else if (icu->flags & IRC_CHANNEL_USER_OP) {
return '@';
} else if (icu->flags & IRC_CHANNEL_USER_HALFOP) {
return '%';
@@ -675,14 +680,33 @@ static gint irc_channel_user_cmp(gconstpointer a_, gconstpointer b_)
return irc_user_cmp(a->iu, b->iu);
}
-void irc_channel_update_ops(irc_channel_t *ic, char *value)
+static int irc_channel_prefix_to_mode(char *value)
{
+ if (g_strcasecmp(value, "~") == 0) {
+ return IRC_CHANNEL_USER_OWNER;
+ } else if (g_strcasecmp(value, "&") == 0) {
+ return IRC_CHANNEL_USER_ADMIN;
+ } else if (g_strcasecmp(value, "@") == 0) {
+ return IRC_CHANNEL_USER_OP;
+ } else if (g_strcasecmp(value, "%") == 0) {
+ return IRC_CHANNEL_USER_HALFOP;
+ } else if (g_strcasecmp(value, "+") == 0) {
+ return IRC_CHANNEL_USER_VOICE;
+ } else {
+ return 0;
+ }
+}
+
+void irc_channel_update_ops(irc_channel_t *ic, char *ops, char *ops_mode)
+{
+ int mode = irc_channel_prefix_to_mode(ops_mode);
+
irc_channel_user_set_mode(ic, ic->irc->root,
- (strcmp(value, "both") == 0 ||
- strcmp(value, "root") == 0) ? IRC_CHANNEL_USER_OP : 0);
+ (strcmp(ops, "both") == 0 ||
+ strcmp(ops, "root") == 0) ? mode : 0);
irc_channel_user_set_mode(ic, ic->irc->user,
- (strcmp(value, "both") == 0 ||
- strcmp(value, "user") == 0) ? IRC_CHANNEL_USER_OP : 0);
+ (strcmp(ops, "both") == 0 ||
+ strcmp(ops, "user") == 0) ? mode : 0);
}
char *set_eval_irc_channel_ops(set_t *set, char *value)
@@ -696,7 +720,27 @@ char *set_eval_irc_channel_ops(set_t *set, char *value)
}
for (l = irc->channels; l; l = l->next) {
- irc_channel_update_ops(l->data, value);
+ irc_channel_update_ops(l->data, value, set_getstr(&irc->b->set, "ops_mode"));
+ }
+
+ return value;
+}
+
+char *set_eval_irc_channel_ops_mode(set_t *set, char *value)
+{
+ irc_t *irc = set->data;
+ GSList *l;
+
+ if (g_strcasecmp(value, "~") != 0 &&
+ g_strcasecmp(value, "&") != 0 &&
+ g_strcasecmp(value, "@") != 0 &&
+ g_strcasecmp(value, "%") != 0 &&
+ g_strcasecmp(value, "+") != 0) {
+ return SET_INVALID;
+ }
+
+ for (l = irc->channels; l; l = l->next) {
+ irc_channel_update_ops(l->data, set_getstr(&irc->b->set, "ops"), value);
}
return value;
@@ -822,17 +866,38 @@ static char *set_eval_by_account(set_t *set, char *value)
struct irc_channel *ic = set->data;
struct irc_control_channel *icc = ic->data;
account_t *acc;
+ GSList *new_acc = NULL;
+ char **accounts, **account;
- if (!(acc = account_get(ic->irc->b, value))) {
- return SET_INVALID;
+ if (value == NULL) {
+ goto out;
+ }
+
+ accounts = g_strsplit(value, ",", 0);
+ for (account = accounts; *account; account++) {
+ if (!(acc = account_get(ic->irc->b, *account))) {
+ goto fail;
+ } else {
+ new_acc = g_slist_append(new_acc, acc);
+ }
}
+ g_strfreev(accounts);
+
+out:
+ g_slist_free(icc->account);
+ icc->account = new_acc;
- icc->account = acc;
if ((icc->type & IRC_CC_TYPE_MASK) == IRC_CC_TYPE_ACCOUNT) {
bee_irc_channel_update(ic->irc, ic, NULL);
}
- return g_strdup(acc->tag);
+ return g_strdup(value);
+
+fail:
+ g_slist_free(new_acc);
+ g_strfreev(accounts);
+
+ return SET_INVALID;
}
static char *set_eval_fill_by(set_t *set, char *value)
@@ -920,6 +985,10 @@ static char *set_eval_show_users(set_t *set, char *value)
modechar = IRC_CHANNEL_USER_HALFOP;
} else if (last == '@') {
modechar = IRC_CHANNEL_USER_OP;
+ } else if (last == '&') {
+ modechar = IRC_CHANNEL_USER_ADMIN;
+ } else if (last == '~') {
+ modechar = IRC_CHANNEL_USER_OWNER;
}
if (strncmp(*part, "offline", 7) == 0) {
@@ -952,6 +1021,7 @@ fail:
gboolean irc_channel_wants_user(irc_channel_t *ic, irc_user_t *iu)
{
struct irc_control_channel *icc = ic->data;
+ GSList *accl;
gboolean ret = FALSE;
if (iu->bu == NULL) {
@@ -963,7 +1033,13 @@ gboolean irc_channel_wants_user(irc_channel_t *ic, irc_user_t *iu)
ret = iu->bu->group == icc->group;
break;
case IRC_CC_TYPE_ACCOUNT:
- ret = iu->bu->ic->acc == icc->account;
+ for (accl = icc->account; accl; accl = accl->next) {
+ account_t *acc = accl->data;
+ if (iu->bu->ic->acc == acc) {
+ ret = TRUE;
+ break;
+ }
+ }
break;
case IRC_CC_TYPE_PROTOCOL:
ret = iu->bu->ic->acc->prpl == icc->protocol;
@@ -991,6 +1067,7 @@ static gboolean control_channel_free(irc_channel_t *ic)
set_del(&ic->set, "protocol");
set_del(&ic->set, "show_users");
+ g_slist_free(icc->account);
g_free(icc);
ic->data = NULL;
diff --git a/irc_commands.c b/irc_commands.c
index dd5bdf38..01b1d821 100644
--- a/irc_commands.c
+++ b/irc_commands.c
@@ -149,6 +149,7 @@ static void irc_cmd_authenticate(irc_t *irc, char **cmd)
/* no check_login here - wait for CAP END */
irc_setpass(irc, pass);
}
+ irc->status |= USTATUS_SASL_AUTHENTICATED;
}
g_free(user);
@@ -743,10 +744,18 @@ static void irc_cmd_away(irc_t *irc, char **cmd)
}
away[j] = '\0';
- irc_send_num(irc, 306, ":You're now away: %s", away);
+ if (set_getbool(&irc->b->set, "strict_away")) {
+ irc_send_num(irc, 306, ":You have been marked as being away");
+ } else {
+ irc_send_num(irc, 306, ":You're now away: %s", away);
+ }
set_setstr(&irc->b->set, "away", away);
} else {
- irc_send_num(irc, 305, ":Welcome back");
+ if (set_getbool(&irc->b->set, "strict_away")) {
+ irc_send_num(irc, 305, ":You are no longer marked as being away");
+ } else {
+ irc_send_num(irc, 305, ":Welcome back");
+ }
set_setstr(&irc->b->set, "away", NULL);
}
}
diff --git a/irc_im.c b/irc_im.c
index 87b5262e..c9bd5a54 100644
--- a/irc_im.c
+++ b/irc_im.c
@@ -112,6 +112,10 @@ static gboolean bee_irc_user_status(bee_t *bee, bee_user_t *bu, bee_user_t *old)
irc_t *irc = bee->ui_data;
irc_user_t *iu = bu->ui_data;
+ if (set_getbool(&bu->ic->acc->set, "offline_is_away") && !(bu->flags & BEE_USER_ONLINE)) {
+ bu->flags |= (BEE_USER_ONLINE | BEE_USER_AWAY);
+ }
+
/* Do this outside the if below since away state can change without
the online state changing. */
iu->flags &= ~IRC_USER_AWAY;
@@ -136,7 +140,8 @@ static gboolean bee_irc_user_status(bee_t *bee, bee_user_t *bu, bee_user_t *old)
one QUIT instead of possibly many (in case of
multiple control chans). If there's a channel that
shows offline people, a JOIN will follow. */
- if (set_getbool(&bee->set, "offline_user_quits")) {
+ if (set_getbool(&bee->set, "offline_user_quits") &&
+ set_getbool(&bu->ic->acc->set, "offline_user_quits")) {
irc_user_quit(iu, "Leaving...");
}
}
@@ -224,9 +229,16 @@ static gboolean bee_irc_user_msg(bee_t *bee, bee_user_t *bu, const char *msg_, g
char *wrapped, *ts = NULL;
char *msg = g_strdup(msg_);
char *message_type = "PRIVMSG";
+ char *tags = NULL;
GSList *l;
-
- if (sent_at > 0 && set_getbool(&irc->b->set, "display_timestamps")) {
+ struct tm msg_time;
+
+ if (sent_at > 0 && (irc->caps & CAP_SERVER_TIME)) {
+ gmtime_r(&sent_at, &msg_time);
+ tags = g_strdup_printf("time=%04d-%02d-%02dT%02d:%02d:%02d.000Z",
+ msg_time.tm_year + 1900, msg_time.tm_mon + 1, msg_time.tm_mday,
+ msg_time.tm_hour, msg_time.tm_min, msg_time.tm_sec);
+ } else if (sent_at > 0 && set_getbool(&irc->b->set, "display_timestamps")) {
ts = irc_format_timestamp(irc, sent_at);
}
@@ -299,13 +311,14 @@ static gboolean bee_irc_user_msg(bee_t *bee, bee_user_t *bu, const char *msg_, g
}
wrapped = word_wrap(msg, 425);
- irc_send_msg(src_iu, message_type, dst, wrapped, prefix);
+ irc_send_tagged_msg(src_iu, message_type, dst, wrapped, prefix, tags);
g_free(wrapped);
cleanup:
g_free(prefix);
g_free(msg);
g_free(ts);
+ g_free(tags);
return TRUE;
}
@@ -663,19 +676,27 @@ static gboolean bee_irc_chat_msg(bee_t *bee, struct groupchat *c, bee_user_t *bu
irc_user_t *iu = flags & OPT_SELFMESSAGE ? irc->user : bu->ui_data;
irc_channel_t *ic = c->ui_data;
char *wrapped, *ts = NULL;
+ char *tags = NULL;
+ struct tm msg_time;
if (ic == NULL) {
return FALSE;
}
- if (sent_at > 0 && set_getbool(&bee->set, "display_timestamps")) {
+ if (sent_at > 0 && (irc->caps & CAP_SERVER_TIME)) {
+ gmtime_r(&sent_at, &msg_time);
+ tags = g_strdup_printf("time=%04d-%02d-%02dT%02d:%02d:%02d.000Z",
+ msg_time.tm_year + 1900, msg_time.tm_mon + 1, msg_time.tm_mday,
+ msg_time.tm_hour, msg_time.tm_min, msg_time.tm_sec);
+ } else if (sent_at > 0 && set_getbool(&bee->set, "display_timestamps")) {
ts = irc_format_timestamp(irc, sent_at);
}
wrapped = word_wrap(msg, 425);
- irc_send_msg(iu, "PRIVMSG", ic->name, wrapped, ts);
+ irc_send_tagged_msg(iu, "PRIVMSG", ic->name, wrapped, ts, tags);
g_free(ts);
g_free(wrapped);
+ g_free(tags);
return TRUE;
}
diff --git a/irc_send.c b/irc_send.c
index 70e4e82a..fd85f1ee 100644
--- a/irc_send.c
+++ b/irc_send.c
@@ -44,7 +44,7 @@ void irc_send_login(irc_t *irc)
PACKAGE, BITLBEE_VERSION);
irc_send_num(irc, 3, ":%s", IRCD_INFO);
irc_send_num(irc, 4, "%s %s %s %s", irc->root->host, BITLBEE_VERSION, UMODES UMODES_PRIV, CMODES);
- irc_send_num(irc, 5, "PREFIX=(ohv)@%%+ CHANTYPES=%s CHANMODES=,,,%s NICKLEN=%d CHANNELLEN=%d "
+ irc_send_num(irc, 5, "PREFIX=(qaohv)~&@%%+ CHANTYPES=%s CHANMODES=,,,%s NICKLEN=%d CHANNELLEN=%d "
"NETWORK=BitlBee SAFELIST CASEMAPPING=rfc1459 MAXTARGETS=1 WATCH=128 "
"FLOOD=0/9999 :are supported by this server",
CTYPES, CMODES, MAX_NICK_LENGTH - 1, MAX_NICK_LENGTH - 1);
@@ -366,6 +366,11 @@ void irc_send_who(irc_t *irc, GSList *l, const char *channel)
void irc_send_msg(irc_user_t *iu, const char *type, const char *dst, const char *msg, const char *prefix)
{
+ irc_send_tagged_msg(iu, type, dst, msg, prefix, NULL);
+}
+
+void irc_send_tagged_msg(irc_user_t *iu, const char *type, const char *dst, const char *msg, const char *prefix, const char *tags)
+{
char last = 0;
const char *s = msg, *line = msg;
char raw_msg[strlen(msg) + 1024];
@@ -385,14 +390,14 @@ void irc_send_msg(irc_user_t *iu, const char *type, const char *dst, const char
strcpy(raw_msg, "\001ACTION ");
strncat(raw_msg, line + 4, s - line - 4);
strcat(raw_msg, "\001");
- irc_send_msg_raw(iu, type, dst, raw_msg);
+ irc_send_tagged_msg_raw(iu, type, dst, raw_msg, tags);
} else {
*raw_msg = '\0';
if (prefix && *prefix) {
strcpy(raw_msg, prefix);
}
strncat(raw_msg, line, s - line);
- irc_send_msg_raw(iu, type, dst, raw_msg);
+ irc_send_tagged_msg_raw(iu, type, dst, raw_msg, tags);
}
line = s + 1;
}
@@ -402,21 +407,56 @@ void irc_send_msg(irc_user_t *iu, const char *type, const char *dst, const char
void irc_send_msg_raw(irc_user_t *iu, const char *type, const char *dst, const char *msg)
{
- irc_write(iu->irc, ":%s!%s@%s %s %s :%s",
- iu->nick, iu->user, iu->host, type, dst, msg && *msg ? msg : " ");
+ irc_send_tagged_msg_raw(iu, type, dst, msg, NULL);
+}
+
+void irc_send_tagged_msg_raw(irc_user_t *iu, const char *type, const char *dst, const char *msg, const char *tags)
+{
+ if (!tags || !*tags) {
+ irc_write(iu->irc, ":%s!%s@%s %s %s :%s",
+ iu->nick, iu->user, iu->host,
+ type, dst, msg && *msg ? msg : " ");
+ } else {
+ irc_write(iu->irc, "@%s :%s!%s@%s %s %s :%s",
+ tags, iu->nick, iu->user, iu->host,
+ type, dst, msg && *msg ? msg : " ");
+ }
}
void irc_send_msg_f(irc_user_t *iu, const char *type, const char *dst, const char *format, ...)
{
- char text[IRC_MAX_LINE];
va_list params;
va_start(params, format);
- g_vsnprintf(text, IRC_MAX_LINE, format, params);
+ irc_send_tagged_msg_vf(iu, type, dst, NULL, format, params);
+ va_end(params);
+
+}
+
+void irc_send_tagged_msg_f(irc_user_t *iu, const char *type, const char *dst, const char *tags, const char *format, ...)
+{
+ va_list params;
+
+ va_start(params, format);
+ irc_send_tagged_msg_vf(iu, type, dst, tags, format, params);
va_end(params);
+}
+
+void irc_send_tagged_msg_vf(irc_user_t *iu, const char *type, const char *dst, const char *tags, const char *format, va_list params)
+{
+ char text[IRC_MAX_LINE];
- irc_write(iu->irc, ":%s!%s@%s %s %s :%s",
- iu->nick, iu->user, iu->host, type, dst, text);
+ g_vsnprintf(text, IRC_MAX_LINE, format, params);
+
+ if (!tags || !*tags) {
+ irc_write(iu->irc, ":%s!%s@%s %s %s :%s",
+ iu->nick, iu->user, iu->host,
+ type, dst, text);
+ } else {
+ irc_write(iu->irc, "@%s :%s!%s@%s %s %s :%s",
+ tags, iu->nick, iu->user, iu->host,
+ type, dst, text);
+ }
}
void irc_send_nick(irc_user_t *iu, const char *new)
@@ -429,11 +469,27 @@ void irc_send_nick(irc_user_t *iu, const char *new)
void irc_send_channel_user_mode_diff(irc_channel_t *ic, irc_user_t *iu,
irc_channel_user_flags_t old, irc_channel_user_flags_t new)
{
- char changes[3 * (5 + strlen(iu->nick))];
- char from[strlen(ic->irc->root->nick) + strlen(ic->irc->root->user) + strlen(ic->irc->root->host) + 3];
+ char changes[5 * (5 + strlen(iu->nick))];
+ char from[strlen(ic->irc->root->nick) + strlen(ic->irc->root->user) + strlen(ic->irc->root->host) + 5];
int n;
*changes = '\0'; n = 0;
+ if ((old & IRC_CHANNEL_USER_OWNER) != (new & IRC_CHANNEL_USER_OWNER)) {
+ n++;
+ if (new & IRC_CHANNEL_USER_OWNER) {
+ strcat(changes, "+q");
+ } else {
+ strcat(changes, "-q");
+ }
+ }
+ if ((old & IRC_CHANNEL_USER_ADMIN) != (new & IRC_CHANNEL_USER_ADMIN)) {
+ n++;
+ if (new & IRC_CHANNEL_USER_ADMIN) {
+ strcat(changes, "+a");
+ } else {
+ strcat(changes, "-a");
+ }
+ }
if ((old & IRC_CHANNEL_USER_OP) != (new & IRC_CHANNEL_USER_OP)) {
n++;
if (new & IRC_CHANNEL_USER_OP) {
diff --git a/lib/ssl_client.h b/lib/ssl_client.h
index d2e12534..08debe48 100644
--- a/lib/ssl_client.h
+++ b/lib/ssl_client.h
@@ -32,6 +32,7 @@
is completed. */
#include <glib.h>
+#include "irc.h"
#include "proxy.h"
/* Some generic error codes. Especially SSL_AGAIN is important if you
@@ -71,6 +72,11 @@ G_MODULE_EXPORT void *ssl_starttls(int fd, char *hostname, gboolean verify, ssl_
G_MODULE_EXPORT int ssl_read(void *conn, char *buf, int len);
G_MODULE_EXPORT int ssl_write(void *conn, const char *buf, int len);
+G_MODULE_EXPORT gboolean ssl_setup_server(void);
+G_MODULE_EXPORT gboolean ssl_accept(irc_t *irc);
+G_MODULE_EXPORT int ssl_server_read(irc_t *irc, char *buf, int len);
+G_MODULE_EXPORT int ssl_server_write(irc_t *irc, const char *buf, int len);
+
/* Now needed by most SSL libs. See for more info:
http://www.gnu.org/software/gnutls/manual/gnutls.html#index-gnutls_005frecord_005fcheck_005fpending-209
http://www.openssl.org/docs/ssl/SSL_pending.html
diff --git a/lib/ssl_gnutls.c b/lib/ssl_gnutls.c
index c9b35fff..c37449c4 100644
--- a/lib/ssl_gnutls.c
+++ b/lib/ssl_gnutls.c
@@ -33,11 +33,14 @@
#include "sock.h"
#include "stdlib.h"
#include "bitlbee.h"
+#include "config.h"
+#include "irc.h"
int ssl_errno = 0;
static gboolean initialized = FALSE;
gnutls_certificate_credentials_t xcred;
+gnutls_certificate_credentials_t server_xcred;
#include <limits.h>
@@ -125,6 +128,40 @@ void *ssl_connect(char *host, int port, gboolean verify, ssl_input_function func
return conn;
}
+gboolean ssl_setup_server()
+{
+ gnutls_certificate_allocate_credentials(&server_xcred);
+ gnutls_certificate_set_x509_key_file(server_xcred, global.conf->ssl_cert, global.conf->ssl_key, GNUTLS_X509_FMT_PEM);
+
+ return TRUE;
+}
+
+gboolean ssl_accept(irc_t *irc)
+{
+ int ret;
+
+ gnutls_init(&irc->ssl_session, GNUTLS_SERVER);
+ gnutls_transport_set_int(irc->ssl_session, irc->fd);
+ gnutls_credentials_set(irc->ssl_session, GNUTLS_CRD_CERTIFICATE, server_xcred);
+ gnutls_certificate_server_set_request(irc->ssl_session, GNUTLS_CERT_REQUEST);
+
+ do {
+ ret = gnutls_handshake(irc->ssl_session);
+ } while (ret < 0 && gnutls_error_is_fatal(ret) == 0);
+
+ if (ret < 0) {
+ close(irc->fd);
+ gnutls_deinit(irc->ssl_session);
+
+ log_message(LOGLVL_INFO, "SSL Handshake failed (%s)", gnutls_strerror(ret)); // XXX
+
+ exit(1);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
void *ssl_starttls(int fd, char *hostname, gboolean verify, ssl_input_function func, gpointer data)
{
struct scd *conn = g_new0(struct scd, 1);
@@ -393,6 +430,24 @@ int ssl_read(void *conn, char *buf, int len)
return st;
}
+int ssl_server_read(irc_t *irc, char *buf, int len)
+{
+ int st;
+
+ st = gnutls_record_recv(irc->ssl_session, buf, len);
+
+ ssl_errno = SSL_OK;
+ if (st == GNUTLS_E_AGAIN || st == GNUTLS_E_INTERRUPTED) {
+ ssl_errno = SSL_AGAIN;
+ }
+
+ if (SSLDEBUG && getenv("BITLBEE_DEBUG") && st > 0) {
+ len = write(2, buf, st);
+ }
+
+ return st;
+}
+
int ssl_write(void *conn, const char *buf, int len)
{
int st;
@@ -416,6 +471,24 @@ int ssl_write(void *conn, const char *buf, int len)
return st;
}
+int ssl_server_write(irc_t *irc, const char *buf, int len)
+{
+ int st;
+
+ st = gnutls_record_send(irc->ssl_session, buf, len);
+
+ ssl_errno = SSL_OK;
+ if (st == GNUTLS_E_AGAIN || st == GNUTLS_E_INTERRUPTED) {
+ ssl_errno = SSL_AGAIN;
+ }
+
+ if (SSLDEBUG && getenv("BITLBEE_DEBUG") && st > 0) {
+ len = write(2, buf, st);
+ }
+
+ return st;
+}
+
int ssl_pending(void *conn)
{
if (conn == NULL) {
diff --git a/protocols/account.c b/protocols/account.c
index e25e40c7..aa14b0c3 100644
--- a/protocols/account.c
+++ b/protocols/account.c
@@ -74,6 +74,8 @@ account_t *account_add(bee_t *bee, struct prpl *prpl, char *user, char *pass)
s = set_add(&a->set, "username", NULL, set_eval_account, a);
s->flags |= SET_NOSAVE | ACC_SET_OFFLINE_ONLY | ACC_SET_LOCKABLE;
set_setstr(&a->set, "username", user);
+ set_add(&a->set, "offline_user_quits", "true", set_eval_bool, a);
+ set_add(&a->set, "offline_is_away", "false", set_eval_bool, a);
/* Hardcode some more clever tag guesses. */
strcpy(tag, prpl->name);
@@ -122,6 +124,36 @@ account_t *account_add(bee_t *bee, struct prpl *prpl, char *user, char *pass)
return a;
}
+void account_update_channel_set(irc_channel_t *ic, char *old_tag, char *new_tag)
+{
+ gboolean found = FALSE;
+ char **account, **accounts;
+ char *saccount = set_getstr(&ic->set, "account");
+
+ if (saccount == NULL || *saccount == '\0') {
+ return;
+ }
+
+ accounts = g_strsplit(saccount, ",", 0);
+ for (account = accounts; *account; account++) {
+ if (g_strcasecmp(*account, old_tag) == 0) {
+ found = TRUE;
+ break;
+ }
+ }
+
+ if (found) {
+ g_free(*account);
+ *account = g_strdup(new_tag);
+
+ saccount = g_strjoinv(",", accounts);
+ set_setstr(&ic->set, "account", saccount);
+ g_free(saccount);
+ }
+
+ g_strfreev(accounts);
+}
+
char *set_eval_account(set_t *set, char *value)
{
account_t *acc = set->data;
@@ -163,14 +195,28 @@ char *set_eval_account(set_t *set, char *value)
return NULL; /* password shouldn't be visible in plaintext! */
} else if (strcmp(set->key, "tag") == 0) {
account_t *oa;
+ irc_t *irc;
+ GSList *l;
+ char *old;
/* Enforce uniqueness. */
if ((oa = account_by_tag(acc->bee, value)) && oa != acc) {
return SET_INVALID;
}
- g_free(acc->tag);
+ old = acc->tag;
acc->tag = g_strdup(value);
+
+ irc = acc->bee->ui_data;
+ for (l = irc->channels; l; l = l->next) {
+ irc_channel_t *ic = l->data;
+
+ if (g_strcasecmp(set_getstr(&ic->set, "type"), "control") == 0) {
+ account_update_channel_set(ic, old, value);
+ }
+ }
+
+ g_free(old);
return value;
} else if (strcmp(set->key, "auto_connect") == 0) {
if (!is_bool(value)) {
@@ -291,9 +337,43 @@ account_t *account_by_tag(bee_t *bee, const char *tag)
return NULL;
}
+void account_remove_from_channel_set(irc_channel_t *ic, char *tag)
+{
+ gboolean found = FALSE;
+ char **account, **accounts;
+ char *saccount = set_getstr(&ic->set, "account");
+
+ if (saccount == NULL || *saccount == '\0') {
+ return;
+ }
+
+ accounts = g_strsplit(saccount, ",", 0);
+ for (account = accounts; *account; account++) {
+ if (g_strcasecmp(*account, tag) == 0) {
+ found = TRUE;
+ break;
+ }
+ }
+
+ if (found) {
+ g_free(*account);
+
+ do {
+ *account = *(account + 1);
+ } while (*(++account) != NULL);
+
+ saccount = g_strjoinv(",", accounts);
+ set_setstr(&ic->set, "account", saccount);
+ }
+
+ g_strfreev(accounts);
+}
+
void account_del(bee_t *bee, account_t *acc)
{
account_t *a, *l = NULL;
+ GSList *accl;
+ irc_t *irc;
if (acc->ic) {
/* Caller should have checked, accounts still in use can't be deleted. */
@@ -317,6 +397,16 @@ void account_del(bee_t *bee, account_t *acc)
}
*/
+ /* Remove from channel set account */
+ irc = acc->bee->ui_data;
+ for (accl = irc->channels; accl; accl = accl->next) {
+ irc_channel_t *ic = accl->data;
+
+ if (g_strcasecmp(set_getstr(&ic->set, "type"), "control") == 0) {
+ account_remove_from_channel_set(ic, acc->tag);
+ }
+ }
+
while (a->set) {
set_del(&a->set, a->set->key);
}
diff --git a/protocols/purple/purple.c b/protocols/purple/purple.c
index d0e8ec40..2b3a09a3 100644
--- a/protocols/purple/purple.c
+++ b/protocols/purple/purple.c
@@ -278,6 +278,18 @@ static void purple_init(account_t *acc)
purple_accounts_remove(pa);
}
+static void purple_save_password(account_t *acc, PurpleAccount *pa)
+{
+ char *old_password, *new_password;
+
+ old_password = set_getstr(&acc->set, "password");
+ new_password = g_strdup(purple_account_get_password(pa));
+ if (!old_password || !*old_password || g_strcmp0(old_password, new_password) != 0) {
+ set_setstr(&acc->set, "password", new_password);
+ }
+ g_free(new_password);
+}
+
static void purple_sync_settings(account_t *acc, PurpleAccount *pa)
{
PurplePlugin *prpl = purple_plugins_find_with_id(pa->protocol_id);
@@ -365,6 +377,8 @@ static void purple_logout(struct im_connection *ic)
imcb_chat_free(ic->groupchats->data);
}
+ purple_save_password(ic->acc, pd->account);
+
purple_account_set_enabled(pd->account, "BitlBee", FALSE);
purple_connections = g_slist_remove(purple_connections, ic);
purple_accounts_remove(pd->account);
@@ -1532,8 +1546,8 @@ void purple_initmodule()
ret = g_memdup(&funcs, sizeof(funcs));
ret->name = ret->data = prot->info->id;
- if (strncmp(ret->name, "prpl-", 5) == 0) {
- ret->name += 5;
+ if (strncmp(ret->name, "prpl-", 5) != 0) {
+ ret->name = g_strdup_printf("prpl-%s", ret->name);
}
register_protocol(ret);
@@ -1541,12 +1555,12 @@ void purple_initmodule()
/* libpurple doesn't define a protocol called OSCAR, but we
need it to be compatible with normal BitlBee. */
- if (g_strcasecmp(prot->info->id, "prpl-aim") == 0) {
+ /*if (g_strcasecmp(prot->info->id, "prpl-aim") == 0) {
ret = g_memdup(&funcs, sizeof(funcs));
ret->name = "oscar";
ret->data = prot->info->id;
register_protocol(ret);
- }
+ }*/
}
g_string_append(help, "\n\nFor used protocols, more information about available "
diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c
index 4fe509bb..5694c1b6 100644
--- a/protocols/twitter/twitter.c
+++ b/protocols/twitter/twitter.c
@@ -304,7 +304,7 @@ static void twitter_main_loop_start(struct im_connection *ic)
struct groupchat *twitter_groupchat_init(struct im_connection *ic)
{
- char *name_hint;
+ char *name_hint, *tmp;
struct groupchat *gc;
struct twitter_data *td = ic->proto_data;
GSList *l;
@@ -315,7 +315,14 @@ struct groupchat *twitter_groupchat_init(struct im_connection *ic)
td->timeline_gc = gc = imcb_chat_new(ic, "twitter/timeline");
- name_hint = g_strdup_printf("%s_%s", td->prefix, ic->acc->user);
+ tmp = set_getstr(&ic->acc->set, "channel_name");
+
+ if (tmp == NULL || strlen(tmp) == 0) {
+ name_hint = g_strdup_printf("%s_%s", td->prefix, ic->acc->user);
+ } else {
+ name_hint = g_strdup(tmp);
+ }
+
imcb_chat_name_hint(gc, name_hint);
g_free(name_hint);
@@ -518,6 +525,23 @@ static char *set_eval_commands(set_t * set, char *value)
}
}
+static char *set_eval_channel_name(set_t * set, char *value)
+{
+ size_t len;
+
+ if (value == NULL) {
+ return NULL;
+ }
+
+ len = strlen(value);
+
+ if (len < MAX_NICK_LENGTH && len > 0) {
+ return value;
+ } else {
+ return NULL;
+ }
+}
+
static char *set_eval_mode(set_t * set, char *value)
{
if (g_strcasecmp(value, "one") == 0 ||
@@ -572,6 +596,12 @@ static void twitter_init(account_t * acc)
s = set_add(&acc->set, "strip_newlines", "false", set_eval_bool, acc);
+ s = set_add(&acc->set, "long_ids", "false", set_eval_bool, acc);
+ s->flags |= ACC_SET_OFFLINE_ONLY;
+
+ s = set_add(&acc->set, "channel_name", NULL, set_eval_channel_name, acc);
+ s->flags |= ACC_SET_OFFLINE_ONLY;
+
s = set_add(&acc->set, "_last_tweet", "0", NULL, acc);
s->flags |= SET_HIDDEN | SET_NOSAVE;
@@ -649,8 +679,13 @@ static void twitter_login(account_t * acc)
imcb_add_buddy(ic, name, NULL);
imcb_buddy_status(ic, name, OPT_LOGGED_IN, NULL, NULL);
- td->log = g_new0(struct twitter_log_data, TWITTER_LOG_LENGTH);
+ td->long_ids = set_getbool(&ic->acc->set, "long_ids");
+ td->log_length = (td->long_ids) ? TWITTER_LONG_LOG_LENGTH : TWITTER_SHORT_LOG_LENGTH;
+
+ td->log = g_new0(struct twitter_log_data, td->log_length);
+ td->filter_log = g_new0(struct twitter_log_data, td->log_length);
td->log_id = -1;
+ td->filter_log_id = -1;
s = set_getstr(&ic->acc->set, "mode");
if (g_strcasecmp(s, "one") == 0) {
@@ -894,7 +929,7 @@ static guint64 twitter_message_id_from_command_arg(struct im_connection *ic, cha
if (arg[0] == '#') {
arg++;
}
- if (parse_int64(arg, 16, &id) && id < TWITTER_LOG_LENGTH) {
+ if (parse_int64(arg, 16, &id) && id < td->log_length) {
bu = td->log[id].bu;
id = td->log[id].id;
} else if (parse_int64(arg, 10, &id)) {
@@ -984,7 +1019,8 @@ static void twitter_handle_command(struct im_connection *ic, char *message)
twitter_report_spam(ic, screen_name);
goto eof;
- } else if (g_strcasecmp(cmd[0], "rt") == 0 && cmd[1]) {
+ } else if ((g_strcasecmp(cmd[0], "rt") == 0 ||
+ g_strcasecmp(cmd[0], "retweet") == 0) && cmd[1]) {
id = twitter_message_id_from_command_arg(ic, cmd[1], NULL);
td->last_status_id = 0;
diff --git a/protocols/twitter/twitter.h b/protocols/twitter/twitter.h
index 86c88262..61afa4bb 100644
--- a/protocols/twitter/twitter.h
+++ b/protocols/twitter/twitter.h
@@ -68,7 +68,9 @@ struct twitter_data {
gint main_loop_id;
gint filter_update_id;
struct http_request *stream;
+ time_t stream_opentime;
struct http_request *filter_stream;
+ time_t filter_stream_opentime;
struct groupchat *timeline_gc;
gint http_fails;
twitter_flags_t flags;
@@ -84,6 +86,11 @@ struct twitter_data {
/* set show_ids */
struct twitter_log_data *log;
int log_id;
+ struct twitter_log_data *filter_log;
+ int filter_log_id;
+
+ gboolean long_ids;
+ int log_length;
};
#define TWITTER_FILTER_UPDATE_WAIT 3000
@@ -99,7 +106,8 @@ struct twitter_user_data {
time_t last_time;
};
-#define TWITTER_LOG_LENGTH 256
+#define TWITTER_SHORT_LOG_LENGTH 256
+#define TWITTER_LONG_LOG_LENGTH (256 * 256)
struct twitter_log_data {
guint64 id;
/* DANGER: bu can be a dead pointer. Check it first.
diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c
index 77f487ae..b69c532e 100644
--- a/protocols/twitter/twitter_lib.c
+++ b/protocols/twitter/twitter_lib.c
@@ -790,7 +790,7 @@ static char *twitter_msg_add_id(struct im_connection *ic,
if (txs->reply_to) {
int i;
- for (i = 0; i < TWITTER_LOG_LENGTH; i++) {
+ for (i = 0; i < td->log_length; i++) {
if (td->log[i].id == txs->reply_to) {
reply_to = i;
break;
@@ -808,26 +808,52 @@ static char *twitter_msg_add_id(struct im_connection *ic,
}
}
- td->log_id = (td->log_id + 1) % TWITTER_LOG_LENGTH;
- td->log[td->log_id].id = txs->id;
- td->log[td->log_id].bu = bee_user_by_handle(ic->bee, ic, txs->user->screen_name);
+ if (txs->from_filter) {
+ td->filter_log_id = (td->filter_log_id + 1) % td->log_length;
+ td->filter_log[td->filter_log_id].id = txs->id;
+ td->filter_log[td->filter_log_id].bu = bee_user_by_handle(ic->bee, ic, txs->user->screen_name);
+ } else {
+ td->log_id = (td->log_id + 1) % td->log_length;
+ td->log[td->log_id].id = txs->id;
+ td->log[td->log_id].bu = bee_user_by_handle(ic->bee, ic, txs->user->screen_name);
+ }
/* This is all getting hairy. :-( If we RT'ed something ourselves,
remember OUR id instead so undo will work. In other cases, the
original tweet's id should be remembered for deduplicating. */
if (g_strcasecmp(txs->user->screen_name, td->user) == 0) {
- td->log[td->log_id].id = txs->rt_id;
- /* More useful than NULL. */
- td->log[td->log_id].bu = &twitter_log_local_user;
+ if (txs->from_filter) {
+ td->filter_log[td->filter_log_id].id = txs->rt_id;
+ /* More useful than NULL. */
+ td->filter_log[td->filter_log_id].bu = &twitter_log_local_user;
+ } else {
+ td->log[td->log_id].id = txs->rt_id;
+ /* More useful than NULL. */
+ td->log[td->log_id].bu = &twitter_log_local_user;
+ }
}
if (set_getbool(&ic->acc->set, "show_ids")) {
if (reply_to != -1) {
- return g_strdup_printf("\002[\002%02x->%02x\002]\002 %s%s",
- td->log_id, reply_to, prefix, txs->text);
+ if (td->long_ids) {
+ return g_strdup_printf("\002[\002%04x->%04x\002]\002 %s%s",
+ txs->from_filter ? td->filter_log_id : td->log_id,
+ reply_to, prefix, txs->text);
+ } else {
+ return g_strdup_printf("\002[\002%02x->%02x\002]\002 %s%s",
+ txs->from_filter ? td->filter_log_id : td->log_id,
+ reply_to, prefix, txs->text);
+ }
} else {
- return g_strdup_printf("\002[\002%02x\002]\002 %s%s",
- td->log_id, prefix, txs->text);
+ if (td->long_ids) {
+ return g_strdup_printf("\002[\002%04x\002]\002 %s%s",
+ txs->from_filter ? td->filter_log_id : td->log_id,
+ prefix, txs->text);
+ } else {
+ return g_strdup_printf("\002[\002%02x\002]\002 %s%s",
+ txs->from_filter ? td->filter_log_id : td->log_id,
+ prefix, txs->text);
+ }
}
} else {
if (*prefix) {
@@ -1009,8 +1035,23 @@ static void twitter_http_stream(struct http_request *req)
if ((req->flags & HTTPC_EOF) || !req->reply_body) {
if (req == td->stream) {
td->stream = NULL;
+
+ if (req->status_code == 200 &&
+ td->stream_opentime + 3 < time(NULL)) {
+ debug("Reconnecting to twitter stream.");
+ twitter_open_stream(ic);
+ twitter_get_timeline(ic, -1);
+ return;
+ }
} else if (req == td->filter_stream) {
td->filter_stream = NULL;
+
+ if (req->status_code == 200 &&
+ td->filter_stream_opentime + 3 < time(NULL)) {
+ debug("Reconnecting to twitter filter stream.");
+ twitter_open_filter_stream(ic);
+ return;
+ }
}
imcb_error(ic, "Stream closed (%s)", req->status_string);
@@ -1090,10 +1131,12 @@ static gboolean twitter_stream_handle_object(struct im_connection *ic, json_valu
static gboolean twitter_stream_handle_status(struct im_connection *ic, struct twitter_xml_status *txs)
{
struct twitter_data *td = ic->proto_data;
+ struct twitter_log_data *tl;
int i;
- for (i = 0; i < TWITTER_LOG_LENGTH; i++) {
- if (td->log[i].id == txs->id) {
+ tl = txs->from_filter ? td->filter_log : td->log;
+ for (i = 0; i < td->log_length; i++) {
+ if (tl[i].id == txs->id) {
/* Got a duplicate (RT, probably). Drop it. */
return TRUE;
}
@@ -1185,6 +1228,7 @@ gboolean twitter_open_stream(struct im_connection *ic)
/* This flag must be enabled or we'll get no data until EOF
(which err, kind of, defeats the purpose of a streaming API). */
td->stream->flags |= HTTPC_STREAMING;
+ td->stream_opentime = time(NULL);
return TRUE;
}
@@ -1240,6 +1284,7 @@ static gboolean twitter_filter_stream(struct im_connection *ic)
/* This flag must be enabled or we'll get no data until EOF
(which err, kind of, defeats the purpose of a streaming API). */
td->filter_stream->flags |= HTTPC_STREAMING;
+ td->filter_stream_opentime = time(NULL);
ret = TRUE;
}
diff --git a/protocols/twitter/twitter_lib.h b/protocols/twitter/twitter_lib.h
index 6833d23d..981ec973 100644
--- a/protocols/twitter/twitter_lib.h
+++ b/protocols/twitter/twitter_lib.h
@@ -77,10 +77,6 @@
#define TWITTER_BLOCKS_CREATE_URL "/blocks/create/"
#define TWITTER_BLOCKS_DESTROY_URL "/blocks/destroy/"
-/* Mute URLs */
-#define TWITTER_MUTES_CREATE_URL "/mutes/users/create.json"
-#define TWITTER_MUTES_DESTROY_URL "/mutes/users/destroy.json"
-
/* Report spam */
#define TWITTER_REPORT_SPAM_URL "/users/report_spam.json"
diff --git a/root_commands.c b/root_commands.c
index dcf7a7ed..702a068d 100644
--- a/root_commands.c
+++ b/root_commands.c
@@ -654,6 +654,23 @@ static void cmd_channel(irc_t *irc, char **cmd)
"channels you're still in cannot be deleted).",
irc->default_channel->name);
}
+ } else if (len >= 1 && g_strncasecmp(cmd[2], "rename", len) == 0) {
+ if (strlen(cmd[3]) < 1) {
+ irc_rootmsg(irc, "You have to specify new name.");
+ } else if (!(ic->flags & IRC_CHANNEL_JOINED) &&
+ ic != ic->irc->default_channel) {
+ if (irc_channel_name_hint(ic, cmd[3])) {
+ irc_rootmsg(irc, "Channel %s renamed to %s.",
+ cmd[1], cmd[3]);
+ } else {
+ irc_rootmsg(irc, "Failed to rename channel %s to %s.",
+ cmd[1], cmd[3]);
+ }
+ } else {
+ irc_rootmsg(irc, "Couldn't rename channel (main channel %s or "
+ "channels you're still in cannot be renamed).",
+ irc->default_channel->name);
+ }
} else {
irc_rootmsg(irc,
"Unknown command: %s [...] %s. Please use \x02help commands\x02 to get a list of available commands.", "channel",
@@ -1315,6 +1332,13 @@ static void cmd_nick(irc_t *irc, char **cmd)
irc_rootmsg(irc, "This command is deprecated. Try: account %s set display_name", cmd[1]);
}
+#ifdef WITH_GNUTLS
+static void cmd_certfp(irc_t *irc, char **cmd)
+{
+ irc_rootmsg(irc, "Show current/set new certfp");
+}
+#endif
+
/* Maybe this should be a stand-alone command as well? */
static void bitlbee_whatsnew(irc_t *irc)
{
@@ -1365,6 +1389,9 @@ command_t root_commands[] = {
{ "set", 0, cmd_set, 0 },
{ "transfer", 0, cmd_transfer, 0 },
{ "yes", 0, cmd_yesno, 0 },
+#ifdef WITH_GNUTLS
+ { "certfp", 1, cmd_certfp, 0 },
+#endif
/* Not expecting too many plugins adding root commands so just make a
dumb array with some empty entried at the end. */
{ NULL },