-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathngx_process.c
93 lines (76 loc) · 1.41 KB
/
ngx_process.c
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
/*
* ngx_process.c
*
* Author: Gandalf
* email: [email protected]
*/
#include "ngx_str.h"
int parse_command(const char *key, char *cmd, size_t cmd_max_len, char *param, size_t param_max_len)
{
const char *pl, *pr;
size_t sz;
for (pl = key; 0 == is_key_char(*pl); pl++)
;
if (pl == key)
return 0;
if (NULL != cmd)
{
if (cmd_max_len <= (sz = (size_t)(pl - key)))
return 0;
memcpy(cmd, key, sz);
cmd[sz] = '\0';
}
if ('\0' == *pl) /* no parameters specified */
{
if (NULL != param)
*param = '\0';
return 1;
}
if ('[' != *pl) /* unsupported character */
return 0;
for (pr = ++pl; '\0' != *pr; pr++)
;
if (']' != *--pr)
return 0;
if (NULL != param)
{
if (param_max_len <= (sz = (size_t)(pr - pl)))
return 0;
memcpy(param, pl, sz);
param[sz] = '\0';
}
return 2;
}
int is_key_char(char c)
{
if (0 != isalnum(c))
return 0;
if (c == '.' || c == '_' || c == '-')
return 0;
return -1;
}
int ngxexecute_fork()
{
fflush(stdout);
fflush(stderr);
return fork();
}
void urldecode(char *dest, const char *src)
{
const char *p = src;
char code[3] = {0};
unsigned long ascii = 0;
char *end = NULL;
while(*p)
{
if(*p == '%')
{
memcpy(code, ++p, 2);
ascii = strtoul(code, &end, 16);
*dest++ = (char)ascii;
p += 2;
}
else
*dest++ = *p++;
}
}