8270fcba990d84fba65f0aa2f2c6a385822012ea
[m6w6/ext-apfd] / php_apfd.c
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: apfd |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2015, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 #ifdef HAVE_CONFIG_H
14 #include "config.h"
15 #endif
16
17 #include "php.h"
18 #include "php_ini.h"
19 #include "ext/standard/info.h"
20 #include "SAPI.h"
21 #include "php_apfd.h"
22
23 PHP_RINIT_FUNCTION(apfd)
24 {
25 /* populate form data on non-POST requests */
26 if (SG(request_info).request_method && strcasecmp(SG(request_info).request_method, "POST") && SG(request_info).content_type && *SG(request_info).content_type) {
27 char *ct_str = zend_str_tolower_dup(SG(request_info).content_type, strlen(SG(request_info).content_type));
28 size_t ct_end = strcspn(ct_str, ";, ");
29 sapi_post_entry *post_entry = NULL;
30 char delim;
31
32 SG(request_info).content_type_dup = ct_str;
33
34 delim = ct_str[ct_end];
35 ct_str[ct_end] = '\0';
36
37 if (SUCCESS == zend_hash_find(&SG(known_post_content_types), ct_str, ct_end+1, (void *) &post_entry)) {
38 zval *files = PG(http_globals)[TRACK_VARS_FILES];
39
40 ct_str[ct_end] = delim;
41
42 if (post_entry) {
43 SG(request_info).post_entry = post_entry;
44
45 if (post_entry->post_reader) {
46 post_entry->post_reader(TSRMLS_C);
47 }
48 }
49
50 if (sapi_module.default_post_reader) {
51 sapi_module.default_post_reader(TSRMLS_C);
52 }
53
54 sapi_handle_post(PG(http_globals)[TRACK_VARS_POST] TSRMLS_CC);
55
56 /*
57 * the rfc1867 handler is an awkward buddy
58 */
59 if (files != PG(http_globals)[TRACK_VARS_FILES] && PG(http_globals)[TRACK_VARS_FILES]) {
60 Z_ADDREF_P(PG(http_globals)[TRACK_VARS_FILES]);
61 zend_hash_update(&EG(symbol_table), "_FILES", sizeof("_FILES"), &PG(http_globals)[TRACK_VARS_FILES], sizeof(zval *), NULL);
62 if (files) {
63 zval_ptr_dtor(&files);
64 }
65 }
66 }
67
68 if (SG(request_info).content_type_dup) {
69 efree(SG(request_info).content_type_dup);
70 SG(request_info).content_type_dup = NULL;
71 }
72 }
73
74 return SUCCESS;
75 }
76
77 PHP_MINFO_FUNCTION(apfd)
78 {
79 php_info_print_table_start();
80 php_info_print_table_header(2, "apfd support", "enabled");
81 php_info_print_table_end();
82 }
83
84 const zend_function_entry apfd_functions[] = {
85 {0}
86 };
87
88 zend_module_entry apfd_module_entry = {
89 STANDARD_MODULE_HEADER,
90 "apfd",
91 apfd_functions,
92 NULL,
93 NULL,
94 PHP_RINIT(apfd),
95 NULL,
96 PHP_MINFO(apfd),
97 PHP_APFD_VERSION,
98 STANDARD_MODULE_PROPERTIES
99 };
100
101 #ifdef COMPILE_DL_APFD
102 ZEND_GET_MODULE(apfd)
103 #endif
104
105 /*
106 * Local variables:
107 * tab-width: 4
108 * c-basic-offset: 4
109 * End:
110 * vim600: noet sw=4 ts=4 fdm=marker
111 * vim<600: noet sw=4 ts=4
112 */