summaryrefslogtreecommitdiff
path: root/server/subscr.c
diff options
context:
space:
mode:
authorGravatar Kenneth G Raeburn <raeburn@mit.edu>1990-11-13 12:02:59 +0000
committerGravatar Kenneth G Raeburn <raeburn@mit.edu>1990-11-13 12:02:59 +0000
commita36a075433165839ec7a02379ad83c03e08498a5 (patch)
treef6ad43e0f7a6e60f5e65d3e632b49edabf9a9a7a /server/subscr.c
parentdb89d0d2485f01c3d411c87952f2cd09e372f844 (diff)
C++ conversion and lots of modifications from summer & fall work
Diffstat (limited to 'server/subscr.c')
-rw-r--r--server/subscr.c487
1 files changed, 215 insertions, 272 deletions
diff --git a/server/subscr.c b/server/subscr.c
index fe071bb..1fb8515 100644
--- a/server/subscr.c
+++ b/server/subscr.c
@@ -62,39 +62,43 @@ static char rcsid_subscr_c[] = "$Id$";
#include "zserver.h"
#include <ctype.h>
+#include <strings.h>
#include <sys/stat.h>
/* for compatibility when sending subscription information to old clients */
#ifdef OLD_COMPAT
#define OLD_ZEPHYR_VERSION "ZEPH0.0"
#define OLD_CLIENT_INCOMPSUBS "INCOMP"
-static void old_compat_subscr_sendlist();
+static void old_compat_subscr_sendlist(ZNotice_t *notice, int auth, struct sockaddr_in *who);
extern int old_compat_count_subscr; /* counter of old use */
#endif /* OLD_COMPAT */
#ifdef NEW_COMPAT
#define NEW_OLD_ZEPHYR_VERSION "ZEPH0.1"
-static void new_old_compat_subscr_sendlist();
+static void new_old_compat_subscr_sendlist(ZNotice_t *notice, int auth, struct sockaddr_in *who);
extern int new_compat_count_subscr; /* counter of old use */
#endif /* NEW_COMPAT */
-extern char *re_comp(), *re_conv(), *rindex(), *index();
-static ZSubscr_t *extract_subscriptions();
-static int subscr_equiv(), clt_unique();
-static void free_subscriptions(), free_sub();
-static char **subscr_marshal_subs();
-static Code_t subscr_subscribe_real();
-static ZSubscr_t *subscr_copy_def_subs();
+extern char *re_comp(), *re_conv();
+static ZSubscr_t *extract_subscriptions(register ZNotice_t *notice);
+static int clt_unique(ZClient_t *clt, ZClientList_t *clist);
+static void free_subscriptions(register ZSubscr_t *subs);
+static const char **subscr_marshal_subs(ZNotice_t *notice, int auth,
+ struct sockaddr_in *who,
+ register int *found);
+static Code_t subscr_subscribe_real(ZClient_t *who, ZSubscr_t *newsubs,
+ ZNotice_t *notice);
+static ZSubscr_t *subscr_copy_def_subs(const ZString&);
+static int cl_match (ZNotice_t*, ZClient_t *);
static int defaults_read = 0; /* set to 1 if the default subs
are in memory */
static ZNotice_t default_notice; /* contains default subscriptions */
-static ZSubscr_t matchall_sub = {
- (ZSubscr_t *) 0,
- (ZSubscr_t *) 0,
- MATCHALL_CLASS,
- "",
- "" };
+extern const ZString wildcard_class (MATCHALL_CLASS, 1);
+extern const ZString wildcard_instance (WILDCARD_INSTANCE, 1);
+
+static ZString empty ("");
+static ZSubscr_t matchall_sub (wildcard_class, empty, empty);
/* WARNING: make sure this is the same as the number of strings you */
/* plan to hand back to the user in response to a subscription check, */
@@ -106,18 +110,16 @@ static ZSubscr_t matchall_sub = {
*/
Code_t
-subscr_subscribe(who, notice)
-ZClient_t *who;
-ZNotice_t *notice;
+subscr_subscribe(ZClient_t *who, ZNotice_t *notice)
{
ZSubscr_t *subs;
if (!who->zct_subs) {
/* allocate a subscription head */
- if (!(subs = (ZSubscr_t *) xmalloc(sizeof(ZSubscr_t))))
+ subs = new ZSubscr_t;
+ if (!subs)
return(ENOMEM);
- subs->q_forw = subs->q_back = subs;
who->zct_subs = subs;
}
@@ -128,15 +130,12 @@ ZNotice_t *notice;
}
static Code_t
-subscr_subscribe_real(who, newsubs, notice)
-ZClient_t *who;
-register ZSubscr_t *newsubs;
-ZNotice_t *notice;
+subscr_subscribe_real(ZClient_t *who, register ZSubscr_t *newsubs, ZNotice_t *notice)
{
- int relation;
int omask;
Code_t retval;
ZAcl_t *acl;
+ ZString sender (notice->z_sender);
register ZSubscr_t *subs2, *subs3, *subs;
omask = sigblock(sigmask(SIGFPE)); /* don't let db dumps start */
@@ -145,43 +144,54 @@ ZNotice_t *notice;
subs = subs->q_forw) {
/* for each new subscription */
- if (!bdumping && *(subs->zst_recipient) &&
- strcmp(subs->zst_recipient, notice->z_sender)) {
+#if 1
+ zdbug ((LOG_DEBUG, "subscr: %s/%s/%s",
+ subs->zst_dest.classname.value (),
+ subs->zst_dest.inst.value (),
+ subs->zst_dest.recip.value ()));
+#endif
+
+ if (!bdumping
+ && *(subs->zst_dest.recip.value ())
+ && subs->zst_dest.recip != sender) {
syslog(LOG_WARNING, "subscr unauth to rcpt %s by %s",
- subs->zst_recipient,
- notice->z_sender);
+ subs->zst_dest.recip.value (),
+ sender.value ());
continue;
}
- acl = class_get_acl(subs->zst_class);
- if (acl && !bdumping) {
- if (!access_check(notice, acl, SUBSCRIBE)) {
+ if (!bdumping) {
+ acl = class_get_acl(subs->zst_dest.classname);
+ if (acl) {
+ if (!acl->ok (sender, SUBSCRIBE)) {
syslog(LOG_WARNING, "subscr unauth %s %s",
- notice->z_sender, subs->zst_class);
+ sender.value (),
+ subs->zst_dest.classname.value ());
continue; /* the for loop */
}
- if (!strcmp(WILDCARD_INSTANCE, subs->zst_classinst)) {
- if (!access_check(notice, acl, INSTWILD)) {
- syslog(LOG_WARNING,
- "subscr unauth wild %s %s.*",
- notice->z_sender,
- subs->zst_class);
- continue;
- }
+ if (wildcard_instance == subs->zst_dest.inst) {
+ if (!acl->ok (sender, INSTWILD)) {
+ syslog(LOG_WARNING,
+ "subscr unauth wild %s %s.*",
+ notice->z_sender,
+ subs->zst_dest.classname.value ());
+ continue;
+ }
}
+ }
}
for (subs2 = who->zct_subs->q_forw;
subs2 != who->zct_subs;
subs2 = subs2->q_forw) {
/* for each existing subscription */
- relation = strcasecmp(subs->zst_class, subs2->zst_class);
- if (relation > 0) /* we have passed the last
- possible one */
+ if (*subs >= *subs2)
break;
- if (relation < 0) /* nope... */
- continue;
- if (subscr_equiv(subs, subs2)) /* duplicate? */
- goto duplicate;
}
+ /*
+ * Can't put a goto in place of the break above,
+ * because cfront can't cope.
+ */
+ if (subs2 != who->zct_subs && *subs == *subs2)
+ continue;
/* subs2 now points to the first class which is greater
than the new class. We need to back up so that the
insertion below goes BEFORE this one (i.e. after the
@@ -190,29 +200,22 @@ ZNotice_t *notice;
/* ok, we are a new subscription. register and chain on. */
- if (!(subs3 = (ZSubscr_t *) xmalloc(sizeof(ZSubscr_t)))) {
+ subs3 = new ZSubscr_t (*subs);
+ if (!subs3) {
free_subscriptions(newsubs);
(void) sigsetmask(omask);
return(ENOMEM);
}
if ((retval = class_register(who, subs)) != ZERR_NONE) {
- xfree(subs3);
+ delete subs3;
free_subscriptions(newsubs);
(void) sigsetmask(omask);
return(retval);
}
- subs3->zst_class = strsave(subs->zst_class);
- subs3->zst_classinst = strsave(subs->zst_classinst);
- subs3->zst_recipient = strsave(subs->zst_recipient);
-
- subs3->q_forw = subs3->q_back = subs3;
-
/* subs2 was adjusted above */
xinsque(subs3, subs2);
-
-duplicate: ; /* just go on to the next */
}
(void) sigsetmask(omask);
@@ -225,18 +228,17 @@ duplicate: ; /* just go on to the next */
*/
Code_t
-subscr_def_subs(who)
-ZClient_t *who;
+subscr_def_subs(ZClient_t *who)
{
ZSubscr_t *subs;
if (!who->zct_subs) {
/* allocate a subscription head */
- if (!(subs = (ZSubscr_t *) xmalloc(sizeof(ZSubscr_t)))) {
+ subs = new ZSubscr_t;
+ if (!subs) {
syslog(LOG_ERR, "no mem subscr_def_subs");
return(ENOMEM);
}
- subs->q_forw = subs->q_back = subs;
who->zct_subs = subs;
}
@@ -245,16 +247,18 @@ ZClient_t *who;
}
void
-subscr_reset()
+subscr_reset(void)
{
+#if 0
zdbug((LOG_DEBUG, "subscr_reset()"));
+#endif
xfree(default_notice.z_message);
+ default_notice.z_message = 0;
defaults_read = 0;
}
static ZSubscr_t *
-subscr_copy_def_subs(person)
-char *person;
+subscr_copy_def_subs(const ZString& person)
{
int retval;
int fd;
@@ -265,7 +269,9 @@ char *person;
register ZSubscr_t *subs2;
if (!defaults_read) {
+#if 1
zdbug((LOG_DEBUG, "reading default subscription file"));
+#endif
fd = open(DEFAULT_SUBS_FILE, O_RDONLY, 0666);
if (fd < 0) {
syslog(LOG_ERR, "can't open %s:%m", DEFAULT_SUBS_FILE);
@@ -278,7 +284,7 @@ char *person;
(void) close(fd);
return((ZSubscr_t *)0);
}
- if (!(def_sub_area = xmalloc(statbuf.st_size + 1))) {
+ if (!(def_sub_area = (char *) xmalloc(statbuf.st_size + 1))) {
syslog(LOG_ERR, "no mem copy_def_subs");
(void) close(fd);
return((ZSubscr_t *)0);
@@ -319,21 +325,21 @@ char *person;
if ((*cp == '\n') || (*cp == ','))
*cp = '\0';
default_notice.z_message = def_sub_area;
- default_notice.z_message_len = statbuf.st_size + 1;
+ default_notice.z_message_len = (int) statbuf.st_size + 1;
default_notice.z_auth = 1;
defaults_read = 1;
}
/* needed later for access_check() */
- default_notice.z_sender = person;
+ default_notice.z_sender = (char *) person.value ();
subs = extract_subscriptions(&default_notice);
/* replace any non-* recipients with "person" */
for (subs2 = subs->q_forw; subs2 != subs; subs2 = subs2->q_forw)
/* if not a wildcard, replace it with person */
- if (strcmp(subs2->zst_recipient, "*")) {
- subs2->zst_recipient = person;
+ if (strcmp(subs2->zst_dest.recip.value (), "*")) {
+ subs2->zst_dest.recip = person;
} else { /* replace with null recipient */
- subs2->zst_recipient = "";
+ subs2->zst_dest.recip = empty;
}
return(subs);
}
@@ -343,17 +349,17 @@ char *person;
*/
Code_t
-subscr_cancel(sin, notice)
-struct sockaddr_in *sin;
-ZNotice_t *notice;
+subscr_cancel(struct sockaddr_in *sin, ZNotice_t *notice)
{
ZClient_t *who;
register ZSubscr_t *subs, *subs2, *subs3, *subs4;
Code_t retval;
- int found = 0, relation;
+ int found = 0;
int omask;
+#if 0
zdbug((LOG_DEBUG,"subscr_cancel"));
+#endif
if (!(who = client_which_client(sin, notice)))
return(ZSRV_NOCLT);
@@ -372,35 +378,33 @@ ZNotice_t *notice;
subs2 != who->zct_subs;) {
/* for each existing subscription */
/* is this what we are canceling? */
- relation = strcasecmp(subs4->zst_class, subs2->zst_class);
- if (relation > 0) /* we have passed the last
- possible one */
- break;
- if (relation < 0) { /* nope... */
- subs2 = subs2->q_forw;
- continue;
+ if (subs4->zst_dest.classname != subs2->zst_dest.classname) {
+ subs2 = subs2->q_forw;
+ continue;
}
- if (subscr_equiv(subs4, subs2)) {
- /* go back, since remque will change things */
- subs3 = subs2->q_back;
- xremque(subs2);
- (void) class_deregister(who, subs2);
- free_sub(subs2);
- found = 1;
- /* now that the remque adjusted the linked
- list, we go forward again */
- subs2 = subs3->q_forw;
+ if (*subs4 == *subs2) {
+ /* go back, since remque will change things */
+ subs3 = subs2->q_back;
+ xremque(subs2);
+ (void) class_deregister(who, subs2);
+ delete subs2;
+ found = 1;
+ /* now that the remque adjusted the linked
+ list, we go forward again */
+ subs2 = subs3->q_forw;
+ } else if (*subs4 >= *subs2) {
+ break;
} else {
- zdbug((LOG_DEBUG, "not %s.%s.%s",
- subs2->zst_class,
- subs2->zst_classinst,
- subs2->zst_recipient));
- subs2 = subs2->q_forw;
-
+#if 0
+ zdbug((LOG_DEBUG, "not %s.%s.%s",
+ subs2->zst_dest.classname.value(),
+ subs2->zst_dest.inst.value(),
+ subs2->zst_dest.recip.value()));
+#endif
+ subs2 = subs2->q_forw;
}
}
- /* make sure we are still registered for all the
- classes */
+ /* make sure we are still registered for all the classes */
if (found)
for (subs2 = who->zct_subs->q_forw;
subs2 != who->zct_subs;
@@ -413,10 +417,14 @@ ZNotice_t *notice;
(void) sigsetmask(omask);
free_subscriptions(subs);
if (found) {
+#if 0
zdbug((LOG_DEBUG, "found & removed"));
+#endif
return(ZERR_NONE);
} else {
+#if 0
zdbug((LOG_DEBUG, "not found"));
+#endif
return(ZSRV_NOSUB);
}
}
@@ -426,13 +434,14 @@ ZNotice_t *notice;
*/
void
-subscr_cancel_client(client)
-register ZClient_t *client;
+subscr_cancel_client(register ZClient_t *client)
{
register ZSubscr_t *subs;
int omask;
+#if 1
zdbug((LOG_DEBUG,"subscr_cancel_client"));
+#endif
if (!client->zct_subs)
return;
@@ -440,18 +449,23 @@ register ZClient_t *client;
for (subs = client->zct_subs->q_forw;
subs != client->zct_subs;
subs = client->zct_subs->q_forw) {
- zdbug((LOG_DEBUG,"sub_can %s",subs->zst_class));
+#if 1
+ zdbug((LOG_DEBUG,"sub_can %s",
+ subs->zst_dest.classname.value()));
+#endif
if (class_deregister(client, subs) != ZERR_NONE) {
+#if 1
zdbug((LOG_DEBUG,"sub_can_clt: not registered!"));
+#endif
}
xremque(subs);
- free_sub(subs);
+ delete subs;
}
/* also flush the head of the queue */
/* subs is now client->zct_subs */
- xfree(subs);
+ delete subs;
client->zct_subs = NULLZST;
(void) sigsetmask(omask);
@@ -484,7 +498,7 @@ struct in_addr *addr;
(void) sigsetmask(omask);
return(ZERR_NONE);
}
-#endif notdef
+#endif
/*
* Here is the bulk of the work in the subscription manager.
@@ -494,55 +508,35 @@ struct in_addr *addr;
*/
ZClientList_t *
-subscr_match_list(notice)
-ZNotice_t *notice;
+subscr_match_list(ZNotice_t *notice)
{
register ZClientList_t *hits, *clients, *majik, *clients2, *hit2;
- register char *cp;
- char *newclass, *saveclass, *newclinst, *saveclinst;
- ZSubscr_t check_sub;
+ char *saveclass, *saveclinst;
+ ZString newclass, newclinst;
+ /* Use this where we can't use "goto" thanks to cfront... */
+ int get_out = 0;
if (!(hits = (ZClientList_t *) xmalloc(sizeof(ZClientList_t))))
return(NULLZCLT);
hits->q_forw = hits->q_back = hits;
-
+
saveclass = notice->z_class;
- cp = newclass = strsave(notice->z_class);
+ newclass = ZString (notice->z_class, 1);
- while (*cp) {
- if (isupper(*cp))
- *cp = tolower(*cp);
- cp++;
- }
saveclinst = notice->z_class_inst;
- cp = newclinst = strsave(notice->z_class_inst);
-
- while (*cp) {
- if (isupper(*cp))
- *cp = tolower(*cp);
- cp++;
- }
+ newclinst = ZString (saveclinst, 1);
- check_sub.zst_class = newclass;
- check_sub.zst_classinst = newclinst;
- check_sub.zst_recipient = notice->z_recipient;
+ ZSubscr_t check_sub (newclass, newclinst, notice->z_recipient);
check_sub.q_forw = check_sub.q_back = &check_sub;
- if (!(clients = class_lookup(&check_sub))) {
- if (!(majik = class_lookup(&matchall_sub))) {
- notice->z_class = saveclass;
- notice->z_class_inst = saveclinst;
- xfree(newclass);
- xfree(newclinst);
- xfree(hits);
- return(NULLZCLT);
- }
- } else
- majik = class_lookup(&matchall_sub);
+ clients = class_lookup (&check_sub);
+ majik = class_lookup (&matchall_sub);
+ if (!clients && !majik)
+ return NULLZCLT;
- notice->z_class = newclass;
- notice->z_class_inst = newclinst;
+ notice->z_class = (char *) newclass.value ();
+ notice->z_class_inst = (char *) newclinst.value ();
if (clients) {
for (clients2 = clients->q_forw;
clients2 != clients;
@@ -554,19 +548,17 @@ ZNotice_t *notice;
if (!(hit2 = (ZClientList_t *) xmalloc(sizeof(ZClientList_t)))) {
syslog(LOG_WARNING,
"subscr_match: punting/no mem");
- notice->z_class = saveclass;
- xfree(newclass);
- notice->z_class_inst = saveclinst;
- xfree(newclinst);
- return(hits);
+ get_out = 1;
+ break;
}
hit2->zclt_client = clients2->zclt_client;
hit2->q_forw = hit2->q_back = hit2;
xinsque(hit2, hits);
}
- class_free(clients);
+ if (!get_out)
+ class_free(clients);
}
- if (majik) {
+ if (!get_out && majik) {
for (clients2 = majik->q_forw;
clients2 != majik;
clients2 = clients2->q_forw) {
@@ -576,23 +568,20 @@ ZNotice_t *notice;
if (!(hit2 = (ZClientList_t *) xmalloc(sizeof(ZClientList_t)))) {
syslog(LOG_WARNING,
"subscr_match(majik): punting/no mem");
- notice->z_class = saveclass;
- xfree(newclass);
- notice->z_class_inst = saveclinst;
- xfree(newclinst);
- return(hits);
+ get_out = 1;
+ break;
}
hit2->zclt_client = clients2->zclt_client;
hit2->q_forw = hit2->q_back = hit2;
xinsque(hit2, hits);
}
- class_free(majik);
+ if (!get_out)
+ class_free(majik);
}
+/* out:*/
notice->z_class = saveclass;
- xfree(newclass);
notice->z_class_inst = saveclinst;
- xfree(newclinst);
if (hits->q_forw == hits) {
xfree(hits);
return(NULLZCLT);
@@ -605,8 +594,7 @@ ZNotice_t *notice;
*/
void
-subscr_free_list(list)
-ZClientList_t *list;
+subscr_free_list(ZClientList_t *list)
{
register ZClientList_t *lyst;
@@ -623,12 +611,9 @@ ZClientList_t *list;
*/
void
-subscr_sendlist(notice, auth, who)
-ZNotice_t *notice;
-int auth;
-struct sockaddr_in *who;
+subscr_sendlist(ZNotice_t *notice, int auth, struct sockaddr_in *who)
{
- char **answer;
+ const char **answer;
int found;
struct sockaddr_in send_to_who;
Code_t retval;
@@ -668,8 +653,8 @@ struct sockaddr_in *who;
/* use xmit_frag() to send each piece of the notice */
- if ((retval = ZSrvSendRawList(notice, answer, found*NUM_FIELDS,
- xmit_frag))
+ if ((retval = ZSrvSendRawList(notice, (char **) answer,
+ found*NUM_FIELDS, xmit_frag))
!= ZERR_NONE) {
syslog(LOG_WARNING, "subscr_sendlist xmit: %s",
error_message(retval));
@@ -679,15 +664,11 @@ struct sockaddr_in *who;
return;
}
-static char **
-subscr_marshal_subs(notice, auth, who, found)
-ZNotice_t *notice;
-int auth;
-struct sockaddr_in *who;
-register int *found;
+static const char **
+subscr_marshal_subs(ZNotice_t *notice, int auth, struct sockaddr_in *who, register int *found)
{
ZNotice_t reply;
- char **answer = (char **) NULL;
+ const char **answer = (const char **) NULL;
int temp;
Code_t retval;
ZClient_t *client;
@@ -695,7 +676,9 @@ register int *found;
register int i;
int defsubs = 0;
+#if 0
zdbug((LOG_DEBUG, "subscr_marshal"));
+#endif
*found = 0;
/* Note that the following code is an incredible crock! */
@@ -732,7 +715,9 @@ register int *found;
if (client)
subs2 = client->zct_subs;
} else if (!strcmp(notice->z_opcode, CLIENT_GIMMEDEFS)) {
+#if 0
zdbug((LOG_DEBUG, "gimmedefs"));
+#endif
/* subscr_copy_def_subs allocates new pointer rings, so
it must be freed when finished.
the string areas pointed to are static, however.*/
@@ -772,9 +757,9 @@ register int *found;
for (i = 0, subs = subs2->q_forw;
i < *found ;
i++, subs = subs->q_forw) {
- answer[i*NUM_FIELDS] = subs->zst_class;
- answer[i*NUM_FIELDS + 1] = subs->zst_classinst;
- answer[i*NUM_FIELDS + 2] = subs->zst_recipient;
+ answer[i*NUM_FIELDS] = subs->zst_dest.classname.value ();
+ answer[i*NUM_FIELDS + 1] = subs->zst_dest.inst.value ();
+ answer[i*NUM_FIELDS + 2] = subs->zst_dest.recip.value ();
}
}
if (defsubs)
@@ -784,17 +769,14 @@ register int *found;
#ifdef NEW_COMPAT
static void
-new_old_compat_subscr_sendlist(notice, auth, who)
-ZNotice_t *notice;
-int auth;
-struct sockaddr_in *who;
+new_old_compat_subscr_sendlist(ZNotice_t *notice, int auth, struct sockaddr_in *who)
{
Code_t retval;
ZNotice_t reply;
ZPacket_t reppacket;
int packlen, found, count, initfound, zerofound;
char buf[64];
- char **answer;
+ const char **answer;
struct sockaddr_in send_to_who;
register int i;
@@ -825,8 +807,10 @@ struct sockaddr_in *who;
/* send 5 at a time until we are finished */
count = found?((found-1) / 5 + 1):1; /* total # to be sent */
i = 0; /* pkt # counter */
+#if 0
zdbug((LOG_DEBUG,"Found %d subscriptions for %d packets",
found,count));
+#endif
initfound = found;
zerofound = (found == 0);
while (found > 0 || zerofound) {
@@ -855,7 +839,9 @@ struct sockaddr_in *who;
found -= 5;
zerofound = 0;
}
+#if 0
zdbug((LOG_DEBUG,"subscr_sendlist acked"));
+#endif
if (answer)
xfree(answer);
return;
@@ -864,10 +850,7 @@ struct sockaddr_in *who;
#ifdef OLD_COMPAT
static void
-old_compat_subscr_sendlist(notice, auth, who)
-ZNotice_t *notice;
-int auth;
-struct sockaddr_in *who;
+old_compat_subscr_sendlist(ZNotice_t *notice, int auth, struct sockaddr_in *who)
{
ZClient_t *client = client_which_client(who, notice);
register ZSubscr_t *subs;
@@ -951,7 +934,9 @@ struct sockaddr_in *who;
xfree(answer);
return;
}
+#if 0
zdbug((LOG_DEBUG,"subscr_sendlist acked"));
+#endif
if (answer)
xfree(answer);
return;
@@ -967,20 +952,21 @@ struct sockaddr_in *who;
/*ARGSUSED*/
Code_t
-subscr_send_subs(client, vers)
-ZClient_t *client;
-char *vers;
+subscr_send_subs(ZClient_t *client, char *vers)
{
register int i = 0;
register ZSubscr_t *sub;
#ifdef KERBEROS
char buf[512];
#endif /* KERBEROS */
- char buf2[512], *lyst[7 * NUM_FIELDS];
+ char buf2[512];
+ const char *lyst[7 * NUM_FIELDS];
int num = 0;
Code_t retval;
+#if 0
zdbug((LOG_DEBUG, "send_subs"));
+#endif
(void) sprintf(buf2, "%d",ntohs(client->zct_sin.sin_port));
lyst[num++] = buf2;
@@ -988,17 +974,22 @@ char *vers;
#ifdef KERBEROS
if ((retval = ZMakeAscii(buf, sizeof(buf), client->zct_cblock,
sizeof(C_Block))) != ZERR_NONE) {
+#if 0
zdbug((LOG_DEBUG,"zmakeascii failed: %s",
error_message(retval)));
+#endif
} else {
lyst[num++] = buf;
+#if 0
zdbug((LOG_DEBUG,"cblock %s",buf));
+#endif
}
#endif KERBEROS
if ((retval = bdump_send_list_tcp(SERVACK, client->zct_sin.sin_port,
ZEPHYR_ADMIN_CLASS,
num > 1 ? "CBLOCK" : "",
- ADMIN_NEWCLT, client->zct_principal,
+ ADMIN_NEWCLT,
+ (char*)client->zct_principal.value(),
"", lyst, num)) != ZERR_NONE ) {
syslog(LOG_ERR, "subscr_send_subs newclt: %s",
error_message(retval));
@@ -1011,9 +1002,9 @@ char *vers;
sub != client->zct_subs;
sub = sub->q_forw) {
/* for each subscription */
- lyst[i * NUM_FIELDS] = sub->zst_class;
- lyst[i * NUM_FIELDS + 1] = sub->zst_classinst;
- lyst[i * NUM_FIELDS + 2] = sub->zst_recipient;
+ lyst[i * NUM_FIELDS] = sub->zst_dest.classname.value ();
+ lyst[i * NUM_FIELDS + 1] = sub->zst_dest.inst.value ();
+ lyst[i * NUM_FIELDS + 2] = sub->zst_dest.recip.value ();
i++;
if (i >= 7) {
/* we only put 7 in each packet, so we don't
@@ -1052,9 +1043,7 @@ char *vers;
*/
static int
-clt_unique(clt, clist)
-ZClient_t *clt;
-ZClientList_t *clist;
+clt_unique(ZClient_t *clt, ZClientList_t *clist)
{
register ZClientList_t *client;
@@ -1071,12 +1060,9 @@ ZClientList_t *clist;
*/
static int
-cl_match(notice, client)
-register ZNotice_t *notice;
-register ZClient_t *client;
+cl_match(register ZNotice_t *notice, register ZClient_t *client)
{
register ZSubscr_t *subs;
- int relation;
if (client->zct_subs == NULLZST) {
syslog(LOG_WARNING, "cl_match w/ no subs");
@@ -1087,15 +1073,20 @@ register ZClient_t *client;
subs != client->zct_subs;
subs = subs->q_forw) {
/* for each subscription, do matching */
- relation = strcasecmp(notice->z_class, subs->zst_class);
+#if 0
+ int relation;
+ relation = strcasecmp(notice->z_class,
+ subs->zst_class.value ());
if (relation > 0) /* past the last possible one */
return(0);
if (relation < 0)
continue; /* no match */
- if (strcmp(subs->zst_classinst, WILDCARD_INSTANCE) &&
- strcasecmp(subs->zst_classinst, notice->z_class_inst))
- continue;
- if (strcmp(notice->z_recipient, subs->zst_recipient))
+#endif
+ if (subs->zst_dest.inst != wildcard_instance
+ && strcasecmp(subs->zst_dest.inst.value (),
+ notice->z_class_inst))
+ continue;
+ if (strcmp(notice->z_recipient, subs->zst_dest.recip.value ()))
continue;
return(1);
}
@@ -1104,53 +1095,22 @@ register ZClient_t *client;
}
/*
- * Free up a subscription
- */
-
-static void
-free_sub(sub)
-ZSubscr_t *sub;
-{
- xfree(sub->zst_class);
- xfree(sub->zst_classinst);
- xfree(sub->zst_recipient);
- xfree(sub);
- return;
-}
-
-/*
* free the memory allocated for the list of subscriptions.
*/
static void
-free_subscriptions(subs)
-register ZSubscr_t *subs;
+free_subscriptions(register ZSubscr_t *subs)
{
register ZSubscr_t *sub;
for (sub = subs->q_forw; sub != subs; sub = subs->q_forw) {
xremque(sub);
- xfree(sub);
+ delete sub;
}
- xfree(subs);
+ delete subs;
return;
}
-/*
- * are the subscriptions the same? 1=yes, 0=no
- */
-
-static int
-subscr_equiv(s1, s2)
-register ZSubscr_t *s1, *s2;
-{
- if (strcasecmp(s1->zst_classinst,s2->zst_classinst))
- return(0);
- if (strcmp(s1->zst_recipient,s2->zst_recipient))
- return(0);
- return(1);
-}
-
#define ADVANCE(xx) { cp += (strlen(cp) + 1); \
if (cp >= notice->z_message + notice->z_message_len) { \
syslog(LOG_WARNING, "malformed subscription %d", xx); \
@@ -1163,60 +1123,45 @@ register ZSubscr_t *s1, *s2;
*/
static ZSubscr_t *
-extract_subscriptions(notice)
-register ZNotice_t *notice;
+extract_subscriptions(register ZNotice_t *notice)
{
register ZSubscr_t *subs = NULLZST, *subs2;
- register char *recip, *class, *classinst;
+ register char *recip, *class_name, *classinst;
register char *cp = notice->z_message;
/* parse the data area for the subscriptions */
while (cp < notice->z_message + notice->z_message_len) {
- class = cp;
+ class_name = cp;
if (*cp == '\0')
/* we've exhausted the subscriptions */
return(subs);
- /* we lowercase the class and class instance
- so we can be case insensitive on comparisons */
- while (*cp) {
- if (isupper(*cp))
- *cp = tolower(*cp);
- cp++;
- }
- cp = class;
ADVANCE(1);
classinst = cp;
- while (*cp) {
- if (isupper(*cp))
- *cp = tolower(*cp);
- cp++;
- }
- cp = classinst;
ADVANCE(2);
recip = cp;
- zdbug((LOG_DEBUG,"CLS: %s INST: %s RCPT: %s",
- class, classinst, cp));
+#if 0
+ zdbug((LOG_DEBUG, "ext_sub: CLS %s INST %s RCPT %s",
+ class_name, classinst, cp));
+#endif
cp += (strlen(cp) + 1);
if (cp > notice->z_message + notice->z_message_len) {
syslog(LOG_WARNING, "malformed sub 3");
return(subs);
}
if (!subs) {
- if (!(subs = (ZSubscr_t *) xmalloc(sizeof(ZSubscr_t)))) {
+ subs = new ZSubscr_t;
+ if (!subs) {
syslog(LOG_WARNING, "ex_subs: no mem");
return(NULLZST);
}
- subs->q_forw = subs->q_back = subs;
- subs->zst_class = subs->zst_classinst = subs->zst_recipient = NULL;
}
- if (!(subs2 = (ZSubscr_t *) xmalloc(sizeof(ZSubscr_t)))) {
+ subs2 = new ZSubscr_t (ZString (class_name, 1),
+ ZString (classinst, 1),
+ ZString (recip));
+ if (!subs2) {
syslog(LOG_WARNING, "ex_subs: no mem 2");
return(subs);
}
- subs2->zst_class = class;
- subs2->zst_classinst = classinst;
- subs2->zst_recipient = recip;
- subs2->q_forw = subs2->q_back = subs2;
xinsque(subs2, subs);
}
@@ -1230,9 +1175,7 @@ register ZNotice_t *notice;
*/
void
-subscr_dump_subs(fp, subs)
-FILE *fp;
-ZSubscr_t *subs;
+subscr_dump_subs(FILE *fp, ZSubscr_t *subs)
{
register ZSubscr_t *ptr;
@@ -1241,11 +1184,11 @@ ZSubscr_t *subs;
for (ptr = subs->q_forw; ptr != subs; ptr = ptr->q_forw) {
fputs("\t\t'", fp);
- fputs(ptr->zst_class, fp);
+ fputs(ptr->zst_dest.classname.value (), fp);
fputs("' '", fp);
- fputs(ptr->zst_classinst, fp);
+ fputs(ptr->zst_dest.inst.value (), fp);
fputs("' '", fp);
- fputs(ptr->zst_recipient, fp);
+ fputs(ptr->zst_dest.recip.value (), fp);
fputs("'\n", fp);
}
return;