↑ 1 #include <stdio.h>
↑ 2 #include <stdlib.h>
↑ 3 #include <fcntl.h>
↑ 4 #include <errno.h>
↑ 5 #include <unistd.h>
↑ 6 #include "config.h"
↑ 7 #include "client.h"
↑ 8 #include "server.h"
↑ 9 #include "rh_string.h"
↑10 #include "handler.h"
↑11 #include "http_request.h"
↑12 #include "rh_chunk.h"
↑13 #include "http_range.h"
↑14
↑15 /*
↑16 *
↑17 * status
↑18 *
↑19 *
↑20 *
↑21 *
↑22 */
↑23
↑24 #define STATUS_URI "/server-status"
↑25
↑26 #define TEST(_call) if (0 != _call) return HANDLER_FAILURE
↑27
↑28 DECLARE_HANDLER_FUNCTION (status,exec)
↑29 {
↑30 http_request_t *request;
↑31
↑32 #ifdef RHTTPD_DUMP_HANDLER_CALL
↑33 printf ("%s(%p)\n", __FUNCTION__, (void*)handler);
↑34 #endif
↑35
↑36 request = handler->request;
↑37
↑38 if (0 != request->header_out.status)
↑39 return HANDLER_FAILURE;
↑40
↑41 if (CONST_LEN(STATUS_URI) != request->header_in.uri.path.used)
↑42 return HANDLER_SUCCESS;
↑43
↑44 if (0 != rh_memcasecmp(request->header_in.uri.path.data,
↑45 CONST_STR_LEN(STATUS_URI)))
↑46 return HANDLER_SUCCESS;
↑47
↑48
↑49 request->header_out.status = 200;
↑50
↑51 TEST( RH_CHUNK_APPEND_CONST (&request->chunk_content,
↑52 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" "
↑53 "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"NL
↑54 "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\">"NL
↑55 "<head>"NL
↑56 "<title>Server Status</title>"
↑57 "</head><body>"
↑58 "<h1>Server Status</h1>"
↑59 ) );
↑60
↑61 TEST( RH_CHUNK_APPEND_CONST (&request->chunk_content,
↑62 "<p>This is rhttpd " RHTTPD_VERSION ".</p>"
↑63 "<p>Current time is: "));
↑64
↑65 TEST(rh_chunk_append_buffer (
↑66 &request->chunk_content,
↑67 request->client->server->gmtime.data,
↑68 request->client->server->gmtime.used,
↑69 NULL, NULL) );
↑70
↑71 TEST( RH_CHUNK_APPEND_CONST (&request->chunk_content,
↑72 ".</p>"));
↑73
↑74 TEST( RH_CHUNK_APPEND_CONST (&request->chunk_content,
↑75 "<p>Current status is: fine (-:</p>"));
↑76
↑77 TEST( RH_CHUNK_APPEND_CONST (&request->chunk_content,
↑78 "</body></html>"));
↑79
↑80 HTTP_HEADER_KEY_SET_CONST_STR (
↑81 &request->header_out,
↑82 CONTENT_TYPE,
↑83 "text/html");
↑84
↑85
↑86 return HANDLER_STOP;
↑87 }
↑88
↑89
↑90 DECLARE_HANDLER_BEGIN (status, CONTENT)
↑91 .DECLARE_HANDLER_NULL (status, setup),
↑92 .DECLARE_HANDLER_NULL (status, init),
↑93 .DECLARE_HANDLER_NULL (status, init_global),
↑94 .DECLARE_HANDLER_NULL (status, free),
↑95 .DECLARE_HANDLER_NULL (status, free_global),
↑96 .DECLARE_HANDLER_SYMBOL (status, exec),
↑97 DECLARE_HANDLER_END
syntax highlighted by Code2HTML, v. 0.9.1