From: nishi Date: Sat, 20 Apr 2024 09:17:52 +0000 (+0000) Subject: login param X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=37ec7fc494571e55cd658ed0c0143ea1a9013276;p=mandshurica.git login param git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@56 f982e544-4a7d-3444-ad1a-fde59a2a69f1 --- diff --git a/Mandshurica/file.c b/Mandshurica/file.c index 28ae8f5..74eeffc 100644 --- a/Mandshurica/file.c +++ b/Mandshurica/file.c @@ -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; diff --git a/Mandshurica/mandshurica.h b/Mandshurica/mandshurica.h index b1206ca..b49e2c8 100644 --- a/Mandshurica/mandshurica.h +++ b/Mandshurica/mandshurica.h @@ -33,6 +33,7 @@ #include "ms_config.h" +#include #include #define MANDSHURICA_VERSION "0.0" @@ -46,11 +47,15 @@ #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; }; diff --git a/Mandshurica/ms_file.h b/Mandshurica/ms_file.h index 66e0fc7..652c6e6 100644 --- a/Mandshurica/ms_file.h +++ b/Mandshurica/ms_file.h @@ -31,8 +31,10 @@ #ifndef __MANDSHURICA_MS_FILE_H__ #define __MANDSHURICA_MS_FILE_H__ +#include "mandshurica.h" + #include -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 diff --git a/Mandshurica/ms_template.h b/Mandshurica/ms_template.h index 67bae3a..057eacd 100644 --- a/Mandshurica/ms_template.h +++ b/Mandshurica/ms_template.h @@ -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 diff --git a/Mandshurica/template.c b/Mandshurica/template.c index ce9ab96..062596f 100644 --- a/Mandshurica/template.c +++ b/Mandshurica/template.c @@ -42,7 +42,7 @@ #include #include -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); diff --git a/Module/http.c b/Module/http.c index 860f13a..de92abe 100644 --- a/Module/http.c +++ b/Module/http.c @@ -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) {