Esempio n. 1
0
static void _owl_keymap_format_bindings(const owl_keymap *km, owl_fmtext *fm)
{
  int i, nbindings;
  const owl_keybinding *kb;
  
  nbindings = owl_list_get_size(&km->bindings);
  for (i=0; i<nbindings; i++) {
    char *kbstr;
    const owl_cmd *cmd;
    const char *tmpdesc, *desc = "";

    kb = owl_list_get_element(&km->bindings, i);
    kbstr = owl_keybinding_tostring(kb);
    owl_fmtext_append_normal(fm, OWL_TABSTR);
    owl_fmtext_append_normal(fm, kbstr);
    owl_fmtext_append_spaces(fm, 11-strlen(kbstr));
    g_free(kbstr);
    owl_fmtext_append_normal(fm, " - ");
    if (kb->desc && *kb->desc) {
      desc = kb->desc;
    } else if ((cmd=owl_function_get_cmd(kb->command))
	       && (tmpdesc = owl_cmd_get_summary(cmd))) {
      desc = tmpdesc;
    }
    owl_fmtext_append_normal(fm, desc);
    if (kb->command && *(kb->command)) {
      owl_fmtext_append_normal(fm, "   [");
      owl_fmtext_append_normal(fm, kb->command);
      owl_fmtext_append_normal(fm, "]");
    } 
    owl_fmtext_append_normal(fm, "\n");
  }
}
Esempio n. 2
0
/* fmtext should already be initialized */
void owl_errqueue_to_fmtext(const owl_errqueue *eq, owl_fmtext *fm)
{
  int i, j;

  j=owl_list_get_size(&(eq->errlist));
  for (i=0; i<j; i++) {
    owl_fmtext_append_normal(fm, owl_list_get_element(&(eq->errlist), i));
    owl_fmtext_append_normal(fm, "\n");
  }
}
Esempio n. 3
0
/* return the AIM buddy with screenname 'name'.  If
 * no such buddy is logged in, return NULL.
 */
owl_buddy *owl_buddylist_get_aim_buddy(const owl_buddylist *bl, const char *name)
{
  int i, j;
  owl_buddy *b;

  j=owl_list_get_size(&(bl->buddies));
  for (i=0; i<j; i++) {
    b=owl_list_get_element(&(bl->buddies), i);
    if (!strcasecmp(name, owl_buddy_get_name(b))) return(b);
  }
  return(NULL);
}
Esempio n. 4
0
/* Returns the valid owl_io_dispatch for a given file descriptor. */
static owl_io_dispatch *owl_select_find_valid_io_dispatch_by_fd(const int fd)
{
  int i, len;
  const owl_list *dl;
  owl_io_dispatch *d;
  dl = owl_global_get_io_dispatch_list(&g);
  len = owl_list_get_size(dl);
  for(i = 0; i < len; i++) {
    d = owl_list_get_element(dl, i);
    if (d->fd == fd && d->valid) return d;
  }
  return NULL;
}
Esempio n. 5
0
/* Returns the index of the dispatch for the file descriptor. */
int owl_select_find_dispatch(int fd)
{
  int i, len;
  owl_list *dl;
  owl_dispatch *d;
  
  dl = owl_global_get_dispatchlist(&g);
  len = owl_list_get_size(dl);
  for(i = 0; i < len; i++) {
    d = (owl_dispatch*)owl_list_get_element(dl, i);
    if (d->fd == fd) return i;
  }
  return -1;
}
Esempio n. 6
0
static owl_io_dispatch *owl_select_find_perl_io_dispatch(int fd)
{
  int i, len;
  const owl_list *dl;
  owl_io_dispatch *d;
  dl = owl_global_get_io_dispatch_list(&g);
  len = owl_list_get_size(dl);
  for(i = 0; i < len; i++) {
    d = owl_list_get_element(dl, i);
    if (d->fd == fd && d->callback == owl_perlconfig_io_dispatch)
      return d;
  }
  return NULL;
}
Esempio n. 7
0
static int owl_select_find_io_dispatch(const owl_io_dispatch *in)
{
  int i, len;
  const owl_list *dl;

  if (in != NULL) {
    dl = owl_global_get_io_dispatch_list(&g);
    len = owl_list_get_size(dl);
    for(i = 0; i < len; i++) {
      const owl_io_dispatch *d = owl_list_get_element(dl, i);
      if (d == in) return i;
    }
  }
  return -1;
}
Esempio n. 8
0
AV *owl_new_av(const owl_list *l, SV *(*to_sv)(const void *))
{
  AV *ret;
  int i;
  void *element;

  ret = newAV();

  for (i = 0; i < owl_list_get_size(l); i++) {
    element = owl_list_get_element(l, i);
    av_push(ret, to_sv(element));
  }

  return ret;
}
Esempio n. 9
0
/* remove an AIM buddy from the buddy list
 */
int owl_buddylist_remove_aim_buddy(owl_buddylist *bl, const char *name)
{
  int i, j;
  owl_buddy *b;

  j=owl_list_get_size(&(bl->buddies));
  for (i=0; i<j; i++) {
    b=owl_list_get_element(&(bl->buddies), i);
    if (!strcasecmp(name, owl_buddy_get_name(b)) && owl_buddy_is_proto_aim(b)) {
      owl_list_remove_element(&(bl->buddies), i);
      owl_buddy_delete(b);
      return(0);
    }
  }
  return(1);
}
Esempio n. 10
0
static void owl_select_io_dispatch_gc(void)
{
  int i;
  owl_list *dl;

  dl = owl_global_get_io_dispatch_list(&g);
  /*
   * Count down so we aren't set off by removing items from the list
   * during the iteration.
   */
  for(i = owl_list_get_size(dl) - 1; i >= 0; i--) {
    owl_io_dispatch *d = owl_list_get_element(dl, i);
    if(d->needs_gc) {
      owl_select_remove_io_dispatch(d);
    }
  }
}
Esempio n. 11
0
int owl_zbuddylist_adduser(owl_zbuddylist *zb, const char *name)
{
  int i, j;
  char *user;

  user=long_zuser(name);

  j=owl_list_get_size(&(zb->zusers));
  for (i=0; i<j; i++) {
    if (!strcasecmp(user, owl_list_get_element(&(zb->zusers), i))) {
      owl_free(user);
      return(-1);
    }
  }
  owl_list_append_element(&(zb->zusers), user);
  return(0);
}
Esempio n. 12
0
static gboolean owl_io_dispatch_check(GSource *source) {
  int i, len;
  const owl_list *dl;

  dl = owl_global_get_io_dispatch_list(&g);
  len = owl_list_get_size(dl);
  for(i = 0; i < len; i++) {
    owl_io_dispatch *d = owl_list_get_element(dl, i);
    if (!d->valid) continue;
    if (d->pollfd.revents & G_IO_NVAL) {
      owl_function_debugmsg("Pruning defunct dispatch on fd %d.", d->fd);
      owl_select_invalidate_io_dispatch(d);
    }
    if (d->pollfd.revents & d->pollfd.events)
      return TRUE;
  }
  return FALSE;
}
Esempio n. 13
0
static gboolean owl_io_dispatch_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) {
  int i, len;
  const owl_list *dl;

  dispatch_active = 1;
  dl = owl_global_get_io_dispatch_list(&g);
  len = owl_list_get_size(dl);
  for (i = 0; i < len; i++) {
    owl_io_dispatch *d = owl_list_get_element(dl, i);
    if (!d->valid) continue;
    if ((d->pollfd.revents & d->pollfd.events) && d->callback != NULL) {
      d->callback(d, d->data);
    }
  }
  dispatch_active = 0;
  owl_select_io_dispatch_gc();

  return TRUE;
}
Esempio n. 14
0
int owl_zbuddylist_deluser(owl_zbuddylist *zb, const char *name)
{
  int i, j;
  char *user, *ptr;

  user=long_zuser(name);

  j=owl_list_get_size(&(zb->zusers));
  for (i=0; i<j; i++) {
    ptr=owl_list_get_element(&(zb->zusers), i);
    if (!strcasecmp(user, ptr)) {
      owl_list_remove_element(&(zb->zusers), i);
      owl_free(ptr);
      owl_free(user);
      return(0);
    }
  }
  owl_free(user);
  return(-1);
}
Esempio n. 15
0
HV *owl_new_hv(const owl_dict *d, SV *(*to_sv)(const void *))
{
  HV *ret;
  owl_list l;
  const char *key;
  void *element;
  int i;

  ret = newHV();

  /* TODO: add an iterator-like interface to owl_dict */
  owl_dict_get_keys(d, &l);
  for (i = 0; i < owl_list_get_size(&l); i++) {
    key = owl_list_get_element(&l, i);
    element = owl_dict_find_element(d, key);
    (void)hv_store(ret, key, strlen(key), to_sv(element), 0);
  }
  owl_list_cleanup(&l, owl_free);

  return ret;
}
Esempio n. 16
0
/* removes the binding associated with the keymap */
int owl_keymap_remove_binding(owl_keymap *km, const char *keyseq)
{
  owl_keybinding *kb, *curkb;
  int i;

  kb = owl_keybinding_new(keyseq, NULL, NULL, NULL);
  if (kb == NULL)
    return -1;

  for (i = owl_list_get_size(&km->bindings)-1; i >= 0; i--) {
    curkb = owl_list_get_element(&km->bindings, i);
    if (owl_keybinding_equal(curkb, kb)) {
      owl_list_remove_element(&km->bindings, i);
      owl_keybinding_delete(curkb);
      owl_keybinding_delete(kb);
      return(0);
    }
  }
  owl_keybinding_delete(kb);
  return(-2);
}
Esempio n. 17
0
/* creates and adds a key binding */
int owl_keymap_create_binding(owl_keymap *km, const char *keyseq, const char *command, void (*function_fn)(void), const char *desc)
{
  owl_keybinding *kb, *curkb;
  int i;

  kb = owl_keybinding_new(keyseq, command, function_fn, desc);
  if (kb == NULL)
    return -1;
  /* see if another matching binding, and if so remove it.
   * otherwise just add this one. 
   */
  for (i = owl_list_get_size(&km->bindings)-1; i>=0; i--) {
    curkb = owl_list_get_element(&km->bindings, i);
    if (owl_keybinding_equal(curkb, kb)) {
      owl_list_remove_element(&km->bindings, i);
      owl_keybinding_delete(curkb);
    }
  }
  return owl_list_append_element(&km->bindings, kb);  

}
Esempio n. 18
0
/* requires that the list values are strings or NULL.
 * joins the elements together with join_with. 
 * If format_fn is specified, passes it the list element value
 * and it will return a string which this needs to free. */
void owl_fmtext_append_list(owl_fmtext *f, const owl_list *l, const char *join_with, char *(format_fn)(const char *))
{
  int i, size;
  const char *elem;
  char *text;

  size = owl_list_get_size(l);
  for (i=0; i<size; i++) {
    elem = owl_list_get_element(l,i);
    if (elem && format_fn) {
      text = format_fn(elem);
      if (text) {
        owl_fmtext_append_normal(f, text);
        owl_free(text);
      }
    } else if (elem) {
      owl_fmtext_append_normal(f, elem);
    }
    if ((i < size-1) && join_with) {
      owl_fmtext_append_normal(f, join_with);
    }
  }
}
Esempio n. 19
0
int owl_dict_regtest(void) {
  owl_dict d;
  owl_list l;
  int numfailed=0;
  char *av="aval", *bv="bval", *cv="cval", *dv="dval";

  printf("# BEGIN testing owl_dict\n");
  FAIL_UNLESS("create", 0==owl_dict_create(&d));
  FAIL_UNLESS("insert b", 0==owl_dict_insert_element(&d, "b", bv, owl_dict_noop_delete));
  FAIL_UNLESS("insert d", 0==owl_dict_insert_element(&d, "d", dv, owl_dict_noop_delete));
  FAIL_UNLESS("insert a", 0==owl_dict_insert_element(&d, "a", av, owl_dict_noop_delete));
  FAIL_UNLESS("insert c", 0==owl_dict_insert_element(&d, "c", cv, owl_dict_noop_delete));
  FAIL_UNLESS("reinsert d (no replace)", -2==owl_dict_insert_element(&d, "d", dv, 0));
  FAIL_UNLESS("find a", av==owl_dict_find_element(&d, "a"));
  FAIL_UNLESS("find b", bv==owl_dict_find_element(&d, "b"));
  FAIL_UNLESS("find c", cv==owl_dict_find_element(&d, "c"));
  FAIL_UNLESS("find d", dv==owl_dict_find_element(&d, "d"));
  FAIL_UNLESS("find e (non-existent)", NULL==owl_dict_find_element(&d, "e"));
  FAIL_UNLESS("remove d", dv==owl_dict_remove_element(&d, "d"));
  FAIL_UNLESS("find d (post-removal)", NULL==owl_dict_find_element(&d, "d"));

  FAIL_UNLESS("get_size", 3==owl_dict_get_size(&d));
  FAIL_UNLESS("get_keys", 0==owl_dict_get_keys(&d, &l));
  FAIL_UNLESS("get_keys result size", 3==owl_list_get_size(&l));
  
  /* these assume the returned keys are sorted */
  FAIL_UNLESS("get_keys result val",0==strcmp("a",owl_list_get_element(&l,0)));
  FAIL_UNLESS("get_keys result val",0==strcmp("b",owl_list_get_element(&l,1)));
  FAIL_UNLESS("get_keys result val",0==strcmp("c",owl_list_get_element(&l,2)));

  owl_list_cleanup(&l, owl_free);
  owl_dict_cleanup(&d, NULL);

  /*  if (numfailed) printf("*** WARNING: failures encountered with owl_dict\n"); */
  printf("# END testing owl_dict (%d failures)\n", numfailed);
  return(numfailed);
}
Esempio n. 20
0
int owl_select_dispatch_count()
{
  return owl_list_get_size(owl_global_get_dispatchlist(&g));
}
Esempio n. 21
0
/* processes a keypress.  returns 0 if the keypress was handled,
 * 1 if not handled, -1 on error, and -2 if j==ERR. */
int owl_keyhandler_process(owl_keyhandler *kh, owl_input j)
{
  const owl_keymap     *km;
  const owl_keybinding *kb;
  int i, match;

  if (!kh->active) {
    owl_function_makemsg("No active keymap!!!");
    return(-1);
  }

  /* deal with ESC prefixing */
  if (!kh->in_esc && j.ch == 27) {
    kh->in_esc = 1;
    return(0);
  }
  if (kh->in_esc) {
    j.ch = OWL_META(j.ch);
    kh->in_esc = 0;
  }
  
  kh->kpstack[++(kh->kpstackpos)] = j.ch;
  if (kh->kpstackpos >= OWL_KEYMAP_MAXSTACK) {
    owl_keyhandler_reset(kh);
    owl_function_makemsg("Too many prefix keys pressed...");
    return(-1);
  }

  /* deal with the always_fn for the map and parents */
  for (km=kh->active; km; km=km->parent) {
    if (km->prealways_fn) {
      km->prealways_fn(j);
    }
  }

  /* search for a match.  goes through active keymap and then
   * through parents... TODO:  clean this up so we can pull
   * keyhandler and keymap apart.  */
  for (km=kh->active; km; km=km->parent) {
    for (i=owl_list_get_size(&km->bindings)-1; i>=0; i--) {
      kb = owl_list_get_element(&km->bindings, i);
      match = owl_keybinding_match(kb, kh);
      if (match == 1) {		/* subset match */

	/* owl_function_debugmsg("processkey: found subset match in %s", km->name); */
	return(0);
      } else if (match == 2) {	/* exact match */
	/* owl_function_debugmsg("processkey: found exact match in %s", km->name); */
	owl_keybinding_execute(kb, j.ch);
	owl_keyhandler_reset(kh);
	if (km->postalways_fn) {
	  km->postalways_fn(j);
	}
	return(0);
      }
    }
  }

  /* see if a default action exists for the active keymap */
  if (kh->active->default_fn && kh->kpstackpos<1) {
    /*owl_function_debugmsg("processkey: executing default_fn");*/

    kh->active->default_fn(j);
    owl_keyhandler_reset(kh);
    if (kh->active->postalways_fn) {
      kh->active->postalways_fn(j);
    }
    return(0);
  }

  owl_keyhandler_invalidkey(kh);
  /* unable to handle */
  return(1);  
}
Esempio n. 22
0
SV *owl_perlconfig_message2hashref(const owl_message *m)
{
  HV *h, *stash;
  SV *hr;
  const char *type;
  char *ptr, *utype, *blessas;
  int i, j;
  const owl_pair *pair;
  const owl_filter *wrap;

  if (!m) return &PL_sv_undef;
  wrap = owl_global_get_filter(&g, "wordwrap");
  if(!wrap) {
      owl_function_error("wrap filter is not defined");
      return &PL_sv_undef;
  }

  h = newHV();

#define MSG2H(h,field) (void)hv_store(h, #field, strlen(#field),        \
                                      owl_new_sv(owl_message_get_##field(m)), 0)

  if (owl_message_is_type_zephyr(m)
      && owl_message_is_direction_in(m)) {
    /* Handle zephyr-specific fields... */
    AV *av_zfields;

    av_zfields = newAV();
    j=owl_zephyr_get_num_fields(owl_message_get_notice(m));
    for (i=0; i<j; i++) {
      ptr=owl_zephyr_get_field_as_utf8(owl_message_get_notice(m), i+1);
      av_push(av_zfields, owl_new_sv(ptr));
      owl_free(ptr);
    }
    (void)hv_store(h, "fields", strlen("fields"), newRV_noinc((SV*)av_zfields), 0);

    (void)hv_store(h, "auth", strlen("auth"), 
                   owl_new_sv(owl_zephyr_get_authstr(owl_message_get_notice(m))),0);
  }

  j=owl_list_get_size(&(m->attributes));
  for(i=0; i<j; i++) {
    pair=owl_list_get_element(&(m->attributes), i);
    (void)hv_store(h, owl_pair_get_key(pair), strlen(owl_pair_get_key(pair)),
                   owl_new_sv(owl_pair_get_value(pair)),0);
  }
  
  MSG2H(h, type);
  MSG2H(h, direction);
  MSG2H(h, class);
  MSG2H(h, instance);
  MSG2H(h, sender);
  MSG2H(h, realm);
  MSG2H(h, recipient);
  MSG2H(h, opcode);
  MSG2H(h, hostname);
  MSG2H(h, body);
  MSG2H(h, login);
  MSG2H(h, zsig);
  MSG2H(h, zwriteline);
  if (owl_message_get_header(m)) {
    MSG2H(h, header); 
  }
  (void)hv_store(h, "time", strlen("time"), owl_new_sv(owl_message_get_timestr(m)),0);
  (void)hv_store(h, "unix_time", strlen("unix_time"), newSViv(m->time), 0);
  (void)hv_store(h, "id", strlen("id"), newSViv(owl_message_get_id(m)),0);
  (void)hv_store(h, "deleted", strlen("deleted"), newSViv(owl_message_is_delete(m)),0);
  (void)hv_store(h, "private", strlen("private"), newSViv(owl_message_is_private(m)),0);
  (void)hv_store(h, "should_wordwrap",
                 strlen("should_wordwrap"), newSViv(
                                                    owl_filter_message_match(wrap, m)),0);

  type = owl_message_get_type(m);
  if(!type || !*type) type = "generic";
  utype = owl_strdup(type);
  utype[0] = toupper(type[0]);
  blessas = owl_sprintf("BarnOwl::Message::%s", utype);

  hr = newRV_noinc((SV*)h);
  stash =  gv_stashpv(blessas,0);
  if(!stash) {
    owl_function_error("No such class: %s for message type %s", blessas, owl_message_get_type(m));
    stash = gv_stashpv("BarnOwl::Message", 1);
  }
  hr = sv_bless(hr,stash);
  owl_free(utype);
  owl_free(blessas);
  return hr;
}
Esempio n. 23
0
/* return the number of logged in buddies */
int owl_buddylist_get_size(const owl_buddylist *bl)
{
  return(owl_list_get_size(&(bl->buddies)));
}