Exemple #1
0
int owl_zephyr_loadloginsubs(char *filename)
{
#ifdef HAVE_LIBZEPHYR
  FILE *file;
  ZSubscription_t *subs;
  int numSubs = 100;
  char subsfile[1024], buffer[1024];
  int count, ret;
  struct stat statbuff;

  subs = owl_malloc(numSubs * sizeof(ZSubscription_t));

  if (filename==NULL) {
    sprintf(subsfile, "%s/%s", owl_global_get_homedir(&g), ".anyone");
  } else {
    strcpy(subsfile, filename);
  }
  
  ret=stat(subsfile, &statbuff);
  if (ret) return(0);

  ret=0;

  ZResetAuthentication();
  count=0;
  file=fopen(subsfile, "r");
  if (file) {
    while ( fgets(buffer, 1024, file)!=NULL ) {
      if (buffer[0]=='#' || buffer[0]=='\n' || buffer[0]=='\n') continue;
      
      if (count == numSubs) {
        numSubs *= 2;
        subs = owl_realloc(subs, numSubs * sizeof(ZSubscription_t));
      }

      buffer[strlen(buffer)-1]='\0';
      subs[count].zsub_class=owl_strdup("login");
      subs[count].zsub_recipient=owl_strdup("*");
      if (strchr(buffer, '@')) {
        subs[count].zsub_classinst=owl_strdup(buffer);
      } else {
        subs[count].zsub_classinst=owl_sprintf("%s@%s", buffer, ZGetRealm());
      }

      count++;
    }
    fclose(file);
  } else {
    count=0;
    ret=-1;
  }

  ret = owl_zephyr_loadsubs_helper(subs, count);
  return(ret);
#else
  return(0);
#endif
}
Exemple #2
0
void unsuball(void)
{
#if HAVE_LIBZEPHYR
  Code_t ret;

  ZResetAuthentication();
  ret = ZCancelSubscriptions(0);
  if (ret != ZERR_NONE)
    owl_function_error("Zephyr: Cancelling subscriptions: %s",
                       error_message(ret));
#endif
}
Exemple #3
0
void unsuball()
{
#if HAVE_LIBZEPHYR
  int ret;

  ZResetAuthentication();
  ret=ZCancelSubscriptions(0);
  if (ret != ZERR_NONE) {
    com_err("owl",ret,"while unsubscribing");
  }
#endif
}
Exemple #4
0
int owl_zephyr_loadloginsubs(const char *filename)
{
#ifdef HAVE_LIBZEPHYR
  FILE *file;
  ZSubscription_t *subs;
  int numSubs = 100;
  char *subsfile;
  char *buffer = NULL;
  int count;
  struct stat statbuff;

  subs = g_new(ZSubscription_t, numSubs);
  subsfile = owl_zephyr_dotfile(".anyone", filename);

  if (stat(subsfile, &statbuff) == -1) {
    g_free(subs);
    g_free(subsfile);
    return 0;
  }

  ZResetAuthentication();
  count = 0;
  file = fopen(subsfile, "r");
  g_free(subsfile);
  if (file) {
    while (owl_getline_chomp(&buffer, file)) {
      if (buffer[0] == '\0' || buffer[0] == '#')
	continue;

      if (count == numSubs) {
        numSubs *= 2;
        subs = g_renew(ZSubscription_t, subs, numSubs);
      }

      subs[count].zsub_class = g_strdup("login");
      subs[count].zsub_recipient = g_strdup("*");
      subs[count].zsub_classinst = long_zuser(buffer);

      count++;
    }
    fclose(file);
  } else {
    return 0;
  }
  g_free(buffer);

  return owl_zephyr_loadsubs_helper(subs, count);
#else
  return 0;
#endif
}
Exemple #5
0
/* Load default BarnOwl subscriptions
 *
 * Returns 0 on success.
 * Return -2 if there is a failure from zephyr to load the subscriptions.
 */
int owl_zephyr_loadbarnowldefaultsubs(void)
{
#ifdef HAVE_LIBZEPHYR
  ZSubscription_t *subs;
  int subSize = 10; /* Max BarnOwl default subs we allow */
  int count, ret;

  subs = g_new(ZSubscription_t, subSize);
  ZResetAuthentication();
  count=0;

  subs[count].zsub_class=g_strdup("message");
  subs[count].zsub_classinst=g_strdup("*");
  subs[count].zsub_recipient=g_strdup("%me%");
  count++;

  ret = owl_zephyr_loadsubs_helper(subs, count);
  return(ret);
#else
  return(0);
#endif
}
Exemple #6
0
/* 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
}
Exemple #7
0
/* 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
}