diff options
Diffstat (limited to 'page.c')
| -rw-r--r-- | page.c | 80 |
1 files changed, 26 insertions, 54 deletions
@@ -1535,73 +1535,45 @@ int page_bad_request(struct http_response *const r) return 0; } -int page_style(struct http_response *const r) +int page_style(struct http_response *const r, const char *const path) { - static const char body[] = - "body\n" - "{\n" - " font-family: 'Courier New', Courier, monospace;\n" - "}\n" - "td\n" - "{\n" - " font-size: 14px;\n" - "}\n" - "a\n" - "{\n" - " text-decoration: none;\n" - "}\n" - ".userform\n" - "{\n" - " padding: 4px;\n" - "}\n" - ".loginform\n" - "{\n" - " display: grid;\n" - "}\n" - "form, label, table\n" - "{\n" - " margin: auto;\n" - "}\n" - "div\n" - "{\n" - " align-items: center;\n" - " display: grid;\n" - "}\n" - "input, .abutton\n" - "{\n" - " margin: auto;\n" - " border: 1px solid;\n" - " border-radius: 8px;\n" - "}\n" - "header, footer\n" - "{\n" - " display: flex;\n" - " justify-content: center;\n" - " text-decoration: auto;\n" - "}\n" - "table\n" - "{\n" - " max-width: 50%;\n" - "}\n" - "tr:nth-child(even)\n" - "{\n" - " background-color: lightgray;\n" - "}\n"; + FILE *f = NULL; + struct stat sb; + + if (stat(path, &sb)) + { + fprintf(stderr, "%s: stat(2): %s\n", __func__, strerror(errno)); + goto failure; + } + else if (!(f = fopen(path, "rb"))) + { + fprintf(stderr, "%s: fopen(3) %s: %s\n", + __func__, path, strerror(errno)); + goto failure; + } *r = (const struct http_response) { .status = HTTP_STATUS_OK, - .buf.ro = body, - .n = sizeof body - 1 + .f = f, + .n = sb.st_size }; if (http_response_add_header(r, "Content-Type", "text/css")) { fprintf(stderr, "%s: http_response_add_header failed\n", __func__); - return -1; + goto failure; } return 0; + +failure: + + if (f && fclose(f)) + fprintf(stderr, "%s: fclose(3) %s: %s\n", + __func__, path, strerror(errno)); + + return -1; } int page_share(struct http_response *const r, const char *const path) |
