minimal request handling

Sun, 30 Oct 2011 16:26:57 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 30 Oct 2011 16:26:57 +0100
changeset 3
137197831306
parent 2
cee3e65e789c
child 4
998844b5ed25

minimal request handling

src/server/Makefile file | annotate | diff | comparison | revisions
src/server/conf.c file | annotate | diff | comparison | revisions
src/server/conf.h file | annotate | diff | comparison | revisions
src/server/func.c file | annotate | diff | comparison | revisions
src/server/func.h file | annotate | diff | comparison | revisions
src/server/httprequest.c file | annotate | diff | comparison | revisions
src/server/httprequest.h file | annotate | diff | comparison | revisions
src/server/nametrans.c file | annotate | diff | comparison | revisions
src/server/nametrans.h file | annotate | diff | comparison | revisions
src/server/nsapi.h file | annotate | diff | comparison | revisions
src/server/object.c file | annotate | diff | comparison | revisions
src/server/object.h file | annotate | diff | comparison | revisions
src/server/objs.mk file | annotate | diff | comparison | revisions
src/server/pblock.cpp file | annotate | diff | comparison | revisions
src/server/request.h file | annotate | diff | comparison | revisions
src/server/service.c file | annotate | diff | comparison | revisions
src/server/service.h file | annotate | diff | comparison | revisions
src/server/vserver.c file | annotate | diff | comparison | revisions
src/server/vserver.h file | annotate | diff | comparison | revisions
src/server/ws-fn.c file | annotate | diff | comparison | revisions
--- a/src/server/Makefile	Tue Sep 06 22:37:51 2011 +0200
+++ b/src/server/Makefile	Sun Oct 30 16:26:57 2011 +0100
@@ -29,7 +29,7 @@
 BUILD_ROOT = ../../
 OBJ_DIR = $(BUILD_ROOT)build/
 
-CFLAGS  = -I/usr/include/mps
+CFLAGS  = -I/usr/include/mps -g
 LDFLAGS = -L/usr/lib/mps -lplds4 -lplc4 -lnspr4 -lpthread -ldl -lposix4  -lsocket -lnsl -lgen -lm -R/usr/lib/mps
 
 MAIN_TARGET = $(BUILD_ROOT)work/bin/webservd
--- a/src/server/conf.c	Tue Sep 06 22:37:51 2011 +0200
+++ b/src/server/conf.c	Sun Oct 30 16:26:57 2011 +0100
@@ -34,6 +34,10 @@
 #include "httplistener.h"
 #include "conf.h"
 
+#include "vserver.h"
+
+VirtualServer *default_vs;
+
 void load_init_conf(char *file) {
     printf("load_init_conf\n");
 }
@@ -47,4 +51,66 @@
     conf->name = "default";
 
     http_listener_new(conf);
+
+    // virtual server
+    default_vs = vs_new();
+    default_vs->objset = create_test_objset();
+    default_vs->default_obj_name = "default";
+
+    // begin objset test
+    /*
+    httpd_objset *objset = default_vs->objset;
+    for(int i=0;i<objset->pos;i++) {
+        httpd_object *obj = objset->obj[i];
+        printf("<object [%s]>\n", obj->name);
+        for(int j=0;j<obj->nd;j++) {
+            dtable *dt;
+            switch(j) {
+                case NSAPIAuthTrans: {
+                    printf("  Get AuthTrans Directives\n");
+                    dt = object_get_dtable(obj, NSAPIAuthTrans);
+                    break;
+                }
+                case NSAPINameTrans: {
+                    printf("  Get NameTrans Directives\n");
+                    dt = object_get_dtable(obj, NSAPINameTrans);
+                    break;
+                }
+                case NSAPIPathCheck: {
+                    printf("  Get PathCheck Directives\n");
+                    dt = object_get_dtable(obj, NSAPIPathCheck);
+                    break;
+                }
+                case NSAPIService: {
+                    printf("  Get Service Directives\n");
+                    dt = object_get_dtable(obj, NSAPIService);
+                    break;
+                }
+                default: {
+                    printf("j: %d\n", j);
+                    dt = object_get_dtable(obj, j);
+                    break;
+                }
+            }
+            if(dt != NULL) {
+                printf("  dtable[%d].length = %d\n", dt, dt->ndir);
+            } else {
+                continue;
+            }
+            for(int k=0;k<dt->ndir;k++) {
+                directive *d = dt->directive[k];
+                if(d == NULL) {
+                    printf("d is null\n");
+                } else {
+                    printf("    Directive[%d].name = %s\n", d, d->func->name);
+                }
+            }
+        }
+    }
+    */
+    // end objset test
 }
+
+VirtualServer* conf_get_default_vs() {
+    return default_vs;
+}
--- a/src/server/conf.h	Tue Sep 06 22:37:51 2011 +0200
+++ b/src/server/conf.h	Sun Oct 30 16:26:57 2011 +0100
@@ -37,6 +37,8 @@
 
 void load_server_conf(char *file);
 
+VirtualServer* conf_get_default_vs();
+
 
 
 #ifdef	__cplusplus
--- a/src/server/func.c	Tue Sep 06 22:37:51 2011 +0200
+++ b/src/server/func.c	Sun Oct 30 16:26:57 2011 +0100
@@ -40,6 +40,8 @@
 }
 
 void add_function(struct FuncStruct *func) {
+    printf("add function: %s\n", func->name);
+
     struct FuncStruct *f = malloc(sizeof(FuncStruct));
     *f = *func;
     hashmap_put(function_map, sstr((char*)f->name), func);
@@ -53,3 +55,6 @@
     }
 }
 
+FuncStruct* get_function(char *name) {
+    return hashmap_get(function_map, sstr(name));
+}
--- a/src/server/func.h	Tue Sep 06 22:37:51 2011 +0200
+++ b/src/server/func.h	Sun Oct 30 16:26:57 2011 +0100
@@ -41,6 +41,8 @@
 
 void add_functions(struct FuncStruct *funcs);
 
+FuncStruct* get_function(char *name);
+
 
 #ifdef	__cplusplus
 }
--- a/src/server/httprequest.c	Tue Sep 06 22:37:51 2011 +0200
+++ b/src/server/httprequest.c	Sun Oct 30 16:26:57 2011 +0100
@@ -35,6 +35,8 @@
 #include "io.h"
 #include "util.h"
 #include "httprequest.h"
+#include "conf.h"
+#include "vserver.h"
 
 HTTPRequest *http_request_new() {
     HTTPRequest *req = malloc(sizeof(HTTPRequest));
@@ -62,6 +64,7 @@
     NSAPISession *sn = malloc(sizeof(NSAPISession));
     NSAPIRequest *rq = malloc(sizeof(NSAPIRequest));
     request->rq = rq;
+    rq->phase = NSAPIAuthTrans;
 
     // fill session structure
     sn->sn.pool = pool_create();
@@ -73,9 +76,14 @@
 
     // init NSAPI request structure
     if(request_initialize(request->pool, request, rq) != 0) {
+        printf("Cannot initialize request structure\n");
         return 1;
     }
 
+    // set default virtual server
+    rq->vs = conf_get_default_vs();
+
+
     /* Pass request line as "clf-request" */
     pblock_kvinsert(
             pb_key_clf_request,
@@ -129,6 +137,7 @@
 
 
     // Send the request to the NSAPI system
+    nsapi_handle_request(sn, rq);
 
     return 0;
 }
@@ -152,3 +161,116 @@
     hd->len++;
 }
 
+
+/*
+ * NSAPI Processing
+ * TODO: add this to new file
+ */
+
+int nsapi_handle_request(NSAPISession *sn, NSAPIRequest *rq) {
+    // TODO: threadpool
+
+    int r = REQ_NOACTION;
+
+    do {
+        switch(rq->phase) {
+            case NSAPIAuthTrans: {
+                rq->phase++;
+            }
+            case NSAPINameTrans: {
+                printf(">>> NameTrans\n");
+                r = nsapi_nametrans(sn, rq);
+                if(r != REQ_PROCEED) {
+                    break;
+                }
+                rq->phase++;
+            }
+            case NSAPIPathCheck: {
+                printf(">>> PathCheck\n");
+                rq->phase++;
+            }
+            case NSAPIService: {
+                printf(">>> Service\n");
+                r = nsapi_service(sn, rq);
+                if(r != REQ_PROCEED) {
+                    break;
+                }
+                rq->phase++;
+            }
+            case REQ_FINISH: {
+                printf(">>> Finish\n");
+                r = nsapi_finish_request(sn, rq);
+            }
+        }
+    } while (r == REQ_RESTART);
+
+
+    return r;
+}
+
+int nsapi_finish_request(NSAPISession *sn, NSAPIRequest *rq) {
+    return 0;
+}
+
+int nsapi_nametrans(NSAPISession *sn, NSAPIRequest *rq) {
+    httpd_objset *objset = rq->vs->objset;
+    printf("nsapi_nametrans\n");
+
+    int ret = -1;
+    for(int i=0;i<objset->pos;i++) {
+        httpd_object *obj = objset->obj[i];
+        dtable *dt = object_get_dtable(obj, NSAPINameTrans);
+
+        printf("object[%s] dt: %d\n", obj->name, dt);
+
+        // execute directives
+        for(int j=0;j<dt->ndir;j++) {
+            directive *d = dt->directive[j];
+
+            printf("execute [%s]\n", d->func->name);
+            ret = d->func->func(d->param, (Session*)sn, (Request*)rq);
+            if(ret == REQ_PROCEED || ret == REQ_PROCESSING) {
+                break;
+            }
+        }
+
+        // TODO: stultus
+        if(ret == REQ_PROCEED || ret == REQ_PROCESSING) {
+            break;
+        }
+    }
+
+    // todo: check object, path, ...
+    char *ppath = pblock_findkeyval(pb_key_ppath, rq->rq.vars);
+    printf("ppath: [%s]\n", ppath);
+
+    return ret;
+}
+
+int nsapi_service(NSAPISession *sn, NSAPIRequest *rq) {
+    httpd_objset *objset = rq->vs->objset;
+
+    int ret = -1;
+    for(int i=0;i<objset->pos;i++) {
+        httpd_object *obj = objset->obj[i];
+        dtable *dt = object_get_dtable(obj, NSAPIService);
+
+        // execute directives
+        for(int j=0;j<dt->ndir;j++) {
+            directive *d = dt->directive[j];
+
+            ret = d->func->func(d->param, (Session*)sn, (Request*)rq);
+            if(ret == REQ_PROCEED || ret == REQ_PROCESSING) {
+                break;
+            }
+        }
+
+        // TODO: stultus
+        if(ret == REQ_PROCEED || ret == REQ_PROCESSING) {
+            break;
+        }
+    }
+
+    return ret;
+}
+
--- a/src/server/httprequest.h	Tue Sep 06 22:37:51 2011 +0200
+++ b/src/server/httprequest.h	Sun Oct 30 16:26:57 2011 +0100
@@ -78,6 +78,11 @@
 
 void header_add(HeaderArray *hd, char *name, char *value);
 
+int nsapi_handle_request(NSAPISession *sn, NSAPIRequest *rq);
+int nsapi_finish_request(NSAPISession *sn, NSAPIRequest *rq);
+int nsapi_nametrans(NSAPISession *sn, NSAPIRequest *rq);
+int nsapi_service(NSAPISession *sn, NSAPIRequest *rq);
+
 
 /* request.h functions */
 int request_initialize(
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/server/nametrans.c	Sun Oct 30 16:26:57 2011 +0100
@@ -0,0 +1,41 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2011 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "nametrans.h"
+
+#include "pblock.h"
+
+int test_nametrans(pblock *pb, Session *sn, Request *rq) {
+    printf("test_nametrans...\n");
+
+    // set ppath
+    char *ppath = "/export/home/olaf/Desktop/hello.txt";
+    pblock_kvinsert(pb_key_ppath, ppath, strlen(ppath), rq->vars);
+
+    return REQ_PROCEED;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/server/nametrans.h	Sun Oct 30 16:26:57 2011 +0100
@@ -0,0 +1,46 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2011 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NAMETRANS_H
+#define	NAMETRANS_H
+
+#include "nsapi.h"
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+int test_nametrans(pblock *pb, Session *sn, Request *rq);
+
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* NAMETRANS_H */
+
--- a/src/server/nsapi.h	Tue Sep 06 22:37:51 2011 +0200
+++ b/src/server/nsapi.h	Sun Oct 30 16:26:57 2011 +0100
@@ -332,6 +332,14 @@
 /* Too busy to execute this now */
 #define REQ_TOOBUSY -5
 
+
+/**** NSAPI extensions ****/
+
+/* The function is still in progress (async extension) */
+#define REQ_PROCESSING -8
+
+/**** END NSAPI extensions ****/
+
 /* --- End miscellaneous definitions --- */
 
 /* --- Begin native platform includes --- */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/server/object.c	Sun Oct 30 16:26:57 2011 +0100
@@ -0,0 +1,88 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2011 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "nsapi.h"
+
+#include "object.h"
+
+#include "func.h"
+
+
+
+httpd_object* object_new(char *name) {
+    // TODO: Speicherverwaltung
+    httpd_object *obj = malloc(sizeof(httpd_object));
+    obj->name = name;
+
+    // create directive table
+    obj->dt = calloc(sizeof(struct dtable), NUM_NSAPI_TYPES - 1);
+    obj->nd = NUM_NSAPI_TYPES - 1;
+
+    return obj;
+}
+
+void object_free(httpd_object *obj) {
+    free(obj->name);
+    // TODO: free objects
+    free(obj->dt);
+}
+
+
+void object_add_directive(httpd_object *obj, directive *dir, int dt) {
+    dtable *l = object_get_dtable(obj, dt);
+    // allocate space for the new directive
+    l->directive = realloc(l->directive, (l->ndir+1)*sizeof(directive*));
+    // add directive
+    l->directive[l->ndir] = dir;
+    l->ndir++;
+}
+
+
+
+
+httpd_objset* create_test_objset() {
+    httpd_objset *objset = malloc(sizeof(httpd_objset));
+    objset->obj = calloc(1, sizeof(httpd_object*));
+
+    httpd_object *obj = object_new("default");
+    objset->obj[0] = obj;
+    objset->pos = 1;
+    
+    directive *d1 = malloc(sizeof(directive));
+    d1->func = get_function("test-nametrans");
+    d1->param = NULL;
+    object_add_directive(obj, d1, NSAPINameTrans);
+
+    directive *d2 = malloc(sizeof(directive));
+    d2->func = get_function("test-service");
+    d2->param = NULL;
+    object_add_directive(obj, d2, NSAPIService);
+    
+    return objset;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/server/object.h	Sun Oct 30 16:26:57 2011 +0100
@@ -0,0 +1,102 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2011 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef OBJECT_H
+#define	OBJECT_H
+
+#include "nsapi.h"
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+// TODO: Enum auslagern in andere Datei?
+enum RequestPhase {
+    NSAPIAuthTrans = 0,
+    NSAPINameTrans,
+    NSAPIPathCheck,
+    NSAPIService,
+    REQ_FINISH,
+    NUM_NSAPI_TYPES
+};
+typedef enum RequestPhase RequestPhase;
+
+struct directive {
+    FuncStruct *func;
+    pblock     *param;
+};
+
+struct dtable {
+    directive **directive;
+    int ndir;
+};
+
+struct httpd_object {
+    char  *name;
+
+    dtable *dt;
+    int    nd;
+};
+
+struct httpd_objset {
+    httpd_object **obj;
+    int pos;
+};
+
+
+/*
+ * create a new httpd_object
+ */
+httpd_object* object_new(char *name);
+
+/*
+ * frees an httpd_object
+ */
+void object_free(httpd_object *obj);
+
+/*
+ * adds a directive to the object with the type dt (enum DirectiveType)
+ */
+void object_add_directive(httpd_object *obj, directive *dir, int dt);
+
+/*
+ * get a list of all directives with a specific type
+ */
+#define object_get_dtable(obj,type) &obj->dt[type];
+
+
+
+httpd_objset* create_test_objset();
+
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* OBJECT_H */
+
--- a/src/server/objs.mk	Tue Sep 06 22:37:51 2011 +0200
+++ b/src/server/objs.mk	Sun Oct 30 16:26:57 2011 +0100
@@ -53,6 +53,10 @@
 MOBJ += sessionhandler.o
 MOBJ += httpparser.o
 MOBJ += httprequest.o
+MOBJ += vserver.o
+MOBJ += object.o
+MOBJ += nametrans.o
+MOBJ += service.o
 
 
 MAINOBJS = $(MOBJ:%=$(OBJPRE)%)
--- a/src/server/pblock.cpp	Tue Sep 06 22:37:51 2011 +0200
+++ b/src/server/pblock.cpp	Sun Oct 30 16:26:57 2011 +0100
@@ -565,12 +565,14 @@
     int pindex = PListGetFreeIndex(pl);
     if (pindex < 1) {
         /* Error - invalid property index */
+        printf("Error - invalid property index\n");
         return;
     }
 
     /* Allocate/grow the symbol table as needed */
     PLSymbolTable_t *pt = PListSymbolTable(pl);
     if (!pt) {
+        printf("!pt\n");
         return;
     }
 
--- a/src/server/request.h	Tue Sep 06 22:37:51 2011 +0200
+++ b/src/server/request.h	Sun Oct 30 16:26:57 2011 +0100
@@ -30,6 +30,7 @@
 #define	REQUEST_H
 
 #include "nsapi.h"
+#include "object.h"
 
 #ifdef	__cplusplus
 extern "C" {
@@ -40,6 +41,8 @@
 
 struct NSAPIRequest {
     Request rq;
+    RequestPhase phase;
+    VirtualServer *vs;
 };
 
 #define REQ_HASHSIZE 10
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/server/service.c	Sun Oct 30 16:26:57 2011 +0100
@@ -0,0 +1,60 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2011 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+#include "service.h"
+#include "io.h"
+#include "pblock.h"
+
+int test_service(pblock *pb, Session *sn, Request *rq) {
+    printf("test_service\n");
+
+    SystemIOStream *io = (SystemIOStream*) sn->csd;
+    char *ppath = pblock_findkeyval(pb_key_ppath, rq->vars);
+    FILE *out = fdopen(io->fd, "w");
+    FILE *in = fopen(ppath, "r");
+    printf("open path: %s\n", ppath);
+
+    fprintf(out, "HTTP/1.1 200 OK\n");
+    fprintf(out, "Server: Webserver Pre-Alpha\n");
+    fprintf(out, "Concent-Length: 27\n");
+    fprintf(out, "Connection: close\n\n");
+    fflush(out);
+
+    char buffer[128];
+    int r;
+    while((r = fread(buffer, 1, 64, in)) > 0) {
+        fwrite(buffer, 1, r, out);
+    }
+    fflush(out);
+    fclose(in);
+    fclose(out);
+
+    return REQ_PROCEED;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/server/service.h	Sun Oct 30 16:26:57 2011 +0100
@@ -0,0 +1,46 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2011 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SERVICE_H
+#define	SERVICE_H
+
+#include "nsapi.h"
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+int test_service(pblock *pb, Session *sn, Request *rq);
+
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* SERVICE_H */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/server/vserver.c	Sun Oct 30 16:26:57 2011 +0100
@@ -0,0 +1,39 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2011 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "vserver.h"
+
+VirtualServer* vs_new() {
+    VirtualServer *vs = malloc(sizeof(VirtualServer));
+    vs->default_obj_name = NULL;
+    vs->objset = NULL;
+    return vs;
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/server/vserver.h	Sun Oct 30 16:26:57 2011 +0100
@@ -0,0 +1,53 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2011 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef VSERVER_H
+#define	VSERVER_H
+
+#include "object.h"
+#include "nsapi.h"
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+struct VirtualServer {
+    char          *default_obj_name;
+    httpd_objset  *objset;
+};
+
+VirtualServer* vs_new();
+
+
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* VSERVER_H */
+
--- a/src/server/ws-fn.c	Tue Sep 06 22:37:51 2011 +0200
+++ b/src/server/ws-fn.c	Sun Oct 30 16:26:57 2011 +0100
@@ -28,6 +28,11 @@
 
 #include "nsapi.h"
 
+#include "nametrans.h"
+#include "service.h"
+
 struct FuncStruct webserver_funcs[] = {
+    { "test-nametrans", test_nametrans, NULL, 0 },
+    { "test-service", test_service, NULL, 0},
     {NULL, NULL, NULL, 0}
 };

mercurial