source: zephyr.c @ 3c7d007a

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