From a323589383be38de2f76b564c5edc493bf7f9ec2 Mon Sep 17 00:00:00 2001 From: Jeffrey Hutzelman Date: Sat, 23 Feb 2013 15:00:54 -0500 Subject: zctl flush_subs Provide a new zctl subcommand, flush_subs, to flush all subscriptions for a specified recipient. This is implemented using a new library function, ZFlushUserSubscriptions(). This is the client side of #103 --- lib/ZSubs.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'lib') diff --git a/lib/ZSubs.c b/lib/ZSubs.c index 3a241db..5e05f20 100644 --- a/lib/ZSubs.c +++ b/lib/ZSubs.c @@ -205,3 +205,42 @@ subscr_sendoff(ZNotice_t *notice, ZFreeNotice(&retnotice); return (ZERR_NONE); } + +Code_t +ZFlushUserSubscriptions(char *recip) +{ + register Code_t retval; + ZNotice_t notice, retnotice; + + (void)memset((char *)¬ice, 0, sizeof(notice)); + notice.z_kind = ACKED; + notice.z_class = ZEPHYR_CTL_CLASS; + notice.z_class_inst = ZEPHYR_CTL_CLIENT; + notice.z_opcode = CLIENT_FLUSHSUBS; + notice.z_recipient = ""; + notice.z_default_format = ""; + if (recip) { + notice.z_message = recip; + notice.z_message_len = strlen(recip) + 1; + } else { + notice.z_message_len = 0; + } + + if ((retval = ZSendNotice(¬ice, ZAUTH)) != ZERR_NONE) + return (retval); + + if ((retval = ZIfNotice(&retnotice, (struct sockaddr_in *)0, + ZCompareUIDPred, (char *)¬ice.z_uid)) != + ZERR_NONE) + return (retval); + if (retnotice.z_kind == SERVNAK) { + ZFreeNotice(&retnotice); + return (ZERR_SERVNAK); + } + if (retnotice.z_kind != SERVACK) { + ZFreeNotice(&retnotice); + return (ZERR_INTERNAL); + } + ZFreeNotice(&retnotice); + return (ZERR_NONE); +} -- cgit v1.2.3