Beispiel #1
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
}
Beispiel #2
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
}