summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Robert S. French <rfrench@mit.edu>1988-05-17 17:21:01 +0000
committerGravatar Robert S. French <rfrench@mit.edu>1988-05-17 17:21:01 +0000
commit031ec0f258f152c1e20905b381aa7f5974db1f3d (patch)
tree1c15619ec8a5192e2d5095c6efde5e9a47ddc7ce /lib
parent4d21b4b5da809cdf4499190a1e27bff679a90422 (diff)
All sorts of changes for ver 0.2
Diffstat (limited to 'lib')
-rw-r--r--lib/ZCkAuth.c79
-rw-r--r--lib/ZCkIfNot.c68
-rw-r--r--lib/ZCmpUID.c8
-rw-r--r--lib/ZCmpUIDP.c8
-rw-r--r--lib/ZFmtAuth.c62
-rw-r--r--lib/ZFmtList.c4
-rw-r--r--lib/ZFmtNotice.c8
-rw-r--r--lib/ZFmtRaw.c11
-rw-r--r--lib/ZFmtRawLst.c14
-rw-r--r--lib/ZFmtSmRaw.c43
-rw-r--r--lib/ZFreeNot.c27
-rw-r--r--lib/ZGetLocs.c28
-rw-r--r--lib/ZGetSubs.c28
-rw-r--r--lib/ZIfNotice.c83
-rw-r--r--lib/ZInit.c9
-rw-r--r--lib/ZLocateU.c130
-rw-r--r--lib/ZLocations.c173
-rw-r--r--lib/ZMakeAscii.c44
-rw-r--r--lib/ZMkAuth.c59
-rw-r--r--lib/ZOpenPort.c12
-rw-r--r--lib/ZParseNot.c39
-rw-r--r--lib/ZPeekIfNot.c84
-rw-r--r--lib/ZPeekNot.c22
-rw-r--r--lib/ZPeekPkt.c57
-rw-r--r--lib/ZReadAscii.c70
-rw-r--r--lib/ZRecvNot.c27
-rw-r--r--lib/ZRecvPkt.c61
-rw-r--r--lib/ZRetSubs.c2
-rw-r--r--lib/ZSendList.c38
-rw-r--r--lib/ZSendNot.c33
-rw-r--r--lib/ZSendPkt.c10
-rw-r--r--lib/ZSendRaw.c29
-rw-r--r--lib/ZSubs.c121
-rw-r--r--lib/ZVariables.c234
-rw-r--r--lib/Zinternal.c687
35 files changed, 1196 insertions, 1216 deletions
diff --git a/lib/ZCkAuth.c b/lib/ZCkAuth.c
index e376df3..6e9e04d 100644
--- a/lib/ZCkAuth.c
+++ b/lib/ZCkAuth.c
@@ -20,49 +20,52 @@ static char rcsid_ZCheckAuthentication_c[] = "$Header$";
#include <zephyr/zephyr_internal.h>
-int ZCheckAuthentication(notice,buffer,from)
- ZNotice_t *notice;
- ZPacket_t buffer;
- struct sockaddr_in *from;
+int ZCheckAuthentication(notice, from)
+ ZNotice_t *notice;
+ struct sockaddr_in *from;
{
- int result;
- char srcprincipal[ANAME_SZ+INST_SZ+REALM_SZ+4];
- KTEXT_ST authent;
- AUTH_DAT dat;
- ZChecksum_t our_checksum;
- CREDENTIALS cred;
+#ifdef KERBEROS
+ int result;
+ char srcprincipal[ANAME_SZ+INST_SZ+REALM_SZ+4];
+ KTEXT_ST authent;
+ AUTH_DAT dat;
+ ZChecksum_t our_checksum;
+ CREDENTIALS cred;
- if (!notice->z_auth)
- return (0);
+ if (!notice->z_auth)
+ return (0);
- if (__Zephyr_server) {
- if (ZReadAscii(notice->z_ascii_authent,
- strlen(notice->z_ascii_authent)+1,
- (unsigned char *)authent.dat,
- notice->z_authent_len) == ZERR_BADFIELD) {
- return (0);
- }
- authent.length = notice->z_authent_len;
- result = rd_ap_req(&authent,SERVER_SERVICE,
- SERVER_INSTANCE,from->sin_addr.s_addr,
- &dat,SERVER_SRVTAB);
- bcopy((char *)dat.session,(char *)__Zephyr_session,
- sizeof(C_Block));
- (void) sprintf(srcprincipal,"%s%s%s@%s",dat.pname,
- dat.pinst[0]?".":"",dat.pinst,dat.prealm);
- if (strcmp(srcprincipal,notice->z_sender))
- return (0);
- return (result == RD_AP_OK);
+ if (__Zephyr_server) {
+ if (ZReadAscii(notice->z_ascii_authent,
+ strlen(notice->z_ascii_authent)+1,
+ (unsigned char *)authent.dat,
+ notice->z_authent_len) == ZERR_BADFIELD) {
+ return (0);
}
+ authent.length = notice->z_authent_len;
+ result = krb_rd_req(&authent, SERVER_SERVICE,
+ SERVER_INSTANCE, from->sin_addr.s_addr,
+ &dat, SERVER_SRVTAB);
+ bcopy((char *)dat.session, (char *)__Zephyr_session,
+ sizeof(C_Block));
+ (void) sprintf(srcprincipal, "%s%s%s@%s", dat.pname,
+ dat.pinst[0]?".":"", dat.pinst, dat.prealm);
+ if (strcmp(srcprincipal, notice->z_sender))
+ return (0);
+ return (result == RD_AP_OK);
+ }
- if (result = get_credentials(SERVER_SERVICE,SERVER_INSTANCE,
- __Zephyr_realm,&cred))
- return (0);
+ if (result = krb_get_cred(SERVER_SERVICE, SERVER_INSTANCE,
+ __Zephyr_realm, &cred))
+ return (0);
- our_checksum = (ZChecksum_t)quad_cksum(buffer,NULL,
- notice->z_default_format+
- strlen(notice->z_default_format)+1-buffer,
- 0,cred.session);
+ our_checksum = (ZChecksum_t)quad_cksum(notice->z_packet, NULL,
+ notice->z_default_format+
+ strlen(notice->z_default_format)+1-
+ notice->z_packet, 0, cred.session);
- return (our_checksum == notice->z_checksum);
+ return (our_checksum == notice->z_checksum);
+#else
+ return (0);
+#endif
}
diff --git a/lib/ZCkIfNot.c b/lib/ZCkIfNot.c
index e584fed..96eaddd 100644
--- a/lib/ZCkIfNot.c
+++ b/lib/ZCkIfNot.c
@@ -20,43 +20,41 @@ static char rcsid_ZCheckIfNotice_c[] = "$Header$";
#include <zephyr/zephyr_internal.h>
-Code_t ZCheckIfNotice(buffer,buffer_len,notice,from,predicate,args)
- ZPacket_t buffer;
- int buffer_len;
- ZNotice_t *notice;
- struct sockaddr_in *from;
- int (*predicate)();
- char *args;
+Code_t ZCheckIfNotice(notice, from, predicate, args)
+ ZNotice_t *notice;
+ struct sockaddr_in *from;
+ int (*predicate)();
+ char *args;
{
- ZNotice_t tmpnotice;
- int qcount,retval;
- struct _Z_InputQ *qptr;
+ ZNotice_t tmpnotice;
+ Code_t retval;
+ char *buffer;
+ struct _Z_InputQ *qptr;
- if ((retval = Z_ReadEnqueue()) != ZERR_NONE)
- return (retval);
-
- qptr = __Q_Head;
- qcount = __Q_Length;
+ if ((retval = Z_ReadEnqueue()) != ZERR_NONE)
+ return (retval);
- for (;qcount;qcount--) {
- if ((retval = ZParseNotice(qptr->packet,qptr->packet_len,
- &tmpnotice))
- != ZERR_NONE)
- return (retval);
- if ((predicate)(&tmpnotice,args)) {
- if (qptr->packet_len > buffer_len)
- return (ZERR_PKTLEN);
- bcopy(qptr->packet,buffer,qptr->packet_len);
- if (from)
- *from = qptr->from;
- if ((retval = ZParseNotice(buffer,qptr->packet_len,
- notice))
- != ZERR_NONE)
- return (retval);
- return (Z_RemQueue(qptr));
- }
- qptr = qptr->next;
- }
+ qptr = (struct _Z_InputQ *)Z_GetFirstComplete();
+
+ while (qptr) {
+ if ((retval = ZParseNotice(qptr->packet, qptr->packet_len,
+ &tmpnotice)) != ZERR_NONE)
+ return (retval);
+ if ((predicate)(&tmpnotice, args)) {
+ if (!(buffer = malloc(qptr->packet_len)))
+ return (ENOMEM);
+ bcopy(qptr->packet, buffer, qptr->packet_len);
+ if (from)
+ *from = qptr->from;
+ if ((retval = ZParseNotice(buffer, qptr->packet_len,
+ notice)) != ZERR_NONE) {
+ free(buffer);
+ return (retval);
+ }
+ return (Z_RemQueue(qptr));
+ }
+ qptr = Z_GetNextComplete(qptr);
+ }
- return (ZERR_NONOTICE);
+ return (ZERR_NONOTICE);
}
diff --git a/lib/ZCmpUID.c b/lib/ZCmpUID.c
index adb14cf..0868cce 100644
--- a/lib/ZCmpUID.c
+++ b/lib/ZCmpUID.c
@@ -18,10 +18,10 @@ static char rcsid_ZCompareUID_c[] = "$Header$";
#include <zephyr/mit-copyright.h>
-#include <zephyr/zephyr.h>
+#include <zephyr/zephyr_internal.h>
-int ZCompareUID(uid1,uid2)
- ZUnique_Id_t *uid1,*uid2;
+int ZCompareUID(uid1, uid2)
+ ZUnique_Id_t *uid1, *uid2;
{
- return (!bcmp((char *)uid1,(char *)uid2,sizeof (*uid1)));
+ return (!bcmp((char *)uid1, (char *)uid2, sizeof (*uid1)));
}
diff --git a/lib/ZCmpUIDP.c b/lib/ZCmpUIDP.c
index b97ab10..0571bf0 100644
--- a/lib/ZCmpUIDP.c
+++ b/lib/ZCmpUIDP.c
@@ -20,9 +20,9 @@ static char rcsid_ZCompareUIDPred_c[] = "$Header$";
#include <zephyr/zephyr_internal.h>
-int ZCompareUIDPred(notice,uid)
- ZNotice_t *notice;
- ZUnique_Id_t *uid;
+int ZCompareUIDPred(notice, uid)
+ ZNotice_t *notice;
+ ZUnique_Id_t *uid;
{
- return (ZCompareUID(&notice->z_uid,uid));
+ return (ZCompareUID(&notice->z_uid, uid));
}
diff --git a/lib/ZFmtAuth.c b/lib/ZFmtAuth.c
index 16ab432..5d7f91c 100644
--- a/lib/ZFmtAuth.c
+++ b/lib/ZFmtAuth.c
@@ -20,47 +20,47 @@ static char rcsid_ZFormatAuthenticNotice_c[] = "$Header$";
#include <zephyr/zephyr_internal.h>
-Code_t ZFormatAuthenticNotice(notice,buffer,buffer_len,len,session)
- ZNotice_t *notice;
- ZPacket_t buffer;
- int buffer_len;
- int *len;
- C_Block session;
+Code_t ZFormatAuthenticNotice(notice, buffer, buffer_len, len, session)
+ ZNotice_t *notice;
+ char *buffer;
+ int buffer_len;
+ int *len;
+ C_Block session;
{
- ZNotice_t newnotice;
- char *ptr;
- int retval,hdrlen;
+ ZNotice_t newnotice;
+ char *ptr;
+ int retval, hdrlen;
- newnotice = *notice;
- newnotice.z_auth = 1;
- newnotice.z_authent_len = 0;
- newnotice.z_ascii_authent = (char *)"";
+ newnotice = *notice;
+ newnotice.z_auth = 1;
+ newnotice.z_authent_len = 0;
+ newnotice.z_ascii_authent = (char *)"";
- if ((retval = Z_FormatRawHeader(&newnotice,buffer,buffer_len,&hdrlen))
- != ZERR_NONE)
- return (retval);
+ if ((retval = Z_FormatRawHeader(&newnotice, buffer, buffer_len, &hdrlen))
+ != ZERR_NONE)
+ return (retval);
- for (hdrlen--;buffer[hdrlen-1];hdrlen--)
- ;
+ for (hdrlen--;buffer[hdrlen-1];hdrlen--)
+ ;
- newnotice.z_checksum = (ZChecksum_t)quad_cksum(buffer,NULL,hdrlen,0,
- session);
+ newnotice.z_checksum = (ZChecksum_t)quad_cksum(buffer, NULL, hdrlen, 0,
+ session);
- if ((retval = Z_FormatRawHeader(&newnotice,buffer,buffer_len,&hdrlen))
- != ZERR_NONE)
- return (retval);
+ if ((retval = Z_FormatRawHeader(&newnotice, buffer, buffer_len, &hdrlen))
+ != ZERR_NONE)
+ return (retval);
- ptr = buffer+hdrlen;
+ ptr = buffer+hdrlen;
- if (newnotice.z_message_len+hdrlen > buffer_len)
- return (ZERR_PKTLEN);
+ if (newnotice.z_message_len+hdrlen > buffer_len)
+ return (ZERR_PKTLEN);
- bcopy(newnotice.z_message,ptr,newnotice.z_message_len);
+ bcopy(newnotice.z_message, ptr, newnotice.z_message_len);
- *len = hdrlen+newnotice.z_message_len;
+ *len = hdrlen+newnotice.z_message_len;
- if (*len > Z_MAXPKTLEN)
- return (ZERR_PKTLEN);
+ if (*len > Z_MAXPKTLEN)
+ return (ZERR_PKTLEN);
- return (ZERR_NONE);
+ return (ZERR_NONE);
}
diff --git a/lib/ZFmtList.c b/lib/ZFmtList.c
index df22bc9..b2a733b 100644
--- a/lib/ZFmtList.c
+++ b/lib/ZFmtList.c
@@ -31,7 +31,7 @@ Code_t ZFormatNoticeList(notice, list, nitems, buffer, ret_len,
{
char header[Z_MAXHEADERLEN];
int hdrlen, i, size;
- char *ptr, *end;
+ char *ptr;
Code_t retval;
if ((retval = Z_FormatHeader(notice, header, sizeof(header), &hdrlen,
@@ -47,6 +47,8 @@ Code_t ZFormatNoticeList(notice, list, nitems, buffer, ret_len,
if (!(*buffer = malloc(*ret_len)))
return (ENOMEM);
+ bcopy(header, *buffer, hdrlen);
+
ptr = *buffer+hdrlen;
for (;nitems;nitems--, list++) {
diff --git a/lib/ZFmtNotice.c b/lib/ZFmtNotice.c
index f1f64e8..8aaab6a 100644
--- a/lib/ZFmtNotice.c
+++ b/lib/ZFmtNotice.c
@@ -18,7 +18,7 @@ static char rcsid_ZFormatNotice_c[] = "$Header$";
#include <zephyr/mit-copyright.h>
-#include <zephyr/zephyr.h>
+#include <zephyr/zephyr_internal.h>
Code_t ZFormatNotice(notice, buffer, ret_len, cert_routine)
ZNotice_t *notice;
@@ -27,7 +27,6 @@ Code_t ZFormatNotice(notice, buffer, ret_len, cert_routine)
int (*cert_routine)();
{
char header[Z_MAXHEADERLEN];
- char *ptr;
int hdrlen;
Code_t retval;
@@ -37,11 +36,10 @@ Code_t ZFormatNotice(notice, buffer, ret_len, cert_routine)
*ret_len = hdrlen+notice->z_message_len;
- if (!(*buffer = malloc(*ret_len)))
+ if (!(*buffer = (char *)malloc(*ret_len)))
return (ENOMEM);
- notice->z_packet = *buffer;
-
+ bcopy(header, *buffer, hdrlen);
bcopy(notice->z_message, *buffer+hdrlen, notice->z_message_len);
return (ZERR_NONE);
diff --git a/lib/ZFmtRaw.c b/lib/ZFmtRaw.c
index 28f5dff..03955b2 100644
--- a/lib/ZFmtRaw.c
+++ b/lib/ZFmtRaw.c
@@ -18,21 +18,19 @@ static char rcsid_ZFormatRawNotice_c[] = "$Header$";
#include <zephyr/mit-copyright.h>
-#include <zephyr/zephyr.h>
+#include <zephyr/zephyr_internal.h>
-Code_t ZFormatRawNotice(notice, buffer, ret_len, cert_routine)
+Code_t ZFormatRawNotice(notice, buffer, ret_len)
ZNotice_t *notice;
char **buffer;
int *ret_len;
- int (*cert_routine)();
{
char header[Z_MAXHEADERLEN];
- char *ptr;
int hdrlen;
Code_t retval;
- if ((retval = Z_FormatRawHeader(notice, header, sizeof(header), &hdrlen,
- cert_routine)) != ZERR_NONE)
+ if ((retval = Z_FormatRawHeader(notice, header, sizeof(header), &hdrlen))
+ != ZERR_NONE)
return (retval);
*ret_len = hdrlen+notice->z_message_len;
@@ -40,6 +38,7 @@ Code_t ZFormatRawNotice(notice, buffer, ret_len, cert_routine)
if (!(*buffer = malloc(*ret_len)))
return (ENOMEM);
+ bcopy(header, *buffer, hdrlen);
bcopy(notice->z_message, *buffer+hdrlen, notice->z_message_len);
return (ZERR_NONE);
diff --git a/lib/ZFmtRawLst.c b/lib/ZFmtRawLst.c
index bc47c1c..5015d77 100644
--- a/lib/ZFmtRawLst.c
+++ b/lib/ZFmtRawLst.c
@@ -18,24 +18,22 @@ static char rcsid_ZFormatRawNoticeList_c[] = "$Header$";
#include <zephyr/mit-copyright.h>
-#include <zephyr/zephyr.h>
+#include <zephyr/zephyr_internal.h>
-Code_t ZFormatRawNoticeList(notice, list, nitems, buffer, ret_len,
- cert_routine)
+Code_t ZFormatRawNoticeList(notice, list, nitems, buffer, ret_len)
ZNotice_t *notice;
char *list[];
int nitems;
char **buffer;
int *ret_len;
- int (*cert_routine)();
{
char header[Z_MAXHEADERLEN];
int hdrlen, i, size;
- char *ptr, *end;
+ char *ptr;
Code_t retval;
- if ((retval = Z_FormatRawHeader(notice, header, sizeof(header), &hdrlen,
- cert_routine)) != ZERR_NONE)
+ if ((retval = Z_FormatRawHeader(notice, header, sizeof(header), &hdrlen))
+ != ZERR_NONE)
return (retval);
size = 0;
@@ -47,6 +45,8 @@ Code_t ZFormatRawNoticeList(notice, list, nitems, buffer, ret_len,
if (!(*buffer = malloc(*ret_len)))
return (ENOMEM);
+ bcopy(header, *buffer, hdrlen);
+
ptr = *buffer+hdrlen;
for (;nitems;nitems--, list++) {
diff --git a/lib/ZFmtSmRaw.c b/lib/ZFmtSmRaw.c
new file mode 100644
index 0000000..781214a
--- /dev/null
+++ b/lib/ZFmtSmRaw.c
@@ -0,0 +1,43 @@
+/* This file is part of the Project Athena Zephyr Notification System.
+ * It contains source for the ZFormatSmallRawNotice 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_ZFormatRawNotice_c[] = "$Header$";
+#endif lint
+
+#include <zephyr/mit-copyright.h>
+
+#include <zephyr/zephyr_internal.h>
+
+Code_t ZFormatSmallRawNotice(notice, buffer, ret_len)
+ ZNotice_t *notice;
+ ZPacket_t buffer;
+ int *ret_len;
+{
+ Code_t retval;
+ int hdrlen;
+
+ if ((retval = Z_FormatRawHeader(notice, buffer, Z_MAXHEADERLEN, &hdrlen))
+ != ZERR_NONE)
+ return (retval);
+
+ *ret_len = hdrlen+notice->z_message_len;
+
+ if (*ret_len > Z_MAXPKTLEN)
+ return (ZERR_PKTLEN);
+
+ bcopy(notice->z_message, buffer+hdrlen, notice->z_message_len);
+
+ return (ZERR_NONE);
+}
diff --git a/lib/ZFreeNot.c b/lib/ZFreeNot.c
new file mode 100644
index 0000000..4d2e778
--- /dev/null
+++ b/lib/ZFreeNot.c
@@ -0,0 +1,27 @@
+/* This file is part of the Project Athena Zephyr Notification System.
+ * It contains source for the ZFreeNotice 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_ZSendPacket_c[] = "$Header$";
+#endif lint
+
+#include <zephyr/mit-copyright.h>
+
+#include <zephyr/zephyr_internal.h>
+
+Code_t ZFreeNotice(notice)
+ ZNotice_t *notice;
+{
+ free(notice->z_packet);
+}
diff --git a/lib/ZGetLocs.c b/lib/ZGetLocs.c
index ccd768e..6e795a2 100644
--- a/lib/ZGetLocs.c
+++ b/lib/ZGetLocs.c
@@ -22,25 +22,25 @@ static char rcsid_ZGetLocations_c[] = "$Header$";
#define min(a,b) ((a)<(b)?(a):(b))
-Code_t ZGetLocations(location,numlocs)
- ZLocations_t *location;
- int *numlocs;
+Code_t ZGetLocations(location, numlocs)
+ ZLocations_t *location;
+ int *numlocs;
{
- int i;
+ int i;
- if (!__locate_list)
- return (ZERR_NOLOCATIONS);
+ if (!__locate_list)
+ return (ZERR_NOLOCATIONS);
- if (__locate_next == __locate_num)
- return (ZERR_NOMORELOCS);
+ if (__locate_next == __locate_num)
+ return (ZERR_NOMORELOCS);
- for (i=0;i<min(*numlocs,__locate_num-__locate_next);i++)
- location[i] = __locate_list[i+__locate_next];
+ for (i=0;i<min(*numlocs, __locate_num-__locate_next);i++)
+ location[i] = __locate_list[i+__locate_next];
- if (__locate_num-__locate_next < *numlocs)
- *numlocs = __locate_num-__locate_next;
+ if (__locate_num-__locate_next < *numlocs)
+ *numlocs = __locate_num-__locate_next;
- __locate_next += *numlocs;
+ __locate_next += *numlocs;
- return (ZERR_NONE);
+ return (ZERR_NONE);
}
diff --git a/lib/ZGetSubs.c b/lib/ZGetSubs.c
index b3bc35d..6b75454 100644
--- a/lib/ZGetSubs.c
+++ b/lib/ZGetSubs.c
@@ -22,25 +22,25 @@ static char rcsid_ZGetSubscriptions_c[] = "$Header$";
#define min(a,b) ((a)<(b)?(a):(b))
-Code_t ZGetSubscriptions(subscription,numsubs)
- ZSubscription_t *subscription;
- int *numsubs;
+Code_t ZGetSubscriptions(subscription, numsubs)
+ ZSubscription_t *subscription;
+ int *numsubs;
{
- int i;
+ int i;
- if (!__subscriptions_list)
- return (ZERR_NOSUBSCRIPTIONS);
+ if (!__subscriptions_list)
+ return (ZERR_NOSUBSCRIPTIONS);
- if (__subscriptions_next == __subscriptions_num)
- return (ZERR_NOMORESUBSCRIPTIONS);
+ 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];
+ 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;
+ if (__subscriptions_num-__subscriptions_next < *numsubs)
+ *numsubs = __subscriptions_num-__subscriptions_next;
- __subscriptions_next += *numsubs;
+ __subscriptions_next += *numsubs;
- return (ZERR_NONE);
+ return (ZERR_NONE);
}
diff --git a/lib/ZIfNotice.c b/lib/ZIfNotice.c
index ef3cdc5..8c87aa4 100644
--- a/lib/ZIfNotice.c
+++ b/lib/ZIfNotice.c
@@ -20,53 +20,48 @@ static char rcsid_ZIfNotice_c[] = "$Header$";
#include <zephyr/zephyr_internal.h>
-Code_t ZIfNotice(buffer,buffer_len,notice,from,predicate,args)
- ZPacket_t buffer;
- int buffer_len;
- ZNotice_t *notice;
- struct sockaddr_in *from;
- int (*predicate)();
- char *args;
+Code_t ZIfNotice(notice, from, predicate, args)
+ ZNotice_t *notice;
+ struct sockaddr_in *from;
+ int (*predicate)();
+ char *args;
{
- ZNotice_t tmpnotice;
- int qcount,retval;
- struct _Z_InputQ *qptr;
+ ZNotice_t tmpnotice;
+ Code_t retval;
+ char *buffer;
+ struct _Z_InputQ *qptr;
- if (__Q_Length)
- retval = Z_ReadEnqueue();
- else
- retval = Z_ReadWait();
+ if (ZQLength())
+ retval = Z_ReadEnqueue();
+ else
+ retval = Z_ReadWait();
- if (retval != ZERR_NONE)
- return (retval);
+ if (retval != ZERR_NONE)
+ return (retval);
- qptr = __Q_Head;
- qcount = __Q_Length;
-
- for (;;qcount--) {
- if ((retval = ZParseNotice(qptr->packet,qptr->packet_len,
- &tmpnotice)) != ZERR_NONE)
- return (retval);
- if ((predicate)(&tmpnotice,args)) {
- if (qptr->packet_len > buffer_len)
- return (ZERR_PKTLEN);
- bcopy(qptr->packet,buffer,qptr->packet_len);
- if (from)
- *from = qptr->from;
- if ((retval = ZParseNotice(buffer,qptr->packet_len,
- notice))
- != ZERR_NONE)
- return (retval);
- return (Z_RemQueue(qptr));
- }
- /* Grunch! */
- if (qcount == 1) {
- if ((retval = Z_ReadWait()) != ZERR_NONE)
- return (retval);
- qcount++;
- qptr = __Q_Tail;
- }
- else
- qptr = qptr->next;
+ qptr = (struct _Z_InputQ *) Z_GetFirstComplete();
+
+ for (;;) {
+ while (qptr) {
+ if ((retval = ZParseNotice(qptr->packet, qptr->packet_len,
+ &tmpnotice)) != ZERR_NONE)
+ return (retval);
+ if ((predicate)(&tmpnotice, args)) {
+ if (!(buffer = malloc(qptr->packet_len)))
+ return (ENOMEM);
+ bcopy(qptr->packet, buffer, qptr->packet_len);
+ if (from)
+ *from = qptr->from;
+ if ((retval = ZParseNotice(buffer, qptr->packet_len,
+ notice)) != ZERR_NONE) {
+ free(buffer);
+ return (retval);
+ }
+ return (Z_RemQueue(qptr));
+ }
+ qptr = Z_GetNextComplete(qptr);
}
+ if ((retval = Z_ReadWait()) != ZERR_NONE)
+ return (retval);
+ }
}
diff --git a/lib/ZInit.c b/lib/ZInit.c
index b08fdc4..76dcdf4 100644
--- a/lib/ZInit.c
+++ b/lib/ZInit.c
@@ -27,8 +27,9 @@ Code_t ZInitialize()
{
struct servent *hmserv;
char addr[4];
- int retval;
-#ifndef KERBEROS
+#ifdef KERBEROS
+ int krbval;
+#else
char hostname[MAXHOSTNAMELEN+1];
struct hostent *hent;
#endif
@@ -59,8 +60,8 @@ Code_t ZInitialize()
__HM_set = 0;
#ifdef KERBEROS
- if ((retval = get_krbrlm(__Zephyr_realm, 1)) != KSUCCESS)
- return (retval);
+ if ((krbval = get_krbrlm(__Zephyr_realm, 1)) != KSUCCESS)
+ return (krbval);
#else
if (gethostname(hostname, MAXHOSTNAMELEN))
return (errno);
diff --git a/lib/ZLocateU.c b/lib/ZLocateU.c
index 59a119b..57af9a5 100644
--- a/lib/ZLocateU.c
+++ b/lib/ZLocateU.c
@@ -20,84 +20,86 @@ static char rcsid_ZLocateUser_c[] = "$Header$";
#include <zephyr/zephyr_internal.h>
-Code_t ZLocateUser(user,nlocs)
- char *user;
- int *nlocs;
+Code_t ZLocateUser(user, nlocs)
+ char *user;
+ int *nlocs;
{
- int locate_pred();
+ int i, retval;
+ ZNotice_t notice, retnotice;
+ char *ptr, *end;
- int i,retval;
- ZNotice_t notice,retnotice;
- ZPacket_t buffer;
- char *ptr,*end;
-
- retval = ZFlushLocations();
+ retval = ZFlushLocations();
- if (retval != ZERR_NONE && retval != ZERR_NOLOCATIONS)
- return (retval);
+ if (retval != ZERR_NONE && retval != ZERR_NOLOCATIONS)
+ return (retval);
- notice.z_kind = ACKED;
- notice.z_port = 0;
- notice.z_class = LOCATE_CLASS;
- notice.z_class_inst = user;
- notice.z_opcode = LOCATE_LOCATE;
- notice.z_sender = 0;
- notice.z_recipient = "";
- notice.z_default_format = "";
- notice.z_message_len = 0;
+ notice.z_kind = ACKED;
+ notice.z_port = 0;
+ notice.z_class = LOCATE_CLASS;
+ notice.z_class_inst = user;
+ notice.z_opcode = LOCATE_LOCATE;
+ notice.z_sender = 0;
+ notice.z_recipient = "";
+ notice.z_default_format = "";
+ notice.z_message_len = 0;
- if ((retval = ZSendNotice(&notice,ZAUTH)) != ZERR_NONE)
- return (retval);
+ if ((retval = ZSendNotice(&notice, ZAUTH)) != ZERR_NONE)
+ return (retval);
- if ((retval = ZIfNotice(buffer,sizeof buffer,&retnotice,NULL,
- ZCompareUIDPred,(char *)&notice.z_uid)) !=
- ZERR_NONE)
- return (retval);
+ if ((retval = ZIfNotice(&retnotice, NULL, ZCompareUIDPred,
+ (char *)&notice.z_uid)) != ZERR_NONE)
+ return (retval);
- if (retnotice.z_kind == SERVNAK)
- return (ZERR_SERVNAK);
+ if (retnotice.z_kind == SERVNAK) {
+ ZFreeNotice(&retnotice);
+ return (ZERR_SERVNAK);
+ }
- if (retnotice.z_kind != SERVACK)
- return (ZERR_INTERNAL);
+ if (retnotice.z_kind != SERVACK) {
+ ZFreeNotice(&retnotice);
+ return (ZERR_INTERNAL);
+ }
- end = retnotice.z_message+retnotice.z_message_len;
+ end = retnotice.z_message+retnotice.z_message_len;
- __locate_num = 0;
+ __locate_num = 0;
- for (ptr=retnotice.z_message;ptr<end;ptr++)
- if (!*ptr)
- __locate_num++;
+ for (ptr=retnotice.z_message;ptr<end;ptr++)
+ if (!*ptr)
+ __locate_num++;
- __locate_num /= 3;
+ __locate_num /= 3;
- __locate_list = (ZLocations_t *)malloc((unsigned)__locate_num*
- sizeof(ZLocations_t));
- if (!__locate_list)
- return (ENOMEM);
+ __locate_list = (ZLocations_t *)malloc((unsigned)__locate_num*
+ sizeof(ZLocations_t));
+ if (!__locate_list)
+ return (ENOMEM);
- for (ptr=retnotice.z_message,i=0;i<__locate_num;i++) {
- __locate_list[i].host = (char *)malloc((unsigned)strlen(ptr)+
- 1);
- if (!__locate_list[i].host)
- return (ENOMEM);
- (void) strcpy(__locate_list[i].host,ptr);
- ptr += strlen(ptr)+1;
- __locate_list[i].time = (char *)malloc((unsigned)strlen(ptr)+
- 1);
- if (!__locate_list[i].time)
- return (ENOMEM);
- (void) strcpy(__locate_list[i].time,ptr);
- ptr += strlen(ptr)+1;
- __locate_list[i].tty = (char *)malloc((unsigned)strlen(ptr)+
- 1);
- if (!__locate_list[i].tty)
- return (ENOMEM);
- (void) strcpy(__locate_list[i].tty,ptr);
- ptr += strlen(ptr)+1;
- }
+ for (ptr=retnotice.z_message, i=0;i<__locate_num;i++) {
+ __locate_list[i].host = (char *)malloc((unsigned)strlen(ptr)+
+ 1);
+ if (!__locate_list[i].host)
+ return (ENOMEM);
+ (void) strcpy(__locate_list[i].host, ptr);
+ ptr += strlen(ptr)+1;
+ __locate_list[i].time = (char *)malloc((unsigned)strlen(ptr)+
+ 1);
+ if (!__locate_list[i].time)
+ return (ENOMEM);
+ (void) strcpy(__locate_list[i].time, ptr);
+ ptr += strlen(ptr)+1;
+ __locate_list[i].tty = (char *)malloc((unsigned)strlen(ptr)+
+ 1);
+ if (!__locate_list[i].tty)
+ return (ENOMEM);
+ (void) strcpy(__locate_list[i].tty, ptr);
+ ptr += strlen(ptr)+1;
+ }
- __locate_next = 0;
- *nlocs = __locate_num;
+ ZFreeNotice(&retnotice);
+
+ __locate_next = 0;
+ *nlocs = __locate_num;
- return (ZERR_NONE);
+ return (ZERR_NONE);
}
diff --git a/lib/ZLocations.c b/lib/ZLocations.c
index 7baf4d3..ebb5081 100644
--- a/lib/ZLocations.c
+++ b/lib/ZLocations.c
@@ -29,97 +29,118 @@ static char rcsid_ZLocations_c[] = "$Header$";
uid_t getuid();
Code_t ZSetLocation(exposure)
- char *exposure;
+ char *exposure;
{
- return (Z_SendLocation(LOGIN_CLASS,exposure,ZAUTH,
- "$sender logged in to $1 on $3 at $2"));
+ return (Z_SendLocation(LOGIN_CLASS, exposure, ZAUTH,
+ "$sender logged in to $1 on $3 at $2"));
}
Code_t ZUnsetLocation()
{
- return (Z_SendLocation(LOGIN_CLASS,LOGIN_USER_LOGOUT,ZNOAUTH,
- "$sender logged out of $1 on $3 at $2"));
+ return (Z_SendLocation(LOGIN_CLASS, LOGIN_USER_LOGOUT, ZNOAUTH,
+ "$sender logged out of $1 on $3 at $2"));
}
Code_t ZFlushMyLocations()
{
- return (Z_SendLocation(LOGIN_CLASS,LOGIN_USER_FLUSH,ZAUTH,""));
+ return (Z_SendLocation(LOGIN_CLASS, LOGIN_USER_FLUSH, ZAUTH, ""));
}
-Z_SendLocation(class,opcode,auth,format)
- char *class;
- char *opcode;
- int (*auth)();
- char *format;
+Z_SendLocation(class, opcode, auth, format)
+ char *class;
+ char *opcode;
+ int (*auth)();
+ char *format;
{
- char *ttyname(),*ctime();
-
- int retval;
- long ourtime;
- ZNotice_t notice,retnotice;
- ZPacket_t buffer;
- char *bptr[3],host[MAXHOSTNAMELEN],mytty[100];
- struct hostent *hent;
-
- notice.z_kind = ACKED;
- notice.z_port = 0;
- notice.z_class = class;
- notice.z_class_inst = ZGetSender();
- notice.z_opcode = opcode;
- notice.z_sender = 0;
- notice.z_recipient = "";
- notice.z_default_format = format;
-
- if (gethostname(host,MAXHOSTNAMELEN) < 0)
- return (errno);
-
- hent = gethostbyname(host);
- if (!hent)
- bptr[0] = "unknown";
- else {
- (void) strcpy(host,hent->h_name);
- bptr[0] = host;
- }
-
- ourtime = time((long *)0);
- bptr[1] = ctime(&ourtime);
- bptr[1][strlen(bptr[1])-1] = '\0';
-
- (void) strcpy(mytty,ttyname(0));
- bptr[2] = rindex(mytty,'/');
+ char *ttyname(), *ctime();
+
+ int retval;
+ long ourtime;
+ ZNotice_t notice, retnotice;
+ char *bptr[3], host[MAXHOSTNAMELEN], mytty[MAXHOSTNAMELEN];
+ char *display;
+ struct hostent *hent;
+
+ notice.z_kind = ACKED;
+ notice.z_port = 0;
+ notice.z_class = class;
+ notice.z_class_inst = ZGetSender();
+ notice.z_opcode = opcode;
+ notice.z_sender = 0;
+ notice.z_recipient = "";
+ notice.z_num_other_fields = 0;
+ notice.z_default_format = format;
+
+ if (gethostname(host, MAXHOSTNAMELEN) < 0)
+ return (errno);
+
+ hent = gethostbyname(host);
+ if (!hent)
+ bptr[0] = "unknown";
+ else {
+ (void) strcpy(host, hent->h_name);
+ bptr[0] = host;
+ }
+
+ ourtime = time((long *)0);
+ bptr[1] = ctime(&ourtime);
+ bptr[1][strlen(bptr[1])-1] = '\0';
+
+ if ((display = (char *)getenv("DISPLAY")) && *display) {
+ strcpy(mytty, display);
+ bptr[2] = mytty;
+ }
+ else {
+ (void) strcpy(mytty, ttyname(0));
+ bptr[2] = rindex(mytty, '/');
if (bptr[2])
- bptr[2]++;
+ bptr[2]++;
else
- bptr[2] = mytty;
+ bptr[2] = mytty;
+ }
- if ((retval = ZSendList(&notice,bptr,3,auth)) != ZERR_NONE)
- return (retval);
-
- if ((retval = ZIfNotice(buffer,sizeof buffer,&retnotice,
- (struct sockaddr_in *)0,
- ZCompareUIDPred,(char *)&notice.z_uid)) !=
- ZERR_NONE)
- return (retval);
-
- if (retnotice.z_kind == SERVNAK) {
- if (!retnotice.z_message_len)
- return (ZERR_SERVNAK);
- if (!strcmp(retnotice.z_message,ZSRVACK_NOTSENT))
- return (ZERR_AUTHFAIL);
- if (!strcmp(retnotice.z_message,ZSRVACK_FAIL))
- return (ZERR_LOGINFAIL);
- return (ZERR_SERVNAK);
- }
+ if ((retval = ZSendList(&notice, bptr, 3, auth)) != ZERR_NONE)
+ return (retval);
+
+ if ((retval = ZIfNotice(&retnotice, (struct sockaddr_in *)0,
+ ZCompareUIDPred, (char *)&notice.z_uid)) !=
+ ZERR_NONE)
+ return (retval);
+
+ if (retnotice.z_kind == SERVNAK) {
+ if (!retnotice.z_message_len) {
+ ZFreeNotice(&retnotice);
+ return (ZERR_SERVNAK);
+ }
+ if (!strcmp(retnotice.z_message, ZSRVACK_NOTSENT)) {
+ ZFreeNotice(&retnotice);
+ return (ZERR_AUTHFAIL);
+ }
+ if (!strcmp(retnotice.z_message, ZSRVACK_FAIL)) {
+ ZFreeNotice(&retnotice);
+ return (ZERR_LOGINFAIL);
+ }
+ ZFreeNotice(&retnotice);
+ return (ZERR_SERVNAK);
+ }
- if (retnotice.z_kind != SERVACK)
- return (ZERR_INTERNAL);
-
- if (!retnotice.z_message_len)
- return (ZERR_INTERNAL);
-
- if (strcmp(retnotice.z_message,ZSRVACK_SENT) &&
- strcmp(retnotice.z_message,ZSRVACK_NOTSENT))
- return (ZERR_INTERNAL);
+ if (retnotice.z_kind != SERVACK) {
+ ZFreeNotice(&retnotice);
+ return (ZERR_INTERNAL);
+ }
+
+ if (!retnotice.z_message_len) {
+ ZFreeNotice(&retnotice);
+ return (ZERR_INTERNAL);
+ }
+
+ if (strcmp(retnotice.z_message, ZSRVACK_SENT) &&
+ strcmp(retnotice.z_message, ZSRVACK_NOTSENT)) {
+ ZFreeNotice(&retnotice);
+ return (ZERR_INTERNAL);
+ }
+
+ ZFreeNotice(&retnotice);
- return (ZERR_NONE);
+ return (ZERR_NONE);
}
diff --git a/lib/ZMakeAscii.c b/lib/ZMakeAscii.c
index a760b62..a5fcb68 100644
--- a/lib/ZMakeAscii.c
+++ b/lib/ZMakeAscii.c
@@ -1,5 +1,5 @@
/* This file is part of the Project Athena Zephyr Notification System.
- * It contains source for the internal Zephyr routines.
+ * It contains source for the ZMakeAscii function.
*
* Created by: Robert French
*
@@ -20,28 +20,28 @@ static char rcsid_ZMakeAscii_c[] = "$Header$";
#include <zephyr/zephyr_internal.h>
-Code_t ZMakeAscii(ptr,len,field,num)
- char *ptr;
- int len;
- unsigned char *field;
- int num;
+Code_t ZMakeAscii(ptr, len, field, num)
+ char *ptr;
+ int len;
+ unsigned char *field;
+ int num;
{
- int i;
+ int i;
- for (i=0;i<num;i++) {
- if (!(i%4)) {
- if (len < 3+(i!=0))
- return (ZERR_FIELDLEN);
- (void) sprintf(ptr,"%s0x",i?" ":"");
- ptr += 2+(i!=0);
- len -= 2+(i!=0);
- }
- if (len < 3)
- return (ZERR_FIELDLEN);
- (void) sprintf(ptr,"%02x",field[i]);
- ptr += 2;
- len -= 2;
- }
+ for (i=0;i<num;i++) {
+ if (!(i%4)) {
+ if (len < 3+(i!=0))
+ return (ZERR_FIELDLEN);
+ (void) sprintf(ptr, "%s0x", i?" ":"");
+ ptr += 2+(i!=0);
+ len -= 2+(i!=0);
+ }
+ if (len < 3)
+ return (ZERR_FIELDLEN);
+ (void) sprintf(ptr, "%02x", field[i]);
+ ptr += 2;
+ len -= 2;
+ }
- return (ZERR_NONE);
+ return (ZERR_NONE);
}
diff --git a/lib/ZMkAuth.c b/lib/ZMkAuth.c
index 136b37f..0b7901b 100644
--- a/lib/ZMkAuth.c
+++ b/lib/ZMkAuth.c
@@ -1,5 +1,5 @@
/* This file is part of the Project Athena Zephyr Notification System.
- * It contains source for the internal Zephyr routines.
+ * It contains source for the ZMakeAuthentication function.
*
* Created by: Robert French
*
@@ -20,34 +20,39 @@ static char rcsid_ZMakeAuthentication_c[] = "$Header$";
#include <zephyr/zephyr_internal.h>
-Code_t ZMakeAuthentication(notice,buffer,buffer_len,len)
- ZNotice_t *notice;
- ZPacket_t buffer;
- int buffer_len;
- int *len;
+Code_t ZMakeAuthentication(notice, buffer, buffer_len, len)
+ ZNotice_t *notice;
+ char *buffer;
+ int buffer_len;
+ int *len;
{
- int retval,result;
- KTEXT_ST authent;
+#ifdef KERBEROS
+ int retval, result;
+ KTEXT_ST authent;
- notice->z_auth = 1;
- if ((result = mk_ap_req(&authent,SERVER_SERVICE,
- SERVER_INSTANCE,__Zephyr_realm,0))
- != MK_AP_OK)
- return (result+krb_err_base);
- notice->z_authent_len = authent.length;
- notice->z_ascii_authent = (char *)malloc((unsigned)authent.length*3);
- if (!notice->z_ascii_authent)
- return (ENOMEM);
- if ((retval = ZMakeAscii(notice->z_ascii_authent,
- authent.length*3,
- authent.dat,
- authent.length)) != ZERR_NONE) {
- free(notice->z_ascii_authent);
- return (retval);
- }
- retval = Z_FormatRawHeader(notice,buffer,buffer_len,len);
+ notice->z_auth = 1;
+ if ((result = krb_mk_req(&authent, SERVER_SERVICE,
+ SERVER_INSTANCE, __Zephyr_realm, 0))
+ != MK_AP_OK)
+ return (result+krb_err_base);
+ notice->z_authent_len = authent.length;
+ notice->z_ascii_authent = (char *)malloc((unsigned)authent.length*3);
+ if (!notice->z_ascii_authent)
+ return (ENOMEM);
+ if ((retval = ZMakeAscii(notice->z_ascii_authent,
+ authent.length*3,
+ authent.dat,
+ authent.length)) != ZERR_NONE) {
free(notice->z_ascii_authent);
- notice->z_authent_len = 0;
-
return (retval);
+ }
+ retval = Z_FormatRawHeader(notice, buffer, buffer_len, len);
+ free(notice->z_ascii_authent);
+ notice->z_authent_len = 0;
+
+ return (retval);
+#else
+ notice->z_authent_len = 0;
+ return (Z_FormatRawHeader(notice, buffer, buffer_len, len));
+#endif
}
diff --git a/lib/ZOpenPort.c b/lib/ZOpenPort.c
index 3cc2bd3..54e0ae8 100644
--- a/lib/ZOpenPort.c
+++ b/lib/ZOpenPort.c
@@ -24,9 +24,9 @@ static char rcsid_ZOpenPort_c[] = "$Header$";
Code_t ZOpenPort(port)
u_short *port;
{
- int retval;
struct sockaddr_in bindin;
-
+ int len;
+
(void) ZClosePort();
if ((__Zephyr_fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
@@ -43,16 +43,18 @@ Code_t ZOpenPort(port)
bindin.sin_addr.s_addr = INADDR_ANY;
- if ((retval = bind(__Zephyr_fd, &bindin, sizeof(bindin))) < 0) {
+ if (bind(__Zephyr_fd, &bindin, sizeof(bindin)) < 0) {
if (errno == EADDRINUSE && port && *port)
return (ZERR_PORTINUSE);
else
return (errno);
}
- if (!bindin.sin_port)
- if (getsockname(__Zephyr_fd, &bindin, sizeof(bindin)))
+ if (!bindin.sin_port) {
+ len = sizeof(bindin);
+ if (getsockname(__Zephyr_fd, &bindin, &len))
return (errno);
+ }
__Zephyr_port = bindin.sin_port;
__Zephyr_open = 1;
diff --git a/lib/ZParseNot.c b/lib/ZParseNot.c
index 96cb4e0..54d3060 100644
--- a/lib/ZParseNot.c
+++ b/lib/ZParseNot.c
@@ -38,7 +38,7 @@ Code_t ZParseNotice(buffer, len, notice)
notice->z_version = ptr;
if (strncmp(ptr, ZVERSIONHDR, strlen(ZVERSIONHDR)))
- return (ZERR_VERS);
+/* return (ZERR_VERS);*/ abort();
ptr += strlen(ZVERSIONHDR);
maj = atoi(ptr);
if (maj != ZVERSIONMAJOR)
@@ -51,15 +51,16 @@ Code_t ZParseNotice(buffer, len, notice)
numfields = ntohl(*temp);
ptr += strlen(ptr)+1;
- numfields -= 2;
+ /*XXX 3 */
+ numfields -= 2; /* numfields, version, and checksum */
if (numfields < 0)
- numfields = 0;
+ return (ZERR_BADPKT);
if (numfields) {
if (ZReadAscii(ptr, end-ptr, (unsigned char *)temp,
sizeof(int)) == ZERR_BADFIELD)
return (ZERR_BADPKT);
- notice->z_kind = (ZNotice_Kind_t)ntohl((ZNotice_Kind_t)*temp);
+ notice->z_kind = (ZNotice_Kind_t)ntohl(*temp);
numfields--;
ptr += strlen(ptr)+1;
}
@@ -169,17 +170,14 @@ Code_t ZParseNotice(buffer, len, notice)
else
notice->z_default_format = "";
- if (numfields) {
- if (ZReadAscii(ptr, end-ptr, (unsigned char *)temp,
- sizeof(ZChecksum_t))
- == ZERR_BADFIELD)
- return (ZERR_BADPKT);
- notice->z_checksum = ntohl(*temp);
- numfields--;
- ptr += strlen(ptr)+1;
- }
- else
- notice->z_checksum = 0;
+/*XXX*/
+ if (ZReadAscii(ptr, end-ptr, (unsigned char *)temp,
+ sizeof(ZChecksum_t))
+ == ZERR_BADFIELD)
+ return (ZERR_BADPKT);
+ notice->z_checksum = ntohl(*temp);
+ numfields--;
+ ptr += strlen(ptr)+1;
if (numfields) {
notice->z_multinotice = ptr;
@@ -191,6 +189,7 @@ Code_t ZParseNotice(buffer, len, notice)
for (i=0;i<Z_MAXOTHERFIELDS && numfields;i++,numfields--) {
notice->z_other_fields[i] = ptr;
+ numfields--;
ptr += strlen(ptr)+1;
}
notice->z_num_other_fields = i;
@@ -198,6 +197,16 @@ Code_t ZParseNotice(buffer, len, notice)
for (i=0;i<numfields;i++)
ptr += strlen(ptr)+1;
+#ifdef notdef
+ if (ZReadAscii(ptr, end-ptr, (unsigned char *)temp,
+ sizeof(ZChecksum_t))
+ == ZERR_BADFIELD)
+ return (ZERR_BADPKT);
+ notice->z_checksum = ntohl(*temp);
+ numfields--;
+ ptr += strlen(ptr)+1;
+#endif
+
notice->z_message = (caddr_t) ptr;
notice->z_message_len = len-(ptr-buffer);
diff --git a/lib/ZPeekIfNot.c b/lib/ZPeekIfNot.c
index b376002..fab3c2b 100644
--- a/lib/ZPeekIfNot.c
+++ b/lib/ZPeekIfNot.c
@@ -20,54 +20,48 @@ static char rcsid_ZPeekIfNotice_c[] = "$Header$";
#include <zephyr/zephyr_internal.h>
-Code_t ZPeekIfNotice(buffer,buffer_len,notice,from,predicate,args)
- ZPacket_t buffer;
- int buffer_len;
- ZNotice_t *notice;
- struct sockaddr_in *from;
- int (*predicate)();
- char *args;
+Code_t ZPeekIfNotice(notice, from, predicate, args)
+ ZNotice_t *notice;
+ struct sockaddr_in *from;
+ int (*predicate)();
+ char *args;
{
- ZNotice_t tmpnotice;
- int qcount,retval;
- struct _Z_InputQ *qptr;
+ ZNotice_t tmpnotice;
+ Code_t retval;
+ char *buffer;
+ struct _Z_InputQ *qptr;
- if (__Q_Length)
- retval = Z_ReadEnqueue();
- else
- retval = Z_ReadWait();
+ if (ZQLength())
+ retval = Z_ReadEnqueue();
+ else
+ retval = Z_ReadWait();
- if (retval != ZERR_NONE)
- return (retval);
+ if (retval != ZERR_NONE)
+ return (retval);
- qptr = __Q_Head;
- qcount = __Q_Length;
-
- for (;;qcount--) {
- if ((retval = ZParseNotice(qptr->packet,qptr->packet_len,
- &tmpnotice))
- != ZERR_NONE)
- return (retval);
- if ((predicate)(&tmpnotice,args)) {
- if (qptr->packet_len > buffer_len)
- return (ZERR_PKTLEN);
- bcopy(qptr->packet,buffer,qptr->packet_len);
- if (from)
- *from = qptr->from;
- if ((retval = ZParseNotice(buffer,qptr->packet_len,
- notice))
- != ZERR_NONE)
- return (retval);
- return (ZERR_NONE);
- }
- /* Grunch! */
- if (qcount == 1) {
- if ((retval = Z_ReadWait()) != ZERR_NONE)
- return (retval);
- qcount++;
- qptr = __Q_Tail;
- }
- else
- qptr = qptr->next;
+ qptr = (struct _Z_InputQ *) Z_GetFirstComplete();
+
+ for (;;) {
+ while (qptr) {
+ if ((retval = ZParseNotice(qptr->packet, qptr->packet_len,
+ &tmpnotice)) != ZERR_NONE)
+ return (retval);
+ if ((predicate)(&tmpnotice, args)) {
+ if (!(buffer = malloc(qptr->packet_len)))
+ return (ENOMEM);
+ bcopy(qptr->packet, buffer, qptr->packet_len);
+ if (from)
+ *from = qptr->from;
+ if ((retval = ZParseNotice(buffer, qptr->packet_len,
+ notice)) != ZERR_NONE) {
+ free(buffer);
+ return (retval);
+ }
+ return (ZERR_NONE);
+ }
+ qptr = Z_GetNextComplete(qptr);
}
+ if ((retval = Z_ReadWait()) != ZERR_NONE)
+ return (retval);
+ }
}
diff --git a/lib/ZPeekNot.c b/lib/ZPeekNot.c
index c2debad..8e6f857 100644
--- a/lib/ZPeekNot.c
+++ b/lib/ZPeekNot.c
@@ -20,18 +20,16 @@ static char rcsid_ZPeekNotice_c[] = "$Header$";
#include <zephyr/zephyr_internal.h>
-Code_t ZPeekNotice(buffer,buffer_len,notice,from)
- ZPacket_t buffer;
- int buffer_len;
- ZNotice_t *notice;
- struct sockaddr_in *from;
+Code_t ZPeekNotice(notice, from)
+ ZNotice_t *notice;
+ struct sockaddr_in *from;
{
- int len;
- Code_t retval;
+ char *buffer;
+ int len;
+ Code_t retval;
+
+ if ((retval = ZPeekPacket(&buffer, &len, from)) != ZERR_NONE)
+ return (retval);
- if ((retval = ZPeekPacket(buffer,buffer_len,&len,from)) !=
- ZERR_NONE)
- return (retval);
-
- return (ZParseNotice(buffer,len,notice));
+ return (ZParseNotice(buffer, len, notice));
}
diff --git a/lib/ZPeekPkt.c b/lib/ZPeekPkt.c
index 57790f9..25acfe1 100644
--- a/lib/ZPeekPkt.c
+++ b/lib/ZPeekPkt.c
@@ -20,32 +20,37 @@ static char rcsid_ZPeekPacket_c[] = "$Header$";
#include <zephyr/zephyr_internal.h>
-Code_t ZPeekPacket(buffer,buffer_len,ret_len,from)
- ZPacket_t buffer;
- int buffer_len;
- int *ret_len;
- struct sockaddr_in *from;
+Code_t ZPeekPacket(buffer, ret_len, from)
+ char **buffer;
+ int *ret_len;
+ struct sockaddr_in *from;
{
- int retval;
-
- if (ZGetFD() < 0)
- return (ZERR_NOPORT);
-
- if (!ZQLength())
- if ((retval = Z_ReadWait()) != ZERR_NONE)
- return (retval);
-
- if (buffer_len < __Q_Head->packet_len) {
- *ret_len = buffer_len;
- retval = ZERR_PKTLEN;
- }
- else {
- *ret_len = __Q_Head->packet_len;
- retval = ZERR_NONE;
- }
-
- bcopy(__Q_Head->packet,buffer,*ret_len);
- bcopy((char *)&__Q_Head->from,(char *)from,sizeof(struct sockaddr_in));
+ int retval;
+ struct _Z_InputQ *nextq;
+
+ if (ZGetFD() < 0)
+ return (ZERR_NOPORT);
+
+ if (ZQLength()) {
+ if ((retval = Z_ReadEnqueue()) != ZERR_NONE)
+ return (retval);
+ }
+ else {
+ if ((retval = Z_ReadWait()) != ZERR_NONE)
+ return (retval);
+ }
+
+ nextq = Z_GetFirstComplete();
+
+ *ret_len = nextq->packet_len;
+
+ if (!(*buffer = malloc(*ret_len)))
+ return (ENOMEM);
+
+ bcopy(nextq->packet, *buffer, *ret_len);
+
+ if (from)
+ *from = nextq->from;
- return (retval);
+ return (ZERR_NONE);
}
diff --git a/lib/ZReadAscii.c b/lib/ZReadAscii.c
index adebb94..d20db26 100644
--- a/lib/ZReadAscii.c
+++ b/lib/ZReadAscii.c
@@ -20,43 +20,43 @@ static char rcsid_ZReadAscii_c[] = "$Header$";
#include <zephyr/zephyr_internal.h>
-int ZReadAscii(ptr,len,field,num)
- char *ptr;
- int len;
- unsigned char *field;
- int num;
+int ZReadAscii(ptr, len, field, num)
+ char *ptr;
+ int len;
+ unsigned char *field;
+ int num;
{
- int i;
- unsigned int hexbyte;
- char bfr[3];
+ int i;
+ unsigned int hexbyte;
+ char bfr[3];
- for (i=0;i<num;i++) {
- if (*ptr == ' ') {
- ptr++;
- if (--len < 0)
- return (ZERR_BADFIELD);
- }
- if (ptr[0] == '0' && ptr[1] == 'x') {
- ptr += 2;
- len -= 2;
- if (len < 0)
- return (ZERR_BADFIELD);
- }
- bfr[0] = ptr[0];
- bfr[1] = ptr[1];
- bfr[2] = '\0';
- if (!bfr[0] || !bfr[1])
- return (ZERR_BADFIELD);
- (void) sscanf(bfr,"%x",&hexbyte);
- field[i] = hexbyte;
- ptr += 2;
- len -= 2;
- if (len < 0)
- return (ZERR_BADFIELD);
- }
-
- if (*ptr)
+ for (i=0;i<num;i++) {
+ if (*ptr == ' ') {
+ ptr++;
+ if (--len < 0)
+ return (ZERR_BADFIELD);
+ }
+ if (ptr[0] == '0' && ptr[1] == 'x') {
+ ptr += 2;
+ len -= 2;
+ if (len < 0)
return (ZERR_BADFIELD);
+ }
+ bfr[0] = ptr[0];
+ bfr[1] = ptr[1];
+ bfr[2] = '\0';
+ if (!bfr[0] || !bfr[1])
+ return (ZERR_BADFIELD);
+ (void) sscanf(bfr, "%x", &hexbyte);
+ field[i] = hexbyte;
+ ptr += 2;
+ len -= 2;
+ if (len < 0)
+ return (ZERR_BADFIELD);
+ }
+
+ if (*ptr)
+ return (ZERR_BADFIELD);
- return (ZERR_NONE);
+ return (ZERR_NONE);
}
diff --git a/lib/ZRecvNot.c b/lib/ZRecvNot.c
index d12a0f7..0ebe3cc 100644
--- a/lib/ZRecvNot.c
+++ b/lib/ZRecvNot.c
@@ -20,18 +20,21 @@ static char rcsid_ZReceiveNotice_c[] = "$Header$";
#include <zephyr/zephyr_internal.h>
-Code_t ZReceiveNotice(buffer,buffer_len,notice,from)
- ZPacket_t buffer;
- int buffer_len;
- ZNotice_t *notice;
- struct sockaddr_in *from;
+Code_t ZReceiveNotice(notice, from)
+ ZNotice_t *notice;
+ struct sockaddr_in *from;
{
- int len;
- Code_t retval;
-
- if ((retval = ZReceivePacket(buffer,buffer_len,&len,from)) !=
- ZERR_NONE)
- return (retval);
+ char *buffer;
+ int len;
+ Code_t retval;
- return (ZParseNotice(buffer,len,notice));
+ if (!(buffer = malloc(Z_MAXPKTLEN)))
+ return (ENOMEM);
+
+ if ((retval = ZReceivePacket(buffer, &len, from)) != ZERR_NONE)
+ return (retval);
+
+ buffer = realloc(buffer, len); /* XXX */
+
+ return (ZParseNotice(buffer, len, notice));
}
diff --git a/lib/ZRecvPkt.c b/lib/ZRecvPkt.c
index 611a3ea..33a48c0 100644
--- a/lib/ZRecvPkt.c
+++ b/lib/ZRecvPkt.c
@@ -20,39 +20,36 @@ static char rcsid_ZReceivePacket_c[] = "$Header$";
#include <zephyr/zephyr_internal.h>
-#define min(a,b) ((a)<(b)?(a):(b))
-
-Code_t ZReceivePacket(buffer,buffer_len,ret_len,from)
- ZPacket_t buffer;
- int buffer_len;
- int *ret_len;
- struct sockaddr_in *from;
+Code_t ZReceivePacket(buffer, ret_len, from)
+ ZPacket_t buffer;
+ int *ret_len;
+ struct sockaddr_in *from;
{
- int retval;
-
- if (ZGetFD() < 0)
- return (ZERR_NOPORT);
-
- if (!ZQLength())
- if ((retval = Z_ReadWait()) != ZERR_NONE)
- return (retval);
-
- if (buffer_len < __Q_Head->packet_len) {
- *ret_len = buffer_len;
- retval = ZERR_PKTLEN;
- }
- else {
- *ret_len = __Q_Head->packet_len;
- retval = ZERR_NONE;
- }
-
- if (ret_len)
- bcopy(__Q_Head->packet,buffer,*ret_len);
- if (from)
- bcopy((char *)&__Q_Head->from,(char *)from,
- sizeof(struct sockaddr_in));
+ int retval;
+ struct _Z_InputQ *nextq;
+
+ if (ZGetFD() < 0)
+ return (ZERR_NOPORT);
+
+ if (ZQLength()) {
+ if ((retval = Z_ReadEnqueue()) != ZERR_NONE)
+ return (retval);
+ }
+ else {
+ if ((retval = Z_ReadWait()) != ZERR_NONE)
+ return (retval);
+ }
+
+ nextq = (struct _Z_InputQ *) Z_GetFirstComplete();
+
+ *ret_len = nextq->packet_len;
+
+ bcopy(nextq->packet, buffer, *ret_len);
+
+ if (from)
+ *from = nextq->from;
- (void) Z_RemQueue(__Q_Head);
+ (void) Z_RemQueue(nextq);
- return (retval);
+ return (ZERR_NONE);
}
diff --git a/lib/ZRetSubs.c b/lib/ZRetSubs.c
index 7fac7a4..7ef9a74 100644
--- a/lib/ZRetSubs.c
+++ b/lib/ZRetSubs.c
@@ -23,6 +23,7 @@ static char rcsid_ZRetrieveSubscriptions_c[] = "$Header$";
#define MAXSUBPACKETS 200 /* If a person has more than 1000
* subscriptions, he loses! */
+#ifdef notdef
Code_t ZRetrieveSubscriptions(port,nsubs)
u_short port;
int *nsubs;
@@ -153,3 +154,4 @@ Code_t ZRetrieveSubscriptions(port,nsubs)
return (returncode);
}
+#endif
diff --git a/lib/ZSendList.c b/lib/ZSendList.c
index 5aeb2ba..3b6fea3 100644
--- a/lib/ZSendList.c
+++ b/lib/ZSendList.c
@@ -20,29 +20,27 @@ static char rcsid_ZSendList_c[] = "$Header$";
#include <zephyr/zephyr_internal.h>
-Code_t ZSendList(notice,list,nitems,cert_routine)
- ZNotice_t *notice;
- char *list[];
- int nitems;
- int (*cert_routine)();
+Code_t ZSendList(notice, list, nitems, cert_routine)
+ ZNotice_t *notice;
+ char *list[];
+ int nitems;
+ int (*cert_routine)();
{
- Code_t retval;
- char *buffer;
- int len;
+ Code_t retval;
+ ZNotice_t newnotice;
+ char *buffer;
+ int len;
- buffer = (char *)malloc(Z_MAXPKTLEN);
- if (!buffer)
- return (ENOMEM);
+ if ((retval = ZFormatNoticeList(notice, list, nitems, &buffer,
+ &len, cert_routine)) != ZERR_NONE)
+ return (retval);
- if ((retval = ZFormatNoticeList(notice,list,nitems,buffer,
- Z_MAXPKTLEN,&len,cert_routine))
- != ZERR_NONE) {
- free(buffer);
- return (retval);
- }
+ if ((retval = ZParseNotice(buffer, len, &newnotice)) != ZERR_NONE)
+ return (retval);
+
+ retval = Z_SendFragmentedNotice(&newnotice, len);
- retval = ZSendPacket(buffer,len);
- free(buffer);
+ free(buffer);
- return (retval);
+ return (retval);
}
diff --git a/lib/ZSendNot.c b/lib/ZSendNot.c
index 9a004a9..8147982 100644
--- a/lib/ZSendNot.c
+++ b/lib/ZSendNot.c
@@ -20,26 +20,25 @@ static char rcsid_ZSendNotice_c[] = "$Header$";
#include <zephyr/zephyr_internal.h>
-Code_t ZSendNotice(notice,cert_routine)
- ZNotice_t *notice;
- int (*cert_routine)();
+Code_t ZSendNotice(notice, cert_routine)
+ ZNotice_t *notice;
+ int (*cert_routine)();
{
- Code_t retval;
- char *buffer;
- int len;
+ Code_t retval;
+ ZNotice_t newnotice;
+ char *buffer;
+ int len;
- buffer = (char *)malloc(Z_MAXPKTLEN);
- if (!buffer)
- return (ENOMEM);
+ if ((retval = ZFormatNotice(notice, &buffer, &len,
+ cert_routine)) != ZERR_NONE)
+ return (retval);
- if ((retval = ZFormatNotice(notice,buffer,Z_MAXPKTLEN,&len,
- cert_routine)) != ZERR_NONE) {
- free(buffer);
- return (retval);
- }
+ if ((retval = ZParseNotice(buffer, len, &newnotice)) != ZERR_NONE)
+ return (retval);
+
+ retval = Z_SendFragmentedNotice(&newnotice, len);
- retval = ZSendPacket(buffer,len);
- free(buffer);
+ free(buffer);
- return (retval);
+ return (retval);
}
diff --git a/lib/ZSendPkt.c b/lib/ZSendPkt.c
index 9228803..0eff764 100644
--- a/lib/ZSendPkt.c
+++ b/lib/ZSendPkt.c
@@ -31,12 +31,14 @@ Code_t ZSendPacket(packet, len, waitforack)
struct timeval tv;
int i;
fd_set t1, t2, t3;
- char *ackpacket;
ZNotice_t notice, acknotice;
- if (!packet || len < 0 || len > Z_MAXPKTLEN)
+ if (!packet || len < 0)
return (ZERR_ILLVAL);
+ if (len > Z_MAXPKTLEN)
+ return (ZERR_PKTLEN);
+
if (ZGetFD() < 0)
if ((retval = ZOpenPort((u_short *)0)) != ZERR_NONE)
return (retval);
@@ -58,8 +60,8 @@ Code_t ZSendPacket(packet, len, waitforack)
for (i=0;i<HM_TIMEOUT*2;i++) {
if (select(0, &t1, &t2, &t3, &tv) < 0)
return (errno);
- retval = ZCheckIfNotice(&acknotice, NULL, ZCompareUIDPred,
- (char *)&notice.z_uid);
+ retval = ZCheckIfNotice(&acknotice, (struct sockaddr_in *)0,
+ ZCompareUIDPred, (char *)&notice.z_uid);
if (retval == ZERR_NONE) {
ZFreeNotice(&acknotice);
return (ZERR_NONE);
diff --git a/lib/ZSendRaw.c b/lib/ZSendRaw.c
index e9b72b4..b981771 100644
--- a/lib/ZSendRaw.c
+++ b/lib/ZSendRaw.c
@@ -21,24 +21,23 @@ static char rcsid_ZSendRawNotice_c[] = "$Header$";
#include <zephyr/zephyr_internal.h>
Code_t ZSendRawNotice(notice)
- ZNotice_t *notice;
+ ZNotice_t *notice;
{
- Code_t retval;
- char *buffer;
- int len;
+ Code_t retval;
+ ZNotice_t newnotice;
+ char *buffer;
+ int len;
- buffer = (char *)malloc(Z_MAXPKTLEN);
- if (!buffer)
- return (ENOMEM);
+ if ((retval = ZFormatRawNotice(notice, &buffer, &len)) !=
+ ZERR_NONE)
+ return (retval);
- if ((retval = ZFormatRawNotice(notice,buffer,Z_MAXPKTLEN,&len)) !=
- ZERR_NONE) {
- free(buffer);
- return (retval);
- }
+ if ((retval = ZParseNotice(buffer, len, &newnotice)) != ZERR_NONE)
+ return (retval);
+
+ retval = Z_SendFragmentedNotice(&newnotice);
- retval = ZSendPacket(buffer,len);
- free(buffer);
+ free(buffer);
- return (retval);
+ return (retval);
}
diff --git a/lib/ZSubs.c b/lib/ZSubs.c
index 83e7ff2..dba8cd1 100644
--- a/lib/ZSubs.c
+++ b/lib/ZSubs.c
@@ -21,85 +21,86 @@ static char rcsid_ZSubscriptions_c[] = "$Header$";
#include <zephyr/zephyr_internal.h>
-Code_t ZSubscribeTo(sublist,nitems,port)
- ZSubscription_t *sublist;
- int nitems;
- u_short port;
+Code_t ZSubscribeTo(sublist, nitems, port)
+ ZSubscription_t *sublist;
+ int nitems;
+ u_short port;
{
- return (Z_Subscriptions(sublist,nitems,port,CLIENT_SUBSCRIBE,1));
+ return (Z_Subscriptions(sublist, nitems, port, CLIENT_SUBSCRIBE, 1));
}
-Code_t ZUnsubscribeTo(sublist,nitems,port)
- ZSubscription_t *sublist;
- int nitems;
- u_short port;
+Code_t ZUnsubscribeTo(sublist, nitems, port)
+ ZSubscription_t *sublist;
+ int nitems;
+ u_short port;
{
- return (Z_Subscriptions(sublist,nitems,port,CLIENT_UNSUBSCRIBE,1));
+ return (Z_Subscriptions(sublist, nitems, port, CLIENT_UNSUBSCRIBE, 1));
}
Code_t ZCancelSubscriptions(port)
- u_short port;
+ u_short port;
{
- return (Z_Subscriptions((ZSubscription_t *)0,0,port,
- CLIENT_CANCELSUB,0));
+ return (Z_Subscriptions((ZSubscription_t *)0, 0, port,
+ CLIENT_CANCELSUB, 0));
}
-Z_Subscriptions(sublist,nitems,port,opcode,authit)
- ZSubscription_t *sublist;
- int nitems;
- u_short port;
- char *opcode;
- int authit;
+Z_Subscriptions(sublist, nitems, port, opcode, authit)
+ ZSubscription_t *sublist;
+ int nitems;
+ u_short port;
+ char *opcode;
+ int authit;
{
- int i,retval;
- ZNotice_t notice,retnotice;
- ZPacket_t buffer;
- char **list;
+ int i, retval;
+ ZNotice_t notice, retnotice;
+ char **list;
- list = (char **)malloc((unsigned)nitems*3*sizeof(char *));
- if (!list)
- return (ENOMEM);
+ 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_default_format = "";
- notice.z_message_len = 0;
+ 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_num_other_fields = 0;
+ notice.z_default_format = "";
+ notice.z_message_len = 0;
- for (i=0;i<nitems;i++) {
- list[i*3] = sublist[i].class;
- list[i*3+1] = sublist[i].classinst;
- if (sublist[i].recipient && *sublist[i].recipient &&
- *sublist[i].recipient != '*')
- list[i*3+2] = ZGetSender();
- else
- list[i*3+2] = "";
- }
+ for (i=0;i<nitems;i++) {
+ list[i*3] = sublist[i].class;
+ list[i*3+1] = sublist[i].classinst;
+ if (sublist[i].recipient && *sublist[i].recipient &&
+ *sublist[i].recipient != '*')
+ list[i*3+2] = ZGetSender();
+ else
+ list[i*3+2] = "";
+ }
- retval = ZSendList(&notice,list,nitems*3,ZAUTH);
- if (retval != ZERR_NONE && !authit)
- retval = ZSendList(&notice,list,nitems*3,ZNOAUTH);
+ retval = ZSendList(&notice, list, nitems*3, ZAUTH);
+ if (retval != ZERR_NONE && !authit)
+ retval = ZSendList(&notice, list, nitems*3, ZNOAUTH);
- free((char *)list);
+ free((char *)list);
- if (retval != ZERR_NONE)
- return (retval);
+ if (retval != ZERR_NONE)
+ return (retval);
- if ((retval = ZIfNotice(buffer,sizeof buffer,&retnotice,
- (struct sockaddr_in *)0,
- ZCompareUIDPred,(char *)&notice.z_uid)) !=
- ZERR_NONE)
- return (retval);
+ if ((retval = ZIfNotice(&retnotice, (struct sockaddr_in *)0,
+ ZCompareUIDPred, (char *)&notice.z_uid)) !=
+ ZERR_NONE)
+ return (retval);
- if (retnotice.z_kind == SERVNAK)
- return (ZERR_SERVNAK);
+ ZFreeNotice(&retnotice);
+
+ if (retnotice.z_kind == SERVNAK)
+ return (ZERR_SERVNAK);
- if (retnotice.z_kind != SERVACK)
- return (ZERR_INTERNAL);
+ if (retnotice.z_kind != SERVACK)
+ return (ZERR_INTERNAL);
- return (ZERR_NONE);
+ return (ZERR_NONE);
}
diff --git a/lib/ZVariables.c b/lib/ZVariables.c
index 1413506..77e8b21 100644
--- a/lib/ZVariables.c
+++ b/lib/ZVariables.c
@@ -27,154 +27,154 @@ static char rcsid_ZVariables_c[] = "$Header$";
#define _toupper(c) (islower(c)?toupper(c):c)
char *ZGetVariable(var)
- char *var;
+ char *var;
{
- char varfile[128],*ret;
- char *get_varval();
+ char varfile[128], *ret;
+ char *get_varval();
- if (get_localvarfile(varfile))
- return ((char *)0);
+ if (get_localvarfile(varfile))
+ return ((char *)0);
+
+ if (ret = get_varval(varfile, var))
+ return (ret);
- if (ret = get_varval(varfile,var))
- return (ret);
- return (get_varval(DEFAULT_VARS_FILE,var));
+ return (get_varval(DEFAULT_VARS_FILE, var));
}
-Code_t ZSetVariable(var,value)
- char *var;
- char *value;
+Code_t ZSetVariable(var, value)
+ char *var;
+ char *value;
{
- int written;
- FILE *fpin,*fpout;
- char varfile[128],varfilebackup[128],varbfr[512];
+ int written;
+ FILE *fpin, *fpout;
+ char varfile[128], varfilebackup[128], varbfr[512];
- written = 0;
+ written = 0;
- if (get_localvarfile(varfile))
- return (ZERR_INTERNAL);
+ if (get_localvarfile(varfile))
+ return (ZERR_INTERNAL);
- strcpy(varfilebackup,varfile);
- strcat(varfilebackup,".backup");
+ strcpy(varfilebackup, varfile);
+ strcat(varfilebackup, ".backup");
- if (!(fpout = fopen(varfilebackup,"w")))
- return (errno);
- if (fpin = fopen(varfile,"r")) {
- while (fgets(varbfr,sizeof varbfr,fpin) != (char *) 0) {
- if (varbfr[strlen(varbfr)-1] < ' ')
- varbfr[strlen(varbfr)-1] = '\0';
- if (varline(varbfr,var)) {
- fprintf(fpout,"%s = %s\n",var,value);
- written = 1;
- }
- else
- fprintf(fpout,"%s\n",varbfr);
- }
- fclose(fpin);
- }
- if (!written)
- fprintf(fpout,"%s = %s\n",var,value);
- fclose(fpout);
- if (rename(varfilebackup,varfile))
- return (errno);
- return (ZERR_NONE);
+ if (!(fpout = fopen(varfilebackup, "w")))
+ return (errno);
+ if (fpin = fopen(varfile, "r")) {
+ while (fgets(varbfr, sizeof varbfr, fpin) != (char *) 0) {
+ if (varbfr[strlen(varbfr)-1] < ' ')
+ varbfr[strlen(varbfr)-1] = '\0';
+ if (varline(varbfr, var)) {
+ fprintf(fpout, "%s = %s\n", var, value);
+ written = 1;
+ }
+ else
+ fprintf(fpout, "%s\n", varbfr);
+ }
+ fclose(fpin);
+ }
+ if (!written)
+ fprintf(fpout, "%s = %s\n", var, value);
+ fclose(fpout);
+ if (rename(varfilebackup, varfile))
+ return (errno);
+ return (ZERR_NONE);
}
Code_t ZUnsetVariable(var)
- char *var;
+ char *var;
{
- FILE *fpin,*fpout;
- char varfile[128],varfilebackup[128],varbfr[512];
+ FILE *fpin, *fpout;
+ char varfile[128], varfilebackup[128], varbfr[512];
- if (get_localvarfile(varfile))
- return (ZERR_INTERNAL);
+ if (get_localvarfile(varfile))
+ return (ZERR_INTERNAL);
- strcpy(varfilebackup,varfile);
- strcat(varfilebackup,".backup");
+ strcpy(varfilebackup, varfile);
+ strcat(varfilebackup, ".backup");
- if (!(fpout = fopen(varfilebackup,"w")))
- return (errno);
- if (fpin = fopen(varfile,"r")) {
- while (fgets(varbfr,sizeof varbfr,fpin) != (char *) 0) {
- if (varbfr[strlen(varbfr)-1] < ' ')
- varbfr[strlen(varbfr)-1] = '\0';
- if (!varline(varbfr,var))
- fprintf(fpout,"%s\n",varbfr);
- }
- fclose(fpin);
- }
- fclose(fpout);
- if (rename(varfilebackup,varfile))
- return (errno);
- return (ZERR_NONE);
+ if (!(fpout = fopen(varfilebackup, "w")))
+ return (errno);
+ if (fpin = fopen(varfile, "r")) {
+ while (fgets(varbfr, sizeof varbfr, fpin) != (char *) 0) {
+ if (varbfr[strlen(varbfr)-1] < ' ')
+ varbfr[strlen(varbfr)-1] = '\0';
+ if (!varline(varbfr, var))
+ fprintf(fpout, "%s\n", varbfr);
+ }
+ fclose(fpin);
+ }
+ fclose(fpout);
+ if (rename(varfilebackup, varfile))
+ return (errno);
+ return (ZERR_NONE);
}
static get_localvarfile(bfr)
- char *bfr;
+ char *bfr;
{
- char *envptr;
- struct passwd *pwd;
-
- envptr = (char *)getenv("HOME");
- if (envptr)
- strcpy(bfr,envptr);
- else {
- if (!(pwd = getpwuid(getuid()))) {
- fprintf(stderr,"Zephyr internal failure: Can't find your entry in /etc/passwd\n");
- return (1);
- }
- strcpy(bfr,pwd->pw_dir);
+ char *envptr;
+ struct passwd *pwd;
+
+ envptr = (char *)getenv("HOME");
+ if (envptr)
+ strcpy(bfr, envptr);
+ else {
+ if (!(pwd = getpwuid(getuid()))) {
+ fprintf(stderr, "Zephyr internal failure: Can't find your entry in /etc/passwd\n");
+ return (1);
}
+ strcpy(bfr, pwd->pw_dir);
+ }
- strcat(bfr,"/");
- strcat(bfr,".zephyr.vars");
- return (0);
+ strcat(bfr, "/");
+ strcat(bfr, ".zephyr.vars");
+ return (0);
}
-static char *get_varval(fn,var)
- char *fn;
- char *var;
+static char *get_varval(fn, var)
+ char *fn;
+ char *var;
{
- FILE *fp;
- char varbfr[512];
- int i;
+ FILE *fp;
+ char varbfr[512];
+ int i;
- fp = fopen(fn,"r");
- if (!fp)
- return ((char *)0);
-
- while (fgets(varbfr,sizeof varbfr,fp) != (char *) 0) {
- if (varbfr[strlen(varbfr)-1] < ' ')
- varbfr[strlen(varbfr)-1] = '\0';
- if (!(i = varline(varbfr,var)))
- continue;
- fclose(fp);
- return (varbfr+i);
- }
- fclose(fp);
+ fp = fopen(fn, "r");
+ if (!fp)
return ((char *)0);
+
+ while (fgets(varbfr, sizeof varbfr, fp) != (char *) 0) {
+ if (varbfr[strlen(varbfr)-1] < ' ')
+ varbfr[strlen(varbfr)-1] = '\0';
+ if (!(i = varline(varbfr, var)))
+ continue;
+ fclose(fp);
+ return (varbfr+i);
+ }
+ fclose(fp);
+ return ((char *)0);
}
-static int varline(bfr,var)
- char *bfr;
- char *var;
+static int varline(bfr, var)
+ char *bfr;
+ char *var;
{
- int i;
+ int i;
- if (!bfr[0] || bfr[0] == '#')
- return (0);
+ if (!bfr[0] || bfr[0] == '#')
+ return (0);
- for (i = 0; bfr[i] && !isspace(bfr[i]) &&
- bfr[i] != '='; i++)
- if (_toupper(bfr[i]) != _toupper(var[i]))
- break;
- if ((!bfr[i] || !isspace(bfr[i])) && bfr[i] != '=')
- return (0);
- while (bfr[i] && isspace(bfr[i]))
- i++;
- if (bfr[i++] != '=')
- return (0);
- while (bfr[i] && isspace(bfr[i]))
- i++;
- return (i);
+ for (i = 0; bfr[i] && !isspace(bfr[i]) &&
+ bfr[i] != '='; i++)
+ if (_toupper(bfr[i]) != _toupper(var[i]))
+ break;
+ if ((!bfr[i] || !isspace(bfr[i])) && bfr[i] != '=')
+ return (0);
+ while (bfr[i] && isspace(bfr[i]))
+ i++;
+ if (bfr[i++] != '=')
+ return (0);
+ while (bfr[i] && isspace(bfr[i]))
+ i++;
+ return (i);
}
-
diff --git a/lib/Zinternal.c b/lib/Zinternal.c
index d0b8012..c0e13a2 100644
--- a/lib/Zinternal.c
+++ b/lib/Zinternal.c
@@ -30,7 +30,7 @@ int __Zephyr_open = 0;
int __Zephyr_port = -1;
int __My_length;
char *__My_addr;
-int __Q_Length = 0;
+int __Q_CompleteLength = 0;
struct _Z_InputQ *__Q_Head = 0, *__Q_Tail = 0;
struct sockaddr_in __HM_addr;
int __HM_set = 0;
@@ -44,473 +44,350 @@ ZSubscription_t *__subscriptions_list = 0;
int __subscriptions_num = 0;
int __subscriptions_next = 0;
+#define min(a,b) ((a)<(b)?(a):(b))
+
Code_t Z_GetMyAddr()
{
- struct hostent *myhost;
- char hostname[BUFSIZ];
- struct hostent *gethostbyname();
+ struct hostent *myhost;
+ char hostname[MAXHOSTNAMELEN];
- if (__My_length > 0)
- return (ZERR_NONE);
+ if (__My_length > 0)
+ return (ZERR_NONE);
- if (gethostname(hostname,BUFSIZ) < 0)
- return (errno);
+ if (gethostname(hostname, MAXHOSTNAMELEN) < 0)
+ return (errno);
- if (!(myhost = gethostbyname(hostname)))
- return (errno);
+ if (!(myhost = gethostbyname(hostname)))
+ return (errno);
- if (!(__My_addr = (char *)malloc((unsigned)myhost->h_length)))
- return (ENOMEM);
+ if (!(__My_addr = (char *)malloc((unsigned)myhost->h_length)))
+ return (ENOMEM);
- __My_length = myhost->h_length;
+ __My_length = myhost->h_length;
- bcopy(myhost->h_addr,__My_addr,myhost->h_length);
+ bcopy(myhost->h_addr, __My_addr, myhost->h_length);
- return (ZERR_NONE);
+ return (ZERR_NONE);
}
-Z_NoticeWaiting()
+Code_t Z_PacketWaiting()
{
- int bytes;
+ int bytes;
- if (ioctl(ZGetFD(),FIONREAD,(char *)&bytes) < 0)
- return (0);
+ if (ioctl(ZGetFD(), FIONREAD, (char *)&bytes) < 0)
+ return (0);
- return (bytes > 0);
+ return (bytes > 0);
}
-Z_ReadEnqueue()
+Code_t Z_ReadEnqueue()
{
- int retval;
+ int retval;
- while (Z_NoticeWaiting())
- if ((retval = Z_ReadWait()) != ZERR_NONE)
- return (retval);
+ while (Z_PacketWaiting())
+ if ((retval = Z_ReadWait()) != ZERR_NONE)
+ return (retval);
- return (ZERR_NONE);
+ return (ZERR_NONE);
}
-Z_ReadWait()
+Code_t Z_ReadWait()
{
- struct _Z_InputQ *newqueue;
- ZNotice_t notice;
- struct sockaddr_in olddest;
- int from_len,retval;
+ struct _Z_InputQ *newqueue;
+ ZNotice_t notice;
+ struct sockaddr_in olddest;
+ int from_len, retval;
- if (ZGetFD() < 0)
- return (ZERR_NOPORT);
+ if (ZGetFD() < 0)
+ return (ZERR_NOPORT);
- if (__Q_Length > Z_MAXQLEN)
- return (ZERR_QLEN);
+ if (__Q_CompleteLength > Z_MAXQLEN)
+ return (ZERR_QLEN);
- newqueue = (struct _Z_InputQ *)malloc(sizeof(struct _Z_InputQ));
- if (!newqueue)
- return (ENOMEM);
+ newqueue = (struct _Z_InputQ *)malloc(sizeof(struct _Z_InputQ));
+ if (!newqueue)
+ return (ENOMEM);
- from_len = sizeof(struct sockaddr_in);
-
- newqueue->packet_len = recvfrom(ZGetFD(),newqueue->packet,
- sizeof newqueue->packet, 0,
- &newqueue->from,
- &from_len);
-
- if (newqueue->packet_len < 0) {
- free((char *)newqueue);
- return (errno);
- }
-
- if (!newqueue->packet_len) {
- free((char *)newqueue);
- return (ZERR_EOF);
- }
-
- if (!__Zephyr_server &&
- ZParseNotice(newqueue->packet, newqueue->packet_len,
- &notice) == ZERR_NONE) {
- if (notice.z_kind != HMACK && notice.z_kind != SERVACK &&
- notice.z_kind != SERVNAK) {
- notice.z_kind = CLIENTACK;
- notice.z_message_len = 0;
- olddest = __HM_addr;
- __HM_addr = newqueue->from;
- if ((retval = ZSendRawNotice(&notice)) != ZERR_NONE)
- return (retval);
- __HM_addr = olddest;
- }
- }
+ from_len = sizeof(struct sockaddr_in);
- newqueue->next = NULL;
- if (__Q_Length) {
- newqueue->prev = __Q_Tail;
- __Q_Tail->next = newqueue;
- __Q_Tail = newqueue;
- }
- else {
- newqueue->prev = NULL;
- __Q_Head = __Q_Tail = newqueue;
- }
+ newqueue->packet_len = recvfrom(ZGetFD(), newqueue->packet,
+ sizeof newqueue->packet, 0,
+ &newqueue->from,
+ &from_len);
+
+ if (newqueue->packet_len < 0) {
+ free((char *)newqueue);
+ return (errno);
+ }
+
+ if (!newqueue->packet_len) {
+ free((char *)newqueue);
+ return (ZERR_EOF);
+ }
+
+ if (!__Zephyr_server &&
+ ZParseNotice(newqueue->packet, newqueue->packet_len,
+ &notice) == ZERR_NONE) {
+ if (notice.z_kind != HMACK && notice.z_kind != SERVACK &&
+ notice.z_kind != SERVNAK) {
+ notice.z_kind = CLIENTACK;
+ notice.z_message_len = 0;
+ olddest = __HM_addr;
+ __HM_addr = newqueue->from;
+ if ((retval = ZSendRawNotice(&notice)) != ZERR_NONE)
+ return (retval);
+ __HM_addr = olddest;
+ }
+ }
+
+ newqueue->next = NULL;
+ if (__Q_CompleteLength) {
+ newqueue->prev = __Q_Tail;
+ __Q_Tail->next = newqueue;
+ __Q_Tail = newqueue;
+ }
+ else {
+ newqueue->prev = NULL;
+ __Q_Head = __Q_Tail = newqueue;
+ }
- __Q_Length++;
+ __Q_CompleteLength++;
- return (ZERR_NONE);
+ return (ZERR_NONE);
}
-Z_FormatHeader(notice,buffer,buffer_len,len,cert_routine)
- ZNotice_t *notice;
- char *buffer;
- int buffer_len;
- int *len;
- int (*cert_routine)();
+Code_t Z_FormatHeader(notice, buffer, buffer_len, len, cert_routine)
+ ZNotice_t *notice;
+ char *buffer;
+ int buffer_len;
+ int *len;
+ int (*cert_routine)();
{
- int retval;
+ Code_t retval;
- if (!notice->z_class || !notice->z_class_inst || !notice->z_opcode ||
- !notice->z_recipient)
- return (ZERR_ILLVAL);
-
- if (!notice->z_sender)
- notice->z_sender = ZGetSender();
-
- (void) gettimeofday(&notice->z_uid.tv,(struct timezone *)0);
- notice->z_uid.tv.tv_sec = htonl(notice->z_uid.tv.tv_sec);
- notice->z_uid.tv.tv_usec = htonl(notice->z_uid.tv.tv_usec);
+ if (!notice->z_sender)
+ notice->z_sender = ZGetSender();
+
+ notice->z_multinotice = "";
+
+ (void) gettimeofday(&notice->z_uid.tv, (struct timezone *)0);
+ notice->z_uid.tv.tv_sec = htonl(notice->z_uid.tv.tv_sec);
+ notice->z_uid.tv.tv_usec = htonl(notice->z_uid.tv.tv_usec);
- if ((retval = Z_GetMyAddr()) != ZERR_NONE)
- return (retval);
+ if ((retval = Z_GetMyAddr()) != ZERR_NONE)
+ return (retval);
- bcopy(__My_addr,(char *)&notice->z_uid.zuid_addr,__My_length);
+ bcopy(__My_addr, (char *)&notice->z_uid.zuid_addr, __My_length);
- if (!cert_routine) {
- notice->z_auth = 0;
- notice->z_authent_len = 0;
- notice->z_ascii_authent = (char *)"";
- return (Z_FormatRawHeader(notice,buffer,buffer_len,len));
- }
+ if (!cert_routine) {
+ notice->z_auth = 0;
+ notice->z_authent_len = 0;
+ notice->z_ascii_authent = "";
+ return (Z_FormatRawHeader(notice, buffer, buffer_len, len));
+ }
- return ((cert_routine)(notice,buffer,buffer_len,len));
+ return ((cert_routine)(notice, buffer, buffer_len, len));
}
-Z_FormatRawHeader(notice,buffer,buffer_len,len)
- ZNotice_t *notice;
- char *buffer;
- int buffer_len;
- int *len;
+Code_t Z_FormatRawHeader(notice, buffer, buffer_len, len)
+ ZNotice_t *notice;
+ char *buffer;
+ int buffer_len;
+ int *len;
{
- unsigned int temp;
- char newrecip[BUFSIZ],version[BUFSIZ];
- char *ptr,*end;
-
- if (!notice->z_class)
- notice->z_class = "";
-
- if (!notice->z_class_inst)
- notice->z_class_inst = "";
-
- if (!notice->z_opcode)
- notice->z_opcode = "";
-
- if (!notice->z_recipient)
- notice->z_recipient = "";
-
- if (!notice->z_default_format)
- notice->z_default_format = "";
-
- ptr = buffer;
- end = buffer+buffer_len;
-
- sprintf(version,"%s%d.%d",ZVERSIONHDR,ZVERSIONMAJOR,ZVERSIONMINOR);
- if (buffer_len < strlen(version)+1)
- return (ZERR_PKTLEN);
-
- strcpy(ptr,version);
- ptr += strlen(ptr)+1;
-
- temp = htonl(ZNUMFIELDS);
- if (ZMakeAscii(ptr,end-ptr,(unsigned char *)&temp,
- sizeof(int)) == ZERR_FIELDLEN)
- return (ZERR_PKTLEN);
- ptr += strlen(ptr)+1;
+ unsigned int temp;
+ char newrecip[BUFSIZ], version[BUFSIZ];
+ char *ptr, *end;
+ int i;
+
+ if (!notice->z_class || !notice->z_class_inst || !notice->z_opcode ||
+ !notice->z_recipient || !notice->z_default_format)
+ return (ZERR_ILLVAL);
+
+ ptr = buffer;
+ end = buffer+buffer_len;
+
+ sprintf(version, "%s%d.%d", ZVERSIONHDR, ZVERSIONMAJOR, ZVERSIONMINOR);
+ if (buffer_len < strlen(version)+1)
+ return (ZERR_HEADERLEN);
+
+ strcpy(ptr, version);
+ ptr += strlen(ptr)+1;
+
+ temp = htonl(ZNUMFIELDS+notice->z_num_other_fields);
+ if (ZMakeAscii(ptr, end-ptr, (unsigned char *)&temp,
+ sizeof(int)) == ZERR_FIELDLEN)
+ return (ZERR_HEADERLEN);
+ ptr += strlen(ptr)+1;
- temp = htonl((int)notice->z_kind);
- if (ZMakeAscii(ptr,end-ptr,(unsigned char *)&temp,
- sizeof(int)) == ZERR_FIELDLEN)
- return (ZERR_PKTLEN);
- ptr += strlen(ptr)+1;
+ temp = htonl((int)notice->z_kind);
+ if (ZMakeAscii(ptr, end-ptr, (unsigned char *)&temp,
+ sizeof(int)) == ZERR_FIELDLEN)
+ return (ZERR_HEADERLEN);
+ ptr += strlen(ptr)+1;
- if (ZMakeAscii(ptr,end-ptr,(unsigned char *)&notice->z_uid,
- sizeof(ZUnique_Id_t)) == ZERR_FIELDLEN)
- return (ZERR_PKTLEN);
- ptr += strlen(ptr)+1;
+ if (ZMakeAscii(ptr, end-ptr, (unsigned char *)&notice->z_uid,
+ sizeof(ZUnique_Id_t)) == ZERR_FIELDLEN)
+ return (ZERR_HEADERLEN);
+ ptr += strlen(ptr)+1;
- if (ZMakeAscii(ptr,end-ptr,(unsigned char *)&notice->z_port,
- sizeof(u_short)) == ZERR_FIELDLEN)
- return (ZERR_PKTLEN);
- ptr += strlen(ptr)+1;
-
- if (ZMakeAscii(ptr,end-ptr,(unsigned char *)&notice->z_auth,
- sizeof(int)) == ZERR_FIELDLEN)
- return (ZERR_PKTLEN);
- ptr += strlen(ptr)+1;
-
- temp = htonl(notice->z_authent_len);
- if (ZMakeAscii(ptr,end-ptr,(unsigned char *)&temp,
- sizeof(int)) == ZERR_FIELDLEN)
- return (ZERR_PKTLEN);
- ptr += strlen(ptr)+1;
+ if (ZMakeAscii(ptr, end-ptr, (unsigned char *)&notice->z_port,
+ sizeof(u_short)) == ZERR_FIELDLEN)
+ return (ZERR_HEADERLEN);
+ ptr += strlen(ptr)+1;
+
+ if (ZMakeAscii(ptr, end-ptr, (unsigned char *)&notice->z_auth,
+ sizeof(int)) == ZERR_FIELDLEN)
+ return (ZERR_HEADERLEN);
+ ptr += strlen(ptr)+1;
+
+ temp = htonl(notice->z_authent_len);
+ if (ZMakeAscii(ptr, end-ptr, (unsigned char *)&temp,
+ sizeof(int)) == ZERR_FIELDLEN)
+ return (ZERR_HEADERLEN);
+ ptr += strlen(ptr)+1;
- if (Z_AddField(&ptr,notice->z_ascii_authent,end))
- return (ZERR_PKTLEN);
- if (Z_AddField(&ptr,notice->z_class,end))
- return (ZERR_PKTLEN);
- if (Z_AddField(&ptr,notice->z_class_inst,end))
- return (ZERR_PKTLEN);
- if (Z_AddField(&ptr,notice->z_opcode,end))
- return (ZERR_PKTLEN);
- if (Z_AddField(&ptr,notice->z_sender,end))
- return (ZERR_PKTLEN);
- if (index(notice->z_recipient,'@') || !*notice->z_recipient) {
- if (Z_AddField(&ptr,notice->z_recipient,end))
- return (ZERR_PKTLEN);
- }
- else {
- (void) sprintf(newrecip,"%s@%s",notice->z_recipient,
- __Zephyr_realm);
- if (Z_AddField(&ptr,newrecip,end))
- return (ZERR_PKTLEN);
- }
- if (Z_AddField(&ptr,notice->z_default_format,end))
- return (ZERR_PKTLEN);
-
- temp = htonl(notice->z_checksum);
- if (ZMakeAscii(ptr,end-ptr,(unsigned char *)&temp,
- sizeof(ZChecksum_t)) == ZERR_FIELDLEN)
- return (ZERR_PKTLEN);
- ptr += strlen(ptr)+1;
-
- if (Z_AddField(&ptr,notice->z_multinotice,end))
- return (ZERR_PKTLEN);
+ if (Z_AddField(&ptr, notice->z_ascii_authent, end))
+ return (ZERR_HEADERLEN);
+ if (Z_AddField(&ptr, notice->z_class, end))
+ return (ZERR_HEADERLEN);
+ if (Z_AddField(&ptr, notice->z_class_inst, end))
+ return (ZERR_HEADERLEN);
+ if (Z_AddField(&ptr, notice->z_opcode, end))
+ return (ZERR_HEADERLEN);
+ if (Z_AddField(&ptr, notice->z_sender, end))
+ return (ZERR_HEADERLEN);
+ if (index(notice->z_recipient, '@') || !*notice->z_recipient) {
+ if (Z_AddField(&ptr, notice->z_recipient, end))
+ return (ZERR_HEADERLEN);
+ }
+ else {
+ (void) sprintf(newrecip, "%s@%s", notice->z_recipient,
+ __Zephyr_realm);
+ if (Z_AddField(&ptr, newrecip, end))
+ return (ZERR_HEADERLEN);
+ }
+ if (Z_AddField(&ptr, notice->z_default_format, end))
+ return (ZERR_HEADERLEN);
+
+ temp = htonl(notice->z_checksum);
+ if (ZMakeAscii(ptr, end-ptr, (unsigned char *)&temp,
+ sizeof(ZChecksum_t)) == ZERR_FIELDLEN)
+ return (ZERR_HEADERLEN);
+ ptr += strlen(ptr)+1;
+
+ if (Z_AddField(&ptr, notice->z_multinotice, end))
+ return (ZERR_HEADERLEN);
+
+ for (i=0;i<notice->z_num_other_fields;i++)
+ if (Z_AddField(&ptr, notice->z_other_fields[i], end))
+ return (ZERR_HEADERLEN);
+
+#ifdef notdef
+ temp = htonl(notice->z_checksum);
+ if (ZMakeAscii(ptr, end-ptr, (unsigned char *)&temp,
+ sizeof(ZChecksum_t)) == ZERR_FIELDLEN)
+ return (ZERR_HEADERLEN);
+ ptr += strlen(ptr)+1;
+#endif
+
+ *len = ptr-buffer;
- *len = ptr-buffer;
-
- return (ZERR_NONE);
+ return (ZERR_NONE);
}
-Z_AddField(ptr,field,end)
- char **ptr,*field,*end;
+Z_AddField(ptr, field, end)
+ char **ptr, *field, *end;
{
- register int len;
+ register int len;
- len = strlen(field)+1;
+ len = strlen(field)+1;
- if (*ptr+len > end)
- return (1);
- (void) strcpy(*ptr,field);
- *ptr += len;
+ if (*ptr+len > end)
+ return (1);
+ (void) strcpy(*ptr, field);
+ *ptr += len;
- return (0);
+ return (0);
+}
+
+struct _Z_InputQ *Z_GetFirstComplete()
+{
+ return (__Q_Head);
+}
+
+struct _Z_InputQ *Z_GetNextComplete(qptr)
+ struct _Z_InputQ *qptr;
+{
+ return (qptr->next);
}
Z_RemQueue(qptr)
- struct _Z_InputQ *qptr;
+ struct _Z_InputQ *qptr;
{
- __Q_Length--;
+ __Q_CompleteLength--;
- if (!__Q_Length) {
- free ((char *)qptr);
- return (ZERR_NONE);
- }
+ if (!__Q_CompleteLength) {
+ free ((char *)qptr);
+ return (ZERR_NONE);
+ }
- if (qptr == __Q_Head) {
- __Q_Head = __Q_Head->next;
- __Q_Head->prev = NULL;
- free ((char *)qptr);
- return (ZERR_NONE);
- }
- if (qptr == __Q_Tail) {
- __Q_Tail = __Q_Tail->prev;
- __Q_Tail->next = NULL;
- free ((char *)qptr);
- return (ZERR_NONE);
- }
- qptr->prev->next = qptr->next;
- qptr->next->prev = qptr->prev;
+ if (qptr == __Q_Head) {
+ __Q_Head = __Q_Head->next;
+ __Q_Head->prev = NULL;
free ((char *)qptr);
return (ZERR_NONE);
+ }
+ if (qptr == __Q_Tail) {
+ __Q_Tail = __Q_Tail->prev;
+ __Q_Tail->next = NULL;
+ free ((char *)qptr);
+ return (ZERR_NONE);
+ }
+ qptr->prev->next = qptr->next;
+ qptr->next->prev = qptr->prev;
+ free ((char *)qptr);
+ return (ZERR_NONE);
}
-Code_t Z_InternalParseNotice(buffer,len,notice)
- ZPacket_t buffer;
- int len;
- ZNotice_t *notice;
+Code_t Z_SendFragmentedNotice(notice, len)
+ ZNotice_t *notice;
+ int len;
{
- char *ptr,*end;
- int maj,numfields,i;
- unsigned int temp[3];
-
- bzero(notice,sizeof(ZNotice_t));
-
- ptr = buffer;
- end = buffer+len;
-
- notice->z_version = ptr;
- if (strncmp(ptr,ZVERSIONHDR,strlen(ZVERSIONHDR)))
- return (ZERR_VERS);
- ptr += strlen(ZVERSIONHDR);
- maj = atoi(ptr);
- if (maj != ZVERSIONMAJOR)
- return (ZERR_VERS);
- ptr += strlen(ptr)+1;
-
- if (ZReadAscii(ptr,end-ptr,(unsigned char *)temp,sizeof(int)) == ZERR_BADFIELD)
- return (ZERR_BADPKT);
- numfields = ntohl(*temp);
- ptr += strlen(ptr)+1;
-
- numfields -= 2;
- if (numfields < 0)
- numfields = 0;
-
- if (numfields) {
- if (ZReadAscii(ptr,end-ptr,(unsigned char *)temp,
- sizeof(int)) == ZERR_BADFIELD)
- return (ZERR_BADPKT);
- notice->z_kind = (ZNotice_Kind_t)ntohl((ZNotice_Kind_t)*temp);
- numfields--;
- ptr += strlen(ptr)+1;
- }
- else
- return (ZERR_BADPKT);
-
- if (numfields) {
- if (ZReadAscii(ptr,end-ptr,(unsigned char *)temp,
- sizeof(ZUnique_Id_t)) ==
- ZERR_BADFIELD)
- return (ZERR_BADPKT);
- bcopy((char *)temp,(char *)&notice->z_uid,sizeof(ZUnique_Id_t));
- notice->z_time.tv_sec = ntohl(notice->z_uid.tv.tv_sec);
- notice->z_time.tv_usec = ntohl(notice->z_uid.tv.tv_usec);
- numfields--;
- ptr += strlen(ptr)+1;
- }
- else
- return (ZERR_BADPKT);
-
- if (numfields) {
- if (ZReadAscii(ptr,end-ptr,(unsigned char *)temp,
- sizeof(u_short)) ==
- ZERR_BADFIELD)
- return (ZERR_BADPKT);
- notice->z_port = *((u_short *)temp);
- numfields--;
- ptr += strlen(ptr)+1;
- }
- else
- return (ZERR_BADPKT);
-
- if (numfields) {
- if (ZReadAscii(ptr,end-ptr,(unsigned char *)temp,
- sizeof(int)) == ZERR_BADFIELD)
- return (ZERR_BADPKT);
- notice->z_auth = *temp;
- numfields--;
- ptr += strlen(ptr)+1;
- }
- else
- return (ZERR_BADPKT);
-
- if (numfields) {
- if (ZReadAscii(ptr,end-ptr,(unsigned char *)temp,
- sizeof(int)) == ZERR_BADFIELD)
- return (ZERR_BADPKT);
- notice->z_authent_len = ntohl(*temp);
- numfields--;
- ptr += strlen(ptr)+1;
- }
- else
- return (ZERR_BADPKT);
-
- if (numfields) {
- notice->z_ascii_authent = ptr;
- numfields--;
- ptr += strlen(ptr)+1;
+ ZNotice_t partnotice;
+ ZPacket_t buffer;
+ char multi[64];
+ int offset, hdrsize, fragsize, ret_len, waitforack;
+ Code_t retval;
+
+ hdrsize = len-notice->z_message_len;
+ fragsize = Z_MAXPKTLEN-hdrsize-10;
+
+ offset = 0;
+
+ waitforack = (notice->z_kind == UNACKED || notice->z_kind == ACKED) &&
+ !__Zephyr_server;
+
+ while (offset < notice->z_message_len || !notice->z_message_len) {
+ sprintf(multi, "%d/%d", offset, notice->z_message_len);
+ partnotice = *notice;
+ partnotice.z_multinotice = multi;
+ partnotice.z_message = notice->z_message+offset;
+ partnotice.z_message_len = min(notice->z_message_len-offset,
+ fragsize);
+ if ((retval = ZFormatSmallRawNotice(&partnotice, buffer,
+ &ret_len)) != ZERR_NONE) {
+ free(buffer);
+ return (retval);
}
- else
- return (ZERR_BADPKT);
-
- if (numfields) {
- notice->z_class = ptr;
- numfields--;
- ptr += strlen(ptr)+1;
- }
- else
- notice->z_class = "";
-
- if (numfields) {
- notice->z_class_inst = ptr;
- numfields--;
- ptr += strlen(ptr)+1;
- }
- else
- notice->z_class_inst = "";
-
- if (numfields) {
- notice->z_opcode = ptr;
- numfields--;
- ptr += strlen(ptr)+1;
+ if ((retval = ZSendPacket(buffer, ret_len, waitforack)) != ZERR_NONE) {
+ free(buffer);
+ return (retval);
}
- else
- notice->z_opcode = "";
+ offset += fragsize;
+ if (!notice->z_message_len)
+ break;
+ }
- if (numfields) {
- notice->z_sender = ptr;
- numfields--;
- ptr += strlen(ptr)+1;
- }
- else
- notice->z_sender = "";
-
- if (numfields) {
- notice->z_recipient = ptr;
- numfields--;
- ptr += strlen(ptr)+1;
- }
- else
- notice->z_recipient = "";
-
- if (numfields) {
- notice->z_default_format = ptr;
- numfields--;
- ptr += strlen(ptr)+1;
- }
- else
- notice->z_default_format = "";
-
- if (numfields) {
- if (ZReadAscii(ptr,end-ptr,(unsigned char *)temp,
- sizeof(ZChecksum_t))
- == ZERR_BADFIELD)
- return (ZERR_BADPKT);
- notice->z_checksum = ntohl(*temp);
- numfields--;
- ptr += strlen(ptr)+1;
- }
- else
- notice->z_checksum = 0;
-
- if (numfields) {
- notice->z_multinotice = ptr;
- numfields--;
- ptr += strlen(ptr)+1;
- }
- else
- notice->z_multinotice = "";
-
- for (i=0;i<numfields;i++)
- ptr += strlen(ptr)+1;
-
- notice->z_message = (caddr_t) ptr;
- notice->z_message_len = len-(ptr-buffer);
-
- return (ZERR_NONE);
+ return (ZERR_NONE);
}
-