diff --git a/src/client.c b/src/client.c
index 8d06702..ce3da11 100644
--- a/src/client.c
+++ b/src/client.c
@@ -93,7 +93,7 @@ int client_request_handler(sock *client, unsigned long client_num, unsigned int
hdr_connection = http_get_header_field(&req.hdr, "Connection");
client_keep_alive = hdr_connection != NULL &&
- (strcmp(hdr_connection, "keep-alive") == 0 || strcmp(hdr_connection, "Keep-Alive") == 0);
+ (strcmp(hdr_connection, "keep-alive") == 0 || strcmp(hdr_connection, "Keep-Alive") == 0);
host_ptr = http_get_header_field(&req.hdr, "Host");
if (host_ptr != NULL && strlen(host_ptr) > 255) {
host[0] = 0;
@@ -132,10 +132,14 @@ int client_request_handler(sock *client, unsigned long client_num, unsigned int
if (ret != 0) {
if (ret == 1) {
sprintf(err_msg, "Invalid URI: has to start with slash.");
+ res.status = http_get_status(400);
} else if (ret == 2) {
sprintf(err_msg, "Invalid URI: contains relative path change (/../).");
+ res.status = http_get_status(400);
+ } else if (ret == 3) {
+ sprintf(err_msg, "The specified webroot directory does not exist.");
+ res.status = http_get_status(203);
}
- res.status = http_get_status(400);
goto respond;
}
@@ -211,7 +215,8 @@ int client_request_handler(sock *client, unsigned long client_num, unsigned int
char *if_modified_since = http_get_header_field(&req.hdr, "If-Modified-Since");
char *if_none_match = http_get_header_field(&req.hdr, "If-None-Match");
if ((if_none_match != NULL && strstr(if_none_match, uri.meta->etag) == NULL) ||
- (accept_if_modified_since && if_modified_since != NULL && strcmp(if_modified_since, last_modified) == 0)) {
+ (accept_if_modified_since && if_modified_since != NULL &&
+ strcmp(if_modified_since, last_modified) == 0)) {
res.status = http_get_status(304);
goto respond;
}
@@ -360,13 +365,35 @@ int client_request_handler(sock *client, unsigned long client_num, unsigned int
http_add_header_field(&res.hdr, "Accept-Ranges", "none");
}
if (!use_fastcgi && !use_rev_proxy && file == NULL &&
- res.status->code >= 400 && res.status->code < 600) {
+ ((res.status->code >= 400 && res.status->code < 600) || err_msg[0] != 0)) {
+ char color[16], mode[16];
+ const char *icon, *document;
+ if (res.status->code >= 100 && res.status->code < 200) {
+ sprintf(mode, "info");
+ sprintf(color, HTTP_COLOR_INFO);
+ icon = http_info_icon;
+ document = http_info_document;
+ } else if (res.status->code >= 200 && res.status->code < 300) {
+ sprintf(mode, "success");
+ sprintf(color, HTTP_COLOR_SUCCESS);
+ icon = http_success_icon;
+ document = http_success_document;
+ } else if (res.status->code >= 300 && res.status->code < 400) {
+ sprintf(mode, "warning");
+ sprintf(color, HTTP_COLOR_WARNING);
+ icon = http_warning_icon;
+ document = http_warning_document;
+ } else if (res.status->code >= 400 && res.status->code < 600) {
+ sprintf(mode, "error");
+ sprintf(color, HTTP_COLOR_ERROR);
+ icon = http_error_icon;
+ document = http_error_document;
+ }
http_error_msg *http_msg = http_get_error_msg(res.status->code);
- sprintf(msg_pre_buf, http_error_document, res.status->code, res.status->msg,
+ sprintf(msg_pre_buf, document, res.status->code, res.status->msg,
http_msg != NULL ? http_msg->err_msg : "", err_msg[0] != 0 ? err_msg : "");
content_length = sprintf(msg_buf, http_default_document, res.status->code, res.status->msg,
- msg_pre_buf, res.status->code >= 300 && res.status->code < 400 ? "info" : "error",
- http_error_icon, "#C00000", host);
+ msg_pre_buf, mode, icon, color, host);
http_add_header_field(&res.hdr, "Content-Type", "text/html; charset=UTF-8");
}
if (content_length >= 0) {
diff --git a/src/debug.c b/src/debug.c
new file mode 100644
index 0000000..75621d0
--- /dev/null
+++ b/src/debug.c
@@ -0,0 +1,17 @@
+//
+// Created by lorenz on 17.01.21.
+//
+
+#include "fastcgi.c"
+#include "http.c"
+#include "sock.c"
+
+const char *msg = "PHP message: PHP Notice: Undefined index: Verifiedd in /srv/necronda/www.necronda.net/admin/users.php on line 58PHP message: PHP Notice: Undefined index: Verifiedd in /srv/necronda/www.necronda.net/admin/users.php on line 58PHP message: PHP Notice: Undefined index: Verifiedd in /srv/necronda/www.necronda.net/admin/users.php on line 58PHP message: PHP Notice: Undefined index: Verifiedd in /srv/necronda/www.necronda.net/admin/users.php on line 58PHP message: PHP Notice: Undefined index: Verifiedd in /srv/necronda/www.necronda.net/admin/users.php on line 58PHP message: PHP Notice: Undefined index: Verifiedd in /srv/necronda/www.necronda.net/admin/users.php on line 58PHP message: PHP Notice: Undefined index: Verifiedd in /srv/necronda/www.necronda.net/admin/users.php on line 58PHP message: PHP Notice: Undefined index: Verifiedd in /srv/necronda/www.necronda.net/admin/users.php on line 58";
+
+int main() {
+ char err[256];
+ int ret = fastcgi_php_error(msg, strlen(msg), err);
+ printf("%i\n", ret);
+ return 0;
+}
+
diff --git a/src/http.c b/src/http.c
index 44f9691..df6b4fa 100644
--- a/src/http.c
+++ b/src/http.c
@@ -254,9 +254,9 @@ http_status *http_get_status(unsigned short status_code) {
}
http_error_msg *http_get_error_msg(unsigned short status_code) {
- for (int i = 0; i < sizeof(http_error_messages) / sizeof(http_error_msg); i++) {
- if (http_error_messages[i].code == status_code) {
- return &http_error_messages[i];
+ for (int i = 0; i < sizeof(http_status_messages) / sizeof(http_error_msg); i++) {
+ if (http_status_messages[i].code == status_code) {
+ return &http_status_messages[i];
}
}
return NULL;
diff --git a/src/http.h b/src/http.h
index da215f1..d8563db 100644
--- a/src/http.h
+++ b/src/http.h
@@ -16,6 +16,11 @@
#define HTTP_REMOVE_ALL 1
#define HTTP_REMOVE_LAST 2
+#define HTTP_COLOR_SUCCESS "#008000"
+#define HTTP_COLOR_INFO "#606060"
+#define HTTP_COLOR_WARNING "#E0C000"
+#define HTTP_COLOR_ERROR "#C00000"
+
#include "sock.h"
#include "utils.h"
@@ -65,7 +70,7 @@ http_status http_statuses[] = {
{301, "Redirection", "Moved Permanently"},
{302, "Redirection", "Found"},
{303, "Redirection", "See Other"},
- {304, "Redirection", "Not Modified"},
+ {304, "Success", "Not Modified"},
{305, "Redirection", "Use Proxy"},
{307, "Redirection", "Temporary Redirect"},
{308, "Redirection", "Permanent Redirect"},
@@ -97,7 +102,27 @@ http_status http_statuses[] = {
{505, "Server Error", "HTTP Version Not Supported"},
};
-http_error_msg http_error_messages[] = {
+http_error_msg http_status_messages[] = {
+ {100, "The client SHOULD continue with its request."},
+ {101, "The server understands and is willing to comply with the clients request, via the Upgrade message header field, for a change in the application protocol being used on this connection."},
+
+ {200, "The request has succeeded."},
+ {201, "The request has been fulfilled and resulted in a new resource being created."},
+ {202, "The request has been accepted for processing, but the processing has not been completed."},
+ {203, "The returned meta information in the entity-header is not the definitive set as available from the origin server, but is gathered from a local or a third-party copy."},
+ {204, "The server has fulfilled the request but does not need to return an entity-body, and might want to return updated meta information."},
+ {205, "The server has fulfilled the request and the user agent SHOULD reset the document view which caused the request to be sent."},
+ {206, "The server has fulfilled the partial GET request for the resource."},
+
+ {300, "The requested resource corresponds to any one of a set of representations, each with its own specific location, and agent-driven negotiation information is being provided so that the user (or user agent) can select a preferred representation and redirect its request to that location."},
+ {301, "The requested resource has been assigned a new permanent URI and any future references to this resource SHOULD use one of the returned URIs."},
+ {302, "The requested resource resides temporarily under a different URI."},
+ {303, "The response to the request can be found under a different URI and SHOULD be retrieved using a GET method on that resource."},
+ {304, "The request has been fulfilled and the requested resource has not been modified."},
+ {305, "The requested resource MUST be accessed through the proxy given by the Location field."},
+ {307, "The requested resource resides temporarily under a different URI."},
+ {308, "The requested resource has been assigned a new permanent URI and any future references to this resource ought to use one of the enclosed URIs."},
+
{400, "The request could not be understood by the server due to malformed syntax."},
{401, "The request requires user authentication."},
{403, "The server understood the request, but is refusing to fulfill it."},
@@ -113,7 +138,7 @@ http_error_msg http_error_messages[] = {
{413, "The server is refusing to process a request because the request entity is larger than the server is willing or able to process."},
{414, "The server is refusing to service the request because the Request-URI is longer than the server is willing to interpret."},
{415, "The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method."},
- {416, "None of the ranges in the request's Range header field overlap the current extent of the selected resource or that the set of ranges requested has been rejected due to invalid ranges or an excessive request of small or overlapping ranges."},
+ {416, "None of the ranges in the requests Range header field overlap the current extent of the selected resource or that the set of ranges requested has been rejected due to invalid ranges or an excessive request of small or overlapping ranges."},
{417, "The expectation given in an Expect request-header field could not be met by this server, or, if the server is a proxy, the server has unambiguous evidence that the request could not be met by the next-hop server."},
{500, "The server encountered an unexpected condition which prevented it from fulfilling the request."},
@@ -136,7 +161,7 @@ const char *http_default_document =
"\t\n"
"%5$s"
"\t