aboutsummaryrefslogtreecommitdiffstats
path: root/irc_channel.c
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2016-04-12 13:00:00 +0200
committerMarius Halden <marius.h@lden.org>2016-05-07 14:31:03 +0200
commita7e12e930adceb0d058400ca5e5616d69747f4d0 (patch)
tree808cb107e0ef91254495c82629e6a1e0f7091536 /irc_channel.c
parentaaf30d6cdb11667ccf8f1eeb523e81272fa8066c (diff)
Add support for multiple accounts in set account
The set account for control channels is now a comma separeted list of accounts instead of just one. If the user changes the tag of an accounts trough `account <id> set tag <new_tag>`, the account set will be updated to reflect this change for all relevant channels. If an account is removed trough `account <id> delete` it will be removed from the account set for all relevant channels.
Diffstat (limited to 'irc_channel.c')
-rw-r--r--irc_channel.c39
1 files changed, 34 insertions, 5 deletions
diff --git a/irc_channel.c b/irc_channel.c
index 34ed54a9..7adc1893 100644
--- a/irc_channel.c
+++ b/irc_channel.c
@@ -866,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;
}
- icc->account = acc;
+ 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;
+
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)
@@ -1000,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) {
@@ -1011,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;
@@ -1039,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;