]>
Commit | Line | Data |
---|---|---|
a3cf6921 | 1 | /* |
2 | * $Source$ | |
3 | * $Author$ | |
4 | * $Header$ | |
5 | * | |
6 | * Copyright (C) 1987 by the Massachusetts Institute of Technology | |
7 | * | |
8 | * $Log$ | |
ac65c1d1 | 9 | * Revision 1.7 1987-07-14 00:39:47 wesommer |
10 | * Changed interface to log_args. | |
a3cf6921 | 11 | * |
ac65c1d1 | 12 | * Revision 1.6 87/07/06 16:09:07 wesommer |
13 | * Only print ... if the string is too long.. | |
14 | * | |
69f63d24 | 15 | * Revision 1.5 87/06/30 20:05:52 wesommer |
16 | * Added range checking. | |
17 | * | |
5aa981ce | 18 | * Revision 1.4 87/06/21 16:42:19 wesommer |
19 | * Performance work, rearrangement of include files. | |
20 | * | |
c27b3454 | 21 | * Revision 1.3 87/06/04 01:35:28 wesommer |
22 | * Added better logging routines. | |
23 | * | |
229feb8a | 24 | * Revision 1.2 87/06/03 16:08:07 wesommer |
25 | * Fixes for lint. | |
26 | * | |
5dbd09a0 | 27 | * Revision 1.1 87/06/02 20:07:32 wesommer |
28 | * Initial revision | |
29 | * | |
a3cf6921 | 30 | */ |
31 | ||
32 | #ifndef lint | |
33 | static char *rcsid_sms_util_c = "$Header$"; | |
34 | #endif lint | |
35 | ||
a3cf6921 | 36 | #include "sms_server.h" |
a3cf6921 | 37 | |
38 | #include <ctype.h> | |
229feb8a | 39 | #include <strings.h> |
40 | ||
41 | extern char *whoami; | |
42 | ||
229feb8a | 43 | char * |
5aa981ce | 44 | requote(buf, cp, len) |
229feb8a | 45 | char *buf; |
a3cf6921 | 46 | register char *cp; |
47 | { | |
5aa981ce | 48 | register int count = 0; |
a3cf6921 | 49 | register char c; |
5aa981ce | 50 | if (len <= 2) return buf; |
51 | *buf++ = '"'; count++; len--; | |
52 | for(; (count < 40) && (len > 1) && (c = *cp); | |
53 | cp++, --len, ++count) { | |
229feb8a | 54 | if (c == '\\' || c == '"') *buf++ = '\\'; |
55 | if (isprint(c)) *buf++ = c; | |
56 | else { | |
57 | sprintf(buf, "\\%03o", c); | |
58 | buf = index(buf, '\0'); | |
59 | } | |
a3cf6921 | 60 | } |
5aa981ce | 61 | if (len > 1) { *buf++ = '"'; count++; len--; } |
69f63d24 | 62 | if (len > 3 && count >= 40) { |
5aa981ce | 63 | *buf++ = '.'; count++; len--; |
64 | *buf++ = '.'; count++; len--; | |
65 | *buf++ = '.'; count++; len--; | |
66 | } | |
67 | if (len > 1) *buf = '\0'; | |
229feb8a | 68 | return buf; |
a3cf6921 | 69 | } |
5aa981ce | 70 | |
ac65c1d1 | 71 | log_args(tag, argc, argv) |
72 | char *tag; | |
229feb8a | 73 | int argc; |
74 | char **argv; | |
75 | { | |
76 | char buf[BUFSIZ]; | |
77 | register int i; | |
78 | register char *bp = buf; | |
79 | ||
ac65c1d1 | 80 | i = strlen(tag); |
81 | bcopy(tag, bp, i+1); | |
82 | bp += i; | |
83 | *bp++ =':'; | |
84 | *bp++ =' '; | |
85 | ||
5aa981ce | 86 | for (i = 0; i < argc && ((buf - bp) + 1024) > 2; i++) { |
229feb8a | 87 | if (i != 0) { |
88 | *bp++ = ','; | |
89 | *bp++ = ' '; | |
90 | } | |
5aa981ce | 91 | bp = requote(bp, argv[i], (buf - bp) + 1024); |
229feb8a | 92 | } |
93 | *bp = '\0'; | |
94 | com_err(whoami, 0, buf); | |
95 | } | |
96 | ||
a3cf6921 | 97 | void sms_com_err(whoami, code, message) |
98 | char *whoami; | |
99 | int code; | |
100 | char *message; | |
101 | { | |
102 | extern char *error_message(); | |
103 | extern client *cur_client; | |
104 | ||
105 | struct iovec strings[7]; | |
106 | char buf[32]; | |
107 | if (cur_client) | |
108 | (void) sprintf(buf, "[#%d]", cur_client->id); | |
109 | else buf[0]='\0'; | |
110 | ||
111 | strings[1].iov_base = buf; | |
112 | strings[1].iov_len = strlen(buf); | |
113 | ||
114 | strings[0].iov_base = whoami; | |
115 | if (whoami) { | |
116 | strings[0].iov_len = strlen(whoami); | |
117 | strings[2].iov_base = ": "; | |
118 | strings[2].iov_len = 2; | |
119 | } else { | |
120 | strings[0].iov_len = 0; | |
121 | strings[2].iov_base = " "; | |
122 | strings[2].iov_len = 1; | |
123 | } | |
124 | if (code) { | |
125 | register char *errmsg = error_message(code); | |
126 | strings[3].iov_base = errmsg; | |
127 | strings[3].iov_len = strlen(errmsg); | |
128 | strings[4].iov_base = " "; | |
129 | strings[4].iov_len = 1; | |
130 | } else { | |
131 | strings[3].iov_len = 0; | |
132 | strings[4].iov_len = 0; | |
133 | } | |
134 | strings[5].iov_base = message; | |
135 | strings[5].iov_len = strlen(message); | |
136 | strings[6].iov_base = "\n"; | |
137 | strings[6].iov_len = 1; | |
138 | (void) writev(2, strings, 7); | |
139 | } |