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