aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2015-11-06 20:46:36 +0100
committerMarius Halden <marius.h@lden.org>2015-11-06 20:46:36 +0100
commite2f96dd34d1ae9470fe65b6fef4a28592bea1a9e (patch)
treef629b79ef2635b47c72544afdd4448aefe0f865e
parente41887d0505123fef792e47a9f7f1d5fdccc22c7 (diff)
Add support for multiple accounts in set account
-rw-r--r--irc_channel.c70
1 files changed, 65 insertions, 5 deletions
diff --git a/irc_channel.c b/irc_channel.c
index 04eb0c4f..72757a56 100644
--- a/irc_channel.c
+++ b/irc_channel.c
@@ -824,22 +824,66 @@ static gboolean control_channel_join(irc_channel_t *ic)
return TRUE;
}
+struct acclist {
+ struct account *acc;
+ struct acclist *next;
+};
+
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;
+ struct acclist *accl, *tmp, *new_acc = NULL;
- if (!(acc = account_get(ic->irc->b, value))) {
- return SET_INVALID;
+ char **accounts, **account;
+ accounts = g_strsplit(value, ",", 0);
+ if (accounts == NULL) {
+ goto fail;
+ }
+
+ for (account = accounts; *account; account++) {
+ if (!(acc = account_get(ic->irc->b, *account))) {
+ goto fail;
+ } else {
+ tmp = g_malloc(sizeof(struct account));
+ if (tmp == NULL) {
+ goto fail;
+ } else {
+ tmp->acc = acc;
+ tmp->next = new_acc;
+ new_acc = tmp;
+ }
+ }
+ }
+
+ accl = (struct acclist *)icc->account;
+ while (accl) {
+ tmp = accl->next;
+ g_free(accl);
+ accl = tmp;
}
- icc->account = acc;
+ icc->account = (struct 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);
+ g_strfreev(accounts);
+
+ return g_strdup(value);
+
+fail:
+ accl = new_acc;
+ while (accl) {
+ tmp = accl->next;
+ g_free(accl);
+ accl = tmp;
+ }
+
+ g_strfreev(accounts);
+
+ return SET_INVALID;
}
static char *set_eval_fill_by(set_t *set, char *value)
@@ -963,6 +1007,7 @@ fail:
gboolean irc_channel_wants_user(irc_channel_t *ic, irc_user_t *iu)
{
struct irc_control_channel *icc = ic->data;
+ struct acclist *accl;
gboolean ret = FALSE;
if (iu->bu == NULL) {
@@ -974,7 +1019,14 @@ 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;
+ accl = (struct acclist *)icc->account;
+ while (accl) {
+ if (iu->bu->ic->acc == accl->acc) {
+ ret = TRUE;
+ break;
+ }
+ accl = accl->next;
+ }
break;
case IRC_CC_TYPE_PROTOCOL:
ret = iu->bu->ic->acc->prpl == icc->protocol;
@@ -995,6 +1047,7 @@ gboolean irc_channel_wants_user(irc_channel_t *ic, irc_user_t *iu)
static gboolean control_channel_free(irc_channel_t *ic)
{
struct irc_control_channel *icc = ic->data;
+ struct acclist *accl, *tmp;
set_del(&ic->set, "account");
set_del(&ic->set, "fill_by");
@@ -1002,6 +1055,13 @@ static gboolean control_channel_free(irc_channel_t *ic)
set_del(&ic->set, "protocol");
set_del(&ic->set, "show_users");
+ accl = (struct acclist *)icc->account;
+ while (accl) {
+ tmp = accl->next;
+ g_free(accl);
+ accl = tmp;
+ }
+
g_free(icc);
ic->data = NULL;