-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphp_script.cpp
More file actions
120 lines (92 loc) · 3.12 KB
/
php_script.cpp
File metadata and controls
120 lines (92 loc) · 3.12 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
$Author = Sargis Ananyan;
$Corp = RedM Inc;
$Web = https://redm.pro/;
$Lincese = BSD 3;
$Name = mLang;
$Description = A programming language for web programming.;
*/
#define _FILE_OFFSET_BITS 64
#include "php_script.h"
#include <map>
#include <string>
#include <cassert>
#include "dl-utils-lite.h"
std::map <std::string, script_t *> scripts;
script_t *get_script (const char *name) {
std::map <std::string, script_t *>::iterator i = scripts.find (name);
if (i != scripts.end()) {
return i->second;
}
return NULL;
}
void set_script (const char *name, void (*run)(php_query_data *, void *mem, size_t mem_size), void (*clear) (void)) {
static int cnt = 0;
script_t *script = new script_t;
script->run = run;
script->clear = clear;
assert (scripts.insert (std::pair <std::string, script_t *> (name, script)).second);
assert (scripts.insert (std::pair <std::string, script_t *> (std::string ("#") + dl_int_to_str (cnt++), script)).second);
}
http_query_data *http_query_data_create (const char *qUri, int qUriLen, const char *qGet, int qGetLen, const char *qHeaders,
int qHeadersLen, const char *qPost, int qPostLen, const char *request_method, int keep_alive, unsigned int ip, unsigned int port) {
http_query_data *d = (http_query_data *)dl_malloc (sizeof (http_query_data));
//TODO remove memdup completely. We can just copy pointers
d->uri = (char *)dl_memdup (qUri, qUriLen);
d->get = (char *)dl_memdup (qGet, qGetLen);
d->headers = (char *)dl_memdup (qHeaders, qHeadersLen);
if (qPost != NULL) {
d->post = (char *)dl_memdup (qPost, qPostLen);
} else {
d->post = NULL;
}
d->uri_len = qUriLen;
d->get_len = qGetLen;
d->headers_len = qHeadersLen;
d->post_len = qPostLen;
d->request_method = (char *)dl_memdup (request_method, strlen (request_method));
d->request_method_len = (int)strlen (request_method);
d->keep_alive = keep_alive;
d->ip = ip;
d->port = port;
return d;
}
void http_query_data_free (http_query_data *d) {
if (d == NULL) {
return;
}
dl_free (d->uri, d->uri_len);
dl_free (d->get, d->get_len);
dl_free (d->headers, d->headers_len);
dl_free (d->post, d->post_len);
dl_free (d, sizeof (http_query_data));
}
rpc_query_data *rpc_query_data_create (int *data, int len, long long req_id, unsigned int ip, short port, short pid, int utime) {
rpc_query_data *d = (rpc_query_data *)dl_malloc (sizeof (rpc_query_data));
d->data = (int *)dl_memdup (data, sizeof (int) * len);
d->len = len;
d->req_id = req_id;
d->ip = ip;
d->port = port;
d->pid = pid;
d->utime = utime;
return d;
}
void rpc_query_data_free (rpc_query_data *d) {
if (d == NULL) {
return;
}
dl_free (d->data, d->len * sizeof (int));
dl_free (d, sizeof (rpc_query_data));
}
php_query_data *php_query_data_create (http_query_data *http_data, rpc_query_data *rpc_data) {
php_query_data *d = (php_query_data *)dl_malloc (sizeof (php_query_data));
d->http_data = http_data;
d->rpc_data = rpc_data;
return d;
}
void php_query_data_free (php_query_data *d) {
http_query_data_free (d->http_data);
rpc_query_data_free (d->rpc_data);
dl_free (d, sizeof (php_query_data));
}