From 018c620564fcd883d714cf9f790b5979015856b3 Mon Sep 17 00:00:00 2001 From: "Robert S. French" Date: Sat, 7 Nov 1987 19:22:50 +0000 Subject: Multiple packet support --- lib/ZRetSubs.c | 143 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 95 insertions(+), 48 deletions(-) (limited to 'lib/ZRetSubs.c') diff --git a/lib/ZRetSubs.c b/lib/ZRetSubs.c index ddfe713..7fac7a4 100644 --- a/lib/ZRetSubs.c +++ b/lib/ZRetSubs.c @@ -20,16 +20,20 @@ static char rcsid_ZRetrieveSubscriptions_c[] = "$Header$"; #include +#define MAXSUBPACKETS 200 /* If a person has more than 1000 + * subscriptions, he loses! */ + Code_t ZRetrieveSubscriptions(port,nsubs) u_short port; int *nsubs; { int subscription_pred(); - int i,retval; + int i,retval,nrecv,totalrecv,npacket,thispacket,returncode,gimmeack; ZNotice_t notice,retnotice; ZPacket_t buffer; char *ptr,*end,*ptr2; + char subs_recvd[MAXSUBPACKETS],asciiport[50]; retval = ZFlushSubscriptions(); @@ -37,72 +41,115 @@ Code_t ZRetrieveSubscriptions(port,nsubs) return (retval); notice.z_kind = ACKED; - notice.z_port = port; + notice.z_port = 0; 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 = 0; - notice.z_message_len = 0; - - if ((retval = ZSendNotice(¬ice,ZAUTH)) != ZERR_NONE) + 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 = ZIfNotice(buffer,sizeof buffer,&retnotice,NULL, - ZCompareUIDPred,(char *)¬ice.z_uid)) != - ZERR_NONE) + if ((retval = ZSendNotice(¬ice,ZAUTH)) != ZERR_NONE) return (retval); - if (retnotice.z_kind == SERVNAK) - return (ZERR_SERVNAK); + for (i=0;i MAXSUBPACKETS) { + returncode = ZERR_TOOMANYSUBS; + totalrecv = MAXSUBPACKETS; + } + thispacket = atoi(retnotice.z_opcode); + if (thispacket > MAXSUBPACKETS) + continue; + + if (subs_recvd[thispacket] == 'y') + continue; + subs_recvd[thispacket] = 'y'; + nrecv++; - __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; - ptr2 = ptr; - if (!*ptr2) - ptr2 = "*"; - __subscriptions_list[i].recipient = (char *) - malloc((unsigned)strlen(ptr2)+1); - if (!__subscriptions_list[i].recipient) + end = retnotice.z_message+retnotice.z_message_len; + + npacket = 0; + for (ptr=retnotice.z_message;ptr