source: zephyr.c @ 2afae56

release-1.10release-1.7release-1.8release-1.9
Last change on this file since 2afae56 was be46e0e, checked in by David Benjamin <davidben@mit.edu>, 13 years ago
Don't leaks memory when .anyone file is missing Also caught by valgrind.
  • Property mode set to 100644
File size: 36.6 KB
Line 
1#include <stdlib.h>
2#include <unistd.h>
3#include <sys/types.h>
4#include <sys/wait.h>
5#include <sys/stat.h>
6#include <string.h>
7#include "owl.h"
8
9#ifdef HAVE_LIBZEPHYR
10static GList *deferred_subs = NULL;
11
12typedef struct _owl_sub_list {                            /* noproto */
13  ZSubscription_t *subs;
14  int nsubs;
15} owl_sub_list;
16
17Code_t ZResetAuthentication(void);
18#endif
19
20#define HM_SVC_FALLBACK         htons((unsigned short) 2104)
21
22static char *owl_zephyr_dotfile(const char *name, const char *input)
23{
24  if (input != NULL)
25    return owl_strdup(input);
26  else
27    return owl_sprintf("%s/%s", owl_global_get_homedir(&g), name);
28}
29
30#ifdef HAVE_LIBZEPHYR
31void owl_zephyr_initialize(void)
32{
33  int ret;
34  struct servent *sp;
35  struct sockaddr_in sin;
36  ZNotice_t req;
37  Code_t code;
38
39  /*
40   * Code modified from libzephyr's ZhmStat.c
41   *
42   * Modified to add the fd to our select loop, rather than hanging
43   * until we get an ack.
44   */
45
46  if ((ret = ZOpenPort(NULL)) != ZERR_NONE) {
47    owl_function_error("Error opening Zephyr port: %s", error_message(ret));
48    return;
49  }
50
51  (void) memset(&sin, 0, sizeof(struct sockaddr_in));
52
53  sp = getservbyname(HM_SVCNAME, "udp");
54
55  sin.sin_port = (sp) ? sp->s_port : HM_SVC_FALLBACK;
56  sin.sin_family = AF_INET;
57
58  sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
59
60  (void) memset(&req, 0, sizeof(req));
61  req.z_kind = STAT;
62  req.z_port = 0;
63  req.z_class = zstr(HM_STAT_CLASS);
64  req.z_class_inst = zstr(HM_STAT_CLIENT);
65  req.z_opcode = zstr(HM_GIMMESTATS);
66  req.z_sender = zstr("");
67  req.z_recipient = zstr("");
68  req.z_default_format = zstr("");
69  req.z_message_len = 0;
70
71  if ((code = ZSetDestAddr(&sin)) != ZERR_NONE) {
72    owl_function_error("Initializing Zephyr: %s", error_message(code));
73    return;
74  }
75
76  if ((code = ZSendNotice(&req, ZNOAUTH)) != ZERR_NONE) {
77    owl_function_error("Initializing Zephyr: %s", error_message(code));
78    return;
79  }
80
81  owl_select_add_io_dispatch(ZGetFD(), OWL_IO_READ|OWL_IO_EXCEPT, &owl_zephyr_finish_initialization, NULL, NULL);
82}
83
84void owl_zephyr_finish_initialization(const owl_io_dispatch *d, void *data) {
85  Code_t code;
86  char *perl;
87
88  owl_select_remove_io_dispatch(d);
89
90  ZClosePort();
91
92  if ((code = ZInitialize()) != ZERR_NONE) {
93    owl_function_error("Initializing Zephyr: %s", error_message(code));
94    return;
95  }
96
97  if ((code = ZOpenPort(NULL)) != ZERR_NONE) {
98    owl_function_error("Initializing Zephyr: %s", error_message(code));
99    return;
100  }
101
102  owl_select_add_io_dispatch(ZGetFD(), OWL_IO_READ|OWL_IO_EXCEPT, &owl_zephyr_process_events, NULL, NULL);
103
104  owl_global_set_havezephyr(&g);
105
106  if(g.load_initial_subs) {
107    owl_zephyr_load_initial_subs();
108  }
109  while(deferred_subs != NULL) {
110    owl_sub_list *subs = deferred_subs->data;
111    owl_function_debugmsg("Loading %d deferred subs.", subs->nsubs);
112    owl_zephyr_loadsubs_helper(subs->subs, subs->nsubs);
113    deferred_subs = g_list_delete_link(deferred_subs, deferred_subs);
114    owl_free(subs);
115  }
116
117  /* zlog in if we need to */
118  if (owl_global_is_startuplogin(&g)) {
119    owl_function_debugmsg("startup: doing zlog in");
120    owl_zephyr_zlog_in();
121  }
122  /* check pseudo-logins if we need to */
123  if (owl_global_is_pseudologins(&g)) {
124    owl_function_debugmsg("startup: checking pseudo-logins");
125    owl_function_zephyr_buddy_check(0);
126  }
127
128  perl = owl_perlconfig_execute("BarnOwl::Zephyr::_zephyr_startup()");
129  owl_free(perl);
130
131  owl_select_add_pre_select_action(owl_zephyr_pre_select_action, NULL, NULL);
132}
133
134void owl_zephyr_load_initial_subs(void) {
135  int ret_sd, ret_bd, ret_u;
136
137  owl_function_debugmsg("startup: loading initial zephyr subs");
138
139  /* load default subscriptions */
140  ret_sd = owl_zephyr_loaddefaultsubs();
141
142  /* load Barnowl default subscriptions */
143  ret_bd = owl_zephyr_loadbarnowldefaultsubs();
144
145  /* load subscriptions from subs file */
146  ret_u = owl_zephyr_loadsubs(NULL, 0);
147
148  if (ret_sd || ret_bd || ret_u) {
149    owl_function_error("Error loading zephyr subscriptions");
150  }
151
152  /* load login subscriptions */
153  if (owl_global_is_loginsubs(&g)) {
154    owl_function_debugmsg("startup: loading login subs");
155    owl_function_loadloginsubs(NULL);
156  }
157}
158#else
159void owl_zephyr_initialize(void)
160{
161}
162#endif
163
164
165int owl_zephyr_shutdown(void)
166{
167#ifdef HAVE_LIBZEPHYR
168  if(owl_global_is_havezephyr(&g)) {
169    unsuball();
170    ZClosePort();
171  }
172#endif
173  return 0;
174}
175
176int owl_zephyr_zpending(void)
177{
178#ifdef HAVE_LIBZEPHYR
179  Code_t code;
180  if(owl_global_is_havezephyr(&g)) {
181    if((code = ZPending()) < 0) {
182      owl_function_debugmsg("Error (%s) in ZPending()\n",
183                            error_message(code));
184      return 0;
185    }
186    return code;
187  }
188#endif
189  return 0;
190}
191
192const char *owl_zephyr_get_realm(void)
193{
194#ifdef HAVE_LIBZEPHYR
195  if (owl_global_is_havezephyr(&g))
196    return(ZGetRealm());
197#endif
198  return "";
199}
200
201const char *owl_zephyr_get_sender(void)
202{
203#ifdef HAVE_LIBZEPHYR
204  if (owl_global_is_havezephyr(&g))
205    return(ZGetSender());
206#endif
207  return "";
208}
209
210#ifdef HAVE_LIBZEPHYR
211int owl_zephyr_loadsubs_helper(ZSubscription_t subs[], int count)
212{
213  int ret = 0;
214  if (owl_global_is_havezephyr(&g)) {
215    int i;
216    /* sub without defaults */
217    if (ZSubscribeToSansDefaults(subs,count,0) != ZERR_NONE) {
218      owl_function_error("Error subscribing to zephyr notifications.");
219      ret=-2;
220    }
221
222    /* free stuff */
223    for (i=0; i<count; i++) {
224      owl_free(subs[i].zsub_class);
225      owl_free(subs[i].zsub_classinst);
226      owl_free(subs[i].zsub_recipient);
227    }
228
229    owl_free(subs);
230  } else {
231    owl_sub_list *s = owl_malloc(sizeof(owl_sub_list));
232    s->subs = subs;
233    s->nsubs = count;
234    deferred_subs = g_list_append(deferred_subs, s);
235  }
236
237  return ret;
238}
239#endif
240
241/* Load zephyr subscriptions from 'filename'.  If 'filename' is NULL,
242 * the default file $HOME/.zephyr.subs will be used.
243 *
244 * Returns 0 on success.  If the file does not exist, return -1 if
245 * 'error_on_nofile' is 1, otherwise return 0.  Return -1 if the file
246 * exists but can not be read.  Return -2 if there is a failure from
247 * zephyr to load the subscriptions.
248 */
249int owl_zephyr_loadsubs(const char *filename, int error_on_nofile)
250{
251#ifdef HAVE_LIBZEPHYR
252  FILE *file;
253  char *tmp, *start;
254  char *buffer = NULL;
255  char *subsfile;
256  ZSubscription_t *subs;
257  int subSize = 1024;
258  int count;
259  struct stat statbuff;
260
261  subs = owl_malloc(sizeof(ZSubscription_t) * subSize);
262  subsfile = owl_zephyr_dotfile(".zephyr.subs", filename);
263
264  if (stat(subsfile, &statbuff) != 0) {
265    owl_free(subsfile);
266    if (error_on_nofile == 1)
267      return -1;
268    return 0;
269  }
270
271  ZResetAuthentication();
272  count = 0;
273  file = fopen(subsfile, "r");
274  owl_free(subsfile);
275  if (!file)
276    return -1;
277  while (owl_getline(&buffer, file)) {
278    if (buffer[0] == '#' || buffer[0] == '\n')
279        continue;
280
281    if (buffer[0] == '-')
282      start = buffer + 1;
283    else
284      start = buffer;
285
286    if (count >= subSize) {
287      subSize *= 2;
288      subs = owl_realloc(subs, sizeof(ZSubscription_t) * subSize);
289    }
290   
291    /* add it to the list of subs */
292    if ((tmp = strtok(start, ",\n\r")) == NULL)
293      continue;
294    subs[count].zsub_class = owl_strdup(tmp);
295    if ((tmp=strtok(NULL, ",\n\r")) == NULL)
296      continue;
297    subs[count].zsub_classinst = owl_strdup(tmp);
298    if ((tmp = strtok(NULL, " \t\n\r")) == NULL)
299      continue;
300    subs[count].zsub_recipient = owl_strdup(tmp);
301
302    /* if it started with '-' then add it to the global punt list, and
303     * remove it from the list of subs. */
304    if (buffer[0] == '-') {
305      owl_function_zpunt(subs[count].zsub_class, subs[count].zsub_classinst, subs[count].zsub_recipient, 0);
306      owl_free(subs[count].zsub_class);
307      owl_free(subs[count].zsub_classinst);
308      owl_free(subs[count].zsub_recipient);
309    } else {
310      count++;
311    }
312  }
313  fclose(file);
314  if (buffer)
315    owl_free(buffer);
316
317  return owl_zephyr_loadsubs_helper(subs, count);
318#else
319  return 0;
320#endif
321}
322
323/* Load default Barnowl subscriptions
324 *
325 * Returns 0 on success.
326 * Return -2 if there is a failure from zephyr to load the subscriptions.
327 */
328int owl_zephyr_loadbarnowldefaultsubs(void)
329{
330#ifdef HAVE_LIBZEPHYR
331  ZSubscription_t *subs;
332  int subSize = 10; /* Max Barnowl default subs we allow */
333  int count, ret;
334
335  subs = owl_malloc(sizeof(ZSubscription_t) * subSize);
336  ret = 0;
337  ZResetAuthentication();
338  count=0;
339
340  subs[count].zsub_class=owl_strdup("message");
341  subs[count].zsub_classinst=owl_strdup("*");
342  subs[count].zsub_recipient=owl_strdup("%me%");
343  count++;
344
345  ret = owl_zephyr_loadsubs_helper(subs, count);
346  return(ret);
347#else
348  return(0);
349#endif
350}
351
352int owl_zephyr_loaddefaultsubs(void)
353{
354#ifdef HAVE_LIBZEPHYR
355  if (owl_global_is_havezephyr(&g)) {
356    ZSubscription_t subs[10];
357   
358    if (ZSubscribeTo(subs,0,0) != ZERR_NONE) {
359      owl_function_error("Error subscribing to default zephyr notifications.");
360      return(-1);
361    }
362  }
363  return(0);
364#else
365  return(0);
366#endif
367}
368
369int owl_zephyr_loadloginsubs(const char *filename)
370{
371#ifdef HAVE_LIBZEPHYR
372  FILE *file;
373  ZSubscription_t *subs;
374  int numSubs = 100;
375  char *subsfile;
376  char *buffer = NULL;
377  int count;
378  struct stat statbuff;
379
380  subs = owl_malloc(numSubs * sizeof(ZSubscription_t));
381  subsfile = owl_zephyr_dotfile(".anyone", filename);
382
383  if (stat(subsfile, &statbuff) == -1) {
384    owl_free(subs);
385    owl_free(subsfile);
386    return 0;
387  }
388
389  ZResetAuthentication();
390  count = 0;
391  file = fopen(subsfile, "r");
392  owl_free(subsfile);
393  if (file) {
394    while (owl_getline_chomp(&buffer, file)) {
395      if (buffer[0] == '\0' || buffer[0] == '#')
396        continue;
397
398      if (count == numSubs) {
399        numSubs *= 2;
400        subs = owl_realloc(subs, numSubs * sizeof(ZSubscription_t));
401      }
402
403      subs[count].zsub_class = owl_strdup("login");
404      subs[count].zsub_recipient = owl_strdup("*");
405      subs[count].zsub_classinst = long_zuser(buffer);
406
407      count++;
408    }
409    fclose(file);
410  } else {
411    return 0;
412  }
413  if (buffer)
414    owl_free(buffer);
415
416  return owl_zephyr_loadsubs_helper(subs, count);
417#else
418  return 0;
419#endif
420}
421
422void unsuball(void)
423{
424#if HAVE_LIBZEPHYR
425  int ret;
426
427  ZResetAuthentication();
428  ret=ZCancelSubscriptions(0);
429  if (ret != ZERR_NONE) {
430    com_err("owl",ret,"while unsubscribing");
431  }
432#endif
433}
434
435int owl_zephyr_sub(const char *class, const char *inst, const char *recip)
436{
437#ifdef HAVE_LIBZEPHYR
438  ZSubscription_t subs[5];
439
440  subs[0].zsub_class=zstr(class);
441  subs[0].zsub_classinst=zstr(inst);
442  subs[0].zsub_recipient=zstr(recip);
443
444  ZResetAuthentication();
445  if (ZSubscribeTo(subs,1,0) != ZERR_NONE) {
446    owl_function_error("Error subbing to <%s,%s,%s>", class, inst, recip);
447    return(-2);
448  }
449  return(0);
450#else
451  return(0);
452#endif
453}
454
455
456int owl_zephyr_unsub(const char *class, const char *inst, const char *recip)
457{
458#ifdef HAVE_LIBZEPHYR
459  ZSubscription_t subs[5];
460
461  subs[0].zsub_class=zstr(class);
462  subs[0].zsub_classinst=zstr(inst);
463  subs[0].zsub_recipient=zstr(recip);
464
465  ZResetAuthentication();
466  if (ZUnsubscribeTo(subs,1,0) != ZERR_NONE) {
467    owl_function_error("Error unsubbing from <%s,%s,%s>", class, inst, recip);
468    return(-2);
469  }
470  return(0);
471#else
472  return(0);
473#endif
474}
475
476/* return a pointer to the data in the Jth field, (NULL terminated by
477 * definition).  Caller must free the return.
478 */
479#ifdef HAVE_LIBZEPHYR
480char *owl_zephyr_get_field(const ZNotice_t *n, int j)
481{
482  int i, count, save;
483  char *out;
484
485  /* If there's no message here, just run along now */
486  if (n->z_message_len == 0)
487    return(owl_strdup(""));
488
489  count=save=0;
490  for (i=0; i<n->z_message_len; i++) {
491    if (n->z_message[i]=='\0') {
492      count++;
493      if (count==j) {
494        /* just found the end of the field we're looking for */
495        return(owl_strdup(n->z_message+save));
496      } else {
497        save=i+1;
498      }
499    }
500  }
501  /* catch the last field, which might not be null terminated */
502  if (count==j-1) {
503    out=owl_malloc(n->z_message_len-save+5);
504    memcpy(out, n->z_message+save, n->z_message_len-save);
505    out[n->z_message_len-save]='\0';
506    return(out);
507  }
508
509  return(owl_strdup(""));
510}
511
512char *owl_zephyr_get_field_as_utf8(const ZNotice_t *n, int j)
513{
514  int i, count, save;
515
516  /* If there's no message here, just run along now */
517  if (n->z_message_len == 0)
518    return(owl_strdup(""));
519
520  count=save=0;
521  for (i = 0; i < n->z_message_len; i++) {
522    if (n->z_message[i]=='\0') {
523      count++;
524      if (count == j) {
525        /* just found the end of the field we're looking for */
526        return(owl_validate_or_convert(n->z_message + save));
527      } else {
528        save = i + 1;
529      }
530    }
531  }
532  /* catch the last field, which might not be null terminated */
533  if (count == j - 1) {
534    char *tmp, *out;
535    tmp = owl_malloc(n->z_message_len-save+5);
536    memcpy(tmp, n->z_message+save, n->z_message_len-save);
537    tmp[n->z_message_len-save]='\0';
538    out = owl_validate_or_convert(tmp);
539    owl_free(tmp);
540    return out;
541  }
542
543  return(owl_strdup(""));
544}
545#else
546char *owl_zephyr_get_field(void *n, int j)
547{
548  return(owl_strdup(""));
549}
550char *owl_zephyr_get_field_as_utf8(void *n, int j)
551{
552  return owl_zephyr_get_field(n, j);
553}
554#endif
555
556
557#ifdef HAVE_LIBZEPHYR
558int owl_zephyr_get_num_fields(const ZNotice_t *n)
559{
560  int i, fields;
561
562  if(n->z_message_len == 0)
563    return 0;
564
565  fields=1;
566  for (i=0; i<n->z_message_len; i++) {
567    if (n->z_message[i]=='\0') fields++;
568  }
569 
570  return(fields);
571}
572#else
573int owl_zephyr_get_num_fields(const void *n)
574{
575  return(0);
576}
577#endif
578
579#ifdef HAVE_LIBZEPHYR
580/* return a pointer to the message, place the message length in k
581 * caller must free the return
582 */
583char *owl_zephyr_get_message(const ZNotice_t *n, const owl_message *m)
584{
585  /* don't let ping messages have a body */
586  if (!strcasecmp(n->z_opcode, "ping")) {
587    return(owl_strdup(""));
588  }
589
590  /* deal with MIT NOC messages */
591  if (!strcasecmp(n->z_default_format, "@center(@bold(NOC Message))\n\n@bold(Sender:) $1 <$sender>\n@bold(Time:  ) $time\n\n@italic($opcode service on $instance $3.) $4\n")) {
592    char *msg, *field3, *field4;
593
594    field3 = owl_zephyr_get_field(n, 3);
595    field4 = owl_zephyr_get_field(n, 4);
596
597    msg = owl_sprintf("%s service on %s %s\n%s", n->z_opcode, n->z_class_inst, field3, field4);
598    owl_free(field3);
599    owl_free(field4);
600    if (msg) {
601      return msg;
602    }
603  }
604  /* deal with MIT Discuss messages */
605  else if (!strcasecmp(n->z_default_format, "New transaction [$1] entered in $2\nFrom: $3 ($5)\nSubject: $4") ||
606           !strcasecmp(n->z_default_format, "New transaction [$1] entered in $2\nFrom: $3\nSubject: $4")) {
607    char *msg, *field1, *field2, *field3, *field4, *field5;
608   
609    field1 = owl_zephyr_get_field(n, 1);
610    field2 = owl_zephyr_get_field(n, 2);
611    field3 = owl_zephyr_get_field(n, 3);
612    field4 = owl_zephyr_get_field(n, 4);
613    field5 = owl_zephyr_get_field(n, 5);
614   
615    msg = owl_sprintf("New transaction [%s] entered in %s\nFrom: %s (%s)\nSubject: %s", field1, field2, field3, field5, field4);
616    owl_free(field1);
617    owl_free(field2);
618    owl_free(field3);
619    owl_free(field4);
620    owl_free(field5);
621    if (msg) {
622      return msg;
623    }
624  }
625  /* deal with MIT Moira messages */
626  else if (!strcasecmp(n->z_default_format, "MOIRA $instance on $fromhost:\n $message\n")) {
627    char *msg, *field1;
628   
629    field1 = owl_zephyr_get_field(n, 1);
630   
631    msg = owl_sprintf("MOIRA %s on %s: %s", n->z_class_inst, owl_message_get_hostname(m), field1);
632    owl_free(field1);
633    if (msg) {
634      return msg;
635    }
636  }
637
638  if (owl_zephyr_get_num_fields(n) == 1) {
639    return(owl_zephyr_get_field(n, 1));
640  }
641  else {
642    return(owl_zephyr_get_field(n, 2));
643  }
644}
645#endif
646
647#ifdef HAVE_LIBZEPHYR
648const char *owl_zephyr_get_zsig(const ZNotice_t *n, int *k)
649{
650  /* return a pointer to the zsig if there is one */
651
652  /* message length 0? No zsig */
653  if (n->z_message_len==0) {
654    *k=0;
655    return("");
656  }
657
658  /* If there's only one field, no zsig */
659  if (owl_zephyr_get_num_fields(n) == 1) {
660    *k=0;
661    return("");
662  }
663
664  /* Everything else is field 1 */
665  *k=strlen(n->z_message);
666  return(n->z_message);
667}
668#else
669const char *owl_zephyr_get_zsig(const void *n, int *k)
670{
671  return("");
672}
673#endif
674
675int send_zephyr(const char *opcode, const char *zsig, const char *class, const char *instance, const char *recipient, const char *message)
676{
677#ifdef HAVE_LIBZEPHYR
678  int ret;
679  ZNotice_t notice;
680   
681  memset(&notice, 0, sizeof(notice));
682
683  ZResetAuthentication();
684
685  if (!zsig) zsig="";
686 
687  notice.z_kind=ACKED;
688  notice.z_port=0;
689  notice.z_class=zstr(class);
690  notice.z_class_inst=zstr(instance);
691  notice.z_sender=NULL;
692  if (!strcmp(recipient, "*") || !strcmp(recipient, "@")) {
693    notice.z_recipient=zstr("");
694    if (*owl_global_get_zsender(&g))
695        notice.z_sender=zstr(owl_global_get_zsender(&g));
696  } else {
697    notice.z_recipient=zstr(recipient);
698  }
699  notice.z_default_format=zstr("Class $class, Instance $instance:\nTo: @bold($recipient) at $time $date\nFrom: @bold{$1 <$sender>}\n\n$2");
700  if (opcode) notice.z_opcode=zstr(opcode);
701
702  notice.z_message_len=strlen(zsig)+1+strlen(message);
703  notice.z_message=owl_malloc(notice.z_message_len+10);
704  strcpy(notice.z_message, zsig);
705  memcpy(notice.z_message+strlen(zsig)+1, message, strlen(message));
706
707  /* ret=ZSendNotice(&notice, ZAUTH); */
708  ret=ZSrvSendNotice(&notice, ZAUTH, send_zephyr_helper);
709 
710  /* free then check the return */
711  owl_free(notice.z_message);
712  ZFreeNotice(&notice);
713  if (ret!=ZERR_NONE) {
714    owl_function_error("Error sending zephyr");
715    return(ret);
716  }
717  return(0);
718#else
719  return(0);
720#endif
721}
722
723#ifdef HAVE_LIBZEPHYR
724Code_t send_zephyr_helper(ZNotice_t *notice, char *buf, int len, int wait)
725{
726  return(ZSendPacket(buf, len, 0));
727}
728#endif
729
730void send_ping(const char *to, const char *zclass, const char *zinstance)
731{
732#ifdef HAVE_LIBZEPHYR
733  send_zephyr("PING", "", zclass, zinstance, to, "");
734#endif
735}
736
737#ifdef HAVE_LIBZEPHYR
738void owl_zephyr_handle_ack(const ZNotice_t *retnotice)
739{
740  char *tmp;
741 
742  /* if it's an HMACK ignore it */
743  if (retnotice->z_kind == HMACK) return;
744
745  if (retnotice->z_kind == SERVNAK) {
746    owl_function_error("Authorization failure sending zephyr");
747  } else if ((retnotice->z_kind != SERVACK) || !retnotice->z_message_len) {
748    owl_function_error("Detected server failure while receiving acknowledgement");
749  } else if (!strcmp(retnotice->z_message, ZSRVACK_SENT)) {
750    if (!strcasecmp(retnotice->z_opcode, "ping")) {
751      return;
752    } else {
753      if (strcasecmp(retnotice->z_recipient, ""))
754      { /* personal */
755        tmp=short_zuser(retnotice->z_recipient);
756        if(!strcasecmp(retnotice->z_class, "message") &&
757           !strcasecmp(retnotice->z_class_inst, "personal")) {
758          owl_function_makemsg("Message sent to %s.", tmp);
759        } else if(!strcasecmp(retnotice->z_class, "message")) { /* instanced, but not classed, personal */
760          owl_function_makemsg("Message sent to %s on -i %s\n", tmp, retnotice->z_class_inst);
761        } else { /* classed personal */
762          owl_function_makemsg("Message sent to %s on -c %s -i %s\n", tmp, retnotice->z_class, retnotice->z_class_inst);
763        }
764        owl_free(tmp);
765      } else {
766        /* class / instance message */
767          owl_function_makemsg("Message sent to -c %s -i %s\n", retnotice->z_class, retnotice->z_class_inst);
768      }
769    }
770  } else if (!strcmp(retnotice->z_message, ZSRVACK_NOTSENT)) {
771    #define BUFFLEN 1024
772    if (retnotice->z_recipient == NULL
773        || *retnotice->z_recipient == 0
774        || *retnotice->z_recipient == '@') {
775      char buff[BUFFLEN];
776      owl_function_error("No one subscribed to class %s", retnotice->z_class);
777      snprintf(buff, BUFFLEN, "Could not send message to class %s: no one subscribed.\n", retnotice->z_class);
778      owl_function_adminmsg("", buff);
779    } else {
780      char buff[BUFFLEN];
781      owl_zwrite zw;
782      char *realm;
783
784      tmp = short_zuser(retnotice->z_recipient);
785      owl_function_error("%s: Not logged in or subscribing.", tmp);
786      /*
787       * These error messages are often over 80 chars, but users who want to
788       * see the whole thing can scroll to the side, and for those with wide
789       * terminals or who don't care, not splitting saves a line in the UI
790       */
791      if(strcasecmp(retnotice->z_class, "message")) {
792        snprintf(buff, BUFFLEN,
793                 "Could not send message to %s: "
794                 "not logged in or subscribing to class %s, instance %s.\n",
795                 tmp,
796                 retnotice->z_class,
797                 retnotice->z_class_inst);
798      } else if(strcasecmp(retnotice->z_class_inst, "personal")) {
799        snprintf(buff, BUFFLEN,
800                 "Could not send message to %s: "
801                 "not logged in or subscribing to instance %s.\n",
802                 tmp,
803                 retnotice->z_class_inst);
804      } else {
805        snprintf(buff, BUFFLEN,
806                 "Could not send message to %s: "
807                 "not logged in or subscribing to messages.\n",
808                 tmp);
809      }
810      owl_function_adminmsg("", buff);
811
812      memset(&zw, 0, sizeof(zw));
813      zw.class = owl_strdup(retnotice->z_class);
814      zw.inst  = owl_strdup(retnotice->z_class_inst);
815      realm = strchr(retnotice->z_recipient, '@');
816      if(realm) {
817        zw.realm = owl_strdup(realm + 1);
818      } else {
819        zw.realm = owl_strdup(owl_zephyr_get_realm());
820      }
821      zw.opcode = owl_strdup(retnotice->z_opcode);
822      zw.zsig   = owl_strdup("");
823      owl_list_create(&(zw.recips));
824      owl_list_append_element(&(zw.recips), owl_strdup(tmp));
825
826      owl_log_outgoing_zephyr_error(&zw, buff);
827
828      owl_zwrite_cleanup(&zw);
829      owl_free(tmp);
830    }
831  } else {
832    owl_function_error("Internal error on ack (%s)", retnotice->z_message);
833  }
834}
835#else
836void owl_zephyr_handle_ack(const void *retnotice)
837{
838}
839#endif
840
841#ifdef HAVE_LIBZEPHYR
842int owl_zephyr_notice_is_ack(const ZNotice_t *n)
843{
844  if (n->z_kind == SERVNAK || n->z_kind == SERVACK || n->z_kind == HMACK) {
845    if (!strcasecmp(n->z_class, LOGIN_CLASS)) return(0);
846    return(1);
847  }
848  return(0);
849}
850#else
851int owl_zephyr_notice_is_ack(const void *n)
852{
853  return(0);
854}
855#endif
856 
857void owl_zephyr_zaway(const owl_message *m)
858{
859#ifdef HAVE_LIBZEPHYR
860  char *tmpbuff, *myuser, *to;
861  owl_message *mout;
862  owl_zwrite *z;
863 
864  /* bail if it doesn't look like a message we should reply to.  Some
865   * of this defined by the way zaway(1) works
866   */
867  if (strcasecmp(owl_message_get_class(m), "message")) return;
868  if (strcasecmp(owl_message_get_recipient(m), ZGetSender())) return;
869  if (!strcasecmp(owl_message_get_sender(m), "")) return;
870  if (!strcasecmp(owl_message_get_opcode(m), "ping")) return;
871  if (!strcasecmp(owl_message_get_opcode(m), "auto")) return;
872  if (!strcasecmp(owl_message_get_zsig(m), "Automated reply:")) return;
873  if (!strcasecmp(owl_message_get_sender(m), ZGetSender())) return;
874  if (owl_message_get_attribute_value(m, "isauto")) return;
875
876  if (owl_global_is_smartstrip(&g)) {
877    to=owl_zephyr_smartstripped_user(owl_message_get_sender(m));
878  } else {
879    to=owl_strdup(owl_message_get_sender(m));
880  }
881
882  send_zephyr("",
883              "Automated reply:",
884              owl_message_get_class(m),
885              owl_message_get_instance(m),
886              to,
887              owl_global_get_zaway_msg(&g));
888
889  myuser=short_zuser(to);
890  if (!strcasecmp(owl_message_get_instance(m), "personal")) {
891    tmpbuff = owl_sprintf("zwrite %s", myuser);
892  } else {
893    tmpbuff = owl_sprintf("zwrite -i %s %s", owl_message_get_instance(m), myuser);
894  }
895  owl_free(myuser);
896  owl_free(to);
897
898  z = owl_zwrite_new(tmpbuff);
899  owl_zwrite_set_message(z, owl_global_get_zaway_msg(&g));
900  owl_zwrite_set_zsig(z, "Automated reply:");
901
902  /* display the message as an admin message in the receive window */
903  mout=owl_function_make_outgoing_zephyr(z);
904  owl_global_messagequeue_addmsg(&g, mout);
905  owl_free(tmpbuff);
906  owl_zwrite_delete(z);
907#endif
908}
909
910#ifdef HAVE_LIBZEPHYR
911void owl_zephyr_hackaway_cr(ZNotice_t *n)
912{
913  /* replace \r's with ' '.  Gross-ish */
914  int i;
915
916  for (i=0; i<n->z_message_len; i++) {
917    if (n->z_message[i]=='\r') {
918      n->z_message[i]=' ';
919    }
920  }
921}
922#endif
923
924char *owl_zephyr_zlocate(const char *user, int auth)
925{
926#ifdef HAVE_LIBZEPHYR
927  int ret, numlocs;
928  int one = 1;
929  ZLocations_t locations;
930  char *myuser;
931  char *p, *result;
932
933  ZResetAuthentication();
934  ret = ZLocateUser(zstr(user), &numlocs, auth ? ZAUTH : ZNOAUTH);
935  if (ret != ZERR_NONE)
936    return owl_sprintf("Error locating user %s: %s\n",
937                       user, error_message(ret));
938
939  myuser = short_zuser(user);
940  if (numlocs == 0) {
941    result = owl_sprintf("%s: Hidden or not logged in\n", myuser);
942  } else {
943    result = owl_strdup("");
944    for (; numlocs; numlocs--) {
945      ZGetLocations(&locations, &one);
946      p = owl_sprintf("%s%s: %s\t%s\t%s\n",
947                          result, myuser,
948                          locations.host ? locations.host : "?",
949                          locations.tty ? locations.tty : "?",
950                          locations.time ? locations.time : "?");
951      owl_free(result);
952      result = p;
953    }
954  }
955  owl_free(myuser);
956
957  return result;
958#else
959  return owl_strdup("");
960#endif
961}
962
963void owl_zephyr_addsub(const char *filename, const char *class, const char *inst, const char *recip)
964{
965#ifdef HAVE_LIBZEPHYR
966  char *line, *subsfile, *s = NULL;
967  FILE *file;
968  int duplicate = 0;
969
970  line = owl_zephyr_makesubline(class, inst, recip);
971  subsfile = owl_zephyr_dotfile(".zephyr.subs", filename);
972
973  /* if the file already exists, check to see if the sub is already there */
974  file = fopen(subsfile, "r");
975  if (file) {
976    while (owl_getline(&s, file)) {
977      if (strcasecmp(s, line) == 0) {
978        owl_function_error("Subscription already present in %s", subsfile);
979        duplicate++;
980      }
981    }
982    fclose(file);
983    owl_free(s);
984  }
985
986  if (!duplicate) {
987    file = fopen(subsfile, "a");
988    if (file) {
989      fputs(line, file);
990      fclose(file);
991      owl_function_makemsg("Subscription added");
992    } else {
993      owl_function_error("Error opening file %s for writing", subsfile);
994    }
995  }
996
997  owl_free(line);
998#endif
999}
1000
1001void owl_zephyr_delsub(const char *filename, const char *class, const char *inst, const char *recip)
1002{
1003#ifdef HAVE_LIBZEPHYR
1004  char *line, *subsfile;
1005  int linesdeleted;
1006 
1007  line=owl_zephyr_makesubline(class, inst, recip);
1008  line[strlen(line)-1]='\0';
1009
1010  subsfile = owl_zephyr_dotfile(".zephyr.subs", filename);
1011 
1012  linesdeleted = owl_util_file_deleteline(subsfile, line, 1);
1013  if (linesdeleted > 0) {
1014    owl_function_makemsg("Subscription removed");
1015  } else {
1016    owl_function_error("No subscription present in %s", subsfile);
1017  }
1018  owl_free(subsfile);
1019  owl_free(line);
1020#endif
1021}
1022
1023/* caller must free the return */
1024char *owl_zephyr_makesubline(const char *class, const char *inst, const char *recip)
1025{
1026  return owl_sprintf("%s,%s,%s\n", class, inst, !strcmp(recip, "") ? "*" : recip);
1027}
1028
1029
1030void owl_zephyr_zlog_in(void)
1031{
1032#ifdef HAVE_LIBZEPHYR
1033  const char *exposure, *eset;
1034  int ret;
1035
1036  ZResetAuthentication();
1037   
1038  eset=EXPOSE_REALMVIS;
1039  exposure=ZGetVariable(zstr("exposure"));
1040  if (exposure==NULL) {
1041    eset=EXPOSE_REALMVIS;
1042  } else if (!strcasecmp(exposure,EXPOSE_NONE)) {
1043    eset = EXPOSE_NONE;
1044  } else if (!strcasecmp(exposure,EXPOSE_OPSTAFF)) {
1045    eset = EXPOSE_OPSTAFF;
1046  } else if (!strcasecmp(exposure,EXPOSE_REALMVIS)) {
1047    eset = EXPOSE_REALMVIS;
1048  } else if (!strcasecmp(exposure,EXPOSE_REALMANN)) {
1049    eset = EXPOSE_REALMANN;
1050  } else if (!strcasecmp(exposure,EXPOSE_NETVIS)) {
1051    eset = EXPOSE_NETVIS;
1052  } else if (!strcasecmp(exposure,EXPOSE_NETANN)) {
1053    eset = EXPOSE_NETANN;
1054  }
1055   
1056  ret=ZSetLocation(zstr(eset));
1057  if (ret != ZERR_NONE) {
1058    /*
1059      owl_function_makemsg("Error setting location: %s", error_message(ret));
1060    */
1061  }
1062#endif
1063}
1064
1065void owl_zephyr_zlog_out(void)
1066{
1067#ifdef HAVE_LIBZEPHYR
1068  int ret;
1069
1070  ZResetAuthentication();
1071  ret=ZUnsetLocation();
1072  if (ret != ZERR_NONE) {
1073    /*
1074      owl_function_makemsg("Error unsetting location: %s", error_message(ret));
1075    */
1076  }
1077#endif
1078}
1079
1080void owl_zephyr_addbuddy(const char *name)
1081{
1082  char *filename;
1083  FILE *file;
1084 
1085  filename = owl_zephyr_dotfile(".anyone", NULL);
1086  file = fopen(filename, "a");
1087  owl_free(filename);
1088  if (!file) {
1089    owl_function_error("Error opening zephyr buddy file for append");
1090    return;
1091  }
1092  fprintf(file, "%s\n", name);
1093  fclose(file);
1094}
1095
1096void owl_zephyr_delbuddy(const char *name)
1097{
1098  char *filename;
1099
1100  filename = owl_zephyr_dotfile(".anyone", NULL);
1101  owl_util_file_deleteline(filename, name, 0);
1102  owl_free(filename);
1103}
1104
1105/* return auth string */
1106#ifdef HAVE_LIBZEPHYR
1107const char *owl_zephyr_get_authstr(const ZNotice_t *n)
1108{
1109
1110  if (!n) return("UNKNOWN");
1111
1112  if (n->z_auth == ZAUTH_FAILED) {
1113    return ("FAILED");
1114  } else if (n->z_auth == ZAUTH_NO) {
1115    return ("NO");
1116  } else if (n->z_auth == ZAUTH_YES) {
1117    return ("YES");
1118  } else {
1119    return ("UNKNOWN");
1120  }           
1121}
1122#else
1123const char *owl_zephyr_get_authstr(const void *n)
1124{
1125  return("");
1126}
1127#endif
1128
1129/* Returns a buffer of subscriptions or an error message.  Caller must
1130 * free the return.
1131 */
1132char *owl_zephyr_getsubs(void)
1133{
1134#ifdef HAVE_LIBZEPHYR
1135  int ret, num, i, one;
1136  int buffsize;
1137  ZSubscription_t sub;
1138  char *out;
1139  one=1;
1140
1141  ret=ZRetrieveSubscriptions(0, &num);
1142  if (ret==ZERR_TOOMANYSUBS) {
1143    return(owl_strdup("Zephyr: too many subscriptions\n"));
1144  } else if (ret || (num <= 0)) {
1145    return(owl_strdup("Zephyr: error retriving subscriptions\n"));
1146  }
1147
1148  buffsize = (num + 1) * 50;
1149  out=owl_malloc(buffsize);
1150  strcpy(out, "");
1151  for (i=0; i<num; i++) {
1152    if ((ret = ZGetSubscriptions(&sub, &one)) != ZERR_NONE) {
1153      owl_free(out);
1154      ZFlushSubscriptions();
1155      out=owl_strdup("Error while getting subscriptions\n");
1156      return(out);
1157    } else {
1158      int tmpbufflen;
1159      char *tmpbuff;
1160      tmpbuff = owl_sprintf("<%s,%s,%s>\n%s", sub.zsub_class, sub.zsub_classinst, sub.zsub_recipient, out);
1161      tmpbufflen = strlen(tmpbuff) + 1;
1162      if (tmpbufflen > buffsize) {
1163        char *out2;
1164        buffsize = tmpbufflen * 2;
1165        out2 = owl_realloc(out, buffsize);
1166        if (out2 == NULL) {
1167          owl_free(out);
1168          owl_free(tmpbuff);
1169          ZFlushSubscriptions();
1170          out=owl_strdup("Realloc error while getting subscriptions\n");
1171          return(out);   
1172        }
1173        out = out2;
1174      }
1175      strcpy(out, tmpbuff);
1176      owl_free(tmpbuff);
1177    }
1178  }
1179
1180  ZFlushSubscriptions();
1181  return(out);
1182#else
1183  return(owl_strdup("Zephyr not available"));
1184#endif
1185}
1186
1187const char *owl_zephyr_get_variable(const char *var)
1188{
1189#ifdef HAVE_LIBZEPHYR
1190  return(ZGetVariable(zstr(var)));
1191#else
1192  return("");
1193#endif
1194}
1195
1196void owl_zephyr_set_locationinfo(const char *host, const char *val)
1197{
1198#ifdef HAVE_LIBZEPHYR
1199  ZInitLocationInfo(zstr(host), zstr(val));
1200#endif
1201}
1202 
1203/* Strip a local realm fron the zephyr user name.
1204 * The caller must free the return
1205 */
1206char *short_zuser(const char *in)
1207{
1208  char *out, *ptr;
1209
1210  out=owl_strdup(in);
1211  ptr=strchr(out, '@');
1212  if (ptr) {
1213    if (!strcasecmp(ptr+1, owl_zephyr_get_realm())) {
1214      *ptr='\0';
1215    }
1216  }
1217  return(out);
1218}
1219
1220/* Append a local realm to the zephyr user name if necessary.
1221 * The caller must free the return.
1222 */
1223char *long_zuser(const char *in)
1224{
1225  if (strchr(in, '@')) {
1226    return(owl_strdup(in));
1227  }
1228  return(owl_sprintf("%s@%s", in, owl_zephyr_get_realm()));
1229}
1230
1231/* strip out the instance from a zsender's principal.  Preserves the
1232 * realm if present.  daemon.webzephyr is a special case.  The
1233 * caller must free the return
1234 */
1235char *owl_zephyr_smartstripped_user(const char *in)
1236{
1237  char *ptr, *realm, *out;
1238
1239  out=owl_strdup(in);
1240
1241  /* bail immeaditly if we don't have to do any work */
1242  ptr=strchr(out, '.');
1243  if (!strchr(out, '/') && !ptr) {
1244    /* no '/' and no '.' */
1245    return(out);
1246  }
1247  if (ptr && strchr(out, '@') && (ptr > strchr(out, '@'))) {
1248    /* There's a '.' but it's in the realm */
1249    return(out);
1250  }
1251  if (!strncasecmp(out, OWL_WEBZEPHYR_PRINCIPAL, strlen(OWL_WEBZEPHYR_PRINCIPAL))) {
1252    return(out);
1253  }
1254
1255  /* remove the realm from out, but hold on to it */
1256  realm=strchr(out, '@');
1257  if (realm) realm[0]='\0';
1258
1259  /* strip */
1260  ptr=strchr(out, '.');
1261  if (!ptr) ptr=strchr(out, '/');
1262  ptr[0]='\0';
1263
1264  /* reattach the realm if we had one */
1265  if (realm) {
1266    strcat(out, "@");
1267    strcat(out, realm+1);
1268  }
1269
1270  return(out);
1271}
1272
1273/* read the list of users in 'filename' as a .anyone file, and put the
1274 * names of the zephyr users in the list 'in'.  If 'filename' is NULL,
1275 * use the default .anyone file in the users home directory.  Returns
1276 * -1 on failure, 0 on success.
1277 */
1278int owl_zephyr_get_anyone_list(owl_list *in, const char *filename)
1279{
1280#ifdef HAVE_LIBZEPHYR
1281  char *ourfile, *tmp, *s = NULL;
1282  FILE *f;
1283
1284  ourfile = owl_zephyr_dotfile(".anyone", filename);
1285
1286  f = fopen(ourfile, "r");
1287  if (!f) {
1288    owl_function_error("Error opening file %s: %s", ourfile, strerror(errno) ? strerror(errno) : "");
1289    owl_free(ourfile);
1290    return -1;
1291  }
1292  owl_free(ourfile);
1293
1294  while (owl_getline_chomp(&s, f)) {
1295    /* ignore comments, blank lines etc. */
1296    if (s[0] == '#' || s[0] == '\0')
1297      continue;
1298
1299    /* ignore from # on */
1300    tmp = strchr(s, '#');
1301    if (tmp)
1302      tmp[0] = '\0';
1303
1304    /* ignore from SPC */
1305    tmp = strchr(s, ' ');
1306    if (tmp)
1307      tmp[0] = '\0';
1308
1309    owl_list_append_element(in, long_zuser(s));
1310  }
1311  owl_free(s);
1312  fclose(f);
1313  return 0;
1314#else
1315  return -1;
1316#endif
1317}
1318
1319#ifdef HAVE_LIBZEPHYR
1320void owl_zephyr_process_pseudologin(ZNotice_t *n)
1321{
1322  owl_message *m;
1323  owl_zbuddylist *zbl;
1324  GList **zaldlist;
1325  GList *zaldptr;
1326  ZAsyncLocateData_t *zald = NULL;
1327  ZLocations_t location;
1328  int numlocs, ret, notify;
1329
1330  /* Find a ZALD to match this notice. */
1331  zaldlist = owl_global_get_zaldlist(&g);
1332  zaldptr = g_list_first(*zaldlist);
1333  while (zaldptr) {
1334    if (ZCompareALDPred(n, zaldptr->data)) {
1335      zald = zaldptr->data;
1336      *zaldlist = g_list_remove(*zaldlist, zaldptr->data);
1337      break;
1338    }
1339    zaldptr = g_list_next(zaldptr);
1340  }
1341  if (zald) {
1342    /* Deal with notice. */
1343    notify = owl_global_get_pseudologin_notify(&g);
1344    zbl = owl_global_get_zephyr_buddylist(&g);
1345    ret = ZParseLocations(n, zald, &numlocs, NULL);
1346    if (ret == ZERR_NONE) {
1347      if (numlocs > 0 && !owl_zbuddylist_contains_user(zbl, zald->user)) {
1348        if (notify) {
1349          numlocs = 1;
1350          ret = ZGetLocations(&location, &numlocs);
1351          if (ret == ZERR_NONE) {
1352            /* Send a PSEUDO LOGIN! */
1353            m = owl_malloc(sizeof(owl_message));
1354            owl_message_create_pseudo_zlogin(m, 0, zald->user,
1355                                             location.host,
1356                                             location.time,
1357                                             location.tty);
1358            owl_global_messagequeue_addmsg(&g, m);
1359          }
1360          owl_zbuddylist_adduser(zbl, zald->user);
1361          owl_function_debugmsg("owl_function_zephyr_buddy_check: login for %s ", zald->user);
1362        }
1363      } else if (numlocs == 0 && owl_zbuddylist_contains_user(zbl, zald->user)) {
1364        /* Send a PSEUDO LOGOUT! */
1365        if (notify) {
1366          m = owl_malloc(sizeof(owl_message));
1367          owl_message_create_pseudo_zlogin(m, 1, zald->user, "", "", "");
1368          owl_global_messagequeue_addmsg(&g, m);
1369        }
1370        owl_zbuddylist_deluser(zbl, zald->user);
1371        owl_function_debugmsg("owl_function_zephyr_buddy_check: logout for %s ", zald->user);
1372      }
1373    }
1374    ZFreeALD(zald);
1375    owl_free(zald);
1376  }
1377}
1378#else
1379void owl_zephyr_process_pseudologin(void *n)
1380{
1381}
1382#endif
1383
1384void owl_zephyr_buddycheck_timer(owl_timer *t, void *data)
1385{
1386  if (owl_global_is_pseudologins(&g)) {
1387    owl_function_debugmsg("Doing zephyr buddy check");
1388    owl_function_zephyr_buddy_check(1);
1389  } else {
1390    owl_function_debugmsg("Warning: owl_zephyr_buddycheck_timer call pointless; timer should have been disabled");
1391  }
1392}
1393
1394/*
1395 * Process zephyrgrams from libzephyr's queue. To prevent starvation,
1396 * process a maximum of OWL_MAX_ZEPHYRGRAMS_TO_PROCESS.
1397 *
1398 * Returns the number of zephyrgrams processed.
1399 */
1400
1401#define OWL_MAX_ZEPHYRGRAMS_TO_PROCESS 20
1402
1403static int _owl_zephyr_process_events(void)
1404{
1405  int zpendcount=0;
1406#ifdef HAVE_LIBZEPHYR
1407  ZNotice_t notice;
1408  Code_t code;
1409  owl_message *m=NULL;
1410
1411  while(owl_zephyr_zpending() && zpendcount < OWL_MAX_ZEPHYRGRAMS_TO_PROCESS) {
1412    if (owl_zephyr_zpending()) {
1413      if ((code = ZReceiveNotice(&notice, NULL)) != ZERR_NONE) {
1414        owl_function_debugmsg("Error: %s while calling ZReceiveNotice\n",
1415                              error_message(code));
1416        continue;
1417      }
1418      zpendcount++;
1419
1420      /* is this an ack from a zephyr we sent? */
1421      if (owl_zephyr_notice_is_ack(&notice)) {
1422        owl_zephyr_handle_ack(&notice);
1423        ZFreeNotice(&notice);
1424        continue;
1425      }
1426
1427      /* if it's a ping and we're not viewing pings then skip it */
1428      if (!owl_global_is_rxping(&g) && !strcasecmp(notice.z_opcode, "ping")) {
1429        ZFreeNotice(&notice);
1430        continue;
1431      }
1432
1433      /* if it is a LOCATE message, it's for pseudologins. */
1434      if (strcmp(notice.z_opcode, LOCATE_LOCATE) == 0) {
1435        owl_zephyr_process_pseudologin(&notice);
1436        ZFreeNotice(&notice);
1437        continue;
1438      }
1439
1440      /* create the new message */
1441      m=owl_malloc(sizeof(owl_message));
1442      owl_message_create_from_znotice(m, &notice);
1443
1444      owl_global_messagequeue_addmsg(&g, m);
1445    }
1446  }
1447#endif
1448  return zpendcount;
1449}
1450
1451void owl_zephyr_process_events(const owl_io_dispatch *d, void *data)
1452{
1453  _owl_zephyr_process_events();
1454}
1455
1456int owl_zephyr_pre_select_action(owl_ps_action *a, void *p)
1457{
1458  return _owl_zephyr_process_events();
1459}
Note: See TracBrowser for help on using the repository browser.