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
31 #define APFD_SG(t) &PG(http_globals)[t]
32 static inline sapi_post_entry
*apfd_get_post_entry(const char *ct_str
, size_t ct_len
)
34 return zend_hash_str_find_ptr(&SG(known_post_content_types
), ct_str
, ct_len
);
37 static inline void apfd_backup(struct apfd
*apfd
)
39 if (SG(rfc1867_uploaded_files
)) {
40 destroy_uploaded_files_hash();
43 zval_ptr_dtor(APFD_SG(TRACK_VARS_POST
));
44 array_init(&apfd
->post
);
45 ZVAL_COPY_VALUE(APFD_SG(TRACK_VARS_POST
), &apfd
->post
);
47 zval_ptr_dtor(APFD_SG(TRACK_VARS_FILES
));
48 array_init(&apfd
->files
);
49 ZVAL_COPY_VALUE(APFD_SG(TRACK_VARS_FILES
), &apfd
->files
);
52 static inline void apfd_update(struct apfd
*apfd
)
54 zend_hash_str_update(&EG(symbol_table
), "_POST", sizeof("_POST")-1, APFD_SG(TRACK_VARS_POST
));
55 Z_TRY_ADDREF_P(APFD_SG(TRACK_VARS_POST
));
57 zend_hash_str_update(&EG(symbol_table
), "_FILES", sizeof("_FILES")-1, APFD_SG(TRACK_VARS_FILES
));
58 Z_TRY_ADDREF_P(APFD_SG(TRACK_VARS_FILES
));
68 #define APFD_SG(t) PG(http_globals)[t]
69 static inline sapi_post_entry
*apfd_get_post_entry(const char *ct_str
, size_t ct_len TSRMLS_DC
)
71 sapi_post_entry
*post_entry
;
73 if (SUCCESS
== zend_hash_find(&SG(known_post_content_types
), ct_str
, ct_len
+1, (void *) &post_entry
)) {
79 static inline void apfd_backup(struct apfd
*apfd TSRMLS_DC
)
81 apfd
->post
= APFD_SG(TRACK_VARS_POST
);
82 apfd
->files
= APFD_SG(TRACK_VARS_FILES
);
85 static inline void apfd_update(struct apfd
*apfd TSRMLS_DC
)
87 if (apfd
->files
!= APFD_SG(TRACK_VARS_FILES
) && APFD_SG(TRACK_VARS_FILES
)) {
88 Z_ADDREF_P(APFD_SG(TRACK_VARS_FILES
));
89 zend_hash_update(&EG(symbol_table
), "_FILES", sizeof("_FILES"), &APFD_SG(TRACK_VARS_FILES
), sizeof(zval
*), NULL
);
91 zval_ptr_dtor(&apfd
->files
);
97 PHP_RINIT_FUNCTION(apfd
)
103 sapi_request_info
*req
= &SG(request_info
);
105 /* populate form data on non-POST requests */
106 if (req
->request_method
&& strcasecmp(req
->request_method
, "POST") && req
->content_type
&& *req
->content_type
) {
107 char *ct_str
, *ct_dup
= estrdup(req
->content_type
);
108 size_t ct_end
= strcspn(ct_dup
, ";, ");
109 sapi_post_entry
*post_entry
= NULL
;
111 req
->content_type_dup
= ct_dup
;
113 ct_str
= zend_str_tolower_dup(ct_dup
, ct_end
);
114 if ((post_entry
= apfd_get_post_entry(ct_str
, ct_end TSRMLS_CC
))) {
117 apfd_backup(&apfd TSRMLS_CC
);
119 req
->post_entry
= post_entry
;
121 if (post_entry
->post_reader
) {
122 post_entry
->post_reader(TSRMLS_C
);
125 if (sapi_module
.default_post_reader
) {
126 sapi_module
.default_post_reader(TSRMLS_C
);
129 sapi_handle_post(APFD_SG(TRACK_VARS_POST
) TSRMLS_CC
);
131 apfd_update(&apfd TSRMLS_CC
);
135 if (req
->content_type_dup
) {
136 efree(req
->content_type_dup
);
137 req
->content_type_dup
= NULL
;
144 PHP_MINFO_FUNCTION(apfd
)
146 php_info_print_table_start();
147 php_info_print_table_header(2, "apfd support", "enabled");
148 php_info_print_table_end();
151 const zend_function_entry apfd_functions
[] = {
155 zend_module_entry apfd_module_entry
= {
156 STANDARD_MODULE_HEADER
,
165 STANDARD_MODULE_PROPERTIES
168 #ifdef COMPILE_DL_APFD
169 ZEND_GET_MODULE(apfd
)
177 * vim600: noet sw=4 ts=4 fdm=marker
178 * vim<600: noet sw=4 ts=4