From e7e4e22b69a0c9965c2d4f96903ae647165e99d3 Mon Sep 17 00:00:00 2001 From: la-ninpre Date: Wed, 2 Jun 2021 17:00:39 +0000 Subject: major refactoring added options to compile cgi for http and gemini FossilOrigin-Name: 393d793150423ffe6680f109ef6b0524fd8e2e3501766a6761aa63276e90d90e --- cgi.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 cgi.c (limited to 'cgi.c') diff --git a/cgi.c b/cgi.c new file mode 100644 index 0000000..d7d2c84 --- /dev/null +++ b/cgi.c @@ -0,0 +1,94 @@ +/* Copyright (c) 2021, la-ninpre + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * ************************************************************************* + * + * this file contains code for cgi version of nimisewi. + * + * i know that there are libraries for cgi in c, but c'mon, it's so small and + * simple. + * stylesheet is arbitrary, replace with anything you want if you don't like it. + */ + +#include +#include +#include +#include + +#include "cgi.h" + +#include "nimisewi.h" + +void +print_response_header(void) +{ + printf("Status: 200 OK\r"); + printf("Content-Type: text/html\r"); +} + +void +print_html_header(void) +{ + printf("\n"); + printf("\n"); + print_html_stylesheet(); + printf("\n"); + printf("\n"); +} + +void +print_html_stylesheet(void) +{ + printf("\n"); +} + +void +print_html_footer(void) +{ + printf("\n"); + printf("\n"); +} + +int +main(void) +{ +#ifdef __OpenBSD__ + if (pledge("stdio", NULL) == -1) { + err(EXIT_FAILURE, "pledge"); + } +#endif + + char *ns; + ns = nimi_sewi(); + if (ns == NULL) { + err(EXIT_FAILURE, "memory could'n be allocated"); + } + + print_response_header(); + print_html_header(); + + printf("

"); + printf("%s", ns); + printf("

\n"); + + weka_e_nimi_sewi(ns); + + print_html_footer(); + + return EXIT_SUCCESS; +} -- cgit v1.2.3