summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Robert S. French <rfrench@mit.edu>1987-06-12 12:58:47 +0000
committerGravatar Robert S. French <rfrench@mit.edu>1987-06-12 12:58:47 +0000
commit2a79930d731c6d85df0fc46e869a4466dbf1d1fd (patch)
tree69baaff8f1bc1fb934473a1fe7b31946f3ceb3b6
parent2a5fbec60dbc9c1a08e104760f64bbdc33c8a1fa (diff)
First working library - safe checkin
-rw-r--r--lib/ZCkIfNot.c55
-rw-r--r--lib/ZIfNotice.c66
-rw-r--r--lib/ZParseNot.c69
-rw-r--r--lib/ZPeekIfNot.c66
-rw-r--r--lib/ZRecvPkt.c10
-rw-r--r--lib/ZSendNot.c2
-rw-r--r--lib/ZSendPkt.c2
7 files changed, 242 insertions, 28 deletions
diff --git a/lib/ZCkIfNot.c b/lib/ZCkIfNot.c
new file mode 100644
index 0000000..71622f2
--- /dev/null
+++ b/lib/ZCkIfNot.c
@@ -0,0 +1,55 @@
+/* This file is part of the Project Athena Zephyr Notification System.
+ * It contains source for the ZCheckIfNotice 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 ZCheckIfNotice(buffer,buffer_len,notice,auth,predicate,args)
+ ZPacket_t buffer;
+ int buffer_len;
+ ZNotice_t *notice;
+ int *auth;
+ int (*predicate)();
+ char *args;
+{
+ ZNotice_t tmpnotice;
+ int qcount,retval,tmpauth;
+ struct _Z_InputQ *qptr;
+
+ if ((retval = Z_ReadEnqueue()) != ZERR_NONE)
+ return (retval);
+
+ qptr = __Q_Head;
+ qcount = __Q_Length;
+
+ for (;qcount;qcount--) {
+ if ((retval = ZParseNotice(qptr->packet,qptr->packet_len,
+ &tmpnotice,&tmpauth)) != 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 ((retval = ZParseNotice(buffer,qptr->packet_len,
+ notice,auth))
+ != ZERR_NONE)
+ return (retval);
+ return (Z_RemQueue(qptr));
+ }
+ qptr = qptr->next;
+ }
+
+ return (ZERR_NONOTICE);
+}
diff --git a/lib/ZIfNotice.c b/lib/ZIfNotice.c
new file mode 100644
index 0000000..8482ef5
--- /dev/null
+++ b/lib/ZIfNotice.c
@@ -0,0 +1,66 @@
+/* This file is part of the Project Athena Zephyr Notification System.
+ * It contains source for the ZIfNotice 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 ZIfNotice(buffer,buffer_len,notice,auth,predicate,args)
+ ZPacket_t buffer;
+ int buffer_len;
+ ZNotice_t *notice;
+ int *auth;
+ int (*predicate)();
+ char *args;
+{
+ ZNotice_t tmpnotice;
+ int qcount,retval,tmpauth;
+ struct _Z_InputQ *qptr;
+
+ if (__Q_Length)
+ retval = Z_ReadEnqueue();
+ else
+ retval = Z_ReadWait();
+
+ if (retval != ZERR_NONE)
+ return (retval);
+
+ qptr = __Q_Head;
+ qcount = __Q_Length;
+
+ for (;;qcount--) {
+ if ((retval = ZParseNotice(qptr->packet,qptr->packet_len,
+ &tmpnotice,&tmpauth)) != 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 ((retval = ZParseNotice(buffer,qptr->packet_len,
+ notice,auth))
+ != 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;
+ }
+}
diff --git a/lib/ZParseNot.c b/lib/ZParseNot.c
index 394e89a..ea4ef67 100644
--- a/lib/ZParseNot.c
+++ b/lib/ZParseNot.c
@@ -22,23 +22,34 @@ Code_t ZParseNotice(buffer,len,notice,auth)
ZNotice_t *notice;
int *auth;
{
- int hdrlen;
char *ptr;
+ int i;
+ unsigned int temp[3];
- hdrlen = *((short *)buffer);
+ ptr = buffer;
+
+ if (Z_ReadField(&ptr,temp,1))
+ return (ZERR_BADPKT);
+
+ if (*temp != ZVERSION)
+ return (ZERR_VERS);
- ptr = buffer+2;
+ if (Z_ReadField(&ptr,temp,1))
+ return (ZERR_BADPKT);
+ notice->z_kind = (ZNotice_Kind_t)*temp;
- if (*ptr++ != ZVERSION)
- return (ZERR_VERS);
+ if (Z_ReadField(&ptr,temp,1))
+ return (ZERR_BADPKT);
+ notice->z_port = (short)*temp;
+
+ if (Z_ReadField(&ptr,temp,2))
+ return (ZERR_BADPKT);
+ bcopy(temp,notice->z_checksum,sizeof(ZChecksum_t));
+
+ if (Z_ReadField(&ptr,temp,3))
+ return (ZERR_BADPKT);
+ bcopy(temp,&notice->z_uid,sizeof(ZUnique_Id_t));
- notice->z_kind = (ZNotice_Kind_t)*ptr++;
- bcopy(ptr,notice->z_checksum,sizeof(ZChecksum_t));
- ptr += sizeof(ZChecksum_t);
- bcopy(ptr,&notice->z_uid,sizeof(ZUnique_Id_t));
- ptr += sizeof(ZUnique_Id_t);
- notice->z_port = *((short *)ptr);
- ptr += sizeof(short);
notice->z_class = ptr;
ptr += strlen(ptr)+1;
notice->z_class_inst = ptr;
@@ -50,11 +61,37 @@ Code_t ZParseNotice(buffer,len,notice,auth)
notice->z_recipient = ptr;
ptr += strlen(ptr)+1;
- if (ptr-buffer != hdrlen)
- return(ZERR_BADPKT);
-
notice->z_message = (caddr_t) ptr;
- notice->z_message_len = len-hdrlen;
+ notice->z_message_len = len-(ptr-buffer);
*auth = 0;
+
+ return (ZERR_NONE);
+}
+
+int Z_ReadField(ptr,temp,num)
+ char **ptr;
+ int *temp;
+ int num;
+{
+ int i;
+ char *space;
+
+ for (i=0;i<num;i++) {
+ space = (char *)index(*ptr,' ');
+ if ((*ptr)[0] != '0' || (*ptr)[1] != 'x')
+ return (1);
+ sscanf(*ptr+2,"%x",temp+i);
+ if (space)
+ *ptr = space+1;
+ else
+ *ptr += strlen(*ptr);
+ if (!*ptr && i != num-1)
+ return (1);
+ }
+
+ if (**ptr)
+ return (1);
+ (*ptr)++;
+ return (0);
}
diff --git a/lib/ZPeekIfNot.c b/lib/ZPeekIfNot.c
new file mode 100644
index 0000000..f52cdd6
--- /dev/null
+++ b/lib/ZPeekIfNot.c
@@ -0,0 +1,66 @@
+/* This file is part of the Project Athena Zephyr Notification System.
+ * It contains source for the ZPeekIfNotice 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 ZPeekIfNotice(buffer,buffer_len,notice,auth,predicate,args)
+ ZPacket_t buffer;
+ int buffer_len;
+ ZNotice_t *notice;
+ int *auth;
+ int (*predicate)();
+ char *args;
+{
+ ZNotice_t tmpnotice;
+ int qcount,retval,tmpauth;
+ struct _Z_InputQ *qptr;
+
+ if (__Q_Length)
+ retval = Z_ReadEnqueue();
+ else
+ retval = Z_ReadWait();
+
+ if (retval != ZERR_NONE)
+ return (retval);
+
+ qptr = __Q_Head;
+ qcount = __Q_Length;
+
+ for (;;qcount--) {
+ if ((retval = ZParseNotice(qptr->packet,qptr->packet_len,
+ &tmpnotice,&tmpauth)) != 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 ((retval = ZParseNotice(buffer,qptr->packet_len,
+ notice,auth))
+ != 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;
+ }
+}
diff --git a/lib/ZRecvPkt.c b/lib/ZRecvPkt.c
index 0f1829e..8e8a179 100644
--- a/lib/ZRecvPkt.c
+++ b/lib/ZRecvPkt.c
@@ -45,15 +45,7 @@ Code_t ZReceivePacket(buffer,buffer_len,ret_len)
bcopy(__Q_Head->packet,buffer,*ret_len);
- __Q_Length--;
-
- old_head = __Q_Head;
- if (__Q_Length)
- __Q_Head = __Q_Head->next;
- else
- __Q_Head = __Q_Tail = NULL;
-
- free (old_head);
+ Z_RemQueue(__Q_Head);
return (retval);
}
diff --git a/lib/ZSendNot.c b/lib/ZSendNot.c
index 683b666..e8cc40f 100644
--- a/lib/ZSendNot.c
+++ b/lib/ZSendNot.c
@@ -29,7 +29,7 @@ Code_t ZSendNotice(notice)
len = BUFSIZ;
- if ((retval = ZFormatNotice(notice,buffer,sizeof buffer,&len)) < 0) {
+ if ((retval = ZFormatNotice(notice,buffer,BUFSIZ,&len)) < 0) {
free(buffer);
return (retval);
}
diff --git a/lib/ZSendPkt.c b/lib/ZSendPkt.c
index 215f548..305d754 100644
--- a/lib/ZSendPkt.c
+++ b/lib/ZSendPkt.c
@@ -38,8 +38,6 @@ Code_t ZSendPacket(packet,len)
sin.sin_port = htons(__HM_port);
bcopy(__HM_addr,&sin.sin_addr,__HM_length);
- printf("Internal: Sending to port %d\n",__HM_port);
-
if (sendto(ZGetFD(),packet,len,0,&sin,sizeof(sin)) < 0)
return (ZERR_UNIX);