summaryrefslogtreecommitdiff
path: root/clients/zwrite
diff options
context:
space:
mode:
authorGravatar John Kohl <jtkohl@mit.edu>1988-06-16 06:49:21 +0000
committerGravatar John Kohl <jtkohl@mit.edu>1988-06-16 06:49:21 +0000
commit67fe835826b8555cdc140e95c305fb8db631f1f4 (patch)
tree1afbdfe65d4c0907315e37867dda44d6d5a5a842 /clients/zwrite
parentaafcff885ece02ef65f5cdccc228bbfa6696f3a3 (diff)
library updates (from rfrench)
Diffstat (limited to 'clients/zwrite')
-rw-r--r--clients/zwrite/zwrite.c495
1 files changed, 243 insertions, 252 deletions
diff --git a/clients/zwrite/zwrite.c b/clients/zwrite/zwrite.c
index b66738a..8771cfc 100644
--- a/clients/zwrite/zwrite.c
+++ b/clients/zwrite/zwrite.c
@@ -19,7 +19,6 @@
static char rcsid_zwrite_c[] = "$Header$";
#endif lint
-#define FUDGEFACTOR 10
#define DEFAULT_CLASS "MESSAGE"
#define DEFAULT_INSTANCE "PERSONAL"
#define URGENT_INSTANCE "URGENT"
@@ -30,290 +29,282 @@ int nrecips, msgarg, verbose, quiet;
char *whoami, *inst, *class, *recips[MAXRECIPS];
int (*auth)();
-char *getenv();
+char *malloc(), *realloc();
-main(argc,argv)
- int argc;
- char *argv[];
+main(argc, argv)
+ int argc;
+ char *argv[];
{
- ZNotice_t notice, retnotice;
- ZPacket_t buffer;
- int retval, len, arg, nocheck, nchars, maxlen;
- long ourtime;
- char bfr[BUFSIZ], message[Z_MAXPKTLEN], *ptr, *signature;
- char classbfr[BUFSIZ], instbfr[BUFSIZ], sigbfr[BUFSIZ];
+ ZNotice_t notice, retnotice;
+ char *buffer;
+ int retval, len, arg, nocheck, nchars, msgsize;
+ long ourtime;
+ char bfr[BUFSIZ], *message, *ptr, *signature;
+ char classbfr[BUFSIZ], instbfr[BUFSIZ], sigbfr[BUFSIZ];
- whoami = argv[0];
+ whoami = argv[0];
- if ((retval = ZInitialize()) != ZERR_NONE) {
- com_err(whoami, retval, "while initializing");
- exit(1);
- }
+ if ((retval = ZInitialize()) != ZERR_NONE) {
+ com_err(whoami, retval, "while initializing");
+ exit(1);
+ }
- if (argc < 2)
- usage(whoami);
+ if (argc < 2)
+ usage(whoami);
- bzero(&notice, sizeof(ZNotice_t));
+ bzero(&notice, sizeof(ZNotice_t));
- maxlen = Z_MAXPKTLEN-FUDGEFACTOR;
- auth = ZAUTH;
- verbose = quiet = msgarg = nrecips = nocheck = 0;
+ auth = ZAUTH;
+ verbose = quiet = msgarg = nrecips = nocheck = 0;
- if (class = ZGetVariable("zwrite-class")) {
- strcpy(classbfr, class);
- class = classbfr;
- }
- else
- class = DEFAULT_CLASS;
- if (inst = ZGetVariable("zwrite-inst")) {
- strcpy(instbfr, inst);
- inst = instbfr;
- }
- else
- inst = DEFAULT_INSTANCE;
- signature = ZGetVariable("zwrite-signature");
- if (signature) {
- strcpy(sigbfr, signature);
- signature = sigbfr;
- maxlen -= strlen(signature)+1;
- }
+ if (class = ZGetVariable("zwrite-class")) {
+ strcpy(classbfr, class);
+ class = classbfr;
+ }
+ else
+ class = DEFAULT_CLASS;
+ if (inst = ZGetVariable("zwrite-inst")) {
+ strcpy(instbfr, inst);
+ inst = instbfr;
+ }
+ else
+ inst = DEFAULT_INSTANCE;
+ signature = ZGetVariable("zwrite-signature");
+ if (signature) {
+ strcpy(sigbfr, signature);
+ signature = sigbfr;
+ }
- arg = 1;
+ arg = 1;
- for (;arg<argc&&!msgarg;arg++) {
- if (*argv[arg] != '-') {
- recips[nrecips++] = argv[arg];
- continue;
- }
- if (strlen(argv[arg]) > 2)
- usage(whoami);
- switch (argv[arg][1]) {
- case 'a': /* Backwards compatibility */
- break;
- case 'o':
- class = DEFAULT_CLASS;
- inst = DEFAULT_INSTANCE;
- break;
- case 'd':
- auth = ZNOAUTH;
- break;
- case 'v':
- verbose = 1;
- break;
- case 'q':
- quiet = 1;
- break;
- case 'n':
- nocheck = 1;
- break;
- case 'u':
- inst = URGENT_INSTANCE;
- break;
- case 'i':
- if (arg == argc-1)
- usage(whoami);
- arg++;
- inst = argv[arg];
- break;
- case 'c':
- if (arg == argc-1)
- usage(whoami);
- arg++;
- class = argv[arg];
- break;
- case 'm':
- if (arg == argc-1)
- usage(whoami);
- msgarg = arg+1;
- break;
- default:
- usage(whoami);
- }
- }
-
- if (!nrecips && !(strcmp(class, DEFAULT_CLASS) ||
- strcmp(inst, DEFAULT_INSTANCE))) {
- fprintf(stderr, "No recipients specified.\n");
- exit (1);
+ for (;arg<argc&&!msgarg;arg++) {
+ if (*argv[arg] != '-') {
+ recips[nrecips++] = argv[arg];
+ continue;
+ }
+ if (strlen(argv[arg]) > 2)
+ usage(whoami);
+ switch (argv[arg][1]) {
+ case 'a': /* Backwards compatibility */
+ break;
+ case 'o':
+ class = DEFAULT_CLASS;
+ inst = DEFAULT_INSTANCE;
+ break;
+ case 'd':
+ auth = ZNOAUTH;
+ break;
+ case 'v':
+ verbose = 1;
+ break;
+ case 'q':
+ quiet = 1;
+ break;
+ case 'n':
+ nocheck = 1;
+ break;
+ case 'u':
+ inst = URGENT_INSTANCE;
+ break;
+ case 'i':
+ if (arg == argc-1)
+ usage(whoami);
+ arg++;
+ inst = argv[arg];
+ break;
+ case 'c':
+ if (arg == argc-1)
+ usage(whoami);
+ arg++;
+ class = argv[arg];
+ break;
+ case 'm':
+ if (arg == argc-1)
+ usage(whoami);
+ msgarg = arg+1;
+ break;
+ default:
+ usage(whoami);
}
+ }
- notice.z_kind = ACKED;
- notice.z_port = 0;
- notice.z_class = class;
- notice.z_class_inst = inst;
- notice.z_opcode = "PING";
- notice.z_sender = 0;
- notice.z_message_len = 0;
- notice.z_recipient = "";
- notice.z_default_format = "";
+ if (!nrecips && !(strcmp(class, DEFAULT_CLASS) ||
+ strcmp(inst, DEFAULT_INSTANCE))) {
+ fprintf(stderr, "No recipients specified.\n");
+ exit (1);
+ }
- if (!nocheck)
- send_off(&notice, 0);
-
- 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 = class;
+ notice.z_class_inst = inst;
+ notice.z_opcode = "PING";
+ notice.z_sender = 0;
+ notice.z_message_len = 0;
+ notice.z_recipient = "";
+ notice.z_default_format = "";
- notice.z_opcode = "";
- notice.z_recipient = "foobar12";
- if (signature)
- notice.z_default_format = "Message from $1 <$sender> at $time:\n\n$2";
- else
- notice.z_default_format = "Message from $sender at $time:\n\n$2";
+ if (!nocheck)
+ send_off(&notice, 0);
- if ((retval = ZFormatNotice(&notice, buffer, sizeof buffer, &len,
- auth)) != ZERR_NONE) {
- com_err(whoami, retval, "formatting notice");
- exit(1);
- }
+ if (!msgarg && isatty(0))
+ printf("Type your message now. End with control-D or a dot on a line by itself.\n");
- maxlen -= len;
+ if (signature) {
+ message = malloc(strlen(signature)+1);
+ strcpy(message, signature);
+ msgsize = strlen(message)+1;
+ }
+ else {
+ message = malloc(1);
+ message[0] = '\0';
+ msgsize = 1;
+ }
- if (signature) {
- strcpy(message, signature);
- ptr = message+strlen(message)+1;
+ if (msgarg) {
+ for (arg=msgarg;arg<argc;arg++) {
+ message = realloc(message, msgsize+strlen(argv[arg])+
+ (arg != argc-1)?2:1);
+ strcpy(message+msgsize, argv[arg]);
+ msgsize += strlen(argv[arg]);
+ if (arg != argc-1) {
+ strcpy(message+msgsize+1, " ");
+ msgsize++;
+ }
}
- else {
- message[0] = '\0';
- ptr = message+1;
- }
-
- if (msgarg) {
- for (arg=msgarg;arg<argc;arg++) {
- strcpy(ptr, argv[arg]);
- if (arg != argc-1)
- strcat(ptr, " ");
- ptr += strlen(ptr);
- }
- *ptr++ = '\n';
- *ptr++ = '\0';
+ message = realloc(message, msgsize+2);
+ message[msgsize] = '\n';
+ message[msgsize+1] = '\0';
+ msgsize += 2;
+ }
+ else {
+ if (isatty(0)) {
+ for (;;) {
+ if (!fgets(bfr, sizeof bfr, stdin))
+ break;
+ if (bfr[0] == '.' &&
+ (bfr[1] == '\n' || bfr[1] == '\0'))
+ break;
+ message = realloc(message, msgsize+
+ strlen(bfr));
+ strcpy(message+msgsize, bfr);
+ msgsize += strlen(bfr);
+ }
+ message = realloc(message, msgsize+1);
+ message[msgsize] = '\0';
}
- else {
- if (isatty(0)) {
- for (;;) {
- if (!fgets(bfr, sizeof bfr, stdin))
- break;
- if (bfr[0] == '.' &&
- (bfr[1] == '\n' || bfr[1] == '\0'))
- break;
- if (strlen(bfr)+(ptr-message) > maxlen) {
- printf("Your message is too long. It will be truncated at this line.\n");
- break;
- }
- strcpy(ptr, bfr);
- ptr += strlen(ptr);
- }
- *ptr++ = '\0';
+ else { /* Use read so you can send binary messages... */
+ while (nchars = read(fileno(stdin), bfr, sizeof bfr)) {
+ if (nchars == -1) {
+ fprintf(stderr, "Read error from stdin! Can't continue!\n");
+ exit(1);
}
- else { /* Use read so you can send binary messages... */
- nchars = read(fileno(stdin), ptr, maxlen+1);
- if (nchars == -1) {
- fprintf(stderr, "Read error from stdin! Can't continue!\n");
- exit(1);
- }
- if (nchars > maxlen) {
- printf("Message too long. Truncated.\n");
- nchars = maxlen;
- }
- ptr += nchars;
- }
- }
+ message = realloc(message, msgsize+nchars);
+ bcopy(bfr, message+msgsize, nchars);
+ msgsize += nchars;
+ }
+ }
+ }
- notice.z_message = message;
- notice.z_message_len = ptr-message;
+ notice.z_opcode = "";
+ notice.z_message = message;
+ notice.z_message_len = msgsize;
- send_off(&notice, 1);
+ send_off(&notice, 1);
}
send_off(notice, real)
- ZNotice_t *notice;
- int real;
+ ZNotice_t *notice;
+ int real;
{
- int i, success, retval;
- char bfr[BUFSIZ];
- ZPacket_t buffer;
- ZNotice_t retnotice;
+ int i, success, retval;
+ char bfr[BUFSIZ];
+ char *buffer;
+ ZNotice_t retnotice;
- success = 0;
+ success = 0;
- for (i=0;i<nrecips || !nrecips;i++) {
- notice->z_recipient = nrecips?recips[i]:"";
- if (verbose && real)
- printf("Sending %smessage, class %s, instance %s, to %s\n",
- auth?"authenticated ":"",
- class, inst,
- nrecips?notice->z_recipient:"everyone");
- if ((retval = ZSendNotice(notice, real?auth:ZNOAUTH)) != ZERR_NONE) {
- sprintf(bfr,"while sending notice to %s",
- nrecips?notice->z_recipient:inst);
- com_err(whoami, retval, bfr);
- continue;
- }
- if ((retval = ZIfNotice(buffer, sizeof buffer, &retnotice,
- 0, ZCompareUIDPred,
- (char *)&notice->z_uid)) !=
- ZERR_NONE) {
- sprintf(bfr, "while waiting for acknowledgement for %s",
- nrecips?notice->z_recipient:inst);
- com_err(whoami, retval, bfr);
- continue;
- }
- if (retnotice.z_kind == SERVNAK) {
- printf("Received authentication failure while sending to %s\n",
- nrecips?notice->z_recipient:inst);
- continue;
- }
- if (retnotice.z_kind != SERVACK || !retnotice.z_message_len) {
- printf("Detected server failure while receiving acknowledgement for %s\n",
+ for (i=0;i<nrecips || !nrecips;i++) {
+ notice->z_recipient = nrecips?recips[i]:"";
+ if (verbose && real)
+ printf("Sending %smessage, class %s, instance %s, to %s\n",
+ auth?"authenticated ":"",
+ class, inst,
+ nrecips?notice->z_recipient:"everyone");
+ if ((retval = ZSendNotice(notice, real?auth:ZNOAUTH)) != ZERR_NONE) {
+ sprintf(bfr, "while sending notice to %s",
+ nrecips?notice->z_recipient:inst);
+ com_err(whoami, retval, bfr);
+ continue;
+ }
+ if ((retval = ZIfNotice(&retnotice,
+ 0, ZCompareUIDPred,
+ (char *)&notice->z_uid)) !=
+ ZERR_NONE) {
+ ZFreeNotice(&retnotice);
+ sprintf(bfr, "while waiting for acknowledgement for %s",
+ nrecips?notice->z_recipient:inst);
+ com_err(whoami, retval, bfr);
+ continue;
+ }
+ ZFreeNotice(&retnotice);
+ if (retnotice.z_kind == SERVNAK) {
+ printf("Received authentication failure while sending to %s\n",
+ nrecips?notice->z_recipient:inst);
+ continue;
+ }
+ if (retnotice.z_kind != SERVACK || !retnotice.z_message_len) {
+ printf("Detected server failure while receiving acknowledgement for %s\n",
+ nrecips?notice->z_recipient:inst);
+ continue;
+ }
+ if (!real || (!quiet && real))
+ if (!strcmp(retnotice.z_message, ZSRVACK_SENT)) {
+ if (real) {
+ if (verbose)
+ printf("Successful\n");
+ else
+ printf("%s: Message sent\n",
nrecips?notice->z_recipient:inst);
- continue;
}
- if (!real || (!quiet && real))
- if (!strcmp(retnotice.z_message, ZSRVACK_SENT)) {
- if (real) {
- if (verbose)
- printf("Successful\n");
- else
- printf("%s: Message sent\n",
- nrecips?notice->z_recipient:inst);
- }
- else
- success = 1;
- }
+ else
+ success = 1;
+ }
+ else
+ if (!strcmp(retnotice.z_message,
+ ZSRVACK_NOTSENT)) {
+ if (verbose && real) {
+ if (strcmp(class, DEFAULT_CLASS))
+ printf("Not logged in or not subscribing to class %s, instance %s\n",
+ class, inst);
else
- if (!strcmp(retnotice.z_message,
- ZSRVACK_NOTSENT)) {
- if (verbose && real) {
- if (strcmp(class, DEFAULT_CLASS))
- printf("Not logged in or not subscribing to class %s, instance %s\n",
- class, inst);
- else
- printf("Not logged in or not subscribing to messages\n");
- }
- else
- if (!nrecips)
- printf("No one subscribing to class %s, instance %s\n",
- class, inst);
- else {
- if (strcmp(class, DEFAULT_CLASS))
- printf("%s: Not logged in or not subscribing to class %s, instance %s\n",
- notice->z_recipient, class, 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 (!nrecips)
- break;
- }
- if (!real && !success)
- exit(1);
+ printf("Not logged in or not subscribing to messages\n");
+ }
+ else
+ if (!nrecips)
+ printf("No one subscribing to class %s, instance %s\n",
+ class, inst);
+ else {
+ if (strcmp(class, DEFAULT_CLASS))
+ printf("%s: Not logged in or not subscribing to class %s, instance %s\n",
+ notice->z_recipient, class, 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 (!nrecips)
+ break;
+ }
+ if (!real && !success)
+ exit(1);
}
usage(s)
- char *s;
+ char *s;
{
- printf("Usage: %s [-a] [-d] [-v] [-q] [-u] [-o] [-c class] [-i inst] [user ...]\n [-m message]\n", s);
- exit(1);
+ printf("Usage: %s [-a] [-d] [-v] [-q] [-u] [-o] [-c class] [-i inst] [user ...]\n [-m message]\n", s);
+ exit(1);
}