summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clients/zlocate/zlocate.c35
-rw-r--r--clients/zstat/zstat.c53
-rw-r--r--clients/zwrite/zwrite.c174
3 files changed, 198 insertions, 64 deletions
diff --git a/clients/zlocate/zlocate.c b/clients/zlocate/zlocate.c
index e2ed5a8..3e06dd6 100644
--- a/clients/zlocate/zlocate.c
+++ b/clients/zlocate/zlocate.c
@@ -1,5 +1,5 @@
/* This file is part of the Project Athena Zephyr Notification System.
- * It contains code for the "locate" command.
+ * It contains code for the "zlocate" command.
*
* Created by: Robert French
*
@@ -16,7 +16,7 @@
#include <zephyr/zephyr.h>
#ifndef lint
-static char rcsid_locate_c[] = "$Header$";
+static char rcsid_zlocate_c[] = "$Header$";
#endif lint
main(argc,argv)
@@ -25,7 +25,7 @@ main(argc,argv)
{
int retval,numlocs,i,one,ourargc;
char *whoami,bfr[BUFSIZ],user[BUFSIZ];
- ZLocations_t locations[1];
+ ZLocations_t locations;
whoami = argv[0];
@@ -60,13 +60,13 @@ main(argc,argv)
if (ourargc > 1)
printf("\t%s:\n",user);
if (!numlocs) {
- printf("Not logged-in\n");
+ printf("Hidden or not logged-in\n");
if (argc)
printf("\n");
continue;
}
for (i=0;i<numlocs;i++) {
- if ((retval = ZGetLocations(locations,&one))
+ if ((retval = ZGetLocations(&locations,&one))
!= ZERR_NONE) {
com_err(whoami,retval,
"while getting location");
@@ -75,12 +75,31 @@ main(argc,argv)
if (one != 1) {
printf("%s: internal failure while getting location\n",whoami);
exit(1);
- }
- printf("%s\t %s\n",locations[0].host,
- locations[0].time);
+ }
+ print_pad(locations.host,43);
+ print_pad(locations.tty,8);
+ printf("%s\n",locations.time);
}
if (argc)
printf("\n");
ZFlushLocations();
}
}
+
+print_pad(s,n)
+ char *s;
+ int n;
+{
+ char bfr[81];
+ int num;
+
+ strcpy(bfr," ");
+
+ if (strlen(s) < n)
+ num = n-strlen(s);
+ else
+ num = 0;
+
+ bfr[num] = '\0';
+ printf("%s%s",s,bfr);
+}
diff --git a/clients/zstat/zstat.c b/clients/zstat/zstat.c
index c6b4db1..ed0a925 100644
--- a/clients/zstat/zstat.c
+++ b/clients/zstat/zstat.c
@@ -43,6 +43,7 @@ char *srv_head[20] = {
};
int serveronly = 0,hmonly = 0;
+int outoftime = 0;
u_short hm_port,srv_port;
main(argc, argv)
@@ -55,7 +56,7 @@ main(argc, argv)
char hostname[MAXHOSTNAMELEN];
char *host = NULL;
char *srv_name;
- char optchar;
+ int optchar;
struct servent *sp;
int ml, i, nitems;
extern char *optarg;
@@ -130,7 +131,8 @@ do_stat(host)
return;
}
- hm_stat(host,srv_host);
+ if (hm_stat(host,srv_host))
+ return;
if (!hmonly)
srv_stat(srv_host);
@@ -147,6 +149,7 @@ hm_stat(host,server)
struct tm *tim;
ZNotice_t notice;
ZPacket_t packet;
+ extern int timeout();
bzero(&sin,sizeof(struct sockaddr_in));
@@ -174,6 +177,7 @@ hm_stat(host,server)
notice.z_opcode = HM_GIMMESTATS;
notice.z_sender = "";
notice.z_recipient = "";
+ notice.z_default_format = "";
notice.z_message_len = 0;
if ((ret = ZSetDestAddr(&sin)) != ZERR_NONE) {
@@ -185,12 +189,21 @@ hm_stat(host,server)
exit(-1);
}
- if ((ret = ZReceiveNotice(packet, sizeof packet, &notice,
- NULL, NULL)) != ZERR_NONE) {
+ signal(SIGALRM,timeout);
+ outoftime = 0;
+ alarm(10);
+ if (((ret = ZReceiveNotice(packet, sizeof packet, &notice,
+ NULL)) != ZERR_NONE) &&
+ ret != EINTR) {
com_err("zstat", ret, "receiving notice");
- exit(1);
+ return (1);
}
-
+ alarm(0);
+ if (outoftime) {
+ fprintf(stderr,"No response after 10 seconds.\n");
+ return (1);
+ }
+
mp = notice.z_message;
for (nf=0;mp<notice.z_message+notice.z_message_len;nf++) {
line[nf] = mp;
@@ -203,7 +216,7 @@ hm_stat(host,server)
if (!strncmp("Time",head[i],4)) {
runtime = atol(line[i]);
tim = gmtime(&runtime);
- printf("%s %d days, %02d:%02d:%02d", head[i],
+ printf("%s %d days, %02d:%02d:%02d\n", head[i],
tim->tm_yday,
tim->tm_hour,
tim->tm_min,
@@ -229,6 +242,7 @@ srv_stat(host)
ZPacket_t packet;
long runtime;
struct tm *tim;
+ extern int timeout();
bzero(&sin,sizeof(struct sockaddr_in));
@@ -256,6 +270,7 @@ srv_stat(host)
notice.z_opcode = ADMIN_STATUS;
notice.z_sender = "";
notice.z_recipient = "";
+ notice.z_default_format = "";
notice.z_message_len = 0;
if ((ret = ZSetDestAddr(&sin)) != ZERR_NONE) {
@@ -267,12 +282,21 @@ srv_stat(host)
exit(-1);
}
- if ((ret = ZReceiveNotice(packet, sizeof packet, &notice,
- NULL, NULL)) != ZERR_NONE) {
+ signal(SIGALRM,timeout);
+ outoftime = 0;
+ alarm(10);
+ if (((ret = ZReceiveNotice(packet, sizeof packet, &notice,
+ NULL)) != ZERR_NONE) &&
+ ret != EINTR) {
com_err("zstat", ret, "receiving notice");
- exit(1);
+ return (1);
}
-
+ alarm(0);
+ if (outoftime) {
+ fprintf(stderr,"No response after 10 seconds.\n");
+ return (1);
+ }
+
mp = notice.z_message;
for (nf=0;mp<notice.z_message+notice.z_message_len;nf++) {
line[nf] = mp;
@@ -296,6 +320,8 @@ srv_stat(host)
printf("%s\n",line[i]);
} else printf("%s\n",line[i]);
}
+ printf("\n");
+
close(sock);
}
@@ -305,3 +331,8 @@ usage(s)
fprintf(stderr,"usage: %s [-s] [-h] [host ...]\n",s);
exit(1);
}
+
+timeout()
+{
+ outoftime = 1;
+}
diff --git a/clients/zwrite/zwrite.c b/clients/zwrite/zwrite.c
index 7d763af..2243d29 100644
--- a/clients/zwrite/zwrite.c
+++ b/clients/zwrite/zwrite.c
@@ -1,5 +1,5 @@
/* This file is part of the Project Athena Zephyr Notification System.
- * It contains code for the "sendmsg" command.
+ * It contains code for the "zwrite" command.
*
* Created by: Robert French
*
@@ -16,10 +16,10 @@
#include <zephyr/zephyr.h>
#ifndef lint
-static char rcsid_sendmsg_c[] = "$Header$";
+static char rcsid_zwrite_c[] = "$Header$";
#endif lint
-#define FUDGEFACTOR 150
+#define FUDGEFACTOR 20
#define MESSAGE_CLASS "MESSAGE"
#define PERSONAL "PERSONAL"
#define URGENT "URGENT"
@@ -30,8 +30,10 @@ main(argc,argv)
{
ZNotice_t notice,retnotice;
ZPacket_t buffer;
- int retval,auth,verbose,urgent;
- char *whoami,bfr[BUFSIZ],message[Z_MAXPKTLEN],*ptr;
+ int retval,verbose,quiet,len,arg,msgarg,nrecips,everyone;
+ long ourtime;
+ int (*auth)();
+ char *whoami,bfr[BUFSIZ],message[Z_MAXPKTLEN],*ptr,*inst;
whoami = argv[0];
@@ -39,99 +41,181 @@ main(argc,argv)
com_err(whoami,retval,"while initializing");
exit(1);
}
+
+ if (argc < 2)
+ usage(whoami);
+
+ bzero(&notice,sizeof(ZNotice_t));
+
+ auth = ZNOAUTH;
+ verbose = quiet = msgarg = nrecips = everyone = 0;
+
+ inst = PERSONAL;
- auth = verbose = urgent = 0;
+ arg = 1;
- for (argv++,argc--;argc;argc--,argv++) {
- if (**argv != '-')
- break;
- if (strlen(argv[0]) > 2)
+ for (;arg<argc&&!msgarg;arg++) {
+ if (*argv[arg] != '-') {
+ nrecips++;
+ everyone = 0;
+ continue;
+ }
+ if (strlen(argv[arg]) > 2)
usage(whoami);
- switch (*(*argv+1)) {
+ switch (argv[arg][1]) {
case 'a':
- auth = 1;
+ auth = ZAUTH;
break;
case 'v':
verbose = 1;
break;
+ case 'q':
+ quiet = 1;
+ break;
case 'u':
- urgent = 1;
+ inst = URGENT;
+ break;
+ case 'i':
+ if (arg == argc-1)
+ usage(whoami);
+ arg++;
+ inst = argv[arg];
+ everyone = 1;
+ break;
+ case 'm':
+ if (arg == argc-1)
+ usage(whoami);
+ msgarg = arg+1;
break;
default:
usage(whoami);
}
}
+
+ if (!nrecips && !everyone) {
+ fprintf(stderr,"No recipients specified.\n");
+ exit (1);
+ }
- if (argc < 1)
- usage(whoami);
+ if (!msgarg && isatty(0))
+ printf("Type your message now. End with control-D or a dot on a line by itself.\n");
notice.z_kind = ACKED;
notice.z_port = 0;
notice.z_class = MESSAGE_CLASS;
- notice.z_class_inst = urgent?URGENT:PERSONAL;
+ notice.z_class_inst = inst;
notice.z_opcode = "";
notice.z_sender = 0;
-
- printf("Type your message now. End with a control-D.\n");
+ notice.z_default_format = "Message from $sender at $time:\n\n$1";
+ notice.z_message_len = 0;
+ notice.z_recipient = "foobar";
+ if ((retval = ZFormatNotice(&notice,buffer,sizeof buffer,&len,
+ auth)) != ZERR_NONE) {
+ com_err(whoami,retval,"formatting notice");
+ exit(1);
+ }
ptr = message;
- for (;;) {
- if (!gets(bfr))
- break;
- if (strlen(bfr)+(ptr-message)+2 > Z_MAXPKTLEN-FUDGEFACTOR) {
- printf("Your message is too long. It will be truncated at this line.\n");
- break;
+ if (msgarg) {
+ for (arg=msgarg;arg<argc;arg++) {
+ strcpy(ptr,argv[arg]);
+ if (arg != argc-1)
+ strcat(ptr," ");
+ ptr += strlen(ptr);
}
- strcpy(ptr,bfr);
- ptr += strlen(ptr);
*ptr++ = '\n';
+ *ptr++ = '\0';
}
+ else {
+ for (;;) {
+ if (!fgets(bfr,sizeof bfr,stdin))
+ break;
+ bfr[strlen(bfr)-1] = '\0';
+ if (bfr[0] == '.' && bfr[1] == '\0')
+ break;
+ if (strlen(bfr)+(ptr-message) > Z_MAXPKTLEN-len-FUDGEFACTOR) {
+ if (isatty(0))
+ printf("Your message is too long. It will be truncated at this line.\n");
+ else
+ printf("Message too long. Truncated.\n");
+ break;
+ }
+ strcpy(ptr,bfr);
+ ptr += strlen(ptr);
+ *ptr++ = '\n';
+ }
- *ptr++ = '\0';
-
+ *ptr++ = '\0';
+ }
+
notice.z_message = message;
notice.z_message_len = ptr-message;
- while (argc--) {
- notice.z_recipient = *(argv++);
+ for (arg=1;everyone||(arg<argc&&!(msgarg&&arg>=msgarg));arg++) {
+ if (*argv[arg] == '-' && !everyone)
+ continue;
+ if (!strcmp(argv[arg-1],"-i") && !everyone)
+ continue;
+ notice.z_recipient = everyone?"":argv[arg];
if (verbose)
- printf("Sending %s%smessage to %s\n",
+ printf("Sending %smessage, instance %s, to %s\n",
auth?"authenticated ":"",
- urgent?"urgent ":"",notice.z_recipient);
+ inst,everyone?"everyone":notice.z_recipient);
if ((retval = ZSendNotice(&notice,auth)) != ZERR_NONE) {
sprintf(bfr,"while sending notice to %s",
- notice.z_recipient);
+ everyone?inst:notice.z_recipient);
com_err(whoami,retval,bfr);
continue;
}
- if ((retval = ZIfNotice(buffer,sizeof buffer,&retnotice,0,
- ZCompareUIDPred,
+ if ((retval = ZIfNotice(buffer,sizeof buffer,&retnotice,
+ 0,ZCompareUIDPred,
(char *)&notice.z_uid)) !=
ZERR_NONE) {
sprintf(bfr,"while waiting for SERVACK for %s",
- notice.z_recipient);
+ everyone?inst:notice.z_recipient);
com_err(whoami,retval,bfr);
continue;
}
if (retnotice.z_kind == SERVNAK) {
- printf("Received SERVNAK for %s\n",
- notice.z_recipient);
+ printf("Received authentication failure while sending to %s\n",
+ everyone?inst:notice.z_recipient);
continue;
}
- if (retnotice.z_kind != SERVACK) {
- printf("Internal failure while receiving SERVACK for %s\n",
- notice.z_recipient);
+ if (retnotice.z_kind != SERVACK || !retnotice.z_message_len) {
+ printf("Detected server failure while receiving SERVACK for %s\n",
+ everyone?inst:notice.z_recipient);
continue;
- }
- if (verbose)
- printf("Successful.\n");
+ }
+ if (!quiet)
+ if (!strcmp(retnotice.z_message,ZSRVACK_SENT)) {
+ if (verbose)
+ printf("Successful\n");
+ else
+ printf("%s: Message sent\n",
+ everyone?inst:notice.z_recipient);
+ }
+ else
+ if (!strcmp(retnotice.z_message,
+ ZSRVACK_NOTSENT)) {
+ if (verbose)
+ printf("Not logged in or subscribing to messages\n");
+ else
+ if (everyone)
+ printf("%s: No one subscribing to this instance\n",inst);
+ else
+ printf("%s: Not logged in or not subscribing to messages\n",notice.z_recipient);
+ }
+ else
+ printf("Internal failure - illegal message field in server response\n");
+ if (everyone)
+ break;
}
}
usage(s)
char *s;
{
- printf("Usage: %s [-a] [-v] [-u] user ...\n",s);
+ printf("Usage: %s [-a] [-v] [-q] [-u] [-i inst] [user ...] [-m message]\n",s);
exit(1);
}