From 60cd1ff0635fdeda3c5a2cafee2d9a53f82cae0d Mon Sep 17 00:00:00 2001 From: Karl Ramm Date: Sun, 15 Mar 2009 22:13:16 +0000 Subject: cmu/zwgcplus changes --- clients/zctl/zctl.c | 238 +++++++++++++++++++++++++++++++++++++++++++++- clients/zctl/zctl_cmds.ct | 10 ++ 2 files changed, 246 insertions(+), 2 deletions(-) (limited to 'clients') diff --git a/clients/zctl/zctl.c b/clients/zctl/zctl.c index e48a651..9624550 100644 --- a/clients/zctl/zctl.c +++ b/clients/zctl/zctl.c @@ -660,6 +660,10 @@ load_subs(int argc, char *argv[]) { ZSubscription_t subs[SUBSATONCE],subs2[SUBSATONCE],unsubs[SUBSATONCE]; +#ifdef CMU_ZCTL_PUNT + ZSubscription_t punts[SUBSATONCE]; + int pind; +#endif FILE *fp; int ind,unind,lineno,i,retval,type; short wgport; @@ -695,7 +699,10 @@ load_subs(int argc, return; } - ind = unind = 0; +#ifdef CMU_ZCTL_PUNT + pind = +#endif + ind = unind = 0; lineno = 1; for (;;lineno++) { @@ -721,6 +728,11 @@ load_subs(int argc, if (*subline == '!') printf("(Un-subscription) Class %s instance %s recipient %s\n", subline+1, comma+1, comma2+1); +#ifdef CMU_ZCTL_PUNT + else if(*subline == '-') + printf("(Punted) Class %s instance %s recipient %s\n", + subline+1, comma+1, comma2+1); +#endif else printf("Class %s instance %s recipient %s\n", subline, comma+1, comma2+1); @@ -746,7 +758,27 @@ load_subs(int argc, /* XXX check malloc return */ (void) strcpy(unsubs[unind].zsub_recipient,comma2+1); unind++; - } else { + } else +#ifdef CMU_ZCTL_PUNT + if (*subline == '-') { /* a punt */ + if (type == UNSUB) + continue; + punts[pind].zsub_class = + (char *)malloc((unsigned)(strlen(subline)+1)); + /* XXX check malloc return */ + (void) strcpy(punts[pind].zsub_class,subline+1); + punts[pind].zsub_classinst = + (char *)malloc((unsigned)(strlen(comma+1)+1)); + /* XXX check malloc return */ + (void) strcpy(punts[pind].zsub_classinst,comma+1); + punts[pind].zsub_recipient = + (char *)malloc((unsigned)(strlen(comma2+1)+1)); + /* XXX check malloc return */ + (void) strcpy(punts[pind].zsub_recipient,comma2+1); + pind++; + } else +#endif + { subs[ind].zsub_class = (char *)malloc((unsigned)(strlen(subline)+1)); /* XXX check malloc return */ @@ -761,6 +793,24 @@ load_subs(int argc, (void) strcpy(subs[ind].zsub_recipient,comma2+1); ind++; } +#ifdef CMU_ZCTL_PUNT + if (pind == SUBSATONCE) { + fix_macros(punts,subs2,pind); + if (retval = ZPunt(subs2,pind,(u_short)wgport) != + ZERR_NONE) + { + ss_perror(sci_idx,retval, + "while punting"); + goto cleanup; + } + for (i=0;i\n", punt ? "Punting" : "Unpunting", + class, inst, *recip ? recip : "*"); + + memset((char *) ¬ice, 0, sizeof(ZNotice_t)); + notice.z_kind = UNSAFE; + notice.z_class = WG_CTL_CLASS; + notice.z_class_inst = WG_CTL_USER; + notice.z_recipient = ""; + notice.z_default_format = ""; + notice.z_opcode = (punt) ? "SUPPRESS" : "UNSUPPRESS"; + notice.z_port = 0; + notice.z_message = msg; + notice.z_message_len = strlen(class)+strlen(inst)+strlen(recip)+3; + + if ((retval = ZSendNotice(¬ice,ZNOAUTH)) != ZERR_NONE) + fprintf(stderr,"%s: while sending notice\n",whoami); + + free(msg); + + ZClosePort(); +#endif + return 0; +} + +list_punts(argc, argv) +int argc; +char **argv; +{ +#ifdef CMU_ZCTL_PUNT + ZNotice_t notice; + int retval, lensofar; + struct sockaddr_in old, to, from; + u_short ourport, zwgcport; + char *msg; + + ourport=0; + retval = ZOpenPort(&ourport); + if(retval != ZERR_NONE) { + com_err("zctl", retval, "while opening Zephyr port."); + return 1; + } + + old = ZGetDestAddr(); + to = old; + if ((zwgcport = ZGetWGPort()) == (u_short)-1) { + fprintf(stderr, "zctl: Can't find windowgram port\n"); + return 1; + } + + to.sin_port = (u_short) zwgcport; + if ((retval = ZSetDestAddr(&to)) != ZERR_NONE) { + com_err("zctl",retval,"while setting destination address"); + return 1; + } + + memset((char *) ¬ice, 0, sizeof(ZNotice_t)); + notice.z_kind = UNSAFE; + notice.z_class = WG_CTL_CLASS; + notice.z_class_inst = WG_CTL_USER; + notice.z_recipient = ""; + notice.z_default_format = ""; + notice.z_opcode = "LIST-SUPPRESSED" /*USER_LIST_SUPPRESSED*/; + notice.z_port = ourport; + notice.z_message = NULL; + notice.z_message_len = 0; + + if ((retval = ZSendNotice(¬ice,ZNOAUTH)) != ZERR_NONE) + com_err("zctl",retval,"while sending notice"); + + if ((retval = ZReceiveNotice(¬ice,&from)) != ZERR_NONE) + com_err("zctl",retval,"while receiving ack"); + + (void) ZFreeNotice(¬ice); + + if ((retval = ZReceiveNotice(¬ice,&from)) != ZERR_NONE) + com_err("zctl",retval,"while receiving notice"); + + notice.z_auth = ZCheckAuthentication(¬ice, &from); + + if ((retval = ZSetDestAddr(&old)) != ZERR_NONE) { + com_err("zctl",retval,"while resetting destination address"); + return 1; + } + + msg = (char *) malloc((notice.z_message_len+1) * sizeof(char)); + (void) strncpy(msg,notice.z_message, notice.z_message_len); + msg[notice.z_message_len]=(char)0; + printf("%s", msg); + (void) free(msg); + (void) ZFreeNotice(¬ice); + (void) ZClosePort(); + +#endif /* CMU_ZCTL_PUNT */ + return 0; +} diff --git a/clients/zctl/zctl_cmds.ct b/clients/zctl/zctl_cmds.ct index 374effc..2f7bbbb 100644 --- a/clients/zctl/zctl_cmds.ct +++ b/clients/zctl/zctl_cmds.ct @@ -84,5 +84,15 @@ request ss_quit, "Quit.", quit, exit, q; +#ifdef CMU_BACKWARD_COMPAT + request do_punt, "Ignore specified messages.", + punt; + request do_punt, "Stop ignoring specified messages.", + unpunt; + + request list_punts, "List current messages to ignore.", + list_punts, lp; + +#endif end; -- cgit v1.2.3