]> Nishi Git Mirror - keine.git/commitdiff
some
authorNishi <nishi@nishi.boats>
Wed, 11 Sep 2024 09:16:23 +0000 (09:16 +0000)
committerNishi <nishi@nishi.boats>
Wed, 11 Sep 2024 09:16:23 +0000 (09:16 +0000)
git-svn-id: file:///raid/svn-personal/keine/trunk@2 a3977ea8-0dc0-2842-9144-a1a46b47fd40

CGI/Makefile [new file with mode: 0644]
CGI/cgi.c [new file with mode: 0644]
CGI/kn_cgi.h [new file with mode: 0644]
CGI/kn_util.h [new file with mode: 0644]
CGI/kn_version.h [new file with mode: 0644]
CGI/main.c [new file with mode: 0644]
CGI/util.c [new file with mode: 0644]
CGI/version.c [new file with mode: 0644]
Makefile [new file with mode: 0644]
Platform/generic.mk [new file with mode: 0644]
config.h.tmpl [new file with mode: 0644]

diff --git a/CGI/Makefile b/CGI/Makefile
new file mode 100644 (file)
index 0000000..b2ed835
--- /dev/null
@@ -0,0 +1,19 @@
+# $Id$
+
+include $(PWD)/Platform/$(PLATFORM).mk
+
+OBJS = main.o cgi.o util.o version.o
+
+.PHONY: all clean
+.SUFFIXES: .c .o
+
+all: keine.cgi
+
+keine.cgi: $(OBJS)
+       $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
+
+.c.o:
+       $(CC) $(CFLAGS) -c -o $@ $<
+
+clean:
+       rm -f *.cgi *.o
diff --git a/CGI/cgi.c b/CGI/cgi.c
new file mode 100644 (file)
index 0000000..8e067c1
--- /dev/null
+++ b/CGI/cgi.c
@@ -0,0 +1,135 @@
+/* $Id$ */
+
+#include "../config.h"
+
+#include "kn_cgi.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+#include <stdio.h>
+
+#include "kn_version.h"
+#include "kn_util.h"
+
+struct q_entry {
+       char* key;
+       char* value;
+};
+
+bool no = false;
+bool showmain = false;
+struct q_entry** entries = NULL;
+
+char* kn_get_query(const char* key){
+       if(entries == NULL) return NULL;
+       int i;
+       for(i = 0; entries[i] != NULL; i++){
+               if(strcmp(entries[i]->key, key) == 0 ) return entries[i]->value;
+       }
+       return NULL;
+}
+
+char* kn_null(const char* a){
+       return a == NULL ? "" : (char*)a;
+}
+
+void kn_parse_query(void){
+       char* query = getenv("QUERY_STRING");
+       if(query != NULL){
+               entries = malloc(sizeof(*entries));
+               entries[0] = NULL;
+               int i;
+               int incr = 0;
+               for(i = 0;; i++){
+                       if(query[i] == 0 || query[i] == '&'){
+                               char* a = malloc(i - incr + 1);
+                               memcpy(a, query + incr , i - incr);
+                               a[i - incr] = 0;
+
+                               char* key = a;
+                               char* value = "";
+
+                               int j;
+                               for(j = 0; key[j] != 0; j++){
+                                       if(key[j] == '='){
+                                               key[j] = 0;
+                                               value = key + j + 1;
+                                               break;
+                                       }
+                               }
+
+                               struct q_entry* e = malloc(sizeof(*e));
+                               e->key = kn_strdup(key);
+                               e->value = kn_strdup(value);
+
+                               struct q_entry** old = entries;
+                               for(j = 0; old[j] != NULL; j++);
+                               entries = malloc(sizeof(*entries) * (j + 2));
+                               for(j = 0; old[j] != NULL; j++) entries[j] = old[j];
+                               entries[j] = e;
+                               entries[j + 1] = NULL;
+                               free(old);
+
+                               free(a);
+
+                               incr = i + 1;
+                               if(query[i] == 0) break;
+                       }
+               }
+       }
+       if(kn_get_query("page") == NULL){
+               printf("Status: 200 OK\n\n");
+               showmain = true;
+       }else{
+               printf("Status: 404 Not Found\n\n");
+               no = true;
+       }
+}
+
+void kn_cgi(void){
+       printf("<html>\n");
+       printf("        <head>\n");
+       printf("                <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n");
+       printf("                <title>Keine - ");
+       if(no){
+               printf("Not found");
+       }else if(showmain){
+               printf("Main");
+       }
+       printf("</title>\n");
+       printf("                <style>\n");
+       printf("html {\n");
+       printf("        background-color: #222222;\n");
+       printf("        color: #ffffff;\n");
+       printf("}\n");
+       printf("body {\n");
+       printf("        width: 900px;\n");
+       printf("        margin: 0 auto;\n");
+       printf("}\n");
+       printf("a:link {\n");
+       printf("        color: #88f;\n");
+       printf("}\n");
+       printf("a:visited {\n");
+       printf("        color: #44b;\n");
+       printf("}\n");
+       printf("                </style>\n");
+       printf("        </head>\n");
+       printf("        <body>\n");
+       printf("                <div style=\"text-align: center;\">\n");
+       printf("                        <form action=\"%s%s\">\n", getenv("SCRIPT_NAME"), kn_null(getenv("PATH_INFO")));
+       printf("                                <a href=\"%s%s\">Main</a> | ", getenv("SCRIPT_NAME"), kn_null(getenv("PATH_INFO")));
+       printf("                                Name: <input name=\"page\">\n");
+       printf("                                <input type=\"submit\">\n");
+       printf("                        </form>\n");
+       printf("                </div>\n");
+       printf("                <hr>\n");
+       if(no){
+               printf("                Not found.\n");
+       }else if(showmain){
+       }
+       printf("                <hr>\n");
+       printf("                <i>Generated by Keine <a href=\"http://nishi.boats/keine\">%s</a></i>\n", kn_get_version());
+       printf("        </body>\n");
+       printf("</html>\n");
+}
diff --git a/CGI/kn_cgi.h b/CGI/kn_cgi.h
new file mode 100644 (file)
index 0000000..ffbd929
--- /dev/null
@@ -0,0 +1,9 @@
+/* $Id$ */
+
+#ifndef __KN_CGI_H__
+#define __KN_CGI_H__
+
+void kn_parse_query(void);
+void kn_cgi(void);
+
+#endif
diff --git a/CGI/kn_util.h b/CGI/kn_util.h
new file mode 100644 (file)
index 0000000..846d1bd
--- /dev/null
@@ -0,0 +1,9 @@
+/* $Id$ */
+
+#ifndef __KN_UTIL_H__
+#define __KN_UTIL_H__
+
+char* kn_strcat(const char* a, const char* b);
+char* kn_strdup(const char* a);
+
+#endif
diff --git a/CGI/kn_version.h b/CGI/kn_version.h
new file mode 100644 (file)
index 0000000..a4d23ee
--- /dev/null
@@ -0,0 +1,8 @@
+/* $Id$ */
+
+#ifndef __KN_VERSION_H__
+#define __KN_VERSION_H__
+
+const char* kn_get_version(void);
+
+#endif
diff --git a/CGI/main.c b/CGI/main.c
new file mode 100644 (file)
index 0000000..621063b
--- /dev/null
@@ -0,0 +1,12 @@
+/* $Id$ */
+
+#include <stdio.h>
+
+#include "kn_cgi.h"
+
+int main(){
+       printf("Content-Type: text/html\n");
+       kn_parse_query();
+       kn_cgi();
+       return 0;
+}
diff --git a/CGI/util.c b/CGI/util.c
new file mode 100644 (file)
index 0000000..73734d1
--- /dev/null
@@ -0,0 +1,18 @@
+/* $Id$ */
+
+#include "kn_util.h"
+
+#include <string.h>
+#include <stdlib.h>
+
+char* kn_strcat(const char* a, const char* b){
+       char* str = malloc(strlen(a) + strlen(b) + 1);
+       memcpy(str, a, strlen(a));
+       memcpy(str + strlen(a), b, strlen(b));
+       str[strlen(a) + strlen(b)] = 0;
+       return str;
+}
+
+char* kn_strdup(const char* a){
+       return kn_strcat(a, "");
+}
diff --git a/CGI/version.c b/CGI/version.c
new file mode 100644 (file)
index 0000000..102fb38
--- /dev/null
@@ -0,0 +1,9 @@
+/* $Id$ */
+
+#include "kn_version.h"
+
+const char* kn_version = "1.00";
+
+const char* kn_get_version(void){
+       return kn_version;
+}
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..ef0b967
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,14 @@
+# $Id$
+
+PWD = `pwd`
+PLATFORM = generic
+
+FLAGS = PWD=$(PWD) PLATFORM=$(PLATFORM)
+
+.PHONY: all clean ./CGI
+
+./CGI::
+       $(MAKE) -C $@ $(FLAGS)
+
+clean:
+       $(MAKE) -C ./CGI $(FLAGS) clean
diff --git a/Platform/generic.mk b/Platform/generic.mk
new file mode 100644 (file)
index 0000000..c26df9c
--- /dev/null
@@ -0,0 +1,6 @@
+# $Id$
+
+CC = cc
+CFLAGS = -std=c99
+LDFLAGS =
+LIBS =
diff --git a/config.h.tmpl b/config.h.tmpl
new file mode 100644 (file)
index 0000000..276454d
--- /dev/null
@@ -0,0 +1,8 @@
+/* $Id$ */
+
+#ifndef __CONFIG_H__
+#define __CONFIG_H__
+
+
+
+#endif