diff options
author | Marius Halden <marius.h@lden.org> | 2015-11-06 20:46:36 +0100 |
---|---|---|
committer | Marius Halden <marius.h@lden.org> | 2016-05-07 14:26:16 +0200 |
commit | e5f97d0aa477be05c2d9b1a6514d51e52ac394dc (patch) | |
tree | b08fb33c54c35f93a8ed2772b24381fe6619da55 /irc_channel.c | |
parent | c7ffd289fe8db21f94ae1455ad780c83e3bf6f9d (diff) |
Add support for multiple accounts in set account
Diffstat (limited to 'irc_channel.c')
-rw-r--r-- | irc_channel.c | 70 |
1 files changed, 65 insertions, 5 deletions
diff --git a/irc_channel.c b/irc_channel.c index 8ea348f2..df8dc22e 100644 --- a/irc_channel.c +++ b/irc_channel.c @@ -861,22 +861,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) @@ -1000,6 +1044,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) { @@ -1011,7 +1056,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; @@ -1032,6 +1084,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"); @@ -1039,6 +1092,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; |