mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-06 13:41:28 +00:00
added support for logic in config directives with a first 'for' implementation
This commit is contained in:
@@ -1747,8 +1747,65 @@ struct uwsgi_option *uwsgi_opt_get(char *name) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *uwsgi_substitue(char *src, char *what, char *with) {
|
||||
|
||||
size_t len = strlen(src)+1;
|
||||
size_t wlen = strlen(with)+1;
|
||||
char *dst = uwsgi_calloc(len);
|
||||
char *ptr = src;
|
||||
|
||||
char *p = strstr(ptr, what);
|
||||
while(p) {
|
||||
strncat(dst, ptr, (p-ptr));
|
||||
ptr = p + (wlen-2);
|
||||
len += wlen;
|
||||
dst = realloc(dst, len);
|
||||
strcat(dst, with);
|
||||
p = strstr(ptr, what);
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
int uwsgi_logic_opt_for(char *key, char *value) {
|
||||
|
||||
char *p = strtok(uwsgi.logic_opt_data, " ");
|
||||
while(p) {
|
||||
uwsgi.logic_opt_running = 1;
|
||||
add_exported_option(key, uwsgi_substitue(value, "%(_)", p), 0);
|
||||
uwsgi.logic_opt_running = 0;
|
||||
p = strtok(NULL, " ");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void add_exported_option(char *key, char *value, int configured) {
|
||||
|
||||
if (uwsgi.logic_opt_running) goto add;
|
||||
|
||||
if (!strcmp(key, "end") || !strcmp(key, "endfor") || !strcmp(key, "endif")) {
|
||||
if (uwsgi.logic_opt_data) {
|
||||
free(uwsgi.logic_opt_data);
|
||||
}
|
||||
uwsgi.logic_opt = NULL;
|
||||
uwsgi.logic_opt_arg = NULL;
|
||||
uwsgi.logic_opt_cycles = 0;
|
||||
uwsgi.logic_opt_data = NULL;
|
||||
}
|
||||
|
||||
if (uwsgi.logic_opt) {
|
||||
if (uwsgi.logic_opt_data) {
|
||||
free(uwsgi.logic_opt_data);
|
||||
}
|
||||
uwsgi.logic_opt_data = uwsgi_str(uwsgi.logic_opt_arg);
|
||||
uwsgi.logic_opt_cycles++;
|
||||
uwsgi.logic_opt(key, value);
|
||||
return;
|
||||
}
|
||||
|
||||
add:
|
||||
|
||||
if (!uwsgi.exported_opts) {
|
||||
uwsgi.exported_opts = uwsgi_malloc(sizeof(struct uwsgi_opt *));
|
||||
}
|
||||
|
||||
@@ -57,6 +57,10 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
{"xml", required_argument, 'x', "load config from xml file", uwsgi_opt_load_xml, NULL, UWSGI_OPT_IMMEDIATE},
|
||||
#endif
|
||||
{"set", required_argument, 'S', "set a custom placeholder", uwsgi_opt_set_placeholder, NULL, UWSGI_OPT_IMMEDIATE},
|
||||
|
||||
{"for", required_argument, 0, "(opt logic) for cycle", uwsgi_opt_logic, (void *) uwsgi_logic_opt_for, UWSGI_OPT_IMMEDIATE},
|
||||
{"endfor", optional_argument, 0, "(opt logic) end for cycle", uwsgi_opt_noop, NULL, UWSGI_OPT_IMMEDIATE},
|
||||
|
||||
{"inherit", required_argument, 0, "use the specified file as config template", uwsgi_opt_load, NULL,0},
|
||||
{"daemonize", required_argument, 'd', "daemonize uWSGI", uwsgi_opt_set_str, &uwsgi.daemonize, 0},
|
||||
{"stop", required_argument, 0, "stop an instance", uwsgi_opt_pidfile_signal, (void *) SIGINT, UWSGI_OPT_IMMEDIATE},
|
||||
@@ -3544,6 +3548,20 @@ void uwsgi_opt_load(char *opt, char *filename, void *none) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void uwsgi_opt_logic(char *opt, char *arg, void *func) {
|
||||
uwsgi.logic_opt = (int (*)(char *, char *)) func;
|
||||
uwsgi.logic_opt_cycles = 0;
|
||||
if (arg) {
|
||||
uwsgi.logic_opt_arg = uwsgi_str(arg);
|
||||
}
|
||||
else {
|
||||
uwsgi.logic_opt_arg = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void uwsgi_opt_noop(char *opt, char *foo, void *bar) {
|
||||
}
|
||||
|
||||
#ifdef UWSGI_INI
|
||||
void uwsgi_opt_load_ini(char *opt, char *filename, void *none) {
|
||||
config_magic_table_fill(filename, uwsgi.magic_table);
|
||||
|
||||
@@ -1043,6 +1043,11 @@ struct uwsgi_server {
|
||||
// store options
|
||||
int dirty_config;
|
||||
int option_index;
|
||||
int (*logic_opt)(char *, char *);
|
||||
char *logic_opt_arg;
|
||||
char *logic_opt_data;
|
||||
int logic_opt_running;
|
||||
int logic_opt_cycles;
|
||||
struct uwsgi_option *options;
|
||||
struct option *long_options;
|
||||
char *short_options;
|
||||
@@ -2556,6 +2561,12 @@ void uwsgi_opt_chmod_socket(char *, char *, void *);
|
||||
void uwsgi_opt_max_vars(char *, char *, void *);
|
||||
void uwsgi_opt_deprecated(char *, char *, void *);
|
||||
|
||||
void uwsgi_opt_noop(char *, char *, void *);
|
||||
|
||||
void uwsgi_opt_logic(char *, char *, void *);
|
||||
int uwsgi_logic_opt_for(char *, char *);
|
||||
|
||||
|
||||
#ifdef UWSGI_CAP
|
||||
void uwsgi_opt_set_cap(char *, char *, void *);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user