summaryrefslogtreecommitdiff
path: root/server/class.c
diff options
context:
space:
mode:
authorGravatar John Kohl <jtkohl@mit.edu>1987-07-07 09:56:05 +0000
committerGravatar John Kohl <jtkohl@mit.edu>1987-07-07 09:56:05 +0000
commit837f784243e7a17f1c58230fe5c4a4328106ade9 (patch)
tree88aa07a2850bb9152db2ff32e37a085fd7532299 /server/class.c
parentd3b86020f0556598fea3ed696fc497ef1a8d3b29 (diff)
make all checks for NULL pointers just use ! rather than == NULLxxx
and add a few comment
Diffstat (limited to 'server/class.c')
-rw-r--r--server/class.c98
1 files changed, 66 insertions, 32 deletions
diff --git a/server/class.c b/server/class.c
index 79b6be1..0c74ff2 100644
--- a/server/class.c
+++ b/server/class.c
@@ -25,7 +25,7 @@ static char rcsid_class_s_c[] = "$Header$";
* Class manager subsystem.
*
*
- * external functions are:
+ * External functions are:
*
* Code_t class_register(client, class)
*
@@ -56,19 +56,22 @@ static char rcsid_class_s_c[] = "$Header$";
*/
/*
- * The data structure used for the class manager is a set of hash buckets
+ * The data structure used for the class manager is an array of hash buckets
* each containing a pointer to a doubly linked circular list (in the style
* of insque/remque). Each element of this list contains a class name (which
* hashes into the bucket associated with this list) and a doubly linked list
* of clients which are interested in this class.
* The data pointed to by these clients is owned by other modules. Care
- * must be taken not to register or fail to register a free()'d client
+ * must be taken by the caller not to register a free()'d client
* structure.
+ *
* If any hash bucket is empty, the pointer is null.
- * The first pointer in the hash bucket is unused for storing classes, and
- * is used for finding the end of the list
+ *
+ * The first element in the hash bucket is a special header unused for
+ * storing classes, and is used for finding the end of the list.
+ *
* If any list of interested clients is empty, the class name is garbage
- * collected.
+ * collected, unless the class has been registered as restricted.
*/
/* Private variables */
@@ -88,6 +91,7 @@ static int hash();
/* public routines */
/* register the client as interested in class */
+
Code_t
class_register(client, class)
ZClient_t *client;
@@ -96,14 +100,14 @@ char *class;
register ZClass_t *ptr, *ptr2;
int hashval = hash(class);
- if ((ptr = class_bucket[hashval]) == NULLZCT) {
+ if (!(ptr = class_bucket[hashval])) {
/* not registered */
- if ((ptr = class_alloc(class)) == NULLZCT)
+ if (!(ptr = class_alloc(class)))
return(ENOMEM);
/* allocate the head of the bucket */
- if ((ptr2 = (ZClass_t *) xmalloc(sizeof(ZClass_t))) == NULLZCT)
+ if (!(ptr2 = (ZClass_t *) xmalloc(sizeof(ZClass_t))))
return(ENOMEM);
ptr2->q_forw = ptr;
@@ -121,7 +125,7 @@ char *class;
return(insert_client(ptr2, client));
/* fell off the end, no match */
- if ((ptr2 = class_alloc(class)) == NULLZCT)
+ if (!(ptr2 = class_alloc(class)))
return(ENOMEM);
xinsque(ptr2, ptr); /* insert new class into hash bucket */
return(insert_client(ptr2, client));
@@ -129,6 +133,7 @@ char *class;
}
/* dissociate client from the class, garbage collecting if appropriate */
+
Code_t
class_deregister(client, class)
ZClient_t *client;
@@ -138,8 +143,8 @@ char *class;
int retval = -1;
int hashval = hash(class);
- zdbug1("class_dereg");
- if ((ptr = class_bucket[hashval]) == NULLZCT)
+ zdbug((LOG_DEBUG, "class_dereg"));
+ if (!(ptr = class_bucket[hashval]))
/* no such class to deregister */
return(ZSRV_BADASSOC);
@@ -147,9 +152,9 @@ char *class;
/* walk down the list, looking for a match */
if (!strcmp(ptr2->zct_classname, class)) {
if ((retval = remove_client(ptr2, client)) == EMPTY_CLASS) {
- zdbug1("empty class");
+ zdbug((LOG_DEBUG,"empty class"));
/* Don't free up restricted classes. */
- if (ptr2->zct_acl != NULLZACLT)
+ if (ptr2->zct_acl)
return(ZERR_NONE);
else {
xremque(ptr2);
@@ -170,6 +175,7 @@ char *class;
}
/* return a linked list of what clients are interested in this class */
+
ZClientList_t *
class_lookup(class)
char *class;
@@ -177,7 +183,7 @@ char *class;
register ZClass_t *ptr, *ptr2;
int hashval = hash(class);
- if ((ptr = class_bucket[hashval]) == NULLZCT)
+ if (!(ptr = class_bucket[hashval]))
return(NULLZCLT); /* no such class */
else { /* go search the list for the class */
for (ptr2 = ptr->q_forw; ptr2 != ptr; ptr2 = ptr2->q_forw) {
@@ -190,6 +196,11 @@ char *class;
}
}
+/*
+ * These routines return 0 or one depending on whether the indicated
+ * notice is of the type named by the routine name.
+ */
+
int
class_is_control(notice)
ZNotice_t *notice;
@@ -225,6 +236,11 @@ ZNotice_t *notice;
return(!strcmp(notice->z_class, LOCATE_CLASS));
}
+/*
+ * return the acl structure associated with class, or NULLZACLT if there is
+ * no such acl struct
+ */
+
ZAcl_t *
class_get_acl(class)
char *class;
@@ -232,7 +248,7 @@ char *class;
register ZClass_t *ptr, *ptr2;
int hashval = hash(class);
- if ((ptr = class_bucket[hashval]) == NULLZCT)
+ if (!(ptr = class_bucket[hashval]))
return(NULLZACLT);
/* walk down the list, looking for a match */
@@ -244,6 +260,12 @@ char *class;
return(NULLZACLT);
}
+/*
+ * restrict class by associating it with the acl structure acl.
+ * return ZERR_NONE if no error, or ZSRV_NOCLASS if there is no such
+ * class, or ZSRV_CLASSRESTRICTED if it is already restricted.
+ */
+
Code_t
class_restrict(class, acl)
char *class;
@@ -252,11 +274,13 @@ ZAcl_t *acl;
register ZClass_t *ptr, *ptr2;
int hashval = hash(class);
- if ((ptr = class_bucket[hashval]) == NULLZCT)
+ if (!(ptr = class_bucket[hashval]))
return(ZSRV_NOCLASS);
for (ptr2 = ptr->q_forw; ptr2 != ptr; ptr2 = ptr2->q_forw)
/* walk down the list, looking for a match */
if (!strcmp(ptr2->zct_classname, class)) {
+ if (ptr2->zct_acl)
+ return(ZSRV_CLASSRESTRICTED);
ptr2->zct_acl = acl;
return(ZERR_NONE);
}
@@ -265,6 +289,12 @@ ZAcl_t *acl;
return(ZSRV_NOCLASS);
}
+/*
+ * restrict class by registering it and associating it with the acl
+ * structure acl. return ZERR_NONE if no error, or ZSRV_CLASSXISTS
+ * if the class is already registered, or ENOMEM in case of malloc failure.
+ */
+
Code_t
class_setup_restricted(class, acl)
char *class;
@@ -273,16 +303,16 @@ ZAcl_t *acl;
register ZClass_t *ptr, *ptr2;
int hashval = hash(class);
- if ((ptr = class_bucket[hashval]) == NULLZCT) {
+ if (!(ptr = class_bucket[hashval])) {
/* not registered */
- if ((ptr = class_alloc(class)) == NULLZCT)
+ if (!(ptr = class_alloc(class)))
return(ENOMEM);
ptr->zct_acl = acl;
/* allocate the head of the bucket */
- if ((ptr2 = (ZClass_t *) xmalloc(sizeof(ZClass_t))) == NULLZCT)
+ if (!(ptr2 = (ZClass_t *) xmalloc(sizeof(ZClass_t))))
return(ENOMEM);
ptr2->q_forw = ptr;
@@ -296,10 +326,10 @@ ZAcl_t *acl;
return(ZSRV_CLASSXISTS);
}
-
/* private routines */
/* the hash function */
+
static int
hash(string)
char *string;
@@ -313,6 +343,7 @@ char *string;
}
/* allocate space for a class structure */
+
static ZClass_t *
class_alloc(class)
char *class;
@@ -320,16 +351,13 @@ char *class;
register ZClass_t *ptr;
ZClientList_t *clist;
- if ((ptr = (ZClass_t *) xmalloc(sizeof(ZClass_t))) == NULLZCT)
+ if (!(ptr = (ZClass_t *) xmalloc(sizeof(ZClass_t))))
return(NULLZCT);
ptr->q_forw = ptr->q_back = ptr;
- if ((ptr->zct_classname = strsave(class)) == NULL) {
- xfree((char *) ptr);
- return(NULLZCT);
- }
- if ((clist = (ZClientList_t *) xmalloc(sizeof(ZClientList_t))) == NULLZCLT) {
+ ptr->zct_classname = strsave(class);
+ if (!(clist = (ZClientList_t *) xmalloc(sizeof(ZClientList_t)))) {
xfree(ptr);
return(NULLZCT);
}
@@ -341,6 +369,7 @@ char *class;
}
/* free up the space used by this class structure */
+
static void
free_class(ptr)
ZClass_t *ptr;
@@ -351,12 +380,13 @@ ZClass_t *ptr;
}
/* allocate space for a client entry */
+
static ZClientList_t *
client_alloc(client)
ZClient_t *client;
{
register ZClientList_t *ptr;
- if ((ptr = (ZClientList_t *) xmalloc(sizeof(ZClientList_t))) == NULLZCLT)
+ if (!(ptr = (ZClientList_t *) xmalloc(sizeof(ZClientList_t))))
return(NULLZCLT);
ptr->zclt_client = client;
@@ -364,6 +394,7 @@ ZClient_t *client;
}
/* insert a client into the list associated with the class *ptr */
+
static Code_t
insert_client(ptr, client)
ZClass_t *ptr;
@@ -378,15 +409,18 @@ ZClient_t *client;
if (clist->zclt_client == client)
return(ZERR_NONE);
- if ((listp = client_alloc(client)) == NULLZCLT)
+ if (!(listp = client_alloc(client)))
return(ENOMEM);
xinsque(listp, ptr->zct_clientlist);
return(ZERR_NONE);
}
-/* remove the client from the list associated with class *ptr, garbage
- collecting if appropriate */
+/*
+ * remove the client from the list associated with class *ptr, garbage
+ * collecting if appropriate
+ */
+
static Code_t remove_client(ptr, client)
ZClass_t *ptr;
ZClient_t *client;
@@ -394,7 +428,7 @@ ZClient_t *client;
register ZClientList_t *listp = ptr->zct_clientlist;
register ZClientList_t *listp2;
- if (listp == NULLZCLT)
+ if (!listp)
return(ZSRV_BADASSOC);
for (listp2 = listp->q_forw;
listp2 != listp;