telize

High performance JSON IP and GeoIP REST API (IP Geolocation)
Log | Files | Refs | README | LICENSE

commit c0b8d26ae6c51a2e39b642c18018a34849f26bab
parent 633b526393a6abac743fb810bf19d8ce45efe7a0
Author: Frederic Cambus <fred@statdns.com>
Date:   Tue,  9 Oct 2018 16:52:12 +0200

Add a dynamic ^/location/[a-f0-9\:.]*$ route to allow specifying custom IP addresses

Diffstat:
Mconf/telize.conf | 4++++
Msrc/location.c | 10+++++++++-
2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/conf/telize.conf b/conf/telize.conf @@ -24,4 +24,8 @@ domain * { params qs:get /location { validate callback v_callback } + dynamic ^/location/[a-f0-9\:.]*$ location + params qs:get ^/location/[a-f0-9\:.]*$ { + validate callback v_callback + } } diff --git a/src/location.c b/src/location.c @@ -51,7 +51,7 @@ init(int state) int location(struct http_request *req) { - const char *visitor_ip, *ip; + const char *custom_ip, *visitor_ip, *ip; char *answer, *callback, *addr; bool is_callback = false; @@ -82,6 +82,14 @@ location(struct http_request *req) ip = addr; } + if (req->hdlr->type == HANDLER_TYPE_DYNAMIC) { + if ((custom_ip = strrchr(req->path, '/')) != NULL) + custom_ip++; + + if (strlen(custom_ip)) + ip = custom_ip; + } + if (http_argument_get_string(req, "callback", &callback)) { kore_buf_appendf(&json, "%s(", callback); is_callback = true;