aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/config.c10
-rw-r--r--src/net.h3
-rw-r--r--src/net/util.c2
3 files changed, 12 insertions, 3 deletions
diff --git a/src/config.c b/src/config.c
index 37f2908..60d4079 100644
--- a/src/config.c
+++ b/src/config.c
@@ -27,7 +27,8 @@ int m_config_index(lua_State* L){
lua_pushinteger(L, *cc.value.c_int);
break;
case c_string:
- lua_pushlstring(L, *cc.value.c_string, *cc.value.len);
+ if(*cc.value.c_string == NULL) lua_pushnil(L);
+ else lua_pushlstring(L, *cc.value.c_string, *cc.value.len);
break;
case c_number:
lua_pushnumber(L, *cc.value.c_number);
@@ -63,7 +64,12 @@ int m_config_newindex(lua_State* L){
*cc.value.c_int = lua_tointeger(L, 3);
break;
case c_string:
- *cc.value.c_string = (char*)luaL_tolstring(L, 3, cc.value.len);
+ if(lua_isnil(L, 3)){
+ *cc.value.c_string = NULL;
+ *cc.value.len = 0;
+ } else {
+ *cc.value.c_string = (char*)luaL_tolstring(L, 3, cc.value.len);
+ }
break;
case c_number:
*cc.value.c_number = lua_tonumber(L, 3);
diff --git a/src/net.h b/src/net.h
index 8c36057..f7e5d64 100644
--- a/src/net.h
+++ b/src/net.h
@@ -53,8 +53,9 @@ static const luaL_Reg net_function_list [] = {
};
extern char* _mimetypes;
+extern uint64_t _mimetypes_len;
static struct config net_config[] = {
- {.name = "mimetypes", .type = c_string, .value = {.c_string = &_mimetypes}},
+ {.name = "mimetypes", .type = c_string, .value = {.c_string = &_mimetypes, .len = &_mimetypes_len}},
{.type = c_none}
};
diff --git a/src/net/util.c b/src/net/util.c
index e8e54d0..efdbe75 100644
--- a/src/net/util.c
+++ b/src/net/util.c
@@ -408,8 +408,10 @@ parray_t* route_match(parray_t* paths, char* request, larray_t** _params){
map_t* mime_type = NULL;
char* _mimetypes = "/etc/mime.types";
+uint64_t _mimetypes_len = 15;
void parse_mimetypes(){
+ if(_mimetypes == NULL || _mimetypes_len == 0) return;
mime_type = map_init();
FILE* fp = fopen(_mimetypes, "r");