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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
|
diff --git c/plugins/php/common.h w/plugins/php/common.h
index 9bf1c069..061b0b59 100644
--- c/plugins/php/common.h
+++ w/plugins/php/common.h
@@ -3,11 +3,6 @@
#include "php_main.h"
#include "php_variables.h"
-#if (PHP_MAJOR_VERSION < 7)
-#include "ext/standard/php_smart_str.h"
-#else
-#define UWSGI_PHP7
-#endif
#include "ext/standard/info.h"
#include "ext/session/php_session.h"
diff --git c/plugins/php/php_plugin.c w/plugins/php/php_plugin.c
index 5cec7805..717d6317 100644
--- c/plugins/php/php_plugin.c
+++ w/plugins/php/php_plugin.c
@@ -4,6 +4,11 @@ extern struct uwsgi_server uwsgi;
static sapi_module_struct uwsgi_sapi_module;
+static int uwsgi_php_init(void);
+
+typedef size_t php_strlen_size;
+typedef zend_long php_long_size;
+
struct uwsgi_php {
struct uwsgi_string_list *allowed_docroot;
struct uwsgi_string_list *allowed_ext;
@@ -17,7 +22,6 @@ struct uwsgi_php {
struct uwsgi_string_list *vars;
struct uwsgi_string_list *constants;
char *docroot;
- size_t docroot_len;
char *app;
char *app_qs;
char *fallback;
@@ -32,7 +36,10 @@ struct uwsgi_php {
struct uwsgi_string_list *exec_after;
char *sapi_name;
+
+ int sapi_initialized;
HashTable user_config_cache;
+ struct uwsgi_dyn_dict *mountpoint;
} uphp;
void uwsgi_opt_php_ini(char *opt, char *value, void *foobar) {
@@ -40,6 +47,10 @@ void uwsgi_opt_php_ini(char *opt, char *value, void *foobar) {
uwsgi_sapi_module.php_ini_ignore = 1;
}
+void uwsgi_opt_early_php(char *opt, char *value, void *foobar) {
+ uwsgi_php_init();
+}
+
struct uwsgi_option uwsgi_php_options[] = {
{"php-ini", required_argument, 0, "set php.ini path", uwsgi_opt_php_ini, NULL, 0},
@@ -69,15 +80,15 @@ struct uwsgi_option uwsgi_php_options[] = {
{"php-exec-after", required_argument, 0, "run specified php code after the requested script", uwsgi_opt_add_string_list, &uphp.exec_after, 0},
{"php-exec-end", required_argument, 0, "run specified php code after the requested script", uwsgi_opt_add_string_list, &uphp.exec_after, 0},
{"php-sapi-name", required_argument, 0, "hack the sapi name (required for enabling zend opcode cache)", uwsgi_opt_set_str, &uphp.sapi_name, 0},
+
+ {"early-php", no_argument, 0, "initialize an early perl interpreter shared by all loaders", uwsgi_opt_early_php, NULL, UWSGI_OPT_IMMEDIATE},
+ {"early-php-sapi-name", required_argument, 0, "hack the sapi name (required for enabling zend opcode cache)", uwsgi_opt_set_str, &uphp.sapi_name, UWSGI_OPT_IMMEDIATE},
+ {"php-mount", required_argument, 0, "add a php mountpoint", uwsgi_opt_add_dyn_dict, &uphp.mountpoint, 0},
UWSGI_END_OF_OPTIONS
};
-#ifdef UWSGI_PHP7
-static size_t sapi_uwsgi_ub_write(const char *str, size_t str_length TSRMLS_DC)
-#else
-static int sapi_uwsgi_ub_write(const char *str, uint str_length TSRMLS_DC)
-#endif
+static size_t sapi_uwsgi_ub_write(const char *str, size_t str_length)
{
struct wsgi_request *wsgi_req = (struct wsgi_request *) SG(server_context);
@@ -89,7 +100,7 @@ static int sapi_uwsgi_ub_write(const char *str, uint str_length TSRMLS_DC)
return str_length;
}
-static int sapi_uwsgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
+static int sapi_uwsgi_send_headers(sapi_headers_struct *sapi_headers)
{
sapi_header_struct *h;
zend_llist_position pos;
@@ -123,11 +134,7 @@ static int sapi_uwsgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
return SAPI_HEADER_SENT_SUCCESSFULLY;
}
-#ifdef UWSGI_PHP7
-static size_t sapi_uwsgi_read_post(char *buffer, size_t count_bytes TSRMLS_DC)
-#else
-static int sapi_uwsgi_read_post(char *buffer, uint count_bytes TSRMLS_DC)
-#endif
+static size_t sapi_uwsgi_read_post(char *buffer, size_t count_bytes)
{
uint read_bytes = 0;
@@ -151,7 +158,7 @@ static int sapi_uwsgi_read_post(char *buffer, uint count_bytes TSRMLS_DC)
}
-static char *sapi_uwsgi_read_cookies(TSRMLS_D)
+static char *sapi_uwsgi_read_cookies()
{
uint16_t len = 0;
struct wsgi_request *wsgi_req = (struct wsgi_request *) SG(server_context);
@@ -164,55 +171,55 @@ static char *sapi_uwsgi_read_cookies(TSRMLS_D)
return NULL;
}
-static void sapi_uwsgi_register_variables(zval *track_vars_array TSRMLS_DC)
+static void sapi_uwsgi_register_variables(zval *track_vars_array)
{
int i;
struct wsgi_request *wsgi_req = (struct wsgi_request *) SG(server_context);
- php_import_environment_variables(track_vars_array TSRMLS_CC);
+ php_import_environment_variables(track_vars_array);
if (uphp.server_software) {
if (!uphp.server_software_len) uphp.server_software_len = strlen(uphp.server_software);
- php_register_variable_safe("SERVER_SOFTWARE", uphp.server_software, uphp.server_software_len, track_vars_array TSRMLS_CC);
+ php_register_variable_safe("SERVER_SOFTWARE", uphp.server_software, uphp.server_software_len, track_vars_array);
}
else {
- php_register_variable_safe("SERVER_SOFTWARE", "uWSGI", 5, track_vars_array TSRMLS_CC);
+ php_register_variable_safe("SERVER_SOFTWARE", "uWSGI", 5, track_vars_array);
}
for (i = 0; i < wsgi_req->var_cnt; i += 2) {
php_register_variable_safe( estrndup(wsgi_req->hvec[i].iov_base, wsgi_req->hvec[i].iov_len),
wsgi_req->hvec[i + 1].iov_base, wsgi_req->hvec[i + 1].iov_len,
- track_vars_array TSRMLS_CC);
+ track_vars_array);
}
- php_register_variable_safe("PATH_INFO", wsgi_req->path_info, wsgi_req->path_info_len, track_vars_array TSRMLS_CC);
+ php_register_variable_safe("PATH_INFO", wsgi_req->path_info, wsgi_req->path_info_len, track_vars_array);
if (wsgi_req->query_string_len > 0) {
- php_register_variable_safe("QUERY_STRING", wsgi_req->query_string, wsgi_req->query_string_len, track_vars_array TSRMLS_CC);
+ php_register_variable_safe("QUERY_STRING", wsgi_req->query_string, wsgi_req->query_string_len, track_vars_array);
}
- php_register_variable_safe("SCRIPT_NAME", wsgi_req->script_name, wsgi_req->script_name_len, track_vars_array TSRMLS_CC);
- php_register_variable_safe("SCRIPT_FILENAME", wsgi_req->file, wsgi_req->file_len, track_vars_array TSRMLS_CC);
+ php_register_variable_safe("SCRIPT_NAME", wsgi_req->script_name, wsgi_req->script_name_len, track_vars_array);
+ php_register_variable_safe("SCRIPT_FILENAME", wsgi_req->file, wsgi_req->file_len, track_vars_array);
- php_register_variable_safe("DOCUMENT_ROOT", wsgi_req->document_root, wsgi_req->document_root_len, track_vars_array TSRMLS_CC);
+ php_register_variable_safe("DOCUMENT_ROOT", wsgi_req->document_root, wsgi_req->document_root_len, track_vars_array);
if (wsgi_req->path_info_len) {
char *path_translated = ecalloc(1, wsgi_req->file_len + wsgi_req->path_info_len + 1);
memcpy(path_translated, wsgi_req->file, wsgi_req->file_len);
memcpy(path_translated + wsgi_req->file_len, wsgi_req->path_info, wsgi_req->path_info_len);
- php_register_variable_safe("PATH_TRANSLATED", path_translated, wsgi_req->file_len + wsgi_req->path_info_len , track_vars_array TSRMLS_CC);
+ php_register_variable_safe("PATH_TRANSLATED", path_translated, wsgi_req->file_len + wsgi_req->path_info_len , track_vars_array);
}
else {
- php_register_variable_safe("PATH_TRANSLATED", "", 0, track_vars_array TSRMLS_CC);
+ php_register_variable_safe("PATH_TRANSLATED", "", 0, track_vars_array);
}
- php_register_variable_safe("PHP_SELF", wsgi_req->script_name, wsgi_req->script_name_len, track_vars_array TSRMLS_CC);
+ php_register_variable_safe("PHP_SELF", wsgi_req->script_name, wsgi_req->script_name_len, track_vars_array);
struct uwsgi_string_list *usl = uphp.vars;
while(usl) {
char *equal = strchr(usl->value, '=');
if (equal) {
php_register_variable_safe( estrndup(usl->value, equal-usl->value),
- equal+1, strlen(equal+1), track_vars_array TSRMLS_CC);
+ equal+1, strlen(equal+1), track_vars_array);
}
usl = usl->next;
}
@@ -253,10 +260,7 @@ PHP_MINIT_FUNCTION(uwsgi_php_minit) {
char *name = usl->value;
char *strval = equal + 1;
equal = NULL;
-#ifndef UWSGI_PHP7
- name_len = name_len + 1;
-#endif
- zend_register_string_constant(name, name_len, strval, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC);
+ zend_register_string_constant(name, name_len, strval, CONST_CS | CONST_PERSISTENT, module_number);
}
usl = usl->next;
}
@@ -264,11 +268,7 @@ PHP_MINIT_FUNCTION(uwsgi_php_minit) {
}
PHP_FUNCTION(uwsgi_version) {
-#ifdef UWSGI_PHP7
RETURN_STRING(UWSGI_VERSION);
-#else
- RETURN_STRING(UWSGI_VERSION, 1);
-#endif
}
PHP_FUNCTION(uwsgi_worker_id) {
@@ -285,11 +285,11 @@ PHP_FUNCTION(uwsgi_masterpid) {
PHP_FUNCTION(uwsgi_cache_exists) {
char *key = NULL;
- int keylen = 0;
+ php_strlen_size keylen = 0;
char *cache = NULL;
- int cachelen = 0;
+ php_strlen_size cachelen = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &key, &keylen, &cache, &cachelen) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", &key, &keylen, &cache, &cachelen) == FAILURE) {
RETURN_NULL();
}
@@ -303,9 +303,9 @@ PHP_FUNCTION(uwsgi_cache_exists) {
PHP_FUNCTION(uwsgi_cache_clear) {
char *cache = NULL;
- int cachelen = 0;
+ php_strlen_size cachelen = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &cache, &cachelen) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &cache, &cachelen) == FAILURE) {
RETURN_NULL();
}
@@ -318,13 +318,13 @@ PHP_FUNCTION(uwsgi_cache_clear) {
PHP_FUNCTION(uwsgi_cache_del) {
-
+
char *key = NULL;
- int keylen = 0;
+ php_strlen_size keylen = 0;
char *cache = NULL;
- int cachelen = 0;
+ php_strlen_size cachelen = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &key, &keylen, &cache, &cachelen) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", &key, &keylen, &cache, &cachelen) == FAILURE) {
RETURN_NULL();
}
@@ -338,15 +338,15 @@ PHP_FUNCTION(uwsgi_cache_del) {
PHP_FUNCTION(uwsgi_cache_get) {
char *key = NULL;
- int keylen = 0;
+ php_strlen_size keylen = 0;
char *cache = NULL;
- int cachelen = 0;
+ php_strlen_size cachelen = 0;
uint64_t valsize;
if (!uwsgi.caches)
RETURN_NULL();
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &key, &keylen, &cache, &cachelen) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", &key, &keylen, &cache, &cachelen) == FAILURE) {
RETURN_NULL();
}
@@ -354,28 +354,24 @@ PHP_FUNCTION(uwsgi_cache_get) {
if (value) {
char *ret = estrndup(value, valsize);
free(value);
-#ifdef UWSGI_PHP7
RETURN_STRING(ret);
-#else
- RETURN_STRING(ret, 0);
-#endif
}
RETURN_NULL();
}
PHP_FUNCTION(uwsgi_cache_set) {
char *key = NULL;
- int keylen;
+ php_strlen_size keylen = 0;
char *value = NULL;
- int vallen;
- uint64_t expires = 0;
+ php_strlen_size vallen = 0;
+ php_long_size expires = 0;
char *cache = NULL;
- int cachelen = 0;
+ php_strlen_size cachelen = 0;
if (!uwsgi.caches)
RETURN_NULL();
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ls", &key, &keylen, &value, &vallen, &expires, &cache, &cachelen) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|ls", &key, &keylen, &value, &vallen, &expires, &cache, &cachelen) == FAILURE) {
RETURN_NULL();
}
@@ -388,17 +384,17 @@ PHP_FUNCTION(uwsgi_cache_set) {
PHP_FUNCTION(uwsgi_cache_update) {
char *key = NULL;
- int keylen;
+ php_strlen_size keylen = 0;
char *value = NULL;
- int vallen;
- uint64_t expires = 0;
+ php_strlen_size vallen = 0;
+ php_long_size expires = 0;
char *cache = NULL;
- int cachelen = 0;
+ php_strlen_size cachelen = 0;
if (!uwsgi.caches)
RETURN_NULL();
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ls", &key, &keylen, &value, &vallen, &expires, &cache, &cachelen) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|ls", &key, &keylen, &value, &vallen, &expires, &cache, &cachelen) == FAILURE) {
RETURN_NULL();
}
@@ -423,7 +419,7 @@ PHP_FUNCTION(uwsgi_rpc) {
uint16_t argvs[256];
uint64_t size = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &varargs, &num_args) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &varargs, &num_args) == FAILURE) {
RETURN_NULL();
}
@@ -462,11 +458,7 @@ PHP_FUNCTION(uwsgi_rpc) {
// here we do not free varargs for performance reasons
char *ret = estrndup(response, size);
free(response);
-#ifdef UWSGI_PHP7
RETURN_STRING(ret);
-#else
- RETURN_STRING(ret, 0);
-#endif
}
clear:
@@ -481,7 +473,7 @@ PHP_FUNCTION(uwsgi_setprocname) {
char *name;
int name_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
RETURN_NULL();
}
@@ -495,7 +487,7 @@ PHP_FUNCTION(uwsgi_signal) {
long long_signum;
uint8_t signum = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &long_signum) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &long_signum) == FAILURE) {
RETURN_NULL();
}
@@ -629,10 +621,12 @@ static int php_uwsgi_startup(sapi_module_struct *sapi_module)
}
}
-#if ((PHP_MAJOR_VERSION >= 7) && (PHP_MINOR_VERSION >= 1))
+#if (PHP_MAJOR_VERSION >= 8)
+static void sapi_uwsgi_log_message(const char *message, int syslog_type_int) {
+#elif ((PHP_MAJOR_VERSION == 7) && (PHP_MINOR_VERSION >= 1))
static void sapi_uwsgi_log_message(char *message, int syslog_type_int) {
#else
-static void sapi_uwsgi_log_message(char *message TSRMLS_DC) {
+static void sapi_uwsgi_log_message(char *message) {
#endif
uwsgi_log("%s\n", message);
}
@@ -668,16 +662,32 @@ static sapi_module_struct uwsgi_sapi_module = {
STANDARD_SAPI_MODULE_PROPERTIES
};
-int uwsgi_php_init(void) {
+static void uwsgi_php_init_mount(struct uwsgi_dyn_dict *mount_dict) {
+ struct uwsgi_dyn_dict *udd = mount_dict;
+ while (udd) {
+ char *orig_dest = udd->value;
+ udd->value = uwsgi_expand_path(udd->value, udd->vallen, NULL);
+ udd->vallen = strlen(udd->value);
+ if (!udd->value) {
+ uwsgi_log("Unable to expand php mountpoint to %s\n", orig_dest);
+ exit(1);
+ }
+ udd = udd->next;
+ }
+}
+
+static int uwsgi_php_init(void) {
struct uwsgi_string_list *pset = uphp.set;
struct uwsgi_string_list *append_config = uphp.append_config;
+ if (!uphp.sapi_initialized) {
#ifdef ZTS
- tsrm_startup(1, 1, 0, NULL);
+ tsrm_startup(1, 1, 0, NULL);
#endif
-
- sapi_startup(&uwsgi_sapi_module);
+ sapi_startup(&uwsgi_sapi_module);
+ uphp.sapi_initialized = 1;
+ }
// applying custom options
while(append_config) {
@@ -705,13 +715,14 @@ int uwsgi_php_init(void) {
uwsgi_log("unable to set php docroot to %s\n", orig_docroot);
exit(1);
}
- uwsgi_log("PHP document root set to %s\n", uphp.docroot);
- uphp.docroot_len = strlen(uphp.docroot);
}
+ uwsgi_php_init_mount(uphp.mountpoint);
+
if (uphp.sapi_name) {
uwsgi_sapi_module.name = uphp.sapi_name;
}
+
uwsgi_sapi_module.startup(&uwsgi_sapi_module);
uwsgi_log("PHP %s initialized\n", PHP_VERSION);
@@ -776,6 +787,33 @@ int uwsgi_php_walk(struct wsgi_request *wsgi_req, char *full_path, char *docroot
}
+static char *uwsgi_php_get_mount(char *path_info, uint16_t path_info_len, struct uwsgi_dyn_dict *mount_dict, int *discard_base) {
+ int best_found = 0;
+ struct uwsgi_dyn_dict *udd = mount_dict, *chosen = NULL;
+
+ while (udd) {
+ if (mount_dict->vallen) {
+ if (!uwsgi_starts_with(path_info, path_info_len, udd->key, udd->keylen)) {
+ if (udd->keylen > best_found) {
+ best_found = udd->keylen;
+ chosen = udd;
+ }
+ }
+ }
+ udd = udd->next;
+ }
+
+ if (chosen) {
+ *discard_base = chosen->keylen;
+ if (chosen->key[chosen->keylen-1] == '/') {
+ *discard_base = *discard_base - 1;
+ }
+ return chosen->value;
+ } else {
+ return NULL;
+ }
+}
+
int uwsgi_php_request(struct wsgi_request *wsgi_req) {
@@ -788,10 +826,6 @@ int uwsgi_php_request(struct wsgi_request *wsgi_req) {
zend_file_handle file_handle;
-#ifdef ZTS
- TSRMLS_FETCH();
-#endif
-
SG(server_context) = (void *) wsgi_req;
if (uwsgi_parse_vars(wsgi_req)) {
@@ -801,7 +835,15 @@ int uwsgi_php_request(struct wsgi_request *wsgi_req) {
char *orig_path_info = wsgi_req->path_info;
uint16_t orig_path_info_len = wsgi_req->path_info_len;
- if (uphp.docroot) {
+ int discard_base = 0;
+
+ char *mount_docroot = uwsgi_php_get_mount(wsgi_req->path_info, wsgi_req->path_info_len, uphp.mountpoint, &discard_base);
+
+ if (mount_docroot) {
+ wsgi_req->document_root = mount_docroot;
+ wsgi_req->path_info = wsgi_req->path_info+discard_base;
+ wsgi_req->path_info_len = wsgi_req->path_info_len-discard_base;
+ } else if (uphp.docroot) {
wsgi_req->document_root = uphp.docroot;
}
// fallback to cwd
@@ -833,7 +875,8 @@ int uwsgi_php_request(struct wsgi_request *wsgi_req) {
}
#endif
- strcpy(real_filename, uphp.app);
+ strncpy(real_filename, uphp.app, PATH_MAX);
+ real_filename[PATH_MAX-1] = '\0';
if (wsgi_req->path_info_len == 1 && wsgi_req->path_info[0] == '/') {
goto appready;
}
@@ -926,7 +969,6 @@ oldstyle:
free(filename);
real_filename_len = strlen(real_filename);
- // first check for valid doc roots
if (uphp.allowed_docroot) {
struct uwsgi_string_list *usl = uphp.allowed_docroot;
while(usl) {
@@ -939,16 +981,6 @@ oldstyle:
uwsgi_log("PHP security error: %s is not under an allowed docroot\n", real_filename);
return -1;
}
- // then for default docroot (if any)
- else if (uphp.docroot)
- {
- if (!uwsgi_starts_with(real_filename, real_filename_len, uphp.docroot, uphp.docroot_len)) {
- goto secure;
- }
- uwsgi_403(wsgi_req);
- uwsgi_log("PHP security error: %s is not under the default docroot\n", real_filename);
- return -1;
- }
secure:
@@ -1065,7 +1097,7 @@ secure3:
file_handle.type = ZEND_HANDLE_FILENAME;
file_handle.filename = real_filename;
- if (php_request_startup(TSRMLS_C) == FAILURE) {
+ if (php_request_startup() == FAILURE) {
uwsgi_500(wsgi_req);
return -1;
}
@@ -1073,13 +1105,13 @@ secure3:
struct uwsgi_string_list *usl=NULL;
uwsgi_foreach(usl, uphp.exec_before) {
- if (zend_eval_string_ex(usl->value, NULL, "uWSGI php exec before", 1 TSRMLS_CC) == FAILURE) goto end;
+ if (zend_eval_string_ex(usl->value, NULL, "uWSGI php exec before", 1) == FAILURE) goto end;
}
- php_execute_script(&file_handle TSRMLS_CC);
+ php_execute_script(&file_handle);
uwsgi_foreach(usl, uphp.exec_after) {
- if (zend_eval_string_ex(usl->value, NULL, "uWSGI php exec after", 1 TSRMLS_CC) == FAILURE) goto end;
+ if (zend_eval_string_ex(usl->value, NULL, "uWSGI php exec after", 1) == FAILURE) goto end;
}
end:
diff --git c/plugins/php/session.c w/plugins/php/session.c
index 2312b6b9..cce06985 100644
--- c/plugins/php/session.c
+++ w/plugins/php/session.c
@@ -12,34 +12,20 @@ PS_CLOSE_FUNC(uwsgi) {
PS_READ_FUNC(uwsgi) {
char *cache = PS_GET_MOD_DATA();
uint64_t valsize = 0;
-#ifdef UWSGI_PHP7
char *value = uwsgi_cache_magic_get(key->val, key->len , &valsize, NULL, cache);
-#else
- char *value = uwsgi_cache_magic_get((char *)key, strlen((char *)key), &valsize, NULL, cache);
-#endif
- if (!value) return FAILURE;
-#ifdef UWSGI_PHP7
+ if (!value) {
+ *val = STR_EMPTY_ALLOC();
+ return SUCCESS;
+ }
*val = zend_string_init(value, valsize, 0);
-#else
- char *new_val = emalloc(valsize);
- memcpy(new_val, value, valsize);
- free(value);
- *val = new_val;
- *vallen = valsize;
-#endif
return SUCCESS;
}
PS_WRITE_FUNC(uwsgi) {
char *cache = PS_GET_MOD_DATA();
-#ifdef UWSGI_PHP7
if (val->len == 0) return SUCCESS;
if (!uwsgi_cache_magic_set(key->val, key->len, val->val, val->len, 0, UWSGI_CACHE_FLAG_UPDATE, cache)) {
-#else
- if (vallen == 0) return SUCCESS;
- if (!uwsgi_cache_magic_set((char *)key, strlen(key), (char *)val, vallen, 0, UWSGI_CACHE_FLAG_UPDATE, cache)) {
-#endif
return SUCCESS;
}
return FAILURE;
@@ -47,11 +33,10 @@ PS_WRITE_FUNC(uwsgi) {
PS_DESTROY_FUNC(uwsgi) {
char *cache = PS_GET_MOD_DATA();
-#ifdef UWSGI_PHP7
+ if (!uwsgi_cache_magic_exists(key->val, key->len, cache))
+ return SUCCESS;
+
if (!uwsgi_cache_magic_del(key->val, key->len, cache)) {
-#else
- if (!uwsgi_cache_magic_del((char *)key, strlen(key), cache)) {
-#endif
return SUCCESS;
}
return FAILURE;
diff --git c/plugins/php/uwsgiplugin.py w/plugins/php/uwsgiplugin.py
index d930c44e..8657eb70 100644
--- c/plugins/php/uwsgiplugin.py
+++ w/plugins/php/uwsgiplugin.py
@@ -1,6 +1,6 @@
import os
-NAME='php'
+NAME = 'php'
ld_run_path = None
PHPPATH = 'php-config'
|