int acl_create(acl_t *acl, const sockaddr_t* addr, acl_rule_t rule, void *val, unsigned flags) { if (!acl || !addr) { return ACL_ERROR; } /* Insert into skip list. */ acl_key_t *key = malloc(sizeof(acl_key_t)); if (key == NULL) { return ACL_ERROR; } memcpy(&key->addr, addr, sizeof(sockaddr_t)); key->rule = rule; key->val = val; if (flags & ACL_PREFER) { skip_insert(acl->rules_pref, &key->addr, key, 0); } else { skip_insert(acl->rules, &key->addr, key, 0); } return ACL_ACCEPT; }
char * test_search_finger() { unsigned int key; int num_found; int * hello; skip_t s = skip_init(free); while(skip_level(s) < 2){ hello = malloc(sizeof( int) * 10); key = (rand() % 200) + 1; skip_insert(s, key, hello); } //debug("NUM is %d",skip_length(s)); //debug("MADIT"); num_found = 0; void * response = NULL; while(num_found< skip_length(s)){ key = (rand() % 200) + 1; response = skip_finger_search(s, key); if(response){ num_found++; } } skip_destroy(s); return NULL; }
int fdset_set_watchdog(fdset_t* fdset, int fd, int interval) { fdset_base_t *base = (fdset_base_t*)fdset; if (base == NULL || base->atimes == NULL) { return -1; } /* Lift watchdog if interval is negative. */ if (interval < 0) { skip_remove(base->atimes, (void*)((size_t)fd), NULL, free); return 0; } /* Find if exists. */ timev_t *ts = NULL; ts = (timev_t*)skip_find(base->atimes, (void*)((size_t)fd)); if (ts == NULL) { ts = malloc(sizeof(timev_t)); if (ts == NULL) { return -1; } skip_insert(base->atimes, (void*)((size_t)fd), (void*)ts, NULL); } /* Update clock. */ if (time_now(ts) < 0) { return -1; } ts->tv_sec += interval; /* Only seconds precision. */ return 0; }
char * test_search() { char hello [] = "Hello"; char world [] = "World"; //char * fake_data = malloc(sizeof(*fake_data)*30); skip_t s = skip_init(NULL); // default free skip_insert(s, 9, hello); skip_insert(s, 11, world); skip_insert(s, 1, hello); skip_insert(s, 7, hello); skip_insert(s, 7, hello); char * r = NULL; r = skip_search(s, 7); mu_assert(r != NULL, "Search func failure"); mu_assert(skip_length(s) == 4, "Failed length"); r = NULL; r = skip_search(s, 9); mu_assert(r != NULL, "Search func failure"); r = NULL; r = skip_search(s, 1); mu_assert(r != NULL, "Search func failure"); r = NULL; r = skip_search(s, 2); mu_assert(r == NULL, "Search func failure"); char * z = NULL; z = skip_search(s, 70); mu_assert(z == NULL, "Failed search gave back an noninserted key"); skip_destroy(s); return NULL; }
char * test_delete_skip_list(){ unsigned int key; int * hello; skip_t s = skip_init(test_free); // wait till we jump to third level while(skip_level(s) < 3){ hello = malloc(sizeof( int) * 10); // give it a large space to avoid hangs key = (rand() % 1000) + 1; skip_insert(s, key, hello); } skip_destroy(s); return NULL; }
char * test_everything() { char hello [] = "Hello"; char * fake_data = malloc(sizeof(*fake_data)*30); skip_t s = skip_init(NULL); // default free skip_insert(s, 9, hello); skip_delete(s,1); char * z = NULL; z = skip_search(s, 70); mu_assert(z == NULL, "Failed search gave back an noninserted key"); free(fake_data); skip_destroy(s); return NULL; }
char * test_insert() { int rvalue; char hello [] = "Hello"; skip_t s = skip_init(NULL); skip_insert(s, 1, hello); skip_insert(s, 10, hello); mu_assert(skip_length(s) == 2, "Failed length"); skip_insert(s, 7, hello); skip_insert(s, 5, hello); skip_insert(s, 3, hello); rvalue = skip_insert(s, 3, hello); mu_assert(rvalue == 2, "Failed return Value"); skip_destroy(s); return NULL; }
char * test_delete_node() { unsigned int key = 0; int level; int length; int * hello; skip_t s = skip_init(free); // wait till we jump to third level while(skip_level(s) < 2){ hello = malloc(sizeof( int) * 10); // give it a large space to avoid hangs key = (rand() % 1000) + 1; skip_insert(s, key, hello); } length = skip_length(s); // immediately delete that node to make us go back down level = skip_level(s); skip_delete(s,key); mu_assert(skip_length(s) == length -1,"failed to decrease length" ) mu_assert(skip_level(s) <= level-1, "Failed to decrease level"); skip_destroy(s); return NULL; }