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) {
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;
#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;
};
#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;
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;
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);
char* header = NULL;
char** headers = NULL;
char cbuf[2];
+ struct ms_param param;
+ param.login = false;
cbuf[1] = 0;
while(true) {
int state;
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) {
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) {
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) {