--- embedaddon/lighttpd/src/mod_magnet.c 2013/10/14 10:32:48 1.1.1.1 +++ embedaddon/lighttpd/src/mod_magnet.c 2014/06/15 20:20:06 1.1.1.2 @@ -103,7 +103,7 @@ SETDEFAULTS_FUNC(mod_magnet_set_defaults) { if (!p) return HANDLER_ERROR; - p->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *)); + p->config_storage = calloc(1, srv->config_context->used * sizeof(plugin_config *)); for (i = 0; i < srv->config_context->used; i++) { plugin_config *s; @@ -446,6 +446,7 @@ typedef struct { MAGNET_ENV_PHYICAL_PATH, MAGNET_ENV_PHYICAL_REL_PATH, MAGNET_ENV_PHYICAL_DOC_ROOT, + MAGNET_ENV_PHYICAL_BASEDIR, MAGNET_ENV_URI_PATH, MAGNET_ENV_URI_PATH_RAW, @@ -466,6 +467,7 @@ static const magnet_env_t magnet_env[] = { { "physical.path", MAGNET_ENV_PHYICAL_PATH }, { "physical.rel-path", MAGNET_ENV_PHYICAL_REL_PATH }, { "physical.doc-root", MAGNET_ENV_PHYICAL_DOC_ROOT }, + { "physical.basedir", MAGNET_ENV_PHYICAL_BASEDIR }, { "uri.path", MAGNET_ENV_URI_PATH }, { "uri.path-raw", MAGNET_ENV_URI_PATH_RAW }, @@ -497,6 +499,7 @@ static buffer *magnet_env_get_buffer_by_id(server *srv case MAGNET_ENV_PHYICAL_PATH: dest = con->physical.path; break; case MAGNET_ENV_PHYICAL_REL_PATH: dest = con->physical.rel_path; break; case MAGNET_ENV_PHYICAL_DOC_ROOT: dest = con->physical.doc_root; break; + case MAGNET_ENV_PHYICAL_BASEDIR: dest = con->physical.basedir; break; case MAGNET_ENV_URI_PATH: dest = con->uri.path; break; case MAGNET_ENV_URI_PATH_RAW: dest = con->uri.path_raw; break; @@ -693,7 +696,7 @@ static int magnet_copy_response_header(server *srv, co /* lighty.header */ lua_getfield(L, -1, "lighty"); /* lighty.* from the env */ - assert(lua_istable(L, -1)); + force_assert(lua_istable(L, -1)); lua_getfield(L, -1, "header"); /* lighty.header */ if (lua_istable(L, -1)) { @@ -737,11 +740,11 @@ static int magnet_attach_content(server *srv, connecti * get the environment of the function */ - assert(lua_isfunction(L, -1)); + force_assert(lua_isfunction(L, -1)); lua_getfenv(L, -1); /* -1 is the function */ lua_getfield(L, -1, "lighty"); /* lighty.* from the env */ - assert(lua_istable(L, -1)); + force_assert(lua_istable(L, -1)); lua_getfield(L, -1, "content"); /* lighty.content */ if (lua_istable(L, -1)) { @@ -763,12 +766,17 @@ static int magnet_attach_content(server *srv, connecti lua_getfield(L, -3, "offset"); if (lua_isstring(L, -3)) { /* filename has to be a string */ - buffer *fn = buffer_init(); + buffer *fn; stat_cache_entry *sce; + const char *fn_str; + handler_t res; - buffer_copy_string(fn, lua_tostring(L, -3)); + fn_str = lua_tostring(L, -3); + fn = buffer_init_string(fn_str); - if (HANDLER_GO_ON == stat_cache_get_entry(srv, con, fn, &sce)) { + res = stat_cache_get_entry(srv, con, fn, &sce); + + if (HANDLER_GO_ON == res) { off_t off = 0; off_t len = 0; @@ -783,11 +791,13 @@ static int magnet_attach_content(server *srv, connecti } if (off < 0) { - return luaL_error(L, "offset for '%s' is negative", fn->ptr); + buffer_free(fn); + return luaL_error(L, "offset for '%s' is negative", fn_str); } if (len < off) { - return luaL_error(L, "offset > length for '%s'", fn->ptr); + buffer_free(fn); + return luaL_error(L, "offset > length for '%s'", fn_str); } chunkqueue_append_file(con->write_queue, fn, off, len - off); @@ -870,7 +880,7 @@ static handler_t magnet_attract(server *srv, connectio lua_pop(L, 1); - assert(lua_gettop(L) == 0); /* only the function should be on the stack */ + force_assert(lua_gettop(L) == 0); /* only the function should be on the stack */ con->http_status = 500; con->mode = DIRECT; @@ -992,7 +1002,7 @@ static handler_t magnet_attract(server *srv, connectio lua_tostring(L, -1)); lua_pop(L, 1); /* remove the error-msg and the function copy from the stack */ - assert(lua_gettop(L) == 1); /* only the function should be on the stack */ + force_assert(lua_gettop(L) == 1); /* only the function should be on the stack */ con->http_status = 500; con->mode = DIRECT; @@ -1002,7 +1012,7 @@ static handler_t magnet_attract(server *srv, connectio lua_remove(L, errfunc); /* we should have the function-copy and the return value on the stack */ - assert(lua_gettop(L) == 2); + force_assert(lua_gettop(L) == 2); if (lua_isnumber(L, -1)) { /* if the ret-value is a number, take it */ @@ -1028,16 +1038,16 @@ static handler_t magnet_attract(server *srv, connectio con->mode = DIRECT; } - assert(lua_gettop(L) == 1); /* only the function should be on the stack */ + force_assert(lua_gettop(L) == 1); /* only the function should be on the stack */ /* we are finished */ return HANDLER_FINISHED; } else if (MAGNET_RESTART_REQUEST == lua_return_value) { - assert(lua_gettop(L) == 1); /* only the function should be on the stack */ + force_assert(lua_gettop(L) == 1); /* only the function should be on the stack */ return HANDLER_COMEBACK; } else { - assert(lua_gettop(L) == 1); /* only the function should be on the stack */ + force_assert(lua_gettop(L) == 1); /* only the function should be on the stack */ return HANDLER_GO_ON; }