/* Load zephyr subscriptions from 'filename'. If 'filename' is NULL, * the default file $HOME/.zephyr.subs will be used. * * Returns 0 on success. If the file does not exist, return -1 if * 'error_on_nofile' is 1, otherwise return 0. Return -1 if the file * exists but can not be read. Return -2 if there is a failure from * zephyr to load the subscriptions. */ int owl_zephyr_loadsubs(const char *filename, int error_on_nofile) { #ifdef HAVE_LIBZEPHYR FILE *file; int fopen_errno; char *tmp, *start; char *buffer = NULL; char *subsfile; ZSubscription_t *subs; int subSize = 1024; int count; subsfile = owl_zephyr_dotfile(".zephyr.subs", filename); count = 0; file = fopen(subsfile, "r"); fopen_errno = errno; g_free(subsfile); if (!file) { if (error_on_nofile == 1 || fopen_errno != ENOENT) return -1; return 0; } subs = g_new(ZSubscription_t, subSize); while (owl_getline(&buffer, file)) { if (buffer[0] == '#' || buffer[0] == '\n') continue; if (buffer[0] == '-') start = buffer + 1; else start = buffer; if (count >= subSize) { subSize *= 2; subs = g_renew(ZSubscription_t, subs, subSize); } /* add it to the list of subs */ if ((tmp = strtok(start, ",\n\r")) == NULL) continue; subs[count].zsub_class = g_strdup(tmp); if ((tmp=strtok(NULL, ",\n\r")) == NULL) continue; subs[count].zsub_classinst = g_strdup(tmp); if ((tmp = strtok(NULL, " \t\n\r")) == NULL) continue; subs[count].zsub_recipient = g_strdup(tmp); /* if it started with '-' then add it to the global punt list, and * remove it from the list of subs. */ if (buffer[0] == '-') { owl_function_zpunt(subs[count].zsub_class, subs[count].zsub_classinst, subs[count].zsub_recipient, 0); g_free(subs[count].zsub_class); g_free(subs[count].zsub_classinst); g_free(subs[count].zsub_recipient); } else { count++; } } fclose(file); if (buffer) g_free(buffer); ZResetAuthentication(); return owl_zephyr_loadsubs_helper(subs, count); #else return 0; #endif }
/* Load zephyr subscriptions from 'filename'. If 'filename' is NULL, * the default file $HOME/.zephyr.subs will be used. * * Returns 0 on success. If the file does not exist, return -1 if * 'error_on_nofile' is 1, otherwise return 0. Return -1 if the file * exists but can not be read. Return -2 if there is a failure from * zephyr to load the subscriptions. */ int owl_zephyr_loadsubs(char *filename, int error_on_nofile) { #ifdef HAVE_LIBZEPHYR FILE *file; char *tmp, *start; char buffer[1024], subsfile[1024]; ZSubscription_t *subs; int subSize = 1024; int count, ret; struct stat statbuff; subs = owl_malloc(sizeof(ZSubscription_t) * subSize); if (filename==NULL) { sprintf(subsfile, "%s/%s", owl_global_get_homedir(&g), ".zephyr.subs"); } else { strcpy(subsfile, filename); } ret=stat(subsfile, &statbuff); if (ret) { if (error_on_nofile==1) return(-1); return(0); } ZResetAuthentication(); count=0; file=fopen(subsfile, "r"); if (!file) return(-1); while ( fgets(buffer, 1024, file)!=NULL ) { if (buffer[0]=='#' || buffer[0]=='\n' || buffer[0]=='\n') continue; if (buffer[0]=='-') { start=buffer+1; } else { start=buffer; } if (count >= subSize) { subSize *= 2; subs = owl_realloc(subs, sizeof(ZSubscription_t) * subSize); } /* add it to the list of subs */ if ((tmp=(char *) strtok(start, ",\n\r"))==NULL) continue; subs[count].zsub_class=owl_strdup(tmp); if ((tmp=(char *) strtok(NULL, ",\n\r"))==NULL) continue; subs[count].zsub_classinst=owl_strdup(tmp); if ((tmp=(char *) strtok(NULL, " \t\n\r"))==NULL) continue; subs[count].zsub_recipient=owl_strdup(tmp); /* if it started with '-' then add it to the global punt list, and * remove it from the list of subs. */ if (buffer[0]=='-') { owl_function_zpunt(subs[count].zsub_class, subs[count].zsub_classinst, subs[count].zsub_recipient, 0); owl_free(subs[count].zsub_class); owl_free(subs[count].zsub_classinst); owl_free(subs[count].zsub_recipient); } else { count++; } } fclose(file); ret = owl_zephyr_loadsubs_helper(subs, count); return(ret); #else return(0); #endif }