コード例 #1
0
ファイル: 01-hash.c プロジェクト: 511860050/onion
void t04_create_and_free_a_dup(){
	INIT_LOCAL();
	onion_dict *dict;
	const char *value;
	
	dict=onion_dict_new();
	FAIL_IF_EQUAL(dict,NULL);

	// Get before anything in
	value=onion_dict_get(dict, "Request");
	FAIL_IF_NOT_EQUAL(value,NULL);

	// basic add
	onion_dict_add(dict, "Request", "GET /", OD_DUP_ALL);
	value=onion_dict_get(dict, "Request");
	FAIL_IF_NOT_EQUAL_STR(value,"GET /");

	onion_dict_add(dict, "Request", "GET /", OD_DUP_ALL);
	value=onion_dict_get(dict, "Request");
	FAIL_IF_NOT_EQUAL_STR(value,"GET /");
	
	// basic remove
	onion_dict_remove(dict, "Request");
	value=onion_dict_get(dict, "Request");
	FAIL_IF_NOT_EQUAL_STR(value,"GET /");
	
	// basic remove
	onion_dict_remove(dict, "Request");
	value=onion_dict_get(dict, "Request");
	FAIL_IF_NOT_EQUAL(value,NULL);

	onion_dict_free(dict);
	
	END_LOCAL();
}
コード例 #2
0
ファイル: 01-hash.c プロジェクト: 511860050/onion
char *t08_thread_read(onion_dict *d){
	char done=0;
	char *ret=NULL;
	while (!done){
		//ONION_DEBUG("Lock read");
		onion_dict_lock_write(d);
		//ONION_DEBUG("Got read lock");
		const char *test=onion_dict_get(d,"test");
		if (test){
			//ONION_DEBUG("Unlock");
			
			//onion_dict_lock_write(d);
			//ONION_DEBUG("Got write lock");
			char tmp[16];
			snprintf(tmp,16,"%d",onion_dict_count(d));
			onion_dict_remove(d,"test");
			onion_dict_add(d,tmp,"test",OD_DUP_ALL);
			ONION_DEBUG("Write answer %d", onion_dict_count(d));
			done=1;
			//ONION_DEBUG("Unlock");
			onion_dict_unlock(d);
			ret=(char*)1;
			break;
		}
		//ONION_DEBUG("Unlock");
		onion_dict_unlock(d);
		usleep(200);
	}
	//ONION_DEBUG("dict free");
	onion_dict_free(d);
	return ret;
}
コード例 #3
0
ファイル: mime.c プロジェクト: Sts0mrg0/onion
/**
 * @short Allow to update mime types.
 * 
 * User can add new mime types, or remove.
 */
void onion_mime_update(const char *extension, const char *mimetype){
	if (!onion_mime_dict)
		onion_mime_fill();
	
	if (mimetype)
		onion_dict_add(onion_mime_dict, extension, mimetype,  OD_DUP_ALL);
	else
		onion_dict_remove(onion_mime_dict, extension);
}
コード例 #4
0
ファイル: sessions_mem.c プロジェクト: MariadeAnton/onion
static void onion_sessions_mem_save(onion_sessions *sessions, const char *session_id, onion_dict *data){
	if (data==NULL){
		data=onion_dict_get_dict(sessions->data, session_id);
		if (data){
			onion_dict_remove(sessions->data, session_id);
		}
		return;
	}
	onion_dict_add(sessions->data, session_id, onion_dict_dup(data), OD_DUP_KEY|OD_FREE_VALUE|OD_DICT|OD_REPLACE);
}
コード例 #5
0
ファイル: 01-hash.c プロジェクト: 511860050/onion
void t03_create_and_free_a_lot_random(unsigned int n){
	INIT_LOCAL();
	onion_dict *dict;
	const char *value;
	unsigned int i;
	
	dict=onion_dict_new();
	FAIL_IF_EQUAL(dict,NULL);

	// Linear add
	for (i=0;i<n;i++){
		char key[16], val[16];
		sprintf(key,"key %d",R1(i));
		sprintf(val,"val %d",R2(i));
		
		onion_dict_add(dict, key, val, OD_DUP_ALL);
	}

	// Linear get
	for (i=0;i<n;i++){
		char key[16], val[16];
		sprintf(key,"key %d",R1(i));
		sprintf(val,"val %d",R2(i));
		
		value=onion_dict_get(dict, key);
		FAIL_IF_NOT_EQUAL_STR(val,value);
	}

	// remove all
	for (i=n;i>0;i--){
		char key[16];
		int removed;
		sprintf(key,"key %d",R1(i-1));
		//fprintf(stderr,"%s %d\n",key,i-1);
		removed=onion_dict_remove(dict, key);
		FAIL_IF_NOT_EQUAL(removed,1);
	}

	// check removed all
	for (i=0;i<n;i++){
		char key[16], val[16];
		sprintf(key,"key %d",R1(i));
		sprintf(val,"val %d",R1(i));
		
		value=onion_dict_get(dict, key);
		//fprintf(stderr,"%s %s\n",key,value);
		FAIL_IF_NOT_EQUAL(NULL,value);
		FAIL_IF_NOT_EQUAL_STR(NULL,value);
	}

	onion_dict_free(dict);
	
	END_LOCAL();
}
コード例 #6
0
ファイル: 03-response.c プロジェクト: Scarberian/onion
void t02_cookies(){
	INIT_LOCAL();
	
	onion_response *res=onion_response_new(NULL);
	onion_dict *h=onion_response_get_headers(res);
	
	onion_response_add_cookie(res, "key1", "value1", -1, NULL, NULL, 0);
	FAIL_IF_NOT_EQUAL_STR(onion_dict_get(h, "Set-Cookie"), "key1=value1");
	
	onion_dict_remove(h, "Set-Cookie");
	onion_response_add_cookie(res, "key2", "value2", -1, "/", "*.example.org", OC_HTTP_ONLY|OC_SECURE);
	FAIL_IF_NOT_EQUAL_STR(onion_dict_get(h, "Set-Cookie"), "key2=value2; path=/; domain=*.example.org; HttpOnly; Secure");

	onion_dict_remove(h, "Set-Cookie");
	onion_response_add_cookie(res, "key3", "value3", 0, "/", "*.example.org", OC_HTTP_ONLY|OC_SECURE);
	FAIL_IF_NOT_EQUAL_STR(onion_dict_get(h, "Set-Cookie"), "key3=value3; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=*.example.org; HttpOnly; Secure");
	
	onion_dict_remove(h, "Set-Cookie");
	onion_response_add_cookie(res, "key4", "value4", 60, "/", "*.example.org", OC_HTTP_ONLY|OC_SECURE);
	FAIL_IF_EQUAL_STR(onion_dict_get(h, "Set-Cookie"), "key4=value4; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=*.example.org; HttpOnly; Secure");
	FAIL_IF_EQUAL_STR(onion_dict_get(h, "Set-Cookie"), "key4=value4; domain=*.example.org; HttpOnly; path=/; Secure");
	
	int i;
	int valid_expires=0;
	char tmpdate[100];
	const char *setcookie=onion_dict_get(h, "Set-Cookie");
	for(i=59;i<62;i++){
		struct tm *tmp;
		time_t t=time(NULL) + i;
		tmp = localtime(&t);
		strftime(tmpdate, sizeof(tmpdate), "key4=value4; expires=%a, %d %b %Y %H:%M:%S %Z; path=/; domain=*.example.org; HttpOnly; Secure", tmp);
		ONION_DEBUG("\ntest  %s =? \nonion %s", tmpdate, setcookie);
		if (strcmp(tmpdate, setcookie)==0)
			valid_expires=1;
	}
	FAIL_IF_NOT(valid_expires);
	
	onion_response_free(res);
	
	END_LOCAL();
}
コード例 #7
0
ファイル: 01-hash.c プロジェクト: 511860050/onion
void t01_create_add_free_10(){
	INIT_LOCAL();
	onion_dict *dict;
	const char *value;
	
	dict=onion_dict_new();
	FAIL_IF_EQUAL(dict,NULL);

	// Get before anything in
	value=onion_dict_get(dict, "Request");
	FAIL_IF_NOT_EQUAL(value,NULL);

	// basic add
	int i;
	char tmp[256];
	for (i=0;i<10;i++){
		snprintf(tmp,sizeof(tmp),"%d",(i*13)%10);
		////ONION_DEBUG("add key %s",tmp);
		onion_dict_add(dict, tmp, "GET /", OD_DUP_ALL);
		value=onion_dict_get(dict, tmp);
		FAIL_IF_NOT_EQUAL_STR(value,"GET /");
		//onion_dict_print_dot(dict);
	}
	for (i=0;i<10;i++){
		snprintf(tmp,sizeof(tmp),"%d",i);
		////ONION_DEBUG("rm key %s",tmp);
		onion_dict_remove(dict, tmp);
		value=onion_dict_get(dict, tmp);
		FAIL_IF_NOT_EQUAL(value,NULL);
		//onion_dict_print_dot(dict);
	}
	
	onion_dict_free(dict);
	
	END_LOCAL();
}
コード例 #8
0
ファイル: dict.hpp プロジェクト: MariadeAnton/onion
		/**
		 * @short Removes an element from the dictionary.
		 */
		Dict &remove(const std::string &k){
			onion_dict_remove(ptr, k.c_str());
			return *this;
		}
コード例 #9
0
ファイル: dict.hpp プロジェクト: adnandzebic/onion
		/**
		 * @short Removes an element from the dictionary.
		 */
		void remove(const std::string &k){
			onion_dict_remove(ptr, k.c_str());
		}