diff --git a/plugins/python/python_plugin.c b/plugins/python/python_plugin.c index c9fc6fae..f02d3b1a 100644 --- a/plugins/python/python_plugin.c +++ b/plugins/python/python_plugin.c @@ -549,6 +549,34 @@ void uwsgi_uwsgi_config(char *module) { +int uwsgi_python_magic(char *mountpoint, char *lazy) { + + char *qc = strchr(lazy, ':'); + if (qc) { + qc[0] = 0; + up.callable = qc + 1; + } + + if (!strcmp(lazy+strlen(lazy)-3, ".py")) { + up.file_config = lazy; + return 1; + } + else if (!strcmp(lazy+strlen(lazy)-5, ".wsgi")) { + up.file_config = lazy; + return 1; + } + else if (qc && strchr(lazy,'.')) { + up.wsgi_config = lazy; + return 1; + } + + // reset lazy + if (qc) { + qc[0] = ':'; + } + return 0; + +} int uwsgi_python_manage_options(int i, char *optarg) { @@ -680,9 +708,10 @@ void uwsgi_uwsgi_config(char *module) { .enable_threads = uwsgi_python_enable_threads, .init_thread = uwsgi_python_init_thread, .manage_xml = uwsgi_python_xml, + + .magic = uwsgi_python_magic, //.spooler = uwsgi_python_spooler, /* - .magic = uwsgi_python_magic, .help = uwsgi_python_help, */ diff --git a/uwsgi.c b/uwsgi.c index 8149b409..a8dfc458 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -494,47 +494,42 @@ int main(int argc, char *argv[], char *envp[]) } - /* if (optind < argc) { - char *lazy = argv[optind]; - char *qc = strchr(lazy, ':'); -// ignore last arg if it starts with [ -if (lazy[0] != '[') { -if (qc) { -qc[0] = 0; -uwsgi.callable = qc + 1; -} -if (!strcmp(lazy+strlen(lazy)-3, ".py")) { -uwsgi.file_config = lazy; -} -else if (!strcmp(lazy+strlen(lazy)-4, ".xml")) { -if (qc) { uwsgi.callable = NULL; qc[0] = ':';} -uwsgi.xml_config = lazy; -} -else if (!strcmp(lazy+strlen(lazy)-4, ".ini")) { -if (qc) { uwsgi.callable = NULL; qc[0] = ':';} -uwsgi.ini = lazy; -} -else if (!strcmp(lazy+strlen(lazy)-5, ".wsgi")) { -uwsgi.file_config = lazy; -} -else if (lazy[0] == '/' && strchr(lazy,'=')) { -if (uwsgi.mounts_cnt < MAX_APPS) { -uwsgi.mounts[uwsgi.mounts_cnt] = lazy; -uwsgi.mounts_cnt++; -} -else { -uwsgi_log("unable to add more that %d mountpoints\n", MAX_APPS); -} -} -else { -uwsgi.wsgi_config = lazy; -} -} -} - -*/ + char *lazy = argv[optind]; + if (lazy[0] != '[') { + if (!strcmp(lazy+strlen(lazy)-4, ".xml")) { + uwsgi.xml_config = lazy; + } + else if (!strcmp(lazy+strlen(lazy)-4, ".ini")) { + uwsgi.ini = lazy; + } + // manage magic mountpoint + else if (lazy[0] == '/' && strchr(lazy,'=')) { + } + else { + int magic = 0; + for(i =0; i < uwsgi.gp_cnt; i++) { + if (uwsgi.gp[i]->magic) { + if (uwsgi.gp[i]->magic(NULL, lazy)) { + magic = 1; + break; + } + } + } + if (!magic) { + for (i = 0; i < 0xFF; i++) { + if (uwsgi.p[i]->magic) { + if (uwsgi.p[i]->magic(NULL, lazy)) { + magic = 1; + break; + } + } + } + } + } + } + } #ifdef UWSGI_XML if (uwsgi.xml_config != NULL) { diff --git a/uwsgi.h b/uwsgi.h index bbe3a042..43eb6190 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -351,7 +351,6 @@ struct uwsgi_plugin { struct option *options; const char *short_options; int (*manage_opt) (int, char *); - void (*magic) (char *); void (*enable_threads) (void); void (*init_thread) (int); int (*request) (struct wsgi_request *); @@ -362,6 +361,8 @@ struct uwsgi_plugin { void (*suspend) (struct wsgi_request *); void (*resume) (struct wsgi_request *); + int (*magic) (char *, char *); + void* (*encode_string)(char *); char* (*decode_string)(void *);