source: zephyr.c @ 86f740e

release-1.10release-1.7release-1.8release-1.9
Last change on this file since 86f740e was d40ad8b, checked in by David Benjamin <davidben@mit.edu>, 14 years ago
Punt OWL_WEBBROWSER_* and userclue That code hasn't been used for quite some time, and only one of those browsers is still in active development anyway.
  • Property mode set to 100644
File size: 36.5 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  ZSubscription_t subs[10];
356   
357  if (ZSubscribeTo(subs,0,0) != ZERR_NONE) {
358    owl_function_error("Error subscribing to default zephyr notifications.");
359    return(-1);
360  }
361  return(0);
362#else
363  return(0);
364#endif
365}
366
367int owl_zephyr_loadloginsubs(const char *filename)
368{
369#ifdef HAVE_LIBZEPHYR
370  FILE *file;
371  ZSubscription_t *subs;
372  int numSubs = 100;
373  char *subsfile;
374  char *buffer = NULL;
375  int count;
376  struct stat statbuff;
377
378  subs = owl_malloc(numSubs * sizeof(ZSubscription_t));
379  subsfile = owl_zephyr_dotfile(".anyone", filename);
380
381  if (stat(subsfile, &statbuff) == -1) {
382    owl_free(subsfile);
383    return 0;
384  }
385
386  ZResetAuthentication();
387  count = 0;
388  file = fopen(subsfile, "r");
389  owl_free(subsfile);
390  if (file) {
391    while (owl_getline_chomp(&buffer, file)) {
392      if (buffer[0] == '\0' || buffer[0] == '#')
393        continue;
394
395      if (count == numSubs) {
396        numSubs *= 2;
397        subs = owl_realloc(subs, numSubs * sizeof(ZSubscription_t));
398      }
399
400      subs[count].zsub_class = owl_strdup("login");
401      subs[count].zsub_recipient = owl_strdup("*");
402      subs[count].zsub_classinst = long_zuser(buffer);
403
404      count++;
405    }
406    fclose(file);
407  } else {
408    return 0;
409  }
410  if (buffer)
411    owl_free(buffer);
412
413  return owl_zephyr_loadsubs_helper(subs, count);
414#else
415  return 0;
416#endif
417}
418
419void unsuball(void)
420{
421#if HAVE_LIBZEPHYR
422  int ret;
423
424  ZResetAuthentication();
425  ret=ZCancelSubscriptions(0);
426  if (ret != ZERR_NONE) {
427    com_err("owl",ret,"while unsubscribing");
428  }
429#endif
430}
431
432int owl_zephyr_sub(const char *class, const char *inst, const char *recip)
433{
434#ifdef HAVE_LIBZEPHYR
435  ZSubscription_t subs[5];
436
437  subs[0].zsub_class=zstr(class);
438  subs[0].zsub_classinst=zstr(inst);
439  subs[0].zsub_recipient=zstr(recip);
440
441  ZResetAuthentication();
442  if (ZSubscribeTo(subs,1,0) != ZERR_NONE) {
443    owl_function_error("Error subbing to <%s,%s,%s>", class, inst, recip);
444    return(-2);
445  }
446  return(0);
447#else
448  return(0);
449#endif
450}
451
452
453int owl_zephyr_unsub(const char *class, const char *inst, const char *recip)
454{
455#ifdef HAVE_LIBZEPHYR
456  ZSubscription_t subs[5];
457
458  subs[0].zsub_class=zstr(class);
459  subs[0].zsub_classinst=zstr(inst);
460  subs[0].zsub_recipient=zstr(recip);
461
462  ZResetAuthentication();
463  if (ZUnsubscribeTo(subs,1,0) != ZERR_NONE) {
464    owl_function_error("Error unsubbing from <%s,%s,%s>", class, inst, recip);
465    return(-2);
466  }
467  return(0);
468#else
469  return(0);
470#endif
471}
472
473/* return a pointer to the data in the Jth field, (NULL terminated by
474 * definition).  Caller must free the return.
475 */
476#ifdef HAVE_LIBZEPHYR
477char *owl_zephyr_get_field(const ZNotice_t *n, int j)
478{
479  int i, count, save;
480  char *out;
481
482  /* If there's no message here, just run along now */
483  if (n->z_message_len == 0)
484    return(owl_strdup(""));
485
486  count=save=0;
487  for (i=0; i<n->z_message_len; i++) {
488    if (n->z_message[i]=='\0') {
489      count++;
490      if (count==j) {
491        /* just found the end of the field we're looking for */
492        return(owl_strdup(n->z_message+save));
493      } else {
494        save=i+1;
495      }
496    }
497  }
498  /* catch the last field, which might not be null terminated */
499  if (count==j-1) {
500    out=owl_malloc(n->z_message_len-save+5);
501    memcpy(out, n->z_message+save, n->z_message_len-save);
502    out[n->z_message_len-save]='\0';
503    return(out);
504  }
505
506  return(owl_strdup(""));
507}
508
509char *owl_zephyr_get_field_as_utf8(const ZNotice_t *n, int j)
510{
511  int i, count, save;
512
513  /* If there's no message here, just run along now */
514  if (n->z_message_len == 0)
515    return(owl_strdup(""));
516
517  count=save=0;
518  for (i = 0; i < n->z_message_len; i++) {
519    if (n->z_message[i]=='\0') {
520      count++;
521      if (count == j) {
522        /* just found the end of the field we're looking for */
523        return(owl_validate_or_convert(n->z_message + save));
524      } else {
525        save = i + 1;
526      }
527    }
528  }
529  /* catch the last field, which might not be null terminated */
530  if (count == j - 1) {
531    char *tmp, *out;
532    tmp = owl_malloc(n->z_message_len-save+5);
533    memcpy(tmp, n->z_message+save, n->z_message_len-save);
534    tmp[n->z_message_len-save]='\0';
535    out = owl_validate_or_convert(tmp);
536    owl_free(tmp);
537    return out;
538  }
539
540  return(owl_strdup(""));
541}
542#else
543char *owl_zephyr_get_field(void *n, int j)
544{
545  return(owl_strdup(""));
546}
547char *owl_zephyr_get_field_as_utf8(void *n, int j)
548{
549  return owl_zephyr_get_field(n, j);
550}
551#endif
552
553
554#ifdef HAVE_LIBZEPHYR
555int owl_zephyr_get_num_fields(const ZNotice_t *n)
556{
557  int i, fields;
558
559  if(n->z_message_len == 0)
560    return 0;
561
562  fields=1;
563  for (i=0; i<n->z_message_len; i++) {
564    if (n->z_message[i]=='\0') fields++;
565  }
566 
567  return(fields);
568}
569#else
570int owl_zephyr_get_num_fields(const void *n)
571{
572  return(0);
573}
574#endif
575
576#ifdef HAVE_LIBZEPHYR
577/* return a pointer to the message, place the message length in k
578 * caller must free the return
579 */
580char *owl_zephyr_get_message(const ZNotice_t *n, const owl_message *m)
581{
582  /* don't let ping messages have a body */
583  if (!strcasecmp(n->z_opcode, "ping")) {
584    return(owl_strdup(""));
585  }
586
587  /* deal with MIT NOC messages */
588  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")) {
589    char *msg, *field3, *field4;
590
591    field3 = owl_zephyr_get_field(n, 3);
592    field4 = owl_zephyr_get_field(n, 4);
593
594    msg = owl_sprintf("%s service on %s %s\n%s", n->z_opcode, n->z_class_inst, field3, field4);
595    owl_free(field3);
596    owl_free(field4);
597    if (msg) {
598      return msg;
599    }
600  }
601  /* deal with MIT Discuss messages */
602  else if (!strcasecmp(n->z_default_format, "New transaction [$1] entered in $2\nFrom: $3 ($5)\nSubject: $4") ||
603           !strcasecmp(n->z_default_format, "New transaction [$1] entered in $2\nFrom: $3\nSubject: $4")) {
604    char *msg, *field1, *field2, *field3, *field4, *field5;
605   
606    field1 = owl_zephyr_get_field(n, 1);
607    field2 = owl_zephyr_get_field(n, 2);
608    field3 = owl_zephyr_get_field(n, 3);
609    field4 = owl_zephyr_get_field(n, 4);
610    field5 = owl_zephyr_get_field(n, 5);
611   
612    msg = owl_sprintf("New transaction [%s] entered in %s\nFrom: %s (%s)\nSubject: %s", field1, field2, field3, field5, field4);
613    owl_free(field1);
614    owl_free(field2);
615    owl_free(field3);
616    owl_free(field4);
617    owl_free(field5);
618    if (msg) {
619      return msg;
620    }
621  }
622  /* deal with MIT Moira messages */
623  else if (!strcasecmp(n->z_default_format, "MOIRA $instance on $fromhost:\n $message\n")) {
624    char *msg, *field1;
625   
626    field1 = owl_zephyr_get_field(n, 1);
627   
628    msg = owl_sprintf("MOIRA %s on %s: %s", n->z_class_inst, owl_message_get_hostname(m), field1);
629    owl_free(field1);
630    if (msg) {
631      return msg;
632    }
633  }
634
635  if (owl_zephyr_get_num_fields(n) == 1) {
636    return(owl_zephyr_get_field(n, 1));
637  }
638  else {
639    return(owl_zephyr_get_field(n, 2));
640  }
641}
642#endif
643
644#ifdef HAVE_LIBZEPHYR
645const char *owl_zephyr_get_zsig(const ZNotice_t *n, int *k)
646{
647  /* return a pointer to the zsig if there is one */
648
649  /* message length 0? No zsig */
650  if (n->z_message_len==0) {
651    *k=0;
652    return("");
653  }
654
655  /* If there's only one field, no zsig */
656  if (owl_zephyr_get_num_fields(n) == 1) {
657    *k=0;
658    return("");
659  }
660
661  /* Everything else is field 1 */
662  *k=strlen(n->z_message);
663  return(n->z_message);
664}
665#else
666const char *owl_zephyr_get_zsig(const void *n, int *k)
667{
668  return("");
669}
670#endif
671
672int send_zephyr(const char *opcode, const char *zsig, const char *class, const char *instance, const char *recipient, const char *message)
673{
674#ifdef HAVE_LIBZEPHYR
675  int ret;
676  ZNotice_t notice;
677   
678  memset(&notice, 0, sizeof(notice));
679
680  ZResetAuthentication();
681
682  if (!zsig) zsig="";
683 
684  notice.z_kind=ACKED;
685  notice.z_port=0;
686  notice.z_class=zstr(class);
687  notice.z_class_inst=zstr(instance);
688  notice.z_sender=NULL;
689  if (!strcmp(recipient, "*") || !strcmp(recipient, "@")) {
690    notice.z_recipient=zstr("");
691    if (*owl_global_get_zsender(&g))
692        notice.z_sender=zstr(owl_global_get_zsender(&g));
693  } else {
694    notice.z_recipient=zstr(recipient);
695  }
696  notice.z_default_format=zstr("Class $class, Instance $instance:\nTo: @bold($recipient) at $time $date\nFrom: @bold{$1 <$sender>}\n\n$2");
697  if (opcode) notice.z_opcode=zstr(opcode);
698
699  notice.z_message_len=strlen(zsig)+1+strlen(message);
700  notice.z_message=owl_malloc(notice.z_message_len+10);
701  strcpy(notice.z_message, zsig);
702  memcpy(notice.z_message+strlen(zsig)+1, message, strlen(message));
703
704  /* ret=ZSendNotice(&notice, ZAUTH); */
705  ret=ZSrvSendNotice(&notice, ZAUTH, send_zephyr_helper);
706 
707  /* free then check the return */
708  owl_free(notice.z_message);
709  ZFreeNotice(&notice);
710  if (ret!=ZERR_NONE) {
711    owl_function_error("Error sending zephyr");
712    return(ret);
713  }
714  return(0);
715#else
716  return(0);
717#endif
718}
719
720#ifdef HAVE_LIBZEPHYR
721Code_t send_zephyr_helper(ZNotice_t *notice, char *buf, int len, int wait)
722{
723  return(ZSendPacket(buf, len, 0));
724}
725#endif
726
727void send_ping(const char *to, const char *zclass, const char *zinstance)
728{
729#ifdef HAVE_LIBZEPHYR
730  send_zephyr("PING", "", zclass, zinstance, to, "");
731#endif
732}
733
734#ifdef HAVE_LIBZEPHYR
735void owl_zephyr_handle_ack(const ZNotice_t *retnotice)
736{
737  char *tmp;
738 
739  /* if it's an HMACK ignore it */
740  if (retnotice->z_kind == HMACK) return;
741
742  if (retnotice->z_kind == SERVNAK) {
743    owl_function_error("Authorization failure sending zephyr");
744  } else if ((retnotice->z_kind != SERVACK) || !retnotice->z_message_len) {
745    owl_function_error("Detected server failure while receiving acknowledgement");
746  } else if (!strcmp(retnotice->z_message, ZSRVACK_SENT)) {
747    if (!strcasecmp(retnotice->z_opcode, "ping")) {
748      return;
749    } else {
750      if (strcasecmp(retnotice->z_recipient, ""))
751      { /* personal */
752        tmp=short_zuser(retnotice->z_recipient);
753        if(!strcasecmp(retnotice->z_class, "message") &&
754           !strcasecmp(retnotice->z_class_inst, "personal")) {
755          owl_function_makemsg("Message sent to %s.", tmp);
756        } else if(!strcasecmp(retnotice->z_class, "message")) { /* instanced, but not classed, personal */
757          owl_function_makemsg("Message sent to %s on -i %s\n", tmp, retnotice->z_class_inst);
758        } else { /* classed personal */
759          owl_function_makemsg("Message sent to %s on -c %s -i %s\n", tmp, retnotice->z_class, retnotice->z_class_inst);
760        }
761        owl_free(tmp);
762      } else {
763        /* class / instance message */
764          owl_function_makemsg("Message sent to -c %s -i %s\n", retnotice->z_class, retnotice->z_class_inst);
765      }
766    }
767  } else if (!strcmp(retnotice->z_message, ZSRVACK_NOTSENT)) {
768    #define BUFFLEN 1024
769    if (retnotice->z_recipient == NULL
770        || *retnotice->z_recipient == 0
771        || *retnotice->z_recipient == '@') {
772      char buff[BUFFLEN];
773      owl_function_error("No one subscribed to class %s", retnotice->z_class);
774      snprintf(buff, BUFFLEN, "Could not send message to class %s: no one subscribed.\n", retnotice->z_class);
775      owl_function_adminmsg("", buff);
776    } else {
777      char buff[BUFFLEN];
778      owl_zwrite zw;
779      char *realm;
780
781      tmp = short_zuser(retnotice->z_recipient);
782      owl_function_error("%s: Not logged in or subscribing.", tmp);
783      /*
784       * These error messages are often over 80 chars, but users who want to
785       * see the whole thing can scroll to the side, and for those with wide
786       * terminals or who don't care, not splitting saves a line in the UI
787       */
788      if(strcasecmp(retnotice->z_class, "message")) {
789        snprintf(buff, BUFFLEN,
790                 "Could not send message to %s: "
791                 "not logged in or subscribing to class %s, instance %s.\n",
792                 tmp,
793                 retnotice->z_class,
794                 retnotice->z_class_inst);
795      } else if(strcasecmp(retnotice->z_class_inst, "personal")) {
796        snprintf(buff, BUFFLEN,
797                 "Could not send message to %s: "
798                 "not logged in or subscribing to instance %s.\n",
799                 tmp,
800                 retnotice->z_class_inst);
801      } else {
802        snprintf(buff, BUFFLEN,
803                 "Could not send message to %s: "
804                 "not logged in or subscribing to messages.\n",
805                 tmp);
806      }
807      owl_function_adminmsg("", buff);
808
809      memset(&zw, 0, sizeof(zw));
810      zw.class = owl_strdup(retnotice->z_class);
811      zw.inst  = owl_strdup(retnotice->z_class_inst);
812      realm = strchr(retnotice->z_recipient, '@');
813      if(realm) {
814        zw.realm = owl_strdup(realm + 1);
815      } else {
816        zw.realm = owl_strdup(owl_zephyr_get_realm());
817      }
818      zw.opcode = owl_strdup(retnotice->z_opcode);
819      zw.zsig   = owl_strdup("");
820      owl_list_create(&(zw.recips));
821      owl_list_append_element(&(zw.recips), owl_strdup(tmp));
822
823      owl_log_outgoing_zephyr_error(&zw, buff);
824
825      owl_zwrite_cleanup(&zw);
826      owl_free(tmp);
827    }
828  } else {
829    owl_function_error("Internal error on ack (%s)", retnotice->z_message);
830  }
831}
832#else
833void owl_zephyr_handle_ack(const void *retnotice)
834{
835}
836#endif
837
838#ifdef HAVE_LIBZEPHYR
839int owl_zephyr_notice_is_ack(const ZNotice_t *n)
840{
841  if (n->z_kind == SERVNAK || n->z_kind == SERVACK || n->z_kind == HMACK) {
842    if (!strcasecmp(n->z_class, LOGIN_CLASS)) return(0);
843    return(1);
844  }
845  return(0);
846}
847#else
848int owl_zephyr_notice_is_ack(const void *n)
849{
850  return(0);
851}
852#endif
853 
854void owl_zephyr_zaway(const owl_message *m)
855{
856#ifdef HAVE_LIBZEPHYR
857  char *tmpbuff, *myuser, *to;
858  owl_message *mout;
859  owl_zwrite *z;
860 
861  /* bail if it doesn't look like a message we should reply to.  Some
862   * of this defined by the way zaway(1) works
863   */
864  if (strcasecmp(owl_message_get_class(m), "message")) return;
865  if (strcasecmp(owl_message_get_recipient(m), ZGetSender())) return;
866  if (!strcasecmp(owl_message_get_sender(m), "")) return;
867  if (!strcasecmp(owl_message_get_opcode(m), "ping")) return;
868  if (!strcasecmp(owl_message_get_opcode(m), "auto")) return;
869  if (!strcasecmp(owl_message_get_zsig(m), "Automated reply:")) return;
870  if (!strcasecmp(owl_message_get_sender(m), ZGetSender())) return;
871  if (owl_message_get_attribute_value(m, "isauto")) return;
872
873  if (owl_global_is_smartstrip(&g)) {
874    to=owl_zephyr_smartstripped_user(owl_message_get_sender(m));
875  } else {
876    to=owl_strdup(owl_message_get_sender(m));
877  }
878
879  send_zephyr("",
880              "Automated reply:",
881              owl_message_get_class(m),
882              owl_message_get_instance(m),
883              to,
884              owl_global_get_zaway_msg(&g));
885
886  myuser=short_zuser(to);
887  if (!strcasecmp(owl_message_get_instance(m), "personal")) {
888    tmpbuff = owl_sprintf("zwrite %s", myuser);
889  } else {
890    tmpbuff = owl_sprintf("zwrite -i %s %s", owl_message_get_instance(m), myuser);
891  }
892  owl_free(myuser);
893  owl_free(to);
894
895  z = owl_zwrite_new(tmpbuff);
896  owl_zwrite_set_message(z, owl_global_get_zaway_msg(&g));
897  owl_zwrite_set_zsig(z, "Automated reply:");
898
899  /* display the message as an admin message in the receive window */
900  mout=owl_function_make_outgoing_zephyr(z);
901  owl_global_messagequeue_addmsg(&g, mout);
902  owl_free(tmpbuff);
903  owl_zwrite_delete(z);
904#endif
905}
906
907#ifdef HAVE_LIBZEPHYR
908void owl_zephyr_hackaway_cr(ZNotice_t *n)
909{
910  /* replace \r's with ' '.  Gross-ish */
911  int i;
912
913  for (i=0; i<n->z_message_len; i++) {
914    if (n->z_message[i]=='\r') {
915      n->z_message[i]=' ';
916    }
917  }
918}
919#endif
920
921char *owl_zephyr_zlocate(const char *user, int auth)
922{
923#ifdef HAVE_LIBZEPHYR
924  int ret, numlocs;
925  int one = 1;
926  ZLocations_t locations;
927  char *myuser;
928  char *p, *result;
929
930  ZResetAuthentication();
931  ret = ZLocateUser(zstr(user), &numlocs, auth ? ZAUTH : ZNOAUTH);
932  if (ret != ZERR_NONE)
933    return owl_sprintf("Error locating user %s: %s\n",
934                       user, error_message(ret));
935
936  myuser = short_zuser(user);
937  if (numlocs == 0) {
938    result = owl_sprintf("%s: Hidden or not logged in\n", myuser);
939  } else {
940    result = owl_strdup("");
941    for (; numlocs; numlocs--) {
942      ZGetLocations(&locations, &one);
943      p = owl_sprintf("%s%s: %s\t%s\t%s\n",
944                          result, myuser,
945                          locations.host ? locations.host : "?",
946                          locations.tty ? locations.tty : "?",
947                          locations.time ? locations.time : "?");
948      owl_free(result);
949      result = p;
950    }
951  }
952
953  return result;
954#else
955  return owl_strdup("");
956#endif
957}
958
959void owl_zephyr_addsub(const char *filename, const char *class, const char *inst, const char *recip)
960{
961#ifdef HAVE_LIBZEPHYR
962  char *line, *subsfile, *s = NULL;
963  FILE *file;
964  int duplicate = 0;
965
966  line = owl_zephyr_makesubline(class, inst, recip);
967  subsfile = owl_zephyr_dotfile(".zephyr.subs", filename);
968
969  /* if the file already exists, check to see if the sub is already there */
970  file = fopen(subsfile, "r");
971  if (file) {
972    while (owl_getline(&s, file)) {
973      if (strcasecmp(s, line) == 0) {
974        owl_function_error("Subscription already present in %s", subsfile);
975        duplicate++;
976      }
977    }
978    fclose(file);
979    owl_free(s);
980  }
981
982  if (!duplicate) {
983    file = fopen(subsfile, "a");
984    if (file) {
985      fputs(line, file);
986      fclose(file);
987      owl_function_makemsg("Subscription added");
988    } else {
989      owl_function_error("Error opening file %s for writing", subsfile);
990    }
991  }
992
993  owl_free(line);
994#endif
995}
996
997void owl_zephyr_delsub(const char *filename, const char *class, const char *inst, const char *recip)
998{
999#ifdef HAVE_LIBZEPHYR
1000  char *line, *subsfile;
1001  int linesdeleted;
1002 
1003  line=owl_zephyr_makesubline(class, inst, recip);
1004  line[strlen(line)-1]='\0';
1005
1006  subsfile = owl_zephyr_dotfile(".zephyr.subs", filename);
1007 
1008  linesdeleted = owl_util_file_deleteline(subsfile, line, 1);
1009  if (linesdeleted > 0) {
1010    owl_function_makemsg("Subscription removed");
1011  } else {
1012    owl_function_error("No subscription present in %s", subsfile);
1013  }
1014  owl_free(subsfile);
1015  owl_free(line);
1016#endif
1017}
1018
1019/* caller must free the return */
1020char *owl_zephyr_makesubline(const char *class, const char *inst, const char *recip)
1021{
1022  return owl_sprintf("%s,%s,%s\n", class, inst, !strcmp(recip, "") ? "*" : recip);
1023}
1024
1025
1026void owl_zephyr_zlog_in(void)
1027{
1028#ifdef HAVE_LIBZEPHYR
1029  const char *exposure, *eset;
1030  int ret;
1031
1032  ZResetAuthentication();
1033   
1034  eset=EXPOSE_REALMVIS;
1035  exposure=ZGetVariable(zstr("exposure"));
1036  if (exposure==NULL) {
1037    eset=EXPOSE_REALMVIS;
1038  } else if (!strcasecmp(exposure,EXPOSE_NONE)) {
1039    eset = EXPOSE_NONE;
1040  } else if (!strcasecmp(exposure,EXPOSE_OPSTAFF)) {
1041    eset = EXPOSE_OPSTAFF;
1042  } else if (!strcasecmp(exposure,EXPOSE_REALMVIS)) {
1043    eset = EXPOSE_REALMVIS;
1044  } else if (!strcasecmp(exposure,EXPOSE_REALMANN)) {
1045    eset = EXPOSE_REALMANN;
1046  } else if (!strcasecmp(exposure,EXPOSE_NETVIS)) {
1047    eset = EXPOSE_NETVIS;
1048  } else if (!strcasecmp(exposure,EXPOSE_NETANN)) {
1049    eset = EXPOSE_NETANN;
1050  }
1051   
1052  ret=ZSetLocation(zstr(eset));
1053  if (ret != ZERR_NONE) {
1054    /*
1055      owl_function_makemsg("Error setting location: %s", error_message(ret));
1056    */
1057  }
1058#endif
1059}
1060
1061void owl_zephyr_zlog_out(void)
1062{
1063#ifdef HAVE_LIBZEPHYR
1064  int ret;
1065
1066  ZResetAuthentication();
1067  ret=ZUnsetLocation();
1068  if (ret != ZERR_NONE) {
1069    /*
1070      owl_function_makemsg("Error unsetting location: %s", error_message(ret));
1071    */
1072  }
1073#endif
1074}
1075
1076void owl_zephyr_addbuddy(const char *name)
1077{
1078  char *filename;
1079  FILE *file;
1080 
1081  filename = owl_zephyr_dotfile(".anyone", NULL);
1082  file = fopen(filename, "a");
1083  owl_free(filename);
1084  if (!file) {
1085    owl_function_error("Error opening zephyr buddy file for append");
1086    return;
1087  }
1088  fprintf(file, "%s\n", name);
1089  fclose(file);
1090}
1091
1092void owl_zephyr_delbuddy(const char *name)
1093{
1094  char *filename;
1095
1096  filename = owl_zephyr_dotfile(".anyone", NULL);
1097  owl_util_file_deleteline(filename, name, 0);
1098  owl_free(filename);
1099}
1100
1101/* return auth string */
1102#ifdef HAVE_LIBZEPHYR
1103const char *owl_zephyr_get_authstr(const ZNotice_t *n)
1104{
1105
1106  if (!n) return("UNKNOWN");
1107
1108  if (n->z_auth == ZAUTH_FAILED) {
1109    return ("FAILED");
1110  } else if (n->z_auth == ZAUTH_NO) {
1111    return ("NO");
1112  } else if (n->z_auth == ZAUTH_YES) {
1113    return ("YES");
1114  } else {
1115    return ("UNKNOWN");
1116  }           
1117}
1118#else
1119const char *owl_zephyr_get_authstr(const void *n)
1120{
1121  return("");
1122}
1123#endif
1124
1125/* Returns a buffer of subscriptions or an error message.  Caller must
1126 * free the return.
1127 */
1128char *owl_zephyr_getsubs(void)
1129{
1130#ifdef HAVE_LIBZEPHYR
1131  int ret, num, i, one;
1132  int buffsize;
1133  ZSubscription_t sub;
1134  char *out;
1135  one=1;
1136
1137  ret=ZRetrieveSubscriptions(0, &num);
1138  if (ret==ZERR_TOOMANYSUBS) {
1139    return(owl_strdup("Zephyr: too many subscriptions\n"));
1140  } else if (ret || (num <= 0)) {
1141    return(owl_strdup("Zephyr: error retriving subscriptions\n"));
1142  }
1143
1144  buffsize = (num + 1) * 50;
1145  out=owl_malloc(buffsize);
1146  strcpy(out, "");
1147  for (i=0; i<num; i++) {
1148    if ((ret = ZGetSubscriptions(&sub, &one)) != ZERR_NONE) {
1149      owl_free(out);
1150      ZFlushSubscriptions();
1151      out=owl_strdup("Error while getting subscriptions\n");
1152      return(out);
1153    } else {
1154      int tmpbufflen;
1155      char *tmpbuff;
1156      tmpbuff = owl_sprintf("<%s,%s,%s>\n%s", sub.zsub_class, sub.zsub_classinst, sub.zsub_recipient, out);
1157      tmpbufflen = strlen(tmpbuff) + 1;
1158      if (tmpbufflen > buffsize) {
1159        char *out2;
1160        buffsize = tmpbufflen * 2;
1161        out2 = owl_realloc(out, buffsize);
1162        if (out2 == NULL) {
1163          owl_free(out);
1164          owl_free(tmpbuff);
1165          ZFlushSubscriptions();
1166          out=owl_strdup("Realloc error while getting subscriptions\n");
1167          return(out);   
1168        }
1169        out = out2;
1170      }
1171      strcpy(out, tmpbuff);
1172      owl_free(tmpbuff);
1173    }
1174  }
1175
1176  ZFlushSubscriptions();
1177  return(out);
1178#else
1179  return(owl_strdup("Zephyr not available"));
1180#endif
1181}
1182
1183const char *owl_zephyr_get_variable(const char *var)
1184{
1185#ifdef HAVE_LIBZEPHYR
1186  return(ZGetVariable(zstr(var)));
1187#else
1188  return("");
1189#endif
1190}
1191
1192void owl_zephyr_set_locationinfo(const char *host, const char *val)
1193{
1194#ifdef HAVE_LIBZEPHYR
1195  ZInitLocationInfo(zstr(host), zstr(val));
1196#endif
1197}
1198 
1199/* Strip a local realm fron the zephyr user name.
1200 * The caller must free the return
1201 */
1202char *short_zuser(const char *in)
1203{
1204  char *out, *ptr;
1205
1206  out=owl_strdup(in);
1207  ptr=strchr(out, '@');
1208  if (ptr) {
1209    if (!strcasecmp(ptr+1, owl_zephyr_get_realm())) {
1210      *ptr='\0';
1211    }
1212  }
1213  return(out);
1214}
1215
1216/* Append a local realm to the zephyr user name if necessary.
1217 * The caller must free the return.
1218 */
1219char *long_zuser(const char *in)
1220{
1221  if (strchr(in, '@')) {
1222    return(owl_strdup(in));
1223  }
1224  return(owl_sprintf("%s@%s", in, owl_zephyr_get_realm()));
1225}
1226
1227/* strip out the instance from a zsender's principal.  Preserves the
1228 * realm if present.  daemon.webzephyr is a special case.  The
1229 * caller must free the return
1230 */
1231char *owl_zephyr_smartstripped_user(const char *in)
1232{
1233  char *ptr, *realm, *out;
1234
1235  out=owl_strdup(in);
1236
1237  /* bail immeaditly if we don't have to do any work */
1238  ptr=strchr(out, '.');
1239  if (!strchr(out, '/') && !ptr) {
1240    /* no '/' and no '.' */
1241    return(out);
1242  }
1243  if (ptr && strchr(out, '@') && (ptr > strchr(out, '@'))) {
1244    /* There's a '.' but it's in the realm */
1245    return(out);
1246  }
1247  if (!strncasecmp(out, OWL_WEBZEPHYR_PRINCIPAL, strlen(OWL_WEBZEPHYR_PRINCIPAL))) {
1248    return(out);
1249  }
1250
1251  /* remove the realm from out, but hold on to it */
1252  realm=strchr(out, '@');
1253  if (realm) realm[0]='\0';
1254
1255  /* strip */
1256  ptr=strchr(out, '.');
1257  if (!ptr) ptr=strchr(out, '/');
1258  ptr[0]='\0';
1259
1260  /* reattach the realm if we had one */
1261  if (realm) {
1262    strcat(out, "@");
1263    strcat(out, realm+1);
1264  }
1265
1266  return(out);
1267}
1268
1269/* read the list of users in 'filename' as a .anyone file, and put the
1270 * names of the zephyr users in the list 'in'.  If 'filename' is NULL,
1271 * use the default .anyone file in the users home directory.  Returns
1272 * -1 on failure, 0 on success.
1273 */
1274int owl_zephyr_get_anyone_list(owl_list *in, const char *filename)
1275{
1276#ifdef HAVE_LIBZEPHYR
1277  char *ourfile, *tmp, *s = NULL;
1278  FILE *f;
1279
1280  ourfile = owl_zephyr_dotfile(".anyone", filename);
1281
1282  f = fopen(ourfile, "r");
1283  if (!f) {
1284    owl_function_error("Error opening file %s: %s", ourfile, strerror(errno) ? strerror(errno) : "");
1285    owl_free(ourfile);
1286    return -1;
1287  }
1288  owl_free(ourfile);
1289
1290  while (owl_getline_chomp(&s, f)) {
1291    /* ignore comments, blank lines etc. */
1292    if (s[0] == '#' || s[0] == '\0')
1293      continue;
1294
1295    /* ignore from # on */
1296    tmp = strchr(s, '#');
1297    if (tmp)
1298      tmp[0] = '\0';
1299
1300    /* ignore from SPC */
1301    tmp = strchr(s, ' ');
1302    if (tmp)
1303      tmp[0] = '\0';
1304
1305    owl_list_append_element(in, long_zuser(s));
1306  }
1307  owl_free(s);
1308  fclose(f);
1309  return 0;
1310#else
1311  return -1;
1312#endif
1313}
1314
1315#ifdef HAVE_LIBZEPHYR
1316void owl_zephyr_process_pseudologin(ZNotice_t *n)
1317{
1318  owl_message *m;
1319  owl_zbuddylist *zbl;
1320  GList **zaldlist;
1321  GList *zaldptr;
1322  ZAsyncLocateData_t *zald = NULL;
1323  ZLocations_t location;
1324  int numlocs, ret, notify;
1325
1326  /* Find a ZALD to match this notice. */
1327  zaldlist = owl_global_get_zaldlist(&g);
1328  zaldptr = g_list_first(*zaldlist);
1329  while (zaldptr) {
1330    if (ZCompareALDPred(n, zaldptr->data)) {
1331      zald = zaldptr->data;
1332      *zaldlist = g_list_remove(*zaldlist, zaldptr->data);
1333      break;
1334    }
1335    zaldptr = g_list_next(zaldptr);
1336  }
1337  if (zald) {
1338    /* Deal with notice. */
1339    notify = owl_global_get_pseudologin_notify(&g);
1340    zbl = owl_global_get_zephyr_buddylist(&g);
1341    ret = ZParseLocations(n, zald, &numlocs, NULL);
1342    if (ret == ZERR_NONE) {
1343      if (numlocs > 0 && !owl_zbuddylist_contains_user(zbl, zald->user)) {
1344        if (notify) {
1345          numlocs = 1;
1346          ret = ZGetLocations(&location, &numlocs);
1347          if (ret == ZERR_NONE) {
1348            /* Send a PSEUDO LOGIN! */
1349            m = owl_malloc(sizeof(owl_message));
1350            owl_message_create_pseudo_zlogin(m, 0, zald->user,
1351                                             location.host,
1352                                             location.time,
1353                                             location.tty);
1354            owl_global_messagequeue_addmsg(&g, m);
1355          }
1356          owl_zbuddylist_adduser(zbl, zald->user);
1357          owl_function_debugmsg("owl_function_zephyr_buddy_check: login for %s ", zald->user);
1358        }
1359      } else if (numlocs == 0 && owl_zbuddylist_contains_user(zbl, zald->user)) {
1360        /* Send a PSEUDO LOGOUT! */
1361        if (notify) {
1362          m = owl_malloc(sizeof(owl_message));
1363          owl_message_create_pseudo_zlogin(m, 1, zald->user, "", "", "");
1364          owl_global_messagequeue_addmsg(&g, m);
1365        }
1366        owl_zbuddylist_deluser(zbl, zald->user);
1367        owl_function_debugmsg("owl_function_zephyr_buddy_check: logout for %s ", zald->user);
1368      }
1369    }
1370    ZFreeALD(zald);
1371    owl_free(zald);
1372  }
1373}
1374#else
1375void owl_zephyr_process_pseudologin(void *n)
1376{
1377}
1378#endif
1379
1380void owl_zephyr_buddycheck_timer(owl_timer *t, void *data)
1381{
1382  if (owl_global_is_pseudologins(&g)) {
1383    owl_function_debugmsg("Doing zephyr buddy check");
1384    owl_function_zephyr_buddy_check(1);
1385  } else {
1386    owl_function_debugmsg("Warning: owl_zephyr_buddycheck_timer call pointless; timer should have been disabled");
1387  }
1388}
1389
1390/*
1391 * Process zephyrgrams from libzephyr's queue. To prevent starvation,
1392 * process a maximum of OWL_MAX_ZEPHYRGRAMS_TO_PROCESS.
1393 *
1394 * Returns the number of zephyrgrams processed.
1395 */
1396
1397#define OWL_MAX_ZEPHYRGRAMS_TO_PROCESS 20
1398
1399static int _owl_zephyr_process_events(void)
1400{
1401  int zpendcount=0;
1402#ifdef HAVE_LIBZEPHYR
1403  ZNotice_t notice;
1404  Code_t code;
1405  owl_message *m=NULL;
1406
1407  while(owl_zephyr_zpending() && zpendcount < OWL_MAX_ZEPHYRGRAMS_TO_PROCESS) {
1408    if (owl_zephyr_zpending()) {
1409      if ((code = ZReceiveNotice(&notice, NULL)) != ZERR_NONE) {
1410        owl_function_debugmsg("Error: %s while calling ZReceiveNotice\n",
1411                              error_message(code));
1412        continue;
1413      }
1414      zpendcount++;
1415
1416      /* is this an ack from a zephyr we sent? */
1417      if (owl_zephyr_notice_is_ack(&notice)) {
1418        owl_zephyr_handle_ack(&notice);
1419        ZFreeNotice(&notice);
1420        continue;
1421      }
1422
1423      /* if it's a ping and we're not viewing pings then skip it */
1424      if (!owl_global_is_rxping(&g) && !strcasecmp(notice.z_opcode, "ping")) {
1425        ZFreeNotice(&notice);
1426        continue;
1427      }
1428
1429      /* if it is a LOCATE message, it's for pseudologins. */
1430      if (strcmp(notice.z_opcode, LOCATE_LOCATE) == 0) {
1431        owl_zephyr_process_pseudologin(&notice);
1432        ZFreeNotice(&notice);
1433        continue;
1434      }
1435
1436      /* create the new message */
1437      m=owl_malloc(sizeof(owl_message));
1438      owl_message_create_from_znotice(m, &notice);
1439
1440      owl_global_messagequeue_addmsg(&g, m);
1441    }
1442  }
1443#endif
1444  return zpendcount;
1445}
1446
1447void owl_zephyr_process_events(const owl_io_dispatch *d, void *data)
1448{
1449  _owl_zephyr_process_events();
1450}
1451
1452int owl_zephyr_pre_select_action(owl_ps_action *a, void *p)
1453{
1454  return _owl_zephyr_process_events();
1455}
Note: See TracBrowser for help on using the repository browser.