From 048f611483962bcea21da85a46d96ba72044beae Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Sat, 16 Sep 2006 12:31:10 +0000 Subject: [PATCH] updates. --- lib/silchttp/silchttpserver.h | 6 ++++-- lib/silchttp/tests/test_silchttpserver.c | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/silchttp/silchttpserver.h b/lib/silchttp/silchttpserver.h index 3abea82d..cfc87c15 100644 --- a/lib/silchttp/silchttpserver.h +++ b/lib/silchttp/silchttpserver.h @@ -24,7 +24,8 @@ * Very simple HTTP server interface. This HTTP server supports basic HTTP * features. All pages on the server are dynamically created by the caller * of this interface. The server does not support plugins, modules, cgi-bin, - * server-side includes or any other special features. + * server-side includes or any other special features. Naturally, the caller + * of this interface may itself implement such features. * ***/ @@ -74,7 +75,7 @@ typedef struct SilcHttpConnectionStruct *SilcHttpConnection; * * DESCRIPTION * - * The HTTP request callback, that is called everytime a new HTTP request + * The HTTP request callback that is called everytime a new HTTP request * comes from a HTTP client. The `uri' is the requested URI (web page), * and the `method' is the HTTP request method (GET, POST, etc.). The * `data' is non-NULL only if the `method' is POST, and it includes the @@ -218,6 +219,7 @@ const char *silc_http_server_get_header(SilcHttpServer httpd, * EXAMPLE * * silc_http_server_add_header(httpd, conn, "Content-Type", "image/jpeg"); + * silc_http_server_send(httpd, conn, image_data); * ***/ SilcBool silc_http_server_add_header(SilcHttpServer httpd, diff --git a/lib/silchttp/tests/test_silchttpserver.c b/lib/silchttp/tests/test_silchttpserver.c index 859688a7..a6b1b049 100644 --- a/lib/silchttp/tests/test_silchttpserver.c +++ b/lib/silchttp/tests/test_silchttpserver.c @@ -19,6 +19,7 @@ static void http_callback(SilcHttpServer httpd, SilcHttpConnection conn, "", silc_http_server_get_header(httpd, conn, "User-Agent"), + "

", "

OUR DEFAULT PAGE IS THIS: ", silc_time_string(silc_time()), "

" @@ -36,6 +37,20 @@ static void http_callback(SilcHttpServer httpd, SilcHttpConnection conn, silc_buffer_purge(&page); 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")) { -- 2.24.0