1 /* SilcHttpServer tests */
4 #include "../silchttpserver.h"
6 static void http_callback(SilcHttpServer httpd, SilcHttpConnection conn,
7 const char *uri, const char *method,
8 SilcBuffer data, void *context)
10 SilcBufferStruct page;
12 SILC_LOG_DEBUG(("HTTP data received, URI:%s, method:%s", uri, method));
14 if (!strcasecmp(method, "GET")) {
15 /* Send our default page */
16 if (!strcmp(uri, "/") || !strcmp(uri, "/index.html")) {
17 memset(&page, 0, sizeof(page));
18 silc_buffer_strformat(&page,
19 "<html><head></head><body>",
20 silc_http_server_get_header(httpd, conn,
22 "<p>OUR DEFAULT PAGE IS THIS: ",
23 silc_time_string(silc_time()),
24 "<P><FORM action=\"/posttest\" method=\"post\"><P>"
25 "<LABEL>First name: </LABEL>"
26 "<INPUT type=\"text\" name=\"firstname\"><BR>"
27 "<INPUT type=\"radio\" name=\"sex\" value=\"Male\"> Male<BR>"
28 "<INPUT type=\"radio\" name=\"sex\" value=\"Female\"> Female<BR>"
29 "<INPUT type=\"submit\" value=\"Send\"> <INPUT type=\"reset\">"
33 silc_http_server_add_header(httpd, conn, "X-Date",
34 silc_time_string(silc_time()));
35 silc_http_server_send(httpd, conn, &page);
36 silc_buffer_purge(&page);
41 if (!strcasecmp(method, "POST")) {
42 if (strcmp(uri, "/posttest"))
44 memset(&page, 0, sizeof(page));
45 silc_buffer_strformat(&page,
46 "<html><head></head><body>",
48 silc_buffer_data(data),
51 silc_http_server_add_header(httpd, conn, "X-Date",
52 silc_time_string(silc_time()));
53 silc_http_server_send(httpd, conn, &page);
54 silc_buffer_purge(&page);
58 silc_http_server_send_error(httpd, conn, "404 Not Found",
59 "<body><h1>404 Not Found: The page you are looking for cannot be located</h1></body>");
62 int main(int argc, char **argv)
64 SilcBool success = FALSE;
65 SilcSchedule schedule;
68 if (argc > 1 && !strcmp(argv[1], "-d")) {
70 silc_log_debug_hexdump(TRUE);
71 silc_log_set_debug_string("*http*,*mime*");
74 signal(SIGPIPE, SIG_IGN);
76 SILC_LOG_DEBUG(("Allocating scheduler"));
77 schedule = silc_schedule_init(0, NULL);
81 SILC_LOG_DEBUG(("Allocating HTTP server at 127.0.0.1:5000"));
82 httpd = silc_http_server_alloc("127.0.0.1", 5000, schedule,
87 silc_schedule(schedule);
89 silc_schedule_uninit(schedule);
94 SILC_LOG_DEBUG(("Testing was %s", success ? "SUCCESS" : "FAILURE"));
95 fprintf(stderr, "Testing was %s\n", success ? "SUCCESS" : "FAILURE");