示例#1
0
void test_clist_get_by_id(void)
{
  struct key k1;
  struct key k2;
  struct key k3;
  k1.id = 1;
  k2.id = 2;
  k3.id = 3;
  struct clist list;
  clist_init(&list, match_function, empty_destroy_function, CLIST_UNSORTED);
  clist_append(&list, (void *)&k1);
  clist_append(&list, (void *)&k2);
  clist_append(&list, (void *)&k3);

  struct key *data;

  int ret = clist_get_by_id(&list, (void **)&data, 1);
  CU_ASSERT(ret == CLIST_TRUE);
  if (ret==CLIST_TRUE)
    CU_ASSERT(data->id == 2);

  ret = clist_get_by_id(&list, (void **)&data, 0);
  CU_ASSERT(ret == CLIST_TRUE);
  if (ret==CLIST_TRUE)
    CU_ASSERT(data->id == 1);

  clist_get_by_id(&list, (void **)&data, -1);
  CU_ASSERT(ret == CLIST_TRUE);
  if (ret==CLIST_TRUE)
    CU_ASSERT(data->id == 3);

  clist_destroy(&list);
}
示例#2
0
static struct mailimf_fields * build_fields(void)
{
  struct mailimf_fields * fields;
  struct mailimf_field * f;
  clist * list;
  struct mailimf_from * from;
	struct mailimf_to * to;
  struct mailimf_mailbox * mb;
  struct mailimf_address * addr;
  struct mailimf_mailbox_list * mb_list;
  struct mailimf_address_list * addr_list;
  clist * fields_list;

  /* build headers */

  fields_list = clist_new();
  
  /* build header 'From' */
  
  list = clist_new();
  mb = mailimf_mailbox_new(strdup("DINH =?iso-8859-1?Q?Vi=EAt_Ho=E0?="),
    strdup("*****@*****.**"));
  clist_append(list, mb);
  mb_list = mailimf_mailbox_list_new(list);
  
  from = mailimf_from_new(mb_list);
  
  f = mailimf_field_new(MAILIMF_FIELD_FROM,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    from, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL);

  clist_append(fields_list, f);
  
  /* build header To */

  list = clist_new();
  mb = mailimf_mailbox_new(strdup("DINH =?iso-8859-1?Q?Vi=EAt_Ho=E0?="),
    strdup("*****@*****.**"));
  addr = mailimf_address_new(MAILIMF_ADDRESS_MAILBOX, mb, NULL);
  clist_append(list, addr);
  addr_list = mailimf_address_list_new(list);
  
  to = mailimf_to_new(addr_list);

  f = mailimf_field_new(MAILIMF_FIELD_TO,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, to, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL);
  
  clist_append(fields_list, f);
  
  fields = mailimf_fields_new(fields_list);
  
  return fields;
}
示例#3
0
void test_clist_append_insert_append(void)
{
#define NUM_ELEMENTS 10
  struct clist list;
  int ret = clist_init(&list, match_function, free_destroy_function, CLIST_UNSORTED);
  struct key *k = NULL;
  int ctr = NUM_ELEMENTS;
  for (; ctr>0; ctr--)
  {
    k = (struct key*)malloc(sizeof(struct key));
    k->id = ctr;
    printf("adding id: %i\n", k->id);
    ret = clist_append(&list, (void *)k);
    CU_ASSERT(ret==CLIST_TRUE);
  }
  for (ctr=NUM_ELEMENTS; ctr>0; ctr--)
  {
    k = (struct key*)malloc(sizeof(struct key));
    k->id = ctr;
    printf("adding id: %i\n", k->id);
    ret = clist_insert(&list, (void *)k, ctr);
    CU_ASSERT(ret==CLIST_TRUE);
  }
  for (ctr=NUM_ELEMENTS; ctr>0; ctr--)
  {
    k = (struct key*)malloc(sizeof(struct key));
    k->id = ctr;
    printf("adding id: %i\n", k->id);
    ret = clist_insert(&list, (void *)k, 0);
    CU_ASSERT(ret==CLIST_TRUE);
  }
  for (ctr=NUM_ELEMENTS; ctr>0; ctr--)
  {
    k = (struct key*)malloc(sizeof(struct key));
    k->id = ctr;
    printf("adding id: %i\n", k->id);
    ret = clist_append(&list, (void *)k);
    CU_ASSERT(ret==CLIST_TRUE);
  }

  struct clist_iterator *it = malloc(sizeof(struct clist_iterator));
  ret = clist_get_iterator(&list, it, 0);

  ret = clist_iterate(&list, it, (void **)&k, 0);
  CU_ASSERT(ret==CLIST_TRUE);
  ctr = 0;
  do
  {
    printf("k->id: %i\n", k->id);
    ctr ++;
  } while (clist_iterate(&list, it, (void **)&k, 1)==CLIST_TRUE);
  CU_ASSERT(ctr==NUM_ELEMENTS*4);
  clist_destroy(&list);

}
示例#4
0
文件: util.c 项目: aido/picocoin
static void test_shuffle(void)
{
	clist *l = NULL;
	l = clist_append(l, strdup("one"));
	l = clist_append(l, strdup("two"));
	l = clist_append(l, strdup("three"));

	clist_shuffle(l);		// TODO: improve test

	clist_free_ext(l, free);
}
示例#5
0
static bool nc_conn_send(struct nc_conn *conn, const char *command,
			 const void *data, size_t data_len)
{
	LOG("attempting to send:[%s] to %s", command, conn->addr_str);
	/* build wire message */
	cstring *msg = message_str(chain->netmagic, command, data, data_len);
	if (!msg)
		return false;

	/* buffer now owns message data */
	struct buffer *buf = calloc(1, sizeof(struct buffer));
	buf->p = msg->str;
	buf->len = msg->len;

	cstr_free(msg, false);

	/* if write q exists, write_evt will handle output */
	if (conn->write_q) {
		conn->write_q = clist_append(conn->write_q, buf);
		return true;
	}

	/* attempt optimistic write */
	ssize_t wrc = write(conn->fd, buf->p, buf->len);

	if (wrc < 0) {
		if (errno != EAGAIN && errno != EWOULDBLOCK) {
			free(buf->p);
			free(buf);
			return false;
		}

		conn->write_q = clist_append(conn->write_q, buf);
		goto out_wrstart;
	}

	/* message fully sent */
	if (wrc == buf->len) {
		free(buf->p);
		free(buf);
		return true;
	}

	/* message partially sent; pause read; poll for writable */
	conn->write_q = clist_append(conn->write_q, buf);
	conn->write_partial = wrc;

out_wrstart:
	nc_conn_read_disable(conn);
	nc_conn_write_enable(conn);
	return true;
}
示例#6
0
int mailmime_add_part(struct mailmime * build_info,
		      struct mailmime * part)
{
  int r;

  if (build_info->mm_type == MAILMIME_MESSAGE) {
    build_info->mm_data.mm_message.mm_msg_mime = part;
    part->mm_parent_type = MAILMIME_MESSAGE;
    part->mm_parent = build_info;
  }
  else if (build_info->mm_type == MAILMIME_MULTIPLE) {
    r = clist_append(build_info->mm_data.mm_multipart.mm_mp_list, part);
    if (r != 0)
      return MAILIMF_ERROR_MEMORY;
    
    part->mm_parent_type = MAILMIME_MULTIPLE;
    part->mm_parent = build_info;
    part->mm_multipart_pos =
      clist_end(build_info->mm_data.mm_multipart.mm_mp_list);
  }
  else {
    return MAILIMF_ERROR_INVAL;
  }
  return MAILIMF_NO_ERROR;
}
示例#7
0
LIBETPAN_EXPORT
struct mailimap_set *
mailimap_set_new_single_item(struct mailimap_set_item * item)
{
  struct mailimap_set * set;
  clist * list;
  int r;
  
  list = clist_new();
  if (list == NULL)
    return NULL;
  
  r = clist_append(list, item);
  if (r < 0) {
    clist_free(list);
    return NULL;
  }
	  
  set = mailimap_set_new(list);
  if (set == NULL) {
    clist_free(list);
    return NULL;
  }

  return set;
}
/* PUBLIC */
void index_hint(Topform c)
{
  Topform h = find_equivalent_hint(c, Hints_idx);
  c->weight = 0;  /* this is used in hints degradation to count matches */
  if (h != NULL) {
    /* copy any bsub_hint_wt attrs from rundundant hint to the indexed hint */
    h->attributes = copy_int_attribute(c->attributes, h->attributes,
				       Bsub_wt_attr);
    if (Collect_labels) {
      /* copy any labels from rundundant hint to the indexed hint */
      h->attributes = copy_string_attribute(c->attributes, h->attributes,
					    label_att());
    }
    clist_append(c, Redundant_hints);
    Redundant_hints_count++;
    /*
    printf("redundant hint: "); f_clause(c);
    printf("      original: "); f_clause(h);
    */
  }
  else {
    Active_hints_count++;
    Hint_id_count++;
    c->id = Hint_id_count;  /* need IDs so that back_subsume() will work */
    lindex_update(Hints_idx, c, INSERT);
    if (Back_demod_hints)
      index_clause_back_demod(c, Back_demod_idx, INSERT);
  }
}  /* index_hint */
示例#9
0
static int get_list_folders(struct mailmh_folder * folder, clist ** result)
{
  unsigned int i;
  clist * list;
  char * new_filename;
  int res;
  int r;

  list = * result;

  new_filename = strdup(folder->fl_filename);
  if (new_filename == NULL) {
    res = MAIL_ERROR_MEMORY;
    goto free;
  }

  r = mailmh_folder_update(folder);

  switch (r) {
  case MAILMH_NO_ERROR:
    break;

  default:
    res = mhdriver_mh_error_to_mail_error(r);
    free(new_filename);
    goto free;
  }

  r = clist_append(list, new_filename);
  if (r < 0) {
    free(new_filename);
    res = MAIL_ERROR_MEMORY;
    goto free;
  }
  
  if (folder->fl_subfolders_tab != NULL) {
    for(i = 0 ; i < carray_count(folder->fl_subfolders_tab) ; i++) {
      struct mailmh_folder * subfolder;

      subfolder = carray_get(folder->fl_subfolders_tab, i);

      r = get_list_folders(subfolder, &list);
      if (r != MAIL_NO_ERROR) {
		    free(new_filename);
	res = MAIL_ERROR_MEMORY;
	goto free;
      }
    }
  }

  * result = list;
  
  free(new_filename);
  return MAIL_NO_ERROR;

 free:
  clist_foreach(list, (clist_func) free, NULL);
  clist_free(list);
  return res;
}
示例#10
0
LIBETPAN_EXPORT
int mailfolder_connect(struct mailfolder * folder)
{
  mailsession * session;
  int res;
  int r;
  
  if (folder->fld_storage == NULL) {
    res = MAIL_ERROR_INVAL;
    goto err;
  }

  if (folder->fld_storage->sto_session == NULL) {
    r = mailstorage_connect(folder->fld_storage);
    if (r != MAIL_NO_ERROR) {
      res = r;
      goto err;
    }
  }

  if (folder->fld_session != NULL) {
    if ((folder->fld_pathname != NULL) && (folder->fld_shared_session)) {
      if (folder->fld_session->sess_driver->sess_select_folder != NULL) {
        r = mailsession_select_folder(folder->fld_session,
            folder->fld_pathname);
        if (r != MAIL_NO_ERROR) {
          res = r;
          goto err;
        }
      }
    }

    return MAIL_NO_ERROR;
  }
  
  r = mailstorage_get_folder(folder->fld_storage, folder->fld_pathname,
      &session);
  if (r != MAIL_NO_ERROR) {
    res = r;
    goto err;
  }
  folder->fld_session = session;
  folder->fld_shared_session = (session == folder->fld_storage->sto_session);
  if (folder->fld_shared_session) {
    r = clist_append(folder->fld_storage->sto_shared_folders, folder);
    if (r < 0) {
      folder->fld_session = NULL;
      res = MAIL_ERROR_MEMORY;
      goto err;
    }
    folder->fld_pos = clist_end(folder->fld_storage->sto_shared_folders);
  }

  return MAIL_NO_ERROR;

err:
  return res;
}
示例#11
0
static clist * read_group_time_list(newsnntp * f)
{
  char * line;
  char * group_name;
  time_t date;
  char * email;
  clist * group_time_list;
  struct newsnntp_group_time * n;
  int r;

  group_time_list = clist_new();
  if (group_time_list == NULL)
    goto err;

  while (1) {
    char * p;
    char * remaining;
    
    line = read_line(f);
    
    if (line == NULL)
      goto free_list;

    if (mailstream_is_end_multiline(line))
      break;
    
    p = cut_token(line);
    if (p == NULL)
      continue;
      
    date = strtoul(p, &remaining, 10);

    p = remaining;
    parse_space(&p);

    email = p;
    
    group_name = line;
    
    n = group_time_new(group_name, date, email);
    if (n == NULL)
      goto free_list;
    
    r = clist_append(group_time_list, n);
    if (r < 0) {
      group_time_free(n);
      goto free_list;
    }
  }
  
  return group_time_list;

 free_list:
  group_time_list_free(group_time_list);
 err:
  return NULL;
}
示例#12
0
static clist * read_distrib_default_value_list(newsnntp * f)
{
  char * line;
  uint32_t weight;
  char * group_pattern;
  char * meaning;
  clist * distrib_default_value_list;
  struct newsnntp_distrib_default_value * n;
  int r;

  distrib_default_value_list = clist_new();
  if (distrib_default_value_list == NULL)
    goto err;

  while (1) {
    char * p;
    char * remaining;
      
    line = read_line(f);
    if (line == NULL)
      goto free_list;

    if (mailstream_is_end_multiline(line))
      break;

    p = line;

    weight = strtoul(p, &remaining, 10);
    p = remaining;
    parse_space(&p);
      
    p = cut_token(line);
    if (p == NULL)
      continue;

    meaning = p;
    group_pattern = line;

    n = distrib_default_value_new(weight, group_pattern, meaning);
    if (n == NULL)
      goto free_list;

    r = clist_append(distrib_default_value_list, n);
    if (r < 0) {
      distrib_default_value_free(n);
      goto free_list;
    }
  }

  return distrib_default_value_list;

 free_list:
  distrib_default_value_list_free(distrib_default_value_list);
 err:
  return NULL;
}
示例#13
0
static void prepare_mime_single(struct mailmime * mime)
{
  struct mailmime_single_fields single_fields;
  int encoding;
  int r;
  
  if (mime->mm_mime_fields != NULL) {
    mailmime_single_fields_init(&single_fields, mime->mm_mime_fields,
        mime->mm_content_type);
    if (single_fields.fld_encoding != NULL) {
      encoding = single_fields.fld_encoding->enc_type;
      switch (encoding) {
      case MAILMIME_MECHANISM_8BIT:
      case MAILMIME_MECHANISM_7BIT:
      case MAILMIME_MECHANISM_BINARY:
        single_fields.fld_encoding->enc_type =
          MAILMIME_MECHANISM_QUOTED_PRINTABLE;
        break;
      }
    }
    else {
      struct mailmime_mechanism * mechanism;
      struct mailmime_field * field;
      
      mechanism =
        mailmime_mechanism_new(MAILMIME_MECHANISM_QUOTED_PRINTABLE, NULL);
      if (mechanism == NULL)
        return;
      
      field = mailmime_field_new(MAILMIME_FIELD_TRANSFER_ENCODING,
          NULL, mechanism, NULL, NULL, 0, NULL, NULL, NULL);
      if (field == NULL) {
        mailmime_mechanism_free(mechanism);
        return;
      }
      
      r = clist_append(mime->mm_mime_fields->fld_list, field);
      if (r < 0) {
        mailmime_field_free(field);
        return;
      }
    }
  }
  
  if (mime->mm_type == MAILMIME_SINGLE) {
    switch (mime->mm_data.mm_single->dt_encoding) {
    case MAILMIME_MECHANISM_8BIT:
    case MAILMIME_MECHANISM_7BIT:
    case MAILMIME_MECHANISM_BINARY:
      mime->mm_data.mm_single->dt_encoding =
        MAILMIME_MECHANISM_QUOTED_PRINTABLE;
      mime->mm_data.mm_single->dt_encoded = 0;
      break;
    }
  }
}
示例#14
0
static inline size_t clist_update(gui::control_list_t<T> *list, uint32_t id, T const &state)
{
    size_t index = 0;
    if (clist_find(list, id, &index))
    {
        list->State[index] = state;
        return index;
    }
    else return clist_append(list, id, state);
}
示例#15
0
struct mailmime_content *
mailmime_content_dup(struct mailmime_content * content)
{
  clist * list;
  struct mailmime_type * type;
  int r;
  struct mailmime_content * dup_content;
  char * subtype;

  type = mailmime_type_dup(content->ct_type);
  if (type == NULL)
    goto err;
  
  subtype = strdup(content->ct_subtype);
  if (subtype == NULL)
    goto free_type;
  
  list = clist_new();
  if (list == NULL)
    goto free_subtype;
  
  if (content->ct_parameters != NULL) {
    clistiter * cur;
    
    for(cur = clist_begin(content->ct_parameters) ;
        cur != NULL ; cur = clist_next(cur)) {
      struct mailmime_parameter * param;
      
      param = mailmime_parameter_dup(clist_content(cur));
      if (param == NULL)
        goto free_list;
      
      r = clist_append(list, param);
      if (r < 0) {
        mailmime_parameter_free(param);
        goto free_list;
      }
    }
  }
  
  dup_content = mailmime_content_new(type, subtype, list);
  if (dup_content == NULL)
    goto free_list;

  return dup_content;
  
 free_list:
  clist_foreach(list, (clist_func) mailmime_parameter_free, NULL);
 free_subtype:
  free(subtype);
 free_type:
  mailmime_type_free(type);
 err:
  return NULL;
}
示例#16
0
void test_clist(void)
{
    /* CU_ASSERT(NULL == ex_path_normalize(NULL)); */
    int i = 0;
    int test_cnt = 10000;
    clist *list = clist_new();

    CU_ASSERT(0 == clist_len(list));
    for(i = 0; i < test_cnt; ++i) {
        clist_append(list, cobj_int_new(i));
    }

    CU_ASSERT(test_cnt == clist_len(list));
    CU_ASSERT(false == clist_is_empty(list));
    CU_ASSERT(0 == cobj_int_val(clist_at_obj(list, 0)));
    CU_ASSERT(1 == cobj_int_val(clist_at_obj(list, 1)));
    CU_ASSERT(test_cnt - 1 == cobj_int_val(clist_at_obj(list, test_cnt - 1)));

    for(i = 0; i < test_cnt; ++i) {
        void *obj = clist_pop_front(list);
        CU_ASSERT(i == cobj_int_val(obj));
        cobj_free(obj);
    }
    CU_ASSERT(0 == clist_len(list));
    CU_ASSERT(true == clist_is_empty(list));

    for(i = 0; i < test_cnt; ++i) {
        clist_append(list, cobj_int_new(i));
    }
    clist_clear(list);
    CU_ASSERT(0 == clist_len(list));
    for(i = 0; i < test_cnt; ++i) {
        clist_append(list, cobj_int_new(i));
    }

    clist_node *node = NULL;
    void *obj = NULL;
    i = 0;
    clist_foreach_val(list, node, obj) {
        CU_ASSERT(i == cobj_int_val(obj));
        ++i;
    }
示例#17
0
int mailmime_fields_add(struct mailmime_fields * fields,
			struct mailmime_field * field)
{
  int r;

  r = clist_append(fields->fld_list, field);
  if (r < 0)
    return MAILIMF_ERROR_MEMORY;

  return MAILIMF_NO_ERROR;
}
示例#18
0
int mailimap_flag_list_add(struct mailimap_flag_list * flag_list,
		struct mailimap_flag * f)
{
  int r;
  
  r = clist_append(flag_list->fl_list, f);
  if (r < 0)
    return MAILIMAP_ERROR_MEMORY;
  
  return MAILIMAP_NO_ERROR;
}
示例#19
0
static
Stree stree_insert(Stree s, Topform c)
{
  if (s == NULL) {
    s = get_stree();
    s->weight = c->weight;
    s->clauses = clist_init("clauses_by_weight");
    clist_append(c, s->clauses);
  }
  else if (c->weight == s->weight) {
    clist_append(c, s->clauses);
  }
  else if (c->weight < s->weight)
    s->left = stree_insert(s->left, c);
  else
    s->right = stree_insert(s->right, c);
  s->greatest_id = c->id;  /* clauses always inserted with increasing IDs */
  s->n++;
  return s;
}  /* stree_insert */
示例#20
0
int mailimap_set_add(struct mailimap_set * set,
                     struct mailimap_set_item * set_item)
{
  int r;
  
  r = clist_append(set->set_list, set_item);
  if (r < 0)
    return MAILIMAP_ERROR_MEMORY;
  
  return MAILIMAP_NO_ERROR;
}
示例#21
0
void test_clist_sort(void)
{
  int items[] = {5, 10, 23, 12, 1,
                 91, 32, 12, 3, 2};
#define NUM_ELEMENTS 10
  struct clist list;
  int ret = clist_init(&list, match_function, free_destroy_function, CLIST_UNSORTED);
  struct key *k = NULL;
  int ctr = 0;
  for (; ctr<NUM_ELEMENTS; ctr++)
  {
    k = (struct key*)malloc(sizeof(struct key));
    k->id = items[ctr];
    printf("adding id: %i\n", k->id);
    ret = clist_append(&list, (void *)k);
    CU_ASSERT(ret==CLIST_TRUE);
  }

/*traverse list before sort*/
  struct clist_iterator *it = malloc(sizeof(struct clist_iterator));
  ret = clist_get_iterator(&list, it, 0);
  CU_ASSERT(ret==CLIST_TRUE);

  ret = clist_iterate(&list, it, (void **)&k, 0);
  CU_ASSERT(ret==CLIST_TRUE);
  ctr = 0;
  do
  {
    printf("k->id: %i\n", k->id);
    ctr ++;
  } while (clist_iterate(&list, it, (void **)&k, 1)==CLIST_TRUE);
  CU_ASSERT(ctr==NUM_ELEMENTS);
  
  clist_qsort(&list, ASCENDING);

/*traverse list after sort*/
  ret = clist_get_iterator(&list, it, 0);
  CU_ASSERT(ret==CLIST_TRUE);
  ret = clist_iterate(&list, it, (void **)&k, 0);
  CU_ASSERT(ret==CLIST_TRUE);
  ctr = 0;
  int prev = k->id;;
  do
  {
    printf("k->id: %i, prev: %i\n", k->id, prev);
    CU_ASSERT(prev<=k->id);
    prev = k->id;
    ctr ++;
  } while (clist_iterate(&list, it, (void **)&k, 1)==CLIST_TRUE);
  CU_ASSERT(ctr==NUM_ELEMENTS);
  free(it);
  
  clist_destroy(&list);
}
示例#22
0
文件: peerman.c 项目: aido/picocoin
static void __peerman_add(struct peer_manager *peers, struct peer *peer,
			  bool prepend_front)
{
	bn_group(peer->group, &peer->group_len, peer->addr.ip);

	if (prepend_front)
		peers->addrlist = clist_prepend(peers->addrlist, peer);
	else
		peers->addrlist = clist_append(peers->addrlist, peer);

	bp_hashtab_put(peers->map_addr, peer->addr.ip, peer);
}
示例#23
0
static struct mailmime * build_body_text(char * text)
{
  struct mailmime_fields * mime_fields;
  struct mailmime * mime_sub;
  struct mailmime_content * content;
  struct mailmime_parameter * param;
  int r;

  /* text/plain part */

  mime_fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT);
  if (mime_fields == NULL) {
    goto err;
  }

  content = mailmime_content_new_with_str("text/plain");
  if (content == NULL) {
    goto free_fields;
  }

  param = mailmime_param_new_with_data("charset", DEST_CHARSET);
  if (param == NULL) {
    goto free_content;
  }

  r = clist_append(content->ct_parameters, param);
  if (r < 0) {
    mailmime_parameter_free(param);
    goto free_content;
  }

  mime_sub = mailmime_new_empty(content, mime_fields);
  if (mime_sub == NULL) {
    goto free_content;
  }

  r = mailmime_set_body_text(mime_sub, text, strlen(text));
  if (r != MAILIMF_NO_ERROR) {
    goto free_mime;
  }

  return mime_sub;

 free_mime:
  mailmime_free(mime_sub);
  goto err;
 free_content:
  mailmime_content_free(content);
 free_fields:
  mailmime_fields_free(mime_fields);
 err:
  return NULL;
}
示例#24
0
static int mailprivacy_smime_add_encryption_id(struct mailprivacy * privacy,
    mailmessage * msg, char * encryption_id)
{
  clist * encryption_id_list;
  int r;
  int res;
  
  LOCK();
  
  res = -1;
  
  encryption_id_list = get_list(privacy, msg);
  if (encryption_id_list == NULL) {
    if (encryption_id_hash == NULL)
      encryption_id_hash = chash_new(CHASH_DEFAULTSIZE, CHASH_COPYKEY);
    
    if (encryption_id_hash != NULL) {
      encryption_id_list = clist_new();
      if (encryption_id_list != NULL) {
        chashdatum key;
        chashdatum value;
        
        key.data = &msg;
        key.len = sizeof(msg);
        value.data = encryption_id_list;
        value.len = 0;
        r = chash_set(encryption_id_hash, &key, &value, NULL);
        if (r < 0)
          clist_free(encryption_id_list);
      }
    }
  }
  
  encryption_id_list = get_list(privacy, msg);
  if (encryption_id_list != NULL) {
    char * str;
    
    str = strdup(encryption_id);
    if (str != NULL) {
      r = clist_append(encryption_id_list, str);
      if (r < 0) {
        free(str);
      }
      else {
        res = 0;
      }
    }
  }
  
  UNLOCK();
  
  return res;
}
示例#25
0
int
mailimap_search_key_multiple_add(struct mailimap_search_key * keys,
				 struct mailimap_search_key * key_item)
{
  int r;
	
  r = clist_append(keys->sk_data.sk_multiple, key_item);
  if (r < 0)
    return MAILIMAP_ERROR_MEMORY;

  return MAILIMAP_NO_ERROR;
}
LIBETPAN_EXPORT
int
mailimap_extension_register(struct mailimap_extension_api * extension)
{
  if (mailimap_extension_list == NULL) {
    mailimap_extension_list = clist_new();
    if (mailimap_extension_list == NULL)
      return MAILIMAP_ERROR_MEMORY;
  }

  return clist_append(mailimap_extension_list, extension);
}
示例#27
0
int
mailimap_fetch_type_new_fetch_att_list_add(struct mailimap_fetch_type *
    fetch_type,
    struct mailimap_fetch_att * fetch_att)
{
  int r;
	
  r = clist_append(fetch_type->ft_data.ft_fetch_att_list, fetch_att);
  if (r < 0)
    return MAILIMAP_ERROR_MEMORY;

  return MAILIMAP_NO_ERROR;
}
示例#28
0
/*!
 * \brief add/save a detected constraint to the list in memory
 * \param pg_constraint_t constraint
 */
static void db_postgres_constraint_add(pg_constraint_t *c)
{
	if (!pg_constraint) {
		pg_constraint = c;
		LM_DBG("adding init constraint [%s][%s][%s]\n", c->database.s,
				c->table.s, c->unique.s);
		clist_init(pg_constraint, next, prev);
	} else {
		LM_DBG("adding append constraint [%s][%s][%s]\n", c->database.s,
				c->table.s, c->unique.s);
		clist_append(pg_constraint, c, next, prev);
	}
}
示例#29
0
int
maildriver_env_list_to_msg_list_no_flags(struct mailmessage_list * env_list,
    clist ** result)
{
  clist * msg_list;
  int r;
  int res;
  unsigned int i;

  msg_list = clist_new();
  if (msg_list == NULL) {
    res = MAIL_ERROR_MEMORY;
    goto err;
  }

  for(i = 0 ; i < carray_count(env_list->msg_tab) ; i ++) {
    mailmessage * msg;

    msg = carray_get(env_list->msg_tab, i);

    if (msg->msg_flags == NULL) {
      uint32_t * pindex;

      pindex = malloc(sizeof(* pindex));
      if (pindex == NULL) {
	res = MAIL_ERROR_MEMORY;
	goto free_msg_list;
      }

      * pindex = msg->msg_index;

      r = clist_append(msg_list, pindex);
      if (r < 0) {
	free(pindex);
	res = MAIL_ERROR_MEMORY;
	goto free_msg_list;
      }

    }
  }

  * result = msg_list;

  return MAIL_NO_ERROR;

 free_msg_list:
  clist_foreach(msg_list, (clist_func) free, NULL);
  clist_free(msg_list);
 err:
  return res;
}
示例#30
0
static int mhdriver_lsub_folders(mailsession * session, const char * mb,
				 struct mail_list ** result)
{
  clist * subscribed;
  clist * lsub_result;
  clistiter * cur;
  struct mail_list * lsub;
  size_t length;
  int r;

  length = strlen(mb);

  subscribed = get_data(session)->mh_subscribed_list;

  lsub_result = clist_new();
  if (lsub_result == NULL)
    return MAIL_ERROR_MEMORY;

  for(cur = clist_begin(subscribed) ; cur != NULL ;
      cur = clist_next(cur)) {
    char * cur_mb;
    char * new_mb;
    
    cur_mb = clist_content(cur);

    if (strncmp(mb, cur_mb, length) == 0) {
      new_mb = strdup(cur_mb);
      if (new_mb == NULL)
	goto free_list;
      
      r = clist_append(lsub_result, new_mb);
      if (r < 0) {
	free(new_mb);
	goto free_list;
      }
    }
  }    
  
  lsub = mail_list_new(lsub_result);
  if (lsub == NULL)
    goto free_list;

  * result = lsub;

  return MAIL_NO_ERROR;

 free_list:
  clist_foreach(lsub_result, (clist_func) free, NULL);
  clist_free(lsub_result);
  return MAIL_ERROR_MEMORY;
}