source: message.c @ 37eab7f

barnowl_perlaimdebianowlrelease-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 37eab7f was 37eab7f, checked in by James M. Kretchmar <kretch@mit.edu>, 17 years ago
Added the loopback message type Added the loopwrite command
  • Property mode set to 100644
File size: 19.4 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_loopback(owl_message *m)
316{
317  m->type=OWL_MESSAGE_TYPE_LOOPBACK;
318}
319
320void owl_message_set_type_zephyr(owl_message *m)
321{
322  m->type=OWL_MESSAGE_TYPE_ZEPHYR;
323}
324
325void owl_message_set_type_aim(owl_message *m)
326{
327  m->type=OWL_MESSAGE_TYPE_AIM;
328}
329                                               
330int owl_message_is_type_admin(owl_message *m)
331{
332  if (m->type==OWL_MESSAGE_TYPE_ADMIN) return(1);
333  return(0);
334}
335
336int owl_message_is_type_loopback(owl_message *m)
337{
338  if (m->type==OWL_MESSAGE_TYPE_LOOPBACK) return(1);
339  return(0);
340}
341
342int owl_message_is_type_zephyr(owl_message *m)
343{
344  if (m->type==OWL_MESSAGE_TYPE_ZEPHYR) return(1);
345  return(0);
346}
347
348int owl_message_is_type_aim(owl_message *m)
349{
350  if (m->type==OWL_MESSAGE_TYPE_AIM) return(1);
351  return(0);
352}
353
354int owl_message_is_type_generic(owl_message *m)
355{
356  if (m->type==OWL_MESSAGE_TYPE_GENERIC) return(1);
357  return(0);
358}
359
360char *owl_message_get_text(owl_message *m)
361{
362  return(owl_fmtext_get_text(&(m->fmtext)));
363}
364
365void owl_message_set_direction_in(owl_message *m)
366{
367  m->direction=OWL_MESSAGE_DIRECTION_IN;
368}
369
370void owl_message_set_direction_out(owl_message *m)
371{
372  m->direction=OWL_MESSAGE_DIRECTION_OUT;
373}
374
375void owl_message_set_direction_none(owl_message *m)
376{
377  m->direction=OWL_MESSAGE_DIRECTION_NONE;
378}
379
380int owl_message_is_direction_in(owl_message *m)
381{
382  if (m->direction==OWL_MESSAGE_DIRECTION_IN) return(1);
383  return(0);
384}
385
386int owl_message_is_direction_out(owl_message *m)
387{
388  if (m->direction==OWL_MESSAGE_DIRECTION_OUT) return(1);
389  return(0);
390}
391
392int owl_message_is_direction_none(owl_message *m)
393{
394  if (m->direction==OWL_MESSAGE_DIRECTION_NONE) return(1);
395  return(0);
396}
397
398int owl_message_get_numlines(owl_message *m)
399{
400  if (m == NULL) return(0);
401  owl_message_format(m);
402  return(owl_fmtext_num_lines(&(m->fmtext)));
403}
404
405void owl_message_mark_delete(owl_message *m)
406{
407  if (m == NULL) return;
408  m->delete=1;
409}
410
411void owl_message_unmark_delete(owl_message *m)
412{
413  if (m == NULL) return;
414  m->delete=0;
415}
416
417char *owl_message_get_zwriteline(owl_message *m)
418{
419  return(m->zwriteline);
420}
421
422void owl_message_set_zwriteline(owl_message *m, char *line)
423{
424  m->zwriteline=strdup(line);
425}
426
427int owl_message_is_delete(owl_message *m)
428{
429  if (m == NULL) return(0);
430  if (m->delete==1) return(1);
431  return(0);
432}
433
434#ifdef HAVE_LIBZEPHYR
435ZNotice_t *owl_message_get_notice(owl_message *m)
436{
437  return(&(m->notice));
438}
439#else
440void *owl_message_get_notice(owl_message *m)
441{
442  return(NULL);
443}
444#endif
445
446char *owl_message_get_hostname(owl_message *m)
447{
448  return(m->hostname);
449}
450
451void owl_message_curs_waddstr(owl_message *m, WINDOW *win, int aline, int bline, int acol, int bcol, int color)
452{
453  owl_fmtext a, b;
454
455  /* this will ensure that our cached copy is up to date */
456  owl_message_format(m);
457
458  owl_fmtext_init_null(&a);
459  owl_fmtext_init_null(&b);
460 
461  owl_fmtext_truncate_lines(&(m->fmtext), aline, bline-aline+1, &a);
462  owl_fmtext_truncate_cols(&a, acol, bcol, &b);
463  if (color!=OWL_COLOR_DEFAULT) {
464    owl_fmtext_colorize(&b, color);
465  }
466
467  if (owl_global_is_search_active(&g)) {
468    owl_fmtext_search_and_highlight(&b, owl_global_get_search_string(&g));
469  }
470     
471  owl_fmtext_curs_waddstr(&b, win);
472
473  owl_fmtext_free(&a);
474  owl_fmtext_free(&b);
475}
476
477int owl_message_is_personal(owl_message *m)
478{
479  if (owl_message_is_type_zephyr(m)) {
480    if (strcasecmp(owl_message_get_class(m), "message")) return(0);
481    if (strcasecmp(owl_message_get_instance(m), "personal")) return(0);
482    if (!strcasecmp(owl_message_get_recipient(m), owl_zephyr_get_sender()) ||
483        !strcasecmp(owl_message_get_sender(m), owl_zephyr_get_sender())) {
484      return(1);
485    }
486  }
487  return(0);
488}
489
490int owl_message_is_from_me(owl_message *m)
491{
492  if (owl_message_is_type_zephyr(m)) {
493    if (!strcasecmp(owl_message_get_sender(m), owl_zephyr_get_sender())) {
494      return(1);
495    } else {
496      return(0);
497    }
498  } else if (owl_message_is_type_aim(m)) {
499    if (!strcasecmp(owl_message_get_sender(m), owl_global_get_aim_screenname(&g))) {
500      return(1);
501    } else {
502      return(0);
503    }
504  } else if (owl_message_is_type_admin(m)) {
505    return(0);
506  }
507  return(0);
508}
509
510int owl_message_is_mail(owl_message *m)
511{
512  if (owl_message_is_type_zephyr(m)) {
513    if (!strcasecmp(owl_message_get_class(m), "mail") && owl_message_is_private(m)) {
514      return(1);
515    } else {
516      return(0);
517    }
518  }
519  return(0);
520}
521
522int owl_message_is_ping(owl_message *m)
523{
524  if (owl_message_is_type_zephyr(m)) {
525    if (!strcasecmp(owl_message_get_opcode(m), "ping")) {
526      return(1);
527    } else {
528      return(0);
529    }
530  }
531  return(0);
532}
533
534int owl_message_is_burningears(owl_message *m)
535{
536  /* we should add a global to cache the short zsender */
537  char sender[LINE], *ptr;
538
539  /* if the message is from us or to us, it doesn't count */
540  if (owl_message_is_from_me(m) || owl_message_is_private(m)) return(0);
541
542  if (owl_message_is_type_zephyr(m)) {
543    strcpy(sender, owl_zephyr_get_sender());
544    ptr=strchr(sender, '@');
545    if (ptr) *ptr='\0';
546  } else if (owl_message_is_type_aim(m)) {
547    strcpy(sender, owl_global_get_aim_screenname(&g));
548  } else {
549    return(0);
550  }
551
552  if (stristr(owl_message_get_body(m), sender)) {
553    return(1);
554  }
555  return(0);
556}
557
558/* caller must free return value. */
559char *owl_message_get_cc(owl_message *m)
560{
561  char *cur, *out, *end;
562
563  cur = owl_message_get_body(m);
564  while (*cur && *cur==' ') cur++;
565  if (strncasecmp(cur, "cc:", 3)) return(NULL);
566  cur+=3;
567  while (*cur && *cur==' ') cur++;
568  out = owl_strdup(cur);
569  end = strchr(out, '\n');
570  if (end) end[0] = '\0';
571  return(out);
572}
573
574int owl_message_get_id(owl_message *m)
575{
576  return(m->id);
577}
578
579char *owl_message_get_type(owl_message *m) {
580  switch (m->type) {
581  case OWL_MESSAGE_TYPE_ADMIN:
582    return("admin");
583  case OWL_MESSAGE_TYPE_ZEPHYR:
584    return("zephyr");
585  case OWL_MESSAGE_TYPE_GENERIC:
586    return("generic");
587  case OWL_MESSAGE_TYPE_AIM:
588    return("aim");
589  case OWL_MESSAGE_TYPE_JABBER:
590    return("jabber");
591  case OWL_MESSAGE_TYPE_ICQ:
592    return("icq");
593  case OWL_MESSAGE_TYPE_YAHOO:
594    return("yahoo");
595  case OWL_MESSAGE_TYPE_MSN:
596    return("msn");
597  case OWL_MESSAGE_TYPE_LOOPBACK:
598    return("loopback");
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/* caller should set the direction */
682void owl_message_create_loopback(owl_message *m, char *text)
683{
684  owl_message_init(m);
685  owl_message_set_type_loopback(m);
686  owl_message_set_body(m, text);
687  owl_message_set_sender(m, "loopback-sender");
688  owl_message_set_recipient(m, "loopback-recipient");
689  owl_message_set_isprivate(m);
690}
691
692#ifdef HAVE_LIBZEPHYR
693void owl_message_create_from_znotice(owl_message *m, ZNotice_t *n)
694{
695  struct hostent *hent;
696  int k;
697  char *ptr, *tmp, *tmp2;
698
699  owl_message_init(m);
700 
701  owl_message_set_type_zephyr(m);
702  owl_message_set_direction_in(m);
703 
704  /* first save the full notice */
705  memcpy(&(m->notice), n, sizeof(ZNotice_t));
706
707  /* a little gross, we'll reaplace \r's with ' ' for now */
708  owl_zephyr_hackaway_cr(&(m->notice));
709 
710  m->delete=0;
711
712  /* set other info */
713  owl_message_set_sender(m, n->z_sender);
714  owl_message_set_class(m, n->z_class);
715  owl_message_set_instance(m, n->z_class_inst);
716  owl_message_set_recipient(m, n->z_recipient);
717  if (n->z_opcode) {
718    owl_message_set_opcode(m, n->z_opcode);
719  } else {
720    owl_message_set_opcode(m, "");
721  }
722  owl_message_set_zsig(m, n->z_message);
723
724  if ((ptr=strchr(n->z_recipient, '@'))!=NULL) {
725    owl_message_set_realm(m, ptr+1);
726  } else {
727    owl_message_set_realm(m, owl_zephyr_get_realm());
728  }
729
730  /* Set the "isloginout" attribute if it's a login message */
731  if (!strcasecmp(n->z_class, "login") || !strcasecmp(n->z_class, OWL_WEBZEPHYR_CLASS)) {
732    if (!strcasecmp(n->z_opcode, "user_login")) {
733      owl_message_set_islogin(m);
734    } else if (!strcasecmp(n->z_opcode, "user_logout")) {
735      owl_message_set_islogout(m);
736    }
737  }
738
739  /* is the "isprivate" attribute if it's a private zephyr */
740  if (!strcasecmp(n->z_recipient, owl_zephyr_get_sender())) {
741    owl_message_set_isprivate(m);
742  }
743
744  m->zwriteline=strdup("");
745
746  /* set the body */
747  ptr=owl_zephyr_get_message(n, &k);
748  tmp=owl_malloc(k+10);
749  memcpy(tmp, ptr, k);
750  tmp[k]='\0';
751  if (owl_global_is_newlinestrip(&g)) {
752    tmp2=owl_util_stripnewlines(tmp);
753    owl_message_set_body(m, tmp2);
754    owl_free(tmp2);
755  } else {
756    owl_message_set_body(m, tmp);
757  }
758  owl_free(tmp);
759
760#ifdef OWL_ENABLE_ZCRYPT
761  /* if zcrypt is enabled try to decrypt the message */
762  if (owl_global_is_zcrypt(&g) && !strcasecmp(n->z_opcode, "crypt")) {
763    char *out;
764    int ret;
765
766    out=owl_malloc(strlen(owl_message_get_body(m))*16+20);
767    ret=owl_zcrypt_decrypt(out, owl_message_get_body(m), owl_message_get_class(m), owl_message_get_instance(m));
768    if (ret==0) {
769      owl_message_set_body(m, out);
770    } else {
771      owl_free(out);
772    }
773  }
774#endif 
775
776  /* save the hostname */
777  owl_function_debugmsg("About to do gethostbyaddr");
778  hent=gethostbyaddr((char *) &(n->z_uid.zuid_addr), sizeof(n->z_uid.zuid_addr), AF_INET);
779  if (hent && hent->h_name) {
780    strcpy(m->hostname, hent->h_name);
781  } else {
782    strcpy(m->hostname, inet_ntoa(n->z_sender_addr));
783  }
784
785  /* save the time */
786  m->time=owl_strdup(ctime((time_t *) &n->z_time.tv_sec));
787  m->time[strlen(m->time)-1]='\0';
788}
789#else
790void owl_message_create_from_znotice(owl_message *m, void *n)
791{
792}
793#endif
794
795void owl_message_create_from_zwriteline(owl_message *m, char *line, char *body, char *zsig)
796{
797  owl_zwrite z;
798  int ret;
799 
800  owl_message_init(m);
801
802  /* create a zwrite for the purpose of filling in other message fields */
803  owl_zwrite_create_from_line(&z, line);
804
805  /* set things */
806  owl_message_set_direction_out(m);
807  owl_message_set_type_zephyr(m);
808  owl_message_set_sender(m, owl_zephyr_get_sender());
809  owl_message_set_class(m, owl_zwrite_get_class(&z));
810  owl_message_set_instance(m, owl_zwrite_get_instance(&z));
811  if (owl_zwrite_get_numrecips(&z)>0) {
812    owl_message_set_recipient(m,
813                              long_zuser(owl_zwrite_get_recip_n(&z, 0))); /* only gets the first user, must fix */
814  }
815  owl_message_set_opcode(m, owl_zwrite_get_opcode(&z));
816  owl_message_set_realm(m, owl_zwrite_get_realm(&z)); /* also a hack, but not here */
817  m->zwriteline=owl_strdup(line);
818  owl_message_set_body(m, body);
819  owl_message_set_zsig(m, zsig);
820 
821  /* save the hostname */
822  ret=gethostname(m->hostname, MAXHOSTNAMELEN);
823  if (ret) {
824    strcpy(m->hostname, "localhost");
825  }
826
827  owl_zwrite_free(&z);
828}
829
830void owl_message_pretty_zsig(owl_message *m, char *buff)
831{
832  /* stick a one line version of the zsig in buff */
833  char *ptr;
834
835  strcpy(buff, owl_message_get_zsig(m));
836  ptr=strchr(buff, '\n');
837  if (ptr) ptr[0]='\0';
838}
839
840void owl_message_free(owl_message *m)
841{
842  int i, j;
843  owl_pair *p;
844#ifdef HAVE_LIBZEPHYR   
845  if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
846    ZFreeNotice(&(m->notice));
847  }
848#endif
849  if (m->time) owl_free(m->time);
850  if (m->zwriteline) owl_free(m->zwriteline);
851
852  /* free all the attributes */
853  j=owl_list_get_size(&(m->attributes));
854  for (i=0; i<j; i++) {
855    p=owl_list_get_element(&(m->attributes), i);
856    owl_free(owl_pair_get_key(p));
857    owl_free(owl_pair_get_value(p));
858    owl_free(p);
859  }
860
861  owl_list_free_simple(&(m->attributes));
862 
863  owl_fmtext_free(&(m->fmtext));
864}
Note: See TracBrowser for help on using the repository browser.