diff --git a/lua_module_v0_9_20.patch b/lua_module_v0_9_20.patch new file mode 100644 index 0000000..94abc73 --- /dev/null +++ b/lua_module_v0_9_20.patch @@ -0,0 +1,141 @@ +diff --git a/config b/config +index 4b770d7..22a9827 100644 +--- a/config ++++ b/config +@@ -352,6 +352,7 @@ NGX_ADDON_SRCS="$NGX_ADDON_SRCS \ + $ngx_addon_dir/src/ngx_http_lua_worker.c \ + $ngx_addon_dir/src/ngx_http_lua_lex.c \ + " ++NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/src/ngx_http_lua_graphite.c" + + NGX_ADDON_DEPS="$NGX_ADDON_DEPS \ + $ngx_addon_dir/src/ddebug.h \ +@@ -406,6 +407,7 @@ NGX_ADDON_DEPS="$NGX_ADDON_DEPS \ + $ngx_addon_dir/src/ngx_http_lua_worker.h \ + $ngx_addon_dir/src/ngx_http_lua_lex.h \ + " ++NGX_ADDON_DEPS="$NGX_ADDON_DEPS $ngx_addon_dir/src/ngx_http_lua_graphite.h" + + CFLAGS="$CFLAGS -DNDK_SET_VAR" + +diff --git a/src/ngx_http_lua_graphite.c b/src/ngx_http_lua_graphite.c +new file mode 100644 +index 0000000..e959199 +--- /dev/null ++++ b/src/ngx_http_lua_graphite.c +@@ -0,0 +1,69 @@ ++#ifndef DDEBUG ++#define DDEBUG 0 ++#endif ++#include "ddebug.h" ++ ++ ++#include "ngx_http_lua_graphite.h" ++#include "ngx_http_lua_util.h" ++ ++ ++typedef ngx_int_t (*ngx_http_graphite_custom_pt)(ngx_http_request_t*, ngx_str_t*, double); ++ ++ ++static ngx_http_graphite_custom_pt custom_pt = NULL; ++static int ngx_http_lua_graphite_custom(lua_State *L); ++ ++ ++void ++ngx_http_lua_inject_graphite_api(lua_State *L) ++{ ++ ngx_str_t name = ngx_string("graphite_custom"); ++ ++ int i; ++ for (i = 0; ngx_modules[i]; i++) { ++ ++ ngx_module_t *module = ngx_modules[i]; ++ if (module->type != NGX_HTTP_MODULE) ++ continue; ++ ++ ngx_command_t *cmd = module->commands; ++ if (cmd == NULL) ++ continue; ++ ++ for (; cmd->name.len; cmd++) { ++ if ((cmd->name.len == name.len) && (ngx_strncmp(cmd->name.data, name.data, name.len) == 0)) { ++ custom_pt = cmd->post; ++ } ++ } ++ } ++ ++ lua_pushcfunction(L, ngx_http_lua_graphite_custom); ++ lua_setfield(L, -2, "graphite"); ++} ++ ++ ++static int ++ngx_http_lua_graphite_custom(lua_State *L) { ++ ++ ngx_http_request_t *r; ++ r = ngx_http_lua_get_req(L); ++ ++ if (r == NULL) { ++ return luaL_error(L, "no request object found"); ++ } ++ ++ double value = lua_tonumber(L, -1); ++ lua_pop(L, 1); ++ ++ ngx_str_t name; ++ name.data = (u_char*)lua_tolstring(L, -1, &name.len); ++ if (name.data == NULL) ++ return 0; ++ lua_pop(L, 1); ++ ++ if (custom_pt) ++ custom_pt(r, &name, value); ++ ++ return 0; ++} +diff --git a/src/ngx_http_lua_graphite.h b/src/ngx_http_lua_graphite.h +new file mode 100644 +index 0000000..cf76efa +--- /dev/null ++++ b/src/ngx_http_lua_graphite.h +@@ -0,0 +1,11 @@ ++#ifndef NGX_HTTP_LUA_GRAPHITE_H ++#define NGX_HTTP_LUA_GRAPHITE_H ++ ++#include "ngx_http_lua_common.h" ++ ++ ++void ngx_http_lua_inject_graphite_api(lua_State *L); ++ ++ ++#endif /* NGX_HTTP_LUA_GRAPHITE_H */ ++ +diff --git a/src/ngx_http_lua_util.c b/src/ngx_http_lua_util.c +index e9d40fc..a0aff09 100644 +--- a/src/ngx_http_lua_util.c ++++ b/src/ngx_http_lua_util.c +@@ -50,6 +50,7 @@ + #include "ngx_http_lua_worker.h" + #include "ngx_http_lua_socket_tcp.h" + ++#include "ngx_http_lua_graphite.h" + + #if 1 + #undef ngx_http_lua_probe_info +@@ -719,7 +720,7 @@ static void + ngx_http_lua_inject_ngx_api(lua_State *L, ngx_http_lua_main_conf_t *lmcf, + ngx_log_t *log) + { +- lua_createtable(L, 0 /* narr */, 116 /* nrec */); /* ngx.* */ ++ lua_createtable(L, 0 /* narr */, 117 /* nrec */); /* ngx.* */ + + lua_pushcfunction(L, ngx_http_lua_get_raw_phase_context); + lua_setfield(L, -2, "_phase_ctx"); +@@ -753,6 +754,7 @@ ngx_http_lua_inject_ngx_api(lua_State *L, ngx_http_lua_main_conf_t *lmcf, + ngx_http_lua_inject_timer_api(L); + ngx_http_lua_inject_config_api(L); + ngx_http_lua_inject_worker_api(L); ++ ngx_http_lua_inject_graphite_api(L); + + ngx_http_lua_inject_misc_api(L); +