some
git-svn-id: file:///raid/svn-personal/keine/trunk@2 a3977ea8-0dc0-2842-9144-a1a46b47fd40
This commit is contained in:
parent
4a152cce6a
commit
1c62692bf1
19
CGI/Makefile
Normal file
19
CGI/Makefile
Normal file
|
@ -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
|
135
CGI/cgi.c
Normal file
135
CGI/cgi.c
Normal file
|
@ -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");
|
||||||
|
}
|
9
CGI/kn_cgi.h
Normal file
9
CGI/kn_cgi.h
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
#ifndef __KN_CGI_H__
|
||||||
|
#define __KN_CGI_H__
|
||||||
|
|
||||||
|
void kn_parse_query(void);
|
||||||
|
void kn_cgi(void);
|
||||||
|
|
||||||
|
#endif
|
9
CGI/kn_util.h
Normal file
9
CGI/kn_util.h
Normal file
|
@ -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
|
8
CGI/kn_version.h
Normal file
8
CGI/kn_version.h
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
#ifndef __KN_VERSION_H__
|
||||||
|
#define __KN_VERSION_H__
|
||||||
|
|
||||||
|
const char* kn_get_version(void);
|
||||||
|
|
||||||
|
#endif
|
12
CGI/main.c
Normal file
12
CGI/main.c
Normal file
|
@ -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;
|
||||||
|
}
|
18
CGI/util.c
Normal file
18
CGI/util.c
Normal file
|
@ -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, "");
|
||||||
|
}
|
9
CGI/version.c
Normal file
9
CGI/version.c
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
#include "kn_version.h"
|
||||||
|
|
||||||
|
const char* kn_version = "1.00";
|
||||||
|
|
||||||
|
const char* kn_get_version(void){
|
||||||
|
return kn_version;
|
||||||
|
}
|
14
Makefile
Normal file
14
Makefile
Normal file
|
@ -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
|
6
Platform/generic.mk
Normal file
6
Platform/generic.mk
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
# $Id$
|
||||||
|
|
||||||
|
CC = cc
|
||||||
|
CFLAGS = -std=c99
|
||||||
|
LDFLAGS =
|
||||||
|
LIBS =
|
8
config.h.tmpl
Normal file
8
config.h.tmpl
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
#ifndef __CONFIG_H__
|
||||||
|
#define __CONFIG_H__
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user