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