mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-11-20 18:37:05 +00:00
uWSGI is now language agnostic, all can be pluginized, python included
This commit is contained in:
@@ -436,7 +436,7 @@ struct wsgi_request * async_loop() {
|
||||
uwsgi.async_running = 0 ;
|
||||
// st global wsgi_req for python functions
|
||||
uwsgi.wsgi_req = wsgi_req ;
|
||||
wsgi_req->async_status = (*uwsgi.shared->hooks[wsgi_req->uh.modifier1]) (wsgi_req);
|
||||
wsgi_req->async_status = (*uwsgi.shared->hook_request[wsgi_req->uh.modifier1]) (wsgi_req);
|
||||
|
||||
if (wsgi_req->async_status < UWSGI_AGAIN) {
|
||||
return wsgi_req;
|
||||
|
||||
@@ -164,7 +164,7 @@ void uwsgi_ini_config(char *file, struct option *long_options) {
|
||||
*aopt->flag = aopt->val;
|
||||
}
|
||||
else {
|
||||
manage_opt(aopt->val, val);
|
||||
manage_opt(aopt->val, val);
|
||||
}
|
||||
}
|
||||
lopt++;
|
||||
|
||||
@@ -40,6 +40,8 @@ void log_request(struct wsgi_request *wsgi_req) {
|
||||
|
||||
struct uwsgi_app *wi;
|
||||
|
||||
uwsgi_log("LOGGING...\n");
|
||||
|
||||
if (wsgi_req->app_id >= 0) {
|
||||
wi = &uwsgi.apps[wsgi_req->app_id];
|
||||
if (wi->requests > 0) {
|
||||
|
||||
@@ -2,26 +2,37 @@
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
struct wsgi_request* threaded_current_wsgi_req() { return pthread_getspecific(uwsgi.tur_key); }
|
||||
struct wsgi_request* simple_current_wsgi_req() { return uwsgi.wsgi_req ; }
|
||||
|
||||
void *simple_loop(void *arg1) {
|
||||
|
||||
long core_id = (long) arg1;
|
||||
|
||||
struct wsgi_request *wsgi_req = uwsgi.wsgi_requests[core_id];
|
||||
int i;
|
||||
|
||||
#ifdef UWSGI_THREADING
|
||||
PyThreadState *pts;
|
||||
//PyThreadState *pts;
|
||||
sigset_t smask;
|
||||
|
||||
if (uwsgi.threads > 1) {
|
||||
|
||||
pthread_setspecific(uwsgi.ut_key, (void *) wsgi_req);
|
||||
pthread_setspecific(uwsgi.tur_key, (void *) wsgi_req);
|
||||
|
||||
if (core_id > 0) {
|
||||
// block all signals on new threads
|
||||
sigfillset(&smask);
|
||||
pthread_sigmask(SIG_BLOCK, &smask, NULL);
|
||||
for(i=0;i<0xFF;i++) {
|
||||
if (uwsgi.shared->hook_init_thread[i]) {
|
||||
uwsgi.shared->hook_init_thread[i]();
|
||||
}
|
||||
}
|
||||
/*
|
||||
pts = PyThreadState_New(uwsgi.main_thread->interp);
|
||||
pthread_setspecific(uwsgi.ut_save_key, (void *) pts);
|
||||
*/
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -45,20 +45,16 @@ void master_loop(char **argv, char **environ) {
|
||||
struct sockaddr_in udp_client;
|
||||
socklen_t udp_len;
|
||||
char udp_client_addr[16];
|
||||
PyObject *udp_callable;
|
||||
PyObject *udp_callable_args = NULL;
|
||||
PyObject *udp_response;
|
||||
int udp_managed = 0 ;
|
||||
int rlen;
|
||||
#endif
|
||||
|
||||
int i,j;
|
||||
#ifdef UWSGI_UDP
|
||||
int rlen;
|
||||
#endif
|
||||
|
||||
struct timeval check_interval = {.tv_sec = 1,.tv_usec = 0 };
|
||||
|
||||
// release the GIL
|
||||
UWSGI_RELEASE_GIL
|
||||
//UWSGI_RELEASE_GIL
|
||||
|
||||
/* route signals to workers... */
|
||||
signal(SIGHUP, (void *) &grace_them_all);
|
||||
@@ -104,14 +100,6 @@ void master_loop(char **argv, char **environ) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_UDP
|
||||
UWSGI_GET_GIL
|
||||
udp_callable = PyDict_GetItemString(uwsgi.embedded_dict, "udp_callable");
|
||||
if (udp_callable) {
|
||||
udp_callable_args = PyTuple_New(3);
|
||||
}
|
||||
UWSGI_RELEASE_GIL
|
||||
#endif
|
||||
for (;;) {
|
||||
if (ready_to_die >= uwsgi.numproc && uwsgi.to_hell) {
|
||||
#ifdef UWSGI_SPOOLER
|
||||
@@ -236,6 +224,18 @@ void master_loop(char **argv, char **environ) {
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
|
||||
// loop the various udp manager until one returns true
|
||||
udp_managed = 0;
|
||||
for(i=0;i<0xFF;i++) {
|
||||
if (uwsgi.shared->hook_manage_udp[i]) {
|
||||
if (uwsgi.shared->hook_manage_udp[i](udp_client_addr, udp_client.sin_port, uwsgi.wsgi_req->buffer, rlen)) {
|
||||
udp_managed = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (udp_callable && udp_callable_args) {
|
||||
UWSGI_GET_GIL
|
||||
PyTuple_SetItem(udp_callable_args, 0, PyString_FromString(udp_client_addr));
|
||||
@@ -252,8 +252,12 @@ void master_loop(char **argv, char **environ) {
|
||||
}
|
||||
else {
|
||||
// a simple udp logger
|
||||
*/
|
||||
|
||||
if (!udp_managed) {
|
||||
uwsgi_log( "[udp:%s:%d] %.*s", udp_client_addr, ntohs(udp_client.sin_port), rlen, uwsgi.wsgi_req->buffer);
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -376,7 +380,7 @@ void master_loop(char **argv, char **environ) {
|
||||
if (WIFEXITED(waitpid_status)) {
|
||||
if (WEXITSTATUS(waitpid_status) != UWSGI_END_CODE) {
|
||||
uwsgi_log( "OOOPS the proxy is no more...trying respawn...\n");
|
||||
uwsgi.shared->spooler_pid = proxy_start(1);
|
||||
uwsgi.shared->proxy_pid = proxy_start(1);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,26 +23,18 @@ void embed_plugins() {
|
||||
|
||||
int uwsgi_load_plugin(int modifier, char *plugin, char *pargs, int absolute) {
|
||||
|
||||
char *plugin_name ;
|
||||
|
||||
void *plugin_handle;
|
||||
int (*plugin_init) (char *);
|
||||
int (*plugin_request) (struct wsgi_request *);
|
||||
void (*plugin_after_request) (struct wsgi_request *);
|
||||
|
||||
|
||||
char *plugin_name ;
|
||||
char *plugin_entry_symbol;
|
||||
struct uwsgi_plugin *up;
|
||||
|
||||
if (absolute) {
|
||||
plugin_name = malloc(strlen(plugin) + 1);
|
||||
memcpy(plugin_name, plugin, strlen(plugin) + 1);
|
||||
}
|
||||
else {
|
||||
plugin_name = malloc(strlen(UWSGI_PLUGIN_DIR) + 1 + strlen(plugin) + 1);
|
||||
if (!plugin_name) {
|
||||
uwsgi_error("malloc()");
|
||||
return -1 ;
|
||||
}
|
||||
memcpy(plugin_name, UWSGI_PLUGIN_DIR, strlen(UWSGI_PLUGIN_DIR));
|
||||
memcpy(plugin_name + strlen(UWSGI_PLUGIN_DIR) , "/", 1);
|
||||
memcpy(plugin_name + strlen(UWSGI_PLUGIN_DIR) + 1, plugin, strlen(plugin) + 1);
|
||||
plugin_name = uwsgi_concat4(UWSGI_PLUGIN_DIR, "/", plugin, "_plugin.so");
|
||||
}
|
||||
plugin_handle = dlopen(plugin_name, RTLD_NOW | RTLD_GLOBAL);
|
||||
free(plugin_name);
|
||||
@@ -51,33 +43,17 @@ int uwsgi_load_plugin(int modifier, char *plugin, char *pargs, int absolute) {
|
||||
uwsgi_log( "%s\n", dlerror());
|
||||
}
|
||||
else {
|
||||
plugin_init = dlsym(plugin_handle, "uwsgi_init");
|
||||
if (plugin_init) {
|
||||
if ((*plugin_init) (pargs)) {
|
||||
uwsgi_log( "plugin initialization returned error\n");
|
||||
if (dlclose(plugin_handle)) {
|
||||
uwsgi_log( "unable to unload plugin\n");
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
plugin_request = dlsym(plugin_handle, "uwsgi_request");
|
||||
if (plugin_request) {
|
||||
uwsgi.shared->hooks[modifier] = plugin_request;
|
||||
plugin_after_request = dlsym(plugin_handle, "uwsgi_after_request");
|
||||
if (plugin_after_request) {
|
||||
uwsgi.shared->after_hooks[modifier] = plugin_after_request;
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
else {
|
||||
uwsgi_log( "%s\n", dlerror());
|
||||
plugin_entry_symbol = uwsgi_concat2(plugin, "_plugin");
|
||||
up = dlsym(plugin_handle, plugin_entry_symbol);
|
||||
if (up) {
|
||||
fill_plugin_table(up->modifier1, up);
|
||||
return 1;
|
||||
}
|
||||
uwsgi_log( "%s\n", dlerror());
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -420,3 +420,16 @@ void uwsgi_after_request(struct wsgi_request *wsgi_req) {
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOGGING])
|
||||
log_request(wsgi_req);
|
||||
}
|
||||
|
||||
struct uwsgi_plugin psgi_plugin = {
|
||||
|
||||
.init = uwsgi_init;
|
||||
.post_fork = uwsgi_post_fork;
|
||||
.options = uwsgi_perl_options;
|
||||
.magic = uwsgi_perl_magic;
|
||||
.help = uwsgi_perl_help;
|
||||
.init_thread = uwsgi_init_thread;
|
||||
.request = uwsgi_request;
|
||||
.post_request = uwsgi_post_request;
|
||||
.init_app = uwsgi_init_app;
|
||||
};
|
||||
|
||||
@@ -127,6 +127,7 @@ int uwsgi_enqueue_message(char *host, int port, uint8_t modifier1, uint8_t modif
|
||||
return uwsgi_poll.fd;
|
||||
}
|
||||
|
||||
/*
|
||||
PyObject *uwsgi_send_message(const char *host, int port, uint8_t modifier1, uint8_t modifier2, char *message, int size, int timeout) {
|
||||
|
||||
struct pollfd uwsgi_mpoll;
|
||||
@@ -214,6 +215,8 @@ PyObject *uwsgi_send_message(const char *host, int port, uint8_t modifier1, uint
|
||||
return PyMarshal_ReadObjectFromString(buffer, uh.pktsize);
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
int uwsgi_parse_response(struct pollfd *upoll, int timeout, struct uwsgi_header *uh, char *buffer) {
|
||||
int rlen, i;
|
||||
|
||||
|
||||
-592
@@ -1,592 +0,0 @@
|
||||
#include "uwsgi.h"
|
||||
|
||||
/* notes
|
||||
|
||||
|
||||
exit(1) on every malloc error: apps can be dinamically loaded so on memory problem
|
||||
it is better to let the master process manager respawn the worker.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
#ifdef UWSGI_SENDFILE
|
||||
PyMethodDef uwsgi_sendfile_method[] = {{"uwsgi_sendfile", py_uwsgi_sendfile, METH_VARARGS, ""}};
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_ASYNC
|
||||
PyMethodDef uwsgi_eventfd_read_method[] = { {"uwsgi_eventfd_read", py_eventfd_read, METH_VARARGS, ""}};
|
||||
PyMethodDef uwsgi_eventfd_write_method[] = { {"uwsgi_eventfd_write", py_eventfd_write, METH_VARARGS, ""}};
|
||||
#endif
|
||||
|
||||
int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, int new_interpreter) {
|
||||
|
||||
PyObject *zero;
|
||||
|
||||
int id = uwsgi.apps_cnt;
|
||||
|
||||
#ifdef UWSGI_ASYNC
|
||||
int i;
|
||||
#endif
|
||||
|
||||
char *mountpoint;
|
||||
|
||||
struct uwsgi_app *wi;
|
||||
|
||||
|
||||
if (wsgi_req->script_name_len == 0) {
|
||||
wsgi_req->script_name = "";
|
||||
if (!uwsgi.vhost) id = 0;
|
||||
}
|
||||
else if (wsgi_req->script_name_len == 1) {
|
||||
if (wsgi_req->script_name[0] == '/') {
|
||||
if (!uwsgi.vhost) id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (uwsgi.vhost && wsgi_req->host_len > 0) {
|
||||
mountpoint = uwsgi_concat3n(wsgi_req->host, wsgi_req->host_len, "|", 1, wsgi_req->script_name, wsgi_req->script_name_len);
|
||||
}
|
||||
else {
|
||||
mountpoint = uwsgi_strncopy(wsgi_req->script_name, wsgi_req->script_name_len);
|
||||
}
|
||||
|
||||
if (uwsgi_get_app_id(mountpoint, strlen(mountpoint)) != -1) {
|
||||
uwsgi_log( "mountpoint %.*s already configured. skip.\n", strlen(mountpoint), mountpoint);
|
||||
free(mountpoint);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
wi = &uwsgi.apps[id];
|
||||
|
||||
memset(wi, 0, sizeof(struct uwsgi_app));
|
||||
wi->mountpoint = mountpoint;
|
||||
wi->mountpoint_len = strlen(mountpoint);
|
||||
|
||||
// dynamic chdir ?
|
||||
if (wsgi_req->chdir_len > 0) {
|
||||
wi->chdir = uwsgi_strncopy(wsgi_req->chdir, wsgi_req->chdir_len);
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_debug("chdir to %s\n", wi->chdir);
|
||||
#endif
|
||||
if (chdir(wi->chdir)) {
|
||||
uwsgi_error("chdir()");
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize a new environment for the new interpreter
|
||||
|
||||
if (new_interpreter && id) {
|
||||
wi->interpreter = Py_NewInterpreter();
|
||||
if (!wi->interpreter) {
|
||||
uwsgi_log( "unable to initialize the new python interpreter\n");
|
||||
exit(1);
|
||||
}
|
||||
PyThreadState_Swap(wi->interpreter);
|
||||
init_pyargv();
|
||||
|
||||
#ifdef UWSGI_EMBEDDED
|
||||
// we need to inizialize an embedded module for every interpreter
|
||||
init_uwsgi_embedded_module();
|
||||
#endif
|
||||
init_uwsgi_vars();
|
||||
|
||||
}
|
||||
else {
|
||||
wi->interpreter = uwsgi.main_thread;
|
||||
}
|
||||
|
||||
|
||||
wi->wsgi_callable = uwsgi.loaders[loader](arg1);
|
||||
|
||||
if (!wi->wsgi_callable) {
|
||||
uwsgi_log("unable to load app SCRIPT_NAME=%s\n", mountpoint);
|
||||
goto doh;
|
||||
}
|
||||
|
||||
#ifdef UWSGI_ASYNC
|
||||
wi->wsgi_environ = malloc(sizeof(PyObject*)*uwsgi.cores);
|
||||
if (!wi->wsgi_environ) {
|
||||
uwsgi_error("malloc()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for(i=0;i<uwsgi.cores;i++) {
|
||||
wi->wsgi_environ[i] = PyDict_New();
|
||||
if (!wi->wsgi_environ[i]) {
|
||||
uwsgi_log("unable to allocate new env dictionary for app\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
#else
|
||||
wi->wsgi_environ = PyDict_New();
|
||||
if (!wi->wsgi_environ) {
|
||||
uwsgi_log("unable to allocate new env dictionary for app\n");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// check function args
|
||||
// by defaut it is a WSGI app
|
||||
wi->argc = 2;
|
||||
zero = PyObject_GetAttrString(wi->wsgi_callable, "__code__");
|
||||
if (!zero) {
|
||||
zero = PyObject_GetAttrString(wi->wsgi_callable, "__call__");
|
||||
if (zero) {
|
||||
zero = PyObject_GetAttrString(wi->wsgi_callable, "__code__");
|
||||
}
|
||||
else {
|
||||
uwsgi_log("WARNING: unable to get the number of callable args. Fallback to WSGI\n");
|
||||
}
|
||||
}
|
||||
|
||||
// avoid __code__ attr error propagation
|
||||
PyErr_Clear();
|
||||
|
||||
if (zero) {
|
||||
zero = PyObject_GetAttrString(zero, "co_argcount");
|
||||
wi->argc = (int) PyInt_AsLong(zero);
|
||||
}
|
||||
|
||||
if (wi->argc == 2) {
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_log("-- WSGI callable detected --\n");
|
||||
#endif
|
||||
wi->request_subhandler = uwsgi_request_subhandler_wsgi;
|
||||
wi->response_subhandler = uwsgi_response_subhandler_wsgi;
|
||||
}
|
||||
#ifdef UWSGI_WEB3
|
||||
else if (wi->argc == 1) {
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_log("-- Web3 callable detected --\n");
|
||||
#endif
|
||||
wi->request_subhandler = uwsgi_request_subhandler_web3;
|
||||
wi->response_subhandler = uwsgi_response_subhandler_web3;
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
uwsgi_log("-- INVALID callable detected --\n");
|
||||
goto doh;
|
||||
}
|
||||
|
||||
#ifdef UWSGI_ASYNC
|
||||
wi->wsgi_args = malloc(sizeof(PyObject*)*uwsgi.cores);
|
||||
if (!wi->wsgi_args) {
|
||||
uwsgi_error("malloc()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for(i=0;i<uwsgi.cores;i++) {
|
||||
wi->wsgi_args[i] = PyTuple_New(wi->argc);
|
||||
if (!wi->wsgi_args[i]) {
|
||||
uwsgi_log("unable to allocate new tuple for app args\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// add start_response on WSGI app
|
||||
if (wi->argc == 2) {
|
||||
if (PyTuple_SetItem(wi->wsgi_args[i], 1, uwsgi.wsgi_spitout)) {
|
||||
uwsgi_log("unable to set start_response in args tuple\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
wi->wsgi_args = PyTuple_New(wi->argc);
|
||||
if (wi->argc == 2) {
|
||||
if (PyTuple_SetItem(wi->wsgi_args, 1, uwsgi.wsgi_spitout)) {
|
||||
uwsgi_log("unable to set start_response in args tuple\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (wi->argc == 2) {
|
||||
#ifdef UWSGI_SENDFILE
|
||||
// prepare sendfile() for WSGI app
|
||||
wi->wsgi_sendfile = PyCFunction_New(uwsgi_sendfile_method, NULL);
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_ASYNC
|
||||
wi->wsgi_eventfd_read = PyCFunction_New(uwsgi_eventfd_read_method, NULL);
|
||||
wi->wsgi_eventfd_write = PyCFunction_New(uwsgi_eventfd_write_method, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (new_interpreter && id) {
|
||||
// if we have multiple threads we need to initialize a PyThreadState for each one
|
||||
if (uwsgi.threads > 1) {
|
||||
for(i=0;i<uwsgi.threads;i++) {
|
||||
uwsgi.workers[uwsgi.mywid].cores[i]->ts[id] = PyThreadState_New(wi->interpreter->interp);
|
||||
if (!uwsgi.workers[uwsgi.mywid].cores[i]->ts[id]) {
|
||||
uwsgi_log("unable to allocate new PyThreadState structure for app %s", mountpoint);
|
||||
goto doh;
|
||||
}
|
||||
}
|
||||
PyThreadState_Swap((PyThreadState *) pthread_getspecific(uwsgi.ut_save_key));
|
||||
}
|
||||
else {
|
||||
PyThreadState_Swap(uwsgi.main_thread);
|
||||
}
|
||||
}
|
||||
|
||||
if (wi->argc == 1) {
|
||||
uwsgi_log( "Web3 application %d (SCRIPT_NAME=%.*s) ready on interpreter %p", id, wi->mountpoint_len, wi->mountpoint, wi->interpreter);
|
||||
}
|
||||
else {
|
||||
uwsgi_log( "WSGI application %d (SCRIPT_NAME=%.*s) ready on interpreter %p", id, wi->mountpoint_len, wi->mountpoint, wi->interpreter);
|
||||
}
|
||||
|
||||
if (id == 0) {
|
||||
uwsgi_log(" (default app)");
|
||||
uwsgi.default_app = 0;
|
||||
if (uwsgi.vhost) uwsgi.apps_cnt++;
|
||||
}
|
||||
else {
|
||||
uwsgi.apps_cnt++;
|
||||
}
|
||||
|
||||
uwsgi_log("\n");
|
||||
|
||||
return id;
|
||||
|
||||
doh:
|
||||
free(mountpoint);
|
||||
PyErr_Print();
|
||||
if (new_interpreter && id) {
|
||||
Py_EndInterpreter(wi->interpreter);
|
||||
if (uwsgi.threads > 1) {
|
||||
PyThreadState_Swap((PyThreadState *) pthread_getspecific(uwsgi.ut_save_key));
|
||||
}
|
||||
else {
|
||||
PyThreadState_Swap(uwsgi.main_thread);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *get_uwsgi_pymodule(char *module) {
|
||||
|
||||
char *quick_callable;
|
||||
|
||||
if ( (quick_callable = strchr(module, ':')) ) {
|
||||
quick_callable[0] = 0 ;
|
||||
quick_callable++;
|
||||
return quick_callable;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyObject *get_uwsgi_pydict(char *module) {
|
||||
|
||||
PyObject *wsgi_module, *wsgi_dict;
|
||||
|
||||
wsgi_module = PyImport_ImportModule(module);
|
||||
if (!wsgi_module) {
|
||||
PyErr_Print();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wsgi_dict = PyModule_GetDict(wsgi_module);
|
||||
if (!wsgi_dict) {
|
||||
PyErr_Print();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return wsgi_dict;
|
||||
|
||||
}
|
||||
|
||||
PyObject *uwsgi_uwsgi_loader(void *arg1) {
|
||||
|
||||
PyObject *wsgi_dict;
|
||||
|
||||
char *quick_callable;
|
||||
|
||||
PyObject *tmp_callable;
|
||||
|
||||
char *module = (char *) arg1 ;
|
||||
|
||||
quick_callable = get_uwsgi_pymodule(module) ;
|
||||
if (quick_callable == NULL) {
|
||||
if (uwsgi.callable) {
|
||||
quick_callable = uwsgi.callable ;
|
||||
}
|
||||
else {
|
||||
quick_callable = "application";
|
||||
}
|
||||
}
|
||||
|
||||
wsgi_dict = get_uwsgi_pydict(module);
|
||||
if (!wsgi_dict) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// quick callable -> thanks gunicorn for the idea
|
||||
// we have extended the concept a bit...
|
||||
if (quick_callable[strlen(quick_callable) -2 ] == '(' && quick_callable[strlen(quick_callable) -1] ==')') {
|
||||
quick_callable[strlen(quick_callable) -2 ] = 0 ;
|
||||
tmp_callable = PyDict_GetItemString(wsgi_dict, quick_callable);
|
||||
if (tmp_callable) {
|
||||
return python_call(tmp_callable, PyTuple_New(0), 0);
|
||||
}
|
||||
}
|
||||
|
||||
return PyDict_GetItemString(wsgi_dict, quick_callable);
|
||||
|
||||
}
|
||||
|
||||
/* this is the mount loader, it loads app on mountpoint automagically */
|
||||
PyObject *uwsgi_mount_loader(void *arg1) {
|
||||
|
||||
PyObject *callable = NULL ;
|
||||
char *what = (char *) arg1;
|
||||
|
||||
if ( !strcmp(what+strlen(what)-3, ".py") || !strcmp(what+strlen(what)-3, ".wsgi")) {
|
||||
callable = uwsgi_file_loader((void *)what);
|
||||
}
|
||||
#ifdef UWSGI_PASTE
|
||||
else if (!strcmp(what+strlen(what)-4, ".ini")) {
|
||||
callable = uwsgi_paste_loader((void *)what);
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
callable = uwsgi_uwsgi_loader((void *)what);
|
||||
}
|
||||
|
||||
return callable;
|
||||
}
|
||||
|
||||
|
||||
/* this is the dynamic loader, it loads app ireading nformation from a wsgi_request */
|
||||
PyObject *uwsgi_dyn_loader(void *arg1) {
|
||||
|
||||
PyObject *callable = NULL ;
|
||||
char *tmpstr;
|
||||
|
||||
struct wsgi_request *wsgi_req = (struct wsgi_request *) arg1;
|
||||
|
||||
// MANAGE UWSGI_SCRIPT
|
||||
if (wsgi_req->wsgi_script_len > 0) {
|
||||
tmpstr = uwsgi_strncopy(wsgi_req->wsgi_script, wsgi_req->wsgi_script_len);
|
||||
callable = uwsgi_uwsgi_loader((void *)tmpstr);
|
||||
free(tmpstr);
|
||||
}
|
||||
// MANAGE UWSGI_MODULE
|
||||
else if (wsgi_req->wsgi_module_len > 0) {
|
||||
if (wsgi_req->wsgi_callable_len > 0) {
|
||||
tmpstr = uwsgi_concat3n(wsgi_req->wsgi_module, wsgi_req->wsgi_module_len, ":", 1, wsgi_req->wsgi_callable, wsgi_req->wsgi_callable_len);
|
||||
}
|
||||
else {
|
||||
tmpstr = uwsgi_strncopy(wsgi_req->wsgi_module, wsgi_req->wsgi_module_len);
|
||||
}
|
||||
callable = uwsgi_uwsgi_loader((void *)tmpstr);
|
||||
free(tmpstr);
|
||||
}
|
||||
// MANAGE UWSGI_FILE
|
||||
else if (wsgi_req->wsgi_file_len > 0) {
|
||||
tmpstr = uwsgi_strncopy(wsgi_req->wsgi_file, wsgi_req->wsgi_file_len);
|
||||
callable = uwsgi_file_loader((void *)tmpstr);
|
||||
free(tmpstr);
|
||||
}
|
||||
#ifdef UWSGI_PASTE
|
||||
// MANAGE UWSGI_PASTE
|
||||
else if (wsgi_req->wsgi_paste_len > 0) {
|
||||
tmpstr = uwsgi_strncopy(wsgi_req->wsgi_paste, wsgi_req->wsgi_paste_len);
|
||||
callable = uwsgi_paste_loader((void *)tmpstr);
|
||||
free(tmpstr);
|
||||
}
|
||||
#endif
|
||||
|
||||
return callable;
|
||||
}
|
||||
|
||||
|
||||
/* trying to emulate Graham's mod_wsgi, this will allows easy and fast migrations */
|
||||
PyObject *uwsgi_file_loader(void *arg1) {
|
||||
|
||||
char *filename = (char *) arg1;
|
||||
FILE *wsgifile;
|
||||
struct _node *wsgi_file_node = NULL;
|
||||
PyObject *wsgi_compiled_node, *wsgi_file_module, *wsgi_file_dict;
|
||||
PyObject *wsgi_file_callable;
|
||||
|
||||
wsgifile = fopen(filename, "r");
|
||||
if (!wsgifile) {
|
||||
uwsgi_error("fopen()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
wsgi_file_node = PyParser_SimpleParseFile(wsgifile, filename, Py_file_input);
|
||||
if (!wsgi_file_node) {
|
||||
PyErr_Print();
|
||||
uwsgi_log( "failed to parse file %s\n", filename);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fclose(wsgifile);
|
||||
|
||||
wsgi_compiled_node = (PyObject *) PyNode_Compile(wsgi_file_node, filename);
|
||||
|
||||
if (!wsgi_compiled_node) {
|
||||
PyErr_Print();
|
||||
uwsgi_log( "failed to compile wsgi file %s\n", filename);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
wsgi_file_module = PyImport_ExecCodeModule("uwsgi_wsgi_file", wsgi_compiled_node);
|
||||
if (!wsgi_file_module) {
|
||||
PyErr_Print();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
Py_DECREF(wsgi_compiled_node);
|
||||
|
||||
wsgi_file_dict = PyModule_GetDict(wsgi_file_module);
|
||||
if (!wsgi_file_dict) {
|
||||
PyErr_Print();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
wsgi_file_callable = PyDict_GetItemString(wsgi_file_dict, "application");
|
||||
if (!wsgi_file_callable) {
|
||||
PyErr_Print();
|
||||
uwsgi_log( "unable to find \"application\" callable in file %s\n", filename);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!PyFunction_Check(wsgi_file_callable) && !PyCallable_Check(wsgi_file_callable)) {
|
||||
uwsgi_log( "\"application\" must be a callable object in file %s\n", filename);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
return wsgi_file_callable;
|
||||
|
||||
}
|
||||
|
||||
#ifdef UWSGI_PASTE
|
||||
PyObject *uwsgi_paste_loader(void *arg1) {
|
||||
|
||||
char *paste = (char *) arg1;
|
||||
PyObject *paste_module, *paste_dict, *paste_loadapp;
|
||||
PyObject *paste_arg, *paste_app;
|
||||
|
||||
uwsgi_log( "Loading paste environment: %s\n", paste);
|
||||
paste_module = PyImport_ImportModule("paste.deploy");
|
||||
if (!paste_module) {
|
||||
PyErr_Print();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
paste_dict = PyModule_GetDict(paste_module);
|
||||
if (!paste_dict) {
|
||||
PyErr_Print();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
paste_loadapp = PyDict_GetItemString(paste_dict, "loadapp");
|
||||
if (!paste_loadapp) {
|
||||
PyErr_Print();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
paste_arg = PyTuple_New(1);
|
||||
if (!paste_arg) {
|
||||
PyErr_Print();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (PyTuple_SetItem(paste_arg, 0, PyString_FromString(paste))) {
|
||||
PyErr_Print();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
paste_app = PyEval_CallObject(paste_loadapp, paste_arg);
|
||||
if (!paste_app) {
|
||||
PyErr_Print();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
return paste_app;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
PyObject *uwsgi_eval_loader(void *arg1) {
|
||||
|
||||
char *code = (char *) arg1;
|
||||
|
||||
PyObject *wsgi_eval_module, *wsgi_eval_callable = NULL;
|
||||
|
||||
struct _node *wsgi_eval_node = NULL;
|
||||
PyObject *wsgi_compiled_node ;
|
||||
|
||||
wsgi_eval_node = PyParser_SimpleParseString(code, Py_file_input);
|
||||
if (!wsgi_eval_node) {
|
||||
PyErr_Print();
|
||||
uwsgi_log( "failed to parse <eval> code\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
wsgi_compiled_node = (PyObject *) PyNode_Compile(wsgi_eval_node, "uwsgi_eval_config");
|
||||
|
||||
if (!wsgi_compiled_node) {
|
||||
PyErr_Print();
|
||||
uwsgi_log( "failed to compile eval code\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
wsgi_eval_module = PyImport_ExecCodeModule("uwsgi_eval_config", wsgi_compiled_node);
|
||||
if (!wsgi_eval_module) {
|
||||
PyErr_Print();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
Py_DECREF(wsgi_compiled_node);
|
||||
|
||||
uwsgi.pyloader_dict = PyModule_GetDict(wsgi_eval_module);
|
||||
if (!uwsgi.pyloader_dict) {
|
||||
PyErr_Print();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
if (uwsgi.callable) {
|
||||
wsgi_eval_callable = PyDict_GetItemString(uwsgi.pyloader_dict, uwsgi.callable);
|
||||
}
|
||||
else {
|
||||
wsgi_eval_callable = PyDict_GetItemString(uwsgi.pyloader_dict, "application");
|
||||
}
|
||||
|
||||
if (wsgi_eval_callable) {
|
||||
uwsgi_log( "found the \"%s\" callable\n", uwsgi.callable);
|
||||
if (!PyFunction_Check(wsgi_eval_callable) && !PyCallable_Check(wsgi_eval_callable)) {
|
||||
uwsgi_log( "you must define a callable object in your code\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
return wsgi_eval_callable;
|
||||
|
||||
}
|
||||
|
||||
PyObject *uwsgi_callable_loader(void *arg1) {
|
||||
return (PyObject *) arg1;
|
||||
}
|
||||
|
||||
PyObject *uwsgi_string_callable_loader(void *arg1) {
|
||||
char *callable = (char *) arg1;
|
||||
|
||||
return PyDict_GetItem(uwsgi.pyloader_dict, UWSGI_PYFROMSTRING(callable));
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
#include "uwsgi.h"
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
int manage_python_response(struct wsgi_request *wsgi_req) {
|
||||
// use standard WSGI response parse
|
||||
return uwsgi_response_subhandler_wsgi(wsgi_req);
|
||||
}
|
||||
|
||||
PyObject *python_call(PyObject *callable, PyObject *args, int catch) {
|
||||
|
||||
PyObject *pyret;
|
||||
|
||||
pyret = PyEval_CallObject(callable, args);
|
||||
|
||||
if (PyErr_Occurred()) {
|
||||
if (!catch) {
|
||||
PyErr_Print();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef UWSGI_DEBUG
|
||||
if (pyret) {
|
||||
uwsgi_debug("called %p %p %d\n", callable, args, pyret->ob_refcnt);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
return pyret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int uwsgi_python_call(struct wsgi_request *wsgi_req, PyObject *callable, PyObject *args) {
|
||||
|
||||
wsgi_req->async_result = python_call(callable, args, 0);
|
||||
|
||||
if (wsgi_req->async_result) {
|
||||
while ( manage_python_response(wsgi_req) != UWSGI_OK) {
|
||||
#ifdef UWSGI_ASYNC
|
||||
if (uwsgi.async > 1) {
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return UWSGI_OK;
|
||||
}
|
||||
|
||||
void init_pyargv() {
|
||||
|
||||
char *ap;
|
||||
|
||||
#ifdef PYTHREE
|
||||
wchar_t pname[6];
|
||||
mbstowcs(pname, "uwsgi", 6);
|
||||
uwsgi.py_argv[0] = pname;
|
||||
#else
|
||||
uwsgi.py_argv[0] = "uwsgi";
|
||||
#endif
|
||||
|
||||
if (uwsgi.pyargv != NULL && !uwsgi.pyargc) {
|
||||
uwsgi.pyargc++;
|
||||
#ifdef PYTHREE
|
||||
wchar_t *wcargv = malloc( sizeof( wchar_t ) * (strlen(uwsgi.pyargv)+1));
|
||||
if (!wcargv) {
|
||||
uwsgi_error("malloc()");
|
||||
exit(1);
|
||||
}
|
||||
memset(wcargv, 0, sizeof( wchar_t ) * (strlen(uwsgi.pyargv)+1));
|
||||
#endif
|
||||
|
||||
#ifdef __sun__
|
||||
// FIX THIS !!!
|
||||
ap = strtok(uwsgi.pyargv, " ");
|
||||
while ((ap = strtok(NULL, " ")) != NULL) {
|
||||
#else
|
||||
while ((ap = strsep(&uwsgi.pyargv, " \t")) != NULL) {
|
||||
#endif
|
||||
if (*ap != '\0') {
|
||||
#ifdef PYTHREE
|
||||
mbstowcs( wcargv + strlen(ap), ap, strlen(ap));
|
||||
uwsgi.py_argv[uwsgi.pyargc] = wcargv + strlen(ap);
|
||||
#else
|
||||
uwsgi.py_argv[uwsgi.pyargc] = ap;
|
||||
#endif
|
||||
uwsgi.pyargc++;
|
||||
}
|
||||
if (uwsgi.pyargc + 1 > MAX_PYARGV)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PySys_SetArgv(uwsgi.pyargc, uwsgi.py_argv);
|
||||
}
|
||||
+2
-27
@@ -4,31 +4,6 @@
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
PyObject *py_uwsgi_sendfile(PyObject * self, PyObject * args) {
|
||||
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O|i:uwsgi_sendfile", &wsgi_req->async_sendfile, &wsgi_req->sendfile_fd_chunk)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef PYTHREE
|
||||
wsgi_req->sendfile_fd = PyObject_AsFileDescriptor(wsgi_req->async_sendfile);
|
||||
#else
|
||||
if (PyFile_Check((PyObject *)wsgi_req->async_sendfile)) {
|
||||
Py_INCREF((PyObject *)wsgi_req->async_sendfile);
|
||||
wsgi_req->sendfile_fd = PyObject_AsFileDescriptor(wsgi_req->async_sendfile);
|
||||
}
|
||||
#endif
|
||||
|
||||
// PEP 333 hack
|
||||
wsgi_req->sendfile_obj = wsgi_req->async_sendfile;
|
||||
//wsgi_req->sendfile_obj = (void *) PyTuple_New(0);
|
||||
|
||||
Py_INCREF((PyObject *) wsgi_req->sendfile_obj);
|
||||
return (PyObject *) wsgi_req->sendfile_obj;
|
||||
}
|
||||
|
||||
ssize_t uwsgi_sendfile(struct wsgi_request *wsgi_req) {
|
||||
|
||||
int fd = wsgi_req->sendfile_fd ;
|
||||
@@ -36,7 +11,7 @@ ssize_t uwsgi_sendfile(struct wsgi_request *wsgi_req) {
|
||||
struct stat stat_buf;
|
||||
ssize_t sst = 0;
|
||||
|
||||
UWSGI_RELEASE_GIL
|
||||
//UWSGI_RELEASE_GIL
|
||||
|
||||
if (!wsgi_req->sendfile_fd_size) {
|
||||
|
||||
@@ -57,7 +32,7 @@ ssize_t uwsgi_sendfile(struct wsgi_request *wsgi_req) {
|
||||
}
|
||||
|
||||
end:
|
||||
UWSGI_GET_GIL
|
||||
//UWSGI_GET_GIL
|
||||
return sst;
|
||||
}
|
||||
|
||||
|
||||
@@ -369,6 +369,7 @@ static ssize_t build_snmp_response(uint8_t oid1, uint8_t oid2, uint8_t * buffer,
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
PyObject *py_snmp_counter32(PyObject * self, PyObject * args) {
|
||||
|
||||
uint8_t oid_num;
|
||||
@@ -484,6 +485,7 @@ void snmp_init() {
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#else
|
||||
#warning "*** SNMP support is disabled ***"
|
||||
|
||||
@@ -350,7 +350,8 @@ void uwsgi_close_request(struct wsgi_request *wsgi_req) {
|
||||
}
|
||||
|
||||
// after_request hook
|
||||
(*uwsgi.shared->after_hooks[wsgi_req->uh.modifier1]) (wsgi_req);
|
||||
uwsgi_log("CALL LOG %p\n", uwsgi.shared->hook_after_request[wsgi_req->uh.modifier1]);
|
||||
uwsgi.shared->hook_after_request[wsgi_req->uh.modifier1](wsgi_req);
|
||||
|
||||
// leave harakiri mode
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
|
||||
@@ -411,7 +412,10 @@ int wsgi_req_recv(struct wsgi_request *wsgi_req) {
|
||||
set_harakiri(uwsgi.shared->options[UWSGI_OPTION_HARAKIRI]);
|
||||
}
|
||||
|
||||
wsgi_req->async_status = (*uwsgi.shared->hooks[wsgi_req->uh.modifier1]) (wsgi_req);
|
||||
uwsgi_log("oooops %p\n", uwsgi.shared->hook_request[wsgi_req->uh.modifier1]);
|
||||
wsgi_req->async_status = uwsgi.shared->hook_request[wsgi_req->uh.modifier1] (wsgi_req);
|
||||
|
||||
uwsgi_log("done\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -697,6 +701,28 @@ char *uwsgi_concat2(char *one, char *two) {
|
||||
|
||||
}
|
||||
|
||||
char *uwsgi_concat4(char *one, char *two, char *three, char *four) {
|
||||
|
||||
char *buf;
|
||||
size_t len = strlen(one) + strlen(two) + strlen(three) + strlen(four) + 1;
|
||||
|
||||
|
||||
buf = malloc(len);
|
||||
if (buf == NULL) {
|
||||
uwsgi_error("malloc()");
|
||||
exit(1);
|
||||
}
|
||||
buf[len-1] = 0;
|
||||
|
||||
memcpy( buf, one, strlen(one));
|
||||
memcpy( buf + strlen(one) , two, strlen(two));
|
||||
memcpy( buf + strlen(one) + strlen(two) , three, strlen(three));
|
||||
memcpy( buf + strlen(one) + strlen(two) + strlen(three) , four, strlen(four));
|
||||
|
||||
return buf;
|
||||
|
||||
}
|
||||
|
||||
|
||||
char *uwsgi_concat3(char *one, char *two, char *three) {
|
||||
|
||||
@@ -822,3 +848,16 @@ int uwsgi_get_app_id(char *script_name, int script_name_len) {
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int count_options(struct option *lopt) {
|
||||
struct option *aopt;
|
||||
int count = 0;
|
||||
|
||||
while ( (aopt = lopt) ) {
|
||||
if (!aopt->name) break;
|
||||
count++;
|
||||
lopt++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -10,16 +10,25 @@
|
||||
#define wsgi_req_time ((wsgi_req->end_of_request.tv_sec * 1000000 + wsgi_req->end_of_request.tv_usec) - (wsgi_req->start_of_request.tv_sec * 1000000 + wsgi_req->start_of_request.tv_usec))/1000
|
||||
|
||||
#define MAX_APPS 64
|
||||
#define MAX_MOUNTPOINTS 64
|
||||
#define MAX_PYTHONPATH 64
|
||||
|
||||
#ifdef UWSGI_THREADING
|
||||
#define UWSGI_GET_GIL (*uwsgi.gil_get)();
|
||||
#define UWSGI_RELEASE_GIL (*uwsgi.gil_release)();
|
||||
#else
|
||||
#define UWSGI_GET_GIL
|
||||
#define UWSGI_RELEASE_GIL
|
||||
#endif
|
||||
#define LEP(lepname) \
|
||||
extern struct uwsgi_plugin lepname##_plugin;\
|
||||
fill_plugin_table(lepup->modifier1, lepname);
|
||||
|
||||
#define fill_plugin_table(x, up)\
|
||||
uwsgi.shared->hook_init[x] = up->init;\
|
||||
uwsgi.shared->hook_post_fork[x] = up->post_fork;\
|
||||
uwsgi.shared->hook_options[x] = up->options;\
|
||||
uwsgi.shared->hook_manage_opt[x] = up->manage_opt;\
|
||||
uwsgi.shared->hook_request[x] = up->request;\
|
||||
uwsgi.shared->hook_after_request[x] = up->after_request;\
|
||||
uwsgi.shared->hook_init_apps[x] = up->init_apps;\
|
||||
uwsgi.shared->hook_enable_threads[x] = up->enable_threads;\
|
||||
uwsgi.shared->hook_init_thread[x] = up->init_thread;\
|
||||
uwsgi.shared->hook_manage_udp[x] = up->manage_udp;\
|
||||
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -30,6 +39,10 @@
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <stdarg.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
|
||||
#include <dirent.h>
|
||||
|
||||
@@ -128,19 +141,6 @@
|
||||
#endif
|
||||
|
||||
#undef _XOPEN_SOURCE
|
||||
#include <Python.h>
|
||||
|
||||
#ifdef UWSGI_STACKLESS
|
||||
#include <stackless_api.h>
|
||||
#endif
|
||||
|
||||
#if PY_MINOR_VERSION == 4 && PY_MAJOR_VERSION == 2
|
||||
#define Py_ssize_t ssize_t
|
||||
#endif
|
||||
|
||||
#if PY_MAJOR_VERSION > 2
|
||||
#define PYTHREE
|
||||
#endif
|
||||
|
||||
/* this value are taken from nginx */
|
||||
#if defined(__APPLE__) || defined(__freebsd__)
|
||||
@@ -149,8 +149,6 @@
|
||||
#define UWSGI_LISTEN_QUEUE 511
|
||||
#endif
|
||||
|
||||
PyAPI_FUNC(PyObject *) PyMarshal_WriteObjectToString(PyObject *, int);
|
||||
PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t);
|
||||
|
||||
#define MAX_CLUSTER_NODES 100
|
||||
|
||||
@@ -287,26 +285,6 @@ PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t);
|
||||
|
||||
#define UWSGI_MODIFIER_RESPONSE 255
|
||||
|
||||
#ifdef PYTHREE
|
||||
#define UWSGI_PYFROMSTRING(x) PyUnicode_FromString(x)
|
||||
#define UWSGI_PYFROMSTRINGSIZE(x, y) PyUnicode_FromStringAndSize(x, y)
|
||||
#define PyInt_FromLong PyLong_FromLong
|
||||
#define PyInt_AsLong PyLong_AsLong
|
||||
#define PyInt_Check PyLong_Check
|
||||
#define PyString_Check PyBytes_Check
|
||||
#define PyString_FromStringAndSize PyBytes_FromStringAndSize
|
||||
#define PyString_FromFormat PyBytes_FromFormat
|
||||
#define PyString_FromString PyBytes_FromString
|
||||
#define PyString_Size PyBytes_Size
|
||||
#define PyString_Concat PyBytes_Concat
|
||||
#define PyString_AsString (char *) PyBytes_AsString
|
||||
#define PyFile_FromFile(A,B,C,D) PyFile_FromFd(fileno((A)), (B), (C), -1, NULL, NULL, NULL, 0)
|
||||
|
||||
#else
|
||||
#define UWSGI_PYFROMSTRING(x) PyString_FromString(x)
|
||||
#define UWSGI_PYFROMSTRINGSIZE(x, y) PyString_FromStringAndSize(x, y)
|
||||
#endif
|
||||
|
||||
#define NL_SIZE 2
|
||||
#define H_SEP_SIZE 2
|
||||
|
||||
@@ -328,30 +306,30 @@ struct uwsgi_server;
|
||||
|
||||
struct uwsgi_app {
|
||||
|
||||
uint8_t modifier1;
|
||||
|
||||
char *mountpoint;
|
||||
int mountpoint_len;
|
||||
|
||||
PyThreadState *interpreter;
|
||||
PyObject *pymain_dict;
|
||||
void *interpreter;
|
||||
//PyObject *pymain_dict;
|
||||
//PyObject *wsgi_dict;
|
||||
PyObject *wsgi_callable;
|
||||
void *callable;
|
||||
|
||||
|
||||
#ifdef UWSGI_ASYNC
|
||||
PyObject **wsgi_args;
|
||||
PyObject **wsgi_environ;
|
||||
void **args;
|
||||
void **environ;
|
||||
#else
|
||||
PyObject *wsgi_args;
|
||||
PyObject *wsgi_environ;
|
||||
void *args;
|
||||
void *environ;
|
||||
#endif
|
||||
PyObject *wsgi_harakiri;
|
||||
|
||||
PyObject *wsgi_sendfile;
|
||||
PyObject *wsgi_cprofile_run;
|
||||
void *sendfile;
|
||||
|
||||
#ifdef UWSGI_ASYNC
|
||||
PyObject *wsgi_eventfd_read;
|
||||
PyObject *wsgi_eventfd_write;
|
||||
void *eventfd_read;
|
||||
void *eventfd_write;
|
||||
#endif
|
||||
|
||||
void* (*request_subhandler)(struct wsgi_request *, struct uwsgi_app *);
|
||||
@@ -497,10 +475,6 @@ struct wsgi_request {
|
||||
char *post_buffering_buf;
|
||||
uint64_t post_buffering_read;
|
||||
|
||||
#ifdef UWSGI_STACKLESS
|
||||
PyTaskletObject* tasklet;
|
||||
#endif
|
||||
|
||||
char *buffer;
|
||||
};
|
||||
|
||||
@@ -528,7 +502,6 @@ struct uwsgi_server {
|
||||
struct wsgi_request **wsgi_requests ;
|
||||
struct wsgi_request *wsgi_req ;
|
||||
|
||||
PyThreadState *_save;
|
||||
char *chroot;
|
||||
gid_t gid;
|
||||
uid_t uid;
|
||||
@@ -673,11 +646,9 @@ struct uwsgi_server {
|
||||
|
||||
char *file_config;
|
||||
|
||||
char *python_path[MAX_PYTHONPATH];
|
||||
//char *python_path[MAX_PYTHONPATH];
|
||||
int python_path_cnt;
|
||||
char *pyargv;
|
||||
|
||||
int pyargc;
|
||||
#ifdef PYTHREE
|
||||
wchar_t *py_argv[MAX_PYARGV];
|
||||
#else
|
||||
@@ -705,23 +676,6 @@ struct uwsgi_server {
|
||||
int single_interpreter;
|
||||
int py_optimize;
|
||||
|
||||
PyObject *embedded_dict;
|
||||
PyObject *embedded_args;
|
||||
PyObject *fastfuncslist;
|
||||
|
||||
PyObject *wsgi_writeout;
|
||||
|
||||
#ifdef UWSGI_STACKLESS
|
||||
PyObject *wsgi_stackless;
|
||||
PyChannelObject *workers_channel;
|
||||
struct stackless_req **stackless_table;
|
||||
#endif
|
||||
|
||||
PyObject *workers_tuple;
|
||||
|
||||
PyThreadState *main_thread;
|
||||
|
||||
|
||||
struct uwsgi_shared *shared;
|
||||
|
||||
struct uwsgi_app apps[MAX_APPS];
|
||||
@@ -733,23 +687,6 @@ struct uwsgi_server {
|
||||
|
||||
int no_orphans;
|
||||
|
||||
#ifdef UWSGI_EMBED_PLUGINS
|
||||
|
||||
#ifdef UWSGI_EMBED_PLUGIN_PSGI
|
||||
char *plugin_arg_psgi;
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_EMBED_PLUGIN_LUA
|
||||
char *plugin_arg_lua;
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_EMBED_PLUGIN_RACK
|
||||
char *plugin_arg_rack;
|
||||
char *plugin_arg_rails;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
char *chdir2;
|
||||
int catch_exceptions;
|
||||
|
||||
@@ -763,8 +700,6 @@ struct uwsgi_server {
|
||||
char *ping;
|
||||
int ping_timeout;
|
||||
|
||||
char *callable;
|
||||
|
||||
int xml_round2;
|
||||
|
||||
char *cwd;
|
||||
@@ -782,39 +717,26 @@ struct uwsgi_server {
|
||||
int cgroup_opt_cnt;
|
||||
#endif
|
||||
|
||||
PyObject *wsgi_spitout;
|
||||
|
||||
int sockets_cnt;
|
||||
struct uwsgi_socket sockets[8];
|
||||
struct pollfd sockets_poll[8];
|
||||
|
||||
time_t respawn_delta;
|
||||
|
||||
PyObject *pyloader_dict;
|
||||
|
||||
PyObject* (*loaders[LOADER_MAX]) (void *);
|
||||
|
||||
char *mounts[MAX_MOUNTPOINTS];
|
||||
char *mounts[MAX_APPS];
|
||||
int mounts_cnt;
|
||||
|
||||
int cores;
|
||||
int threads;
|
||||
pthread_key_t ut_key;
|
||||
pthread_key_t ut_save_key;
|
||||
|
||||
// this key old the u_request structure per core/thread
|
||||
pthread_key_t tur_key;
|
||||
|
||||
|
||||
#ifdef UWSGI_THREADING
|
||||
void (*gil_get) (void);
|
||||
void (*gil_release) (void);
|
||||
#endif
|
||||
|
||||
struct wsgi_request* (*current_wsgi_req)(void);
|
||||
|
||||
int close_on_exec;
|
||||
|
||||
#ifdef UWSGI_THREADING
|
||||
pthread_mutex_t lock_pyloaders;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct uwsgi_cluster_node {
|
||||
@@ -847,8 +769,16 @@ struct uwsgi_shared {
|
||||
// vga 80x25 specific !
|
||||
char warning_message[81];
|
||||
|
||||
int (*hooks[256]) (struct wsgi_request *);
|
||||
void (*after_hooks[256]) (struct wsgi_request *);
|
||||
int (*hook_init[0xFF]) (void);
|
||||
void (*hook_post_fork[0xFF]) (void);
|
||||
void (*hook_enable_threads[0xFF]) (void);
|
||||
int (*hook_request[0xFF]) (struct wsgi_request *);
|
||||
void (*hook_after_request[0xFF]) (struct wsgi_request *);
|
||||
void (*hook_init_thread[0xFF]) (void);
|
||||
void (*hook_init_apps[0xFF]) (void);
|
||||
struct option *hook_options[0xFF];
|
||||
int (*hook_manage_opt[0xFF]) (int, char*);
|
||||
int (*hook_manage_udp[0xFF]) (char *, int, char*, int);
|
||||
uint32_t options[256];
|
||||
|
||||
struct uwsgi_cluster_node nodes[MAX_CLUSTER_NODES];
|
||||
@@ -888,7 +818,7 @@ struct uwsgi_core {
|
||||
uint64_t failed_requests;
|
||||
|
||||
// multiple ts per-core are needed only with multiple_interpreter + threads
|
||||
PyThreadState *ts[MAX_APPS];
|
||||
void *ts[MAX_APPS];
|
||||
|
||||
};
|
||||
|
||||
@@ -948,28 +878,12 @@ void harakiri(void);
|
||||
|
||||
void stats(void);
|
||||
|
||||
void init_uwsgi_vars(void);
|
||||
void init_uwsgi_embedded_module(void);
|
||||
|
||||
#ifdef UWSGI_XML
|
||||
void uwsgi_xml_config(struct wsgi_request *, struct option *);
|
||||
#endif
|
||||
|
||||
void uwsgi_wsgi_config(char *);
|
||||
#ifdef UWSGI_PASTE
|
||||
void uwsgi_paste_config(char *);
|
||||
#endif
|
||||
void uwsgi_file_config(char *);
|
||||
void uwsgi_eval_config(char *);
|
||||
|
||||
void internal_server_error(int, char *);
|
||||
|
||||
void init_uwsgi_module_sharedarea(PyObject *);
|
||||
void init_uwsgi_module_advanced(PyObject *);
|
||||
#ifdef UWSGI_SPOOLER
|
||||
void init_uwsgi_module_spooler(PyObject *);
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_SNMP
|
||||
void manage_snmp(int, uint8_t *, int, struct sockaddr_in *);
|
||||
void snmp_init(void);
|
||||
@@ -990,10 +904,6 @@ uint32_t uwsgi_swap32(uint32_t);
|
||||
uint64_t uwsgi_swap64(uint64_t);
|
||||
#endif
|
||||
|
||||
int init_uwsgi_app(int, void *, struct wsgi_request *wsgi_req, int);
|
||||
|
||||
PyObject *uwsgi_send_message(const char *, int, uint8_t, uint8_t, char *, int, int);
|
||||
|
||||
#ifdef UWSGI_UDP
|
||||
ssize_t send_udp_message(uint8_t, char *, char *, uint16_t);
|
||||
#endif
|
||||
@@ -1003,19 +913,6 @@ int uwsgi_parse_vars(struct wsgi_request *);
|
||||
|
||||
int uwsgi_enqueue_message(char *, int, uint8_t, uint8_t, char *, int, int);
|
||||
|
||||
/* included HOOKS */
|
||||
int uwsgi_request_wsgi(struct wsgi_request *);
|
||||
void uwsgi_after_request_wsgi(struct wsgi_request *);
|
||||
|
||||
int uwsgi_request_admin(struct wsgi_request *);
|
||||
#ifdef UWSGI_SPOOLER
|
||||
int uwsgi_request_spooler(struct wsgi_request *);
|
||||
#endif
|
||||
int uwsgi_request_eval(struct wsgi_request *);
|
||||
int uwsgi_request_fastfunc(struct wsgi_request *);
|
||||
int uwsgi_request_marshal(struct wsgi_request *);
|
||||
int uwsgi_request_ping(struct wsgi_request *);
|
||||
|
||||
#ifdef UWSGI_ERLANG
|
||||
|
||||
#include <erl_interface.h>
|
||||
@@ -1023,8 +920,6 @@ int uwsgi_request_ping(struct wsgi_request *);
|
||||
|
||||
int init_erlang(char *, char *);
|
||||
void erlang_loop(struct wsgi_request *);
|
||||
PyObject *eterm_to_py(ETERM *);
|
||||
ETERM *py_to_eterm(PyObject *);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1092,29 +987,8 @@ void async_unpause_all(void);
|
||||
#define ASYNC_IS_OUT ASYNC_EV == ASYNC_OUT
|
||||
#endif
|
||||
|
||||
PyObject *py_eventfd_read(PyObject *, PyObject *) ;
|
||||
PyObject *py_eventfd_write(PyObject *, PyObject *) ;
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_STACKLESS
|
||||
PyObject *py_uwsgi_stackless(PyObject *, PyObject *) ;
|
||||
#endif
|
||||
|
||||
int manage_python_response(struct wsgi_request *);
|
||||
int uwsgi_python_call(struct wsgi_request *, PyObject *, PyObject *);
|
||||
PyObject *python_call(PyObject *, PyObject *, int);
|
||||
|
||||
#ifdef UWSGI_SENDFILE
|
||||
PyObject *py_uwsgi_sendfile(PyObject *, PyObject *) ;
|
||||
ssize_t uwsgi_sendfile(struct wsgi_request *);
|
||||
ssize_t uwsgi_do_sendfile(int, int, size_t, size_t, off_t*, int);
|
||||
#endif
|
||||
|
||||
PyObject *py_uwsgi_write(PyObject *, PyObject *) ;
|
||||
PyObject *py_uwsgi_spit(PyObject *, PyObject *) ;
|
||||
|
||||
void uwsgi_as_root(void);
|
||||
|
||||
#ifdef UWSGI_NAGIOS
|
||||
@@ -1122,18 +996,6 @@ void nagios(void);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef UWSGI_STACKLESS
|
||||
struct stackless_req {
|
||||
PyTaskletObject *tasklet;
|
||||
struct wsgi_request *wsgi_req;
|
||||
PyChannelObject *channel;
|
||||
};
|
||||
struct wsgi_request *find_request_by_tasklet(PyTaskletObject *);
|
||||
|
||||
void stackless_init(void);
|
||||
void stackless_loop(void);
|
||||
#endif
|
||||
|
||||
void uwsgi_close_request(struct wsgi_request *) ;
|
||||
|
||||
void wsgi_req_setup(struct wsgi_request *, int);
|
||||
@@ -1164,78 +1026,10 @@ void uwsgi_log(const char *, ...);
|
||||
void uwsgi_log_verbose(const char *, ...);
|
||||
|
||||
|
||||
#ifdef UWSGI_EVDIS
|
||||
#define EVDIS_TYPE_FILE
|
||||
#define EVDIS_TYPE_DNSSD
|
||||
#endif
|
||||
|
||||
int uwsgi_load_plugin(int, char *, char *, int);
|
||||
void embed_plugins(void);
|
||||
|
||||
|
||||
// PLUGINS
|
||||
|
||||
#define UWSGI_PLUGIN_LONGOPT_PSGI
|
||||
#define UWSGI_PLUGIN_LONGOPT_LUA
|
||||
#define UWSGI_PLUGIN_LONGOPT_RACK
|
||||
#define LONG_ARGS_PLUGIN_EMBED_PSGI
|
||||
#define LONG_ARGS_PLUGIN_EMBED_LUA
|
||||
#define LONG_ARGS_PLUGIN_EMBED_RACK
|
||||
|
||||
|
||||
|
||||
#ifdef UWSGI_EMBED_PLUGINS
|
||||
|
||||
|
||||
#ifdef UWSGI_EMBED_PLUGIN_PSGI
|
||||
|
||||
#undef UWSGI_PLUGIN_LONGOPT_PSGI
|
||||
#define UWSGI_PLUGIN_LONGOPT_PSGI {"psgi", required_argument, 0, 30005},
|
||||
|
||||
#undef LONG_ARGS_PLUGIN_EMBED_PSGI
|
||||
#define LONG_ARGS_PLUGIN_EMBED_PSGI case 30005:\
|
||||
uwsgi.plugin_arg_psgi = optarg;\
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_EMBED_PLUGIN_LUA
|
||||
|
||||
#undef UWSGI_PLUGIN_LONGOPT_LUA
|
||||
#define UWSGI_PLUGIN_LONGOPT_LUA {"lua", required_argument, 0, 30006},
|
||||
|
||||
#undef LONG_ARGS_PLUGIN_EMBED_LUA
|
||||
#define LONG_ARGS_PLUGIN_EMBED_LUA case 30006:\
|
||||
uwsgi.plugin_arg_lua = optarg;\
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_EMBED_PLUGIN_RACK
|
||||
|
||||
#undef UWSGI_PLUGIN_LONGOPT_RACK
|
||||
#define UWSGI_PLUGIN_LONGOPT_RACK {"rack", required_argument, 0, 30007},\
|
||||
{"rails", required_argument, 0, 30008},
|
||||
|
||||
#undef LONG_ARGS_PLUGIN_EMBED_RACK
|
||||
#define LONG_ARGS_PLUGIN_EMBED_RACK case 30007:\
|
||||
uwsgi.plugin_arg_rack = optarg;\
|
||||
break;\
|
||||
case 30008:\
|
||||
uwsgi.plugin_arg_rails = optarg;\
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_ROUTING
|
||||
void routing_setup(void);
|
||||
void check_route(struct wsgi_request *);
|
||||
void uwsgi_route_action_uwsgi(struct wsgi_request *, struct uwsgi_route *);
|
||||
void uwsgi_route_action_wsgi(struct wsgi_request *, struct uwsgi_route *);
|
||||
#endif
|
||||
|
||||
void init_pyargv(void);
|
||||
|
||||
void http_loop();
|
||||
|
||||
int unconfigured_hook(struct wsgi_request *);
|
||||
@@ -1263,16 +1057,9 @@ char *uwsgi_concatn(int, ...);
|
||||
char *uwsgi_concat2(char *, char *);
|
||||
char *uwsgi_concat3(char *, char *, char *);
|
||||
char *uwsgi_concat3n(char *, int, char *, int, char *, int);
|
||||
char *uwsgi_concat4(char *, char *, char *, char *);
|
||||
|
||||
|
||||
void *uwsgi_request_subhandler_wsgi(struct wsgi_request *, struct uwsgi_app *);
|
||||
int uwsgi_response_subhandler_wsgi(struct wsgi_request *);
|
||||
|
||||
#ifdef UWSGI_WEB3
|
||||
void *uwsgi_request_subhandler_web3(struct wsgi_request *, struct uwsgi_app *);
|
||||
int uwsgi_response_subhandler_web3(struct wsgi_request *);
|
||||
#endif
|
||||
|
||||
int uwsgi_get_app_id(char *, int);
|
||||
char *uwsgi_strncopy(char *, int );
|
||||
|
||||
@@ -1280,31 +1067,36 @@ void master_loop(char **, char **);
|
||||
|
||||
|
||||
int find_worker_id(pid_t);
|
||||
void init_uwsgi_py_interpreter(struct wsgi_request *);
|
||||
|
||||
|
||||
|
||||
PyObject *uwsgi_uwsgi_loader(void *);
|
||||
PyObject *uwsgi_dyn_loader(void *);
|
||||
PyObject *uwsgi_file_loader(void *);
|
||||
PyObject *uwsgi_eval_loader(void *);
|
||||
PyObject *uwsgi_paste_loader(void *);
|
||||
PyObject *uwsgi_callable_loader(void *);
|
||||
PyObject *uwsgi_string_callable_loader(void *);
|
||||
PyObject *uwsgi_mount_loader(void *);
|
||||
|
||||
char *get_uwsgi_pymodule(char *);
|
||||
PyObject *get_uwsgi_pydict(char *);
|
||||
|
||||
void *simple_loop(void *);
|
||||
void complex_loop(void);
|
||||
|
||||
struct uwsgi_plugin {
|
||||
|
||||
char *name;
|
||||
uint8_t modifier1;
|
||||
void *data;
|
||||
int (*init)(void);
|
||||
void (*post_fork)(void);
|
||||
struct option *options;
|
||||
int (*manage_opt)(int, char*);
|
||||
void (*magic)(char *);
|
||||
void (*enable_threads)(void);
|
||||
void (*init_thread)(void);
|
||||
int (*request)(struct wsgi_request*);
|
||||
void (*after_request)(struct wsgi_request*);
|
||||
void (*init_apps)(void);
|
||||
int (*manage_udp)(char *, int, char *, int);
|
||||
|
||||
};
|
||||
|
||||
int count_options(struct option*);
|
||||
|
||||
#ifdef UWSGI_SENDFILE
|
||||
ssize_t uwsgi_do_sendfile(int , int , size_t , size_t , off_t *, int );
|
||||
#endif
|
||||
|
||||
|
||||
void gil_real_get(void);
|
||||
void gil_real_release(void);
|
||||
void gil_fake_get(void);
|
||||
void gil_fake_release(void);
|
||||
|
||||
struct wsgi_request* threaded_current_wsgi_req(void);
|
||||
struct wsgi_request* simple_current_wsgi_req(void);
|
||||
struct wsgi_request* threaded_current_wsgi_req(void);
|
||||
|
||||
@@ -2,61 +2,6 @@
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
/* uwsgi PING|100 */
|
||||
int uwsgi_request_ping(struct wsgi_request *wsgi_req) {
|
||||
char len;
|
||||
|
||||
uwsgi_log( "PING\n");
|
||||
wsgi_req->uh.modifier2 = 1;
|
||||
wsgi_req->uh.pktsize = 0;
|
||||
|
||||
len = strlen(uwsgi.shared->warning_message);
|
||||
if (len > 0) {
|
||||
// TODO: check endianess ?
|
||||
wsgi_req->uh.pktsize = len;
|
||||
}
|
||||
if (write(wsgi_req->poll.fd, wsgi_req, 4) != 4) {
|
||||
uwsgi_error("write()");
|
||||
}
|
||||
|
||||
if (len > 0) {
|
||||
if (write(wsgi_req->poll.fd, uwsgi.shared->warning_message, len)
|
||||
!= len) {
|
||||
uwsgi_error("write()");
|
||||
}
|
||||
}
|
||||
|
||||
return UWSGI_OK;
|
||||
}
|
||||
|
||||
/* uwsgi ADMIN|10 */
|
||||
int uwsgi_request_admin(struct wsgi_request *wsgi_req) {
|
||||
uint32_t opt_value = 0;
|
||||
int i;
|
||||
|
||||
if (wsgi_req->uh.pktsize >= 4) {
|
||||
memcpy(&opt_value, wsgi_req->buffer, 4);
|
||||
// TODO: check endianess ?
|
||||
}
|
||||
|
||||
uwsgi_log( "setting internal option %d to %d\n", wsgi_req->uh.modifier2, opt_value);
|
||||
uwsgi.shared->options[wsgi_req->uh.modifier2] = opt_value;
|
||||
|
||||
// ACK
|
||||
wsgi_req->uh.modifier1 = 255;
|
||||
wsgi_req->uh.pktsize = 0;
|
||||
wsgi_req->uh.modifier2 = 1;
|
||||
|
||||
i = write(wsgi_req->poll.fd, wsgi_req, 4);
|
||||
if (i != 4) {
|
||||
uwsgi_error("write()");
|
||||
}
|
||||
|
||||
|
||||
|
||||
return UWSGI_OK;
|
||||
}
|
||||
|
||||
int uwsgi_request_eval(struct wsgi_request *wsgi_req) {
|
||||
|
||||
PyObject *code, *py_dict;
|
||||
|
||||
+202
-332
@@ -1,53 +1,4 @@
|
||||
# uWSGI configuration
|
||||
|
||||
XML=True
|
||||
INI=True
|
||||
SNMP=True
|
||||
SCTP=False
|
||||
ERLANG=False
|
||||
SPOOLER=True
|
||||
EMBEDDED=True
|
||||
UDP=True
|
||||
MULTICAST=True
|
||||
THREADING=True
|
||||
SENDFILE=True
|
||||
NAGIOS=True
|
||||
PROXY=True
|
||||
PASTE=True
|
||||
MINTERPRETERS=True
|
||||
ASYNC=True
|
||||
UGREEN=False
|
||||
HTTP=True
|
||||
EVDIS=False
|
||||
LDAP=True
|
||||
WEB3=True
|
||||
ROUTING=False
|
||||
STACKLESS=False
|
||||
#PLUGINS = ['psgi']
|
||||
PLUGINS = ['psgi']
|
||||
USWALLOW=False
|
||||
UNBIT=False
|
||||
DEBUG=False
|
||||
EMBED_PLUGINS=True
|
||||
UWSGI_BIN_NAME = 'uwsgi'
|
||||
UWSGI_PLUGIN_DIR = '.'
|
||||
|
||||
|
||||
# specific compilation flags
|
||||
# libxml2 or expat
|
||||
XML_IMPLEMENTATION = 'libxml2'
|
||||
# if you want to use alternative python lib, specifiy its path here
|
||||
#PYLIB_PATH = '/home/roberto/uwsgi/STACKLESS/slp/lib'
|
||||
PYLIB_PATH = ''
|
||||
ERLANG_CFLAGS = ''
|
||||
ERLANG_LDFLAGS = '-lerl_interface -lei'
|
||||
# for source distribution installed in /usr/local
|
||||
#ERLANG_CFLAGS = '-I /usr/local/lib/erlang/lib/erl_interface-3.6.5/include/'
|
||||
#ERLANG_LDFLAGS = '-L/usr/local/lib/erlang/lib/erl_interface-3.6.5/lib -lerl_interface -lei'
|
||||
|
||||
|
||||
|
||||
# end of configuration
|
||||
# uWSGI build system
|
||||
|
||||
import os
|
||||
uwsgi_os = os.uname()[0]
|
||||
@@ -58,6 +9,8 @@ import subprocess
|
||||
|
||||
from distutils import sysconfig
|
||||
|
||||
import ConfigParser
|
||||
|
||||
GCC = os.environ.get('CC', sysconfig.get_config_var('CC'))
|
||||
if not GCC:
|
||||
GCC = 'gcc'
|
||||
@@ -83,42 +36,6 @@ def spcall2(cmd):
|
||||
else:
|
||||
return None
|
||||
|
||||
gcc_version = str(spcall2("%s -v" % GCC)).split('\n')[-1].split()[2]
|
||||
|
||||
gcc_major = int(gcc_version.split('.')[0])
|
||||
gcc_minor = int(gcc_version.split('.')[1])
|
||||
|
||||
|
||||
gcc_list = ['utils', 'pyutils', 'pyloader', 'protocol', 'socket', 'logging', 'master', 'wsgi_handlers', 'wsgi_subhandler', 'wsgi_headers', 'uwsgi_handlers', 'plugins', 'loop', 'gil', 'uwsgi']
|
||||
|
||||
cflags = ['-O2', '-Wall', '-Werror', '-D_LARGEFILE_SOURCE', '-D_FILE_OFFSET_BITS=64'] + os.environ.get("CFLAGS", "").split()
|
||||
|
||||
# add -fno-strict-aliasing only on python2 and gcc < 4.3
|
||||
if (sys.version_info[0] == 2) or (gcc_major < 4) or (gcc_major == 4 and gcc_minor < 3):
|
||||
cflags = cflags + ['-fno-strict-aliasing']
|
||||
|
||||
if gcc_major >= 4:
|
||||
cflags = cflags + [ '-Wextra', '-Wno-unused-parameter', '-Wno-missing-field-initializers' ]
|
||||
|
||||
cflags = cflags + ['-I' + sysconfig.get_python_inc(), '-I' + sysconfig.get_python_inc(plat_specific=True) ]
|
||||
|
||||
ldflags = os.environ.get("LDFLAGS", "").split()
|
||||
libs = ['-lpthread', '-rdynamic'] + sysconfig.get_config_var('LIBS').split() + sysconfig.get_config_var('SYSLIBS').split()
|
||||
if not sysconfig.get_config_var('Py_ENABLE_SHARED'):
|
||||
libs.append('-L' + sysconfig.get_config_var('LIBPL'))
|
||||
|
||||
|
||||
if USWALLOW:
|
||||
cflags = cflags + sysconfig.get_config_var('LLVM_CXXFLAGS').split()
|
||||
ldflags = ldflags + sysconfig.get_config_var('LLVM_LDFLAGS').split() + sysconfig.get_config_var('LINKFORSHARED').split()
|
||||
GCC = 'clang'
|
||||
|
||||
def depends_on(what, dep):
|
||||
for d in dep:
|
||||
if not globals()[d]:
|
||||
print("%s needs %s support." % (what, d))
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def add_o(x):
|
||||
if x == 'uwsgi':
|
||||
@@ -126,24 +43,65 @@ def add_o(x):
|
||||
x = x + '.o'
|
||||
return x
|
||||
|
||||
def compile(file, objfile, cflags):
|
||||
cmdline = "%s -c %s -o %s %s" % (GCC, cflags, objfile, file)
|
||||
print(cmdline)
|
||||
ret = os.system(cmdline)
|
||||
if ret != 0:
|
||||
sys.exit(1)
|
||||
|
||||
def build_uwsgi(bin_name):
|
||||
print("*** uWSGI compiling ***")
|
||||
def build_uwsgi(uc):
|
||||
|
||||
gcc_list, cflags, ldflags, libs = uc.get_gcll()
|
||||
|
||||
print("*** uWSGI compiling server core ***")
|
||||
for file in gcc_list:
|
||||
objfile = file
|
||||
if objfile == 'uwsgi':
|
||||
objfile = 'main'
|
||||
cmdline = "%s -c %s -o %s %s" % (GCC, ' '.join(cflags), objfile + '.o', file + '.c')
|
||||
print(cmdline)
|
||||
ret = os.system(cmdline)
|
||||
if ret != 0:
|
||||
sys.exit(1)
|
||||
compile(' '.join(cflags), objfile + '.o', file + '.c')
|
||||
|
||||
if len(PLUGINS) > 0:
|
||||
print("*** uWSGI building plugins ***")
|
||||
for plugin in PLUGINS:
|
||||
print("*** building plugin: %s ***" % plugin)
|
||||
build_plugin("plugins/%s" % plugin)
|
||||
if uc.get('embedded_plugins'):
|
||||
ep = uc.get('embedded_plugins').split(',')
|
||||
|
||||
if len(ep) > 0:
|
||||
print("*** uWSGI compiling embedded plugins ***")
|
||||
for p in ep:
|
||||
path = 'plugins/%s' % p
|
||||
path = path.rstrip('/')
|
||||
|
||||
sys.path.insert(0, path)
|
||||
import uwsgiplugin as up
|
||||
reload(up)
|
||||
|
||||
p_cflags = cflags[:]
|
||||
p_ldflags = ldflags[:]
|
||||
|
||||
p_cflags += up.CFLAGS
|
||||
p_ldflags += up.LDFLAGS
|
||||
|
||||
for cfile in up.GCC_LIST:
|
||||
compile(' '.join(p_cflags), path + '/' + cfile + '.o', path + '/' + cfile + '.c')
|
||||
gcc_list.append('%s/%s' % (path, cfile))
|
||||
|
||||
libs += up.LIBS
|
||||
|
||||
up.CFLAGS = None
|
||||
up.LDFLAGS = None
|
||||
up.LIBS = None
|
||||
up.GCC_LIST = None
|
||||
|
||||
if uc.get('plugins'):
|
||||
|
||||
plugins = uc.get('plugins').split(',')
|
||||
if len(plugins) > 0:
|
||||
print("*** uWSGI building plugins ***")
|
||||
|
||||
for p in plugins:
|
||||
print("*** building plugin: %s ***" % p)
|
||||
build_plugin("plugins/%s" % p, uc, cflags, ldflags, libs)
|
||||
|
||||
bin_name = uc.get('bin_name')
|
||||
|
||||
print("*** uWSGI linking ***")
|
||||
ldline = "%s -o %s %s %s %s" % (GCC, bin_name, ' '.join(ldflags), ' '.join(map(add_o, gcc_list)), ' '.join(libs))
|
||||
@@ -157,180 +115,100 @@ def build_uwsgi(bin_name):
|
||||
bin_name = './' + bin_name
|
||||
print("*** uWSGI is ready, launch it with %s ***" % bin_name)
|
||||
|
||||
def unbit_setup():
|
||||
class uConf():
|
||||
|
||||
global XML
|
||||
XML=True
|
||||
def __init__(self, filename):
|
||||
self.config = ConfigParser.ConfigParser()
|
||||
self.config.read(filename)
|
||||
self.gcc_list = ['utils', 'protocol', 'socket', 'logging', 'master', 'plugins', 'loop', 'uwsgi']
|
||||
self.cflags = ['-O2', '-Wall', '-Werror', '-D_LARGEFILE_SOURCE', '-D_FILE_OFFSET_BITS=64'] + os.environ.get("CFLAGS", "").split()
|
||||
gcc_version = str(spcall2("%s -v" % GCC)).split('\n')[-1].split()[2]
|
||||
gcc_major = int(gcc_version.split('.')[0])
|
||||
gcc_minor = int(gcc_version.split('.')[1])
|
||||
if (sys.version_info[0] == 2) or (gcc_major < 4) or (gcc_major == 4 and gcc_minor < 3):
|
||||
self.cflags = self.cflags + ['-fno-strict-aliasing']
|
||||
# add -fno-strict-aliasing only on python2 and gcc < 4.3
|
||||
if gcc_major >= 4:
|
||||
self.cflags = self.cflags + [ '-Wextra', '-Wno-unused-parameter', '-Wno-missing-field-initializers' ]
|
||||
|
||||
global INI
|
||||
INI=False
|
||||
self.ldflags = os.environ.get("LDFLAGS", "").split()
|
||||
self.libs = ['-lpthread', '-rdynamic']
|
||||
|
||||
global SNMP
|
||||
SNMP=False
|
||||
def get(self,key):
|
||||
try:
|
||||
value = self.config.get('uwsgi', key)
|
||||
if value == "" or value == "false":
|
||||
return None
|
||||
return value
|
||||
except:
|
||||
return None
|
||||
|
||||
global SCTP
|
||||
SCTP=False
|
||||
|
||||
global ERLANG
|
||||
ERLANG=False
|
||||
|
||||
global SPOOLER
|
||||
SPOOLER=True
|
||||
def depends_on(self, what, dep):
|
||||
for d in dep:
|
||||
if not self.get(d):
|
||||
print("%s needs %s support." % (what, d))
|
||||
sys.exit(1)
|
||||
|
||||
global EMBEDDED
|
||||
EMBEDDED=True
|
||||
|
||||
global UDP
|
||||
UDP=False
|
||||
|
||||
global MULTICAST
|
||||
MULTICAST=False
|
||||
def get_gcll(self):
|
||||
kvm_list = ['FreeBSD', 'OpenBSD', 'NetBSD', 'DragonFly']
|
||||
|
||||
global THREADING
|
||||
THREADING=False
|
||||
if uwsgi_os == 'SunOS':
|
||||
self.libs.append('-lsendfile')
|
||||
self.libs.remove('-rdynamic')
|
||||
|
||||
global SENDFILE
|
||||
SENDFILE=True
|
||||
if uwsgi_os in kvm_list:
|
||||
self.libs.append('-lkvm')
|
||||
|
||||
global NAGIOS
|
||||
NAGIOS=False
|
||||
if uwsgi_os == 'OpenBSD' or uwsgi_cpu[0:3] == 'arm' or uwsgi_os == 'Haiku':
|
||||
self.set('ugreen', 'false')
|
||||
|
||||
global PROXY
|
||||
PROXY=False
|
||||
if uwsgi_os == 'Haiku':
|
||||
self.set('async', 'false')
|
||||
self.set('proxy', 'false')
|
||||
self.libs.remove('-rdynamic')
|
||||
self.libs.remove('-lpthread')
|
||||
self.libs.append('-lroot')
|
||||
|
||||
global PASTE
|
||||
PASTE=False
|
||||
if self.get('embedded'):
|
||||
self.cflags.append('-DUWSGI_EMBEDDED')
|
||||
self.gcc_list.append('uwsgi_pymodule')
|
||||
|
||||
global MINTERPRETERS
|
||||
MINTERPRETERS=False
|
||||
|
||||
global ASYNC
|
||||
ASYNC=False
|
||||
if self.get('udp'):
|
||||
self.cflags.append("-DUWSGI_UDP")
|
||||
|
||||
global UGREEN
|
||||
UGREEN=False
|
||||
if self.get('async'):
|
||||
self.cflags.append("-DUWSGI_ASYNC")
|
||||
self.gcc_list.append('async')
|
||||
|
||||
global HTTP
|
||||
HTTP=False
|
||||
if self.get('multicast'):
|
||||
self.depends_on('multicast', ['udp'])
|
||||
self.cflags.append("-DUWSGI_MULTICAST")
|
||||
|
||||
global EVDIS
|
||||
EVDIS=False
|
||||
if self.get('minterpreters'):
|
||||
self.cflags.append("-DUWSGI_MINTERPRETERS")
|
||||
|
||||
global WEB3
|
||||
WEB3=False
|
||||
if self.get('nagios'):
|
||||
self.cflags.append("-DUWSGI_NAGIOS")
|
||||
self.gcc_list.append('nagios')
|
||||
|
||||
global LDAP
|
||||
LDAP=False
|
||||
if self.get('ini'):
|
||||
self.cflags.append("-DUWSGI_INI")
|
||||
self.gcc_list.append('ini')
|
||||
|
||||
global ROUTING
|
||||
ROUTING=False
|
||||
if self.get('proxy'):
|
||||
self.depends_on('proxy', ['async'])
|
||||
self.cflags.append("-DUWSGI_PROXY")
|
||||
self.gcc_list.append('proxy')
|
||||
|
||||
global STACKLESS
|
||||
STACKLESS=False
|
||||
|
||||
global PLUGINS
|
||||
#PLUGINS = ['psgi']
|
||||
PLUGINS = []
|
||||
|
||||
global USWALLOW
|
||||
USWALLOW=False
|
||||
|
||||
global UNBIT
|
||||
UNBIT=True
|
||||
|
||||
global DEBUG
|
||||
DEBUG=False
|
||||
|
||||
global EMBED_PLUGINS
|
||||
EMBED_PLUGINS=True
|
||||
|
||||
global UWSGI_BIN_NAME
|
||||
UWSGI_BIN_NAME = '../bin/uwsgi'
|
||||
|
||||
global UWSGI_PLUGIN_DIR
|
||||
UWSGI_PLUGIN_DIR = '../bin'
|
||||
|
||||
global PYLIB_PATH
|
||||
PYLIB_PATH = '/proc/unbit/opt/python26/lib'
|
||||
|
||||
def parse_vars():
|
||||
|
||||
global UGREEN, ASYNC, PROXY
|
||||
|
||||
version = sys.version_info
|
||||
uver = "%d.%d" % (version[0], version[1])
|
||||
|
||||
libs.append('-lpython' + uver)
|
||||
|
||||
if str(PYLIB_PATH) != '':
|
||||
libs.insert(0,'-L' + PYLIB_PATH)
|
||||
os.environ['LD_RUN_PATH'] = PYLIB_PATH
|
||||
|
||||
kvm_list = ['FreeBSD', 'OpenBSD', 'NetBSD', 'DragonFly']
|
||||
|
||||
if uwsgi_os == 'SunOS':
|
||||
libs.append('-lsendfile')
|
||||
libs.remove('-rdynamic')
|
||||
|
||||
if uwsgi_os in kvm_list:
|
||||
libs.append('-lkvm')
|
||||
|
||||
if uwsgi_os == 'OpenBSD' or uwsgi_cpu[0:3] == 'arm' or uwsgi_os == 'Haiku':
|
||||
UGREEN = False
|
||||
|
||||
if uwsgi_os == 'Haiku':
|
||||
ASYNC = False
|
||||
PROXY = False
|
||||
libs.remove('-rdynamic')
|
||||
libs.remove('-lpthread')
|
||||
libs.append('-lroot')
|
||||
|
||||
if EMBEDDED:
|
||||
cflags.append('-DUWSGI_EMBEDDED')
|
||||
gcc_list.append('uwsgi_pymodule')
|
||||
|
||||
if UDP:
|
||||
cflags.append("-DUWSGI_UDP")
|
||||
|
||||
if ASYNC:
|
||||
cflags.append("-DUWSGI_ASYNC")
|
||||
gcc_list.append('async')
|
||||
|
||||
if MULTICAST:
|
||||
depends_on("MULTICAST", ['UDP'])
|
||||
cflags.append("-DUWSGI_MULTICAST")
|
||||
|
||||
if STACKLESS:
|
||||
if not cflags.__contains__('-DSTACKLESS_FRHACK=1'):
|
||||
print("you need Stackless Python to use Tasklet")
|
||||
sys.exit(1)
|
||||
cflags.append("-DUWSGI_STACKLESS")
|
||||
gcc_list.append('stackless')
|
||||
|
||||
if MINTERPRETERS:
|
||||
cflags.append("-DUWSGI_MINTERPRETERS")
|
||||
|
||||
if NAGIOS:
|
||||
cflags.append("-DUWSGI_NAGIOS")
|
||||
gcc_list.append('nagios')
|
||||
|
||||
if INI:
|
||||
cflags.append("-DUWSGI_INI")
|
||||
gcc_list.append('ini')
|
||||
|
||||
if DEBUG:
|
||||
cflags.append("-DUWSGI_DEBUG")
|
||||
|
||||
if PROXY:
|
||||
depends_on("PROXY", ['ASYNC'])
|
||||
cflags.append("-DUWSGI_PROXY")
|
||||
gcc_list.append('proxy')
|
||||
|
||||
if LDAP:
|
||||
cflags.append("-DUWSGI_LDAP")
|
||||
gcc_list.append('ldap')
|
||||
libs.append('-lldap')
|
||||
if self.get('ldap'):
|
||||
self.cflags.append("-DUWSGI_LDAP")
|
||||
self.gcc_list.append('ldap')
|
||||
self.libs.append('-lldap')
|
||||
|
||||
"""
|
||||
if ROUTING:
|
||||
depends_on("ROUTING", ['WEB3', 'XML'])
|
||||
cflags.append("-DUWSGI_ROUTING")
|
||||
@@ -348,119 +226,114 @@ def parse_vars():
|
||||
sys.exit(1)
|
||||
else:
|
||||
libs.append(pcreconf)
|
||||
"""
|
||||
|
||||
if HTTP:
|
||||
cflags.append("-DUWSGI_HTTP")
|
||||
gcc_list.append('http')
|
||||
if self.get('http'):
|
||||
self.cflags.append("-DUWSGI_HTTP")
|
||||
self.gcc_list.append('http')
|
||||
|
||||
if EVDIS:
|
||||
cflags.append("-DUWSGI_EVDIS")
|
||||
gcc_list.append('evdis')
|
||||
if self.get('evdis'):
|
||||
self.cflags.append("-DUWSGI_EVDIS")
|
||||
self.gcc_list.append('evdis')
|
||||
|
||||
|
||||
if UGREEN:
|
||||
if uwsgi_os == 'Darwin':
|
||||
cflags.append("-D_XOPEN_SOURCE")
|
||||
depends_on("UGREEN", ['ASYNC'])
|
||||
cflags.append("-DUWSGI_UGREEN")
|
||||
gcc_list.append('ugreen')
|
||||
if self.get('ugreen'):
|
||||
if uwsgi_os == 'Darwin':
|
||||
self.cflags.append("-D_XOPEN_SOURCE")
|
||||
self.depends_on("ugreen", ['async'])
|
||||
self.cflags.append("-DUWSGI_UGREEN")
|
||||
self.gcc_list.append('ugreen')
|
||||
|
||||
if SNMP:
|
||||
depends_on("SNMP", ['UDP'])
|
||||
cflags.append("-DUWSGI_SNMP")
|
||||
gcc_list.append('snmp')
|
||||
if self.get('snmp'):
|
||||
self.depends_on("snmp", ['udp'])
|
||||
self.cflags.append("-DUWSGI_SNMP")
|
||||
self.gcc_list.append('snmp')
|
||||
|
||||
if THREADING:
|
||||
cflags.append("-DUWSGI_THREADING")
|
||||
if self.get('threading'):
|
||||
self.cflags.append("-DUWSGI_THREADING")
|
||||
|
||||
if PASTE:
|
||||
cflags.append('-DUWSGI_PASTE')
|
||||
if self.get('sendfile'):
|
||||
self.cflags.append("-DUWSGI_SENDFILE")
|
||||
self.gcc_list.append('sendfile')
|
||||
|
||||
if SENDFILE:
|
||||
cflags.append("-DUWSGI_SENDFILE")
|
||||
gcc_list.append('sendfile')
|
||||
|
||||
if XML:
|
||||
if XML_IMPLEMENTATION == 'libxml2':
|
||||
xmlconf = spcall('xml2-config --libs')
|
||||
if xmlconf is None:
|
||||
print("*** libxml2 headers unavailable. uWSGI build is interrupted. You have to install libxml2 development package or use libexpat or disable XML")
|
||||
sys.exit(1)
|
||||
else:
|
||||
libs.append(xmlconf)
|
||||
xmlconf = spcall("xml2-config --cflags")
|
||||
if self.get('xml'):
|
||||
if self.get('xml_implementation') == 'libxml2':
|
||||
xmlconf = spcall('xml2-config --libs')
|
||||
if xmlconf is None:
|
||||
print("*** libxml2 headers unavailable. uWSGI build is interrupted. You have to install libxml2 development package or use libexpat or disable XML")
|
||||
sys.exit(1)
|
||||
else:
|
||||
cflags.append(xmlconf)
|
||||
cflags.append("-DUWSGI_XML -DUWSGI_XML_LIBXML2")
|
||||
gcc_list.append('xmlconf')
|
||||
elif XML_IMPLEMENTATION == 'expat':
|
||||
cflags.append("-DUWSGI_XML -DUWSGI_XML_EXPAT")
|
||||
libs.append('-lexpat')
|
||||
gcc_list.append('xmlconf')
|
||||
self.libs.append(xmlconf)
|
||||
xmlconf = spcall("xml2-config --cflags")
|
||||
if xmlconf is None:
|
||||
print("*** libxml2 headers unavailable. uWSGI build is interrupted. You have to install libxml2 development package or use libexpat or disable XML")
|
||||
sys.exit(1)
|
||||
else:
|
||||
self.cflags.append(xmlconf)
|
||||
self.cflags.append("-DUWSGI_XML -DUWSGI_XML_LIBXML2")
|
||||
self.gcc_list.append('xmlconf')
|
||||
elif self.get('xml_implementation') == 'expat':
|
||||
self.cflags.append("-DUWSGI_XML -DUWSGI_XML_EXPAT")
|
||||
self.libs.append('-lexpat')
|
||||
self.gcc_list.append('xmlconf')
|
||||
|
||||
|
||||
if ERLANG:
|
||||
depends_on("ERLANG", ['EMBEDDED'])
|
||||
cflags.append("-DUWSGI_ERLANG")
|
||||
libs.append(ERLANG_LDFLAGS)
|
||||
if str(ERLANG_CFLAGS) != '':
|
||||
cflags.append(ERLANG_CFLAGS)
|
||||
gcc_list.append('erlang')
|
||||
if self.get('erlang'):
|
||||
self.depends_on("ERLANG", ['EMBEDDED'])
|
||||
self.cflags.append("-DUWSGI_ERLANG")
|
||||
self.libs.append(ERLANG_LDFLAGS)
|
||||
if str(ERLANG_CFLAGS) != '':
|
||||
self.cflags.append(ERLANG_CFLAGS)
|
||||
self.gcc_list.append('erlang')
|
||||
|
||||
if UWSGI_PLUGIN_DIR is not None:
|
||||
cflags.append("-DUWSGI_PLUGIN_DIR=\\\"%s\\\"" % UWSGI_PLUGIN_DIR)
|
||||
if self.get('plugin_dir'):
|
||||
self.cflags.append('-DUWSGI_PLUGIN_DIR=\\"%s\\"' % self.get('plugin_dir'))
|
||||
|
||||
if len(PLUGINS) > 0 and EMBED_PLUGINS:
|
||||
cflags.append("-DUWSGI_EMBED_PLUGINS")
|
||||
for plugin in PLUGINS:
|
||||
cflags.append("-DUWSGI_EMBED_PLUGIN_%s" % plugin.upper())
|
||||
if self.get('spooler'):
|
||||
self.depends_on("spooler", ['embedded'])
|
||||
self.cflags.append("-DUWSGI_SPOOLER")
|
||||
self.gcc_list.append('spooler')
|
||||
|
||||
if SCTP:
|
||||
libs.append("-lsctp")
|
||||
cflags.append("-DUWSGI_SCTP")
|
||||
if self.get('debug'):
|
||||
self.cflags.append("-DUWSGI_DEBUG")
|
||||
self.cflags.append("-g")
|
||||
|
||||
if SPOOLER:
|
||||
depends_on("SPOOLER", ['EMBEDDED'])
|
||||
cflags.append("-DUWSGI_SPOOLER")
|
||||
gcc_list.append('spooler')
|
||||
if self.get('unbit'):
|
||||
self.cflags.append("-DUNBIT")
|
||||
|
||||
if WEB3:
|
||||
cflags.append("-DUWSGI_WEB3")
|
||||
gcc_list.append('web3_subhandler')
|
||||
return self.gcc_list, self.cflags, self.ldflags, self.libs
|
||||
|
||||
if DEBUG:
|
||||
cflags.append("-DUWSGI_DEBUG")
|
||||
cflags.append("-g")
|
||||
|
||||
if UNBIT:
|
||||
cflags.append("-DUNBIT")
|
||||
|
||||
def build_plugin(path):
|
||||
def build_plugin(path, uc, cflags, ldflags, libs):
|
||||
path = path.rstrip('/')
|
||||
|
||||
sys.path.insert(0, path)
|
||||
import uwsgiplugin as up
|
||||
reload(up)
|
||||
|
||||
p_cflags = cflags[:]
|
||||
p_ldflags = ldflags[:]
|
||||
p_libs = libs[:]
|
||||
|
||||
p_cflags.append(up.CFLAGS)
|
||||
p_ldflags.append(up.LDFLAGS)
|
||||
p_cflags += up.CFLAGS
|
||||
p_ldflags += up.LDFLAGS
|
||||
p_libs += up.LIBS
|
||||
|
||||
p_cflags.insert(0, '-I.')
|
||||
|
||||
plugin_base = path + '/' + up.NAME + '_plugin'
|
||||
plugin_dest = UWSGI_PLUGIN_DIR + '/' + up.NAME + '_plugin'
|
||||
plugin_dest = uc.get('plugin_dir') + '/' + up.NAME + '_plugin'
|
||||
|
||||
shared_flag = '-shared'
|
||||
|
||||
gcc_list = []
|
||||
|
||||
if uwsgi_os == 'Darwin':
|
||||
shared_flag = '-dynamiclib -undefined dynamic_lookup'
|
||||
|
||||
gccline = "%s -fPIC %s -o %s.so %s %s %s.c" % (GCC, shared_flag, plugin_dest, ' '.join(p_cflags), ' '.join(p_ldflags), plugin_base )
|
||||
for cfile in up.GCC_LIST:
|
||||
gcc_list.append(path + '/' + cfile + '.c')
|
||||
|
||||
|
||||
gccline = "%s -fPIC %s -o %s.so %s %s %s %s" % (GCC, shared_flag, plugin_dest, ' '.join(p_cflags), ' '.join(p_ldflags), ' '.join(gcc_list), ' '.join(p_libs) )
|
||||
print(gccline)
|
||||
|
||||
ret = os.system(gccline)
|
||||
@@ -491,15 +364,12 @@ if __name__ == "__main__":
|
||||
if cmd == '--libs':
|
||||
print(' '.join(libs))
|
||||
elif cmd == '--build':
|
||||
parse_vars()
|
||||
build_uwsgi(UWSGI_BIN_NAME)
|
||||
build_uwsgi(uConf('buildconf/default.ini'))
|
||||
elif cmd == '--unbit':
|
||||
unbit_setup()
|
||||
parse_vars()
|
||||
build_uwsgi(UWSGI_BIN_NAME)
|
||||
build_uwsgi(uConf('buildconf/unbit.ini'))
|
||||
elif cmd == '--plugin':
|
||||
parse_vars()
|
||||
build_plugin(sys.argv[2])
|
||||
build_plugin(sys.argv[2], uConf('buildconf/unbit.ini'))
|
||||
else:
|
||||
print("unknown uwsgiconfig command")
|
||||
sys.exit(1)
|
||||
|
||||
@@ -1,165 +0,0 @@
|
||||
#include "uwsgi.h"
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
void *uwsgi_request_subhandler_web3(struct wsgi_request *wsgi_req, struct uwsgi_app *wi) {
|
||||
|
||||
PyObject *zero, *wsgi_socket;
|
||||
|
||||
|
||||
wsgi_socket = PyFile_FromFile(wsgi_req->async_post, "web3_input", "r", NULL);
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "web3.input", wsgi_socket);
|
||||
Py_DECREF(wsgi_socket);
|
||||
|
||||
zero = PyTuple_New(2);
|
||||
PyTuple_SetItem(zero, 0, PyInt_FromLong(1));
|
||||
PyTuple_SetItem(zero, 1, PyInt_FromLong(0));
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "web3.version", zero);
|
||||
Py_DECREF(zero);
|
||||
|
||||
zero = PyFile_FromFile(stderr, "web3_input", "w", NULL);
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "web3.errors", zero);
|
||||
Py_DECREF(zero);
|
||||
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "web3.run_once", Py_False);
|
||||
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "web3.multithread", Py_False);
|
||||
if (uwsgi.numproc == 1) {
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "web3.multiprocess", Py_False);
|
||||
}
|
||||
else {
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "web3.multiprocess", Py_True);
|
||||
}
|
||||
|
||||
if (wsgi_req->scheme_len > 0) {
|
||||
zero = PyString_FromStringAndSize(wsgi_req->scheme, wsgi_req->scheme_len);
|
||||
}
|
||||
else if (wsgi_req->https_len > 0) {
|
||||
if (!strncasecmp(wsgi_req->https, "on", 2) || wsgi_req->https[0] == '1') {
|
||||
zero = PyString_FromString("https");
|
||||
}
|
||||
else {
|
||||
zero = PyString_FromString("http");
|
||||
}
|
||||
}
|
||||
else {
|
||||
zero = PyString_FromString("http");
|
||||
}
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "web3.url_scheme", zero);
|
||||
Py_DECREF(zero);
|
||||
|
||||
|
||||
wsgi_req->async_app = wi->wsgi_callable ;
|
||||
|
||||
PyDict_SetItemString(uwsgi.embedded_dict, "env", wsgi_req->async_environ);
|
||||
|
||||
// TODO: fix this
|
||||
//PyDict_SetItemString(wsgi_req->async_environ, "uwsgi.version", uwsgi_version);
|
||||
|
||||
|
||||
// call
|
||||
|
||||
PyTuple_SetItem(wsgi_req->async_args, 0, wsgi_req->async_environ);
|
||||
return python_call(wsgi_req->async_app, wsgi_req->async_args, uwsgi.catch_exceptions);
|
||||
}
|
||||
|
||||
|
||||
int uwsgi_response_subhandler_web3(struct wsgi_request *wsgi_req) {
|
||||
|
||||
PyObject *pychunk ;
|
||||
ssize_t wsize ;
|
||||
|
||||
// return or yield ? (PyString on python2 PyBytes on python3)
|
||||
if (PyString_Check((PyObject *)wsgi_req->async_result)) {
|
||||
if ((wsize = write(wsgi_req->poll.fd, PyString_AsString(wsgi_req->async_result), PyString_Size(wsgi_req->async_result))) < 0) {
|
||||
uwsgi_error("write()");
|
||||
goto clear;
|
||||
}
|
||||
wsgi_req->response_size += wsize;
|
||||
goto clear;
|
||||
}
|
||||
|
||||
|
||||
// ok its a yield
|
||||
if (!wsgi_req->async_placeholder) {
|
||||
if (PyTuple_Check((PyObject *)wsgi_req->async_result)) {
|
||||
if (PyTuple_Size((PyObject *)wsgi_req->async_result) != 3) {
|
||||
uwsgi_log("invalid Web3 response.\n");
|
||||
goto clear;
|
||||
}
|
||||
if (py_uwsgi_spit(NULL, (PyObject *)wsgi_req->async_result) == Py_None) {
|
||||
goto clear;
|
||||
}
|
||||
|
||||
wsgi_req->async_result = PyTuple_GetItem((PyObject *)wsgi_req->async_result, 0);
|
||||
|
||||
wsgi_req->async_placeholder = PyObject_GetIter( (PyObject *)wsgi_req->async_result );
|
||||
|
||||
if (!wsgi_req->async_placeholder) {
|
||||
goto clear2;
|
||||
}
|
||||
#ifdef UWSGI_ASYNC
|
||||
if (uwsgi.async > 1) {
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
}
|
||||
else {
|
||||
uwsgi_log("invalid Web3 response.\n");
|
||||
goto clear;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
pychunk = PyIter_Next(wsgi_req->async_placeholder) ;
|
||||
|
||||
if (!pychunk) {
|
||||
if (PyErr_Occurred()) PyErr_Print();
|
||||
goto clear;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (PyString_Check(pychunk)) {
|
||||
if ((wsize = write(wsgi_req->poll.fd, PyString_AsString(pychunk), PyString_Size(pychunk))) < 0) {
|
||||
uwsgi_error("write()");
|
||||
Py_DECREF(pychunk);
|
||||
goto clear;
|
||||
}
|
||||
wsgi_req->response_size += wsize;
|
||||
}
|
||||
|
||||
|
||||
Py_DECREF(pychunk);
|
||||
return UWSGI_AGAIN ;
|
||||
|
||||
clear:
|
||||
if (wsgi_req->async_environ) {
|
||||
PyDict_Clear(wsgi_req->async_environ);
|
||||
}
|
||||
if (wsgi_req->async_post && !wsgi_req->fd_closed) {
|
||||
fclose(wsgi_req->async_post);
|
||||
if (!uwsgi.post_buffering || wsgi_req->post_cl <= (size_t) uwsgi.post_buffering) {
|
||||
wsgi_req->fd_closed = 1 ;
|
||||
}
|
||||
}
|
||||
Py_XDECREF((PyObject *)wsgi_req->async_placeholder);
|
||||
clear2:
|
||||
Py_DECREF((PyObject *)wsgi_req->async_result);
|
||||
PyErr_Clear();
|
||||
|
||||
#ifdef UWSGI_DEBUG
|
||||
if (wsgi_req->async_placeholder) {
|
||||
uwsgi_debug("wsgi_req->async_placeholder: %d\n", ((PyObject *)wsgi_req->async_placeholder)->ob_refcnt);
|
||||
}
|
||||
if (wsgi_req->async_result) {
|
||||
uwsgi_debug("wsgi_req->async_result: %d\n", ((PyObject *)wsgi_req->async_result)->ob_refcnt);
|
||||
}
|
||||
if (wsgi_req->async_app) {
|
||||
uwsgi_debug("wsgi_req->async_app: %d\n", ((PyObject *)wsgi_req->async_app)->ob_refcnt);
|
||||
}
|
||||
#endif
|
||||
return UWSGI_OK;
|
||||
}
|
||||
|
||||
-413
@@ -1,413 +0,0 @@
|
||||
#include "uwsgi.h"
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
PyObject *py_uwsgi_write(PyObject * self, PyObject * args) {
|
||||
PyObject *data;
|
||||
char *content;
|
||||
int len;
|
||||
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
|
||||
data = PyTuple_GetItem(args, 0);
|
||||
if (PyString_Check(data)) {
|
||||
content = PyString_AsString(data);
|
||||
len = PyString_Size(data);
|
||||
UWSGI_RELEASE_GIL
|
||||
wsgi_req->response_size = write(wsgi_req->poll.fd, content, len);
|
||||
UWSGI_GET_GIL
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
#ifdef UWSGI_ASYNC
|
||||
|
||||
PyObject *py_eventfd_read(PyObject * self, PyObject * args) {
|
||||
int fd, timeout;
|
||||
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i|i", &fd, &timeout)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (fd >= 0) {
|
||||
wsgi_req->async_waiting_fd = fd ;
|
||||
wsgi_req->async_waiting_fd_type = ASYNC_IN ;
|
||||
wsgi_req->async_waiting_fd_monitored = 0 ;
|
||||
}
|
||||
|
||||
return PyString_FromString("") ;
|
||||
}
|
||||
|
||||
|
||||
PyObject *py_eventfd_write(PyObject * self, PyObject * args) {
|
||||
int fd, timeout;
|
||||
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i|i", &fd, &timeout)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (fd >= 0) {
|
||||
wsgi_req->async_waiting_fd = fd ;
|
||||
wsgi_req->async_waiting_fd_type = ASYNC_OUT ;
|
||||
wsgi_req->async_waiting_fd_monitored = 0 ;
|
||||
}
|
||||
|
||||
return PyString_FromString("") ;
|
||||
}
|
||||
#endif
|
||||
|
||||
int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) {
|
||||
|
||||
int i;
|
||||
|
||||
size_t post_remains = wsgi_req->post_cl;
|
||||
ssize_t post_chunk;
|
||||
|
||||
PyObject *pydictkey, *pydictvalue;
|
||||
|
||||
char *path_info;
|
||||
struct uwsgi_app *wi ;
|
||||
|
||||
int tmp_stderr;
|
||||
char *what;
|
||||
int what_len;
|
||||
|
||||
#ifdef UWSGI_ASYNC
|
||||
if (wsgi_req->async_status == UWSGI_AGAIN) {
|
||||
// get rid of timeout
|
||||
if (wsgi_req->async_timeout_expired) {
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "x-wsgiorg.fdevent.timeout", Py_True);
|
||||
wsgi_req->async_timeout_expired = 0 ;
|
||||
}
|
||||
else {
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "x-wsgiorg.fdevent.timeout", Py_None);
|
||||
}
|
||||
return manage_python_response(wsgi_req);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Standard WSGI request */
|
||||
if (!wsgi_req->uh.pktsize) {
|
||||
uwsgi_log( "Invalid WSGI request. skip.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (uwsgi_parse_vars(wsgi_req)) {
|
||||
uwsgi_log("Invalid WSGI request. skip.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (uwsgi.limit_post) {
|
||||
if (wsgi_req->post_cl > uwsgi.limit_post) {
|
||||
uwsgi_log("Invalid (too big) CONTENT_LENGTH. skip.\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!uwsgi.ignore_script_name) {
|
||||
|
||||
if (!wsgi_req->script_name)
|
||||
wsgi_req->script_name = "";
|
||||
|
||||
if (uwsgi.vhost) {
|
||||
what = uwsgi_concat3n(wsgi_req->host, wsgi_req->host_len, "|",1, wsgi_req->script_name, wsgi_req->script_name_len);
|
||||
what_len = wsgi_req->host_len + 1 + wsgi_req->script_name_len ;
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_debug("VirtualHost SCRIPT_NAME=%s\n", what);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
what = wsgi_req->script_name;
|
||||
what_len = wsgi_req->script_name_len ;
|
||||
}
|
||||
|
||||
|
||||
if ( (wsgi_req->app_id = uwsgi_get_app_id(what, what_len)) == -1) {
|
||||
if (wsgi_req->script_name_len > 1 || uwsgi.default_app < 0 || uwsgi.vhost) {
|
||||
/* unavailable app for this SCRIPT_NAME */
|
||||
wsgi_req->app_id = -1;
|
||||
if (wsgi_req->wsgi_script_len > 0
|
||||
|| wsgi_req->wsgi_module_len > 0
|
||||
|| wsgi_req->wsgi_file_len > 0
|
||||
#ifdef UWSGI_PASTE
|
||||
|| wsgi_req->wsgi_paste_len > 0
|
||||
#endif
|
||||
) {
|
||||
// a bit of magic: 1-1 = 0 / 0-1 = -1
|
||||
// this part must be heavy locked in threaded modes
|
||||
if (uwsgi.threads > 1) {
|
||||
pthread_mutex_lock(&uwsgi.lock_pyloaders);
|
||||
}
|
||||
UWSGI_GET_GIL
|
||||
wsgi_req->app_id = init_uwsgi_app(LOADER_DYN, (void *) wsgi_req, wsgi_req, uwsgi.single_interpreter-1);
|
||||
UWSGI_RELEASE_GIL
|
||||
if (uwsgi.threads > 1) {
|
||||
pthread_mutex_unlock(&uwsgi.lock_pyloaders);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (uwsgi.vhost) {
|
||||
free(what);
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
wsgi_req->app_id = 0;
|
||||
}
|
||||
|
||||
|
||||
if (wsgi_req->app_id == -1) {
|
||||
// use default app ?
|
||||
if (!uwsgi.no_default_app && uwsgi.default_app >= 0) {
|
||||
wsgi_req->app_id = uwsgi.default_app ;
|
||||
}
|
||||
else {
|
||||
internal_server_error(wsgi_req->poll.fd, "wsgi application not found");
|
||||
goto clear2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
wi = &uwsgi.apps[wsgi_req->app_id];
|
||||
|
||||
if (uwsgi.single_interpreter == 0 && wsgi_req->app_id > 0) {
|
||||
if (!wi->interpreter) {
|
||||
internal_server_error(wsgi_req->poll.fd, "wsgi application's %d interpreter not found");
|
||||
goto clear2;
|
||||
}
|
||||
|
||||
// set the interpreter
|
||||
UWSGI_GET_GIL
|
||||
if (uwsgi.threads > 1) {
|
||||
PyThreadState_Swap(uwsgi.workers[uwsgi.mywid].cores[wsgi_req->async_id]->ts[wsgi_req->app_id]);
|
||||
}
|
||||
else {
|
||||
PyThreadState_Swap(wi->interpreter);
|
||||
}
|
||||
UWSGI_RELEASE_GIL
|
||||
if (wi->chdir) {
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_debug("chdir to %s\n", wi->chdir);
|
||||
#endif
|
||||
if (chdir(wi->chdir)) {
|
||||
uwsgi_error("chdir()");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (wsgi_req->protocol_len < 5) {
|
||||
uwsgi_log( "INVALID PROTOCOL: %.*s\n", wsgi_req->protocol_len, wsgi_req->protocol);
|
||||
internal_server_error(wsgi_req->poll.fd, "invalid HTTP protocol !!!");
|
||||
goto clear;
|
||||
|
||||
}
|
||||
if (strncmp(wsgi_req->protocol, "HTTP/", 5)) {
|
||||
uwsgi_log( "INVALID PROTOCOL: %.*s\n", wsgi_req->protocol_len, wsgi_req->protocol);
|
||||
internal_server_error(wsgi_req->poll.fd, "invalid HTTP protocol !!!");
|
||||
goto clear;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef UWSGI_ASYNC
|
||||
wsgi_req->async_environ = wi->wsgi_environ[wsgi_req->async_id];
|
||||
wsgi_req->async_args = wi->wsgi_args[wsgi_req->async_id];
|
||||
#else
|
||||
wsgi_req->async_environ = wi->wsgi_environ;
|
||||
wsgi_req->async_args = wi->wsgi_args;
|
||||
#endif
|
||||
|
||||
UWSGI_GET_GIL
|
||||
|
||||
// no fear of race conditions for this counter as it is already protected by the GIL
|
||||
wi->requests++;
|
||||
|
||||
Py_INCREF((PyObject *)wsgi_req->async_environ);
|
||||
|
||||
for (i = 0; i < wsgi_req->var_cnt; i += 2) {
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_debug("%.*s: %.*s\n", wsgi_req->hvec[i].iov_len, wsgi_req->hvec[i].iov_base, wsgi_req->hvec[i+1].iov_len, wsgi_req->hvec[i+1].iov_base);
|
||||
#endif
|
||||
#ifdef PYTHREE
|
||||
pydictkey = PyUnicode_DecodeLatin1(wsgi_req->hvec[i].iov_base, wsgi_req->hvec[i].iov_len, "ignore");
|
||||
pydictvalue = PyUnicode_DecodeLatin1(wsgi_req->hvec[i + 1].iov_base, wsgi_req->hvec[i + 1].iov_len, "ignore");
|
||||
#else
|
||||
pydictkey = PyString_FromStringAndSize(wsgi_req->hvec[i].iov_base, wsgi_req->hvec[i].iov_len);
|
||||
pydictvalue = PyString_FromStringAndSize(wsgi_req->hvec[i + 1].iov_base, wsgi_req->hvec[i + 1].iov_len);
|
||||
#endif
|
||||
PyDict_SetItem(wsgi_req->async_environ, pydictkey, pydictvalue);
|
||||
Py_DECREF(pydictkey);
|
||||
Py_DECREF(pydictvalue);
|
||||
}
|
||||
|
||||
if (wsgi_req->uh.modifier1 == UWSGI_MODIFIER_MANAGE_PATH_INFO) {
|
||||
pydictkey = PyDict_GetItemString(wsgi_req->async_environ, "SCRIPT_NAME");
|
||||
if (pydictkey) {
|
||||
if (PyString_Check(pydictkey)) {
|
||||
pydictvalue = PyDict_GetItemString(wsgi_req->async_environ, "PATH_INFO");
|
||||
if (pydictvalue) {
|
||||
if (PyString_Check(pydictvalue)) {
|
||||
path_info = PyString_AsString(pydictvalue);
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "PATH_INFO", PyString_FromString(path_info + PyString_Size(pydictkey)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (uwsgi.post_buffering > 0 && wsgi_req->post_cl > (size_t) uwsgi.post_buffering) {
|
||||
UWSGI_RELEASE_GIL
|
||||
wsgi_req->async_post = tmpfile();
|
||||
if (!wsgi_req->async_post) {
|
||||
uwsgi_error("tmpfile()");
|
||||
goto clear;
|
||||
}
|
||||
|
||||
|
||||
while(post_remains > 0) {
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
|
||||
inc_harakiri(uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
}
|
||||
if (post_remains > (size_t) uwsgi.post_buffering_bufsize) {
|
||||
post_chunk = read(wsgi_req->poll.fd, wsgi_req->post_buffering_buf, uwsgi.post_buffering_bufsize);
|
||||
}
|
||||
else {
|
||||
post_chunk = read(wsgi_req->poll.fd, wsgi_req->post_buffering_buf, post_remains);
|
||||
}
|
||||
if (post_chunk < 0) {
|
||||
uwsgi_error("read()");
|
||||
goto clear;
|
||||
}
|
||||
if (!fwrite(wsgi_req->post_buffering_buf, post_chunk, 1, wsgi_req->async_post)) {
|
||||
uwsgi_error("fwrite()");
|
||||
goto clear;
|
||||
}
|
||||
post_remains -= post_chunk;
|
||||
}
|
||||
rewind(wsgi_req->async_post);
|
||||
UWSGI_GET_GIL
|
||||
}
|
||||
else {
|
||||
wsgi_req->async_post = fdopen(wsgi_req->poll.fd, "r");
|
||||
}
|
||||
|
||||
|
||||
wsgi_req->async_result = (*wi->request_subhandler)(wsgi_req, wi);
|
||||
|
||||
|
||||
if (wsgi_req->async_result) {
|
||||
|
||||
|
||||
UWSGI_RELEASE_GIL
|
||||
while ( (*wi->response_subhandler)(wsgi_req) != UWSGI_OK) {
|
||||
wsgi_req->switches++;
|
||||
#ifdef UWSGI_ASYNC
|
||||
if (uwsgi.async > 1) {
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
else if (uwsgi.catch_exceptions) {
|
||||
|
||||
// LOCK THIS PART
|
||||
|
||||
wsgi_req->response_size += write(wsgi_req->poll.fd, wsgi_req->protocol, wsgi_req->protocol_len);
|
||||
wsgi_req->response_size += write(wsgi_req->poll.fd, " 500 Internal Server Error\r\n", 28 );
|
||||
wsgi_req->response_size += write(wsgi_req->poll.fd, "Content-type: text/plain\r\n\r\n", 28 );
|
||||
wsgi_req->header_cnt = 1 ;
|
||||
|
||||
/*
|
||||
sorry that is a hack to avoid the rewrite of PyErr_Print
|
||||
temporarily map (using dup2) stderr to wsgi_req->poll.fd
|
||||
*/
|
||||
tmp_stderr = dup(2);
|
||||
if (tmp_stderr < 0) {
|
||||
uwsgi_error("dup()");
|
||||
goto clear;
|
||||
}
|
||||
// map 2 to wsgi_req
|
||||
if (dup2(wsgi_req->poll.fd, 2) < 0) {
|
||||
close(tmp_stderr);
|
||||
uwsgi_error("dup2()");
|
||||
goto clear;
|
||||
}
|
||||
// print the error
|
||||
PyErr_Print();
|
||||
// ...resume the original stderr, in case of error we are damaged forever !!!
|
||||
if (dup2(tmp_stderr, 2) < 0) {
|
||||
uwsgi_error("dup2()");
|
||||
}
|
||||
close(tmp_stderr);
|
||||
}
|
||||
|
||||
|
||||
clear:
|
||||
|
||||
UWSGI_GET_GIL
|
||||
|
||||
if (uwsgi.single_interpreter == 0 && wsgi_req->app_id > 0) {
|
||||
// restoring main interpreter
|
||||
if (uwsgi.threads > 1) {
|
||||
PyThreadState_Swap((PyThreadState *) pthread_getspecific(uwsgi.ut_save_key));
|
||||
}
|
||||
else {
|
||||
PyThreadState_Swap(uwsgi.main_thread);
|
||||
}
|
||||
}
|
||||
|
||||
UWSGI_RELEASE_GIL
|
||||
|
||||
clear2:
|
||||
|
||||
|
||||
return UWSGI_OK;
|
||||
|
||||
}
|
||||
|
||||
void uwsgi_after_request_wsgi(struct wsgi_request *wsgi_req) {
|
||||
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOGGING]) {
|
||||
log_request(wsgi_req);
|
||||
}
|
||||
else {
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOG_ZERO]) {
|
||||
if (wsgi_req->response_size == 0) { log_request(wsgi_req); return; }
|
||||
}
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOG_SLOW]) {
|
||||
if ((uint32_t) wsgi_req_time >= uwsgi.shared->options[UWSGI_OPTION_LOG_SLOW]) { log_request(wsgi_req); return; }
|
||||
}
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOG_4xx]) {
|
||||
if (wsgi_req->status >= 400 && wsgi_req->status <= 499) { log_request(wsgi_req); return; }
|
||||
}
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOG_5xx]) {
|
||||
if (wsgi_req->status >= 500 && wsgi_req->status <= 599) { log_request(wsgi_req); return; }
|
||||
}
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOG_BIG]) {
|
||||
if (wsgi_req->response_size >= uwsgi.shared->options[UWSGI_OPTION_LOG_BIG]) { log_request(wsgi_req); return; }
|
||||
}
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOG_SENDFILE]) {
|
||||
if (wsgi_req->sendfile_fd > -1 && wsgi_req->sendfile_obj == wsgi_req->async_result) { log_request(wsgi_req); return; }
|
||||
}
|
||||
}
|
||||
}
|
||||
-160
@@ -1,160 +0,0 @@
|
||||
#include "uwsgi.h"
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
static char *nl = "\r\n";
|
||||
static char *h_sep = ": ";
|
||||
static const char *http_protocol = "HTTP/1.1";
|
||||
|
||||
// check here
|
||||
|
||||
PyObject *py_uwsgi_spit(PyObject * self, PyObject * args) {
|
||||
PyObject *headers, *head;
|
||||
PyObject *h_key, *h_value;
|
||||
int i, j;
|
||||
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
|
||||
int base = 0;
|
||||
int shift = 0;
|
||||
|
||||
// use writev()
|
||||
|
||||
// is a Web3 response ?
|
||||
/*
|
||||
if (PyTuple_Size(args) == 3) {
|
||||
shift = 0;
|
||||
}
|
||||
*/
|
||||
|
||||
head = PyTuple_GetItem(args, 0+shift);
|
||||
if (!head) {
|
||||
goto clear;
|
||||
}
|
||||
|
||||
if (!PyString_Check(head)) {
|
||||
uwsgi_log( "http status must be a string !\n");
|
||||
goto clear;
|
||||
}
|
||||
|
||||
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_CGI_MODE] == 0) {
|
||||
base = 4;
|
||||
|
||||
if (wsgi_req->protocol_len == 0) {
|
||||
wsgi_req->hvec[0].iov_base = (char *) http_protocol;
|
||||
wsgi_req->protocol_len = 8;
|
||||
}
|
||||
else {
|
||||
wsgi_req->hvec[0].iov_base = wsgi_req->protocol;
|
||||
}
|
||||
|
||||
wsgi_req->hvec[0].iov_len = wsgi_req->protocol_len;
|
||||
wsgi_req->hvec[1].iov_base = " ";
|
||||
wsgi_req->hvec[1].iov_len = 1;
|
||||
#ifdef PYTHREE
|
||||
wsgi_req->hvec[2].iov_base = PyBytes_AsString(PyUnicode_AsASCIIString(head));
|
||||
wsgi_req->hvec[2].iov_len = strlen(wsgi_req->hvec[2].iov_base);
|
||||
#else
|
||||
wsgi_req->hvec[2].iov_base = PyString_AsString(head);
|
||||
wsgi_req->hvec[2].iov_len = PyString_Size(head);
|
||||
#endif
|
||||
wsgi_req->status = atoi(wsgi_req->hvec[2].iov_base);
|
||||
wsgi_req->hvec[3].iov_base = nl;
|
||||
wsgi_req->hvec[3].iov_len = NL_SIZE;
|
||||
}
|
||||
else {
|
||||
// drop http status on cgi mode
|
||||
base = 3;
|
||||
wsgi_req->hvec[0].iov_base = "Status: ";
|
||||
wsgi_req->hvec[0].iov_len = 8;
|
||||
#ifdef PYTHREE
|
||||
wsgi_req->hvec[1].iov_base = PyBytes_AsString(PyUnicode_AsASCIIString(head));
|
||||
wsgi_req->hvec[1].iov_len = strlen(wsgi_req->hvec[1].iov_base);
|
||||
#else
|
||||
wsgi_req->hvec[1].iov_base = PyString_AsString(head);
|
||||
wsgi_req->hvec[1].iov_len = PyString_Size(head);
|
||||
#endif
|
||||
wsgi_req->status = atoi(wsgi_req->hvec[1].iov_base);
|
||||
wsgi_req->hvec[2].iov_base = nl;
|
||||
wsgi_req->hvec[2].iov_len = NL_SIZE;
|
||||
}
|
||||
|
||||
|
||||
headers = PyTuple_GetItem(args, 1+shift);
|
||||
if (!headers) {
|
||||
goto clear;
|
||||
}
|
||||
if (!PyList_Check(headers)) {
|
||||
uwsgi_log( "http headers must be in a python list\n");
|
||||
goto clear;
|
||||
}
|
||||
wsgi_req->header_cnt = PyList_Size(headers);
|
||||
|
||||
|
||||
|
||||
if (wsgi_req->header_cnt > uwsgi.max_vars) {
|
||||
wsgi_req->header_cnt = uwsgi.max_vars;
|
||||
}
|
||||
for (i = 0; i < wsgi_req->header_cnt; i++) {
|
||||
j = (i * 4) + base;
|
||||
head = PyList_GetItem(headers, i);
|
||||
if (!head) {
|
||||
goto clear;
|
||||
}
|
||||
if (!PyTuple_Check(head)) {
|
||||
uwsgi_log( "http header must be defined in a tuple !\n");
|
||||
goto clear;
|
||||
}
|
||||
h_key = PyTuple_GetItem(head, 0);
|
||||
if (!h_key) {
|
||||
goto clear;
|
||||
}
|
||||
h_value = PyTuple_GetItem(head, 1);
|
||||
if (!h_value) {
|
||||
goto clear;
|
||||
}
|
||||
#ifdef PYTHREE
|
||||
wsgi_req->hvec[j].iov_base = PyBytes_AsString(PyUnicode_AsASCIIString(h_key));
|
||||
wsgi_req->hvec[j].iov_len = strlen(wsgi_req->hvec[j].iov_base);
|
||||
#else
|
||||
wsgi_req->hvec[j].iov_base = PyString_AsString(h_key);
|
||||
wsgi_req->hvec[j].iov_len = PyString_Size(h_key);
|
||||
#endif
|
||||
wsgi_req->hvec[j + 1].iov_base = h_sep;
|
||||
wsgi_req->hvec[j + 1].iov_len = H_SEP_SIZE;
|
||||
#ifdef PYTHREE
|
||||
wsgi_req->hvec[j + 2].iov_base = PyBytes_AsString(PyUnicode_AsASCIIString(h_value));
|
||||
wsgi_req->hvec[j + 2].iov_len = strlen(wsgi_req->hvec[j + 2].iov_base);
|
||||
#else
|
||||
wsgi_req->hvec[j + 2].iov_base = PyString_AsString(h_value);
|
||||
wsgi_req->hvec[j + 2].iov_len = PyString_Size(h_value);
|
||||
#endif
|
||||
wsgi_req->hvec[j + 3].iov_base = nl;
|
||||
wsgi_req->hvec[j + 3].iov_len = NL_SIZE;
|
||||
//uwsgi_log( "%.*s: %.*s\n", wsgi_req->hvec[j].iov_len, (char *)wsgi_req->hvec[j].iov_base, wsgi_req->hvec[j+2].iov_len, (char *) wsgi_req->hvec[j+2].iov_base);
|
||||
}
|
||||
|
||||
|
||||
// \r\n
|
||||
j = (i * 4) + base;
|
||||
wsgi_req->hvec[j].iov_base = nl;
|
||||
wsgi_req->hvec[j].iov_len = NL_SIZE;
|
||||
|
||||
UWSGI_RELEASE_GIL
|
||||
wsgi_req->headers_size = writev(wsgi_req->poll.fd, wsgi_req->hvec, j + 1);
|
||||
UWSGI_GET_GIL
|
||||
if (wsgi_req->headers_size < 0) {
|
||||
uwsgi_error("writev()");
|
||||
}
|
||||
|
||||
Py_INCREF(uwsgi.wsgi_writeout);
|
||||
|
||||
|
||||
return uwsgi.wsgi_writeout;
|
||||
|
||||
clear:
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
@@ -1,215 +0,0 @@
|
||||
#include "uwsgi.h"
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
void *uwsgi_request_subhandler_wsgi(struct wsgi_request *wsgi_req, struct uwsgi_app *wi) {
|
||||
|
||||
PyObject *wsgi_socket, *zero;
|
||||
|
||||
static PyObject *uwsgi_version = NULL;
|
||||
|
||||
if (uwsgi_version == NULL) {
|
||||
uwsgi_version = PyString_FromString(UWSGI_VERSION);
|
||||
}
|
||||
|
||||
|
||||
wsgi_socket = PyFile_FromFile(wsgi_req->async_post, "wsgi_input", "r", NULL);
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "wsgi.input", wsgi_socket);
|
||||
Py_DECREF(wsgi_socket);
|
||||
|
||||
#ifdef UWSGI_SENDFILE
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "wsgi.file_wrapper", wi->wsgi_sendfile);
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_ASYNC
|
||||
if (uwsgi.async > 1) {
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "x-wsgiorg.fdevent.readable", wi->wsgi_eventfd_read);
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "x-wsgiorg.fdevent.writable", wi->wsgi_eventfd_write);
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "x-wsgiorg.fdevent.timeout", Py_None);
|
||||
}
|
||||
#endif
|
||||
|
||||
zero = PyTuple_New(2);
|
||||
PyTuple_SetItem(zero, 0, PyInt_FromLong(1));
|
||||
PyTuple_SetItem(zero, 1, PyInt_FromLong(0));
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "wsgi.version", zero);
|
||||
Py_DECREF(zero);
|
||||
|
||||
zero = PyFile_FromFile(stderr, "wsgi_input", "w", NULL);
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "wsgi.errors", zero);
|
||||
Py_DECREF(zero);
|
||||
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "wsgi.run_once", Py_False);
|
||||
|
||||
if (uwsgi.threads > 1) {
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "wsgi.multithread", Py_True);
|
||||
}
|
||||
else {
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "wsgi.multithread", Py_False);
|
||||
}
|
||||
if (uwsgi.numproc == 1) {
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "wsgi.multiprocess", Py_False);
|
||||
}
|
||||
else {
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "wsgi.multiprocess", Py_True);
|
||||
}
|
||||
|
||||
if (wsgi_req->scheme_len > 0) {
|
||||
zero = PyString_FromStringAndSize(wsgi_req->scheme, wsgi_req->scheme_len);
|
||||
}
|
||||
else if (wsgi_req->https_len > 0) {
|
||||
if (!strncasecmp(wsgi_req->https, "on", 2) || wsgi_req->https[0] == '1') {
|
||||
zero = PyString_FromString("https");
|
||||
}
|
||||
else {
|
||||
zero = PyString_FromString("http");
|
||||
}
|
||||
}
|
||||
else {
|
||||
zero = PyString_FromString("http");
|
||||
}
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "wsgi.url_scheme", zero);
|
||||
Py_DECREF(zero);
|
||||
|
||||
|
||||
wsgi_req->async_app = wi->wsgi_callable ;
|
||||
|
||||
//PyDict_SetItemString(uwsgi.embedded_dict, "env", wsgi_req->async_environ);
|
||||
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "uwsgi.version", uwsgi_version);
|
||||
|
||||
|
||||
#ifdef UWSGI_ROUTING
|
||||
uwsgi_log("routing %d routes %d\n", uwsgi.routing, uwsgi.nroutes);
|
||||
if (uwsgi.routing && uwsgi.nroutes > 0) {
|
||||
check_route(uwsgi, wsgi_req);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// call
|
||||
|
||||
|
||||
PyTuple_SetItem(wsgi_req->async_args, 0, wsgi_req->async_environ);
|
||||
return python_call(wsgi_req->async_app, wsgi_req->async_args, uwsgi.catch_exceptions);
|
||||
}
|
||||
|
||||
int uwsgi_response_subhandler_wsgi(struct wsgi_request *wsgi_req) {
|
||||
|
||||
PyObject *pychunk ;
|
||||
ssize_t wsize ;
|
||||
#ifdef UWSGI_SENDFILE
|
||||
ssize_t sf_len = 0 ;
|
||||
#endif
|
||||
|
||||
UWSGI_GET_GIL
|
||||
|
||||
// return or yield ?
|
||||
if (PyString_Check((PyObject *)wsgi_req->async_result)) {
|
||||
if ((wsize = write(wsgi_req->poll.fd, PyString_AsString(wsgi_req->async_result), PyString_Size(wsgi_req->async_result))) < 0) {
|
||||
uwsgi_error("write()");
|
||||
goto clear;
|
||||
}
|
||||
wsgi_req->response_size += wsize;
|
||||
goto clear;
|
||||
}
|
||||
|
||||
#ifdef UWSGI_SENDFILE
|
||||
if (wsgi_req->sendfile_obj == wsgi_req->async_result && wsgi_req->sendfile_fd != -1) {
|
||||
sf_len = uwsgi_sendfile(wsgi_req);
|
||||
if (sf_len < 1) goto clear;
|
||||
wsgi_req->response_size += sf_len ;
|
||||
#ifdef UWSGI_ASYNC
|
||||
if (uwsgi.async > 1) {
|
||||
if (wsgi_req->response_size < wsgi_req->sendfile_fd_size) {
|
||||
UWSGI_RELEASE_GIL
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
goto clear;
|
||||
}
|
||||
#endif
|
||||
|
||||
// ok its a yield
|
||||
if (!wsgi_req->async_placeholder) {
|
||||
wsgi_req->async_placeholder = PyObject_GetIter(wsgi_req->async_result);
|
||||
if (!wsgi_req->async_placeholder) {
|
||||
goto clear2;
|
||||
}
|
||||
#ifdef UWSGI_ASYNC
|
||||
if (uwsgi.async > 1) {
|
||||
UWSGI_RELEASE_GIL
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
pychunk = PyIter_Next(wsgi_req->async_placeholder) ;
|
||||
|
||||
if (!pychunk) {
|
||||
if (PyErr_Occurred()) PyErr_Print();
|
||||
goto clear;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (PyString_Check(pychunk)) {
|
||||
if ((wsize = write(wsgi_req->poll.fd, PyString_AsString(pychunk), PyString_Size(pychunk))) < 0) {
|
||||
uwsgi_error("write()");
|
||||
Py_DECREF(pychunk);
|
||||
goto clear;
|
||||
}
|
||||
wsgi_req->response_size += wsize;
|
||||
}
|
||||
|
||||
#ifdef UWSGI_SENDFILE
|
||||
else if (wsgi_req->sendfile_obj == pychunk && wsgi_req->sendfile_fd != -1) {
|
||||
sf_len = uwsgi_sendfile(wsgi_req);
|
||||
if (sf_len < 1) goto clear;
|
||||
wsgi_req->response_size += sf_len ;
|
||||
}
|
||||
#endif
|
||||
|
||||
Py_DECREF(pychunk);
|
||||
UWSGI_RELEASE_GIL
|
||||
return UWSGI_AGAIN ;
|
||||
|
||||
clear:
|
||||
if (wsgi_req->sendfile_fd != -1) {
|
||||
Py_DECREF((PyObject *)wsgi_req->async_sendfile);
|
||||
}
|
||||
if (wsgi_req->async_environ) {
|
||||
PyDict_Clear(wsgi_req->async_environ);
|
||||
}
|
||||
if (wsgi_req->async_post && !wsgi_req->fd_closed) {
|
||||
fclose(wsgi_req->async_post);
|
||||
if (!uwsgi.post_buffering || wsgi_req->post_cl <= (size_t) uwsgi.post_buffering) {
|
||||
wsgi_req->fd_closed = 1 ;
|
||||
|
||||
}
|
||||
}
|
||||
Py_XDECREF((PyObject *)wsgi_req->async_placeholder);
|
||||
clear2:
|
||||
Py_DECREF((PyObject *)wsgi_req->async_result);
|
||||
PyErr_Clear();
|
||||
|
||||
#ifdef UWSGI_DEBUG
|
||||
if (wsgi_req->async_placeholder) {
|
||||
uwsgi_debug("wsgi_req->async_placeholder: %d\n", ((PyObject *)wsgi_req->async_placeholder)->ob_refcnt);
|
||||
}
|
||||
if (wsgi_req->async_result) {
|
||||
uwsgi_debug("wsgi_req->async_result: %d\n", ((PyObject *)wsgi_req->async_result)->ob_refcnt);
|
||||
}
|
||||
if (wsgi_req->async_app) {
|
||||
uwsgi_debug("wsgi_req->async_app: %d\n", ((PyObject *)wsgi_req->async_app)->ob_refcnt);
|
||||
}
|
||||
#endif
|
||||
|
||||
UWSGI_RELEASE_GIL
|
||||
return UWSGI_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -181,10 +181,12 @@ next:
|
||||
|
||||
}
|
||||
else if (!strcmp((char *) node2->name, "callable")) {
|
||||
/*
|
||||
if (!uwsgi.pyloader_dict) {
|
||||
uwsgi_log( "no module loaded in memory. skip.\n");
|
||||
continue;
|
||||
}
|
||||
*/
|
||||
if (!node2->children) {
|
||||
uwsgi_log( "no callable defined. skip.\n");
|
||||
continue;
|
||||
@@ -194,7 +196,7 @@ next:
|
||||
continue;
|
||||
}
|
||||
|
||||
init_uwsgi_app(LOADER_STRING_CALLABLE, (void *) node2->children->content, wsgi_req, uwsgi.single_interpreter-1);
|
||||
//init_uwsgi_app(LOADER_STRING_CALLABLE, (void *) node2->children->content, wsgi_req, uwsgi.single_interpreter-1);
|
||||
}
|
||||
else if (!strcmp((char *) node2->name, "eval")) {
|
||||
if (!node2->children) {
|
||||
@@ -206,7 +208,7 @@ next:
|
||||
continue;
|
||||
}
|
||||
|
||||
init_uwsgi_app(LOADER_EVAL, (void *) node2->children->content, wsgi_req, uwsgi.single_interpreter-1);
|
||||
//init_uwsgi_app(LOADER_EVAL, (void *) node2->children->content, wsgi_req, uwsgi.single_interpreter-1);
|
||||
|
||||
}
|
||||
else if (!strcmp((char *) node2->name, "file")) {
|
||||
@@ -219,7 +221,7 @@ next:
|
||||
continue;
|
||||
}
|
||||
|
||||
init_uwsgi_app(LOADER_FILE, (void *) node2->children->content, wsgi_req, uwsgi.single_interpreter-1);
|
||||
//init_uwsgi_app(LOADER_FILE, (void *) node2->children->content, wsgi_req, uwsgi.single_interpreter-1);
|
||||
|
||||
}
|
||||
else if (!strcmp((char *) node2->name, "module")) {
|
||||
@@ -232,7 +234,7 @@ next:
|
||||
continue;
|
||||
}
|
||||
|
||||
init_uwsgi_app(LOADER_UWSGI, (void *) node2->children->content, wsgi_req, uwsgi.single_interpreter-1);
|
||||
//init_uwsgi_app(LOADER_UWSGI, (void *) node2->children->content, wsgi_req, uwsgi.single_interpreter-1);
|
||||
}
|
||||
else if (!strcmp((char *) node2->name, "script")) {
|
||||
if (!node2->children) {
|
||||
@@ -243,7 +245,7 @@ next:
|
||||
uwsgi_log( "no script defined. skip.\n");
|
||||
continue;
|
||||
}
|
||||
init_uwsgi_app(LOADER_UWSGI, (void *) node2->children->content, wsgi_req, uwsgi.single_interpreter-1);
|
||||
//init_uwsgi_app(LOADER_UWSGI, (void *) node2->children->content, wsgi_req, uwsgi.single_interpreter-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -378,7 +380,7 @@ void uwsgi_textApp(void *userData, const char *s, int len) {
|
||||
if (current_xmlnode) {
|
||||
wsgi_req->wsgi_script = (char *) s;
|
||||
wsgi_req->wsgi_script_len = len;
|
||||
init_uwsgi_app(&uwsgi, NULL);
|
||||
//init_uwsgi_app(&uwsgi, NULL);
|
||||
current_xmlnode = 0;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user