source: zephyr.c @ 30ac47f

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