| 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 | |
|---|
| 9 | static const char fileIdent[] = "$Id$"; |
|---|
| 10 | |
|---|
| 11 | #ifdef HAVE_LIBZEPHYR |
|---|
| 12 | Code_t ZResetAuthentication(); |
|---|
| 13 | #endif |
|---|
| 14 | |
|---|
| 15 | int owl_zephyr_initialize() |
|---|
| 16 | { |
|---|
| 17 | #ifdef HAVE_LIBZEPHYR |
|---|
| 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 | } |
|---|
| 28 | #endif |
|---|
| 29 | return(0); |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | int owl_zephyr_shutdown() |
|---|
| 34 | { |
|---|
| 35 | #ifdef HAVE_LIBZEPHYR |
|---|
| 36 | unsuball(); |
|---|
| 37 | ZClosePort(); |
|---|
| 38 | #endif |
|---|
| 39 | return(0); |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | int owl_zephyr_zpending() |
|---|
| 43 | { |
|---|
| 44 | #ifdef HAVE_LIBZEPHYR |
|---|
| 45 | return(ZPending()); |
|---|
| 46 | #else |
|---|
| 47 | return(0); |
|---|
| 48 | #endif |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | char *owl_zephyr_get_realm() |
|---|
| 52 | { |
|---|
| 53 | #ifdef HAVE_LIBZEPHYR |
|---|
| 54 | return(ZGetRealm()); |
|---|
| 55 | #else |
|---|
| 56 | return(""); |
|---|
| 57 | #endif |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | char *owl_zephyr_get_sender() |
|---|
| 61 | { |
|---|
| 62 | #ifdef HAVE_LIBZEPHYR |
|---|
| 63 | return(ZGetSender()); |
|---|
| 64 | #else |
|---|
| 65 | return(""); |
|---|
| 66 | #endif |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | int owl_zephyr_loadsubs(char *filename) |
|---|
| 70 | { |
|---|
| 71 | #ifdef HAVE_LIBZEPHYR |
|---|
| 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 | } |
|---|
| 89 | |
|---|
| 90 | ZResetAuthentication(); |
|---|
| 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); |
|---|
| 141 | #else |
|---|
| 142 | return(0); |
|---|
| 143 | #endif |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | int owl_zephyr_loadloginsubs(char *filename) |
|---|
| 147 | { |
|---|
| 148 | #ifdef HAVE_LIBZEPHYR |
|---|
| 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 | |
|---|
| 162 | ZResetAuthentication(); |
|---|
| 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 { |
|---|
| 178 | subs[count].zsub_classinst=owl_sprintf("%s@%s", buffer, ZGetRealm()); |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | count++; |
|---|
| 182 | } |
|---|
| 183 | fclose(file); |
|---|
| 184 | } else { |
|---|
| 185 | count=0; |
|---|
| 186 | ret=-1; |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | /* sub with defaults */ |
|---|
| 190 | if (ZSubscribeToSansDefaults(subs,count,0) != ZERR_NONE) { |
|---|
| 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); |
|---|
| 201 | #else |
|---|
| 202 | return(0); |
|---|
| 203 | #endif |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | void unsuball() |
|---|
| 207 | { |
|---|
| 208 | #if HAVE_LIBZEPHYR |
|---|
| 209 | int ret; |
|---|
| 210 | |
|---|
| 211 | ZResetAuthentication(); |
|---|
| 212 | ret=ZCancelSubscriptions(0); |
|---|
| 213 | if (ret != ZERR_NONE) { |
|---|
| 214 | com_err("owl",ret,"while unsubscribing"); |
|---|
| 215 | } |
|---|
| 216 | #endif |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | int owl_zephyr_sub(char *class, char *inst, char *recip) |
|---|
| 220 | { |
|---|
| 221 | #ifdef HAVE_LIBZEPHYR |
|---|
| 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 | |
|---|
| 229 | ZResetAuthentication(); |
|---|
| 230 | if (ZSubscribeTo(subs,1,0) != ZERR_NONE) { |
|---|
| 231 | fprintf(stderr, "Error subbing\n"); |
|---|
| 232 | ret=-2; |
|---|
| 233 | } |
|---|
| 234 | return(0); |
|---|
| 235 | #else |
|---|
| 236 | return(0); |
|---|
| 237 | #endif |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | int owl_zephyr_unsub(char *class, char *inst, char *recip) |
|---|
| 242 | { |
|---|
| 243 | #ifdef HAVE_LIBZEPHYR |
|---|
| 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 | |
|---|
| 251 | ZResetAuthentication(); |
|---|
| 252 | if (ZUnsubscribeTo(subs,1,0) != ZERR_NONE) { |
|---|
| 253 | fprintf(stderr, "Error unsubbing\n"); |
|---|
| 254 | ret=-2; |
|---|
| 255 | } |
|---|
| 256 | return(0); |
|---|
| 257 | #else |
|---|
| 258 | return(0); |
|---|
| 259 | #endif |
|---|
| 260 | } |
|---|
| 261 | |
|---|
| 262 | #ifdef HAVE_LIBZEPHYR |
|---|
| 263 | char *owl_zephyr_get_field(ZNotice_t *n, int j, int *k) |
|---|
| 264 | { |
|---|
| 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 | } |
|---|
| 291 | #else |
|---|
| 292 | char *owl_zephyr_get_field(void *n, int j, int *k) |
|---|
| 293 | { |
|---|
| 294 | return(""); |
|---|
| 295 | } |
|---|
| 296 | #endif |
|---|
| 297 | |
|---|
| 298 | #ifdef HAVE_LIBZEPHYR |
|---|
| 299 | int owl_zephyr_get_num_fields(ZNotice_t *n) |
|---|
| 300 | { |
|---|
| 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 | } |
|---|
| 310 | #else |
|---|
| 311 | int owl_zephyr_get_num_fields(void *n) |
|---|
| 312 | { |
|---|
| 313 | return(0); |
|---|
| 314 | } |
|---|
| 315 | #endif |
|---|
| 316 | |
|---|
| 317 | #ifdef HAVE_LIBZEPHYR |
|---|
| 318 | char *owl_zephyr_get_message(ZNotice_t *n, int *k) |
|---|
| 319 | { |
|---|
| 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 | } |
|---|
| 328 | #endif |
|---|
| 329 | |
|---|
| 330 | #ifdef HAVE_LIBZEPHYR |
|---|
| 331 | char *owl_zephyr_get_zsig(ZNotice_t *n, int *k) |
|---|
| 332 | { |
|---|
| 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 | } |
|---|
| 342 | #else |
|---|
| 343 | char *owl_zephyr_get_zsig(void *n, int *k) |
|---|
| 344 | { |
|---|
| 345 | return(""); |
|---|
| 346 | } |
|---|
| 347 | #endif |
|---|
| 348 | |
|---|
| 349 | int send_zephyr(char *opcode, char *zsig, char *class, char *instance, char *recipient, char *message) |
|---|
| 350 | { |
|---|
| 351 | #ifdef HAVE_LIBZEPHYR |
|---|
| 352 | int ret; |
|---|
| 353 | ZNotice_t notice; |
|---|
| 354 | |
|---|
| 355 | memset(¬ice, 0, sizeof(notice)); |
|---|
| 356 | |
|---|
| 357 | ZResetAuthentication(); |
|---|
| 358 | |
|---|
| 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 | |
|---|
| 372 | notice.z_message_len=strlen(zsig)+1+strlen(message); |
|---|
| 373 | notice.z_message=owl_malloc(notice.z_message_len+10); |
|---|
| 374 | strcpy(notice.z_message, zsig); |
|---|
| 375 | memcpy(notice.z_message+strlen(zsig)+1, message, strlen(message)); |
|---|
| 376 | |
|---|
| 377 | /* ret=ZSendNotice(¬ice, ZAUTH); */ |
|---|
| 378 | ret=ZSrvSendNotice(¬ice, ZAUTH, send_zephyr_helper); |
|---|
| 379 | |
|---|
| 380 | /* free then check the return */ |
|---|
| 381 | owl_free(notice.z_message); |
|---|
| 382 | ZFreeNotice(¬ice); |
|---|
| 383 | if (ret!=ZERR_NONE) { |
|---|
| 384 | owl_function_makemsg("Error sending zephyr"); |
|---|
| 385 | return(ret); |
|---|
| 386 | } |
|---|
| 387 | return(0); |
|---|
| 388 | #else |
|---|
| 389 | return(0); |
|---|
| 390 | #endif |
|---|
| 391 | } |
|---|
| 392 | |
|---|
| 393 | #ifdef HAVE_LIBZEPHYR |
|---|
| 394 | Code_t send_zephyr_helper(ZNotice_t *notice, char *buf, int len, int wait) |
|---|
| 395 | { |
|---|
| 396 | return(ZSendPacket(buf, len, 0)); |
|---|
| 397 | } |
|---|
| 398 | #endif |
|---|
| 399 | |
|---|
| 400 | void send_ping(char *to) |
|---|
| 401 | { |
|---|
| 402 | #ifdef HAVE_LIBZEPHYR |
|---|
| 403 | send_zephyr("PING", "", "MESSAGE", "PERSONAL", to, ""); |
|---|
| 404 | #endif |
|---|
| 405 | } |
|---|
| 406 | |
|---|
| 407 | #ifdef HAVE_LIBZEPHYR |
|---|
| 408 | void owl_zephyr_handle_ack(ZNotice_t *retnotice) |
|---|
| 409 | { |
|---|
| 410 | char *tmp; |
|---|
| 411 | |
|---|
| 412 | /* if it's an HMACK ignore it */ |
|---|
| 413 | if (retnotice->z_kind == HMACK) return; |
|---|
| 414 | |
|---|
| 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")) { |
|---|
| 424 | tmp=short_zuser(retnotice->z_recipient); |
|---|
| 425 | owl_function_makemsg("Message sent to %s.", tmp); |
|---|
| 426 | free(tmp); |
|---|
| 427 | } else { |
|---|
| 428 | owl_function_makemsg("Message sent to -c %s -i %s\n", retnotice->z_class, retnotice->z_class_inst); |
|---|
| 429 | } |
|---|
| 430 | } else if (!strcmp(retnotice->z_message, ZSRVACK_NOTSENT)) { |
|---|
| 431 | if (strcasecmp(retnotice->z_class, "message")) { |
|---|
| 432 | owl_function_makemsg("Not logged in or not subscribing to class %s, instance %s", |
|---|
| 433 | retnotice->z_class, retnotice->z_class_inst); |
|---|
| 434 | } else { |
|---|
| 435 | tmp = short_zuser(retnotice->z_recipient); |
|---|
| 436 | owl_function_makemsg("%s: Not logged in or subscribing to messages.", |
|---|
| 437 | tmp); |
|---|
| 438 | owl_free(tmp); |
|---|
| 439 | } |
|---|
| 440 | } else { |
|---|
| 441 | owl_function_makemsg("Internal error on ack (%s)", retnotice->z_message); |
|---|
| 442 | } |
|---|
| 443 | } |
|---|
| 444 | #else |
|---|
| 445 | void owl_zephyr_handle_ack(void *retnotice) |
|---|
| 446 | { |
|---|
| 447 | } |
|---|
| 448 | #endif |
|---|
| 449 | |
|---|
| 450 | #ifdef HAVE_LIBZEPHYR |
|---|
| 451 | int owl_zephyr_notice_is_ack(ZNotice_t *n) |
|---|
| 452 | { |
|---|
| 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 | } |
|---|
| 459 | #else |
|---|
| 460 | int owl_zephyr_notice_is_ack(void *n) |
|---|
| 461 | { |
|---|
| 462 | return(0); |
|---|
| 463 | } |
|---|
| 464 | #endif |
|---|
| 465 | |
|---|
| 466 | void owl_zephyr_zaway(owl_message *m) |
|---|
| 467 | { |
|---|
| 468 | #ifdef HAVE_LIBZEPHYR |
|---|
| 469 | char *tmpbuff, *myuser, *to; |
|---|
| 470 | |
|---|
| 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 */ |
|---|
| 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; |
|---|
| 478 | if (!strcasecmp(owl_message_get_zsig(m), "Automated reply:")) return; |
|---|
| 479 | if (!strcasecmp(owl_message_get_sender(m), ZGetSender())) return; |
|---|
| 480 | |
|---|
| 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 | |
|---|
| 487 | send_zephyr("", |
|---|
| 488 | "Automated reply:", |
|---|
| 489 | owl_message_get_class(m), |
|---|
| 490 | owl_message_get_instance(m), |
|---|
| 491 | to, |
|---|
| 492 | owl_global_get_zaway_msg(&g)); |
|---|
| 493 | |
|---|
| 494 | myuser=short_zuser(to); |
|---|
| 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); |
|---|
| 501 | owl_free(to); |
|---|
| 502 | |
|---|
| 503 | /* display the message as an admin message in the receive window */ |
|---|
| 504 | owl_function_make_outgoing_zephyr(owl_global_get_zaway_msg(&g), tmpbuff, "Automated reply:"); |
|---|
| 505 | owl_free(tmpbuff); |
|---|
| 506 | #endif |
|---|
| 507 | } |
|---|
| 508 | |
|---|
| 509 | #ifdef HAVE_LIBZEPHYR |
|---|
| 510 | void owl_zephyr_hackaway_cr(ZNotice_t *n) |
|---|
| 511 | { |
|---|
| 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 | } |
|---|
| 521 | #endif |
|---|
| 522 | |
|---|
| 523 | void owl_zephyr_zlocate(char *user, char *out, int auth) |
|---|
| 524 | { |
|---|
| 525 | #ifdef HAVE_LIBZEPHYR |
|---|
| 526 | int ret, numlocs; |
|---|
| 527 | int one = 1; |
|---|
| 528 | ZLocations_t locations; |
|---|
| 529 | char *myuser; |
|---|
| 530 | |
|---|
| 531 | strcpy(out, ""); |
|---|
| 532 | ZResetAuthentication(); |
|---|
| 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) { |
|---|
| 539 | myuser=short_zuser(user); |
|---|
| 540 | sprintf(out, "%s: Hidden or not logged-in\n", myuser); |
|---|
| 541 | owl_free(myuser); |
|---|
| 542 | return; |
|---|
| 543 | } |
|---|
| 544 | |
|---|
| 545 | for (;numlocs;numlocs--) { |
|---|
| 546 | ZGetLocations(&locations,&one); |
|---|
| 547 | myuser=short_zuser(user); |
|---|
| 548 | sprintf(out, "%s%s: %s\t%s\t%s\n", out, myuser, locations.host, locations.tty, locations.time); |
|---|
| 549 | owl_free(myuser); |
|---|
| 550 | } |
|---|
| 551 | #endif |
|---|
| 552 | } |
|---|
| 553 | |
|---|
| 554 | void owl_zephyr_addsub(char *filename, char *class, char *inst, char *recip) |
|---|
| 555 | { |
|---|
| 556 | #ifdef HAVE_LIBZEPHYR |
|---|
| 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); |
|---|
| 596 | #endif |
|---|
| 597 | } |
|---|
| 598 | |
|---|
| 599 | void owl_zephyr_delsub(char *filename, char *class, char *inst, char *recip) |
|---|
| 600 | { |
|---|
| 601 | #ifdef HAVE_LIBZEPHYR |
|---|
| 602 | char *line, *subsfile; |
|---|
| 603 | |
|---|
| 604 | line=owl_zephyr_makesubline(class, inst, recip); |
|---|
| 605 | line[strlen(line)-1]='\0'; |
|---|
| 606 | |
|---|
| 607 | if (!filename) { |
|---|
| 608 | subsfile=owl_sprintf("%s/.zephyr.subs", owl_global_get_homedir(&g)); |
|---|
| 609 | } else { |
|---|
| 610 | subsfile=owl_strdup(filename); |
|---|
| 611 | } |
|---|
| 612 | |
|---|
| 613 | owl_util_file_deleteline(subsfile, line, 1); |
|---|
| 614 | owl_free(subsfile); |
|---|
| 615 | owl_free(line); |
|---|
| 616 | owl_function_makemsg("Subscription removed"); |
|---|
| 617 | #endif |
|---|
| 618 | } |
|---|
| 619 | |
|---|
| 620 | /* caller must free the return */ |
|---|
| 621 | char *owl_zephyr_makesubline(char *class, char *inst, char *recip) |
|---|
| 622 | { |
|---|
| 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 | } |
|---|
| 629 | |
|---|
| 630 | |
|---|
| 631 | void owl_zephyr_zlog_in(void) |
|---|
| 632 | { |
|---|
| 633 | #ifdef HAVE_LIBZEPHYR |
|---|
| 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 | } |
|---|
| 665 | #endif |
|---|
| 666 | } |
|---|
| 667 | |
|---|
| 668 | void owl_zephyr_zlog_out(void) |
|---|
| 669 | { |
|---|
| 670 | #ifdef HAVE_LIBZEPHYR |
|---|
| 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 | } |
|---|
| 682 | #endif |
|---|
| 683 | } |
|---|
| 684 | |
|---|
| 685 | void 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 | |
|---|
| 701 | void 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 | } |
|---|
| 709 | |
|---|
| 710 | /* return auth string */ |
|---|
| 711 | #ifdef HAVE_LIBZEPHYR |
|---|
| 712 | char *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 | } |
|---|
| 727 | #else |
|---|
| 728 | char *owl_zephyr_get_authstr(void *n) |
|---|
| 729 | { |
|---|
| 730 | return(""); |
|---|
| 731 | } |
|---|
| 732 | #endif |
|---|
| 733 | |
|---|
| 734 | |
|---|
| 735 | /* returns a buffer of subscriptions or an error message. |
|---|
| 736 | * Caller must free the return. |
|---|
| 737 | */ |
|---|
| 738 | char *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 { |
|---|
| 763 | sprintf(tmpbuff, "<%s,%s,%s>\n%s", sub.zsub_class, sub.zsub_classinst, sub.zsub_recipient, out); |
|---|
| 764 | strcpy(out, tmpbuff); |
|---|
| 765 | } |
|---|
| 766 | } |
|---|
| 767 | |
|---|
| 768 | owl_free(tmpbuff); |
|---|
| 769 | ZFlushSubscriptions(); |
|---|
| 770 | return(out); |
|---|
| 771 | #else |
|---|
| 772 | return(""); |
|---|
| 773 | #endif |
|---|
| 774 | } |
|---|
| 775 | |
|---|
| 776 | char *owl_zephyr_get_variable(char *var) |
|---|
| 777 | { |
|---|
| 778 | #ifdef HAVE_LIBZEPHYR |
|---|
| 779 | return(ZGetVariable(var)); |
|---|
| 780 | #else |
|---|
| 781 | return(""); |
|---|
| 782 | #endif |
|---|
| 783 | } |
|---|
| 784 | |
|---|
| 785 | void owl_zephyr_set_locationinfo(char *host, char *val) |
|---|
| 786 | { |
|---|
| 787 | #ifdef HAVE_LIBZEPHYR |
|---|
| 788 | ZInitLocationInfo(host, val); |
|---|
| 789 | #endif |
|---|
| 790 | } |
|---|
| 791 | |
|---|