2 +--------------------------------------------------------------------+
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 +--------------------------------------------------------------------+
19 #include "ext/standard/info.h"
24 #if PHP_VERSION_ID >= 70000
26 #define APFD_SG(t) &PG(http_globals)[t]
27 static inline sapi_post_entry
*apfd_get_post_entry(const char *ct_str
, size_t ct_len
)
29 return zend_hash_str_find_ptr(&SG(known_post_content_types
), ct_str
, ct_len
);
32 static inline zval
*apfd_backup_files(void)
34 if (SG(rfc1867_uploaded_files
)) {
35 destroy_uploaded_files_hash();
40 static inline void apfd_update_files(zval
*files
)
42 Z_TRY_ADDREF_P(APFD_SG(TRACK_VARS_FILES
));
43 zend_hash_str_update(&EG(symbol_table
), "_FILES", sizeof("_FILES")-1, APFD_SG(TRACK_VARS_FILES
));
48 #define APFD_SG(t) PG(http_globals)[t]
49 static inline sapi_post_entry
*apfd_get_post_entry(const char *ct_str
, size_t ct_len TSRMLS_DC
)
51 sapi_post_entry
*post_entry
;
53 if (SUCCESS
== zend_hash_find(&SG(known_post_content_types
), ct_str
, ct_len
+1, (void *) &post_entry
)) {
59 static inline zval
*apfd_backup_files(TSRMLS_D
)
61 return APFD_SG(TRACK_VARS_FILES
);
64 static inline void apfd_update_files(zval
*files TSRMLS_DC
)
66 if (files
!= APFD_SG(TRACK_VARS_FILES
) && APFD_SG(TRACK_VARS_FILES
)) {
67 Z_ADDREF_P(APFD_SG(TRACK_VARS_FILES
));
68 zend_hash_update(&EG(symbol_table
), "_FILES", sizeof("_FILES"), &APFD_SG(TRACK_VARS_FILES
), sizeof(zval
*), NULL
);
70 zval_ptr_dtor(&files
);
76 PHP_RINIT_FUNCTION(apfd
)
78 /* populate form data on non-POST requests */
79 if (SG(request_info
).request_method
&& strcasecmp(SG(request_info
).request_method
, "POST") && SG(request_info
).content_type
&& *SG(request_info
).content_type
) {
80 char *ct_str
, *ct_dup
= estrdup(SG(request_info
).content_type
);
81 size_t ct_end
= strcspn(ct_dup
, ";, ");
82 sapi_post_entry
*post_entry
= NULL
;
84 SG(request_info
).content_type_dup
= ct_dup
;
86 ct_str
= zend_str_tolower_dup(ct_dup
, ct_end
);
87 if ((post_entry
= apfd_get_post_entry(ct_str
, ct_end TSRMLS_CC
))) {
88 zval
*files
= apfd_backup_files(TSRMLS_C
);
91 SG(request_info
).post_entry
= post_entry
;
93 if (post_entry
->post_reader
) {
94 post_entry
->post_reader(TSRMLS_C
);
98 if (sapi_module
.default_post_reader
) {
99 sapi_module
.default_post_reader(TSRMLS_C
);
102 sapi_handle_post(APFD_SG(TRACK_VARS_POST
) TSRMLS_CC
);
105 * the rfc1867 handler is an awkward buddy
107 apfd_update_files(files TSRMLS_CC
);
111 if (SG(request_info
).content_type_dup
) {
112 efree(SG(request_info
).content_type_dup
);
113 SG(request_info
).content_type_dup
= NULL
;
120 PHP_MINFO_FUNCTION(apfd
)
122 php_info_print_table_start();
123 php_info_print_table_header(2, "apfd support", "enabled");
124 php_info_print_table_end();
127 const zend_function_entry apfd_functions
[] = {
131 zend_module_entry apfd_module_entry
= {
132 STANDARD_MODULE_HEADER
,
141 STANDARD_MODULE_PROPERTIES
144 #ifdef COMPILE_DL_APFD
145 ZEND_GET_MODULE(apfd
)
153 * vim600: noet sw=4 ts=4 fdm=marker
154 * vim<600: noet sw=4 ts=4