comparison page-fork.c @ 51:07b6887d3557

pasterd: split into individual pages While here add a similar mini.css theme as in imgup.
author David Demelier <markand@malikania.fr>
date Mon, 21 Dec 2020 18:22:44 +0100
parents
children fba88439ec0a
comparison
equal deleted inserted replaced
50:520f57836ff3 51:07b6887d3557
1 /*
2 * page-fork.c -- page /fork/<id>
3 *
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #include <sys/types.h>
20 #include <assert.h>
21 #include <stdarg.h>
22 #include <stdint.h>
23 #include <string.h>
24
25 #include <kcgi.h>
26
27 #include "database.h"
28 #include "page-new.h"
29 #include "page.h"
30 #include "paste.h"
31
32 static void
33 get(struct kreq *req)
34 {
35 struct paste paste = {0};
36
37 if (!database_get(&paste, req->path))
38 page(req, NULL, KHTTP_404, "404.html");
39 else {
40 page_new_render(req, &paste);
41 paste_finish(&paste);
42 }
43 }
44
45 void
46 page_fork(struct kreq *req)
47 {
48 switch (req->method) {
49 case KMETHOD_GET:
50 get(req);
51 break;
52 default:
53 page(req, NULL, KHTTP_400, "400.html");
54 break;
55 }
56 }