backage builder
This commit is contained in:
@@ -201,8 +201,8 @@ void setup_unit_paths(Request* context, SharedUnit* su, String file_name)
|
||||
return;
|
||||
|
||||
su->src_path = dirname(file_name);
|
||||
su->bin_path = context->server->config.BIN_DIRECTORY + su->src_path;
|
||||
su->pre_path = context->server->config.BIN_DIRECTORY + su->src_path;
|
||||
su->bin_path = context->server->config["BIN_DIRECTORY"] + su->src_path;
|
||||
su->pre_path = context->server->config["BIN_DIRECTORY"] + su->src_path;
|
||||
|
||||
su->src_file_name = basename(file_name);
|
||||
su->bin_file_name = su->src_file_name + ".so";
|
||||
@@ -253,8 +253,8 @@ String compile_setup_file(Request* context, SharedUnit* su)
|
||||
String result =
|
||||
String("#ifndef UCE_LIB_INCLUDED\n") +
|
||||
"#define UCE_LIB_INCLUDED\n" +
|
||||
("#include \"")+context->server->config.COMPILER_SYS_PATH +"/src/lib/uce_lib.h\" \n"+
|
||||
file_get_contents(context->server->config.COMPILER_SYS_PATH + "/" + context->server->config.SETUP_TEMPLATE) +
|
||||
("#include \"")+context->server->config["COMPILER_SYS_PATH"] +"/src/lib/uce_lib.h\" \n"+
|
||||
file_get_contents(context->server->config["COMPILER_SYS_PATH"] + "/" + context->server->config["SETUP_TEMPLATE"]) +
|
||||
"#endif \n";
|
||||
StringList declarations;
|
||||
StringList load_units;
|
||||
@@ -279,10 +279,8 @@ void compile_shared_unit(Request* context, SharedUnit* su, String file_name)
|
||||
file_put_contents(su->setup_file_name, compile_setup_file(context, su));
|
||||
file_put_contents(su->api_file_name, join(su->api_declarations, "\n"));
|
||||
|
||||
//printf("Config.COMPILE_SCRIPT %s\n", String(su->pre_path + "/" + su->pre_file_name).c_str());
|
||||
|
||||
if(!su->opt_so_optional)
|
||||
su->compiler_messages = trim(shell_exec(context->server->config.COMPILE_SCRIPT+" "+
|
||||
su->compiler_messages = trim(shell_exec(context->server->config["COMPILE_SCRIPT"]+" "+
|
||||
shell_escape(su->src_path)+" "+
|
||||
shell_escape(su->bin_path)+" "+
|
||||
shell_escape(su->file_name)+" "+
|
||||
|
||||
@@ -140,6 +140,41 @@ StringList split(String str, String delim)
|
||||
return(result);
|
||||
}
|
||||
|
||||
StringMap split_kv(String s, char separator, bool trim_whitespace)
|
||||
{
|
||||
StringMap result;
|
||||
String k;
|
||||
String v;
|
||||
for(auto s : split(s, "\n"))
|
||||
{
|
||||
u8 mode = 0;
|
||||
k = "";
|
||||
v = "";
|
||||
for(auto c : s)
|
||||
{
|
||||
if(mode == 0)
|
||||
{
|
||||
if(c == separator)
|
||||
mode = 1;
|
||||
else
|
||||
k.append(1, c);
|
||||
}
|
||||
else
|
||||
{
|
||||
v.append(1, c);
|
||||
}
|
||||
}
|
||||
if(k != "")
|
||||
{
|
||||
if(trim_whitespace)
|
||||
result[trim(k)] = trim(v);
|
||||
else
|
||||
result[k] = v;
|
||||
}
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
String join(StringList l, String delim)
|
||||
{
|
||||
String result;
|
||||
|
||||
@@ -10,6 +10,7 @@ String trim(String raw);
|
||||
StringList split_space(String str);
|
||||
StringList split(String str, String delim);
|
||||
StringList split_utf8(String s, bool compound_characters = false);
|
||||
StringMap split_kv(String s, char separator = '=', bool trim_whitespace = true);
|
||||
String join(StringList l, String delim = "\n");
|
||||
String nibble(String& haystack, String delim);
|
||||
void json_consume_space(String s, u32& i);
|
||||
|
||||
+30
-2
@@ -440,7 +440,7 @@ void spawn_subprocess(std::function<void()> exec_after_spawn)
|
||||
|
||||
pid_t task_pid(String key)
|
||||
{
|
||||
String status_file_name = context->server->config.BIN_DIRECTORY + "/task-" + key;
|
||||
String status_file_name = context->server->config["BIN_DIRECTORY"] + "/task-" + key;
|
||||
String status_file = file_get_contents(status_file_name);
|
||||
pid_t p = 0;
|
||||
if(status_file != "")
|
||||
@@ -455,7 +455,7 @@ pid_t task_pid(String key)
|
||||
|
||||
pid_t task(String key, std::function<void()> exec_after_spawn, u64 timeout)
|
||||
{
|
||||
String status_file_name = context->server->config.BIN_DIRECTORY + "/task-" + key;
|
||||
String status_file_name = context->server->config["BIN_DIRECTORY"] + "/task-" + key;
|
||||
String status_file = file_get_contents(status_file_name);
|
||||
pid_t p;
|
||||
if(status_file != "")
|
||||
@@ -510,3 +510,31 @@ StringList ls(String dir)
|
||||
{
|
||||
return(split(trim(shell_exec("ls -1 "+shell_escape(dir))), "\n"));
|
||||
}
|
||||
|
||||
StringMap make_server_settings()
|
||||
{
|
||||
StringMap cfg;
|
||||
|
||||
cfg["BIN_DIRECTORY"] = "/tmp/uce/work";
|
||||
cfg["COMPILE_SCRIPT"] = "scripts/compile";
|
||||
cfg["SETUP_TEMPLATE"] = "scripts/setup.h.template";
|
||||
cfg["LIT_ESC"] = "3d5b5_1";
|
||||
cfg["CONTENT_TYPE"] = "text/html; charset=utf-8";
|
||||
cfg["SOCKET_PATH"] = "/run/uce.sock";
|
||||
cfg["TMP_UPLOAD_PATH"] = "/tmp/uce/uploads";
|
||||
cfg["SESSION_PATH"] = "/tmp/uce/sessions";
|
||||
cfg["COMPILER_SYS_PATH"] = ".";
|
||||
cfg["PRECOMPILE_FILES_IN"] = ".";
|
||||
|
||||
cfg["LISTEN_PORT"] = std::to_string(9993);
|
||||
cfg["SESSION_TIME"] = std::to_string(60*60*24*30);
|
||||
cfg["WORKER_COUNT"] = std::to_string(4);
|
||||
cfg["MAX_MEMORY"] = std::to_string(1024*1024*16);
|
||||
|
||||
for(auto& it : split_kv(file_get_contents("/etc/uce/settings.cfg")))
|
||||
{
|
||||
cfg[it.first] = it.second;
|
||||
}
|
||||
|
||||
return(cfg);
|
||||
}
|
||||
|
||||
@@ -39,20 +39,6 @@ String nibble(String div, String& haystack)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void Request::invoke(String file_name)
|
||||
{
|
||||
DTree call_param;
|
||||
compiler_invoke(this, file_name, call_param);
|
||||
}
|
||||
|
||||
void Request::invoke(String file_name, DTree& call_param)
|
||||
{
|
||||
compiler_invoke(this, file_name, call_param);
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
void Request::ob_start()
|
||||
{
|
||||
ob_stack.push_back(new std::ostringstream());
|
||||
|
||||
+3
-3
@@ -146,7 +146,7 @@ typedef void (*request_handler)(Request* request);
|
||||
|
||||
String to_string(s64 v) { return(std::to_string(v)); }
|
||||
|
||||
struct ServerSettings {
|
||||
/*struct ServerSettings {
|
||||
|
||||
String BIN_DIRECTORY = "/tmp/uce/work";
|
||||
String COMPILE_SCRIPT = "scripts/compile";
|
||||
@@ -164,7 +164,7 @@ struct ServerSettings {
|
||||
u32 WORKER_COUNT = 4;
|
||||
u32 MAX_MEMORY = 1024*1024*16;
|
||||
|
||||
};
|
||||
};*/
|
||||
|
||||
struct SharedUnit {
|
||||
|
||||
@@ -204,7 +204,7 @@ struct UploadedFile {
|
||||
struct ServerState {
|
||||
|
||||
std::map<String, SharedUnit*> units;
|
||||
ServerSettings config;
|
||||
StringMap config;
|
||||
u32 request_count = 0;
|
||||
|
||||
};
|
||||
|
||||
+5
-5
@@ -124,7 +124,7 @@ StringMap parse_multipart(String q, String boundary, std::vector<UploadedFile>&
|
||||
{
|
||||
nibble("=\"", field);
|
||||
UploadedFile f;
|
||||
f.tmp_name = context->server->config.TMP_UPLOAD_PATH + std::to_string(rand());
|
||||
f.tmp_name = context->server->config["TMP_UPLOAD_PATH"] + std::to_string(rand());
|
||||
f.file_name = nibble("\"", field);
|
||||
String bin = field.substr(4, field.length()-6);
|
||||
f.size = bin.length();
|
||||
@@ -289,19 +289,19 @@ String make_session_id()
|
||||
|
||||
StringMap load_session_data(String session_id)
|
||||
{
|
||||
return(parse_query(file_get_contents(context->server->config.SESSION_PATH + "/" + session_id)));
|
||||
return(parse_query(file_get_contents(context->server->config["SESSION_PATH"] + "/" + session_id)));
|
||||
}
|
||||
|
||||
void save_session_data(String session_id, StringMap data)
|
||||
{
|
||||
file_put_contents(context->server->config.SESSION_PATH + "/" + session_id, encode_query(data));
|
||||
file_put_contents(context->server->config["SESSION_PATH"] + "/" + session_id, encode_query(data));
|
||||
}
|
||||
|
||||
String session_start(String session_name)
|
||||
{
|
||||
if(context->cookies[session_name].length() == 0)
|
||||
{
|
||||
set_cookie(session_name, make_session_id(), time() + context->server->config.SESSION_TIME);
|
||||
set_cookie(session_name, make_session_id(), time() + int_val(context->server->config["SESSION_TIME"]));
|
||||
}
|
||||
context->session_id = context->cookies[session_name];
|
||||
context->session_name = session_name;
|
||||
@@ -313,7 +313,7 @@ void session_destroy(String session_name)
|
||||
{
|
||||
if(context->cookies[session_name].length() > 0)
|
||||
{
|
||||
set_cookie(session_name, "", time() - context->server->config.SESSION_TIME);
|
||||
set_cookie(session_name, "", time() - int_val(context->server->config["SESSION_TIME"]));
|
||||
context->session.clear();
|
||||
save_session_data(context->session_id, context->session);
|
||||
context->session_id = "";
|
||||
|
||||
Reference in New Issue
Block a user