added some nsapi stuff

Sun, 30 Jun 2013 15:11:48 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 30 Jun 2013 15:11:48 +0200
changeset 82
740cfd9dd443
parent 81
d25825f37967
child 83
28433f06d5ee

added some nsapi stuff

src/server/daemon/log.c file | annotate | diff | comparison | revisions
src/server/daemon/log.h file | annotate | diff | comparison | revisions
src/server/daemon/main.c file | annotate | diff | comparison | revisions
src/server/daemon/netsite.h file | annotate | diff | comparison | revisions
src/server/daemon/protocol.c file | annotate | diff | comparison | revisions
src/server/daemon/request.c file | annotate | diff | comparison | revisions
src/server/daemon/vserver.c file | annotate | diff | comparison | revisions
src/server/public/nsapi.h file | annotate | diff | comparison | revisions
src/server/util/io.c file | annotate | diff | comparison | revisions
--- a/src/server/daemon/log.c	Fri Jun 28 14:52:35 2013 +0200
+++ b/src/server/daemon/log.c	Sun Jun 30 15:11:48 2013 +0200
@@ -205,7 +205,15 @@
  * log api functions
  */
 
-int log_ereport(int degree, const char *format, ...) { 
+int log_ereport(int degree, const char *format, ...) {
+    va_list args;
+    va_start(args, format);
+    int ret = log_ereport_v(degree, format, args);
+    va_end(args);
+    return ret;
+}
+
+int log_ereport_v(int degree, const char *format, va_list args) { 
     if(degree > 6) {
         return 0;
     }
@@ -215,14 +223,12 @@
     
     sstr_t lmsg;
     lmsg.ptr = NULL;
-    va_list ap;
-    va_start(ap, format);
     
     /* create log message prefix */
     sstr_t lpre = log_get_prefix(degree); 
     
     /* format message */
-    int len = vasprintf(&lmsg.ptr, format, ap);
+    int len = vasprintf(&lmsg.ptr, format, args);
     lmsg.length = len;
     
     /* create message string */
@@ -243,6 +249,23 @@
     return 0;
 }
 
+int log_error(int degree, const char *func, Session *sn, Request *rq,
+                       const char *format, ...)
+{
+    va_list args;
+    va_start(args, format);
+    int ret = log_error_v(degree, func, sn, rq, format, args);
+    va_end(args);
+    return ret;
+}
+
+int log_error_v(int degree, const char *func, Session *sn, Request *rq,
+                       const char *format, va_list args)
+{
+    // TODO: implement
+    return log_ereport(degree, format, args);
+}
+
 
 /*
  * access log
--- a/src/server/daemon/log.h	Fri Jun 28 14:52:35 2013 +0200
+++ b/src/server/daemon/log.h	Sun Jun 30 15:11:48 2013 +0200
@@ -65,7 +65,6 @@
 
 sstr_t log_get_prefix(int level);
 
-int log_ereport(int degree, const char *format, ...);
 
 // access logging
 LogFile* get_access_log_file(sstr_t file);
--- a/src/server/daemon/main.c	Fri Jun 28 14:52:35 2013 +0200
+++ b/src/server/daemon/main.c	Sun Jun 30 15:11:48 2013 +0200
@@ -97,7 +97,7 @@
     //test();
     
     /* if the -c parameter is specified, we don't create a daemon */
-    int d = 0;
+    int d = 1;
     for(int i=0;i<argc;i++) {
         char *p = argv[i];
         if(p[0] == '-' && p[1] == 'c') {
--- a/src/server/daemon/netsite.h	Fri Jun 28 14:52:35 2013 +0200
+++ b/src/server/daemon/netsite.h	Sun Jun 30 15:11:48 2013 +0200
@@ -87,16 +87,16 @@
    when the current request is finished.
  */
 
-#define MALLOC(size) INTsystem_malloc(size)
+//define MALLOC(size) INTsystem_malloc(size)
 NSAPI_PUBLIC void *INTsystem_malloc(int size);
 
-#define CALLOC(size) INTsystem_calloc(size)
+//define CALLOC(size) INTsystem_calloc(size)
 NSAPI_PUBLIC void *INTsystem_calloc(int size);
 
-#define REALLOC(ptr, size) INTsystem_realloc(ptr, size)
+//define REALLOC(ptr, size) INTsystem_realloc(ptr, size)
 NSAPI_PUBLIC void *INTsystem_realloc(void *ptr, int size);
 
-#define FREE(ptr) INTsystem_free(ptr)
+//define FREE(ptr) INTsystem_free(ptr)
 NSAPI_PUBLIC void INTsystem_free(void *ptr);
 
 #define STRDUP(ptr) INTsystem_strdup(ptr)
--- a/src/server/daemon/protocol.c	Fri Jun 28 14:52:35 2013 +0200
+++ b/src/server/daemon/protocol.c	Sun Jun 30 15:11:48 2013 +0200
@@ -374,3 +374,15 @@
         return REQ_NOACTION;
     }
 }
+
+char *http_uri2url(const char *prefix, const char *suffix) {
+    // TODO: implement
+    return NULL;
+}
+
+char *http_uri2url_dynamic(const char *prefix, const char *suffix,
+                                    Session *sn, Request *rq)
+{
+    // TODO: implement
+    return NULL;
+}
--- a/src/server/daemon/request.c	Fri Jun 28 14:52:35 2013 +0200
+++ b/src/server/daemon/request.c	Sun Jun 30 15:11:48 2013 +0200
@@ -30,6 +30,7 @@
 
 #include "../util/pblock.h"
 #include "httprequest.h"
+#include "../public/vfs.h"
 
 
 /* Code from req.cpp */
@@ -107,3 +108,30 @@
 const VirtualServer* request_get_vs(Request *rq) {
     return ((NSAPIRequest*)rq)->vs;
 }
+
+struct stat* request_stat_path(const char *path, Request *rq) {
+    // TODO: reimplement with vfs support
+    // TODO: use pool
+    struct stat *s = malloc(sizeof(struct stat));
+    if(stat(path, s)) {
+        return NULL;
+    }
+    // TODO: statpath and staterror
+    rq->finfo = s;
+    return s;
+}
+
+void request_free(Request *rq) {
+    // TODO: implement
+}
+
+Request* request_restart_internal(const char *uri, Request *rq) {
+    // TODO: implement
+    return NULL;
+}
+
+
+char* servact_translate_uri(char *uri, Session *sn) {
+    // TODO: implement
+    return NULL;
+}
--- a/src/server/daemon/vserver.c	Fri Jun 28 14:52:35 2013 +0200
+++ b/src/server/daemon/vserver.c	Sun Jun 30 15:11:48 2013 +0200
@@ -54,3 +54,13 @@
     return newvs;
 }
 
+
+
+
+
+// public API
+
+char* vs_translate_uri(const VirtualServer *vs, const char *uri) {
+    // TODO: implement
+    return NULL;
+}
--- a/src/server/public/nsapi.h	Fri Jun 28 14:52:35 2013 +0200
+++ b/src/server/public/nsapi.h	Sun Jun 30 15:11:48 2013 +0200
@@ -1201,9 +1201,28 @@
 const VirtualServer* request_get_vs(Request *rq);
 #define request_get_vs request_get_vs
 
+struct stat* request_stat_path(const char *path, Request *rq);
+#define request_stat_path request_stat_path
+
+void request_free(Request *rq);
+#define request_free request_free
+
+Request* request_restart_internal(const char *uri, Request *rq);
+#define request_restart_internal request_restart_internal
+
+
+char* vs_translate_uri(const VirtualServer *vs, const char *uri);
+#define vs_translate_uri vs_translate_uri
+
+char* servact_translate_uri(char *uri, Session *sn);
+#define servact_translate_uri servact_translate_uri
+#define request_translate_uri servact_translate_uri
 
 ssize_t net_write(SYS_NETFD fd, void *buf, size_t nbytes);
 ssize_t net_writev(SYS_NETFD fd, struct iovec *iovec, int iovcnt);
+ssize_t net_sendfile(SYS_NETFD fd, sendfiledata *sfd);
+ssize_t net_read(SYS_NETFD fd, void *buf, size_t nbytes);
+int net_flush(SYS_NETFD sd);
 
 // NSAPI extension
 ssize_t net_printf(SYS_NETFD fd, char *format, ...);
@@ -1325,6 +1344,12 @@
 #define pool_realloc INTpool_realloc
 #define pool_strdup INTpool_strdup
 
+
+#define MALLOC  malloc
+#define CALLOC(size) calloc(1, size)
+#define REALLOC realloc
+#define FREE    free
+
 // func util functions
 FuncStruct* func_resolve(pblock *pb, Session *sn, Request *rq);
 int func_exec (pblock *pb, Session *sn, Request *rq);
@@ -1337,6 +1362,12 @@
 #define protocol_start_response http_start_response
 int request_header(char *name, char **value, Session *sn, Request *rq);
 
+char *http_uri2url(const char *prefix, const char *suffix);
+char *http_uri2url_dynamic(const char *prefix, const char *suffix,
+                                    Session *sn, Request *rq);
+#define protocol_uri2url http_uri2url
+#define protocol_uri2url_dynamic http_uri2url_dynamic
+
 typedef void (*thrstartfunc)(void *);
 SYS_THREAD INTsysthread_start(int prio, int stksz, thrstartfunc fn, void *arg);
 NSAPI_PUBLIC void INTsysthread_sleep(int milliseconds);
@@ -1347,6 +1378,7 @@
 
 void webserver_atrestart(void (*fn)(void *), void *data);
 #define magnus_atrestart webserver_atrestart
+#define daemon_atrestart webserver_atrestart
 
 
 NSAPI_PUBLIC int INTshexp_match(const char *str, const char *exp);
@@ -1385,6 +1417,14 @@
 NSAPI_PUBLIC off_t system_lseek(SYS_FILE fd, off_t offset, int whence);
 NSAPI_PUBLIC int system_fclose(SYS_FILE fd);
 
+
+int log_ereport(int degree, const char *format, ...);
+int log_ereport_v(int degree, const char *format, va_list args);
+int log_error(int degree, const char *func, Session *sn, Request *rq,
+                       const char *format, ...);
+int log_error_v(int degree, const char *func, Session *sn, Request *rq,
+                       const char *format, va_list args);
+
 /* new macro and function definitions begin */
 
 NSAPI_PUBLIC int util_errno2status(int errno_value); // new
--- a/src/server/util/io.c	Fri Jun 28 14:52:35 2013 +0200
+++ b/src/server/util/io.c	Sun Jun 30 15:11:48 2013 +0200
@@ -297,6 +297,11 @@
     return IO_ERROR;
 }
 
+int net_flush(SYS_NETFD sd) {
+    // TODO: implement
+    return 0;
+}
+
 void net_close(SYS_NETFD fd) {
     ((IOStream*)fd)->close(fd);
 }

mercurial