W7 done done

This commit is contained in:
root
2026-06-15 10:28:23 +00:00
parent b1a0df9c93
commit f5637bb587
31 changed files with 558 additions and 1148 deletions
+2
View File
@@ -28,7 +28,9 @@ DValue unit_info(String path = "");
StringList units_list();
bool unit_compile(String path = "");
#ifndef __UCE_WASM_UNIT__
SharedUnit* unit_load(String file_name);
#endif
void unit_render(String file_name);
void unit_render(String file_name, Request& context);
DValue* unit_call(String file_name, String function_name, DValue* call_param = 0);
+146 -18
View File
@@ -2,6 +2,7 @@
#include <cmath>
#include "types.h"
#include "functionlib.h"
#include "hash.h"
#include "uri.h"
#include "sys.h"
@@ -34,6 +35,18 @@ int uce_host_server_stop(const char* key, size_t key_len);
size_t uce_host_memcache_command(uint64_t sockfd, const char* command, size_t command_len, char* buf, size_t cap);
size_t uce_host_mysql(const char* in, size_t in_len, char* out, size_t cap);
size_t uce_host_request_perf(const char* in, size_t in_len, char* out, size_t cap);
size_t uce_host_shell_exec(const char* cmd, size_t cmd_len, char* buf, size_t cap);
int uce_host_file_open_locked(const char* path, size_t path_len, int open_flags, int lock_type, int create_mode, double wait_timeout_seconds, const char* purpose, size_t purpose_len);
void uce_host_file_close_locked(int handle);
void uce_host_file_release_process_locks(const char* reason, size_t reason_len);
size_t uce_host_file_read_locked_fd(int handle, char* buf, size_t cap);
int uce_host_file_write_locked_fd(int handle, const char* content, size_t content_len);
size_t uce_host_path_real(const char* path, size_t path_len, char* buf, size_t cap);
int uce_host_path_is_within(const char* path, size_t path_len, const char* root, size_t root_len);
size_t uce_host_cwd_get(char* buf, size_t cap);
int uce_host_cwd_set(const char* path, size_t path_len);
size_t uce_host_process_start_directory(char* buf, size_t cap);
size_t uce_host_last_trap_trace(char* buf, size_t cap);
}
static String wasm_current_unit_file()
@@ -41,13 +54,45 @@ static String wasm_current_unit_file()
return(context ? context->resources.current_unit_file : String(""));
}
String shell_exec(String cmd) { (void)cmd; return(""); }
String shell_escape(String raw) { return(raw); }
String shell_exec(String cmd)
{
size_t required = uce_host_shell_exec(cmd.data(), cmd.size(), 0, 0);
if(required == 0)
return("");
String output(required, 0);
size_t got = uce_host_shell_exec(cmd.data(), cmd.size(), &output[0], required);
output.resize(got <= required ? got : 0);
return(output);
}
String shell_escape(String raw)
{
String result;
for(auto c : raw)
{
if(c == '\'')
result.append("'\\''");
else
result.append(1, c);
}
return("'" + result + "'");
}
String basename(String fn) { while(fn.find("/") != String::npos) fn = fn.substr(fn.find("/") + 1); return(fn); }
String dirname(String fn) { auto pos = fn.find_last_of('/'); return(pos == String::npos ? "" : fn.substr(0, pos)); }
String path_join(String base, String child) { if(base == "") return(child); if(child == "") return(base); if(child[0] == '/') return(child); return(base + (base.back() == '/' ? "" : "/") + child); }
String path_real(String path) { return(path); }
bool path_is_within(String path, String root) { return(str_starts_with(path, root)); }
String path_real(String path)
{
size_t required = uce_host_path_real(path.data(), path.size(), 0, 0);
if(required == 0)
return("");
String resolved(required, 0);
size_t got = uce_host_path_real(path.data(), path.size(), &resolved[0], required);
resolved.resize(got <= required ? got : 0);
return(resolved);
}
bool path_is_within(String path, String root)
{
return(uce_host_path_is_within(path.data(), path.size(), root.data(), root.size()) != 0);
}
bool mkdir(String path)
{
String current = wasm_current_unit_file();
@@ -58,11 +103,29 @@ bool file_exists(String path)
String current = wasm_current_unit_file();
return(uce_host_file_exists(path.data(), path.size(), current.data(), current.size()) != 0);
}
int file_open_locked(String file_name, int open_flags, int lock_type, int create_mode, f64 wait_timeout_seconds, String purpose) { (void)file_name; (void)open_flags; (void)lock_type; (void)create_mode; (void)wait_timeout_seconds; (void)purpose; return(-1); }
void file_close_locked(int fd) { (void)fd; }
void file_release_process_locks(String reason) { (void)reason; }
String file_get_contents_locked_fd(int fd) { (void)fd; return(""); }
bool file_put_contents_locked_fd(int fd, String content) { (void)fd; (void)content; return(false); }
int file_open_locked(String file_name, int open_flags, int lock_type, int create_mode, f64 wait_timeout_seconds, String purpose)
{
return(uce_host_file_open_locked(
file_name.data(), file_name.size(), open_flags, lock_type, create_mode, wait_timeout_seconds,
purpose.data(), purpose.size()
));
}
void file_close_locked(int fd) { uce_host_file_close_locked(fd); }
void file_release_process_locks(String reason) { uce_host_file_release_process_locks(reason.data(), reason.size()); }
String file_get_contents_locked_fd(int fd)
{
size_t required = uce_host_file_read_locked_fd(fd, 0, 0);
if(required == 0)
return("");
String content(required, 0);
size_t got = uce_host_file_read_locked_fd(fd, &content[0], required);
content.resize(got <= required ? got : 0);
return(content);
}
bool file_put_contents_locked_fd(int fd, String content)
{
return(uce_host_file_write_locked_fd(fd, content.data(), content.size()) != 0);
}
String file_get_contents(String file_name)
{
String current = wasm_current_unit_file();
@@ -84,9 +147,27 @@ bool file_append_contents(String file_name, String content)
String current = wasm_current_unit_file();
return(uce_host_file_write(file_name.data(), file_name.size(), current.data(), current.size(), content.data(), content.size(), 1) != 0);
}
String cwd_get() { return("/"); }
void cwd_set(String path) { (void)path; }
String process_start_directory() { return("/"); }
String cwd_get()
{
size_t required = uce_host_cwd_get(0, 0);
if(required == 0)
return("");
String cwd(required, 0);
size_t got = uce_host_cwd_get(&cwd[0], required);
cwd.resize(got <= required ? got : 0);
return(cwd);
}
void cwd_set(String path) { uce_host_cwd_set(path.data(), path.size()); }
String process_start_directory()
{
size_t required = uce_host_process_start_directory(0, 0);
if(required == 0)
return("");
String cwd(required, 0);
size_t got = uce_host_process_start_directory(&cwd[0], required);
cwd.resize(got <= required ? got : 0);
return(cwd);
}
time_t file_mtime(String file_name)
{
String current = wasm_current_unit_file();
@@ -253,11 +334,51 @@ bool ws_close(String connection_id)
context->resources.websocket_dispatch_commands.push(command);
return(true);
}
String backtrace_frames_string(void* const* frames, size_t size, u32 skip_frames) { (void)frames; (void)size; (void)skip_frames; return(""); }
String capture_backtrace_string(u32 max_frames, u32 skip_frames) { (void)max_frames; (void)skip_frames; return(""); }
String signal_name(int sig) { (void)sig; return(""); }
String memcache_escape_key(String key) { return(key); }
StringList memcache_escape_keys(StringList keys) { return(keys); }
String backtrace_frames_string(void* const* frames, size_t size, u32 skip_frames) { (void)frames; (void)size; (void)skip_frames; return(capture_backtrace_string(0, 0)); }
String capture_backtrace_string(u32 max_frames, u32 skip_frames)
{
(void)max_frames;
(void)skip_frames;
size_t required = uce_host_last_trap_trace(0, 0);
if(required == 0)
return("");
String trace(required, 0);
size_t got = uce_host_last_trap_trace(&trace[0], required);
trace.resize(got <= required ? got : 0);
return(trace);
}
String signal_name(int sig)
{
switch(sig)
{
case 6: return("SIGABRT");
case 7: return("SIGBUS");
case 8: return("SIGFPE");
case 4: return("SIGILL");
case 2: return("SIGINT");
case 11: return("SIGSEGV");
case 15: return("SIGTERM");
default: return("");
}
}
String memcache_escape_key(String key)
{
String result;
for(auto c : key)
{
if(isspace((unsigned char)c))
c = '_';
result.append(1, c);
}
return(result);
}
StringList memcache_escape_keys(StringList keys)
{
StringList result;
for(auto s : keys)
result.push_back(memcache_escape_key(s));
return(result);
}
u64 memcache_connect(String host, short port)
{
if(host == "")
@@ -345,7 +466,14 @@ extern "C" int uce_wasm_task_run(uint64_t callback_id)
}
int task_kill(pid_t pid, int sig) { return(uce_host_task_kill(pid, sig)); }
String runtime_safe_key(String key, String label) { (void)label; return(key); }
String runtime_safe_key(String key, String label)
{
(void)label;
key = trim(key);
if(key == "")
return("");
return(gen_sha1(key));
}
pid_t task(String key, std::function<void()> exec_after_spawn, u64 timeout)
{
u64 id = wasm_next_task_callback_id++;
+4 -4
View File
@@ -3,10 +3,10 @@
#include <cstring>
extern "C" {
#include "../../vendor/miniz/miniz.c"
#include "../../vendor/miniz/miniz_tdef.c"
#include "../../vendor/miniz/miniz_tinfl.c"
#include "../../vendor/miniz/miniz_zip.c"
#include "../3rdparty/miniz/miniz.c"
#include "../3rdparty/miniz/miniz_tdef.c"
#include "../3rdparty/miniz/miniz_tinfl.c"
#include "../3rdparty/miniz/miniz_zip.c"
}
String zip_error(String api, String detail)