diff --git a/plugins/cplusplus/base.cc b/plugins/cplusplus/base.cc new file mode 100644 index 00000000..21fc6bb3 --- /dev/null +++ b/plugins/cplusplus/base.cc @@ -0,0 +1,63 @@ +#include "../../uwsgi.h" + +extern struct uwsgi_server uwsgi; + +class FakeClass { + + public: + char *foobar; + uint16_t foobar_len; + void hello_world(struct wsgi_request *); + +}; + +void FakeClass::hello_world(struct wsgi_request *wsgi_req) { + + wsgi_req->response_size += wsgi_req->socket->proto_write(wsgi_req, (char *) "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n", 44); + wsgi_req->response_size += wsgi_req->socket->proto_write(wsgi_req, foobar, foobar_len); +} + +extern "C" int uwsgi_cplusplus_init(){ + uwsgi_log("Initializing example c++ plugin\n"); + return 0; +} + +extern "C" int uwsgi_cplusplus_request(struct wsgi_request *wsgi_req) { + + FakeClass *fc; + + // empty request ? + if (!wsgi_req->uh.pktsize) { + uwsgi_log( "Invalid request. skip.\n"); + goto clear; + } + + // get uwsgi variables + if (uwsgi_parse_vars(wsgi_req)) { + uwsgi_log("Invalid request. skip.\n"); + goto clear; + } + + fc = new FakeClass(); + // get PATH_INFO + fc->foobar = uwsgi_get_var(wsgi_req, (char *) "PATH_INFO", &fc->foobar_len); + + if (fc->foobar) { + // send output + fc->hello_world(wsgi_req); + } + + delete fc; + +clear: + return UWSGI_OK; +} + + +extern "C" void uwsgi_cplusplus_after_request(struct wsgi_request *wsgi_req) { + uwsgi_log("logging c++ request\n"); +} + + + + diff --git a/plugins/cplusplus/plugin.c b/plugins/cplusplus/plugin.c new file mode 100644 index 00000000..b80c835c --- /dev/null +++ b/plugins/cplusplus/plugin.c @@ -0,0 +1,17 @@ +#include "../../uwsgi.h" + + +int uwsgi_cplusplus_init(void); +int uwsgi_cplusplus_request(struct wsgi_request *); +void uwsgi_cplusplus_after_request(struct wsgi_request *); + +struct uwsgi_plugin cplusplus_plugin = { + + .name = "cplusplus", + .modifier1 = 250, + .init = uwsgi_cplusplus_init, + .request = uwsgi_cplusplus_request, + .after_request = uwsgi_cplusplus_after_request, + +}; + diff --git a/plugins/cplusplus/uwsgiplugin.py b/plugins/cplusplus/uwsgiplugin.py new file mode 100644 index 00000000..07548c63 --- /dev/null +++ b/plugins/cplusplus/uwsgiplugin.py @@ -0,0 +1,6 @@ +NAME='cplusplus' + +CFLAGS = [] +LDFLAGS = [] +LIBS = ['-lstdc++'] +GCC_LIST = ['base.cc', 'plugin'] diff --git a/plugins/example/example_plugin.c b/plugins/example/example_plugin.c index 728afd0d..37378e3b 100644 --- a/plugins/example/example_plugin.c +++ b/plugins/example/example_plugin.c @@ -2,21 +2,33 @@ extern struct uwsgi_server uwsgi; -int uwsgi_init(char *args){ - uwsgi_log("i am the example plugin initialization function with arg: %s\n", args); +int uwsgi_example_init(){ + uwsgi_log("i am the example plugin initialization function\n"); return 0; } -int uwsgi_request(struct wsgi_request *wsgi_req) { +int uwsgi_example_request(struct wsgi_request *wsgi_req) { char *http = "HTTP/1.1 200 Ok\r\nContent-type: text/html\r\n\r\n