*/
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
}
}
-/* 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)
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, "<script>"))
+ goto failed;
+ free(escaped);
+
+ escaped = evhttp_htmlescape("\"\'&");
+ if (strcmp(escaped, ""'&"))
+ 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();