source: stylefunc.c @ 778d0a9

barnowl_perlaimdebianowlrelease-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 778d0a9 was 778d0a9, checked in by James M. Kretchmar <kretch@mit.edu>, 17 years ago
Added hostname and tty name to LOGIN/LOGOUT zephyrs on oneline style
  • Property mode set to 100644
File size: 17.3 KB
Line 
1#include "owl.h"
2
3static const char fileIdent[] = "$Id$";
4
5/* In all of these functions, 'fm' is expected to already be
6 * initialized.
7 */
8   
9void owl_stylefunc_basic(owl_fmtext *fm, owl_message *m)
10{
11  char *body, *indent, *ptr, *zsigbuff, frombuff[LINE];
12  ZNotice_t *n;
13
14  if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
15    n=owl_message_get_notice(m);
16
17    /* get the body */
18    body=owl_strdup(owl_message_get_body(m));
19    body=realloc(body, strlen(body)+30);
20
21    /* add a newline if we need to */
22    if (body[0]!='\0' && body[strlen(body)-1]!='\n') {
23      strcat(body, "\n");
24    }
25   
26    /* do the indenting into indent */
27    indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10);
28    owl_text_indent(indent, body, OWL_MSGTAB);
29   
30    /* edit the from addr for printing */
31    strcpy(frombuff, owl_message_get_sender(m));
32    ptr=strchr(frombuff, '@');
33    if (ptr && !strncmp(ptr+1, ZGetRealm(), strlen(ZGetRealm()))) {
34      *ptr='\0';
35    }
36   
37    /* set the message for printing */
38    owl_fmtext_append_normal(fm, OWL_TABSTR);
39   
40    if (owl_message_is_ping(m)) {
41      owl_fmtext_append_bold(fm, "PING");
42      owl_fmtext_append_normal(fm, " from ");
43      owl_fmtext_append_bold(fm, frombuff);
44      owl_fmtext_append_normal(fm, "\n");
45    } else if (owl_message_is_loginout(m)) {
46      char *ptr, *host, *tty;
47      int len;
48
49      ptr=owl_zephyr_get_field(n, 1, &len);
50      host=owl_malloc(len+10);
51      strncpy(host, ptr, len);
52      host[len]='\0';
53
54      ptr=owl_zephyr_get_field(n, 3, &len);
55      tty=owl_malloc(len+10);
56      strncpy(tty, ptr, len);
57      tty[len]='\0';
58
59      if (owl_message_is_login(m)) {
60        owl_fmtext_append_bold(fm, "LOGIN");
61      } else if (owl_message_is_logout(m)) {
62        owl_fmtext_append_bold(fm, "LOGOUT");
63      }
64      owl_fmtext_append_normal(fm, " for ");
65      ptr=short_zuser(owl_message_get_instance(m));
66      owl_fmtext_append_bold(fm, ptr);
67      owl_free(ptr);
68      owl_fmtext_append_normal(fm, " at ");
69      owl_fmtext_append_normal(fm, host);
70      owl_fmtext_append_normal(fm, " ");
71      owl_fmtext_append_normal(fm, tty);
72      owl_fmtext_append_normal(fm, "\n");
73
74      owl_free(host);
75      owl_free(tty);
76    } else {
77      owl_fmtext_append_normal(fm, "From: ");
78      if (strcasecmp(owl_message_get_class(m), "message")) {
79        owl_fmtext_append_normal(fm, "Class ");
80        owl_fmtext_append_normal(fm, owl_message_get_class(m));
81        owl_fmtext_append_normal(fm, " / Instance ");
82        owl_fmtext_append_normal(fm, owl_message_get_instance(m));
83        owl_fmtext_append_normal(fm, " / ");
84      }
85      owl_fmtext_append_normal(fm, frombuff);
86      if (strcasecmp(owl_message_get_realm(m), ZGetRealm())) {
87        owl_fmtext_append_normal(fm, " {");
88        owl_fmtext_append_normal(fm, owl_message_get_realm(m));
89        owl_fmtext_append_normal(fm, "} ");
90      }
91     
92      /* stick on the zsig */
93      zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);
94      owl_message_pretty_zsig(m, zsigbuff);
95      owl_fmtext_append_normal(fm, "    (");
96      owl_fmtext_append_ztext(fm, zsigbuff);
97      owl_fmtext_append_normal(fm, ")");
98      owl_fmtext_append_normal(fm, "\n");
99      owl_free(zsigbuff);
100     
101      /* then the indented message */
102      owl_fmtext_append_ztext(fm, indent);
103     
104      /* make personal messages bold for smaat users */
105      if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {
106        if (owl_message_is_personal(m)) {
107          owl_fmtext_addattr((&m->fmtext), OWL_FMTEXT_ATTR_BOLD);
108        }
109      }
110    }
111   
112    owl_free(body);
113    owl_free(indent);
114  } else if (owl_message_is_type_zephyr(m) && owl_message_is_direction_out(m)) {
115    char *indent, *text, *zsigbuff, *foo;
116     
117    text=owl_message_get_body(m);
118   
119    indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
120    owl_text_indent(indent, text, OWL_MSGTAB);
121    owl_fmtext_append_normal(fm, OWL_TABSTR);
122    owl_fmtext_append_normal(fm, "To: ");
123    foo=short_zuser(owl_message_get_recipient(m));
124    owl_fmtext_append_normal(fm, foo);
125    owl_free(foo);
126    owl_fmtext_append_normal(fm, "  (Zsig: ");
127   
128    zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);
129    owl_message_pretty_zsig(m, zsigbuff);
130    owl_fmtext_append_ztext(fm, zsigbuff);
131    owl_free(zsigbuff);
132   
133    owl_fmtext_append_normal(fm, ")");
134    owl_fmtext_append_normal(fm, "\n");
135    owl_fmtext_append_ztext(fm, indent);
136    if (text[strlen(text)-1]!='\n') {
137      owl_fmtext_append_normal(fm, "\n");
138    }
139   
140    owl_free(indent);
141  } else if (owl_message_is_type_aim(m)) {
142    char *indent;
143   
144    if (owl_message_is_loginout(m)) {
145      owl_fmtext_append_normal(fm, OWL_TABSTR);
146      if (owl_message_is_login(m)) {
147        owl_fmtext_append_bold(fm, "AIM LOGIN");
148      } else {
149        owl_fmtext_append_bold(fm, "AIM LOGOUT");
150      }
151      owl_fmtext_append_normal(fm, " for ");
152      owl_fmtext_append_normal(fm, owl_message_get_sender(m));
153      owl_fmtext_append_normal(fm, "\n");
154    } else if (owl_message_is_direction_in(m)) {
155      indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10);
156      owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB);
157      owl_fmtext_append_bold(fm, OWL_TABSTR);
158      owl_fmtext_append_bold(fm, "AIM from ");
159      owl_fmtext_append_bold(fm, owl_message_get_sender(m));
160      owl_fmtext_append_bold(fm, "\n");
161      owl_fmtext_append_bold(fm, indent);
162      if (indent[strlen(indent)-1]!='\n') {
163        owl_fmtext_append_normal(fm, "\n");
164      }
165      owl_free(indent);
166    } else if (owl_message_is_direction_out(m)) {
167      indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10);
168      owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB);
169      owl_fmtext_append_normal(fm, OWL_TABSTR);
170      owl_fmtext_append_normal(fm, "AIM sent to ");
171      owl_fmtext_append_normal(fm, owl_message_get_recipient(m));
172      owl_fmtext_append_normal(fm, "\n");
173      owl_fmtext_append_ztext(fm, indent);
174      if (indent[strlen(indent)-1]!='\n') {
175        owl_fmtext_append_normal(fm, "\n");
176      }
177      owl_free(indent);
178    }
179  } else if (owl_message_is_type_admin(m)) {
180    char *text, *header, *indent;
181   
182    text=owl_message_get_body(m);
183    header=owl_message_get_attribute_value(m, "adminheader");
184   
185    indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
186    owl_text_indent(indent, text, OWL_MSGTAB);
187    owl_fmtext_append_normal(fm, OWL_TABSTR);
188    owl_fmtext_append_bold(fm, "OWL ADMIN ");
189    owl_fmtext_append_ztext(fm, header);
190    owl_fmtext_append_normal(fm, "\n");
191    owl_fmtext_append_ztext(fm, indent);
192    if (text[strlen(text)-1]!='\n') {
193      owl_fmtext_append_normal(fm, "\n");
194    }
195   
196    owl_free(indent);
197  }
198}
199
200void owl_stylefunc_default(owl_fmtext *fm, owl_message *m)
201{
202  char *body, *indent, *ptr, *zsigbuff, frombuff[LINE];
203  ZNotice_t *n;
204
205  if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
206    n=owl_message_get_notice(m);
207 
208    /* get the body */
209    body=owl_malloc(strlen(owl_message_get_body(m))+30);
210    strcpy(body, owl_message_get_body(m));
211   
212    /* add a newline if we need to */
213    if (body[0]!='\0' && body[strlen(body)-1]!='\n') {
214      strcat(body, "\n");
215    }
216   
217    /* do the indenting into indent */
218    indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10);
219    owl_text_indent(indent, body, OWL_MSGTAB);
220   
221    /* edit the from addr for printing */
222    strcpy(frombuff, owl_message_get_sender(m));
223    ptr=strchr(frombuff, '@');
224    if (ptr && !strncmp(ptr+1, ZGetRealm(), strlen(ZGetRealm()))) {
225      *ptr='\0';
226    }
227   
228    /* set the message for printing */
229    owl_fmtext_append_normal(fm, OWL_TABSTR);
230   
231    if (owl_message_is_ping(m) && owl_message_is_private(m)) {
232      owl_fmtext_append_bold(fm, "PING");
233      owl_fmtext_append_normal(fm, " from ");
234      owl_fmtext_append_bold(fm, frombuff);
235      owl_fmtext_append_normal(fm, "\n");
236    } else if (owl_message_is_loginout(m)) {
237      char *ptr, *host, *tty;
238      int len;
239
240      ptr=owl_zephyr_get_field(n, 1, &len);
241      host=owl_malloc(len+10);
242      strncpy(host, ptr, len);
243      host[len]='\0';
244
245      ptr=owl_zephyr_get_field(n, 3, &len);
246      tty=owl_malloc(len+10);
247      strncpy(tty, ptr, len);
248      tty[len]='\0';
249     
250      if (owl_message_is_login(m)) {
251        owl_fmtext_append_bold(fm, "LOGIN");
252      } else if (owl_message_is_logout(m)) {
253        owl_fmtext_append_bold(fm, "LOGOUT");
254      }
255      owl_fmtext_append_normal(fm, " for ");
256      ptr=short_zuser(n->z_class_inst);
257      owl_fmtext_append_bold(fm, ptr);
258      owl_free(ptr);
259      owl_fmtext_append_normal(fm, " at ");
260      owl_fmtext_append_normal(fm, host);
261      owl_fmtext_append_normal(fm, " ");
262      owl_fmtext_append_normal(fm, tty);
263      owl_fmtext_append_normal(fm, "\n");
264
265      owl_free(host);
266      owl_free(tty);
267    } else {
268      owl_fmtext_append_normal(fm, owl_message_get_class(m));
269      owl_fmtext_append_normal(fm, " / ");
270      owl_fmtext_append_normal(fm, owl_message_get_instance(m));
271      owl_fmtext_append_normal(fm, " / ");
272      owl_fmtext_append_bold(fm, frombuff);
273      if (strcasecmp(owl_message_get_realm(m), ZGetRealm())) {
274        owl_fmtext_append_normal(fm, " {");
275        owl_fmtext_append_normal(fm, owl_message_get_realm(m));
276        owl_fmtext_append_normal(fm, "} ");
277      }
278      if (n->z_opcode[0]!='\0') {
279        owl_fmtext_append_normal(fm, " [");
280        owl_fmtext_append_normal(fm, owl_message_get_opcode(m));
281        owl_fmtext_append_normal(fm, "] ");
282      }
283     
284      /* stick on the zsig */
285      zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);
286      owl_message_pretty_zsig(m, zsigbuff);
287      owl_fmtext_append_normal(fm, "    (");
288      owl_fmtext_append_ztext(fm, zsigbuff);
289      owl_fmtext_append_normal(fm, ")");
290      owl_fmtext_append_normal(fm, "\n");
291      owl_free(zsigbuff);
292     
293      /* then the indented message */
294      owl_fmtext_append_ztext(fm, indent);
295     
296      /* make private messages bold for smaat users */
297      if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {
298        if (owl_message_is_personal(m)) {
299          owl_fmtext_addattr((&m->fmtext), OWL_FMTEXT_ATTR_BOLD);
300        }
301      }
302    }
303   
304    owl_free(body);
305    owl_free(indent);
306  } else if (owl_message_is_type_zephyr(m) && owl_message_is_direction_out(m)) {
307    char *indent, *text, *zsigbuff, *foo;
308   
309    text=owl_message_get_body(m);
310   
311    indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
312    owl_text_indent(indent, text, OWL_MSGTAB);
313    owl_fmtext_append_normal(fm, OWL_TABSTR);
314    owl_fmtext_append_normal(fm, "Zephyr sent to ");
315    foo=short_zuser(owl_message_get_recipient(m));
316    owl_fmtext_append_normal(fm, foo);
317    owl_free(foo);
318    owl_fmtext_append_normal(fm, "  (Zsig: ");
319   
320    zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);
321    owl_message_pretty_zsig(m, zsigbuff);
322    owl_fmtext_append_ztext(fm, zsigbuff);
323    owl_free(zsigbuff);
324   
325    owl_fmtext_append_normal(fm, ")");
326    owl_fmtext_append_normal(fm, "\n");
327    owl_fmtext_append_ztext(fm, indent);
328    if (text[strlen(text)-1]!='\n') {
329      owl_fmtext_append_normal(fm, "\n");
330    }
331   
332    owl_free(indent);
333  } else if (owl_message_is_type_aim(m)) {
334    char *indent;
335   
336    if (owl_message_is_loginout(m)) {
337      owl_fmtext_append_normal(fm, OWL_TABSTR);
338      if (owl_message_is_login(m)) {
339        owl_fmtext_append_bold(fm, "AIM LOGIN");
340      } else {
341        owl_fmtext_append_bold(fm, "AIM LOGOUT");
342      }
343      owl_fmtext_append_normal(fm, " for ");
344      owl_fmtext_append_normal(fm, owl_message_get_sender(m));
345      owl_fmtext_append_normal(fm, "\n");
346    } else if (owl_message_is_direction_in(m)) {
347      indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10);
348      owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB);
349      owl_fmtext_append_bold(fm, OWL_TABSTR);
350      owl_fmtext_append_bold(fm, "AIM from ");
351      owl_fmtext_append_bold(fm, owl_message_get_sender(m));
352      owl_fmtext_append_bold(fm, "\n");
353      owl_fmtext_append_bold(fm, indent);
354      if (indent[strlen(indent)-1]!='\n') {
355        owl_fmtext_append_normal(fm, "\n");
356      }
357      owl_free(indent);
358    } else if (owl_message_is_direction_out(m)) {
359      indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10);
360      owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB);
361      owl_fmtext_append_normal(fm, OWL_TABSTR);
362      owl_fmtext_append_normal(fm, "AIM sent to ");
363      owl_fmtext_append_normal(fm, owl_message_get_recipient(m));
364      owl_fmtext_append_normal(fm, "\n");
365      owl_fmtext_append_ztext(fm, indent);
366      if (indent[strlen(indent)-1]!='\n') {
367        owl_fmtext_append_normal(fm, "\n");
368      }
369      owl_free(indent);
370    }
371  } else if (owl_message_is_type_admin(m)) {
372    char *text, *header, *indent;
373   
374    text=owl_message_get_body(m);
375    header=owl_message_get_attribute_value(m, "adminheader");
376   
377    indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
378    owl_text_indent(indent, text, OWL_MSGTAB);
379    owl_fmtext_append_normal(fm, OWL_TABSTR);
380    owl_fmtext_append_bold(fm, "OWL ADMIN ");
381    owl_fmtext_append_ztext(fm, header);
382    owl_fmtext_append_normal(fm, "\n");
383    owl_fmtext_append_ztext(fm, indent);
384    if (text[strlen(text)-1]!='\n') {
385      owl_fmtext_append_normal(fm, "\n");
386    }
387   
388    owl_free(indent);
389  }
390}
391
392void owl_stylefunc_oneline(owl_fmtext *fm, owl_message *m)
393{
394  char *tmp;
395  char *baseformat="%s %-13.13s %-11.11s %-12.12s ";
396  char *sender, *recip;
397  ZNotice_t *n;
398
399
400  sender=short_zuser(owl_message_get_sender(m));
401  recip=short_zuser(owl_message_get_recipient(m));
402 
403  if (owl_message_is_type_zephyr(m)) {
404    n=owl_message_get_notice(m);
405   
406    owl_fmtext_append_spaces(fm, OWL_TAB);
407
408    if (owl_message_is_loginout(m)) {
409      char *ptr, *host, *tty;
410      int len;
411     
412      ptr=owl_zephyr_get_field(n, 1, &len);
413      host=owl_malloc(len+10);
414      strncpy(host, ptr, len);
415      host[len]='\0';
416
417      ptr=owl_zephyr_get_field(n, 3, &len);
418      tty=owl_malloc(len+10);
419      strncpy(tty, ptr, len);
420      tty[len]='\0';
421
422      if (owl_message_is_login(m)) {
423        tmp=owl_sprintf(baseformat, "<", "LOGIN", "", sender);
424        owl_fmtext_append_normal(fm, tmp);
425        owl_free(tmp);
426      } else if (owl_message_is_logout(m)) {
427        tmp=owl_sprintf(baseformat, "<", "LOGOUT", "", sender);
428        owl_fmtext_append_normal(fm, tmp);
429        owl_free(tmp);
430      }
431
432      owl_fmtext_append_normal(fm, "at ");
433      owl_fmtext_append_normal(fm, host);
434      owl_fmtext_append_normal(fm, " ");
435      owl_fmtext_append_normal(fm, tty);
436      owl_fmtext_append_normal(fm, "\n");
437
438      owl_free(host);
439      owl_free(tty);
440
441    } else if (owl_message_is_ping(m)) {
442      tmp=owl_sprintf(baseformat, "<", "PING", "", sender);
443      owl_fmtext_append_normal(fm, tmp);
444      owl_fmtext_append_normal(fm, "\n");
445      owl_free(tmp);
446
447    } else {
448      if (owl_message_is_direction_in(m)) {
449        tmp=owl_sprintf(baseformat, "<", owl_message_get_class(m), owl_message_get_instance(m), sender);
450      } else if (owl_message_is_direction_out(m)) {
451        tmp=owl_sprintf(baseformat, ">", owl_message_get_class(m), owl_message_get_instance(m), recip);
452      } else {
453        tmp=owl_sprintf(baseformat, "-", owl_message_get_class(m), owl_message_get_instance(m), sender);
454      }
455      owl_fmtext_append_normal(fm, tmp);
456      if (tmp) owl_free(tmp);
457     
458      tmp=owl_strdup(owl_message_get_body(m));
459      owl_util_tr(tmp, '\n', ' ');
460      owl_fmtext_append_ztext(fm, tmp);
461      owl_fmtext_append_normal(fm, "\n");
462      if (tmp) owl_free(tmp);
463    }
464     
465    /* make personal messages bold for smaat users */
466    if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES) &&
467        owl_message_is_personal(m) &&
468        owl_message_is_direction_in(m)) {
469      owl_fmtext_addattr(fm, OWL_FMTEXT_ATTR_BOLD);
470    }
471
472    owl_free(sender);
473    owl_free(recip);
474   
475  } else if (owl_message_is_type_aim(m)) {
476    owl_fmtext_append_spaces(fm, OWL_TAB);
477    if (owl_message_is_login(m)) {
478      tmp=owl_sprintf(baseformat, "<", "AIM LOGIN", "", owl_message_get_sender(m));
479      owl_fmtext_append_normal(fm, tmp);
480      owl_fmtext_append_normal(fm, "\n");
481      if (tmp) owl_free(tmp);
482    } else if (owl_message_is_logout(m)) {
483      tmp=owl_sprintf(baseformat, "<", "AIM LOGOUT", "", owl_message_get_sender(m));
484      owl_fmtext_append_normal(fm, tmp);
485      owl_fmtext_append_normal(fm, "\n");
486      if (tmp) owl_free(tmp);
487    } else {
488      if (owl_message_is_direction_in(m)) {
489        tmp=owl_sprintf(baseformat, "<", "AIM", "", owl_message_get_sender(m));
490        owl_fmtext_append_normal(fm, tmp);
491        if (tmp) owl_free(tmp);
492      } else if (owl_message_is_direction_out(m)) {
493        tmp=owl_sprintf(baseformat, ">", "AIM", "", owl_message_get_recipient(m));
494        owl_fmtext_append_normal(fm, tmp);
495        if (tmp) owl_free(tmp);
496      }
497     
498      tmp=owl_strdup(owl_message_get_body(m));
499      owl_util_tr(tmp, '\n', ' ');
500      owl_fmtext_append_normal(fm, tmp);
501      owl_fmtext_append_normal(fm, "\n");
502      if (tmp) owl_free(tmp);
503
504      /* make personal messages bold for smaat users */
505      if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES) && owl_message_is_direction_in(m)) {
506        owl_fmtext_addattr(fm, OWL_FMTEXT_ATTR_BOLD);
507      }
508    }
509  } else if (owl_message_is_type_admin(m)) {
510    owl_fmtext_append_spaces(fm, OWL_TAB);
511    owl_fmtext_append_normal(fm, "< ADMIN                                        ");
512   
513    tmp=owl_strdup(owl_message_get_body(m));
514    owl_util_tr(tmp, '\n', ' ');
515    owl_fmtext_append_normal(fm, tmp);
516    owl_fmtext_append_normal(fm, "\n");
517    if (tmp) owl_free(tmp);
518  }
519
520}
Note: See TracBrowser for help on using the repository browser.