-
Notifications
You must be signed in to change notification settings - Fork 0
/
php5activescript.c
276 lines (234 loc) · 7.82 KB
/
php5activescript.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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2004 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_0.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Wez Furlong <wez@thebrainroom.com> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#include "php.h"
#include "php_main.h"
#include "SAPI.h"
#include "php_globals.h"
#include "ext/standard/info.h"
#include "php_variables.h"
#include "php_ini.h"
#include "php5activescript.h"
/* SAPI definitions and DllMain */
static int php_activescript_startup(sapi_module_struct *sapi_module)
{
if (php_module_startup(sapi_module, &php_activescript_module, 1) == FAILURE) {
return FAILURE;
} else {
return SUCCESS;
}
}
static int sapi_activescript_ub_write(const char *str, uint str_length TSRMLS_DC)
{
/* In theory, this is a blackhole. In practice, I want to see the output
* in the debugger! */
#if ZEND_DEBUG
char buf[1024];
uint l, a = str_length;
while(a) {
l = a;
if (l > sizeof(buf) - 1)
l = sizeof(buf) - 1;
memcpy(buf, str, l);
buf[l] = 0;
OutputDebugString(buf);
a -= l;
}
#endif
return str_length;
}
static void init_request_info( TSRMLS_D)
{
/*
sapi_cgibin_putenv("PATH_INFO", "d:\\noname2.php" TSRMLS_CC);
// Build the special-case PHP_SELF variable for the CLI version //
sapi_cgibin_putenv("PHP_SELF", "d:\\noname2.php" TSRMLS_CC);
sapi_cgibin_putenv("SCRIPT_NAME", "d:\\noname2.php" TSRMLS_CC);
// filenames are empty for stdin //
sapi_cgibin_putenv("SCRIPT_FILENAME", "d:\\noname2.php" TSRMLS_CC);
sapi_cgibin_putenv("PATH_TRANSLATED", "d:\\noname2.php" TSRMLS_CC);
// just make it available //
//sapi_cgibin_putenv("DOCUMENT_ROOT", "", TSRMLS_CC);
sapi_cgibin_putenv("LOCAL_ADDR", "127.0.0.1" TSRMLS_CC);
sapi_cgibin_putenv("REMOTE_ADDR", "127.0.0.1" TSRMLS_CC);
sapi_cgibin_putenv("REMOTE_HOST", "127.0.0.1" TSRMLS_CC);
sapi_cgibin_putenv("HTTP_X_REWRITE_URL", "d:\\noname2.php?DBGSESSID=1@clienthost%3A7869%3Bd%3D1%2Cp%3D1&" TSRMLS_CC);
sapi_cgibin_putenv("QUERY_STRING","DBGSESSID=1@clienthost%3A7869%3Bd%3D1%2Cp%3D1&" TSRMLS_CC);
sapi_cgibin_putenv("HTTP_COOKIE", "DBGSESSID=1@clienthost:7869" TSRMLS_CC);
*/
}
static void sapi_activescript_register_server_variables(zval *track_vars_array TSRMLS_DC)
{
/*
// char *env_path_info = "d:\\noname203.php";
// env_path_info = sapi_cgibin_putenv("PATH_INFO", env_path_info TSRMLS_CC);
init_request_info( TSRMLS_C);
php_import_environment_variables(track_vars_array TSRMLS_CC);
// init_request_info(TSRMLS_C);
// Build the special-case PHP_SELF variable for the CLI version //
php_register_variable("PHP_SELF", "d:\\noname1.php", track_vars_array TSRMLS_CC);
php_register_variable("SCRIPT_NAME", "d:\\noname1.php", track_vars_array TSRMLS_CC);
// filenames are empty for stdin //
php_register_variable("SCRIPT_FILENAME", "d:\\noname1.php", track_vars_array TSRMLS_CC);
php_register_variable("PATH_TRANSLATED", "d:\\noname1.php", track_vars_array TSRMLS_CC);
// just make it available //
php_register_variable("DOCUMENT_ROOT", "", track_vars_array TSRMLS_CC);
php_register_variable("QUERY_STRING","DBGSESSID=1@clienthost%3A7869%3Bd%3D1%2Cp%3D1&", track_vars_array TSRMLS_CC);
// php_register_variable_safe("PHP_SELF", "2222", 5, track_vars_array TSRMLS_CC);
*/
return ;
}
static char *sapi_activescript_read_cookies(TSRMLS_D)
{
//return "DBGSESSID=1@clienthost:7869";
return NULL;
}
static int sapi_activescript_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC)
{
return SAPI_HEADER_ADD;
}
static int sapi_activescript_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
{
return SAPI_HEADER_SENT_SUCCESSFULLY;
}
static char *sapi_cgibin_getenv(char *name, size_t name_len TSRMLS_DC)
{ /* if cgi, or fastcgi and not found in fcgi env
check the regular environment */
return getenv(name);
}
static char *sapi_cgibin_putenv(char *name, char *value TSRMLS_DC)
{
int name_len;
#if !HAVE_SETENV || !HAVE_UNSETENV
int len;
char *buf;
#endif
if (!name) {
return NULL;
}
name_len = strlen(name);
#if HAVE_SETENV
if (value) {
setenv(name, value, 1);
}
#endif
#if HAVE_UNSETENV
if (!value) {
unsetenv(name);
}
#endif
#if !HAVE_SETENV || !HAVE_UNSETENV
/* if cgi, or fastcgi and not found in fcgi env
check the regular environment
this leaks, but it's only cgi anyway, we'll fix
it for 5.0
*/
len = name_len + (value ? strlen(value) : 0) + sizeof("=") + 2;
buf = (char *) malloc(len);
if (buf == NULL) {
return getenv(name);
}
#endif
#if !HAVE_SETENV
if (value) {
len = slprintf(buf, len - 1, "%s=%s", name, value);
putenv(buf);
}
#endif
#if !HAVE_UNSETENV
if (!value) {
len = slprintf(buf, len - 1, "%s=", name);
putenv(buf);
}
#endif
return getenv(name);
}
zend_module_entry php_activescript_module = {
STANDARD_MODULE_HEADER,
"PDAinterface",
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
STANDARD_MODULE_PROPERTIES
};
sapi_module_struct activescript_sapi_module = {
"pdascript", /* name */
"PDAScript", /* pretty name */
php_activescript_startup, /* startup */
php_module_shutdown_wrapper, /* shutdown */
NULL, /* activate */
NULL, /* deactivate */
sapi_activescript_ub_write, /* unbuffered write */
NULL, /* flush */
NULL, /* get uid */
sapi_cgibin_getenv, /* getenv */
zend_error, /* error handler */
sapi_activescript_header_handler, /* header handler */
sapi_activescript_send_headers, /* send headers handler */
NULL, /* send header handler */
NULL, /* read POST data */
sapi_activescript_read_cookies, /* read Cookies */
sapi_activescript_register_server_variables, /* register server variables */
NULL, /* Log message */
STANDARD_SAPI_MODULE_PROPERTIES
};
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
module_handle = hinstDLL;
tsrm_startup(128, 32, TSRM_ERROR_LEVEL_CORE, "C:\\TSRM.log");
/* useful behaviour for the host: we take the application path
* and use that dir as the override for the php.ini, so that
* we don't pick up a global .ini file */
{
char module_dir[MAXPATHLEN];
char *slash;
GetModuleFileName(0, module_dir, sizeof(module_dir));
slash = strrchr(module_dir, '\\');
if (slash) {
slash[1] = '\0';
}
activescript_sapi_module.php_ini_path_override = strdup(module_dir);
}
sapi_startup(&activescript_sapi_module);
if (activescript_sapi_module.startup) {
activescript_sapi_module.startup(&sapi_module);
}
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
//OutputDebugString("THREAD_DETACH\n");
ts_free_thread();
break;
case DLL_PROCESS_DETACH:
if (activescript_sapi_module.shutdown) {
activescript_sapi_module.shutdown(&sapi_module);
}
//OutputDebugString("PROCESS_DETACH\n");
sapi_shutdown();
tsrm_shutdown();
break;
}
return TRUE;
}