/* 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$ */ #ifndef lint static char rcsid_ZRetrieveSubscriptions_c[] = "$Header$"; #endif lint #include #include Code_t ZRetrieveSubscriptions(port,nsubs) u_short port; int *nsubs; { int subscription_pred(); int i,retval,nrecv,gimmeack; ZNotice_t notice,retnotice; ZPacket_t buffer; char *ptr,*end,*ptr2; char asciiport[50]; retval = ZFlushSubscriptions(); if (retval != ZERR_NONE && retval != ZERR_NOSUBSCRIPTIONS) return (retval); if (ZGetFD() < 0) if ((retval = ZOpenPort((u_short *)0)) != ZERR_NONE) return (retval); notice.z_kind = ACKED; notice.z_port = __Zephyr_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_default_format = ""; notice.z_num_other_fields = 0; notice.z_message = asciiport; if ((retval = ZMakeAscii(asciiport,sizeof(asciiport), (unsigned char *)&port, sizeof(u_short))) != ZERR_NONE) return (retval); notice.z_message_len = strlen(asciiport)+1; if ((retval = ZSendNotice(¬ice,ZAUTH)) != ZERR_NONE) return (retval); nrecv = 0; gimmeack = 0; __subscriptions_list = (ZSubscription_t *) 0; while (!nrecv || !gimmeack) { if ((retval = ZIfNotice(&retnotice,NULL, ZCompareMultiUIDPred, (char *)¬ice.z_multiuid)) != ZERR_NONE) return (retval); if (retnotice.z_kind == SERVNAK) { ZFreeNotice(&retnotice); return (ZERR_SERVNAK); } if (retnotice.z_kind == SERVACK && !strcmp(retnotice.z_opcode,CLIENT_GIMMESUBS)) { gimmeack = 1; continue; } if (retnotice.z_kind != ACKED) { ZFreeNotice(&retnotice); return (ZERR_INTERNAL); } nrecv++; end = retnotice.z_message+retnotice.z_message_len; __subscriptions_num = 0; for (ptr=retnotice.z_message;ptr