• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ INIT_LOCAL函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中INIT_LOCAL函数的典型用法代码示例。如果您正苦于以下问题:C++ INIT_LOCAL函数的具体用法?C++ INIT_LOCAL怎么用?C++ INIT_LOCAL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了INIT_LOCAL函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: t01_server_min

void t01_server_min(){
	INIT_LOCAL();
	
	onion *server=onion_new(0);
  onion_listen_point *lp=onion_buffer_listen_point_new();
  onion_add_listen_point(server,NULL,NULL,lp);
	onion_set_root_handler(server, onion_handler_static("Succedded", 200));
	
	onion_request *req=onion_request_new(lp);
	onion_request_write(req, "GET ",4);
	onion_request_write(req, "/",1);
	onion_request_write(req, " HTTP/1.1\r\n",11);
	
	onion_request_write(req, "\r\n",2);
	
	const char *buffer=onion_buffer_listen_point_get_buffer_data(req);
	
	FAIL_IF_EQUAL_STR(buffer,"");
	FAIL_IF_NOT_STRSTR(buffer, "HTTP/1.1 200 OK\r\n");
	FAIL_IF_NOT_STRSTR(buffer, "\r\nContent-Length: 9\r\n");
	FAIL_IF_NOT_STRSTR(buffer, "libonion");
	FAIL_IF_NOT_STRSTR(buffer, "\r\n\r\nSuccedded");
	
	onion_request_free(req);
	onion_free(server);
	
	END_LOCAL();
}
开发者ID:511860050,项目名称:onion,代码行数:28,代码来源:05-server.c


示例2: t01_handle_static_request

void t01_handle_static_request(){
	INIT_LOCAL();

	char ok;
	onion *server=onion_new(0);
	onion_listen_point *lp=onion_buffer_listen_point_new();
	onion_add_listen_point(server, NULL, NULL, lp);
	
	onion_request *request=onion_request_new(lp);
	FILL(request,"GET / HTTP/1.1\n");
	
	onion_handler *handler=onion_handler_static("Not ready",302);
	FAIL_IF_NOT(handler);
	onion_set_root_handler(server, handler);
	
	onion_response *response=onion_response_new(request);
	ok=onion_handler_handle(handler, request, response);
	FAIL_IF_NOT_EQUAL(ok, OCS_PROCESSED);
	onion_response_free(response);

	const char *buffer=onion_buffer_listen_point_get_buffer_data(request);
	FAIL_IF_EQUAL_STR(buffer,"");
	FAIL_IF_NOT_STRSTR(buffer, "HTTP/1.1 302 REDIRECT\r\n");
	FAIL_IF_NOT_STRSTR(buffer, "\r\nContent-Length: 9\r\n");
	FAIL_IF_NOT_STRSTR(buffer, "libonion");
	FAIL_IF_STRSTR(buffer, "License: AGPL"); // License is now LGPL, no need to advertise
	FAIL_IF_STRSTR(buffer, "License");
	FAIL_IF_NOT_STRSTR(buffer, "\r\n\r\nNot ready");
	
	onion_request_free(request);
	onion_free(server);
	
	END_LOCAL();
}
开发者ID:511860050,项目名称:onion,代码行数:34,代码来源:04-handler.c


示例3: t01_codecs_base64_decode

void t01_codecs_base64_decode(){
	INIT_LOCAL();
	{
	/// Text from wikipedia. Leviathan by Hobbes.
	char *orig ="dGVzdDphYWE=";
	char *realtext="test:aaa";
	
	char *res=onion_base64_decode(orig, NULL);
	FAIL_IF_NOT_EQUAL_STR(res,realtext);
	free(res);
	}
	{
	/// Text from wikipedia. Leviathan by Hobbes.
	char *orig ="TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz\n"
							"IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg\n"
							"dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu\n"
							"dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo\n"
							"ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=\n";
	char *realtext="Man is distinguished, not only by his reason, but by this singular passion from other animals,"
								 " which is a lust of the mind, that by a perseverance of delight in the continued and"
								 " indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.";
	
	int l;
	char *res=onion_base64_decode(orig, &l);
	//fprintf(stderr,"l %d len %ld\n",l,strlen(realtext));
	FAIL_IF_NOT_EQUAL(l,strlen(realtext));
	FAIL_IF_NOT_EQUAL_STR(res,realtext);
	free(res);
	}
	END_LOCAL();
}
开发者ID:Andrepuel,项目名称:onion,代码行数:31,代码来源:07-codecs.c


示例4: t05_post_content_json

void t05_post_content_json(){
	INIT_LOCAL();

	onion *server=onion_new(0);
	onion_listen_point *lp=onion_buffer_listen_point_new();
	json_response post_json = { 0 };
	
	onion_add_listen_point(server,NULL,NULL,lp);
	onion_set_root_handler(server, onion_handler_new((void*)&post_json_check,&post_json,NULL));
	
	onion_request *req=onion_request_new(lp);
#define POST_HEADER "POST / HTTP/1.1\nContent-Type: application/json\nContent-Length: %d\n\n"
	char tmp[1024];
	int json_length=sizeof(JSON_EXAMPLE);
	ONION_DEBUG("Post size is about %d",json_length);
	snprintf(tmp, sizeof(tmp), POST_HEADER, json_length);
// 	ONION_DEBUG("%s",tmp);
	onion_request_write(req,tmp,strlen(tmp));
	onion_request_write(req,JSON_EXAMPLE,json_length);
// 	ONION_DEBUG("%s",JSON_EXAMPLE);
	
	FAIL_IF_NOT_EQUAL_INT(post_json.processed, 2);
	
	onion_request_free(req);
	onion_free(server);
	
	END_LOCAL();
}
开发者ID:Scarberian,项目名称:onion,代码行数:28,代码来源:08-post.c


示例5: t08_server_with_error_404

void t08_server_with_error_404(){
	INIT_LOCAL();
	onion *server=onion_new(0);
  onion_listen_point *lp=onion_buffer_listen_point_new();
  onion_add_listen_point(server,NULL,NULL,lp);
	onion_url *urls=onion_url_new();
	onion_set_root_handler(server, onion_url_to_handler(urls));
	
	onion_request *req=onion_request_new(lp);
#define S "GET / HTTP/1.1"
	onion_request_write(req, S,sizeof(S)-1); // send it all, but the final 0.
#undef S
	const char *buffer=onion_buffer_listen_point_get_buffer_data(req);
	FAIL_IF_NOT_EQUAL_STR(buffer,"");
	onion_request_write(req, "\n",1); // finish this request. no \n\n before to check possible bugs.
	onion_request_write(req, "\n",1); // finish this request. no \n\n before to check possible bugs. The last \n was not processed, as was overflowing.
	
	buffer=onion_buffer_listen_point_get_buffer_data(req);
	FAIL_IF_EQUAL_STR(buffer,"");
	FAIL_IF_NOT_STRSTR(buffer, "HTTP/1.1 404 NOT FOUND\r\n");
	FAIL_IF_NOT_STRSTR(buffer, "libonion");

	onion_request_free(req);
	onion_free(server);

	END_LOCAL();
}
开发者ID:511860050,项目名称:onion,代码行数:27,代码来源:05-server.c


示例6: t16_soft_dup_dict_in_dict

void t16_soft_dup_dict_in_dict(){
	INIT_LOCAL();

	onion_dict *orig=onion_dict_new();

	char tmp[9];
	int i;
	for (i=0;i<256;i++){
		sprintf(tmp,"%08X",rand());
		onion_dict_add(orig, tmp, tmp, OD_DUP_ALL);
	}
	onion_dict_add(orig, "0", "no frees", 0);

	onion_dict *subdict=onion_dict_new();
	onion_dict_add(subdict,"subdict","test",0);
	onion_dict_add(orig, "subdict", subdict, OD_DICT|OD_FREE_VALUE);

	onion_dict *dest=onion_dict_dup(orig);

	FAIL_IF_NOT(orig==dest);

	/// Check they have exactly the same keys.
	onion_dict_preorder(orig, cmpdict, dest);
	onion_dict_preorder(dest, cmpdict, orig);

	onion_dict_free(orig);
	onion_dict_free(dest);

	END_LOCAL();
}
开发者ID:1514louluo,项目名称:onion,代码行数:30,代码来源:01-hash.c


示例7: t04_server_overflow

void t04_server_overflow(){
	INIT_LOCAL();
	onion *server=onion_new(0);
  onion_listen_point *lp=onion_buffer_listen_point_new();
  onion_add_listen_point(server,NULL,NULL,lp);
	onion_set_root_handler(server, onion_handler_static("Succedded", 200));
	
	onion_block *long_req=onion_block_new();
	
	onion_block_add_str(long_req,"GET / HTTP/1.1\n");
	int i;
	for(i=0;i<1000;i++){
		onion_block_add_str(long_req,"Header-1: This is header1 Header-2: This is header 2 ");
	}
	onion_request *req=onion_request_new(lp);
	onion_request_write(req, onion_block_data(long_req),onion_block_size(long_req)-1); // send it all, but the final 0.
	const char *buffer=onion_buffer_listen_point_get_buffer_data(req);
	FAIL_IF_NOT_EQUAL_STR(buffer,"");
	onion_request_write(req, "\n\n",2); // finish this request. no \n\n before to check possible bugs.

	buffer=onion_buffer_listen_point_get_buffer_data(req);
	FAIL_IF_EQUAL_STR(buffer,"");
	FAIL_IF_NOT_STRSTR(buffer, "HTTP/1.1 200 OK\r\n");
	FAIL_IF_NOT_STRSTR(buffer, "\r\nContent-Length: 9\r\n");
	FAIL_IF_NOT_STRSTR(buffer, "libonion");
	FAIL_IF_NOT_STRSTR(buffer, "\r\n\r\nSuccedded");

	onion_block_free(long_req);
	onion_request_free(req);
	onion_free(server);

	END_LOCAL();
}
开发者ID:Andrepuel,项目名称:onion,代码行数:33,代码来源:05-server.c


示例8: t06_empty

void t06_empty(){
	INIT_LOCAL();

	onion *server=onion_new(0);
	onion_add_listen_point(server,NULL,NULL,onion_buffer_listen_point_new());
	onion_request *request;
	char buffer[4096];
	memset(buffer,0,sizeof(buffer));
	
	request=onion_request_new(server->listen_points[0]);
	onion_response *response=onion_response_new(request);
	
// 	onion_response_write_headers(response);
	
	onion_response_flush(response);
	onion_response_free(response);

	buffer[sizeof(buffer)-1]=0;
	strncpy(buffer,onion_buffer_listen_point_get_buffer_data(request),sizeof(buffer)-1);
	onion_request_free(request);
	onion_free(server);
	
	FAIL_IF_NOT_STRSTR(buffer, "Server:");
	FAIL_IF_NOT_STRSTR(buffer, "Content-Type:");
	
// 	ONION_DEBUG(buffer);

	END_LOCAL();
}
开发者ID:SEI-AMS,项目名称:onion,代码行数:29,代码来源:03-response.c


示例9: t01_create_add_free

void t01_create_add_free(){
	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 /");

	// 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();
}
开发者ID:1514louluo,项目名称:onion,代码行数:26,代码来源:01-hash.c


示例10: t02_full_cycle_http10

void t02_full_cycle_http10(){
	INIT_LOCAL();
	
	onion *server=onion_new(0);
	onion_add_listen_point(server,NULL,NULL,onion_buffer_listen_point_new());
	onion_request *request;
	char buffer[4096];
	memset(buffer,0,sizeof(buffer));
	
	request=onion_request_new(server->listen_points[0]);
	
	onion_response *response=onion_response_new(request);
	
	onion_response_set_length(response, 30);
	FAIL_IF_NOT_EQUAL(response->length,30);
	onion_response_write_headers(response);
	
	onion_response_write0(response,"123456789012345678901234567890");
	
	FAIL_IF_NOT_EQUAL(response->sent_bytes,30);
	
	onion_response_free(response);
	strncpy(buffer,onion_buffer_listen_point_get_buffer_data(request),sizeof(buffer));
	onion_request_free(request);
	onion_free(server);
	
	FAIL_IF_NOT_STRSTR(buffer, "HTTP/1.0 200 OK\r\n");
	FAIL_IF_NOT_STRSTR(buffer, "Connection: Keep-Alive\r\n");
	FAIL_IF_NOT_STRSTR(buffer, "Content-Length: 30\r\n");
	FAIL_IF_NOT_STRSTR(buffer, "Server: libonion");
	FAIL_IF_NOT_STRSTR(buffer, "coralbits");
	FAIL_IF_NOT_STRSTR(buffer, "\r\n\r\n123456789012345678901234567890");
	
	END_LOCAL();
}
开发者ID:511860050,项目名称:onion,代码行数:35,代码来源:03-response.c


示例11: t05_printf

void t05_printf(){
	INIT_LOCAL();

	onion *server=onion_new(0);
	onion_add_listen_point(server,NULL,NULL,onion_buffer_listen_point_new());
	onion_request *request;
	char buffer[4096];
	memset(buffer,0,sizeof(buffer));
	
	request=onion_request_new(server->listen_points[0]);
	
	onion_response *response=onion_response_new(request);

	onion_response_printf(response, "%s %d %p", "Hello world", 123, NULL);
	onion_response_flush(response);
	onion_response_free(response);
	buffer[sizeof(buffer)-1]=0;
	strncpy(buffer,onion_buffer_listen_point_get_buffer_data(request),sizeof(buffer)-1);
	onion_request_free(request);
	onion_free(server);
	
	FAIL_IF_NOT_STRSTR(buffer, "Hello world 123 (nil)");
	
	END_LOCAL();
}
开发者ID:SEI-AMS,项目名称:onion,代码行数:25,代码来源:03-response.c


示例12: t10_repeated_header

void t10_repeated_header(){
	INIT_LOCAL();
	
	onion_request *req;
	int ok;
	
	onion_set_max_post_size(server, 1024);
	req=onion_request_new(custom_io);
	FAIL_IF_EQUAL(req,NULL);
	FAIL_IF_NOT_EQUAL(req->connection.fd, -1);
	
	{
		const char *query="GET / HTTP/1.0\n"
											"Content-Type: application/x-www-form-urlencoded\n"
											"Host: 127.0.0.1\n\r"
											"Content-Length: 24\n"
											"Accept-Language: en\n"
											"Content-Type: application/x-www-form-urlencoded-bis\n\n";
		
		ok=onion_request_write(req,query,strlen(query));
	}
	FAIL_IF_EQUAL(ok,OCS_INTERNAL_ERROR);
	FAIL_IF_NOT_EQUAL_STR(onion_request_get_header(req,"Host"),"127.0.0.1");
	FAIL_IF_NOT_EQUAL_STR(onion_request_get_header(req,"Content-Length"),"24");
	FAIL_IF_NOT_EQUAL_STR(onion_request_get_header(req,"Content-Type"),"application/x-www-form-urlencoded");

	
	onion_request_free(req);
	
	
	END_LOCAL();
}
开发者ID:Scarberian,项目名称:onion,代码行数:32,代码来源:02-request.c


示例13: t06_create_add_free_POST_toobig

void t06_create_add_free_POST_toobig(){
	INIT_LOCAL();
	
	onion_request *req;
	int ok;
	
	req=onion_request_new(custom_io);
	FAIL_IF_EQUAL(req,NULL);
	FAIL_IF_NOT_EQUAL(req->connection.fd, -1);
	
	onion_set_max_post_size(server, 10); // Very small limit
	
	const char *query="POST /myurl%20/is/very/deeply/nested?test=test&query2=query%202&more_query=%20more%20query+10 HTTP/1.0\n"
													"Host: 127.0.0.1\n\rContent-Length: 24\n"
													"Other-Header: My header is very long and with spaces...\r\n\r\npost_data=1&post_data2=2&post_data=1&post_data2=2";
	
	int i; // Straight write, with clean (keep alive like)
	for (i=0;i<10;i++){
		FAIL_IF_NOT_EQUAL(req->flags,0);
		ok=REQ_WRITE(req,query);
		
		FAIL_IF_NOT_EQUAL(ok,OCS_INTERNAL_ERROR);

		onion_request_clean(req);
		FAIL_IF_NOT_EQUAL(req->GET,NULL);
	}
	
	onion_request_free(req);
	
	END_LOCAL();
}
开发者ID:Scarberian,项目名称:onion,代码行数:31,代码来源:02-request.c


示例14: t06_codecs_c_unicode

void t06_codecs_c_unicode(){
	INIT_LOCAL();
	
	const char *text="\302Hola!";
	char *res=onion_c_quote_new(text);
	
	FAIL_IF_NOT_STRSTR(res,"\\302");
	FAIL_IF_NOT_STRSTR(res,"\\302Hola!");
	
	free(res);
	
	text="€";
	res=onion_c_quote_new(text);
	
	FAIL_IF_NOT_STRSTR(text,"€");
	FAIL_IF_NOT_EQUAL_STR(res,"\"\\342\\202\\254\"");
	
	free(res);

	text="\377";
	res=onion_c_quote_new(text);
	
	FAIL_IF_NOT_EQUAL_STR(res,"\"\\377\"");
	
	free(res);

	END_LOCAL();
}
开发者ID:Andrepuel,项目名称:onion,代码行数:28,代码来源:07-codecs.c


示例15: t02_server_full

void t02_server_full(){
	INIT_LOCAL();
	onion *server=onion_new(0);
  onion_listen_point *lp=onion_buffer_listen_point_new();
  onion_add_listen_point(server,NULL,NULL,lp);
	onion_set_root_handler(server, onion_handler_static("Succedded", 200));
	
	onion_request *req=onion_request_new(lp);
#define S "GET / HTTP/1.1\r\nHeader-1: This is header1\r\nHeader-2: This is header 2\r\n"
	onion_request_write(req, S,sizeof(S)-1); // send it all, but the final 0.
#undef S
	const char *buffer=onion_buffer_listen_point_get_buffer_data(req);
	FAIL_IF_NOT_EQUAL_STR(buffer,"");
	onion_request_write(req, "\n",1); // finish this request. no \n\n before to check possible bugs.

	buffer=onion_buffer_listen_point_get_buffer_data(req);
	
	FAIL_IF_EQUAL_STR(buffer,"");
	FAIL_IF_NOT_STRSTR(buffer, "HTTP/1.1 200 OK\r\n");
	FAIL_IF_NOT_STRSTR(buffer, "\r\nContent-Length: 9\r\n");
	FAIL_IF_NOT_STRSTR(buffer, "libonion");
	FAIL_IF_NOT_STRSTR(buffer, "\r\n\r\nSuccedded");

	onion_request_free(req);
	onion_free(server);

	END_LOCAL();
}
开发者ID:511860050,项目名称:onion,代码行数:28,代码来源:05-server.c


示例16: t12_dict_in_dict

void t12_dict_in_dict(){
	INIT_LOCAL();
	
	onion_dict *A=onion_dict_new();
	onion_dict *B=onion_dict_new();
	onion_dict *C=onion_dict_new();
	onion_dict *D=onion_dict_new();
	
	int i;
	for (i=0;i<16;i++){
		char tmp[9];
		sprintf(tmp,"%08X",rand());
		onion_dict_add(A, tmp, tmp, OD_DUP_ALL);
		sprintf(tmp,"%08X",rand());
		onion_dict_add(B, tmp, tmp, OD_DUP_ALL);
		sprintf(tmp,"%08X",rand());
		onion_dict_add(C, tmp, tmp, OD_DUP_ALL);
		sprintf(tmp,"%08X",rand());
		onion_dict_add(D, tmp, tmp, OD_DUP_ALL);
	}

	onion_dict_add(A, "B", B, OD_DICT|OD_FREE_VALUE);
	onion_dict_add(A, "C", C, OD_DICT|OD_FREE_VALUE);
	onion_dict_add(A, "D", D, OD_DICT|OD_FREE_VALUE);

	FAIL_IF_NOT_EQUAL((onion_dict*)onion_dict_get(A, "B"), NULL);
	FAIL_IF_NOT_EQUAL((onion_dict*)onion_dict_get(A, "C"), NULL);
	FAIL_IF_NOT_EQUAL((onion_dict*)onion_dict_get(A, "D"), NULL);

	FAIL_IF_NOT_EQUAL((onion_dict*)onion_dict_get_dict(A, "B"), B);
	FAIL_IF_NOT_EQUAL((onion_dict*)onion_dict_get_dict(A, "C"), C);
	FAIL_IF_NOT_EQUAL((onion_dict*)onion_dict_get_dict(A, "D"), D);
	
	{
		onion_block *tmpA=onion_dict_to_json(A);
		onion_block *tmpB=onion_dict_to_json(B);
		onion_block *tmpC=onion_dict_to_json(C);
		onion_block *tmpD=onion_dict_to_json(D);
		/*
		ONION_DEBUG("Json is: %s",tmpA);
		ONION_DEBUG("Json is: %s",tmpB);
		ONION_DEBUG("Json is: %s",tmpC);
		ONION_DEBUG("Json is: %s",tmpD);
		*/
		FAIL_IF_EQUAL( strstr(onion_block_data(tmpA), onion_block_data(tmpB)), NULL);
		FAIL_IF_EQUAL( strstr(onion_block_data(tmpA), onion_block_data(tmpC)), NULL);
		FAIL_IF_EQUAL( strstr(onion_block_data(tmpA), onion_block_data(tmpD)), NULL);
		onion_block_free(tmpA);
		onion_block_free(tmpB);
		onion_block_free(tmpC);
		onion_block_free(tmpD);
	}
	B=onion_dict_hard_dup(A);
	
	onion_dict_free(A);
	onion_dict_free(B);
	
	END_LOCAL();
}
开发者ID:511860050,项目名称:onion,代码行数:59,代码来源:01-hash.c


示例17: t07_codecs_html

void t07_codecs_html(){
	INIT_LOCAL();
	
	char *encoded=onion_html_quote("<\"Hello\">");
	FAIL_IF_NOT_EQUAL_STR( encoded, "&lt;&quot;Hello&quot;&gt;");
	free(encoded);
	
	END_LOCAL();
}
开发者ID:Andrepuel,项目名称:onion,代码行数:9,代码来源:07-codecs.c


示例18: t02_handle_generic_request

void t02_handle_generic_request(){
	INIT_LOCAL();

	onion *server=onion_new(0);
	onion_listen_point *lp=onion_buffer_listen_point_new();
	onion_add_listen_point(server, NULL, NULL, lp);
	
	onion_url *url=onion_url_new();
	int error;
	error=onion_url_add_handler(url, "^$", onion_handler_static("Not ready",302));
	FAIL_IF(error);

	error=onion_url_add_handler(url, "^a.*$", onion_handler_static("any",200));
	FAIL_IF(error);

	error=onion_url_add_static(url, "^.*", "Internal error", 500);
	FAIL_IF(error);

	onion_set_root_handler(server, onion_url_to_handler(url));
	
	onion_request *request;


	request=onion_request_new(lp);
	FILL(request,"GET / HTTP/1.1\n");
	onion_request_process(request);
	const char *buffer=onion_buffer_listen_point_get_buffer_data(request);
	FAIL_IF_NOT_STRSTR(buffer, "HTTP/1.1 302 REDIRECT\r\n");
	FAIL_IF_NOT_STRSTR(buffer, "Content-Length: 9\r\n");
	FAIL_IF_NOT_STRSTR(buffer, "\r\n\r\nNot ready");
	onion_request_free(request);
	
	// gives error, as such url does not exist.
	request=onion_request_new(lp);
	FILL(request,"GET /error HTTP/1.1\n");
	onion_request_process(request);
	buffer=onion_buffer_listen_point_get_buffer_data(request);
	ONION_DEBUG("<%s>", buffer);
	FAIL_IF_NOT_STRSTR(buffer, "HTTP/1.1 500 INTERNAL ERROR\r\n");
	FAIL_IF_NOT_STRSTR(buffer, "Content-Length: 14\r\n");
	FAIL_IF_NOT_STRSTR(buffer, "\r\n\r\nInternal error");
	onion_request_free(request);

	request=onion_request_new(lp);
	FILL(request,"GET /any HTTP/1.1\n");
	onion_request_process(request);
	buffer=onion_buffer_listen_point_get_buffer_data(request);
	FAIL_IF_NOT_STRSTR(buffer, "HTTP/1.1 200 OK\r\n");
	FAIL_IF_NOT_STRSTR(buffer, "Content-Length: 3\r\n");
	FAIL_IF_NOT_STRSTR(buffer, "\r\n\r\nany");
	onion_request_free(request);

	onion_free(server);

	END_LOCAL();
}
开发者ID:Andrepuel,项目名称:onion,代码行数:56,代码来源:04-handler.c


示例19: t03_create_and_free_a_lot_random

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();
}
开发者ID:511860050,项目名称:onion,代码行数:54,代码来源:01-hash.c


示例20: t01_url

void t01_url() {
  INIT_LOCAL();

  onion_url *url = onion_url_new();
  onion_url_add_handler(url, "^handler1.$",
                        onion_handler_new((onion_handler_handler) handler1,
                                          NULL, NULL));
  onion_url_add(url, "handler2/", handler2);
  onion_url_add_with_data(url, "^handler(3|4)/", handler3, NULL, NULL);

  onion_set_root_handler(server, onion_url_to_handler(url));

  onion_request *req = onion_request_new(onion_get_listen_point(server, 0));

#define R "GET /handler1/ HTTP/1.1\n\n"
  onion_request_write(req, R, sizeof(R));
  onion_request_process(req);
  FAIL_IF_NOT_EQUAL_INT(handler_called, 1);
  FAIL_IF_NOT_EQUAL_STR(urltxt, "");
  free(urltxt);
  urltxt = NULL;

  onion_request_clean(req);
  onion_request_write(req, "GET /handler2/ HTTP/1.1\n\n", sizeof(R));
  onion_request_process(req);
  FAIL_IF_NOT_EQUAL_INT(handler_called, 2);
  ONION_DEBUG("%s", urltxt);
  FAIL_IF_NOT_EQUAL_STR(urltxt, "");
  free(urltxt);
  urltxt = NULL;

  onion_request_clean(req);
  onion_request_write(req, "GET /handler3/hello HTTP/1.1\n\n", sizeof(R) + 5);
  onion_request_process(req);
  FAIL_IF_NOT_EQUAL_INT(handler_called, 3);
  FAIL_IF_NOT_EQUAL_STR(urltxt, "hello");
  free(urltxt);
  urltxt = NULL;

  handler_called = 0;
  onion_request_clean(req);
  onion_request_write(req, "GET /handler2/hello HTTP/1.1\n\n", sizeof(R) + 5);
  onion_request_process(req);
  FAIL_IF_NOT_EQUAL_INT(handler_called, 0);
  FAIL_IF_EQUAL_STR(urltxt, "");
  free(urltxt);
  urltxt = NULL;

  onion_request_free(req);
  onion_url_free(url);
  onion_set_root_handler(server, NULL);

  END_LOCAL();
}
开发者ID:davidmoreno,项目名称:onion,代码行数:54,代码来源:16-url.c



注:本文中的INIT_LOCAL函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ INIT_MINMAX函数代码示例发布时间:2022-05-30
下一篇:
C++ INIT_LIST函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap