From: discomfitor Date: Sat, 16 Jul 2011 08:01:19 +0000 (+0000) Subject: clean up ecore-con server example: HTTP requires a seperator (\r\n in this case)... X-Git-Tag: accepted/2.0/20130306.224007~181^2~33 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6992cfd1de1e5cb4c94833a68f0f51bca90b2035;p=profile%2Fivi%2Fecore.git clean up ecore-con server example: HTTP requires a seperator (\r\n in this case) following each header line and a double separator between headers and body. additionally, content-length must be EXACTLY the length of the body, and must not include trailing garbage. snprintf use here is incorrect due to inconsistent behavior of snprintf, so we can lazily fall back to strlen since this is just a simple example git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/ecore@61421 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- diff --git a/src/examples/ecore_con_server_http_example.c b/src/examples/ecore_con_server_http_example.c index fec6a1a..d3fdeee 100644 --- a/src/examples/ecore_con_server_http_example.c +++ b/src/examples/ecore_con_server_http_example.c @@ -14,11 +14,10 @@ static const char response_template[] = "Server: Ecore_Con custom server\r\n" "Content-Length: %zd\r\n" "Content-Type: text/html; charset=UTF-8\r\n" -"Set-Cookie: MYCOOKIE=1; path=/; expires=%s" +"Set-Cookie: MYCOOKIE=1; path=/; expires=%s\r\n" "Set-Cookie: SESSIONCOOKIE=1; path=/\r\n" "\r\n" -"%s" -"\r\n\r\n"; +"%s"; struct _Client { int sdata; @@ -31,7 +30,6 @@ _add(void *data __UNUSED__, int type __UNUSED__, Ecore_Con_Event_Client_Add *ev) client->sdata = 0; static char buf[4096]; char welcome[] = "Welcome to Ecore_Con server!"; - int nbytes; time_t t; printf("Client with ip %s, port %d, connected = %d!\n", @@ -43,9 +41,9 @@ _add(void *data __UNUSED__, int type __UNUSED__, Ecore_Con_Event_Client_Add *ev) t = time(NULL); t += 60 * 60 * 24; - nbytes = snprintf(buf, sizeof(buf), response_template, sizeof(welcome), ctime(&t), welcome); + snprintf(buf, sizeof(buf), response_template, sizeof(welcome) - 1, ctime(&t), welcome); - ecore_con_client_send(ev->client, buf, nbytes); + ecore_con_client_send(ev->client, buf, strlen(buf)); ecore_con_client_flush(ev->client);