source: zephyr.c @ 03955f3

barnowl_perlaimdebianowlrelease-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 03955f3 was 03955f3, checked in by James M. Kretchmar <kretch@mit.edu>, 18 years ago
Fixed a few glitches introduced in the new build
  • Property mode set to 100644
File size: 17.2 KB
RevLine 
[7d4fbcd]1#include <stdlib.h>
2#include <unistd.h>
3#include <sys/types.h>
4#include <sys/wait.h>
5#include <string.h>
6#include <com_err.h>
7#include "owl.h"
8
[1aee7d9]9static const char fileIdent[] = "$Id$";
10
[09489b89]11#ifdef HAVE_LIBZEPHYR
[8262340]12Code_t ZResetAuthentication();
[09489b89]13#endif
[8262340]14
[be0a79f]15int owl_zephyr_initialize()
16{
[09489b89]17#ifdef HAVE_LIBZEPHYR
[be0a79f]18  int ret;
19 
20  if ((ret = ZInitialize()) != ZERR_NONE) {
21    com_err("owl",ret,"while initializing");
22    return(1);
23  }
24  if ((ret = ZOpenPort(NULL)) != ZERR_NONE) {
25    com_err("owl",ret,"while opening port");
26    return(1);
27  }
[09489b89]28#endif
29  return(0);
30}
31
32
33int owl_zephyr_shutdown()
34{
35#ifdef HAVE_LIBZEPHYR
36  unsuball();
37  ZClosePort();
38#endif
[be0a79f]39  return(0);
40}
41
42int owl_zephyr_zpending()
43{
44#ifdef HAVE_LIBZEPHYR
45  return(ZPending());
46#else
47  return(0);
48#endif
49}
50
[09489b89]51char *owl_zephyr_get_realm()
52{
53#ifdef HAVE_LIBZEPHYR
54  return(ZGetRealm());
55#else
56  return("");
57#endif
58}
59
60char *owl_zephyr_get_sender()
61{
62#ifdef HAVE_LIBZEPHYR
63  return(ZGetSender());
64#else
65  return("");
66#endif
67}
68
[31e48a3]69int owl_zephyr_loadsubs(char *filename)
70{
[be0a79f]71#ifdef HAVE_LIBZEPHYR
[7d4fbcd]72  /* return 0  on success
73   *        -1 on file error
74   *        -2 on subscription error
75   */
76  FILE *file;
77  char *tmp, *start;
78  char buffer[1024], subsfile[1024];
79  ZSubscription_t subs[3001];
80  int count, ret, i;
81
82  ret=0;
83 
84  if (filename==NULL) {
85    sprintf(subsfile, "%s/%s", owl_global_get_homedir(&g), ".zephyr.subs");
86  } else {
87    strcpy(subsfile, filename);
88  }
[8262340]89
90  ZResetAuthentication();
[7d4fbcd]91  /* need to redo this to do chunks, not just bail after 3000 */
92  count=0;
93  file=fopen(subsfile, "r");
94  if (file) {
95    while ( fgets(buffer, 1024, file)!=NULL ) {
96      if (buffer[0]=='#' || buffer[0]=='\n' || buffer[0]=='\n') continue;
97
98      if (buffer[0]=='-') {
99        start=buffer+1;
100      } else {
101        start=buffer;
102      }
103     
104      if (count >= 3000) break; /* also tell the user */
105
106      /* add it to the list of subs */
107      if ((tmp=(char *) strtok(start, ",\n\r"))==NULL) continue;
108      subs[count].zsub_class=owl_strdup(tmp);
109      if ((tmp=(char *) strtok(NULL, ",\n\r"))==NULL) continue;
110      subs[count].zsub_classinst=owl_strdup(tmp);
111      if ((tmp=(char *) strtok(NULL, " \t\n\r"))==NULL) continue;
112      subs[count].zsub_recipient=owl_strdup(tmp);
113
114      /* if it started with '-' then add it to the global punt list */
115      if (buffer[0]=='-') {
116        owl_function_zpunt(subs[count].zsub_class, subs[count].zsub_classinst, subs[count].zsub_recipient, 0);
117      }
118     
119      count++;
120    }
121    fclose(file);
122  } else {
123    count=0;
124    ret=-1;
125  }
126
127  /* sub with defaults */
128  if (ZSubscribeTo(subs,count,0) != ZERR_NONE) {
129    fprintf(stderr, "Error subbing\n");
130    ret=-2;
131  }
132
133  /* free stuff */
134  for (i=0; i<count; i++) {
135    owl_free(subs[i].zsub_class);
136    owl_free(subs[i].zsub_classinst);
137    owl_free(subs[i].zsub_recipient);
138  }
139
140  return(ret);
[be0a79f]141#else
142  return(0);
143#endif
[7d4fbcd]144}
145
[31e48a3]146int owl_zephyr_loadloginsubs(char *filename)
147{
[be0a79f]148#ifdef HAVE_LIBZEPHYR
[7d4fbcd]149  FILE *file;
150  ZSubscription_t subs[3001];
151  char subsfile[1024], buffer[1024];
152  int count, ret, i;
153
154  ret=0;
155
156  if (filename==NULL) {
157    sprintf(subsfile, "%s/%s", owl_global_get_homedir(&g), ".anyone");
158  } else {
159    strcpy(subsfile, filename);
160  }
161
[8262340]162  ZResetAuthentication();
[7d4fbcd]163  /* need to redo this to do chunks, not just bag out after 3000 */
164  count=0;
165  file=fopen(subsfile, "r");
166  if (file) {
167    while ( fgets(buffer, 1024, file)!=NULL ) {
168      if (buffer[0]=='#' || buffer[0]=='\n' || buffer[0]=='\n') continue;
169     
170      if (count >= 3000) break; /* also tell the user */
171
172      buffer[strlen(buffer)-1]='\0';
173      subs[count].zsub_class="login";
174      subs[count].zsub_recipient="*";
175      if (strchr(buffer, '@')) {
176        subs[count].zsub_classinst=owl_strdup(buffer);
177      } else {
[1c6c4d3]178        subs[count].zsub_classinst=owl_sprintf("%s@%s", buffer, ZGetRealm());
[7d4fbcd]179      }
180
181      count++;
182    }
183    fclose(file);
184  } else {
185    count=0;
186    ret=-1;
187  }
188
189  /* sub with defaults */
[7933748]190  if (ZSubscribeToSansDefaults(subs,count,0) != ZERR_NONE) {
[7d4fbcd]191    fprintf(stderr, "Error subbing\n");
192    ret=-2;
193  }
194
195  /* free stuff */
196  for (i=0; i<count; i++) {
197    owl_free(subs[i].zsub_classinst);
198  }
199
200  return(ret);
[be0a79f]201#else
202  return(0);
203#endif
[7d4fbcd]204}
205
[31e48a3]206void unsuball()
207{
[be0a79f]208#if HAVE_LIBZEPHYR
[7d4fbcd]209  int ret;
[8262340]210
211  ZResetAuthentication();
[7d4fbcd]212  ret=ZCancelSubscriptions(0);
213  if (ret != ZERR_NONE) {
214    com_err("owl",ret,"while unsubscribing");
215  }
[be0a79f]216#endif
[7d4fbcd]217}
218
[31e48a3]219int owl_zephyr_sub(char *class, char *inst, char *recip)
220{
[be0a79f]221#ifdef HAVE_LIBZEPHYR
[7d4fbcd]222  ZSubscription_t subs[5];
223  int ret;
224
225  subs[0].zsub_class=class;
226  subs[0].zsub_classinst=inst;
227  subs[0].zsub_recipient=recip;
228
[8262340]229  ZResetAuthentication();
[7d4fbcd]230  if (ZSubscribeTo(subs,1,0) != ZERR_NONE) {
231    fprintf(stderr, "Error subbing\n");
232    ret=-2;
233  }
234  return(0);
[be0a79f]235#else
236  return(0);
237#endif
[7d4fbcd]238}
239
240
[31e48a3]241int owl_zephyr_unsub(char *class, char *inst, char *recip)
242{
[be0a79f]243#ifdef HAVE_LIBZEPHYR
[7d4fbcd]244  ZSubscription_t subs[5];
245  int ret;
246
247  subs[0].zsub_class=class;
248  subs[0].zsub_classinst=inst;
249  subs[0].zsub_recipient=recip;
250
[8262340]251  ZResetAuthentication();
[7d4fbcd]252  if (ZUnsubscribeTo(subs,1,0) != ZERR_NONE) {
253    fprintf(stderr, "Error unsubbing\n");
254    ret=-2;
255  }
256  return(0);
[be0a79f]257#else
258  return(0);
259#endif
[7d4fbcd]260}
261
[be0a79f]262#ifdef HAVE_LIBZEPHYR
[31e48a3]263char *owl_zephyr_get_field(ZNotice_t *n, int j, int *k)
264{
[7d4fbcd]265  /* return a pointer to the Jth field, place the length in k.  If the
266     field doesn't exist return an emtpy string */
267  int i, count, save;
268
269  count=save=0;
270  for (i=0; i<n->z_message_len; i++) {
271    if (n->z_message[i]=='\0') {
272      count++;
273      if (count==j) {
274        /* just found the end of the field we're looking for */
275        *k=i-save;
276        return(n->z_message+save);
277      } else {
278        save=i+1;
279      }
280    }
281  }
282  /* catch the last field */
283  if (count==j-1) {
284    *k=n->z_message_len-save;
285    return(n->z_message+save);
286  }
287 
288  *k=0;
289  return("");
290}
[09489b89]291#else
292char *owl_zephyr_get_field(void *n, int j, int *k)
293{
294  return("");
295}
[be0a79f]296#endif
[7d4fbcd]297
[be0a79f]298#ifdef HAVE_LIBZEPHYR
[31e48a3]299int owl_zephyr_get_num_fields(ZNotice_t *n)
300{
[7d4fbcd]301  int i, fields;
302
303  fields=1;
304  for (i=0; i<n->z_message_len; i++) {
305    if (n->z_message[i]=='\0') fields++;
306  }
307 
308  return(fields);
309}
[09489b89]310#else
311int owl_zephyr_get_num_fields(void *n)
312{
313  return(0);
314}
[be0a79f]315#endif
[7d4fbcd]316
[be0a79f]317#ifdef HAVE_LIBZEPHYR
[31e48a3]318char *owl_zephyr_get_message(ZNotice_t *n, int *k)
319{
[7d4fbcd]320  /* return a pointer to the message, place the message length in k */
321  if (!strcasecmp(n->z_opcode, "ping")) {
322    *k=0;
323    return("");
324  }
325
326  return(owl_zephyr_get_field(n, 2, k));
327}
[be0a79f]328#endif
[7d4fbcd]329
[be0a79f]330#ifdef HAVE_LIBZEPHYR
[31e48a3]331char *owl_zephyr_get_zsig(ZNotice_t *n, int *k)
332{
[7d4fbcd]333  /* return a pointer to the zsig if there is one */
334
335  if (n->z_message_len==0) {
336    *k=0;
337    return("");
338  }
339  *k=strlen(n->z_message);
340  return(n->z_message);
341}
[09489b89]342#else
343char *owl_zephyr_get_zsig(void *n, int *k)
344{
345  return("");
346}
[be0a79f]347#endif
[7d4fbcd]348
[31e48a3]349int send_zephyr(char *opcode, char *zsig, char *class, char *instance, char *recipient, char *message)
350{
[be0a79f]351#ifdef HAVE_LIBZEPHYR
[7d4fbcd]352  int ret;
353  ZNotice_t notice;
354   
355  memset(&notice, 0, sizeof(notice));
356
[8262340]357  ZResetAuthentication();
358 
[7d4fbcd]359  notice.z_kind=ACKED;
360  notice.z_port=0;
361  notice.z_class=class;
362  notice.z_class_inst=instance;
363  if (!strcmp(recipient, "*") || !strcmp(recipient, "@")) {
364    notice.z_recipient="";
365  } else {
366    notice.z_recipient=recipient;
367  }
368  notice.z_default_format="Class $class, Instance $instance:\nTo: @bold($recipient) at $time $date\nFrom: @bold{$1 <$sender>}\n\n$2";
369  notice.z_sender=NULL;
370  if (opcode) notice.z_opcode=opcode;
371
[56330ff]372  notice.z_message_len=strlen(zsig)+1+strlen(message);
[7d4fbcd]373  notice.z_message=owl_malloc(notice.z_message_len+10);
[56330ff]374  strcpy(notice.z_message, zsig);
375  memcpy(notice.z_message+strlen(zsig)+1, message, strlen(message));
[7d4fbcd]376
377  /* ret=ZSendNotice(&notice, ZAUTH); */
378  ret=ZSrvSendNotice(&notice, ZAUTH, send_zephyr_helper);
379 
380  /* free then check the return */
381  owl_free(notice.z_message);
382  ZFreeNotice(&notice);
383  if (ret!=ZERR_NONE) {
384    owl_function_makemsg("Error sending zephyr");
385    return(ret);
386  }
387  return(0);
[be0a79f]388#else
389  return(0);
390#endif
[7d4fbcd]391}
392
[be0a79f]393#ifdef HAVE_LIBZEPHYR
[31e48a3]394Code_t send_zephyr_helper(ZNotice_t *notice, char *buf, int len, int wait)
395{
[7d4fbcd]396  return(ZSendPacket(buf, len, 0));
397}
[be0a79f]398#endif
[7d4fbcd]399
[31e48a3]400void send_ping(char *to)
401{
[be0a79f]402#ifdef HAVE_LIBZEPHYR
[7d4fbcd]403  send_zephyr("PING", "", "MESSAGE", "PERSONAL", to, "");
[be0a79f]404#endif
[7d4fbcd]405}
406
[be0a79f]407#ifdef HAVE_LIBZEPHYR
[31e48a3]408void owl_zephyr_handle_ack(ZNotice_t *retnotice)
409{
[7d4fbcd]410  char *tmp;
411 
412  /* if it's an HMACK ignore it */
413  if (retnotice->z_kind == HMACK) return;
[aecf3e6]414
[7d4fbcd]415  if (retnotice->z_kind == SERVNAK) {
416    owl_function_makemsg("Authorization failure sending zephyr");
417  } else if ((retnotice->z_kind != SERVACK) || !retnotice->z_message_len) {
418    owl_function_makemsg("Detected server failure while receiving acknowledgement");
419  } else if (!strcmp(retnotice->z_message, ZSRVACK_SENT)) {
420    if (!strcasecmp(retnotice->z_opcode, "ping")) {
421      return;
422    } else if (!strcasecmp(retnotice->z_class, "message") &&
423               !strcasecmp(retnotice->z_class_inst, "personal")) {
[4b464a4]424      tmp=short_zuser(retnotice->z_recipient);
[1c6c4d3]425      owl_function_makemsg("Message sent to %s.", tmp);
[7d4fbcd]426      free(tmp);
427    } else {
[1c6c4d3]428      owl_function_makemsg("Message sent to -c %s -i %s\n", retnotice->z_class, retnotice->z_class_inst);
[7d4fbcd]429    }
430  } else if (!strcmp(retnotice->z_message, ZSRVACK_NOTSENT)) {
431    if (strcasecmp(retnotice->z_class, "message")) {
[1c6c4d3]432      owl_function_makemsg("Not logged in or not subscribing to class %s, instance %s",
[aecf3e6]433                           retnotice->z_class, retnotice->z_class_inst);
[7d4fbcd]434    } else {
[4b464a4]435      tmp = short_zuser(retnotice->z_recipient);
[1c6c4d3]436      owl_function_makemsg("%s: Not logged in or subscribing to messages.", 
437                           tmp);
438      owl_free(tmp);
[7d4fbcd]439    }
440  } else {
[1c6c4d3]441    owl_function_makemsg("Internal error on ack (%s)", retnotice->z_message);
[7d4fbcd]442  }
443}
[09489b89]444#else
445void owl_zephyr_handle_ack(void *retnotice)
446{
447}
[be0a79f]448#endif
[7d4fbcd]449
[be0a79f]450#ifdef HAVE_LIBZEPHYR
[31e48a3]451int owl_zephyr_notice_is_ack(ZNotice_t *n)
452{
[7d4fbcd]453  if (n->z_kind == SERVNAK || n->z_kind == SERVACK || n->z_kind == HMACK) {
454    if (!strcasecmp(n->z_class, LOGIN_CLASS)) return(0);
455    return(1);
456  }
457  return(0);
458}
[09489b89]459#else
460int owl_zephyr_notice_is_ack(void *n)
461{
462  return(0);
463}
[be0a79f]464#endif
[7d4fbcd]465 
[31e48a3]466void owl_zephyr_zaway(owl_message *m)
467{
[be0a79f]468#ifdef HAVE_LIBZEPHYR
[7c8060d0]469  char *tmpbuff, *myuser, *to;
[7d4fbcd]470 
[aa2f6364]471  /* bail if it doesn't look like a message we should reply to.  Some
472     of this defined by the way zaway(1) works */
[7d4fbcd]473  if (strcasecmp(owl_message_get_class(m), "message")) return;
474  if (strcasecmp(owl_message_get_recipient(m), ZGetSender())) return;
475  if (!strcasecmp(owl_message_get_sender(m), "")) return;
476  if (!strcasecmp(owl_message_get_opcode(m), "ping")) return;
477  if (!strcasecmp(owl_message_get_opcode(m), "auto")) return;
[d023c25]478  if (!strcasecmp(owl_message_get_zsig(m), "Automated reply:")) return;
[7d4fbcd]479  if (!strcasecmp(owl_message_get_sender(m), ZGetSender())) return;
480
[7c8060d0]481  if (owl_global_is_smartstrip(&g)) {
482    to=owl_util_smartstripped_user(owl_message_get_sender(m));
483  } else {
484    to=owl_strdup(owl_message_get_sender(m));
485  }
486
[7d4fbcd]487  send_zephyr("",
488              "Automated reply:",
489              owl_message_get_class(m),
490              owl_message_get_instance(m),
[7c8060d0]491              to,
[7d4fbcd]492              owl_global_get_zaway_msg(&g));
493
[7c8060d0]494  myuser=short_zuser(to);
[aa2f6364]495  if (!strcasecmp(owl_message_get_instance(m), "personal")) {
496    tmpbuff = owl_sprintf("zwrite %s", myuser);
497  } else {
498    tmpbuff = owl_sprintf("zwrite -i %s %s", owl_message_get_instance(m), myuser);
499  }
500  owl_free(myuser);
[7c8060d0]501  owl_free(to);
[aa2f6364]502
[7d4fbcd]503  /* display the message as an admin message in the receive window */
[d023c25]504  owl_function_make_outgoing_zephyr(owl_global_get_zaway_msg(&g), tmpbuff, "Automated reply:");
[7d4fbcd]505  owl_free(tmpbuff);
[be0a79f]506#endif
[7d4fbcd]507}
508
[be0a79f]509#ifdef HAVE_LIBZEPHYR
[31e48a3]510void owl_zephyr_hackaway_cr(ZNotice_t *n)
511{
[7d4fbcd]512  /* replace \r's with ' '.  Gross-ish */
513  int i;
514
515  for (i=0; i<n->z_message_len; i++) {
516    if (n->z_message[i]=='\r') {
517      n->z_message[i]=' ';
518    }
519  }
520}
[be0a79f]521#endif
[7d4fbcd]522
[31e48a3]523void owl_zephyr_zlocate(char *user, char *out, int auth)
524{
[be0a79f]525#ifdef HAVE_LIBZEPHYR
[7d4fbcd]526  int ret, numlocs;
527  int one = 1;
528  ZLocations_t locations;
529  char *myuser;
530 
531  strcpy(out, "");
[8262340]532  ZResetAuthentication();
[7d4fbcd]533  ret=ZLocateUser(user,&numlocs,auth?ZAUTH:ZNOAUTH);
534  if (ret != ZERR_NONE) {
535    owl_function_makemsg("Error locating user");
536  }
537
538  if (numlocs==0) {
[2527615]539    myuser=short_zuser(user);
540    sprintf(out, "%s: Hidden or not logged-in\n", myuser);
541    owl_free(myuser);
[7d4fbcd]542    return;
543  }
544   
545  for (;numlocs;numlocs--) {
546    ZGetLocations(&locations,&one);
[4b464a4]547    myuser=short_zuser(user);
[7d4fbcd]548    sprintf(out, "%s%s: %s\t%s\t%s\n", out, myuser, locations.host, locations.tty, locations.time);
549    owl_free(myuser);
550  }
[be0a79f]551#endif
[7d4fbcd]552}
[bde7714]553
[31e48a3]554void owl_zephyr_addsub(char *filename, char *class, char *inst, char *recip)
555{
[be0a79f]556#ifdef HAVE_LIBZEPHYR
[bde7714]557  char *line, subsfile[LINE], buff[LINE];
558  FILE *file;
559
560  line=owl_zephyr_makesubline(class, inst, recip);
561
562  if (filename==NULL) {
563    sprintf(subsfile, "%s/%s", owl_global_get_homedir(&g), ".zephyr.subs");
564  } else {
565    strcpy(subsfile, filename);
566  }
567
568  /* first check if it exists already */
569  file=fopen(subsfile, "r");
570  if (!file) {
571    owl_function_makemsg("Error opening file %s", subsfile);
572    owl_free(line);
573    return;
574  }
575  while (fgets(buff, LINE, file)!=NULL) {
576    if (!strcasecmp(buff, line)) {
577      owl_function_makemsg("Subscription already present in %s", subsfile);
578      owl_free(line);
579      return;
580    }
581  }
582
583  /* if we get here then we didn't find it */
584  fclose(file);
585  file=fopen(subsfile, "a");
586  if (!file) {
587    owl_function_makemsg("Error opening file %s for writing", subsfile);
588    owl_free(line);
589    return;
590  }
591  fputs(line, file);
592  fclose(file);
593  owl_function_makemsg("Subscription added");
594 
595  owl_free(line);
[be0a79f]596#endif
[bde7714]597}
598
[31e48a3]599void owl_zephyr_delsub(char *filename, char *class, char *inst, char *recip)
600{
[be0a79f]601#ifdef HAVE_LIBZEPHYR
[b2a91b6]602  char *line, *subsfile;
[bde7714]603 
604  line=owl_zephyr_makesubline(class, inst, recip);
[b2a91b6]605  line[strlen(line)-1]='\0';
[bde7714]606
[b2a91b6]607  if (!filename) {
608    subsfile=owl_sprintf("%s/.zephyr.subs", owl_global_get_homedir(&g));
[bde7714]609  } else {
[b2a91b6]610    subsfile=owl_strdup(filename);
[bde7714]611  }
[b2a91b6]612 
613  owl_util_file_deleteline(subsfile, line, 1);
614  owl_free(subsfile);
[bde7714]615  owl_free(line);
616  owl_function_makemsg("Subscription removed");
[be0a79f]617#endif
[bde7714]618}
619
[b2a91b6]620/* caller must free the return */
[31e48a3]621char *owl_zephyr_makesubline(char *class, char *inst, char *recip)
622{
[bde7714]623  char *out;
624
625  out=owl_malloc(strlen(class)+strlen(inst)+strlen(recip)+30);
626  sprintf(out, "%s,%s,%s\n", class, inst, !strcmp(recip, "") ? "*" : recip);
627  return(out);
628}
[31e48a3]629
630
631void owl_zephyr_zlog_in(void)
632{
[be0a79f]633#ifdef HAVE_LIBZEPHYR
[31e48a3]634  char *exposure, *eset;
635  int ret;
636
637  ZResetAuthentication();
638   
639  eset=EXPOSE_REALMVIS;
640  exposure=ZGetVariable("exposure");
641  if (exposure==NULL) {
642    eset=EXPOSE_REALMVIS;
643  } else if (!strcasecmp(exposure,EXPOSE_NONE)) {
644    eset = EXPOSE_NONE;
645  } else if (!strcasecmp(exposure,EXPOSE_OPSTAFF)) {
646    eset = EXPOSE_OPSTAFF;
647  } else if (!strcasecmp(exposure,EXPOSE_REALMVIS)) {
648    eset = EXPOSE_REALMVIS;
649  } else if (!strcasecmp(exposure,EXPOSE_REALMANN)) {
650    eset = EXPOSE_REALMANN;
651  } else if (!strcasecmp(exposure,EXPOSE_NETVIS)) {
652    eset = EXPOSE_NETVIS;
653  } else if (!strcasecmp(exposure,EXPOSE_NETANN)) {
654    eset = EXPOSE_NETANN;
655  }
656   
657  ret=ZSetLocation(eset);
658  if (ret != ZERR_NONE) {
659    /*
660      char buff[LINE];
661      sprintf(buff, "Error setting location: %s", error_message(ret));
662      owl_function_makemsg(buff);
663    */
664  }
[be0a79f]665#endif
[31e48a3]666}
667
668void owl_zephyr_zlog_out(void)
669{
[be0a79f]670#ifdef HAVE_LIBZEPHYR
[31e48a3]671  int ret;
672
673  ZResetAuthentication();
674  ret=ZUnsetLocation();
675  if (ret != ZERR_NONE) {
676    /*
677      char buff[LINE];
678      sprintf(buff, "Error unsetting location: %s", error_message(ret));
679      owl_function_makemsg(buff);
680    */
681  }
[be0a79f]682#endif
[31e48a3]683}
684
[65ad073]685void owl_zephyr_addbuddy(char *name)
686{
687  char *filename;
688  FILE *file;
689 
690  filename=owl_sprintf("%s/.anyone", owl_global_get_homedir(&g));
691  file=fopen(filename, "a");
692  owl_free(filename);
693  if (!file) {
694    owl_function_makemsg("Error opening zephyr buddy file for append");
695    return;
696  }
697  fprintf(file, "%s\n", name);
698  fclose(file);
699}
700
701void owl_zephyr_delbuddy(char *name)
702{
703  char *filename;
704
705  filename=owl_sprintf("%s/.anyone", owl_global_get_homedir(&g));
706  owl_util_file_deleteline(filename, name, 0);
707  owl_free(filename);
708}
[9381782]709
710/* return auth string */
[09489b89]711#ifdef HAVE_LIBZEPHYR
[9381782]712char *owl_zephyr_get_authstr(ZNotice_t *n)
713{
714
715  if (!n) return("UNKNOWN");
716
717  if (n->z_auth == ZAUTH_FAILED) {
718    return ("FAILED");
719  } else if (n->z_auth == ZAUTH_NO) {
720    return ("NO");
721  } else if (n->z_auth == ZAUTH_YES) {
722    return ("YES");
723  } else {
724    return ("UNKNOWN");
725  }           
726}
[09489b89]727#else
728char *owl_zephyr_get_authstr(void *n)
729{
730  return("");
731}
732#endif
[9381782]733
734
[09489b89]735/* returns a buffer of subscriptions or an error message.
736 * Caller must free the return.
737 */
738char *owl_zephyr_getsubs()
739{
740#ifdef HAVE_LIBZEPHYR
741  int ret, num, i, one;
742  ZSubscription_t sub;
743  char *out, *tmpbuff;
744  one=1;
745
746  ret=ZRetrieveSubscriptions(0, &num);
747  if (ret==ZERR_TOOMANYSUBS) {
748    out=owl_strdup("Zephyr: too many subscriptions\n");
749    return(out);
750  }
751
752  out=owl_malloc(num*500);
753  tmpbuff=owl_malloc(num*500);
754  strcpy(out, "");
755  for (i=0; i<num; i++) {
756    if ((ret = ZGetSubscriptions(&sub, &one)) != ZERR_NONE) {
757      owl_free(out);
758      owl_free(tmpbuff);
759      ZFlushSubscriptions();
760      out=owl_strdup("Error while getting subscriptions\n");
761      return(out);
762    } else {
[03955f3]763      sprintf(tmpbuff, "<%s,%s,%s>\n%s", sub.zsub_class, sub.zsub_classinst, sub.zsub_recipient, out);
[09489b89]764      strcpy(out, tmpbuff);
765    }
766  }
767
768  owl_free(tmpbuff);
769  ZFlushSubscriptions();
770  return(out);
771#else
772  return("");
773#endif
774}
775
776char *owl_zephyr_get_variable(char *var)
777{
778#ifdef HAVE_LIBZEPHYR
779  return(ZGetVariable(var));
780#else
781  return("");
782#endif
783}
784
785void owl_zephyr_set_locationinfo(char *host, char *val)
786{
787#ifdef HAVE_LIBZEPHYR
788  ZInitLocationInfo(host, val);
789#endif
790}
791 
Note: See TracBrowser for help on using the repository browser.