diff --git a/core/config.c b/core/config.c index 5d863201..d75b4279 100644 --- a/core/config.c +++ b/core/config.c @@ -816,3 +816,19 @@ char *uwsgi_manage_placeholder(char *key) { return current_value; } + +void uwsgi_opt_resolve(char *opt, char *value, void *foo) { + char *equal = strchr(value, '='); + if (!equal) { + uwsgi_log("invalid resolve syntax, must be placeholder=domain\n"); + exit(1); + } + char *ip = uwsgi_resolve_ip(equal+1); + if (!ip) { + uwsgi_log("unable to resolve name %s\n", equal+1); + uwsgi_error("uwsgi_resolve_ip()"); + exit(1); + } + char *new_opt = uwsgi_concat2n(value, (equal-value)+1, ip, strlen(ip)); + uwsgi_opt_set_placeholder(opt, new_opt, (void *) 1); +} diff --git a/core/uwsgi.c b/core/uwsgi.c index 30c6561a..efcfe28f 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -101,6 +101,8 @@ static struct uwsgi_option uwsgi_base_options[] = { {"declare-option", required_argument, 0, "declare a new uWSGI custom option", uwsgi_opt_add_custom_option, NULL, UWSGI_OPT_IMMEDIATE}, {"declare-option2", required_argument, 0, "declare a new uWSGI custom option (non-immediate)", uwsgi_opt_add_custom_option, NULL, 0}, + {"resolve", required_argument, 0, "place the result of a dns query in the specified placeholder, sytax: placeholder=name (immediate option)", uwsgi_opt_resolve, NULL, UWSGI_OPT_IMMEDIATE}, + {"for", required_argument, 0, "(opt logic) for cycle", uwsgi_opt_logic, (void *) uwsgi_logic_opt_for, UWSGI_OPT_IMMEDIATE}, {"for-glob", required_argument, 0, "(opt logic) for cycle (expand glob)", uwsgi_opt_logic, (void *) uwsgi_logic_opt_for_glob, UWSGI_OPT_IMMEDIATE}, {"for-times", required_argument, 0, "(opt logic) for cycle (expand the specified num to a list starting from 1)", uwsgi_opt_logic, (void *) uwsgi_logic_opt_for_times, UWSGI_OPT_IMMEDIATE}, diff --git a/uwsgi.h b/uwsgi.h index 3f00e2ed..1c763830 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -3792,6 +3792,8 @@ int uwsgi_logic_opt_if_plugin(char *, char *); int uwsgi_logic_opt_if_not_plugin(char *, char *); +void uwsgi_opt_resolve(char *, char *, void *); + #ifdef UWSGI_CAP void uwsgi_opt_set_cap(char *, char *, void *); void uwsgi_opt_set_emperor_cap(char *, char *, void *);