Esempio n. 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
}
Esempio n. 2
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
}
Esempio n. 3
0
void owl_zephyr_finish_initialization(const owl_io_dispatch *d, void *data) {
  Code_t code;
  char *perl;
  GSource *event_source;

  owl_select_remove_io_dispatch(d);

  ZClosePort();

  if ((code = ZInitialize()) != ZERR_NONE) {
    owl_function_error("Initializing Zephyr: %s", error_message(code));
    return;
  }

  if ((code = ZOpenPort(NULL)) != ZERR_NONE) {
    owl_function_error("Initializing Zephyr: %s", error_message(code));
    return;
  }

  event_source = owl_zephyr_event_source_new(ZGetFD());
  g_source_attach(event_source, NULL);
  g_source_unref(event_source);

  owl_global_set_havezephyr(&g);

  if(g.load_initial_subs) {
    owl_zephyr_load_initial_subs();
  }
  while(deferred_subs != NULL) {
    owl_sub_list *subs = deferred_subs->data;
    owl_function_debugmsg("Loading %d deferred subs.", subs->nsubs);
    owl_zephyr_loadsubs_helper(subs->subs, subs->nsubs);
    deferred_subs = g_list_delete_link(deferred_subs, deferred_subs);
    g_free(subs);
  }

  /* zlog in if we need to */
  if (owl_global_is_startuplogin(&g)) {
    owl_function_debugmsg("startup: doing zlog in");
    owl_zephyr_zlog_in();
  }
  /* check pseudo-logins if we need to */
  if (owl_global_is_pseudologins(&g)) {
    owl_function_debugmsg("startup: checking pseudo-logins");
    owl_function_zephyr_buddy_check(0);
  }

  perl = owl_perlconfig_execute("BarnOwl::Zephyr::_zephyr_startup()");
  g_free(perl);
}
Esempio n. 4
0
void owl_zephyr_finish_initialization(owl_dispatch *d) {
  Code_t code;

  owl_select_remove_dispatch(d->fd);

  ZClosePort();

  if ((code = ZInitialize()) != ZERR_NONE) {
    owl_function_error("Initializing Zephyr: %s", error_message(code));
    return;
  }

  if ((code = ZOpenPort(NULL)) != ZERR_NONE) {
    owl_function_error("Initializing Zephyr: %s", error_message(code));
    return;
  }

  d = owl_malloc(sizeof(owl_dispatch));
  d->fd = ZGetFD();
  d->cfunc = &owl_zephyr_process_events;
  d->destroy = NULL;
  owl_select_add_dispatch(d);
  owl_global_set_havezephyr(&g);

  if(g.load_initial_subs) {
    owl_zephyr_load_initial_subs();
  }
  while(deferred_subs != NULL) {
    owl_sub_list *subs = deferred_subs->data;
    owl_function_debugmsg("Loading %d deferred subs.", subs->nsubs);
    owl_zephyr_loadsubs_helper(subs->subs, subs->nsubs);
    deferred_subs = g_list_delete_link(deferred_subs, deferred_subs);
    owl_free(subs);
  }

  /* zlog in if we need to */
  if (owl_global_is_startuplogin(&g)) {
    owl_function_debugmsg("startup: doing zlog in");
    owl_zephyr_zlog_in();
  }
}
Esempio n. 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
}
Esempio n. 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
}
Esempio n. 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
}