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