1 | #include "owl.h" |
---|
2 | |
---|
3 | static const char fileIdent[] = "$Id$"; |
---|
4 | |
---|
5 | /* In all of these functions, 'fm' is expected to already be |
---|
6 | * initialized. |
---|
7 | */ |
---|
8 | |
---|
9 | void owl_stylefunc_basic(owl_fmtext *fm, owl_message *m) |
---|
10 | { |
---|
11 | #ifdef HAVE_LIBZEPHYR |
---|
12 | char *body, *indent, *ptr, *zsigbuff, frombuff[LINE]; |
---|
13 | ZNotice_t *n; |
---|
14 | #endif |
---|
15 | |
---|
16 | if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) { |
---|
17 | #ifdef HAVE_LIBZEPHYR |
---|
18 | n=owl_message_get_notice(m); |
---|
19 | |
---|
20 | /* get the body */ |
---|
21 | body=owl_strdup(owl_message_get_body(m)); |
---|
22 | body=realloc(body, strlen(body)+30); |
---|
23 | |
---|
24 | /* add a newline if we need to */ |
---|
25 | if (body[0]!='\0' && body[strlen(body)-1]!='\n') { |
---|
26 | strcat(body, "\n"); |
---|
27 | } |
---|
28 | |
---|
29 | /* do the indenting into indent */ |
---|
30 | indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10); |
---|
31 | owl_text_indent(indent, body, OWL_MSGTAB); |
---|
32 | |
---|
33 | /* edit the from addr for printing */ |
---|
34 | strcpy(frombuff, owl_message_get_sender(m)); |
---|
35 | ptr=strchr(frombuff, '@'); |
---|
36 | if (ptr && !strncmp(ptr+1, owl_zephyr_get_realm(), strlen(owl_zephyr_get_realm()))) { |
---|
37 | *ptr='\0'; |
---|
38 | } |
---|
39 | |
---|
40 | /* set the message for printing */ |
---|
41 | owl_fmtext_append_normal(fm, OWL_TABSTR); |
---|
42 | |
---|
43 | if (owl_message_is_ping(m)) { |
---|
44 | owl_fmtext_append_bold(fm, "PING"); |
---|
45 | owl_fmtext_append_normal(fm, " from "); |
---|
46 | owl_fmtext_append_bold(fm, frombuff); |
---|
47 | owl_fmtext_append_normal(fm, "\n"); |
---|
48 | } else if (owl_message_is_loginout(m)) { |
---|
49 | char *ptr, *host, *tty; |
---|
50 | int len; |
---|
51 | |
---|
52 | ptr=owl_zephyr_get_field(n, 1, &len); |
---|
53 | host=owl_malloc(len+10); |
---|
54 | strncpy(host, ptr, len); |
---|
55 | host[len]='\0'; |
---|
56 | |
---|
57 | ptr=owl_zephyr_get_field(n, 3, &len); |
---|
58 | tty=owl_malloc(len+10); |
---|
59 | strncpy(tty, ptr, len); |
---|
60 | tty[len]='\0'; |
---|
61 | |
---|
62 | if (owl_message_is_login(m)) { |
---|
63 | owl_fmtext_append_bold(fm, "LOGIN"); |
---|
64 | } else if (owl_message_is_logout(m)) { |
---|
65 | owl_fmtext_append_bold(fm, "LOGOUT"); |
---|
66 | } |
---|
67 | owl_fmtext_append_normal(fm, " for "); |
---|
68 | ptr=short_zuser(owl_message_get_instance(m)); |
---|
69 | owl_fmtext_append_bold(fm, ptr); |
---|
70 | owl_free(ptr); |
---|
71 | owl_fmtext_append_normal(fm, " at "); |
---|
72 | owl_fmtext_append_normal(fm, host); |
---|
73 | owl_fmtext_append_normal(fm, " "); |
---|
74 | owl_fmtext_append_normal(fm, tty); |
---|
75 | owl_fmtext_append_normal(fm, "\n"); |
---|
76 | |
---|
77 | owl_free(host); |
---|
78 | owl_free(tty); |
---|
79 | } else { |
---|
80 | owl_fmtext_append_normal(fm, "From: "); |
---|
81 | if (strcasecmp(owl_message_get_class(m), "message")) { |
---|
82 | owl_fmtext_append_normal(fm, "Class "); |
---|
83 | owl_fmtext_append_normal(fm, owl_message_get_class(m)); |
---|
84 | owl_fmtext_append_normal(fm, " / Instance "); |
---|
85 | owl_fmtext_append_normal(fm, owl_message_get_instance(m)); |
---|
86 | owl_fmtext_append_normal(fm, " / "); |
---|
87 | } |
---|
88 | owl_fmtext_append_normal(fm, frombuff); |
---|
89 | if (strcasecmp(owl_message_get_realm(m), owl_zephyr_get_realm())) { |
---|
90 | owl_fmtext_append_normal(fm, " {"); |
---|
91 | owl_fmtext_append_normal(fm, owl_message_get_realm(m)); |
---|
92 | owl_fmtext_append_normal(fm, "} "); |
---|
93 | } |
---|
94 | |
---|
95 | /* stick on the zsig */ |
---|
96 | zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30); |
---|
97 | owl_message_pretty_zsig(m, zsigbuff); |
---|
98 | owl_fmtext_append_normal(fm, " ("); |
---|
99 | owl_fmtext_append_ztext(fm, zsigbuff); |
---|
100 | owl_fmtext_append_normal(fm, ")"); |
---|
101 | owl_fmtext_append_normal(fm, "\n"); |
---|
102 | owl_free(zsigbuff); |
---|
103 | |
---|
104 | /* then the indented message */ |
---|
105 | owl_fmtext_append_ztext(fm, indent); |
---|
106 | |
---|
107 | /* make personal messages bold for smaat users */ |
---|
108 | if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) { |
---|
109 | if (owl_message_is_personal(m)) { |
---|
110 | owl_fmtext_addattr((&m->fmtext), OWL_FMTEXT_ATTR_BOLD); |
---|
111 | } |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | owl_free(body); |
---|
116 | owl_free(indent); |
---|
117 | #endif |
---|
118 | } else if (owl_message_is_type_zephyr(m) && owl_message_is_direction_out(m)) { |
---|
119 | char *indent, *text, *zsigbuff, *foo; |
---|
120 | |
---|
121 | text=owl_message_get_body(m); |
---|
122 | |
---|
123 | indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10); |
---|
124 | owl_text_indent(indent, text, OWL_MSGTAB); |
---|
125 | owl_fmtext_append_normal(fm, OWL_TABSTR); |
---|
126 | owl_fmtext_append_normal(fm, "To: "); |
---|
127 | foo=short_zuser(owl_message_get_recipient(m)); |
---|
128 | owl_fmtext_append_normal(fm, foo); |
---|
129 | owl_free(foo); |
---|
130 | owl_fmtext_append_normal(fm, " (Zsig: "); |
---|
131 | |
---|
132 | zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30); |
---|
133 | owl_message_pretty_zsig(m, zsigbuff); |
---|
134 | owl_fmtext_append_ztext(fm, zsigbuff); |
---|
135 | owl_free(zsigbuff); |
---|
136 | |
---|
137 | owl_fmtext_append_normal(fm, ")"); |
---|
138 | owl_fmtext_append_normal(fm, "\n"); |
---|
139 | owl_fmtext_append_ztext(fm, indent); |
---|
140 | if (text[strlen(text)-1]!='\n') { |
---|
141 | owl_fmtext_append_normal(fm, "\n"); |
---|
142 | } |
---|
143 | |
---|
144 | owl_free(indent); |
---|
145 | } else if (owl_message_is_type_aim(m)) { |
---|
146 | char *indent; |
---|
147 | |
---|
148 | if (owl_message_is_loginout(m)) { |
---|
149 | owl_fmtext_append_normal(fm, OWL_TABSTR); |
---|
150 | if (owl_message_is_login(m)) { |
---|
151 | owl_fmtext_append_bold(fm, "AIM LOGIN"); |
---|
152 | } else { |
---|
153 | owl_fmtext_append_bold(fm, "AIM LOGOUT"); |
---|
154 | } |
---|
155 | owl_fmtext_append_normal(fm, " for "); |
---|
156 | owl_fmtext_append_normal(fm, owl_message_get_sender(m)); |
---|
157 | owl_fmtext_append_normal(fm, "\n"); |
---|
158 | } else if (owl_message_is_direction_in(m)) { |
---|
159 | indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10); |
---|
160 | owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB); |
---|
161 | owl_fmtext_append_bold(fm, OWL_TABSTR); |
---|
162 | owl_fmtext_append_bold(fm, "AIM from "); |
---|
163 | owl_fmtext_append_bold(fm, owl_message_get_sender(m)); |
---|
164 | owl_fmtext_append_bold(fm, "\n"); |
---|
165 | owl_fmtext_append_bold(fm, indent); |
---|
166 | if (indent[strlen(indent)-1]!='\n') { |
---|
167 | owl_fmtext_append_normal(fm, "\n"); |
---|
168 | } |
---|
169 | owl_free(indent); |
---|
170 | } else if (owl_message_is_direction_out(m)) { |
---|
171 | indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10); |
---|
172 | owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB); |
---|
173 | owl_fmtext_append_normal(fm, OWL_TABSTR); |
---|
174 | owl_fmtext_append_normal(fm, "AIM sent to "); |
---|
175 | owl_fmtext_append_normal(fm, owl_message_get_recipient(m)); |
---|
176 | owl_fmtext_append_normal(fm, "\n"); |
---|
177 | owl_fmtext_append_ztext(fm, indent); |
---|
178 | if (indent[strlen(indent)-1]!='\n') { |
---|
179 | owl_fmtext_append_normal(fm, "\n"); |
---|
180 | } |
---|
181 | owl_free(indent); |
---|
182 | } |
---|
183 | } else if (owl_message_is_type_admin(m)) { |
---|
184 | char *text, *header, *indent; |
---|
185 | |
---|
186 | text=owl_message_get_body(m); |
---|
187 | header=owl_message_get_attribute_value(m, "adminheader"); |
---|
188 | |
---|
189 | indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10); |
---|
190 | owl_text_indent(indent, text, OWL_MSGTAB); |
---|
191 | owl_fmtext_append_normal(fm, OWL_TABSTR); |
---|
192 | owl_fmtext_append_bold(fm, "OWL ADMIN "); |
---|
193 | owl_fmtext_append_ztext(fm, header); |
---|
194 | owl_fmtext_append_normal(fm, "\n"); |
---|
195 | owl_fmtext_append_ztext(fm, indent); |
---|
196 | if (text[strlen(text)-1]!='\n') { |
---|
197 | owl_fmtext_append_normal(fm, "\n"); |
---|
198 | } |
---|
199 | |
---|
200 | owl_free(indent); |
---|
201 | } |
---|
202 | } |
---|
203 | |
---|
204 | void owl_stylefunc_default(owl_fmtext *fm, owl_message *m) |
---|
205 | { |
---|
206 | #ifdef HAVE_LIBZEPHYR |
---|
207 | char *body, *indent, *ptr, *zsigbuff, frombuff[LINE]; |
---|
208 | ZNotice_t *n; |
---|
209 | #endif |
---|
210 | |
---|
211 | if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) { |
---|
212 | #ifdef HAVE_LIBZEPHYR |
---|
213 | n=owl_message_get_notice(m); |
---|
214 | |
---|
215 | /* get the body */ |
---|
216 | body=owl_malloc(strlen(owl_message_get_body(m))+30); |
---|
217 | strcpy(body, owl_message_get_body(m)); |
---|
218 | |
---|
219 | /* add a newline if we need to */ |
---|
220 | if (body[0]!='\0' && body[strlen(body)-1]!='\n') { |
---|
221 | strcat(body, "\n"); |
---|
222 | } |
---|
223 | |
---|
224 | /* do the indenting into indent */ |
---|
225 | indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10); |
---|
226 | owl_text_indent(indent, body, OWL_MSGTAB); |
---|
227 | |
---|
228 | /* edit the from addr for printing */ |
---|
229 | strcpy(frombuff, owl_message_get_sender(m)); |
---|
230 | ptr=strchr(frombuff, '@'); |
---|
231 | if (ptr && !strncmp(ptr+1, owl_zephyr_get_realm(), strlen(owl_zephyr_get_realm()))) { |
---|
232 | *ptr='\0'; |
---|
233 | } |
---|
234 | |
---|
235 | /* set the message for printing */ |
---|
236 | owl_fmtext_append_normal(fm, OWL_TABSTR); |
---|
237 | |
---|
238 | if (owl_message_is_ping(m) && owl_message_is_private(m)) { |
---|
239 | owl_fmtext_append_bold(fm, "PING"); |
---|
240 | owl_fmtext_append_normal(fm, " from "); |
---|
241 | owl_fmtext_append_bold(fm, frombuff); |
---|
242 | owl_fmtext_append_normal(fm, "\n"); |
---|
243 | } else if (owl_message_is_loginout(m)) { |
---|
244 | char *ptr, *host, *tty; |
---|
245 | int len; |
---|
246 | |
---|
247 | ptr=owl_zephyr_get_field(n, 1, &len); |
---|
248 | host=owl_malloc(len+10); |
---|
249 | strncpy(host, ptr, len); |
---|
250 | host[len]='\0'; |
---|
251 | |
---|
252 | ptr=owl_zephyr_get_field(n, 3, &len); |
---|
253 | tty=owl_malloc(len+10); |
---|
254 | strncpy(tty, ptr, len); |
---|
255 | tty[len]='\0'; |
---|
256 | |
---|
257 | if (owl_message_is_login(m)) { |
---|
258 | owl_fmtext_append_bold(fm, "LOGIN"); |
---|
259 | } else if (owl_message_is_logout(m)) { |
---|
260 | owl_fmtext_append_bold(fm, "LOGOUT"); |
---|
261 | } |
---|
262 | owl_fmtext_append_normal(fm, " for "); |
---|
263 | ptr=short_zuser(owl_message_get_instance(m)); |
---|
264 | owl_fmtext_append_bold(fm, ptr); |
---|
265 | owl_free(ptr); |
---|
266 | owl_fmtext_append_normal(fm, " at "); |
---|
267 | owl_fmtext_append_normal(fm, host); |
---|
268 | owl_fmtext_append_normal(fm, " "); |
---|
269 | owl_fmtext_append_normal(fm, tty); |
---|
270 | owl_fmtext_append_normal(fm, "\n"); |
---|
271 | |
---|
272 | owl_free(host); |
---|
273 | owl_free(tty); |
---|
274 | } else { |
---|
275 | owl_fmtext_append_normal(fm, owl_message_get_class(m)); |
---|
276 | owl_fmtext_append_normal(fm, " / "); |
---|
277 | owl_fmtext_append_normal(fm, owl_message_get_instance(m)); |
---|
278 | owl_fmtext_append_normal(fm, " / "); |
---|
279 | owl_fmtext_append_bold(fm, frombuff); |
---|
280 | if (strcasecmp(owl_message_get_realm(m), ZGetRealm())) { |
---|
281 | owl_fmtext_append_normal(fm, " {"); |
---|
282 | owl_fmtext_append_normal(fm, owl_message_get_realm(m)); |
---|
283 | owl_fmtext_append_normal(fm, "} "); |
---|
284 | } |
---|
285 | if (strcmp(owl_message_get_opcode(m), "")) { |
---|
286 | owl_fmtext_append_normal(fm, " ["); |
---|
287 | owl_fmtext_append_normal(fm, owl_message_get_opcode(m)); |
---|
288 | owl_fmtext_append_normal(fm, "] "); |
---|
289 | } |
---|
290 | |
---|
291 | /* stick on the zsig */ |
---|
292 | zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30); |
---|
293 | owl_message_pretty_zsig(m, zsigbuff); |
---|
294 | owl_fmtext_append_normal(fm, " ("); |
---|
295 | owl_fmtext_append_ztext(fm, zsigbuff); |
---|
296 | owl_fmtext_append_normal(fm, ")"); |
---|
297 | owl_fmtext_append_normal(fm, "\n"); |
---|
298 | owl_free(zsigbuff); |
---|
299 | |
---|
300 | /* then the indented message */ |
---|
301 | owl_fmtext_append_ztext(fm, indent); |
---|
302 | |
---|
303 | /* make private messages bold for smaat users */ |
---|
304 | if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) { |
---|
305 | if (owl_message_is_personal(m)) { |
---|
306 | owl_fmtext_addattr((&m->fmtext), OWL_FMTEXT_ATTR_BOLD); |
---|
307 | } |
---|
308 | } |
---|
309 | } |
---|
310 | |
---|
311 | owl_free(body); |
---|
312 | owl_free(indent); |
---|
313 | #endif |
---|
314 | } else if (owl_message_is_type_zephyr(m) && owl_message_is_direction_out(m)) { |
---|
315 | char *indent, *text, *zsigbuff, *foo; |
---|
316 | |
---|
317 | text=owl_message_get_body(m); |
---|
318 | |
---|
319 | indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10); |
---|
320 | owl_text_indent(indent, text, OWL_MSGTAB); |
---|
321 | owl_fmtext_append_normal(fm, OWL_TABSTR); |
---|
322 | owl_fmtext_append_normal(fm, "Zephyr sent to "); |
---|
323 | foo=short_zuser(owl_message_get_recipient(m)); |
---|
324 | owl_fmtext_append_normal(fm, foo); |
---|
325 | owl_free(foo); |
---|
326 | owl_fmtext_append_normal(fm, " (Zsig: "); |
---|
327 | |
---|
328 | zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30); |
---|
329 | owl_message_pretty_zsig(m, zsigbuff); |
---|
330 | owl_fmtext_append_ztext(fm, zsigbuff); |
---|
331 | owl_free(zsigbuff); |
---|
332 | |
---|
333 | owl_fmtext_append_normal(fm, ")"); |
---|
334 | owl_fmtext_append_normal(fm, "\n"); |
---|
335 | owl_fmtext_append_ztext(fm, indent); |
---|
336 | if (text[strlen(text)-1]!='\n') { |
---|
337 | owl_fmtext_append_normal(fm, "\n"); |
---|
338 | } |
---|
339 | |
---|
340 | owl_free(indent); |
---|
341 | } else if (owl_message_is_type_aim(m)) { |
---|
342 | char *indent; |
---|
343 | |
---|
344 | if (owl_message_is_loginout(m)) { |
---|
345 | owl_fmtext_append_normal(fm, OWL_TABSTR); |
---|
346 | if (owl_message_is_login(m)) { |
---|
347 | owl_fmtext_append_bold(fm, "AIM LOGIN"); |
---|
348 | } else { |
---|
349 | owl_fmtext_append_bold(fm, "AIM LOGOUT"); |
---|
350 | } |
---|
351 | owl_fmtext_append_normal(fm, " for "); |
---|
352 | owl_fmtext_append_normal(fm, owl_message_get_sender(m)); |
---|
353 | owl_fmtext_append_normal(fm, "\n"); |
---|
354 | } else if (owl_message_is_direction_in(m)) { |
---|
355 | indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10); |
---|
356 | owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB); |
---|
357 | owl_fmtext_append_bold(fm, OWL_TABSTR); |
---|
358 | owl_fmtext_append_bold(fm, "AIM from "); |
---|
359 | owl_fmtext_append_bold(fm, owl_message_get_sender(m)); |
---|
360 | owl_fmtext_append_bold(fm, "\n"); |
---|
361 | owl_fmtext_append_bold(fm, indent); |
---|
362 | if (indent[strlen(indent)-1]!='\n') { |
---|
363 | owl_fmtext_append_normal(fm, "\n"); |
---|
364 | } |
---|
365 | owl_free(indent); |
---|
366 | } else if (owl_message_is_direction_out(m)) { |
---|
367 | indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10); |
---|
368 | owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB); |
---|
369 | owl_fmtext_append_normal(fm, OWL_TABSTR); |
---|
370 | owl_fmtext_append_normal(fm, "AIM sent to "); |
---|
371 | owl_fmtext_append_normal(fm, owl_message_get_recipient(m)); |
---|
372 | owl_fmtext_append_normal(fm, "\n"); |
---|
373 | owl_fmtext_append_ztext(fm, indent); |
---|
374 | if (indent[strlen(indent)-1]!='\n') { |
---|
375 | owl_fmtext_append_normal(fm, "\n"); |
---|
376 | } |
---|
377 | owl_free(indent); |
---|
378 | } |
---|
379 | } else if (owl_message_is_type_admin(m)) { |
---|
380 | char *text, *header, *indent; |
---|
381 | |
---|
382 | text=owl_message_get_body(m); |
---|
383 | header=owl_message_get_attribute_value(m, "adminheader"); |
---|
384 | |
---|
385 | indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10); |
---|
386 | owl_text_indent(indent, text, OWL_MSGTAB); |
---|
387 | owl_fmtext_append_normal(fm, OWL_TABSTR); |
---|
388 | owl_fmtext_append_bold(fm, "OWL ADMIN "); |
---|
389 | owl_fmtext_append_ztext(fm, header); |
---|
390 | owl_fmtext_append_normal(fm, "\n"); |
---|
391 | owl_fmtext_append_ztext(fm, indent); |
---|
392 | if (text[strlen(text)-1]!='\n') { |
---|
393 | owl_fmtext_append_normal(fm, "\n"); |
---|
394 | } |
---|
395 | |
---|
396 | owl_free(indent); |
---|
397 | } |
---|
398 | } |
---|
399 | |
---|
400 | void owl_stylefunc_oneline(owl_fmtext *fm, owl_message *m) |
---|
401 | { |
---|
402 | char *tmp; |
---|
403 | char *baseformat="%s %-13.13s %-11.11s %-12.12s "; |
---|
404 | char *sender, *recip; |
---|
405 | #ifdef HAVE_LIBZEPHYR |
---|
406 | ZNotice_t *n; |
---|
407 | #endif |
---|
408 | |
---|
409 | sender=short_zuser(owl_message_get_sender(m)); |
---|
410 | recip=short_zuser(owl_message_get_recipient(m)); |
---|
411 | |
---|
412 | if (owl_message_is_type_zephyr(m)) { |
---|
413 | #ifdef HAVE_LIBZEPHYR |
---|
414 | n=owl_message_get_notice(m); |
---|
415 | |
---|
416 | owl_fmtext_append_spaces(fm, OWL_TAB); |
---|
417 | |
---|
418 | if (owl_message_is_loginout(m)) { |
---|
419 | char *ptr, *host, *tty; |
---|
420 | int len; |
---|
421 | |
---|
422 | ptr=owl_zephyr_get_field(n, 1, &len); |
---|
423 | host=owl_malloc(len+10); |
---|
424 | strncpy(host, ptr, len); |
---|
425 | host[len]='\0'; |
---|
426 | |
---|
427 | ptr=owl_zephyr_get_field(n, 3, &len); |
---|
428 | tty=owl_malloc(len+10); |
---|
429 | strncpy(tty, ptr, len); |
---|
430 | tty[len]='\0'; |
---|
431 | |
---|
432 | if (owl_message_is_login(m)) { |
---|
433 | tmp=owl_sprintf(baseformat, "<", "LOGIN", "", sender); |
---|
434 | owl_fmtext_append_normal(fm, tmp); |
---|
435 | owl_free(tmp); |
---|
436 | } else if (owl_message_is_logout(m)) { |
---|
437 | tmp=owl_sprintf(baseformat, "<", "LOGOUT", "", sender); |
---|
438 | owl_fmtext_append_normal(fm, tmp); |
---|
439 | owl_free(tmp); |
---|
440 | } |
---|
441 | |
---|
442 | owl_fmtext_append_normal(fm, "at "); |
---|
443 | owl_fmtext_append_normal(fm, host); |
---|
444 | owl_fmtext_append_normal(fm, " "); |
---|
445 | owl_fmtext_append_normal(fm, tty); |
---|
446 | owl_fmtext_append_normal(fm, "\n"); |
---|
447 | |
---|
448 | owl_free(host); |
---|
449 | owl_free(tty); |
---|
450 | |
---|
451 | } else if (owl_message_is_ping(m)) { |
---|
452 | tmp=owl_sprintf(baseformat, "<", "PING", "", sender); |
---|
453 | owl_fmtext_append_normal(fm, tmp); |
---|
454 | owl_fmtext_append_normal(fm, "\n"); |
---|
455 | owl_free(tmp); |
---|
456 | |
---|
457 | } else { |
---|
458 | if (owl_message_is_direction_in(m)) { |
---|
459 | tmp=owl_sprintf(baseformat, "<", owl_message_get_class(m), owl_message_get_instance(m), sender); |
---|
460 | } else if (owl_message_is_direction_out(m)) { |
---|
461 | tmp=owl_sprintf(baseformat, ">", owl_message_get_class(m), owl_message_get_instance(m), recip); |
---|
462 | } else { |
---|
463 | tmp=owl_sprintf(baseformat, "-", owl_message_get_class(m), owl_message_get_instance(m), sender); |
---|
464 | } |
---|
465 | owl_fmtext_append_normal(fm, tmp); |
---|
466 | if (tmp) owl_free(tmp); |
---|
467 | |
---|
468 | tmp=owl_strdup(owl_message_get_body(m)); |
---|
469 | owl_util_tr(tmp, '\n', ' '); |
---|
470 | owl_fmtext_append_ztext(fm, tmp); |
---|
471 | owl_fmtext_append_normal(fm, "\n"); |
---|
472 | if (tmp) owl_free(tmp); |
---|
473 | } |
---|
474 | |
---|
475 | /* make personal messages bold for smaat users */ |
---|
476 | if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES) && |
---|
477 | owl_message_is_personal(m) && |
---|
478 | owl_message_is_direction_in(m)) { |
---|
479 | owl_fmtext_addattr(fm, OWL_FMTEXT_ATTR_BOLD); |
---|
480 | } |
---|
481 | |
---|
482 | owl_free(sender); |
---|
483 | owl_free(recip); |
---|
484 | #endif |
---|
485 | } else if (owl_message_is_type_aim(m)) { |
---|
486 | owl_fmtext_append_spaces(fm, OWL_TAB); |
---|
487 | if (owl_message_is_login(m)) { |
---|
488 | tmp=owl_sprintf(baseformat, "<", "AIM LOGIN", "", owl_message_get_sender(m)); |
---|
489 | owl_fmtext_append_normal(fm, tmp); |
---|
490 | owl_fmtext_append_normal(fm, "\n"); |
---|
491 | if (tmp) owl_free(tmp); |
---|
492 | } else if (owl_message_is_logout(m)) { |
---|
493 | tmp=owl_sprintf(baseformat, "<", "AIM LOGOUT", "", owl_message_get_sender(m)); |
---|
494 | owl_fmtext_append_normal(fm, tmp); |
---|
495 | owl_fmtext_append_normal(fm, "\n"); |
---|
496 | if (tmp) owl_free(tmp); |
---|
497 | } else { |
---|
498 | if (owl_message_is_direction_in(m)) { |
---|
499 | tmp=owl_sprintf(baseformat, "<", "AIM", "", owl_message_get_sender(m)); |
---|
500 | owl_fmtext_append_normal(fm, tmp); |
---|
501 | if (tmp) owl_free(tmp); |
---|
502 | } else if (owl_message_is_direction_out(m)) { |
---|
503 | tmp=owl_sprintf(baseformat, ">", "AIM", "", owl_message_get_recipient(m)); |
---|
504 | owl_fmtext_append_normal(fm, tmp); |
---|
505 | if (tmp) owl_free(tmp); |
---|
506 | } |
---|
507 | |
---|
508 | tmp=owl_strdup(owl_message_get_body(m)); |
---|
509 | owl_util_tr(tmp, '\n', ' '); |
---|
510 | owl_fmtext_append_normal(fm, tmp); |
---|
511 | owl_fmtext_append_normal(fm, "\n"); |
---|
512 | if (tmp) owl_free(tmp); |
---|
513 | |
---|
514 | /* make personal messages bold for smaat users */ |
---|
515 | if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES) && owl_message_is_direction_in(m)) { |
---|
516 | owl_fmtext_addattr(fm, OWL_FMTEXT_ATTR_BOLD); |
---|
517 | } |
---|
518 | } |
---|
519 | } else if (owl_message_is_type_admin(m)) { |
---|
520 | owl_fmtext_append_spaces(fm, OWL_TAB); |
---|
521 | owl_fmtext_append_normal(fm, "< ADMIN "); |
---|
522 | |
---|
523 | tmp=owl_strdup(owl_message_get_body(m)); |
---|
524 | owl_util_tr(tmp, '\n', ' '); |
---|
525 | owl_fmtext_append_normal(fm, tmp); |
---|
526 | owl_fmtext_append_normal(fm, "\n"); |
---|
527 | if (tmp) owl_free(tmp); |
---|
528 | } |
---|
529 | |
---|
530 | } |
---|
531 | |
---|
532 | void owl_stylefunc_vt(owl_fmtext *fm, owl_message *m) |
---|
533 | { |
---|
534 | #ifdef HAVE_LIBZEPHYR |
---|
535 | char *body, *indent, *ptr, *zsigbuff, frombuff[LINE]; |
---|
536 | owl_fmtext fm_first, fm_other, fm_tmp; |
---|
537 | ZNotice_t *n; |
---|
538 | #endif |
---|
539 | char *sender, *hostname, *timestr, *classinst1, *classinst2; |
---|
540 | |
---|
541 | if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) { |
---|
542 | #ifdef HAVE_LIBZEPHYR |
---|
543 | n=owl_message_get_notice(m); |
---|
544 | |
---|
545 | /* get the body */ |
---|
546 | body=owl_malloc(strlen(owl_message_get_body(m))+30); |
---|
547 | strcpy(body, owl_message_get_body(m)); |
---|
548 | |
---|
549 | /* add a newline if we need to */ |
---|
550 | if (body[0]!='\0' && body[strlen(body)-1]!='\n') { |
---|
551 | strcat(body, "\n"); |
---|
552 | } |
---|
553 | |
---|
554 | owl_fmtext_init_null(&fm_tmp); |
---|
555 | owl_fmtext_append_ztext(&fm_tmp, body); |
---|
556 | owl_fmtext_init_null(&fm_first); |
---|
557 | owl_fmtext_truncate_lines(&fm_tmp, 0, 1, &fm_first); |
---|
558 | |
---|
559 | /* do the indenting into indent */ |
---|
560 | indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10); |
---|
561 | owl_text_indent(indent, body, 31); |
---|
562 | |
---|
563 | owl_fmtext_free(&fm_tmp); |
---|
564 | owl_fmtext_init_null(&fm_tmp); |
---|
565 | owl_fmtext_append_ztext(&fm_tmp, indent); |
---|
566 | owl_fmtext_init_null(&fm_other); |
---|
567 | owl_fmtext_truncate_lines(&fm_tmp, 1, owl_fmtext_num_lines(&fm_tmp)-1, &fm_other); |
---|
568 | owl_fmtext_free(&fm_tmp); |
---|
569 | |
---|
570 | /* edit the from addr for printing */ |
---|
571 | strcpy(frombuff, owl_message_get_sender(m)); |
---|
572 | ptr=strchr(frombuff, '@'); |
---|
573 | if (ptr && !strncmp(ptr+1, owl_zephyr_get_realm(), strlen(owl_zephyr_get_realm()))) { |
---|
574 | *ptr='\0'; |
---|
575 | } |
---|
576 | sender=owl_sprintf("%-9.9s", frombuff); |
---|
577 | |
---|
578 | hostname=owl_sprintf("%-9.9s", owl_message_get_hostname(m)); |
---|
579 | timestr=owl_strdup("00:00"); |
---|
580 | classinst1=owl_sprintf("<%s>[%s]", owl_message_get_class(m), owl_message_get_instance(m)); |
---|
581 | classinst2=owl_sprintf("%-9.9s", classinst1); |
---|
582 | |
---|
583 | /* set the message for printing */ |
---|
584 | owl_fmtext_append_normal(fm, OWL_TABSTR); |
---|
585 | |
---|
586 | if (owl_message_is_ping(m) && owl_message_is_private(m)) { |
---|
587 | owl_fmtext_append_bold(fm, "PING"); |
---|
588 | owl_fmtext_append_normal(fm, " from "); |
---|
589 | owl_fmtext_append_bold(fm, frombuff); |
---|
590 | owl_fmtext_append_normal(fm, "\n"); |
---|
591 | } else if (owl_message_is_loginout(m)) { |
---|
592 | char *ptr, *host, *tty; |
---|
593 | int len; |
---|
594 | |
---|
595 | ptr=owl_zephyr_get_field(n, 1, &len); |
---|
596 | host=owl_malloc(len+10); |
---|
597 | strncpy(host, ptr, len); |
---|
598 | host[len]='\0'; |
---|
599 | |
---|
600 | ptr=owl_zephyr_get_field(n, 3, &len); |
---|
601 | tty=owl_malloc(len+10); |
---|
602 | strncpy(tty, ptr, len); |
---|
603 | tty[len]='\0'; |
---|
604 | |
---|
605 | if (owl_message_is_login(m)) { |
---|
606 | owl_fmtext_append_bold(fm, "LOGIN"); |
---|
607 | } else if (owl_message_is_logout(m)) { |
---|
608 | owl_fmtext_append_bold(fm, "LOGOUT"); |
---|
609 | } |
---|
610 | owl_fmtext_append_normal(fm, " for "); |
---|
611 | ptr=short_zuser(owl_message_get_instance(m)); |
---|
612 | owl_fmtext_append_bold(fm, ptr); |
---|
613 | owl_free(ptr); |
---|
614 | owl_fmtext_append_normal(fm, " at "); |
---|
615 | owl_fmtext_append_normal(fm, host); |
---|
616 | owl_fmtext_append_normal(fm, " "); |
---|
617 | owl_fmtext_append_normal(fm, tty); |
---|
618 | owl_fmtext_append_normal(fm, "\n"); |
---|
619 | |
---|
620 | owl_free(host); |
---|
621 | owl_free(tty); |
---|
622 | } else { |
---|
623 | owl_fmtext_append_normal(fm, sender); |
---|
624 | owl_fmtext_append_normal(fm, "|"); |
---|
625 | owl_fmtext_append_normal(fm, hostname); |
---|
626 | owl_fmtext_append_normal(fm, " "); |
---|
627 | owl_fmtext_append_normal(fm, timestr); |
---|
628 | owl_fmtext_append_normal(fm, " "); |
---|
629 | owl_fmtext_append_normal(fm, classinst2); |
---|
630 | |
---|
631 | owl_fmtext_append_normal(fm, " "); |
---|
632 | owl_fmtext_append_fmtext(fm, &fm_first); |
---|
633 | owl_fmtext_append_fmtext(fm, &fm_other); |
---|
634 | |
---|
635 | owl_fmtext_free(&fm_other); |
---|
636 | owl_fmtext_free(&fm_first); |
---|
637 | |
---|
638 | /* make private messages bold for smaat users */ |
---|
639 | if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) { |
---|
640 | if (owl_message_is_personal(m)) { |
---|
641 | owl_fmtext_addattr((&m->fmtext), OWL_FMTEXT_ATTR_BOLD); |
---|
642 | } |
---|
643 | } |
---|
644 | } |
---|
645 | |
---|
646 | owl_free(sender); |
---|
647 | owl_free(hostname); |
---|
648 | owl_free(timestr); |
---|
649 | owl_free(classinst1); |
---|
650 | owl_free(classinst2); |
---|
651 | |
---|
652 | owl_free(body); |
---|
653 | owl_free(indent); |
---|
654 | #endif |
---|
655 | } else if (owl_message_is_type_zephyr(m) && owl_message_is_direction_out(m)) { |
---|
656 | char *indent, *text, *zsigbuff, *foo; |
---|
657 | |
---|
658 | text=owl_message_get_body(m); |
---|
659 | |
---|
660 | indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10); |
---|
661 | owl_text_indent(indent, text, OWL_MSGTAB); |
---|
662 | owl_fmtext_append_normal(fm, OWL_TABSTR); |
---|
663 | owl_fmtext_append_normal(fm, "Zephyr sent to "); |
---|
664 | foo=short_zuser(owl_message_get_recipient(m)); |
---|
665 | owl_fmtext_append_normal(fm, foo); |
---|
666 | owl_free(foo); |
---|
667 | owl_fmtext_append_normal(fm, " (Zsig: "); |
---|
668 | |
---|
669 | zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30); |
---|
670 | owl_message_pretty_zsig(m, zsigbuff); |
---|
671 | owl_fmtext_append_ztext(fm, zsigbuff); |
---|
672 | owl_free(zsigbuff); |
---|
673 | |
---|
674 | owl_fmtext_append_normal(fm, ")"); |
---|
675 | owl_fmtext_append_normal(fm, "\n"); |
---|
676 | owl_fmtext_append_ztext(fm, indent); |
---|
677 | if (text[strlen(text)-1]!='\n') { |
---|
678 | owl_fmtext_append_normal(fm, "\n"); |
---|
679 | } |
---|
680 | |
---|
681 | owl_free(indent); |
---|
682 | } else if (owl_message_is_type_aim(m)) { |
---|
683 | char *indent; |
---|
684 | |
---|
685 | if (owl_message_is_loginout(m)) { |
---|
686 | owl_fmtext_append_normal(fm, OWL_TABSTR); |
---|
687 | if (owl_message_is_login(m)) { |
---|
688 | owl_fmtext_append_bold(fm, "AIM LOGIN"); |
---|
689 | } else { |
---|
690 | owl_fmtext_append_bold(fm, "AIM LOGOUT"); |
---|
691 | } |
---|
692 | owl_fmtext_append_normal(fm, " for "); |
---|
693 | owl_fmtext_append_normal(fm, owl_message_get_sender(m)); |
---|
694 | owl_fmtext_append_normal(fm, "\n"); |
---|
695 | } else if (owl_message_is_direction_in(m)) { |
---|
696 | indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10); |
---|
697 | owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB); |
---|
698 | owl_fmtext_append_bold(fm, OWL_TABSTR); |
---|
699 | owl_fmtext_append_bold(fm, "AIM from "); |
---|
700 | owl_fmtext_append_bold(fm, owl_message_get_sender(m)); |
---|
701 | owl_fmtext_append_bold(fm, "\n"); |
---|
702 | owl_fmtext_append_bold(fm, indent); |
---|
703 | if (indent[strlen(indent)-1]!='\n') { |
---|
704 | owl_fmtext_append_normal(fm, "\n"); |
---|
705 | } |
---|
706 | owl_free(indent); |
---|
707 | } else if (owl_message_is_direction_out(m)) { |
---|
708 | indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10); |
---|
709 | owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB); |
---|
710 | owl_fmtext_append_normal(fm, OWL_TABSTR); |
---|
711 | owl_fmtext_append_normal(fm, "AIM sent to "); |
---|
712 | owl_fmtext_append_normal(fm, owl_message_get_recipient(m)); |
---|
713 | owl_fmtext_append_normal(fm, "\n"); |
---|
714 | owl_fmtext_append_ztext(fm, indent); |
---|
715 | if (indent[strlen(indent)-1]!='\n') { |
---|
716 | owl_fmtext_append_normal(fm, "\n"); |
---|
717 | } |
---|
718 | owl_free(indent); |
---|
719 | } |
---|
720 | } else if (owl_message_is_type_admin(m)) { |
---|
721 | char *text, *header, *indent; |
---|
722 | |
---|
723 | text=owl_message_get_body(m); |
---|
724 | header=owl_message_get_attribute_value(m, "adminheader"); |
---|
725 | |
---|
726 | indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10); |
---|
727 | owl_text_indent(indent, text, OWL_MSGTAB); |
---|
728 | owl_fmtext_append_normal(fm, OWL_TABSTR); |
---|
729 | owl_fmtext_append_bold(fm, "OWL ADMIN "); |
---|
730 | owl_fmtext_append_ztext(fm, header); |
---|
731 | owl_fmtext_append_normal(fm, "\n"); |
---|
732 | owl_fmtext_append_ztext(fm, indent); |
---|
733 | if (text[strlen(text)-1]!='\n') { |
---|
734 | owl_fmtext_append_normal(fm, "\n"); |
---|
735 | } |
---|
736 | |
---|
737 | owl_free(indent); |
---|
738 | } |
---|
739 | } |
---|