2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.0 of the PHP license, that |
6 | is bundled with this package in the file LICENSE, and is available |
7 | through the world-wide-web at http://www.php.net/license/3_0.txt. |
8 | If you did not receive a copy of the PHP license and are unable to |
9 | obtain it through the world-wide-web, please send a note to |
10 | license@php.net so we can mail you a copy immediately. |
11 +----------------------------------------------------------------------+
12 | Copyright (c) 2004-2005 Michael Wallner <mike@php.net> |
13 +----------------------------------------------------------------------+
24 #include "php_http_std_defs.h"
25 #include "php_http_api.h"
26 #include "php_http_request_method_api.h"
28 #include "phpstr/phpstr.h"
30 ZEND_EXTERN_MODULE_GLOBALS(http
);
32 /* {{{ char *http_request_methods[] */
33 static const char *const http_request_methods
[] = {
44 /* WebDAV - RFC 2518 */
52 /* WebDAV Versioning - RFC 3253 */
64 /* WebDAV Access Control - RFC 3744 */
70 /* {{{ char *http_request_method_name(http_request_method) */
71 PHP_HTTP_API
const char *_http_request_method_name(http_request_method m TSRMLS_DC
)
75 if (HTTP_STD_REQUEST_METHOD(m
)) {
76 return http_request_methods
[m
];
79 if (SUCCESS
== zend_hash_index_find(&HTTP_G(request
).methods
.custom
, HTTP_CUSTOM_REQUEST_METHOD(m
), (void **) &meth
)) {
80 return Z_STRVAL_PP(meth
);
83 return http_request_methods
[0];
87 /* {{{ unsigned long http_request_method_exists(zend_bool, unsigned long, char *) */
88 PHP_HTTP_API
unsigned long _http_request_method_exists(zend_bool by_name
, unsigned long id
, const char *name TSRMLS_DC
)
93 for (i
= HTTP_NO_REQUEST_METHOD
+ 1; i
< HTTP_MAX_REQUEST_METHOD
; ++i
) {
94 if (!strcmp(name
, http_request_methods
[i
])) {
103 FOREACH_HASH_KEYVAL(&HTTP_G(request
).methods
.custom
, key
, idx
, data
) {
104 if (!strcmp(name
, Z_STRVAL_PP(data
))) {
105 return idx
+ HTTP_MAX_REQUEST_METHOD
;
111 return HTTP_STD_REQUEST_METHOD(id
) || zend_hash_index_exists(&HTTP_G(request
).methods
.custom
, HTTP_CUSTOM_REQUEST_METHOD(id
)) ? id
: 0;
116 /* {{{ unsigned long http_request_method_register(char *) */
117 PHP_HTTP_API
unsigned long _http_request_method_register(const char *method TSRMLS_DC
)
121 unsigned long meth_num
= HTTP_G(request
).methods
.custom
.nNextFreeElement
+ HTTP_MAX_REQUEST_METHOD
;
123 Z_ARRVAL(array
) = &HTTP_G(request
).methods
.custom
;
124 add_next_index_string(&array
, estrdup(method
), 0);
126 spprintf(&http_method
, 0, "HTTP_%s", method
);
127 zend_register_long_constant(http_method
, strlen(http_method
) + 1, meth_num
, CONST_CS
, http_module_number TSRMLS_CC
);
134 /* {{{ STATUS http_request_method_unregister(usngigned long) */
135 PHP_HTTP_API STATUS
_http_request_method_unregister(unsigned long method TSRMLS_DC
)
140 if (SUCCESS
!= zend_hash_index_find(&HTTP_G(request
).methods
.custom
, HTTP_CUSTOM_REQUEST_METHOD(method
), (void **) &zmethod
)) {
141 http_error_ex(HE_NOTICE
, HTTP_E_REQUEST_METHOD
, "Request method with id %lu does not exist", method
);
145 spprintf(&http_method
, 0, "HTTP_%s", Z_STRVAL_PP(zmethod
));
147 if ( (SUCCESS
!= zend_hash_index_del(&HTTP_G(request
).methods
.custom
, HTTP_CUSTOM_REQUEST_METHOD(method
)))
148 || (SUCCESS
!= zend_hash_del(EG(zend_constants
), http_method
, strlen(http_method
) + 1))) {
149 http_error_ex(HE_NOTICE
, HTTP_E_REQUEST_METHOD
, "Could not unregister request method: %s", http_method
);
164 * vim600: noet sw=4 ts=4 fdm=marker
165 * vim<600: noet sw=4 ts=4