diff options
author | Robert S. French <rfrench@mit.edu> | 1987-07-05 22:09:03 +0000 |
---|---|---|
committer | Robert S. French <rfrench@mit.edu> | 1987-07-05 22:09:03 +0000 |
commit | 6d052aeba968f16100de9e59add743abcfb06094 (patch) | |
tree | 368c868683b79102cca00e89abbe29987573e639 /lib/ZSubs.c | |
parent | 63e063c0681783c90e604aa788dc4e9e52f0719b (diff) |
safety
Diffstat (limited to 'lib/ZSubs.c')
-rw-r--r-- | lib/ZSubs.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/lib/ZSubs.c b/lib/ZSubs.c new file mode 100644 index 0000000..7587f3a --- /dev/null +++ b/lib/ZSubs.c @@ -0,0 +1,92 @@ +/* This file is part of the Project Athena Zephyr Notification System. + * It contains source for the ZSubscribeTo, ZUnsubscribeTo, and + * ZCancelSubscriptions functions. + * + * Created by: Robert French + * + * $Source$ + * $Author$ + * + * Copyright (c) 1987 by the Massachusetts Institute of Technology. + * For copying and distribution information, see the file + * "mit-copyright.h". + */ +/* $Header$ */ + +#include <zephyr/mit-copyright.h> + +#include <zephyr/zephyr_internal.h> + +Code_t ZSubscribeTo(sublist,nitems,port) + ZSubscription_t *sublist; + int nitems; + u_short port; +{ + return (Z_Subscriptions(sublist,nitems,port,CLIENT_SUBSCRIBE)); +} + +Code_t ZUnsubscribeTo(sublist,nitems,port) + ZSubscription_t *sublist; + int nitems; + u_short port; +{ + return (Z_Subscriptions(sublist,nitems,port,CLIENT_UNSUBSCRIBE)); +} + +Code_t ZCancelSubscriptions(port) + u_short port; +{ + return (Z_Subscriptions((ZSubscription_t *)0,0,port, + CLIENT_CANCELSUB)); +} + +Z_Subscriptions(sublist,nitems,port,opcode) + ZSubscription_t *sublist; + int nitems; + u_short port; + char *opcode; +{ + int i,retval; + ZNotice_t notice,retnotice; + ZPacket_t buffer; + char **list; + + list = (char **)malloc((unsigned)nitems*3*sizeof(char *)); + if (!list) + return (ENOMEM); + + notice.z_kind = ACKED; + notice.z_port = port; + notice.z_class = ZEPHYR_CTL_CLASS; + notice.z_class_inst = ZEPHYR_CTL_CLIENT; + notice.z_opcode = opcode; + notice.z_sender = 0; + notice.z_recipient = ""; + notice.z_message_len = 0; + + for (i=0;i<nitems;i++) { + list[i*3] = sublist[i].class; + list[i*3+1] = sublist[i].classinst; + list[i*3+2] = sublist[i].recipient; + } + + retval = ZSendList(¬ice,list,nitems*3,ZAUTH); + + free((char *)list); + + if (retval != ZERR_NONE) + return (retval); + + if ((retval = ZIfNotice(buffer,sizeof buffer,&retnotice,(int *)0, + ZCompareUIDPred,(char *)¬ice.z_uid)) != + ZERR_NONE) + return (retval); + + if (retnotice.z_kind == SERVNAK) + return (ZERR_SERVNAK); + + if (retnotice.z_kind != SERVACK) + return (ZERR_INTERNAL); + + return (ZERR_NONE); +} |