]> Nishi Git Mirror - mandshurica.git/commitdiff
login param
authornishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Sat, 20 Apr 2024 09:17:52 +0000 (09:17 +0000)
committernishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Sat, 20 Apr 2024 09:17:52 +0000 (09:17 +0000)
git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@56 f982e544-4a7d-3444-ad1a-fde59a2a69f1

Mandshurica/file.c
Mandshurica/mandshurica.h
Mandshurica/ms_file.h
Mandshurica/ms_template.h
Mandshurica/template.c
Module/http.c

index 28ae8f581e8d19d9f9ece2cf153fe07040194a27..74eeffcaf6d810f36f63bc227fe1ebc4ab0a4f1f 100644 (file)
@@ -67,7 +67,7 @@ char* get_mime(const char* _path) {
        return mandshurica_strdup("application/octet-stream");
 }
 
-char* mandshurica_load(const char* path, char** type, char** lastmod, uint64_t* len) {
+char* mandshurica_load(const char* path, char** type, char** lastmod, uint64_t* len, struct ms_param param) {
        bool tmpl = false;
        *lastmod = NULL;
        if(strlen(path) > 4 && memcmp(path + strlen(path) - 5, ".tmpl", 5) == 0) {
@@ -82,7 +82,7 @@ char* mandshurica_load(const char* path, char** type, char** lastmod, uint64_t*
                        fdata[s.st_size] = 0;
                        *type = get_mime(path);
                        if(tmpl) {
-                               char* data = mandshurica_parse_template(fdata);
+                               char* data = mandshurica_parse_template(fdata, param);
                                *len = strlen(data);
                                fclose(f);
                                return data;
index b1206caf991192060e30f1bf76528330100b423d..b49e2c8235c151ed25587b61bc6a54777970e4ce 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "ms_config.h"
 
+#include <stdbool.h>
 #include <stdint.h>
 
 #define MANDSHURICA_VERSION "0.0"
 #define MS_AUTH_OK 0
 #define MS_AUTH_FAIL 1
 
+struct ms_param {
+       bool login;
+};
+
 struct mandshurica_config {
        void (*mandshurica_log)(const char*, const char*);
        char* (*mandshurica_get_param)(const char* param);
-       char* (*mandshurica_parse_template)(const char* data);
-       char* (*mandshurica_load)(const char* path, char** type, char** lastmod, uint64_t* len);
+       char* (*mandshurica_parse_template)(const char* data, struct ms_param param);
+       char* (*mandshurica_load)(const char* path, char** type, char** lastmod, uint64_t* len, struct ms_param param);
        char* (*mandshurica_sha512)(const char* pwd);
        struct mandshurica_mod*** libs;
 };
index 66e0fc7a00c3ba41c74e16dc21d513055db8e35a..652c6e622f519a1d17c9ef2de2f154d14d68d36b 100644 (file)
 #ifndef __MANDSHURICA_MS_FILE_H__
 #define __MANDSHURICA_MS_FILE_H__
 
+#include "mandshurica.h"
+
 #include <stdint.h>
 
-char* mandshurica_load(const char* path, char** type, char** lastmod, uint64_t* len);
+char* mandshurica_load(const char* path, char** type, char** lastmod, uint64_t* len, struct ms_param param);
 
 #endif
index 67bae3ad0d892f4f3a07e8d08ad1bfe82c34629b..057eacdb010994dad9f70361f076c2c720a2a775 100644 (file)
@@ -31,6 +31,8 @@
 #ifndef __MANDSHURICA_MS_TEMPLATE_H__
 #define __MANDSHURICA_MS_TEMPLATE_H__
 
-char* mandshurica_parse_template(const char* data);
+#include "mandshurica.h"
+
+char* mandshurica_parse_template(const char* data, struct ms_param param);
 
 #endif
index ce9ab9640bee7ab79e39c124c9dd73ab182312be..062596f5375341840ab35a6681ba6903f3e81bcf 100644 (file)
@@ -42,7 +42,7 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
-char* mandshurica_parse_template(const char* data) {
+char* mandshurica_parse_template(const char* data, struct ms_param param) {
        char* webroot = mandshurica_get_param("HTTPRoot");
        if(webroot == NULL) webroot = WEBROOT_PREFIX;
 
@@ -86,6 +86,8 @@ char* mandshurica_parse_template(const char* data) {
                                                        result = true;
                                                } else if(mandshurica_strcaseequ(arg, "false")) {
                                                        result = false;
+                                               } else if(mandshurica_strcaseequ(arg, "login")) {
+                                                       result = param.login;
                                                }
                                        }
                                        if(strcmp(op, "ifnot") == 0) result = !result;
@@ -101,7 +103,7 @@ char* mandshurica_parse_template(const char* data) {
                                                        fread(fb, s.st_size, 1, f);
                                                        fclose(f);
 
-                                                       char* res = mandshurica_parse_template(fb);
+                                                       char* res = mandshurica_parse_template(fb, param);
 
                                                        char* tmp = ret;
                                                        ret = mandshurica_strcat(tmp, res);
index 860f13ab179247d98a5f06acc26783374790ca43..de92abeeb46bd46a08741191dcb83f723d635c40 100644 (file)
@@ -128,6 +128,8 @@ void http_handler(int sock) {
        char* header = NULL;
        char** headers = NULL;
        char cbuf[2];
+       struct ms_param param;
+       param.login = false;
        cbuf[1] = 0;
        while(true) {
                int state;
@@ -211,16 +213,16 @@ void http_handler(int sock) {
                                                                                                                        if(S_ISDIR(st.st_mode)) {
                                                                                                                                if(data == NULL) {
                                                                                                                                        s = mandshurica_strcat(pth, "/index.html.tmpl");
-                                                                                                                                       data = config->mandshurica_load(s, &type, &lastmod, &len);
+                                                                                                                                       data = config->mandshurica_load(s, &type, &lastmod, &len, param);
                                                                                                                                        free(s);
                                                                                                                                }
                                                                                                                                if(data == NULL) {
                                                                                                                                        s = mandshurica_strcat(pth, "/index.html");
-                                                                                                                                       data = config->mandshurica_load(s, &type, &lastmod, &len);
+                                                                                                                                       data = config->mandshurica_load(s, &type, &lastmod, &len, param);
                                                                                                                                        free(s);
                                                                                                                                }
                                                                                                                        } else {
-                                                                                                                               data = config->mandshurica_load(pth, &type, &lastmod, &len);
+                                                                                                                               data = config->mandshurica_load(pth, &type, &lastmod, &len, param);
                                                                                                                        }
                                                                                                                }
                                                                                                                if(data != NULL) {
@@ -270,16 +272,16 @@ void http_handler(int sock) {
                                                                                                                        if(S_ISDIR(st.st_mode)) {
                                                                                                                                if(data == NULL) {
                                                                                                                                        s = mandshurica_strcat(pth, "/index.html.tmpl");
-                                                                                                                                       data = config->mandshurica_load(s, &type, &lastmod, &len);
+                                                                                                                                       data = config->mandshurica_load(s, &type, &lastmod, &len, param);
                                                                                                                                        free(s);
                                                                                                                                }
                                                                                                                                if(data == NULL) {
                                                                                                                                        s = mandshurica_strcat(pth, "/index.html");
-                                                                                                                                       data = config->mandshurica_load(s, &type, &lastmod, &len);
+                                                                                                                                       data = config->mandshurica_load(s, &type, &lastmod, &len, param);
                                                                                                                                        free(s);
                                                                                                                                }
                                                                                                                        } else {
-                                                                                                                               data = config->mandshurica_load(pth, &type, &lastmod, &len);
+                                                                                                                               data = config->mandshurica_load(pth, &type, &lastmod, &len, param);
                                                                                                                        }
                                                                                                                }
                                                                                                                if(data != NULL) {
@@ -441,16 +443,16 @@ void http_handler(int sock) {
                                                                                        if(S_ISDIR(st.st_mode)) {
                                                                                                if(data == NULL) {
                                                                                                        s = mandshurica_strcat(pth, "/index.html.tmpl");
-                                                                                                       data = config->mandshurica_load(s, &type, &lastmod, &len);
+                                                                                                       data = config->mandshurica_load(s, &type, &lastmod, &len, param);
                                                                                                        free(s);
                                                                                                }
                                                                                                if(data == NULL) {
                                                                                                        s = mandshurica_strcat(pth, "/index.html");
-                                                                                                       data = config->mandshurica_load(s, &type, &lastmod, &len);
+                                                                                                       data = config->mandshurica_load(s, &type, &lastmod, &len, param);
                                                                                                        free(s);
                                                                                                }
                                                                                        } else {
-                                                                                               data = config->mandshurica_load(pth, &type, &lastmod, &len);
+                                                                                               data = config->mandshurica_load(pth, &type, &lastmod, &len, param);
                                                                                        }
 
                                                                                        if(data != NULL) {