summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/ZFlsSubs.c39
-rw-r--r--lib/ZGetSubs.c42
-rw-r--r--lib/ZRetSubs.c100
3 files changed, 181 insertions, 0 deletions
diff --git a/lib/ZFlsSubs.c b/lib/ZFlsSubs.c
new file mode 100644
index 0000000..330a468
--- /dev/null
+++ b/lib/ZFlsSubs.c
@@ -0,0 +1,39 @@
+/* This file is part of the Project Athena Zephyr Notification System.
+ * It contains source for the ZFlushSubscriptions function.
+ *
+ * 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 ZFlushSubscriptions()
+{
+ int i;
+
+ if (!__subscriptions_list)
+ return (ZERR_NONE);
+
+ for (i=0;i<__subscriptions_num;i++) {
+ free(__subscriptions_list[i].class);
+ free(__subscriptions_list[i].classinst);
+ free(__subscriptions_list[i].recipient);
+ }
+
+ free((char *)__subscriptions_list);
+
+ __subscriptions_list = 0;
+ __subscriptions_num = 0;
+
+ return (ZERR_NONE);
+}
+
diff --git a/lib/ZGetSubs.c b/lib/ZGetSubs.c
new file mode 100644
index 0000000..002a473
--- /dev/null
+++ b/lib/ZGetSubs.c
@@ -0,0 +1,42 @@
+/* This file is part of the Project Athena Zephyr Notification System.
+ * It contains source for the ZGetSubscriptions function.
+ *
+ * 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>
+
+#define min(a,b) ((a)<(b)?(a):(b))
+
+Code_t ZGetSubscriptions(subscription,numsubs)
+ ZSubscription_t *subscription;
+ int *numsubs;
+{
+ int i;
+
+ if (!__subscriptions_list)
+ return (ZERR_NOSUBSCRIPTIONS);
+
+ if (__subscriptions_next == __subscriptions_num)
+ return (ZERR_NOMORESUBSCRIPTIONS);
+
+ for (i=0;i<min(*numsubs,__subscriptions_num-__subscriptions_next);i++)
+ subscription[i] = __subscriptions_list[i+__subscriptions_next];
+
+ if (__subscriptions_num-__subscriptions_next < *numsubs)
+ *numsubs = __subscriptions_num-__subscriptions_next;
+
+ __subscriptions_next += *numsubs;
+
+ return (ZERR_NONE);
+}
diff --git a/lib/ZRetSubs.c b/lib/ZRetSubs.c
new file mode 100644
index 0000000..9522eec
--- /dev/null
+++ b/lib/ZRetSubs.c
@@ -0,0 +1,100 @@
+/* This file is part of the Project Athena Zephyr Notification System.
+ * It contains source for the ZRetrieveSubscriptions function.
+ *
+ * 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 ZRetrieveSubscriptions(port,nsubs)
+ u_short port;
+ int *nsubs;
+{
+ int subscription_pred();
+
+ int i,retval;
+ ZNotice_t notice,retnotice;
+ ZPacket_t buffer;
+ char *ptr,*end;
+
+ retval = ZFlushSubscriptions();
+
+ if (retval != ZERR_NONE && retval != ZERR_NOSUBSCRIPTIONS)
+ return (retval);
+
+ notice.z_kind = ACKED;
+ notice.z_port = port;
+ notice.z_class = ZEPHYR_CTL_CLASS;
+ notice.z_class_inst = ZEPHYR_CTL_CLIENT;
+ notice.z_opcode = CLIENT_GIMMESUBS;
+ notice.z_sender = 0;
+ notice.z_recipient = "";
+ notice.z_message_len = 0;
+
+ if ((retval = ZSendNotice(&notice,ZAUTH)) != ZERR_NONE)
+ return (retval);
+
+ if ((retval = Z_NoAuthIfNotice(buffer,sizeof buffer,&retnotice,
+ ZCompareUIDPred,(char *)&notice.z_uid)) !=
+ ZERR_NONE)
+ return (retval);
+
+ if (retnotice.z_kind == SERVNAK)
+ return (ZERR_SERVNAK);
+
+ if (retnotice.z_kind != SERVACK)
+ return (ZERR_INTERNAL);
+
+ end = retnotice.z_message+retnotice.z_message_len;
+
+ __subscriptions_num = 0;
+
+ for (ptr=retnotice.z_message;ptr<end;ptr++)
+ if (!*ptr)
+ __subscriptions_num++;
+
+ __subscriptions_num /= 3;
+
+ __subscriptions_list = (ZSubscription_t *)malloc((unsigned)__subscriptions_num*
+ sizeof(ZSubscription_t));
+ if (!__subscriptions_list)
+ return (ENOMEM);
+
+ for (ptr=retnotice.z_message,i=0;i<__subscriptions_num;i++) {
+ __subscriptions_list[i].class = (char *)
+ malloc((unsigned)strlen(ptr)+1);
+ if (!__subscriptions_list[i].class)
+ return (ENOMEM);
+ (void) strcpy(__subscriptions_list[i].class,ptr);
+ ptr += strlen(ptr)+1;
+ __subscriptions_list[i].classinst = (char *)
+ malloc((unsigned)strlen(ptr)+1);
+ if (!__subscriptions_list[i].classinst)
+ return (ENOMEM);
+ (void) strcpy(__subscriptions_list[i].classinst,ptr);
+ ptr += strlen(ptr)+1;
+ __subscriptions_list[i].recipient = (char *)
+ malloc((unsigned)strlen(ptr)+1);
+ if (!__subscriptions_list[i].recipient)
+ return (ENOMEM);
+ (void) strcpy(__subscriptions_list[i].recipient,ptr);
+ ptr += strlen(ptr)+1;
+ }
+
+ __subscriptions_next = 0;
+ *nsubs = __subscriptions_num;
+
+ if (strcmp(retnotice.z_opcode,CLIENT_INCOMPSUBS))
+ return (ZERR_NONE);
+ return (ZERR_TOOMANYSUBS);
+}