From eada0c09e0f09ba01caeb1fb02ebe496202aaed4 Mon Sep 17 00:00:00 2001 From: "roberto@debian32" Date: Fri, 30 Sep 2011 10:21:26 +0200 Subject: [PATCH] refactored placeholder management --- utils.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ uwsgi.c | 56 ++++++----------------------------------------------- uwsgi.h | 2 ++ welcome.ini | 10 ++++++---- 4 files changed, 70 insertions(+), 54 deletions(-) diff --git a/utils.c b/utils.c index 5442f141..27607e3f 100644 --- a/utils.c +++ b/utils.c @@ -3087,5 +3087,61 @@ void uwsgi_build_cap(char *what) { } free(caps); +} + +void uwsgi_apply_config_pass(char symbol, char*(*hook)(char *) ) { + + int i, j; + + for (i = 0; i < uwsgi.exported_opts_cnt; i++) { + int has_symbol = 0; + char *magic_key = NULL; + char *magic_val = NULL; + if (uwsgi.exported_opts[i]->value && !uwsgi.exported_opts[i]->configured) { + for (j = 0; j < (int) strlen(uwsgi.exported_opts[i]->value); j++) { + if (uwsgi.exported_opts[i]->value[j] == symbol) { + has_symbol = 1; + } + else if (uwsgi.exported_opts[i]->value[j] == '(' && has_symbol == 1) { + has_symbol = 2; + magic_key = uwsgi.exported_opts[i]->value + j + 1; + } + else if (has_symbol > 1) { + if (uwsgi.exported_opts[i]->value[j] == ')') { + if (has_symbol <= 2) { + magic_key = NULL; + has_symbol = 0; + continue; + } +#ifdef UWSGI_DEBUG + uwsgi_log("need to interpret the %.*s tag\n", has_symbol - 2, magic_key); +#endif + char *tmp_magic_key = uwsgi_concat2n(magic_key, has_symbol - 2, "", 0); + magic_val = hook(tmp_magic_key); + free(tmp_magic_key); + if (!magic_val) { + magic_key = NULL; + has_symbol = 0; + continue; + } + uwsgi.exported_opts[i]->value = uwsgi_concat4n(uwsgi.exported_opts[i]->value, (magic_key - 2) - uwsgi.exported_opts[i]->value, magic_val, strlen(magic_val), magic_key + (has_symbol - 1), strlen(magic_key + (has_symbol - 1)), "", 0); +#ifdef UWSGI_DEBUG + uwsgi_log("computed new value = %s\n", uwsgi.exported_opts[i]->value); +#endif + magic_key = NULL; + has_symbol = 0; + j = 0; + } + else { + has_symbol++; + } + } + else { + has_symbol = 0; + } + } + } + } + } #endif diff --git a/uwsgi.c b/uwsgi.c index c4488eb4..78d0942a 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -828,7 +828,7 @@ int uwsgi_init(int argc, char *argv[], char *envp[]) { int main(int argc, char *argv[], char *envp[]) { #endif - int i, j; + int i; int rlen; FILE *pidfile; @@ -1212,55 +1212,11 @@ int main(int argc, char *argv[], char *envp[]) { } // second pass - for (i = 0; i < uwsgi.exported_opts_cnt; i++) { - int has_percent = 0; - char *magic_key = NULL; - char *magic_val = NULL; - if (uwsgi.exported_opts[i]->value && !uwsgi.exported_opts[i]->configured) { - for (j = 0; j < (int) strlen(uwsgi.exported_opts[i]->value); j++) { - if (uwsgi.exported_opts[i]->value[j] == '%') { - has_percent = 1; - } - else if (uwsgi.exported_opts[i]->value[j] == '(' && has_percent == 1) { - has_percent = 2; - magic_key = uwsgi.exported_opts[i]->value + j + 1; - } - else if (has_percent > 1) { - if (uwsgi.exported_opts[i]->value[j] == ')') { - if (has_percent <= 2) { - magic_key = NULL; - has_percent = 0; - continue; - } -#ifdef UWSGI_DEBUG - uwsgi_log("need to interpret the %.*s tag\n", has_percent - 2, magic_key); -#endif - char *tmp_magic_key = uwsgi_concat2n(magic_key, has_percent - 2, "", 0); - magic_val = uwsgi_get_exported_opt(tmp_magic_key); - free(tmp_magic_key); - if (!magic_val) { - magic_key = NULL; - has_percent = 0; - continue; - } - uwsgi.exported_opts[i]->value = uwsgi_concat4n(uwsgi.exported_opts[i]->value, (magic_key - 2) - uwsgi.exported_opts[i]->value, magic_val, strlen(magic_val), magic_key + (has_percent - 1), strlen(magic_key + (has_percent - 1)), "", 0); -#ifdef UWSGI_DEBUG - uwsgi_log("computed new value = %s\n", uwsgi.exported_opts[i]->value); -#endif - magic_key = NULL; - has_percent = 0; - j = 0; - } - else { - has_percent++; - } - } - else { - has_percent = 0; - } - } - } - } + uwsgi_apply_config_pass('%', uwsgi_get_exported_opt); + + // third pass: ENVs + uwsgi_apply_config_pass('$', (char *(*)(char *))getenv); + // ok, the options dictionary is available, lets manage it diff --git a/uwsgi.h b/uwsgi.h index c8742b33..98f1b8dd 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -2233,6 +2233,8 @@ struct uwsgi_dyn_dict *uwsgi_dyn_dict_new(struct uwsgi_dyn_dict **, char *, int, void uwsgi_send_stats(int); +void uwsgi_apply_config_pass(char symbol, char*(*)(char *) ); + #ifdef UWSGI_CAP void uwsgi_build_cap(char *); #endif diff --git a/welcome.ini b/welcome.ini index 7379a79e..d2cd1cca 100644 --- a/welcome.ini +++ b/welcome.ini @@ -1,9 +1,11 @@ [uwsgi] -socket = :3031 +socket = :$(PORT) socket = /tmp/uwsgi_welcome.socket vacuum = true -module = welcome -master = true -processes = 4 +appname = welcome +module = %(appname) +numproc = 4 +master = %(vacuum) +processes = %(numproc) mount = /werkzeug=tests/werkzeug.py manage-script-name = true