test some primitives from http.c

svn:r739
This commit is contained in:
Niels Provos 2008-04-29 00:24:00 +00:00
parent 9485ff9a66
commit 72a3902e5c
3 changed files with 59 additions and 1 deletions

View File

@ -362,6 +362,17 @@ void evhttp_parse_query(const char *uri, struct evkeyvalq *);
*/
char *evhttp_htmlescape(const char *html);
/**
* Separate the host, port and path component from a URL.
*
* @param url the url for which to separate the components
* @param phost pointer in which to store the pointer to the host
* @param pport pointer in which to store the port number
* @param pfile pointer in which to store the pointer to the path
* @return 0 on success and -1 on failure
*/
int evhttp_hostportfile(char *url, char **phost, u_short *pport, char **pfile);
#ifdef __cplusplus
}
#endif

2
http.c
View File

@ -465,7 +465,7 @@ evhttp_make_header(struct evhttp_connection *evcon, struct evhttp_request *req)
}
}
/* Separated host, port and file from URI */
/* Separate host, port and file from URI */
int
evhttp_hostportfile(char *url, char **phost, u_short *pport, char **pfile)

View File

@ -1384,9 +1384,56 @@ http_connection_retry(void)
fprintf(stdout, "OK\n");
}
static void
http_primitives(void)
{
char *escaped;
char *host = NULL, *path = NULL;
unsigned short port = 0;
fprintf(stdout, "Testing HTTP Primitives: ");
escaped = evhttp_htmlescape("<script>");
if (strcmp(escaped, "&lt;script&gt;"))
goto failed;
free(escaped);
escaped = evhttp_htmlescape("\"\'&");
if (strcmp(escaped, "&quot;&#039;&amp;"))
goto failed;
free(escaped);
if (evhttp_hostportfile("fto://some", NULL, NULL, NULL) != -1)
goto failed;
if (evhttp_hostportfile("http://www.foo.com/path.html",
&host, &port, &path) == -1)
goto failed;
if (strcmp(host, "www.foo.com") || port != 80 ||
strcmp(path, "/path.html"))
goto failed;
if (evhttp_hostportfile("http://foo.com:8080",
&host, &port, &path) == -1)
goto failed;
if (strcmp(host, "foo.com") || port != 8080 || strcmp(path, "/"))
goto failed;
fprintf(stdout, "OK\n");
return;
failed:
fprintf(stdout, "FAILED\n");
exit(1);
}
void
http_suite(void)
{
http_primitives();
http_base_test();
http_bad_header_test();
http_basic_test();