int test_hash_table(void) { htbl t = htbl_init(NUM_SKEYS); // 64 ht_assert(!htbl_find(&t, "hello")); ht_assert(htbl_insert(&t, "hello")); ht_assert(htbl_find(&t, "hello")); ht_assert(!htbl_find(&t, "goodbye")); ht_assert(htbl_insert(&t, "goodbye")); ht_assert(htbl_find(&t, "goodbye")); ht_assert(htbl_delete(&t, "hello")); ht_assert(!htbl_find(&t, "hello")); ht_assert(htbl_find(&t, "goodbye")); for (uint32_t i = 0; i < NUM_SKEYS; ++i) { if (sprintf(skeys[i], "%" PRIu32, i) < 0) { goto error; } ht_assert(htbl_insert(&t, skeys[i])); } for (uint32_t i = 0; i < NUM_SKEYS; ++i) { //fprintf(stderr, "%" PRIu32 "\n", i); if (!htbl_find(&t, skeys[i])) { fprintf(stderr, "Error: %s %" PRIu32 "\n", skeys[i], i); goto error; } ht_assert(htbl_delete(&t, skeys[i])); ht_assert(!htbl_find(&t, skeys[i])); } htbl_destroy(t); return(0); error: htbl_destroy(t); return(-1); }
void http_option_set(http_ctx_t *c, http_opt_t o, void *v) { void *opt_val = NULL; char *opt_id = NULL; uint32_t opt_len = 0; bool copy = true; if(c == NULL) { libnet_error_set(LIBNET_E_INV_ARG); return; } opt_id = http_option_get_id(o); switch(o) { case LIBNET_HTTP_OPT_VERSION: { if(v == NULL) { break; } opt_len = http_option_translate_version((uint32_t)(v), &opt_val); } break; case LIBNET_HTTP_OPT_METHOD: { if(v == NULL) { break; } opt_len = http_option_translate_method((uint32_t)(v), &opt_val); } break; case LIBNET_HTTP_OPT_PARAM: case LIBNET_HTTP_OPT_AGENT: { if(v == NULL) { break; } opt_len = strlen((char *)v); opt_val = v; } break; case LIBNET_HTTP_OPT_FOLLOW: { copy = false; if(((bool)v) != true && ((bool)v) != false) { break; } opt_len = 1; opt_val = v; } break; case LIBNET_HTTP_OPT_CALLBACK_READ: { copy = false; opt_len = 4; opt_val = v; } break; default: return; } if(opt_len > 0) { /*printf("inserting '%s' -> '%s' of size %d %s\n", opt_id, opt_val, opt_len, copy == true ? "(copy)": ""); */ if(copy == true) { htbl_insert_copy(&c->options, opt_id, opt_val, opt_len); } else { htbl_insert(&c->options, opt_id, opt_val); } } }