Outsource default favicons
This commit is contained in:
1
Makefile
1
Makefile
@ -59,6 +59,7 @@ bin/sesimos: bin/server.o bin/logger.o bin/cache_handler.o bin/async.o bin/worke
|
||||
bin/worker/request_handler.o bin/worker/tcp_acceptor.o \
|
||||
bin/worker/fastcgi_handler.o bin/worker/local_handler.o bin/worker/proxy_handler.o \
|
||||
bin/lib/http_static.o bin/res/default.o bin/res/proxy.o bin/res/style.o \
|
||||
bin/res/icon_error.o bin/res/icon_info.o bin/res/icon_success.o bin/res/icon_warning.o \
|
||||
bin/lib/compress.o bin/lib/config.o bin/lib/fastcgi.o bin/lib/geoip.o \
|
||||
bin/lib/http.o bin/lib/proxy.o bin/lib/sock.o bin/lib/uri.o \
|
||||
bin/lib/utils.o bin/lib/websocket.o bin/lib/mpmc.o bin/lib/list.o
|
||||
|
@ -8,8 +8,9 @@
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
|
||||
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico"/>
|
||||
<link rel="stylesheet" type="text/css" href="/.sesimos/style.css"/>
|
||||
%5$s <style>html{--color:var(--%4$s);}</style>
|
||||
<link rel="stylesheet" type="text/css" href="/.sesimos/res/style.css"/>
|
||||
<link rel="alternate icon" type="image/svg+xml" sizes="any" href="%5$s"/>
|
||||
<style>html{--color:var(--%4$s);}</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
|
3
res/icon_error.svg
Normal file
3
res/icon_error.svg
Normal file
@ -0,0 +1,3 @@
|
||||
<svg width="16" height="16" xmlns="http://www.w3.org/2000/svg">
|
||||
<text x="4" y="12" fill="#C00000" style="font-family:'Arial',sans-serif">:(</text>
|
||||
</svg>
|
After Width: | Height: | Size: 158 B |
3
res/icon_info.svg
Normal file
3
res/icon_info.svg
Normal file
@ -0,0 +1,3 @@
|
||||
<svg width="16" height="16" xmlns="http://www.w3.org/2000/svg">
|
||||
<text x="4" y="12" fill="#606060" style="font-family:'Arial',sans-serif">:)</text>
|
||||
</svg>
|
After Width: | Height: | Size: 158 B |
3
res/icon_success.svg
Normal file
3
res/icon_success.svg
Normal file
@ -0,0 +1,3 @@
|
||||
<svg width="16" height="16" xmlns="http://www.w3.org/2000/svg">
|
||||
<text x="4" y="12" fill="#008000" style="font-family:'Arial',sans-serif">:)</text>
|
||||
</svg>
|
After Width: | Height: | Size: 158 B |
3
res/icon_warning.svg
Normal file
3
res/icon_warning.svg
Normal file
@ -0,0 +1,3 @@
|
||||
<svg width="16" height="16" xmlns="http://www.w3.org/2000/svg">
|
||||
<text x="4" y="12" fill="#E0C000" style="font-family:'Arial',sans-serif">:)</text>
|
||||
</svg>
|
After Width: | Height: | Size: 158 B |
@ -419,10 +419,10 @@ char *http_get_date(char *buf, size_t size) {
|
||||
const http_doc_info *http_get_status_info(const http_status *status) {
|
||||
unsigned short code = status->code;
|
||||
static http_doc_info info[] = {
|
||||
{"info", HTTP_COLOR_INFO, http_info_icon, http_info_doc},
|
||||
{"success", HTTP_COLOR_SUCCESS, http_success_icon, http_success_doc},
|
||||
{"warning", HTTP_COLOR_WARNING, http_warning_icon, http_warning_doc},
|
||||
{"error", HTTP_COLOR_ERROR, http_error_icon, http_error_doc}
|
||||
{"info", HTTP_COLOR_INFO, "/.sesimos/res/icon-info.svg", http_info_doc},
|
||||
{"success", HTTP_COLOR_SUCCESS, "/.sesimos/res/icon-success.svg", http_success_doc},
|
||||
{"warning", HTTP_COLOR_WARNING, "/.sesimos/res/icon-warning.svg", http_warning_doc},
|
||||
{"error", HTTP_COLOR_ERROR, "/.sesimos/res/icon-error.svg", http_error_doc}
|
||||
};
|
||||
if (code >= 100 && code < 200) {
|
||||
return &info[0];
|
||||
|
@ -117,10 +117,7 @@ extern const http_status_msg http_status_messages[];
|
||||
extern const int http_statuses_size;
|
||||
extern const int http_status_messages_size;
|
||||
|
||||
extern const char http_error_doc[], http_error_icon[];
|
||||
extern const char http_warning_doc[], http_warning_icon[];
|
||||
extern const char http_success_doc[], http_success_icon[];
|
||||
extern const char http_info_doc[], http_info_icon[];
|
||||
extern const char http_error_doc[], http_warning_doc[], http_success_doc[], http_info_doc[];
|
||||
|
||||
void http_to_camel_case(char *str, int mode);
|
||||
|
||||
|
@ -112,47 +112,20 @@ const char http_error_doc[] =
|
||||
" <p>%3$s</p>\n"
|
||||
" <p>%4$s</p>\n";
|
||||
|
||||
const char http_error_icon[] =
|
||||
" <link rel=\"alternate icon\" type=\"image/svg+xml\" sizes=\"any\" href=\"data:image/svg+xml;base64,"
|
||||
"PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAw"
|
||||
"L3N2ZyI+PHRleHQgeD0iNCIgeT0iMTIiIGZpbGw9IiNDMDAwMDAiIHN0eWxlPSJmb250LWZhbWls"
|
||||
"eTonQXJpYWwnLHNhbnMtc2VyaWYiPjooPC90ZXh0Pjwvc3ZnPgo=\"/>\n";
|
||||
|
||||
|
||||
const char http_warning_doc[] =
|
||||
" <h1>%1$i</h1>\n"
|
||||
" <h2>%2$s :)</h2>\n"
|
||||
" <p>%3$s</p>\n"
|
||||
" <p>%4$s</p>\n";
|
||||
|
||||
const char http_warning_icon[] =
|
||||
" <link rel=\"alternate icon\" type=\"image/svg+xml\" sizes=\"any\" href=\"data:image/svg+xml;base64,"
|
||||
"PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAw"
|
||||
"L3N2ZyI+PHRleHQgeD0iNCIgeT0iMTIiIGZpbGw9IiNFMEMwMDAiIHN0eWxlPSJmb250LWZhbWls"
|
||||
"eTonQXJpYWwnLHNhbnMtc2VyaWYiPjopPC90ZXh0Pjwvc3ZnPgo=\"/>\n";
|
||||
|
||||
|
||||
const char http_success_doc[] =
|
||||
" <h1>%1$i</h1>\n"
|
||||
" <h2>%2$s :)</h2>\n"
|
||||
" <p>%3$s</p>\n"
|
||||
" <p>%4$s</p>\n";
|
||||
|
||||
const char http_success_icon[] =
|
||||
" <link rel=\"alternate icon\" type=\"image/svg+xml\" sizes=\"any\" href=\"data:image/svg+xml;base64,"
|
||||
"PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAw"
|
||||
"L3N2ZyI+PHRleHQgeD0iNCIgeT0iMTIiIGZpbGw9IiMwMDgwMDAiIHN0eWxlPSJmb250LWZhbWls"
|
||||
"eTonQXJpYWwnLHNhbnMtc2VyaWYiPjopPC90ZXh0Pjwvc3ZnPgo=\"/>\n";
|
||||
|
||||
|
||||
const char http_info_doc[] =
|
||||
" <h1>%1$i</h1>\n"
|
||||
" <h2>%2$s :)</h2>\n"
|
||||
" <p>%3$s</p>\n"
|
||||
" <p>%4$s</p>\n";
|
||||
|
||||
const char http_info_icon[] =
|
||||
" <link rel=\"alternate icon\" type=\"image/svg+xml\" sizes=\"any\" href=\"data:image/svg+xml;base64,"
|
||||
"PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAw"
|
||||
"L3N2ZyI+PHRleHQgeD0iNCIgeT0iMTIiIGZpbGw9IiM2MDYwNjAiIHN0eWxlPSJmb250LWZhbWls"
|
||||
"eTonQXJpYWwnLHNhbnMtc2VyaWYiPjopPC90ZXh0Pjwvc3ZnPgo=\"/>\n";
|
||||
|
@ -16,6 +16,22 @@
|
||||
#define http_style_doc _binary_bin_res_style_txt_start
|
||||
#define http_style_doc_size ((unsigned int) (_binary_bin_res_style_txt_end - _binary_bin_res_style_txt_start) - 1)
|
||||
|
||||
#define http_icon_error _binary_bin_res_icon_error_txt_start
|
||||
#define http_icon_error_size ((unsigned int) (_binary_bin_res_icon_error_txt_end - _binary_bin_res_icon_error_txt_start) - 1)
|
||||
#define http_icon_info _binary_bin_res_icon_info_txt_start
|
||||
#define http_icon_info_size ((unsigned int) (_binary_bin_res_icon_info_txt_end - _binary_bin_res_icon_info_txt_start) - 1)
|
||||
#define http_icon_success _binary_bin_res_icon_success_txt_start
|
||||
#define http_icon_success_size ((unsigned int) (_binary_bin_res_icon_success_txt_end - _binary_bin_res_icon_success_txt_start) - 1)
|
||||
#define http_icon_warning _binary_bin_res_icon_warning_txt_start
|
||||
#define http_icon_warning_size ((unsigned int) (_binary_bin_res_icon_warning_txt_end - _binary_bin_res_icon_warning_txt_start) - 1)
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
const char *type;
|
||||
const char *content;
|
||||
const unsigned int size;
|
||||
} res_t;
|
||||
|
||||
extern const char _binary_bin_res_default_txt_start[];
|
||||
extern const char _binary_bin_res_default_txt_end[];
|
||||
|
||||
@ -25,4 +41,16 @@ extern const char _binary_bin_res_proxy_txt_end[];
|
||||
extern const char _binary_bin_res_style_txt_start[];
|
||||
extern const char _binary_bin_res_style_txt_end[];
|
||||
|
||||
extern const char _binary_bin_res_icon_error_txt_start[];
|
||||
extern const char _binary_bin_res_icon_error_txt_end[];
|
||||
|
||||
extern const char _binary_bin_res_icon_info_txt_start[];
|
||||
extern const char _binary_bin_res_icon_info_txt_end[];
|
||||
|
||||
extern const char _binary_bin_res_icon_success_txt_start[];
|
||||
extern const char _binary_bin_res_icon_success_txt_end[];
|
||||
|
||||
extern const char _binary_bin_res_icon_warning_txt_start[];
|
||||
extern const char _binary_bin_res_icon_warning_txt_end[];
|
||||
|
||||
#endif //SESIMOS_RES_H
|
||||
|
@ -130,12 +130,28 @@ static int request_handler(client_ctx_t *ctx) {
|
||||
logger_set_prefix("[%s%*s%s]%s", BLD_STR, INET6_ADDRSTRLEN, ctx->req_host, CLR_STR, ctx->log_prefix);
|
||||
info(BLD_STR "%s %s", req->method, req->uri);
|
||||
|
||||
if (strcmp(req->uri, "/.sesimos/style.css") == 0 && (strcmp(req->method, "GET") == 0 || strcmp(req->method, "HEAD") == 0)) {
|
||||
ctx->msg_buf = (char *) http_style_doc;
|
||||
ctx->content_length = http_style_doc_size;
|
||||
if (strncmp(req->uri, "/.sesimos/res/", 14) == 0 && (strcmp(req->method, "GET") == 0 || strcmp(req->method, "HEAD") == 0)) {
|
||||
const res_t resources[] = {
|
||||
{"style.css", "text/css; charset=UTF-8", http_style_doc, http_style_doc_size},
|
||||
{"icon-error.svg", "image/svg+xml; charset=UTF-8", http_icon_error, http_icon_error_size},
|
||||
{"icon-info.svg", "image/svg+xml; charset=UTF-8", http_icon_info, http_icon_info_size},
|
||||
{"icon-success.svg", "image/svg+xml; charset=UTF-8", http_icon_success, http_icon_success_size},
|
||||
{"icon-warning.svg", "image/svg+xml; charset=UTF-8", http_icon_warning, http_icon_warning_size},
|
||||
};
|
||||
|
||||
res->status = http_get_status(404);
|
||||
for (int i = 0; i < sizeof(resources) / sizeof(res_t); i++) {
|
||||
const res_t *r = &resources[i];
|
||||
if (strcmp(req->uri + 14, r->name) == 0) {
|
||||
res->status = http_get_status(200);
|
||||
http_add_header_field(&res->hdr, "Content-Type", "text/css; charset=UTF-8");
|
||||
http_add_header_field(&res->hdr, "Cache-Control", "public, max-age=3600");
|
||||
http_add_header_field(&res->hdr, "Content-Type", r->type);
|
||||
http_add_header_field(&res->hdr, "Cache-Control", "public, max-age=86400");
|
||||
ctx->msg_buf = (char *) r->content;
|
||||
ctx->content_length = r->size;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user