source: message.c @ 8c92848

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 8c92848 was f4d0975, checked in by James M. Kretchmar <kretch@mit.edu>, 21 years ago
Fixed bug with idle times causing broken pipes. New libfaim
  • Property mode set to 100644
File size: 19.2 KB
Line 
1#include <stdlib.h>
2#include <unistd.h>
3#include <string.h>
4#include <sys/socket.h>
5#include <netdb.h>
6#include <sys/types.h>
7#include <sys/socket.h>
8#include <netinet/in.h>
9#include <arpa/inet.h>
10#include <time.h>
11#include "owl.h"
12
13static const char fileIdent[] = "$Id$";
14
15void owl_message_init(owl_message *m)
16{
17  time_t t;
18
19  m->id=owl_global_get_nextmsgid(&g);
20  m->type=OWL_MESSAGE_TYPE_GENERIC;
21  owl_message_set_direction_none(m);
22  m->delete=0;
23  strcpy(m->hostname, "");
24  m->zwriteline=strdup("");
25  m->invalid_format=1;
26
27  owl_list_create(&(m->attributes));
28 
29  /* save the time */
30  t=time(NULL);
31  m->time=owl_strdup(ctime(&t));
32  m->time[strlen(m->time)-1]='\0';
33  owl_fmtext_init_null(&(m->fmtext));
34}
35
36void owl_message_set_attribute(owl_message *m, char *attrname, char *attrvalue)
37{
38  /* add the named attribute to the message.  If an attribute with the
39     name already exists, replace the old value with the new value */
40
41  int i, j;
42  owl_pair *p;
43
44  /* look for an existing pair with this key, and nuke the entry if
45     found */
46  j=owl_list_get_size(&(m->attributes));
47  for (i=0; i<j; i++) {
48    p=owl_list_get_element(&(m->attributes), i);
49    if (!strcmp(owl_pair_get_key(p), attrname)) {
50      owl_free(owl_pair_get_key(p));
51      owl_free(owl_pair_get_value(p));
52      owl_free(p);
53      owl_list_remove_element(&(m->attributes), i);
54      break;
55    }
56  }
57
58  p=owl_malloc(sizeof(owl_pair));
59  owl_pair_create(p, owl_strdup(attrname), owl_strdup(attrvalue));
60  owl_list_append_element(&(m->attributes), p);
61}
62
63char *owl_message_get_attribute_value(owl_message *m, char *attrname)
64{
65  /* return the value associated with the named attribute, or NULL if
66     the attribute does not exist */
67  int i, j;
68  owl_pair *p;
69
70  j=owl_list_get_size(&(m->attributes));
71  for (i=0; i<j; i++) {
72    p=owl_list_get_element(&(m->attributes), i);
73    if (!strcmp(owl_pair_get_key(p), attrname)) {
74      return(owl_pair_get_value(p));
75    }
76  }
77
78  /*
79  owl_function_debugmsg("No attribute %s found for message %i",
80                        attrname,
81                        owl_message_get_id(m));
82  */
83  return(NULL);
84}
85
86/* We cheat and indent it for now, since we really want this for
87 * the 'info' function.  Later there should just be a generic
88 * function to indent fmtext.
89 */
90void owl_message_attributes_tofmtext(owl_message *m, owl_fmtext *fm) {
91  int i, j;
92  owl_pair *p;
93  char *buff;
94
95  owl_fmtext_init_null(fm);
96
97  j=owl_list_get_size(&(m->attributes));
98  for (i=0; i<j; i++) {
99    p=owl_list_get_element(&(m->attributes), i);
100    buff=owl_sprintf("  %-15.15s: %-35.35s\n", owl_pair_get_key(p), owl_pair_get_value(p));
101    owl_fmtext_append_normal(fm, buff);
102    owl_free(buff);
103  }
104}
105
106void owl_message_invalidate_format(owl_message *m)
107{
108  m->invalid_format=1;
109}
110
111owl_fmtext *owl_message_get_fmtext(owl_message *m)
112{
113  owl_message_format(m);
114  return(&(m->fmtext));
115}
116
117void owl_message_format(owl_message *m)
118{
119  owl_style *s;
120  owl_view *v;
121
122  if (m->invalid_format) {
123    /* for now we assume there's jsut the one view and use that style */
124    v=owl_global_get_current_view(&g);
125    s=owl_view_get_style(v);
126
127    owl_fmtext_free(&(m->fmtext));
128    owl_fmtext_init_null(&(m->fmtext));
129    owl_style_get_formattext(s, &(m->fmtext), m);
130    m->invalid_format=0;
131  }
132}
133
134void owl_message_set_class(owl_message *m, char *class)
135{
136  owl_message_set_attribute(m, "class", class);
137}
138
139char *owl_message_get_class(owl_message *m)
140{
141  char *class;
142
143  class=owl_message_get_attribute_value(m, "class");
144  if (!class) return("");
145  return(class);
146}
147
148void owl_message_set_instance(owl_message *m, char *inst)
149{
150  owl_message_set_attribute(m, "instance", inst);
151}
152
153char *owl_message_get_instance(owl_message *m)
154{
155  char *instance;
156
157  instance=owl_message_get_attribute_value(m, "instance");
158  if (!instance) return("");
159  return(instance);
160}
161
162void owl_message_set_sender(owl_message *m, char *sender)
163{
164  owl_message_set_attribute(m, "sender", sender);
165}
166
167char *owl_message_get_sender(owl_message *m)
168{
169  char *sender;
170
171  sender=owl_message_get_attribute_value(m, "sender");
172  if (!sender) return("");
173  return(sender);
174}
175
176void owl_message_set_zsig(owl_message *m, char *zsig)
177{
178  owl_message_set_attribute(m, "zsig", zsig);
179}
180
181char *owl_message_get_zsig(owl_message *m)
182{
183  char *zsig;
184
185  zsig=owl_message_get_attribute_value(m, "zsig");
186  if (!zsig) return("");
187  return(zsig);
188}
189
190void owl_message_set_recipient(owl_message *m, char *recip)
191{
192  owl_message_set_attribute(m, "recipient", recip);
193}
194
195char *owl_message_get_recipient(owl_message *m)
196{
197  /* this is stupid for outgoing messages, we need to fix it. */
198
199  char *recip;
200
201  recip=owl_message_get_attribute_value(m, "recipient");
202  if (!recip) return("");
203  return(recip);
204}
205
206void owl_message_set_realm(owl_message *m, char *realm)
207{
208  owl_message_set_attribute(m, "realm", realm);
209}
210
211char *owl_message_get_realm(owl_message *m)
212{
213  char *realm;
214 
215  realm=owl_message_get_attribute_value(m, "realm");
216  if (!realm) return("");
217  return(realm);
218}
219
220void owl_message_set_body(owl_message *m, char *body)
221{
222  owl_message_set_attribute(m, "body", body);
223}
224
225char *owl_message_get_body(owl_message *m)
226{
227  char *body;
228
229  body=owl_message_get_attribute_value(m, "body");
230  if (!body) return("");
231  return(body);
232}
233
234
235void owl_message_set_opcode(owl_message *m, char *opcode)
236{
237  owl_message_set_attribute(m, "opcode", opcode);
238}
239
240char *owl_message_get_opcode(owl_message *m)
241{
242  char *opcode;
243
244  opcode=owl_message_get_attribute_value(m, "opcode");
245  if (!opcode) return("");
246  return(opcode);
247}
248
249
250void owl_message_set_islogin(owl_message *m)
251{
252  owl_message_set_attribute(m, "loginout", "login");
253}
254
255
256void owl_message_set_islogout(owl_message *m)
257{
258  owl_message_set_attribute(m, "loginout", "logout");
259}
260
261int owl_message_is_loginout(owl_message *m)
262{
263  char *res;
264
265  res=owl_message_get_attribute_value(m, "loginout");
266  if (!res) return(0);
267  return(1);
268}
269
270int owl_message_is_login(owl_message *m)
271{
272  char *res;
273
274  res=owl_message_get_attribute_value(m, "loginout");
275  if (!res) return(0);
276  if (!strcmp(res, "login")) return(1);
277  return(0);
278}
279
280
281int owl_message_is_logout(owl_message *m)
282{
283  char *res;
284
285  res=owl_message_get_attribute_value(m, "loginout");
286  if (!res) return(0);
287  if (!strcmp(res, "logout")) return(1);
288  return(0);
289}
290
291void owl_message_set_isprivate(owl_message *m)
292{
293  owl_message_set_attribute(m, "isprivate", "");
294}
295
296int owl_message_is_private(owl_message *m)
297{
298  char *res;
299
300  res=owl_message_get_attribute_value(m, "isprivate");
301  if (!res) return(0);
302  return(1);
303}
304
305char *owl_message_get_timestr(owl_message *m)
306{
307  return(m->time);
308}
309
310void owl_message_set_type_admin(owl_message *m)
311{
312  m->type=OWL_MESSAGE_TYPE_ADMIN;
313}
314
315void owl_message_set_type_zephyr(owl_message *m)
316{
317  m->type=OWL_MESSAGE_TYPE_ZEPHYR;
318}
319
320void owl_message_set_type_aim(owl_message *m)
321{
322  m->type=OWL_MESSAGE_TYPE_AIM;
323}
324                                               
325int owl_message_is_type_admin(owl_message *m)
326{
327  if (m->type==OWL_MESSAGE_TYPE_ADMIN) return(1);
328  return(0);
329}
330
331int owl_message_is_type_zephyr(owl_message *m)
332{
333  if (m->type==OWL_MESSAGE_TYPE_ZEPHYR) return(1);
334  return(0);
335}
336
337int owl_message_is_type_aim(owl_message *m)
338{
339  if (m->type==OWL_MESSAGE_TYPE_AIM) return(1);
340  return(0);
341}
342
343int owl_message_is_type_generic(owl_message *m)
344{
345  if (m->type==OWL_MESSAGE_TYPE_GENERIC) return(1);
346  return(0);
347}
348
349char *owl_message_type_to_string(owl_message *m)
350{
351  if (m->type==OWL_MESSAGE_TYPE_ADMIN) return("admin");
352  if (m->type==OWL_MESSAGE_TYPE_GENERIC) return("generic");
353  if (m->type==OWL_MESSAGE_TYPE_ZEPHYR) return("zephyr");
354  if (m->type==OWL_MESSAGE_TYPE_AIM) return("aim");
355  if (m->type==OWL_MESSAGE_TYPE_JABBER) return("jabber");
356  if (m->type==OWL_MESSAGE_TYPE_ICQ) return("icq");
357  if (m->type==OWL_MESSAGE_TYPE_MSN) return("msn");
358  return("unknown");
359}
360
361char *owl_message_get_text(owl_message *m)
362{
363  return(owl_fmtext_get_text(&(m->fmtext)));
364}
365
366void owl_message_set_direction_in(owl_message *m)
367{
368  m->direction=OWL_MESSAGE_DIRECTION_IN;
369}
370
371void owl_message_set_direction_out(owl_message *m)
372{
373  m->direction=OWL_MESSAGE_DIRECTION_OUT;
374}
375
376void owl_message_set_direction_none(owl_message *m)
377{
378  m->direction=OWL_MESSAGE_DIRECTION_NONE;
379}
380
381int owl_message_is_direction_in(owl_message *m)
382{
383  if (m->direction==OWL_MESSAGE_DIRECTION_IN) return(1);
384  return(0);
385}
386
387int owl_message_is_direction_out(owl_message *m)
388{
389  if (m->direction==OWL_MESSAGE_DIRECTION_OUT) return(1);
390  return(0);
391}
392
393int owl_message_is_direction_none(owl_message *m)
394{
395  if (m->direction==OWL_MESSAGE_DIRECTION_NONE) return(1);
396  return(0);
397}
398
399int owl_message_get_numlines(owl_message *m)
400{
401  if (m == NULL) return(0);
402  owl_message_format(m);
403  return(owl_fmtext_num_lines(&(m->fmtext)));
404}
405
406void owl_message_mark_delete(owl_message *m)
407{
408  if (m == NULL) return;
409  m->delete=1;
410}
411
412void owl_message_unmark_delete(owl_message *m)
413{
414  if (m == NULL) return;
415  m->delete=0;
416}
417
418char *owl_message_get_zwriteline(owl_message *m)
419{
420  return(m->zwriteline);
421}
422
423void owl_message_set_zwriteline(owl_message *m, char *line)
424{
425  m->zwriteline=strdup(line);
426}
427
428int owl_message_is_delete(owl_message *m)
429{
430  if (m == NULL) return(0);
431  if (m->delete==1) return(1);
432  return(0);
433}
434
435#ifdef HAVE_LIBZEPHYR
436ZNotice_t *owl_message_get_notice(owl_message *m)
437{
438  return(&(m->notice));
439}
440#else
441void *owl_message_get_notice(owl_message *m)
442{
443  return(NULL);
444}
445#endif
446
447char *owl_message_get_hostname(owl_message *m)
448{
449  return(m->hostname);
450}
451
452
453void owl_message_curs_waddstr(owl_message *m, WINDOW *win, int aline, int bline, int acol, int bcol, int color)
454{
455  owl_fmtext a, b;
456
457  /* this will ensure that our cached copy is up to date */
458  owl_message_format(m);
459
460  owl_fmtext_init_null(&a);
461  owl_fmtext_init_null(&b);
462 
463  owl_fmtext_truncate_lines(&(m->fmtext), aline, bline-aline+1, &a);
464  owl_fmtext_truncate_cols(&a, acol, bcol, &b);
465  if (color!=OWL_COLOR_DEFAULT) {
466    owl_fmtext_colorize(&b, color);
467  }
468
469  if (owl_global_is_search_active(&g)) {
470    owl_fmtext_search_and_highlight(&b, owl_global_get_search_string(&g));
471  }
472     
473  owl_fmtext_curs_waddstr(&b, win);
474
475  owl_fmtext_free(&a);
476  owl_fmtext_free(&b);
477}
478
479int owl_message_is_personal(owl_message *m)
480{
481  if (owl_message_is_type_zephyr(m)) {
482    if (strcasecmp(owl_message_get_class(m), "message")) return(0);
483    if (strcasecmp(owl_message_get_instance(m), "personal")) return(0);
484    if (!strcasecmp(owl_message_get_recipient(m), owl_zephyr_get_sender()) ||
485        !strcasecmp(owl_message_get_sender(m), owl_zephyr_get_sender())) {
486      return(1);
487    }
488  }
489  return(0);
490}
491
492int owl_message_is_from_me(owl_message *m)
493{
494  if (owl_message_is_type_zephyr(m)) {
495    if (!strcasecmp(owl_message_get_sender(m), owl_zephyr_get_sender())) {
496      return(1);
497    } else {
498      return(0);
499    }
500  } else if (owl_message_is_type_aim(m)) {
501    if (!strcasecmp(owl_message_get_sender(m), owl_global_get_aim_screenname(&g))) {
502      return(1);
503    } else {
504      return(0);
505    }
506  } else if (owl_message_is_type_admin(m)) {
507    return(0);
508  }
509  return(0);
510}
511
512int owl_message_is_mail(owl_message *m)
513{
514  if (owl_message_is_type_zephyr(m)) {
515    if (!strcasecmp(owl_message_get_class(m), "mail") && owl_message_is_private(m)) {
516      return(1);
517    } else {
518      return(0);
519    }
520  }
521  return(0);
522}
523
524int owl_message_is_ping(owl_message *m)
525{
526  if (owl_message_is_type_zephyr(m)) {
527    if (!strcasecmp(owl_message_get_opcode(m), "ping")) {
528      return(1);
529    } else {
530      return(0);
531    }
532  }
533  return(0);
534}
535
536int owl_message_is_burningears(owl_message *m)
537{
538  /* we should add a global to cache the short zsender */
539  char sender[LINE], *ptr;
540
541  /* if the message is from us or to us, it doesn't count */
542  if (owl_message_is_from_me(m) || owl_message_is_private(m)) return(0);
543
544  if (owl_message_is_type_zephyr(m)) {
545    strcpy(sender, owl_zephyr_get_sender());
546    ptr=strchr(sender, '@');
547    if (ptr) *ptr='\0';
548  } else if (owl_message_is_type_aim(m)) {
549    strcpy(sender, owl_global_get_aim_screenname(&g));
550  } else {
551    return(0);
552  }
553
554  if (stristr(owl_message_get_body(m), sender)) {
555    return(1);
556  }
557  return(0);
558}
559
560/* caller must free return value. */
561char *owl_message_get_cc(owl_message *m)
562{
563  char *cur, *out, *end;
564
565  cur = owl_message_get_body(m);
566  while (*cur && *cur==' ') cur++;
567  if (strncasecmp(cur, "cc:", 3)) return(NULL);
568  cur+=3;
569  while (*cur && *cur==' ') cur++;
570  out = owl_strdup(cur);
571  end = strchr(out, '\n');
572  if (end) end[0] = '\0';
573  return(out);
574}
575
576int owl_message_get_id(owl_message *m)
577{
578  return(m->id);
579}
580
581char *owl_message_get_type(owl_message *m) {
582  switch (m->type) {
583  case OWL_MESSAGE_TYPE_ADMIN:
584    return("admin");
585  case OWL_MESSAGE_TYPE_ZEPHYR:
586    return("zephyr");
587  case OWL_MESSAGE_TYPE_GENERIC:
588    return("generic");
589  case OWL_MESSAGE_TYPE_AIM:
590    return("aim");
591  case OWL_MESSAGE_TYPE_JABBER:
592    return("jabber");
593  case OWL_MESSAGE_TYPE_ICQ:
594    return("icq");
595  case OWL_MESSAGE_TYPE_YAHOO:
596    return("yahoo");
597  case OWL_MESSAGE_TYPE_MSN:
598    return("msn");
599  default:
600    return("unknown");
601  }
602}
603
604char *owl_message_get_direction(owl_message *m) {
605  switch (m->direction) {
606  case OWL_MESSAGE_DIRECTION_IN:
607    return("in");
608  case OWL_MESSAGE_DIRECTION_OUT:
609    return("out");
610  case OWL_MESSAGE_DIRECTION_NONE:
611    return("none");
612  default:
613    return("unknown");
614  }
615}
616
617char *owl_message_get_login(owl_message *m) {
618  if (owl_message_is_login(m)) {
619    return "login";
620  } else if (owl_message_is_logout(m)) {
621    return "logout";
622  } else {
623    return "none";
624  }
625}
626
627char *owl_message_get_header(owl_message *m) {
628  return owl_message_get_attribute_value(m, "adminheader");
629}
630
631/* return 1 if the message contains "string", 0 otherwise.  This is
632 * case insensitive because the functions it uses are
633 */
634int owl_message_search(owl_message *m, char *string)
635{
636
637  owl_message_format(m); /* is this necessary? */
638 
639  return (owl_fmtext_search(&(m->fmtext), string));
640}
641
642
643/* if loginout == -1 it's a logout message
644 *                 0 it's not a login/logout message
645 *                 1 it's a login message
646 */
647void owl_message_create_aim(owl_message *m, char *sender, char *recipient, char *text, int direction, int loginout)
648{
649  owl_message_init(m);
650  owl_message_set_body(m, text);
651  owl_message_set_sender(m, sender);
652  owl_message_set_recipient(m, recipient);
653  owl_message_set_type_aim(m);
654
655  if (direction==OWL_MESSAGE_DIRECTION_IN) {
656    owl_message_set_direction_in(m);
657  } else if (direction==OWL_MESSAGE_DIRECTION_OUT) {
658    owl_message_set_direction_out(m);
659  }
660
661  /* for now all messages that aren't loginout are private */
662  if (!loginout) {
663    owl_message_set_isprivate(m);
664  }
665
666  if (loginout==-1) {
667    owl_message_set_islogout(m);
668  } else if (loginout==1) {
669    owl_message_set_islogin(m);
670  }
671}
672
673void owl_message_create_admin(owl_message *m, char *header, char *text)
674{
675  owl_message_init(m);
676  owl_message_set_type_admin(m);
677  owl_message_set_body(m, text);
678  owl_message_set_attribute(m, "adminheader", header); /* just a hack for now */
679}
680
681#ifdef HAVE_LIBZEPHYR
682void owl_message_create_from_znotice(owl_message *m, ZNotice_t *n)
683{
684  struct hostent *hent;
685  int k;
686  char *ptr, *tmp, *tmp2;
687
688  owl_message_init(m);
689 
690  owl_message_set_type_zephyr(m);
691  owl_message_set_direction_in(m);
692 
693  /* first save the full notice */
694  memcpy(&(m->notice), n, sizeof(ZNotice_t));
695
696  /* a little gross, we'll reaplace \r's with ' ' for now */
697  owl_zephyr_hackaway_cr(&(m->notice));
698 
699  m->delete=0;
700
701  /* set other info */
702  owl_message_set_sender(m, n->z_sender);
703  owl_message_set_class(m, n->z_class);
704  owl_message_set_instance(m, n->z_class_inst);
705  owl_message_set_recipient(m, n->z_recipient);
706  if (n->z_opcode) {
707    owl_message_set_opcode(m, n->z_opcode);
708  } else {
709    owl_message_set_opcode(m, "");
710  }
711  owl_message_set_zsig(m, n->z_message);
712
713  if ((ptr=strchr(n->z_recipient, '@'))!=NULL) {
714    owl_message_set_realm(m, ptr+1);
715  } else {
716    owl_message_set_realm(m, owl_zephyr_get_realm());
717  }
718
719  /* Set the "isloginout" attribute if it's a login message */
720  if (!strcasecmp(n->z_class, "login") || !strcasecmp(n->z_class, OWL_WEBZEPHYR_CLASS)) {
721    if (!strcasecmp(n->z_opcode, "user_login")) {
722      owl_message_set_islogin(m);
723    } else if (!strcasecmp(n->z_opcode, "user_logout")) {
724      owl_message_set_islogout(m);
725    }
726  }
727
728  /* is the "isprivate" attribute if it's a private zephyr */
729  if (!strcasecmp(n->z_recipient, owl_zephyr_get_sender())) {
730    owl_message_set_isprivate(m);
731  }
732
733  m->zwriteline=strdup("");
734
735  /* set the body */
736  ptr=owl_zephyr_get_message(n, &k);
737  tmp=owl_malloc(k+10);
738  memcpy(tmp, ptr, k);
739  tmp[k]='\0';
740  if (owl_global_is_newlinestrip(&g)) {
741    tmp2=owl_util_stripnewlines(tmp);
742    owl_message_set_body(m, tmp2);
743    owl_free(tmp2);
744  } else {
745    owl_message_set_body(m, tmp);
746  }
747  owl_free(tmp);
748
749#ifdef OWL_ENABLE_ZCRYPT
750  /* if zcrypt is enabled try to decrypt the message */
751  if (owl_global_is_zcrypt(&g) && !strcasecmp(n->z_opcode, "crypt")) {
752    char *out;
753    int ret;
754
755    out=owl_malloc(strlen(owl_message_get_body(m))*16+20);
756    ret=owl_zcrypt_decrypt(out, owl_message_get_body(m), owl_message_get_class(m), owl_message_get_instance(m));
757    if (ret==0) {
758      owl_message_set_body(m, out);
759    } else {
760      owl_free(out);
761    }
762  }
763#endif 
764
765  /* save the hostname */
766  owl_function_debugmsg("About to do gethostbyaddr");
767  hent=gethostbyaddr((char *) &(n->z_uid.zuid_addr), sizeof(n->z_uid.zuid_addr), AF_INET);
768  if (hent && hent->h_name) {
769    strcpy(m->hostname, hent->h_name);
770  } else {
771    strcpy(m->hostname, inet_ntoa(n->z_sender_addr));
772  }
773
774  /* save the time */
775  m->time=owl_strdup(ctime((time_t *) &n->z_time.tv_sec));
776  m->time[strlen(m->time)-1]='\0';
777}
778#else
779void owl_message_create_from_znotice(owl_message *m, void *n)
780{
781}
782#endif
783
784void owl_message_create_from_zwriteline(owl_message *m, char *line, char *body, char *zsig)
785{
786  owl_zwrite z;
787  int ret;
788 
789  owl_message_init(m);
790
791  /* create a zwrite for the purpose of filling in other message fields */
792  owl_zwrite_create_from_line(&z, line);
793
794  /* set things */
795  owl_message_set_direction_out(m);
796  owl_message_set_type_zephyr(m);
797  owl_message_set_sender(m, owl_zephyr_get_sender());
798  owl_message_set_class(m, owl_zwrite_get_class(&z));
799  owl_message_set_instance(m, owl_zwrite_get_instance(&z));
800  if (owl_zwrite_get_numrecips(&z)>0) {
801    owl_message_set_recipient(m,
802                              long_zuser(owl_zwrite_get_recip_n(&z, 0))); /* only gets the first user, must fix */
803  }
804  owl_message_set_opcode(m, owl_zwrite_get_opcode(&z));
805  owl_message_set_realm(m, owl_zwrite_get_realm(&z)); /* also a hack, but not here */
806  m->zwriteline=owl_strdup(line);
807  owl_message_set_body(m, body);
808  owl_message_set_zsig(m, zsig);
809 
810  /* save the hostname */
811  ret=gethostname(m->hostname, MAXHOSTNAMELEN);
812  if (ret) {
813    strcpy(m->hostname, "localhost");
814  }
815
816  owl_zwrite_free(&z);
817}
818
819
820void owl_message_pretty_zsig(owl_message *m, char *buff)
821{
822  /* stick a one line version of the zsig in buff */
823  char *ptr;
824
825  strcpy(buff, owl_message_get_zsig(m));
826  ptr=strchr(buff, '\n');
827  if (ptr) ptr[0]='\0';
828}
829
830void owl_message_free(owl_message *m)
831{
832  int i, j;
833  owl_pair *p;
834#ifdef HAVE_LIBZEPHYR   
835  if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
836    ZFreeNotice(&(m->notice));
837  }
838#endif
839  if (m->time) owl_free(m->time);
840  if (m->zwriteline) owl_free(m->zwriteline);
841
842  /* free all the attributes */
843  j=owl_list_get_size(&(m->attributes));
844  for (i=0; i<j; i++) {
845    p=owl_list_get_element(&(m->attributes), i);
846    owl_free(owl_pair_get_key(p));
847    owl_free(owl_pair_get_value(p));
848    owl_free(p);
849  }
850
851  owl_list_free_simple(&(m->attributes));
852 
853  owl_fmtext_free(&(m->fmtext));
854}
Note: See TracBrowser for help on using the repository browser.