source: message.c @ 4b464a4

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 4b464a4 was 4b464a4, checked in by James M. Kretchmar <kretch@mit.edu>, 22 years ago
Messages now have a direciton (in, out or none). Filters can this direction Outbound messages are no longer type 'admin' but are of the appropriate message type (i.e. 'zephyr') and are direction 'out'. Smartnarrow now works on outgoing messages 'info' updated to show more information for admin and outgoing messages Renamed pretty_sender to short_zuser and renamed long_sender to long_zuser
  • Property mode set to 100644
File size: 18.3 KB
Line 
1#include <zephyr/zephyr.h>
2#include <stdlib.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_raw(owl_message *m) {
16  time_t t;
17
18  m->id=owl_global_get_nextmsgid(&g);
19  m->type=OWL_MESSAGE_TYPE_GENERIC;
20  owl_message_set_direction_none(m);
21  m->delete=0;
22  m->sender=owl_strdup("");
23  m->class=owl_strdup("");
24  m->inst=owl_strdup("");
25  m->recip=owl_strdup("");
26  m->opcode=owl_strdup("");
27  m->realm=owl_strdup("");
28  strcpy(m->hostname, "");
29  m->zwriteline=strdup("");
30
31  /* save the time */
32  t=time(NULL);
33  m->time=owl_strdup(ctime(&t));
34  m->time[strlen(m->time)-1]='\0';
35}
36
37
38owl_fmtext *owl_message_get_fmtext(owl_message *m) {
39  return(&(m->fmtext));
40}
41
42void owl_message_set_class(owl_message *m, char *class) {
43  if (m->class) owl_free(m->class);
44  m->class=owl_strdup(class);
45}
46
47char *owl_message_get_class(owl_message *m) {
48  return(m->class);
49}
50
51void owl_message_set_instance(owl_message *m, char *inst) {
52  if (m->inst) owl_free(m->inst);
53  m->inst=owl_strdup(inst);
54}
55
56char *owl_message_get_instance(owl_message *m) {
57  return(m->inst);
58}
59
60void owl_message_set_sender(owl_message *m, char *sender) {
61  if (m->sender) owl_free(m->sender);
62  m->sender=owl_strdup(sender);
63}
64
65char *owl_message_get_sender(owl_message *m) {
66  return(m->sender);
67}
68
69void owl_message_set_recipient(owl_message *m, char *recip) {
70  if (m->recip) owl_free(m->recip);
71  m->recip=owl_strdup(recip);
72}
73
74char *owl_message_get_recipient(owl_message *m) {
75  /* this is stupid for outgoing messages, we need to fix it. */
76     
77  if (m->type==OWL_MESSAGE_TYPE_ZEPHYR) {
78    return(m->recip);
79  } else if (owl_message_is_direction_out(m)) {
80    return(m->zwriteline);
81  } else {
82    return(m->recip);
83  }
84}
85
86void owl_message_set_realm(owl_message *m, char *realm) {
87  if (m->realm) owl_free(m->realm);
88  m->realm=owl_strdup(realm);
89}
90
91char *owl_message_get_realm(owl_message *m) {
92  return(m->realm);
93}
94
95void owl_message_set_opcode(owl_message *m, char *opcode) {
96  if (m->opcode) free(m->opcode);
97  m->opcode=owl_strdup(opcode);
98}
99
100char *owl_message_get_opcode(owl_message *m) {
101  return(m->opcode);
102}
103
104char *owl_message_get_timestr(owl_message *m) {
105  return(m->time);
106}
107
108void owl_message_set_type_admin(owl_message *m) {
109  m->type=OWL_MESSAGE_TYPE_ADMIN;
110}
111
112void owl_message_set_type_zephyr(owl_message *m) {
113  m->type=OWL_MESSAGE_TYPE_ZEPHYR;
114}
115                                               
116int owl_message_is_type_admin(owl_message *m) {
117  if (m->type==OWL_MESSAGE_TYPE_ADMIN) return(1);
118  return(0);
119}
120
121int owl_message_is_type_zephyr(owl_message *m) {
122  if (m->type==OWL_MESSAGE_TYPE_ZEPHYR) return(1);
123  return(0);
124}
125
126int owl_message_is_type_generic(owl_message *m) {
127  if (m->type==OWL_MESSAGE_TYPE_GENERIC) return(1);
128  return(0);
129}
130
131char *owl_message_get_text(owl_message *m) {
132  return(owl_fmtext_get_text(&(m->fmtext)));
133}
134
135char *owl_message_get_body(owl_message *m) {
136  return(m->body);
137}
138
139void owl_message_set_direction_in(owl_message *m) {
140  m->direction=OWL_MESSAGE_DIRECTION_IN;
141}
142
143void owl_message_set_direction_out(owl_message *m) {
144  m->direction=OWL_MESSAGE_DIRECTION_OUT;
145}
146
147void owl_message_set_direction_none(owl_message *m) {
148  m->direction=OWL_MESSAGE_DIRECTION_NONE;
149}
150
151int owl_message_is_direction_in(owl_message *m) {
152  if (m->direction==OWL_MESSAGE_DIRECTION_IN) return(1);
153  return(0);
154}
155
156int owl_message_is_direction_out(owl_message *m) {
157  if (m->direction==OWL_MESSAGE_DIRECTION_OUT) return(1);
158  return(0);
159}
160
161int owl_message_is_direction_none(owl_message *m) {
162  if (m->direction==OWL_MESSAGE_DIRECTION_NONE) return(1);
163  return(0);
164}
165
166int owl_message_get_numlines(owl_message *m) {
167  if (m == NULL) return(0);
168  return(owl_fmtext_num_lines(&(m->fmtext)));
169}
170
171void owl_message_mark_delete(owl_message *m) {
172  if (m == NULL) return;
173  m->delete=1;
174}
175
176void owl_message_unmark_delete(owl_message *m) {
177  if (m == NULL) return;
178  m->delete=0;
179}
180
181char *owl_message_get_zwriteline(owl_message *m) {
182  return(m->zwriteline);
183}
184
185void owl_message_set_zwriteline(owl_message *m, char *line) {
186  m->zwriteline=strdup(line);
187}
188
189int owl_message_is_delete(owl_message *m) {
190  if (m == NULL) return(0);
191  if (m->delete==1) return(1);
192  return(0);
193}
194
195ZNotice_t *owl_message_get_notice(owl_message *m) {
196  return(&(m->notice));
197}
198
199char *owl_message_get_hostname(owl_message *m) {
200  return(m->hostname);
201}
202
203
204void owl_message_curs_waddstr(owl_message *m, WINDOW *win, int aline, int bline, int acol, int bcol, int color) {
205  owl_fmtext a, b;
206
207  owl_fmtext_truncate_lines(&(m->fmtext), aline, bline-aline+1, &a);
208  owl_fmtext_truncate_cols(&a, acol, bcol, &b);
209  if (color!=OWL_COLOR_DEFAULT) {
210    owl_fmtext_colorize(&b, color);
211  }
212
213  if (owl_global_is_search_active(&g)) {
214    owl_fmtext_search_and_highlight(&b, owl_global_get_search_string(&g));
215  }
216     
217  owl_fmtext_curs_waddstr(&b, win);
218
219  owl_fmtext_free(&a);
220  owl_fmtext_free(&b);
221}
222
223int owl_message_is_personal(owl_message *m) {
224  if (strcasecmp(owl_message_get_class(m), "message")) return(0);
225  if (strcasecmp(owl_message_get_instance(m), "personal")) return(0);
226  if (!strcmp(owl_message_get_recipient(m), ZGetSender()) ||
227      !strcmp(owl_message_get_sender(m), ZGetSender())) {
228    return(1);
229  }
230  return(0);
231}
232
233int owl_message_is_private(owl_message *m) {
234  if (!strcmp(owl_message_get_recipient(m), ZGetSender())) return(1);
235  return(0);
236}
237
238int owl_message_is_mail(owl_message *m) {
239  if (!strcasecmp(owl_message_get_class(m), "mail") && owl_message_is_private(m)) {
240    return(1);
241  }
242  return(0);
243}
244
245int owl_message_is_ping(owl_message *m) {
246  if (!strcasecmp(owl_message_get_opcode(m), "ping")) return(1);
247  return(0);
248}
249
250int owl_message_is_login(owl_message *m) {
251  if (!strcasecmp(owl_message_get_class(m), "login")) return(1);
252  return(0);
253  /* is this good enough? */
254}
255
256int owl_message_is_burningears(owl_message *m) {
257  /* we should add a global to cache the short zsender */
258  char sender[LINE], *ptr;
259
260  /* if the message is from us or to us, it doesn't count */
261  if (!strcasecmp(ZGetSender(), owl_message_get_sender(m))) return(0);
262  if (!strcasecmp(ZGetSender(), owl_message_get_recipient(m))) return(0);
263
264  strcpy(sender, ZGetSender());
265  ptr=strchr(sender, '@');
266  if (ptr) *ptr='\0';
267
268  if (stristr(owl_message_get_body(m), sender)) {
269    return(1);
270  }
271  return(0);
272}
273
274/* caller must free return value. */
275char *owl_message_get_cc(owl_message *m) {
276  char *cur, *out, *end;
277
278  cur = owl_message_get_body(m);
279  while (*cur && *cur==' ') cur++;
280  if (strncasecmp(cur, "cc:", 2)) return(NULL);
281  cur+=3;
282  while (*cur && *cur==' ') cur++;
283  out = owl_strdup(cur);
284  end = strchr(out, '\n');
285  if (end) end[0] = '\0';
286  return(out);
287}
288
289int owl_message_get_id(owl_message *m) {
290  return(m->id);
291}
292                                       
293int owl_message_search(owl_message *m, char *string) {
294  /* return 1 if the message contains "string", 0 otherwise.  This is
295   * case insensitive because the functions it uses are */
296
297  return (owl_fmtext_search(&(m->fmtext), string));
298}
299
300void owl_message_create(owl_message *m, char *header, char *text) {
301  char *indent;
302
303  owl_message_init_raw(m);
304
305  m->body=owl_strdup(text);
306
307  indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
308  owl_text_indent(indent, text, OWL_MSGTAB);
309  owl_fmtext_init_null(&(m->fmtext));
310  owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);
311  owl_fmtext_append_ztext(&(m->fmtext), header);
312  owl_fmtext_append_normal(&(m->fmtext), "\n");
313  owl_fmtext_append_ztext(&(m->fmtext), indent);
314  if (text[strlen(text)-1]!='\n') {
315    owl_fmtext_append_normal(&(m->fmtext), "\n");
316  }
317
318  owl_free(indent);
319}
320
321void owl_message_create_admin(owl_message *m, char *header, char *text) {
322  char *indent;
323
324  owl_message_init_raw(m);
325  owl_message_set_type_admin(m);
326
327  m->body=owl_strdup(text);
328
329  /* do something to make it clear the notice shouldn't be used for now */
330
331  indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
332  owl_text_indent(indent, text, OWL_MSGTAB);
333  owl_fmtext_init_null(&(m->fmtext));
334  owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);
335  owl_fmtext_append_bold(&(m->fmtext), "OWL ADMIN ");
336  owl_fmtext_append_ztext(&(m->fmtext), header);
337  owl_fmtext_append_normal(&(m->fmtext), "\n");
338  owl_fmtext_append_ztext(&(m->fmtext), indent);
339  if (text[strlen(text)-1]!='\n') {
340    owl_fmtext_append_normal(&(m->fmtext), "\n");
341  }
342
343  owl_free(indent);
344}
345
346void owl_message_create_from_zephyr(owl_message *m, ZNotice_t *n) {
347  struct hostent *hent;
348  int k;
349  char *ptr;
350
351  m->id=owl_global_get_nextmsgid(&g);
352  owl_message_set_type_zephyr(m);
353  owl_message_set_direction_in(m);
354 
355  /* first save the full notice */
356  memcpy(&(m->notice), n, sizeof(ZNotice_t));
357
358  /* a little gross, we'll reaplace \r's with ' ' for now */
359  owl_zephyr_hackaway_cr(&(m->notice));
360 
361  m->delete=0;
362
363  /* set other info */
364  m->sender=owl_strdup(n->z_sender);
365  m->class=owl_strdup(n->z_class);
366  m->inst=owl_strdup(n->z_class_inst);
367  m->recip=owl_strdup(n->z_recipient);
368  if (n->z_opcode) {
369    m->opcode=owl_strdup(n->z_opcode);
370  } else {
371    n->z_opcode=owl_strdup("");
372  }
373
374  if ((ptr=strchr(n->z_recipient, '@'))!=NULL) {
375    m->realm=owl_strdup(ptr+1);
376  } else {
377    m->realm=owl_strdup(ZGetRealm());
378  }
379
380  m->zwriteline=strdup("");
381
382  ptr=owl_zephyr_get_message(n, &k);
383  m->body=owl_malloc(k+10);
384  memcpy(m->body, ptr, k);
385  m->body[k]='\0';
386
387  /* save the hostname */
388  owl_function_debugmsg("About to do get hostbyaddr");
389  hent=gethostbyaddr((char *) &(n->z_uid.zuid_addr), sizeof(n->z_uid.zuid_addr), AF_INET);
390  if (hent && hent->h_name) {
391    strcpy(m->hostname, hent->h_name);
392  } else {
393    strcpy(m->hostname, inet_ntoa(n->z_sender_addr));
394  }
395
396  /* save the time */
397  m->time=owl_strdup(ctime((time_t *) &n->z_time.tv_sec));
398  m->time[strlen(m->time)-1]='\0';
399
400  /* create the formatted message */
401  if (owl_global_is_config_format(&g)) {
402    _owl_message_make_text_from_config(m);
403  } else if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {
404    _owl_message_make_text_from_notice_standard(m);
405  } else {
406    _owl_message_make_text_from_notice_simple(m);
407  }
408
409}
410
411
412void _owl_message_make_text_from_config(owl_message *m) {
413  char *body, *indent;
414 
415  owl_fmtext_init_null(&(m->fmtext));
416
417  /* get body from the config */
418  body=owl_config_getmsg(m, 1);
419 
420  /* indent */
421  indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_TAB+10);
422  owl_text_indent(indent, body, OWL_TAB);
423
424  /* fmtext_append.  This needs to change */
425  owl_fmtext_append_ztext(&(m->fmtext), indent);
426
427  owl_free(indent);
428  owl_free(body);
429}
430
431void _owl_message_make_text_from_notice_standard(owl_message *m) {
432  char *body, *indent, *ptr;
433  char frombuff[1024];
434  char zsigbuff[LINE];
435  ZNotice_t *n;
436  int len;
437
438  /* get the body */
439  n=&(m->notice);
440  ptr=(owl_zephyr_get_message(n, &len));
441  body=owl_malloc(len+20);
442  strncpy(body, ptr, len);
443  body[len]='\0';
444
445  /* add a newline if we need to */
446  if (body[0]!='\0' && body[strlen(body)-1]!='\n') {
447    strcat(body, "\n");
448  }
449
450  /* do the indenting into indent */
451  indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10);
452  owl_text_indent(indent, body, OWL_MSGTAB);
453
454  /* edit the from addr for printing */
455  strcpy(frombuff, m->sender);
456  ptr=strchr(frombuff, '@');
457  if (ptr && !strncmp(ptr+1, ZGetRealm(), strlen(ZGetRealm()))) {
458    *ptr='\0';
459  }
460
461  /* set the message for printing */
462  owl_fmtext_init_null(&(m->fmtext));
463  owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);
464
465  if (!strcasecmp(n->z_opcode, "ping")) {
466    owl_fmtext_append_bold(&(m->fmtext), "PING");
467    owl_fmtext_append_normal(&(m->fmtext), " from ");
468    owl_fmtext_append_bold(&(m->fmtext), frombuff);
469    owl_fmtext_append_normal(&(m->fmtext), "\n");
470  } else if (!strcasecmp(n->z_class, "login")) {
471    char *ptr, host[LINE], tty[LINE];
472    int len;
473
474    ptr=owl_zephyr_get_field(n, 1, &len);
475    strncpy(host, ptr, len);
476    host[len]='\0';
477    ptr=owl_zephyr_get_field(n, 3, &len);
478    strncpy(tty, ptr, len);
479    tty[len]='\0';
480   
481    if (!strcasecmp(n->z_opcode, "user_login")) {
482      owl_fmtext_append_bold(&(m->fmtext), "LOGIN");
483    } else if (!strcasecmp(n->z_opcode, "user_logout")) {
484      owl_fmtext_append_bold(&(m->fmtext), "LOGOUT");
485    }
486    owl_fmtext_append_normal(&(m->fmtext), " for ");
487    ptr=short_zuser(n->z_class_inst);
488    owl_fmtext_append_bold(&(m->fmtext), ptr);
489    owl_free(ptr);
490    owl_fmtext_append_normal(&(m->fmtext), " at ");
491    owl_fmtext_append_normal(&(m->fmtext), host);
492    owl_fmtext_append_normal(&(m->fmtext), " ");
493    owl_fmtext_append_normal(&(m->fmtext), tty);
494    owl_fmtext_append_normal(&(m->fmtext), "\n");
495  } else {
496    owl_fmtext_append_normal(&(m->fmtext), m->class);
497    owl_fmtext_append_normal(&(m->fmtext), " / ");
498    owl_fmtext_append_normal(&(m->fmtext), m->inst);
499    owl_fmtext_append_normal(&(m->fmtext), " / ");
500    owl_fmtext_append_bold(&(m->fmtext), frombuff);
501    if (strcasecmp(owl_message_get_realm(m), ZGetRealm())) {
502      owl_fmtext_append_normal(&(m->fmtext), " {");
503      owl_fmtext_append_normal(&(m->fmtext), owl_message_get_realm(m));
504      owl_fmtext_append_normal(&(m->fmtext), "} ");
505    }
506    if (n->z_opcode[0]!='\0') {
507      owl_fmtext_append_normal(&(m->fmtext), " [");
508      owl_fmtext_append_normal(&(m->fmtext), n->z_opcode);
509      owl_fmtext_append_normal(&(m->fmtext), "] ");
510    }
511
512    /* stick on the zsig */
513    _owl_message_get_zsig(m, zsigbuff, LINE);
514    if (zsigbuff[0]!='\0') {
515      owl_fmtext_append_normal(&(m->fmtext), "    (");
516      owl_fmtext_append_ztext(&(m->fmtext), zsigbuff);
517      owl_fmtext_append_normal(&(m->fmtext), ")");
518    }
519    owl_fmtext_append_normal(&(m->fmtext), "\n");
520    owl_fmtext_append_ztext(&(m->fmtext), indent);
521
522    /* make personal messages bold for smaat users */
523    if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {
524      if (owl_message_is_personal(m)) {
525        owl_fmtext_addattr((&m->fmtext), OWL_FMTEXT_ATTR_BOLD);
526      }
527    }
528  }
529
530  owl_free(body);
531  owl_free(indent);
532}
533
534void _owl_message_make_text_from_notice_simple(owl_message *m) {
535  char *body, *indent, *ptr;
536  char frombuff[1024];
537  char zsigbuff[LINE];
538  ZNotice_t *n;
539  int len;
540
541  /* get the body */
542  n=&(m->notice);
543  ptr=(owl_zephyr_get_message(n, &len));
544  body=owl_malloc(len+20);
545  strncpy(body, ptr, len);
546  body[len]='\0';
547
548  /* add a newline if we need to */
549  if (body[0]!='\0' && body[strlen(body)-1]!='\n') {
550    strcat(body, "\n");
551  }
552
553  /* do the indenting into indent */
554  indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10);
555  owl_text_indent(indent, body, OWL_MSGTAB);
556
557  /* edit the from addr for printing */
558  strcpy(frombuff, m->sender);
559  ptr=strchr(frombuff, '@');
560  if (ptr && !strncmp(ptr+1, ZGetRealm(), strlen(ZGetRealm()))) {
561    *ptr='\0';
562  }
563
564  /* set the message for printing */
565  owl_fmtext_init_null(&(m->fmtext));
566  owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);
567
568  if (!strcasecmp(n->z_opcode, "ping")) {
569    owl_fmtext_append_bold(&(m->fmtext), "PING");
570    owl_fmtext_append_normal(&(m->fmtext), " from ");
571    owl_fmtext_append_bold(&(m->fmtext), frombuff);
572    owl_fmtext_append_normal(&(m->fmtext), "\n");
573  } else if (!strcasecmp(n->z_class, "login")) {
574    char *ptr, host[LINE], tty[LINE];
575    int len;
576
577    ptr=owl_zephyr_get_field(n, 1, &len);
578    strncpy(host, ptr, len);
579    host[len]='\0';
580    ptr=owl_zephyr_get_field(n, 3, &len);
581    strncpy(tty, ptr, len);
582    tty[len]='\0';
583   
584    if (!strcasecmp(n->z_opcode, "user_login")) {
585      owl_fmtext_append_bold(&(m->fmtext), "LOGIN");
586    } else if (!strcasecmp(n->z_opcode, "user_logout")) {
587      owl_fmtext_append_bold(&(m->fmtext), "LOGOUT");
588    }
589    owl_fmtext_append_normal(&(m->fmtext), " for ");
590    ptr=short_zuser(n->z_class_inst);
591    owl_fmtext_append_bold(&(m->fmtext), ptr);
592    owl_free(ptr);
593    owl_fmtext_append_normal(&(m->fmtext), " at ");
594    owl_fmtext_append_normal(&(m->fmtext), host);
595    owl_fmtext_append_normal(&(m->fmtext), " ");
596    owl_fmtext_append_normal(&(m->fmtext), tty);
597    owl_fmtext_append_normal(&(m->fmtext), "\n");
598  } else {
599    owl_fmtext_append_normal(&(m->fmtext), "From: ");
600    if (strcasecmp(m->class, "message")) {
601      owl_fmtext_append_normal(&(m->fmtext), "Class ");
602      owl_fmtext_append_normal(&(m->fmtext), m->class);
603      owl_fmtext_append_normal(&(m->fmtext), " / Instance ");
604      owl_fmtext_append_normal(&(m->fmtext), m->inst);
605      owl_fmtext_append_normal(&(m->fmtext), " / ");
606    }
607    owl_fmtext_append_normal(&(m->fmtext), frombuff);
608    if (strcasecmp(owl_message_get_realm(m), ZGetRealm())) {
609      owl_fmtext_append_normal(&(m->fmtext), " {");
610      owl_fmtext_append_normal(&(m->fmtext), owl_message_get_realm(m));
611      owl_fmtext_append_normal(&(m->fmtext), "} ");
612    }
613
614    /* stick on the zsig */
615    _owl_message_get_zsig(m, zsigbuff, LINE);
616    if (zsigbuff[0]!='\0') {
617      owl_fmtext_append_normal(&(m->fmtext), "    (");
618      owl_fmtext_append_ztext(&(m->fmtext), zsigbuff);
619      owl_fmtext_append_normal(&(m->fmtext), ")");
620    }
621    owl_fmtext_append_normal(&(m->fmtext), "\n");
622    owl_fmtext_append_ztext(&(m->fmtext), indent);
623
624    /* make personal messages bold for smaat users */
625    if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {
626      if (owl_message_is_personal(m)) {
627        owl_fmtext_addattr((&m->fmtext), OWL_FMTEXT_ATTR_BOLD);
628      }
629    }
630  }
631
632  owl_free(body);
633  owl_free(indent);
634}
635
636void _owl_message_get_zsig(owl_message *m, char *buff, int size) {
637  char *ptr;
638  ZNotice_t n;
639  int len;
640  /* just a hackish thing for now.  We'll only present the first line
641     or the first 'size'. characters.  If the message is not
642     appropriate for having a zsig we'll return an empty string */
643  n=m->notice;
644
645
646  /* bail if it shouldn't have a zsig */
647  buff[0]='\0';
648  if (!strcasecmp(n.z_opcode, "ping")) {
649    return;
650  }
651
652  /* find the right length to copy */
653  len=strlen(n.z_message);
654  if (size < len) {
655    len=size;
656  }
657  if ((ptr=strchr(n.z_message, '\n'))!=NULL) {
658    if ((ptr-n.z_message) < len) {
659      len=ptr-n.z_message;
660    }
661  }
662
663  /* copy */
664  strncpy(buff, n.z_message, len);
665  buff[len]='\0';
666}
667
668
669void owl_message_free(owl_message *m) {
670  if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
671    ZFreeNotice(&(m->notice));
672  }
673  if (m->sender) owl_free(m->sender);
674  if (m->recip) owl_free(m->recip);
675  if (m->class) owl_free(m->class);
676  if (m->inst) owl_free(m->inst);
677  if (m->opcode) owl_free(m->opcode);
678  if (m->time) owl_free(m->time);
679  if (m->realm) owl_free(m->realm);
680  if (m->body) owl_free(m->body);
681  if (m->zwriteline) owl_free(m->zwriteline);
682 
683  owl_fmtext_free(&(m->fmtext));
684}
685
Note: See TracBrowser for help on using the repository browser.