Exemple #1
0
void gpgdo()
{
	if (*cgi("delpub"))
		delkey(cgi("pubkeyname"), 0);
	else if (*cgi("delsec") && *cgi("really"))
		delkey(cgi("seckeyname"), 1);
	else if (*cgi("sign"))
		signkey(cgi("pubkeyname"), cgi("seckeyname"),
			cgi("signlevel"));
	else if (*cgi("setdefault"))
		setdefault(cgi("seckeyname"));
}
Exemple #2
0
//test bucket_find_entry and bucket_overflow_remove
static void test_bucket_find_entry(struct lruhash *table)
{
    testkey *k1 = newkey(12);
    testkey *k2 = newkey(12 + 1024);
    testkey *k3 = newkey(14);
    testkey *k4 = newkey(12 + 1024*2);
    hashvalue_t h = simplehash(12);
    struct lruhash_bucket bucket;
    memset(&bucket, 0, sizeof(bucket));

    //remove from empty list
    bucket_overflow_remove(&bucket, &k1->entry);

    //find in empty list
    unit_assert(bucket_find_entry(table, &bucket, h, k1) == NULL);

    //insert
    bucket.overflow_list = &k1->entry;
    unit_assert(bucket_find_entry(table, &bucket, simplehash(13), k1) == NULL);
    unit_assert(k1->entry.hash == k2->entry.hash);
    unit_assert(bucket_find_entry(table, &bucket, h, k2) == NULL);
    unit_assert(bucket_find_entry(table, &bucket, h, k1) == &k1->entry);

    //remove
    bucket_overflow_remove(&bucket, &k1->entry);
    unit_assert(bucket_find_entry(table, &bucket, h, k1) == NULL);

    //insert multi
    unit_assert(k1->entry.hash == k4->entry.hash);
    k4->entry.overflow_next = &k1->entry;
    k3->entry.overflow_next = &k4->entry;
    bucket.overflow_list = &k3->entry;
    unit_assert(bucket_find_entry(table, &bucket, simplehash(13), k1) == NULL);
    unit_assert(k1->entry.hash == k2->entry.hash);
    unit_assert(bucket_find_entry(table, &bucket, h, k2) == NULL);
    unit_assert(bucket_find_entry(table, &bucket, h, k1) == &k1->entry);

    //remove mid
    unit_assert(bucket_find_entry(table, &bucket, k4->entry.hash, k4) == &k4->entry);
    bucket_overflow_remove(&bucket, &k4->entry);
    unit_assert(bucket_find_entry(table, &bucket, k4->entry.hash, k4) == NULL);

    //remove last
    bucket_overflow_remove(&bucket, &k1->entry);
    unit_assert(bucket_find_entry(table, &bucket, h, k1) == NULL);

    delkey(k1);
    delkey(k2);
    delkey(k3);
    delkey(k4);
}
Exemple #3
0
//test lru_front and lru_remove
static void test_lru(struct lruhash *table)
{
    testkey *k1 = newkey(12);
    testkey *k2 = newkey(14);
    lock_basic_lock(&table->lock);

    unit_assert(table->lru_head == NULL && table->lru_tail == NULL);
    lru_remove(table, &k1->entry);
    unit_assert(table->lru_head == NULL && table->lru_tail == NULL);

    //add one
    lru_front(table, &k1->entry);
    unit_assert( table->lru_head == &k1->entry && table->lru_tail == &k1->entry);

    //remove
    lru_remove(table, &k1->entry);
    unit_assert(table->lru_head == NULL && table->lru_tail == NULL);

    //add two
    lru_front(table, &k1->entry);
    unit_assert(table->lru_head == &k1->entry &&
                table->lru_tail == &k1->entry);
    lru_front(table, &k2->entry);
    unit_assert(table->lru_head == &k2->entry &&
                table->lru_tail == &k1->entry);

    //remove first
    lru_remove(table, &k2->entry);
    unit_assert(table->lru_head == &k1->entry &&
                table->lru_tail == &k1->entry);
    lru_front(table, &k2->entry);
    unit_assert(table->lru_head == &k2->entry &&
                table->lru_tail == &k1->entry);

    //remove last
    lru_remove(table, &k1->entry);
    unit_assert(table->lru_head == &k2->entry &&
                table->lru_tail == &k2->entry);

    //empty
    lru_remove(table, &k2->entry);
    unit_assert(table->lru_head == NULL && table->lru_tail == NULL);

    lock_basic_unlock(&table->lock);

    delkey(k1);
    delkey(k2);
}
/** test adding a random element */
static void
testremove(struct lruhash* table, testdata_t* ref[])
{
	int num = random() % HASHTESTMAX;
	testkey_t* key = newkey(num);
	lruhash_remove(table, myhash(num), key);
	ref[num] = NULL;
	delkey(key);
}
Exemple #5
0
//test remove a random element
static void testremove(struct lruhash *table, testdata *ref[])
{
    int num = random() % MAXHASH;
    testkey *key = newkey(num);
    lruhash_remove(table, simplehash(num), key);
    if (ref)
        ref[num] = NULL;
    delkey(key);
}
/** test lru_front lru_remove */
static void test_lru(struct lruhash* table)
{
	testkey_t* k = newkey(12);
	testkey_t* k2 = newkey(14);
	lock_quick_lock(&table->lock);

	unit_assert( table->lru_start == NULL && table->lru_end == NULL);
	lru_remove(table, &k->entry);
	unit_assert( table->lru_start == NULL && table->lru_end == NULL);

	/* add one */
	lru_front(table, &k->entry);
	unit_assert( table->lru_start == &k->entry && 
		table->lru_end == &k->entry);
	/* remove it */
	lru_remove(table, &k->entry);
	unit_assert( table->lru_start == NULL && table->lru_end == NULL);

	/* add two */
	lru_front(table, &k->entry);
	unit_assert( table->lru_start == &k->entry && 
		table->lru_end == &k->entry);
	lru_front(table, &k2->entry);
	unit_assert( table->lru_start == &k2->entry && 
		table->lru_end == &k->entry);
	/* remove first in list */
	lru_remove(table, &k2->entry);
	unit_assert( table->lru_start == &k->entry && 
		table->lru_end == &k->entry);
	lru_front(table, &k2->entry);
	unit_assert( table->lru_start == &k2->entry && 
		table->lru_end == &k->entry);
	/* remove last in list */
	lru_remove(table, &k->entry);
	unit_assert( table->lru_start == &k2->entry && 
		table->lru_end == &k2->entry);

	/* empty the list */
	lru_remove(table, &k2->entry);
	unit_assert( table->lru_start == NULL && table->lru_end == NULL);
	lock_quick_unlock(&table->lock);
	delkey(k);
	delkey(k2);
}
/** test adding a random element (unlimited range) */
static void
testremove_unlim(struct lruhash* table, testdata_t** ref)
{
	int num = random() % (HASHTESTMAX*10);
	testkey_t* key = newkey(num);
	lruhash_remove(table, myhash(num), key);
	if(ref)
		ref[num] = NULL;
	delkey(key);
}
/** test adding a random element */
static void
testlookup(struct lruhash* table, testdata_t* ref[])
{
	int num = random() % HASHTESTMAX;
	testkey_t* key = newkey(num);
	struct lruhash_entry* en = lruhash_lookup(table, myhash(num), key, 0);
	testdata_t* data = en? (testdata_t*)en->data : NULL;
	if(en) {
		unit_assert(en->key);
		unit_assert(en->data);
	}
	if(0) log_info("lookup %d got %d, expect %d", num, en? data->data :-1,
		ref[num]? ref[num]->data : -1);
	unit_assert( data == ref[num] );
	if(en) { lock_rw_unlock(&en->lock); }
	delkey(key);
}
Exemple #9
0
//test lookup a random element
static void testlookup(struct lruhash *table, testdata *ref[])
{
    int num = random() % MAXHASH;
    testkey *key = newkey(num);
    struct lruhash_entry *e = lruhash_lookup(table, simplehash(num), key);
    testdata *data = e ? (testdata *)e->data : NULL;

    if(e) {
        unit_assert(e->key);
        unit_assert(e->data);
        lock_basic_unlock(&e->lock);
    }
    if (ref)
        unit_assert(data == ref[num]);

    delkey(key);
}
/** test adding a random element (unlimited range) */
static void
testlookup_unlim(struct lruhash* table, testdata_t** ref)
{
	int num = random() % (HASHTESTMAX*10);
	testkey_t* key = newkey(num);
	struct lruhash_entry* en = lruhash_lookup(table, myhash(num), key, 0);
	testdata_t* data = en? (testdata_t*)en->data : NULL;
	if(en) {
		unit_assert(en->key);
		unit_assert(en->data);
	}
	if(0 && ref) log_info("lookup unlim %d got %d, expect %d", num, en ? 
		data->data :-1, ref[num] ? ref[num]->data : -1);
	if(data && ref) {
		/* its okay for !data, it fell off the lru */
		unit_assert( data == ref[num] );
	}
	if(en) { lock_rw_unlock(&en->lock); }
	delkey(key);
}
Exemple #11
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	TCHAR cap[16]=TEXT("");
	static HWND hCalcButton=0;

	switch (msg)
	{		
	case WM_CLOSE:
		DestroyWindow(hWnd);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	case WM_KEYDOWN:
		if (wParam==VK_RETURN){
			hCalc=FindWindow(TEXT("CalcFrame"),TEXT(" алькул¤тор"));
			//hCalcButton=FindWindowEx(hCalc,hCalcButton,TEXT("Button"),TEXT(""));
			//SetClassLong(hCalcButton,GCL_STYLE,CS_
			if (button_list.empty()){
			EnumChildWindows((HWND)hCalc, EnumChildProc, (LPARAM)hWnd);
			button_list.sort();
			}
			//ShowWindow(button_list.back(), SW_HIDE);
			SetTimer(hWnd,1,1000,NULL);
			
		}
		if (wParam==VK_ESCAPE) KillTimer(hWnd,1);
		break;
	case WM_TIMER:
		delkey(hCalc);
		break;
	default:
		return DefWindowProc(hWnd, msg, wParam, lParam);
	}

	return 0;
}
Exemple #12
0
void test_slabhash_delkey(void* key, void* ATTR_UNUSED(arg))
{
	delkey((struct slabhash_testkey*)key);
}
/** test bin_find_entry function and bin_overflow_remove */
static void
test_bin_find_entry(struct lruhash* table)
{
	testkey_t* k = newkey(12);
	testdata_t* d = newdata(128);
	testkey_t* k2 = newkey(12 + 1024);
	testkey_t* k3 = newkey(14);
	testkey_t* k4 = newkey(12 + 1024*2);
	hashvalue_t h = myhash(12);
	struct lruhash_bin bin;
	memset(&bin, 0, sizeof(bin));
	bin_init(&bin, 1);

	/* remove from empty list */
	bin_overflow_remove(&bin, &k->entry);

	/* find in empty list */
	unit_assert( bin_find_entry(table, &bin, h, k) == NULL );

	/* insert */
	lock_quick_lock(&bin.lock);
	bin.overflow_list = &k->entry;
	lock_quick_unlock(&bin.lock);

	/* find, hash not OK. */
	unit_assert( bin_find_entry(table, &bin, myhash(13), k) == NULL );

	/* find, hash OK, but cmp not */
	unit_assert( k->entry.hash == k2->entry.hash );
	unit_assert( bin_find_entry(table, &bin, h, k2) == NULL );

	/* find, hash OK, and cmp too */
	unit_assert( bin_find_entry(table, &bin, h, k) == &k->entry );

	/* remove the element */
	lock_quick_lock(&bin.lock);
	bin_overflow_remove(&bin, &k->entry);
	lock_quick_unlock(&bin.lock);
	unit_assert( bin_find_entry(table, &bin, h, k) == NULL );

	/* prepend two different elements; so the list is long */
	/* one has the same hash, but different cmp */
	lock_quick_lock(&bin.lock);
	unit_assert( k->entry.hash == k4->entry.hash );
	k4->entry.overflow_next = &k->entry;
	k3->entry.overflow_next = &k4->entry;
	bin.overflow_list = &k3->entry;
	lock_quick_unlock(&bin.lock);

	/* find, hash not OK. */
	unit_assert( bin_find_entry(table, &bin, myhash(13), k) == NULL );

	/* find, hash OK, but cmp not */
	unit_assert( k->entry.hash == k2->entry.hash );
	unit_assert( bin_find_entry(table, &bin, h, k2) == NULL );

	/* find, hash OK, and cmp too */
	unit_assert( bin_find_entry(table, &bin, h, k) == &k->entry );

	/* remove middle element */
	unit_assert( bin_find_entry(table, &bin, k4->entry.hash, k4) 
		== &k4->entry );
	lock_quick_lock(&bin.lock);
	bin_overflow_remove(&bin, &k4->entry);
	lock_quick_unlock(&bin.lock);
	unit_assert( bin_find_entry(table, &bin, k4->entry.hash, k4) == NULL);

	/* remove last element */
	lock_quick_lock(&bin.lock);
	bin_overflow_remove(&bin, &k->entry);
	lock_quick_unlock(&bin.lock);
	unit_assert( bin_find_entry(table, &bin, h, k) == NULL );

	lock_quick_destroy(&bin.lock);
	delkey(k);
	delkey(k2);
	delkey(k3);
	delkey(k4);
	deldata(d);
}