From f5356302a7eda8040bde81e9e08c346074e138ed Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Wed, 21 Dec 2016 22:05:47 -0500 Subject: [PATCH] [mod_geoip] call from handle_request_env hook (instead of handle_subrequest_start hook) The handle_request_env hook is called on demand by dynamic handlers and this change makes mod_geoip available for mod_magnet lua code. --- src/mod_geoip.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/mod_geoip.c b/src/mod_geoip.c index 64c98370..694f2de2 100644 --- a/src/mod_geoip.c +++ b/src/mod_geoip.c @@ -211,12 +211,7 @@ static int mod_geoip_patch_connection(server *srv, connection *con, plugin_data } #undef PATCH -URIHANDLER_FUNC(mod_geoip_subrequest) { - plugin_data *p = p_d; - - mod_geoip_patch_connection(srv, con, p); - - if (!buffer_is_empty(p->conf.db_name)) { +static handler_t mod_geoip_query (connection *con, plugin_data *p) { const char *remote_ip; data_string *ds; GeoIPRecord *gir; @@ -391,12 +386,18 @@ URIHANDLER_FUNC(mod_geoip_subrequest) { GeoIPRecord_delete(gir); } - } - /* keep walking... (johnnie walker style ;) */ return HANDLER_GO_ON; } +CONNECTION_FUNC(mod_geoip_handle_request_env) { + plugin_data *p = p_d; + mod_geoip_patch_connection(srv, con, p); + if (buffer_is_empty(p->conf.db_name)) return HANDLER_GO_ON; + + return mod_geoip_query(con, p); +} + /* this function is called at dlopen() time and inits the callbacks */ int mod_geoip_plugin_init(plugin *p); @@ -405,7 +406,7 @@ int mod_geoip_plugin_init(plugin *p) { p->name = buffer_init_string("geoip"); p->init = mod_geoip_init; - p->handle_subrequest_start = mod_geoip_subrequest; + p->handle_request_env = mod_geoip_handle_request_env; p->set_defaults = mod_geoip_set_defaults; p->cleanup = mod_geoip_free;