source: stylefunc.c @ f98c74e

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