|
|
| version 1.1.1.1, 2013/10/14 10:32:48 | version 1.1.1.2, 2014/06/15 20:20:06 |
|---|---|
| Line 103 SETDEFAULTS_FUNC(mod_magnet_set_defaults) { | Line 103 SETDEFAULTS_FUNC(mod_magnet_set_defaults) { |
| if (!p) return HANDLER_ERROR; | 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++) { | for (i = 0; i < srv->config_context->used; i++) { |
| plugin_config *s; | plugin_config *s; |
| Line 446 typedef struct { | Line 446 typedef struct { |
| MAGNET_ENV_PHYICAL_PATH, | MAGNET_ENV_PHYICAL_PATH, |
| MAGNET_ENV_PHYICAL_REL_PATH, | MAGNET_ENV_PHYICAL_REL_PATH, |
| MAGNET_ENV_PHYICAL_DOC_ROOT, | MAGNET_ENV_PHYICAL_DOC_ROOT, |
| MAGNET_ENV_PHYICAL_BASEDIR, | |
| MAGNET_ENV_URI_PATH, | MAGNET_ENV_URI_PATH, |
| MAGNET_ENV_URI_PATH_RAW, | MAGNET_ENV_URI_PATH_RAW, |
| Line 466 static const magnet_env_t magnet_env[] = { | Line 467 static const magnet_env_t magnet_env[] = { |
| { "physical.path", MAGNET_ENV_PHYICAL_PATH }, | { "physical.path", MAGNET_ENV_PHYICAL_PATH }, |
| { "physical.rel-path", MAGNET_ENV_PHYICAL_REL_PATH }, | { "physical.rel-path", MAGNET_ENV_PHYICAL_REL_PATH }, |
| { "physical.doc-root", MAGNET_ENV_PHYICAL_DOC_ROOT }, | { "physical.doc-root", MAGNET_ENV_PHYICAL_DOC_ROOT }, |
| { "physical.basedir", MAGNET_ENV_PHYICAL_BASEDIR }, | |
| { "uri.path", MAGNET_ENV_URI_PATH }, | { "uri.path", MAGNET_ENV_URI_PATH }, |
| { "uri.path-raw", MAGNET_ENV_URI_PATH_RAW }, | { "uri.path-raw", MAGNET_ENV_URI_PATH_RAW }, |
| Line 497 static buffer *magnet_env_get_buffer_by_id(server *srv | Line 499 static buffer *magnet_env_get_buffer_by_id(server *srv |
| case MAGNET_ENV_PHYICAL_PATH: dest = con->physical.path; break; | 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_REL_PATH: dest = con->physical.rel_path; break; |
| case MAGNET_ENV_PHYICAL_DOC_ROOT: dest = con->physical.doc_root; 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: dest = con->uri.path; break; |
| case MAGNET_ENV_URI_PATH_RAW: dest = con->uri.path_raw; break; | case MAGNET_ENV_URI_PATH_RAW: dest = con->uri.path_raw; break; |
| Line 693 static int magnet_copy_response_header(server *srv, co | Line 696 static int magnet_copy_response_header(server *srv, co |
| /* lighty.header */ | /* lighty.header */ |
| lua_getfield(L, -1, "lighty"); /* lighty.* from the env */ | 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 */ | lua_getfield(L, -1, "header"); /* lighty.header */ |
| if (lua_istable(L, -1)) { | if (lua_istable(L, -1)) { |
| Line 737 static int magnet_attach_content(server *srv, connecti | Line 740 static int magnet_attach_content(server *srv, connecti |
| * get the environment of the function | * 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_getfenv(L, -1); /* -1 is the function */ |
| lua_getfield(L, -1, "lighty"); /* lighty.* from the env */ | 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 */ | lua_getfield(L, -1, "content"); /* lighty.content */ |
| if (lua_istable(L, -1)) { | if (lua_istable(L, -1)) { |
| Line 763 static int magnet_attach_content(server *srv, connecti | Line 766 static int magnet_attach_content(server *srv, connecti |
| lua_getfield(L, -3, "offset"); | lua_getfield(L, -3, "offset"); |
| if (lua_isstring(L, -3)) { /* filename has to be a string */ | if (lua_isstring(L, -3)) { /* filename has to be a string */ |
| buffer *fn = buffer_init(); | buffer *fn; |
| stat_cache_entry *sce; | 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 off = 0; |
| off_t len = 0; | off_t len = 0; |
| Line 783 static int magnet_attach_content(server *srv, connecti | Line 791 static int magnet_attach_content(server *srv, connecti |
| } | } |
| if (off < 0) { | 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) { | 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); | chunkqueue_append_file(con->write_queue, fn, off, len - off); |
| Line 870 static handler_t magnet_attract(server *srv, connectio | Line 880 static handler_t magnet_attract(server *srv, connectio |
| lua_pop(L, 1); | 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->http_status = 500; |
| con->mode = DIRECT; | con->mode = DIRECT; |
| Line 992 static handler_t magnet_attract(server *srv, connectio | Line 1002 static handler_t magnet_attract(server *srv, connectio |
| lua_tostring(L, -1)); | lua_tostring(L, -1)); |
| lua_pop(L, 1); /* remove the error-msg and the function copy from the stack */ | 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->http_status = 500; |
| con->mode = DIRECT; | con->mode = DIRECT; |
| Line 1002 static handler_t magnet_attract(server *srv, connectio | Line 1012 static handler_t magnet_attract(server *srv, connectio |
| lua_remove(L, errfunc); | lua_remove(L, errfunc); |
| /* we should have the function-copy and the return value on the stack */ | /* 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 (lua_isnumber(L, -1)) { |
| /* if the ret-value is a number, take it */ | /* if the ret-value is a number, take it */ |
| Line 1028 static handler_t magnet_attract(server *srv, connectio | Line 1038 static handler_t magnet_attract(server *srv, connectio |
| con->mode = DIRECT; | 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 */ | /* we are finished */ |
| return HANDLER_FINISHED; | return HANDLER_FINISHED; |
| } else if (MAGNET_RESTART_REQUEST == lua_return_value) { | } 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; | return HANDLER_COMEBACK; |
| } else { | } 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; | return HANDLER_GO_ON; |
| } | } |