/* SilcHttpServer tests */ #include "silc.h" #include "../silchttpserver.h" #include "../silchttpphp.h" static void http_callback(SilcHttpServer httpd, SilcHttpConnection conn, const char *uri, const char *method, SilcBuffer data, void *context) { SilcBufferStruct page; SILC_LOG_DEBUG(("HTTP data received, URI:%s, method:%s", uri, method)); if (!strcasecmp(method, "GET")) { /* Send our default page */ if (!strcmp(uri, "/") || !strcmp(uri, "/index.html")) { SilcBuffer php; const char *php_data = NULL; /* Execute PHP data */ php = silc_http_php("" "UPDATED " "| VERSION 4.0 | A HANDMADE WEB-SITE | (C) 1995 - 2006 PEKKA RIIKONEN"); if (php) php_data = silc_buffer_data(php); memset(&page, 0, sizeof(page)); silc_buffer_strformat(&page, "", silc_http_server_get_header(httpd, conn, "User-Agent"), "
", "
OUR DEFAULT PAGE IS THIS: ", silc_time_string(silc_time()), "
", php_data, "", SILC_STRFMT_END); silc_http_server_add_header(httpd, conn, "X-Date", silc_time_string(silc_time())); silc_http_server_send(httpd, conn, &page); silc_buffer_purge(&page); silc_buffer_free(php); return; } if (!strcmp(uri, "/pr_1995.jpg")) { SilcUInt32 data_len; unsigned char *data = silc_file_readfile("pr_1995.jpg", &data_len); if (!data) { silc_http_server_send_error(httpd, conn, "404 Not Found", NULL); return; } silc_buffer_set(&page, data, data_len), silc_http_server_add_header(httpd, conn, "Content-Type", "image/jpeg"); silc_http_server_send(httpd, conn, &page); silc_buffer_purge(&page); return; } } if (!strcasecmp(method, "POST")) { if (strcmp(uri, "/posttest")) return; memset(&page, 0, sizeof(page)); silc_buffer_strformat(&page, "", "POST PROCESSED:", silc_buffer_data(data), "", SILC_STRFMT_END); silc_http_server_add_header(httpd, conn, "X-Date", silc_time_string(silc_time())); silc_http_server_send(httpd, conn, &page); silc_buffer_purge(&page); return; } silc_http_server_send_error(httpd, conn, "404 Not Found", "