File: base.cc

package info (click to toggle)
uwsgi 2.0.31-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,564 kB
  • sloc: ansic: 87,066; python: 7,004; cpp: 1,133; java: 708; perl: 678; sh: 585; ruby: 555; makefile: 148; xml: 130; cs: 121; objc: 37; php: 28; erlang: 20; javascript: 11
file content (65 lines) | stat: -rw-r--r-- 1,365 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#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) {

	uwsgi_response_prepare_headers(wsgi_req, (char *)"200 OK", 6);
	uwsgi_response_add_content_type(wsgi_req, (char *)"text/html", 9);
	uwsgi_response_write_body_do(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", 9, &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) {
	// call log_request(wsgi_req) if you want a standard logline
        uwsgi_log("logging c++ request\n");
}