Stop using cv2pdb and improve HTTP handling a little

This commit is contained in:
2023-07-03 15:18:21 -04:00
parent ea10bddb0b
commit af62ac040f
4 changed files with 36 additions and 16 deletions

View File

@@ -121,7 +121,6 @@ ifeq "$(OS)" "linux"
LINKDLL=g++ -Wall $(OPT) -std=c++17 -export-dynamic -Wl,--no-allow-shlib-undefined -Wl,-z,defs -shared -o
LINKEXE=g++ -Wall $(OPT) -std=c++17 -o
MAKEDEPS=true
MAKEPDB=true
OPENSSL_INCLUDE=-I./ext/openssl-3.0.1/inc
LUA_FLAGS=-DLUA_USE_APICHECK -DLUA_USE_POSIX
LIBS=-L./ext/openssl-3.0.1/lib/linux -lssl -lcrypto -ldl
@@ -143,7 +142,6 @@ ifeq "$(OS)" "mingw"
LINKDLL=g++ -Wall $(OPT) -std=c++17 -Wl,--no-allow-shlib-undefined -shared -o
LINKEXE=g++ -Wall $(OPT) -std=c++17 -o
MAKEDEPS=true
MAKEPDB=./ext/cv2pdb.exe
OPENSSL_INCLUDE=-I./ext/openssl-3.0.1/inc
LUA_FLAGS=-DLUA_USE_APICHECK -DLUA_COMPAT_ALL
LIBS=-L./ext/openssl-3.0.1/lib/mingw -lssl -lcrypto -lws2_32 -lcrypt32 -lcryptui
@@ -168,7 +166,6 @@ ifeq "$(OS)" "visual"
LINKDLL=CL $(OPT) /std:c++17 /EHsc /nologo /LDd /Fe:
LINKEXE=CL $(OPT) /std:c++17 /EHsc /nologo /Fe:
MAKEDEPS=g++ -Wall -std=c++17 -MMD -E -o
MAKEPDB=true
OPENSSL_INCLUDE=-I./ext/openssl-3.1.0/inc
LUA_FLAGS=-DLUA_USE_APICHECK -DLUA_COMPAT_ALL
LIBS=ext/openssl-3.1.0/lib/visual/libcrypto.lib ext/openssl-3.1.0/lib/visual/libssl.lib ws2_32.lib crypt32.lib cryptui.lib user32.lib advapi32.lib
@@ -188,15 +185,12 @@ build/DIRECTORY:
build/$(OS)/$(LUPREX_EXE): build/$(OS)/$(LUPREXLIB_DLL) $(OBJ_DRV)
$(LINKEXE) $@ $(OBJ_DRV) $(LIBS)
$(MAKEPDB) $@
build/$(OS)/$(LUPREXSTATIC_EXE): $(OBJ_DRV) $(OBJ_ERIS) $(OBJ_CORE)
$(LINKEXE) $@ $^ $(LIBS)
$(MAKEPDB) $@
build/$(OS)/$(LUPREXLIB_DLL): $(OBJ_ERIS) $(OBJ_CORE)
$(LINKDLL) $@ $^
$(MAKEPDB) $@
build/$(OS)/eris/%.obj: ext/eris-master/src/%.c build/DIRECTORY
$(MAKEDEPS) $@d $(LUA_FLAGS) $<

View File

@@ -1143,6 +1143,24 @@ eng::string HttpParser::first_path_component(std::string_view defval) const {
}
}
eng::string HttpParser::to_lua_identifier(std::string_view pathcomp) {
eng::ostringstream oss;
for (char c : pathcomp) {
if (sv::ascii_islower(c)) {
oss << c;
} else if (sv::ascii_isupper(c)) {
oss << char(c + 'a' - 'A');
} else if (sv::ascii_isdigit(c)) {
oss << c;
} else if ((c == '.') || (c == '_')) {
oss << '_';
} else {
return "";
}
}
return oss.str();
}
void HttpParser::fail(int code, std::string_view message) {
status_ = code;
error_ = message;

View File

@@ -421,6 +421,13 @@ public:
// Synthesize an error and store it in lua.
//
static void store_fail(LuaCoreStack &LS, LuaSlot tab, int status, std::string_view error);
// Convert a path component into a lua identifier.
//
// Returns the empty string if the path component cannot be converted
// to a lua identifier.
//
static eng::string to_lua_identifier(std::string_view pathcomp);
};
class HttpClientRequestMap : public eng::map<int64_t, HttpClientRequest> {

View File

@@ -457,13 +457,6 @@ HttpServerResponse World::http_serve(const HttpParser &request) {
return response;
}
// Get the name of the desired function.
std::string_view fn = request.first_path_component("index");
if (!sv::is_lua_id(fn)) {
response.fail(404, util::ss("not a function name: ", fn));
return response;
}
lua_State *L = state();
LuaVar www, func, reqtab;
LuaExtStack LS(L, www, func, reqtab);
@@ -476,11 +469,19 @@ HttpServerResponse World::http_serve(const HttpParser &request) {
return response;
}
// Get the name of the desired function.
std::string_view orig_fn = request.first_path_component("index");
eng::string lua_fn = HttpParser::to_lua_identifier(orig_fn);
if (lua_fn.empty()) {
response.fail(404, util::ss("cannot convert to lua function name: ", orig_fn));
return response;
}
// Get the closure. If there's no such closure,
// return a 404 Not Found to the client.
LS.rawget(func, www, fn);
LS.rawget(func, www, lua_fn);
if (!LS.isfunction(func)) {
response.fail(404, util::ss("no such function: www.", fn));
response.fail(404, util::ss("no such lua function: www.", lua_fn));
return response;
}
@@ -507,7 +508,7 @@ HttpServerResponse World::http_serve(const HttpParser &request) {
// a 500 Internal Server Error to the client.
int newtop = lua_gettop(L);
if ((newtop != oldtop + 1) || (!lua_istable(L, newtop))) {
response.fail(500, util::ss("lua function www.", fn, " didn't return a table"));
response.fail(500, util::ss("lua function www.", lua_fn, " didn't return a table"));
return response;
}