]>
Commit | Line | Data |
---|---|---|
a3cf6921 | 1 | /* |
2 | * $Source$ | |
3 | * $Author$ | |
4 | * $Header$ | |
5 | * | |
6 | * Copyright (C) 1987 by the Massachusetts Institute of Technology | |
7 | * | |
a3cf6921 | 8 | */ |
9 | ||
10 | #ifndef lint | |
11 | static char *rcsid_sms_util_c = "$Header$"; | |
12 | #endif lint | |
13 | ||
a3cf6921 | 14 | #include "sms_server.h" |
a3cf6921 | 15 | |
16 | #include <ctype.h> | |
229feb8a | 17 | #include <strings.h> |
c93d352e | 18 | #include <sys/types.h> |
19 | #include <zephyr/zephyr.h> | |
229feb8a | 20 | |
21 | extern char *whoami; | |
22 | ||
229feb8a | 23 | char * |
5aa981ce | 24 | requote(buf, cp, len) |
229feb8a | 25 | char *buf; |
a3cf6921 | 26 | register char *cp; |
27 | { | |
5aa981ce | 28 | register int count = 0; |
caeb1b25 | 29 | register unsigned char c; |
5aa981ce | 30 | if (len <= 2) return buf; |
31 | *buf++ = '"'; count++; len--; | |
32 | for(; (count < 40) && (len > 1) && (c = *cp); | |
33 | cp++, --len, ++count) { | |
229feb8a | 34 | if (c == '\\' || c == '"') *buf++ = '\\'; |
35 | if (isprint(c)) *buf++ = c; | |
36 | else { | |
37 | sprintf(buf, "\\%03o", c); | |
38 | buf = index(buf, '\0'); | |
39 | } | |
a3cf6921 | 40 | } |
5aa981ce | 41 | if (len > 1) { *buf++ = '"'; count++; len--; } |
69f63d24 | 42 | if (len > 3 && count >= 40) { |
5aa981ce | 43 | *buf++ = '.'; count++; len--; |
44 | *buf++ = '.'; count++; len--; | |
45 | *buf++ = '.'; count++; len--; | |
46 | } | |
47 | if (len > 1) *buf = '\0'; | |
229feb8a | 48 | return buf; |
a3cf6921 | 49 | } |
5aa981ce | 50 | |
2423a5db | 51 | log_args(tag, version, argc, argv) |
ac65c1d1 | 52 | char *tag; |
2423a5db | 53 | int version; |
229feb8a | 54 | int argc; |
55 | char **argv; | |
56 | { | |
57 | char buf[BUFSIZ]; | |
58 | register int i; | |
2423a5db | 59 | register char *bp; |
229feb8a | 60 | |
ac65c1d1 | 61 | i = strlen(tag); |
2423a5db | 62 | sprintf(buf, "%s[%d]: ", tag, version); |
63 | for (bp = buf; *bp; bp++); | |
ac65c1d1 | 64 | |
5aa981ce | 65 | for (i = 0; i < argc && ((buf - bp) + 1024) > 2; i++) { |
229feb8a | 66 | if (i != 0) { |
67 | *bp++ = ','; | |
68 | *bp++ = ' '; | |
69 | } | |
5aa981ce | 70 | bp = requote(bp, argv[i], (buf - bp) + 1024); |
229feb8a | 71 | } |
72 | *bp = '\0'; | |
5cc7d26c | 73 | com_err(whoami, 0, "%s", buf); |
229feb8a | 74 | } |
75 | ||
b4182127 | 76 | void sms_com_err(whoami, code, fmt, pvar) |
a3cf6921 | 77 | char *whoami; |
78 | int code; | |
b4182127 | 79 | char *fmt; |
80 | caddr_t pvar; | |
a3cf6921 | 81 | { |
82 | extern char *error_message(); | |
83 | extern client *cur_client; | |
84 | ||
a3cf6921 | 85 | if (whoami) { |
b4182127 | 86 | fputs(whoami, stderr); |
87 | if (cur_client) fprintf(stderr, "[#%d]", cur_client->id); | |
88 | fputs(": ", stderr); | |
a3cf6921 | 89 | } |
90 | if (code) { | |
b4182127 | 91 | fputs(error_message(code), stderr); |
92 | } | |
93 | if (fmt) { | |
94 | _doprnt(fmt, pvar, stderr); | |
a3cf6921 | 95 | } |
b4182127 | 96 | putc('\n', stderr); |
a3cf6921 | 97 | } |
2423a5db | 98 | |
99 | ||
100 | /* sms_trim_args: passed an argument vector, it will trim any trailing | |
101 | * spaces on the args by writing a null into the string. | |
102 | */ | |
103 | ||
104 | int sms_trim_args(argc, argv) | |
105 | int argc; | |
106 | char **argv; | |
107 | { | |
108 | register char **arg; | |
109 | register char *p, *lastch; | |
110 | ||
111 | for (arg = argv; argc--; arg++) { | |
112 | for (lastch = p = *arg; *p; p++) | |
113 | if (!isspace(*p)) | |
114 | lastch = p; | |
115 | if (p != lastch) { | |
116 | if (isspace(*lastch)) | |
117 | *lastch = 0; | |
118 | else | |
119 | *(++lastch) = 0; | |
120 | } | |
121 | } | |
122 | return(0); | |
123 | } | |
124 | ||
125 | ||
126 | trim(s) | |
127 | register char *s; | |
128 | { | |
129 | register char *p; | |
130 | ||
131 | for (p = s; *s; s++) | |
132 | if (*s != ' ') | |
133 | p = s; | |
134 | if (p != s) { | |
135 | if (*p == ' ') | |
136 | *p = 0; | |
137 | else | |
138 | p[1] = 0; | |
139 | } | |
140 | } | |
c93d352e | 141 | |
142 | ||
143 | /* Sends a zephyrgram of class "SMS", instance as a parameter. Ignores | |
144 | * errors while sending message. | |
145 | */ | |
146 | ||
147 | send_zgram(inst, msg) | |
148 | char *inst; | |
149 | char *msg; | |
150 | { | |
151 | ZNotice_t znotice; | |
152 | ||
153 | bzero (&znotice, sizeof (znotice)); | |
154 | znotice.z_kind = UNSAFE; | |
155 | znotice.z_class = "SMS"; | |
156 | znotice.z_class_inst = inst; | |
157 | znotice.z_default_format = "SMS $instance:\n $message\n"; | |
158 | (void) ZInitialize (); | |
159 | znotice.z_message = msg; | |
160 | znotice.z_message_len = strlen(msg) + 1; | |
161 | znotice.z_opcode = ""; | |
162 | znotice.z_recipient = ""; | |
163 | ZSendNotice(&znotice, ZNOAUTH); | |
164 | } |