From: Nishi Date: Wed, 11 Sep 2024 09:16:23 +0000 (+0000) Subject: some X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=1c62692bf126c99b93f9171d5edd8195ecf891a9;p=keine.git some git-svn-id: file:///raid/svn-personal/keine/trunk@2 a3977ea8-0dc0-2842-9144-a1a46b47fd40 --- diff --git a/CGI/Makefile b/CGI/Makefile new file mode 100644 index 0000000..b2ed835 --- /dev/null +++ b/CGI/Makefile @@ -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 index 0000000..8e067c1 --- /dev/null +++ b/CGI/cgi.c @@ -0,0 +1,135 @@ +/* $Id$ */ + +#include "../config.h" + +#include "kn_cgi.h" + +#include +#include +#include +#include + +#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("\n"); + printf(" \n"); + printf(" \n"); + printf(" Keine - "); + if(no){ + printf("Not found"); + }else if(showmain){ + printf("Main"); + } + printf("\n"); + printf(" \n"); + printf(" \n"); + printf(" \n"); + printf("
\n"); + printf("
\n", getenv("SCRIPT_NAME"), kn_null(getenv("PATH_INFO"))); + printf(" Main | ", getenv("SCRIPT_NAME"), kn_null(getenv("PATH_INFO"))); + printf(" Name: \n"); + printf(" \n"); + printf("
\n"); + printf("
\n"); + printf("
\n"); + if(no){ + printf(" Not found.\n"); + }else if(showmain){ + } + printf("
\n"); + printf(" Generated by Keine %s\n", kn_get_version()); + printf(" \n"); + printf("\n"); +} diff --git a/CGI/kn_cgi.h b/CGI/kn_cgi.h new file mode 100644 index 0000000..ffbd929 --- /dev/null +++ b/CGI/kn_cgi.h @@ -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 index 0000000..846d1bd --- /dev/null +++ b/CGI/kn_util.h @@ -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 index 0000000..a4d23ee --- /dev/null +++ b/CGI/kn_version.h @@ -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 index 0000000..621063b --- /dev/null +++ b/CGI/main.c @@ -0,0 +1,12 @@ +/* $Id$ */ + +#include + +#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 index 0000000..73734d1 --- /dev/null +++ b/CGI/util.c @@ -0,0 +1,18 @@ +/* $Id$ */ + +#include "kn_util.h" + +#include +#include + +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 index 0000000..102fb38 --- /dev/null +++ b/CGI/version.c @@ -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 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 index 0000000..c26df9c --- /dev/null +++ b/Platform/generic.mk @@ -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 index 0000000..276454d --- /dev/null +++ b/config.h.tmpl @@ -0,0 +1,8 @@ +/* $Id$ */ + +#ifndef __CONFIG_H__ +#define __CONFIG_H__ + + + +#endif