Exemplo n.º 1
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);

}
Exemplo n.º 2
0
clist_t * clist_init_from_refs(hpsig_t * hsig, frefs_t * refs)
{
	clist_t * cl;
	fref_t * fl;
	psig_t * sig;

	cl = (clist_t *)qalloc(sizeof(*cl));
	if (!cl) return NULL;

	cl->num = 0;
	cl->nmatch = 0;
	cl->sigs = NULL;
	cl->pos = NULL;
	cl->msigs = NULL;

	if (!refs) return cl;

	fl = refs->list;

	while(fl)
	{
		sig = hash_find_ea(hsig, fl->ea);
		if (sig && sig_get_matched_type(sig) == DIFF_UNMATCHED)
			clist_insert(cl, sig);

		fl = fl->next;
	}

	cl->pos = cl->sigs;

	return cl;
}
Exemplo n.º 3
0
void test_clist_insert(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);
  int ret = clist_append(&list, (void *)&k1);

  CU_ASSERT(ret == CLIST_TRUE);
  ret = clist_append(&list, (void *)&k2);
  CU_ASSERT(ret == CLIST_TRUE);
  ret = clist_insert(&list, (void *)&k3, 1);
  CU_ASSERT(ret == CLIST_TRUE);

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

  ret = clist_destroy(&list);
  CU_ASSERT(ret == CLIST_TRUE);
}
Exemplo n.º 4
0
/* resgiter a new flag name and associates it with pos
 * pos== -1 => any position will do 
 * returns flag pos on success (>=0)
 *         -1  flag is an alias for an already existing flag
 *         -2  flag already registered
 *         -3  mem. alloc. failure
 *         -4  invalid pos
 *         -5 no free flags */
int register_flag(char* name, int pos)
{
	struct flag_entry* e;
	int len;
	unsigned int r;
	static unsigned int crt_flag=0;
	unsigned int last_flag;
	unsigned int h;
	
	len=strlen(name);
	h=get_hash1_raw(name, len) & (FLAGS_NAME_HASH_ENTRIES-1);
	/* check if the name already exists */
	e=flag_search(&name2flags[h], name, len);
	if (e){
		LOG(L_ERR, "ERROR: register_flag: flag %.*s already registered\n",
					len, name);
		return -2;
	}
	/* check if there is already another flag registered at pos */
	if (pos!=-1){
		if ((pos<0) || (pos>MAX_FLAG)){
			LOG(L_ERR, "ERROR: register_flag: invalid flag %.*s "
					"position(%d)\n", len, name, pos);
			return -4;
		}
		if (registered_flags[pos]!=0){
			LOG(L_WARN, "WARNING: register_flag:  %.*s:  flag %d already in "
					"use under another name\n", len, name, pos);
			/* continue */
		}
	}else{
		/* alloc an empty flag */
		last_flag=crt_flag+(MAX_FLAG+1);
		for (; crt_flag!=last_flag; crt_flag++){
			r=crt_flag%(MAX_FLAG+1);
			if (registered_flags[r]==0){
				pos=r;
				break;
			}
		}
		if (pos==-1){
			LOG(L_ERR, "ERROR: register_flag: could not register %.*s"
					" - too many flags\n", len, name);
			return -5;
		}
	}
	registered_flags[pos]++;
	
	e=pkg_malloc(sizeof(struct flag_entry));
	if (e==0){
		LOG(L_ERR, "ERROR: register_flag: memory allocation failure\n");
		return -3;
	}
	e->name.s=name;
	e->name.len=len;
	e->no=pos;
	clist_insert(&name2flags[h], e, next, prev);
	return pos;
}
Exemplo n.º 5
0
int
session_provide_access(struct session *session, objref_t object, int interface)
{
    /* Search for the capability in our clists -- either the master or exact */
    cap_t cap = INVALID_CAP;

    assert(session != NULL);

    cap = iguana_get_cap(object, interface);
    if (IS_VALID_CAP(cap) == 0) {
        return 0;
    }
    return clist_insert(session->clist, cap) == 0;
}