X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_misc.h;h=cbb2d3d155d2d9d64a5bc2d3facaf7d5eea26237;hp=2b3d6e96226d244d2fb99a76d8e670eb4936c6e3;hb=20a7c37b273e313e53a37f4406eb49898dd50b6d;hpb=d3485e3b28336153dca690e872ffe1ddc60fedd2 diff --git a/php_http_misc.h b/php_http_misc.h index 2b3d6e9..cbb2d3d 100644 --- a/php_http_misc.h +++ b/php_http_misc.h @@ -6,12 +6,10 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2010, Michael Wallner | + | Copyright (c) 2004-2011, Michael Wallner | +--------------------------------------------------------------------+ */ -/* $Id: php_http_api.h 298891 2010-05-03 08:26:38Z mike $ */ - #ifndef PHP_HTTP_MISC_H #define PHP_HTTP_MISC_H @@ -79,7 +77,7 @@ PHP_HTTP_API void php_http_sleep(double s); #define PHP_HTTP_MATCH_CASE 0x01 #define PHP_HTTP_MATCH_WORD 0x10 #define PHP_HTTP_MATCH_FULL 0x20 -#define PHP_HTTP_MATCH_STRICT (PHP_HTTP_ENV_MATCH_CASE|PHP_HTTP_ENV_MATCH_FULL) +#define PHP_HTTP_MATCH_STRICT (PHP_HTTP_MATCH_CASE|PHP_HTTP_MATCH_FULL) extern int php_http_match(const char *haystack, const char *needle, int flags); @@ -158,7 +156,7 @@ static inline const char *php_http_locate_bin_eol(const char *bin, size_t len, i Z_ARRVAL_P(zv) = (ht); \ } -static inline zval *php_http_zsep(int type, zval *z) +static inline zval *php_http_ztyp(int type, zval *z) { SEPARATE_ARG_IF_REF(z); if (Z_TYPE_P(z) != type) { @@ -175,6 +173,26 @@ static inline zval *php_http_zsep(int type, zval *z) return z; } +static inline zval *php_http_zsep(zend_bool add_ref, int type, zval *z) { + if (add_ref) { + Z_ADDREF_P(z); + } + if (Z_TYPE_P(z) != type) { + switch (type) { + case IS_NULL: convert_to_null_ex(&z); break; + case IS_BOOL: convert_to_boolean_ex(&z); break; + case IS_LONG: convert_to_long_ex(&z); break; + case IS_DOUBLE: convert_to_double_ex(&z); break; + case IS_STRING: convert_to_string_ex(&z); break; + case IS_ARRAY: convert_to_array_ex(&z); break; + case IS_OBJECT: convert_to_object_ex(&z); break; + } + } else { + SEPARATE_ZVAL_IF_NOT_REF(&z); + } + return z; +} + /* return bool (v == SUCCESS) */ #define RETVAL_SUCCESS(v) RETVAL_BOOL(SUCCESS == (v)) @@ -275,6 +293,15 @@ static inline zval *php_http_zsep(int type, zval *z) php_ ##name## _class_entry->ce_flags |= flags; \ } +#define PHP_HTTP_REGISTER_INTERFACE(ns, ifacename, name, flags) \ + { \ + zend_class_entry ce; \ + memset(&ce, 0, sizeof(zend_class_entry)); \ + INIT_NS_CLASS_ENTRY(ce, #ns, #ifacename, php_ ##name## _method_entry); \ + php_ ##name## _class_entry = zend_register_internal_interface(&ce TSRMLS_CC); \ + php_ ##name## _class_entry->ce_flags |= flags; \ + } + #define PHP_HTTP_REGISTER_EXCEPTION(classname, cename, parent) \ { \ zend_class_entry ce; \ @@ -323,6 +350,12 @@ static inline zval *php_http_zsep(int type, zval *z) ZEND_ARG_PASS_INFO(0) \ ZEND_ARG_PASS_INFO(1) \ ZEND_END_ARG_INFO(); \ +\ + ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_3, 0) \ + ZEND_ARG_PASS_INFO(0) \ + ZEND_ARG_PASS_INFO(0) \ + ZEND_ARG_PASS_INFO(1) \ + ZEND_END_ARG_INFO(); \ \ ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_4, 0) \ ZEND_ARG_PASS_INFO(0) \ @@ -343,19 +376,19 @@ typedef struct php_http_array_hashkey { } php_http_array_hashkey_t; #define php_http_array_hashkey_init(dup) {NULL, 0, 0, (dup), 0} -#define FOREACH_VAL(pos, array, val) FOREACH_HASH_VAL(pos, Z_ARRVAL_P(array), val) +#define FOREACH_VAL(pos, array, val) FOREACH_HASH_VAL(pos, HASH_OF(array), val) #define FOREACH_HASH_VAL(pos, hash, val) \ for ( zend_hash_internal_pointer_reset_ex(hash, &pos); \ zend_hash_get_current_data_ex(hash, (void *) &val, &pos) == SUCCESS; \ zend_hash_move_forward_ex(hash, &pos)) -#define FOREACH_KEY(pos, array, key) FOREACH_HASH_KEY(pos, Z_ARRVAL_P(array), key) +#define FOREACH_KEY(pos, array, key) FOREACH_HASH_KEY(pos, HASH_OF(array), key) #define FOREACH_HASH_KEY(pos, hash, _key) \ for ( zend_hash_internal_pointer_reset_ex(hash, &pos); \ ((_key).type = zend_hash_get_current_key_ex(hash, &(_key).str, &(_key).len, &(_key).num, (zend_bool) (_key).dup, &pos)) != HASH_KEY_NON_EXISTANT; \ zend_hash_move_forward_ex(hash, &pos)) \ -#define FOREACH_KEYVAL(pos, array, key, val) FOREACH_HASH_KEYVAL(pos, Z_ARRVAL_P(array), key, val) +#define FOREACH_KEYVAL(pos, array, key, val) FOREACH_HASH_KEYVAL(pos, HASH_OF(array), key, val) #define FOREACH_HASH_KEYVAL(pos, hash, _key, val) \ for ( zend_hash_internal_pointer_reset_ex(hash, &pos); \ ((_key).type = zend_hash_get_current_key_ex(hash, &(_key).str, &(_key).len, &(_key).num, (zend_bool) (_key).dup, &pos)) != HASH_KEY_NON_EXISTANT && \ @@ -373,7 +406,7 @@ extern int php_http_array_apply_merge_func(void *pDest TSRMLS_DC, int num_args, /* PASS CALLBACK */ typedef size_t (*php_http_pass_callback_t)(void *cb_arg, const char *str, size_t len); -typedef size_t (*php_http_pass_php_http_buffer_callback_t)(void *cb_arg, php_http_buffer *str); +typedef size_t (*php_http_pass_php_http_buffer_callback_t)(void *cb_arg, php_http_buffer_t *str); typedef struct php_http_pass_callback_arg { size_t (*cb_zts)(void *cb_arg, const char *str, size_t len TSRMLS_DC); @@ -404,6 +437,7 @@ extern void php_http_error(long type TSRMLS_DC, long code, const char *format, . #define HE_ERROR E_ERROR TSRMLS_CC typedef enum php_http_error { + PHP_HTTP_E_UNKNOWN = 0, PHP_HTTP_E_RUNTIME, PHP_HTTP_E_INVALID_PARAM, PHP_HTTP_E_HEADER, @@ -411,9 +445,12 @@ typedef enum php_http_error { PHP_HTTP_E_REQUEST_METHOD, PHP_HTTP_E_MESSAGE, PHP_HTTP_E_MESSAGE_TYPE, + PHP_HTTP_E_MESSAGE_BODY, PHP_HTTP_E_ENCODING, PHP_HTTP_E_REQUEST, PHP_HTTP_E_REQUEST_POOL, + PHP_HTTP_E_REQUEST_DATASHARE, + PHP_HTTP_E_REQUEST_FACTORY, PHP_HTTP_E_SOCKET, PHP_HTTP_E_RESPONSE, PHP_HTTP_E_URL, @@ -421,42 +458,7 @@ typedef enum php_http_error { PHP_HTTP_E_COOKIE, } php_http_error_t; -/* CURL */ - -#define PHP_HTTP_CURL_OPT(OPTION, p) curl_easy_setopt((request->ch), OPTION, (p)) - -#define PHP_HTTP_CURL_OPT_STRING(OPTION, ldiff, obdc) \ - { \ - char *K = #OPTION; \ - PHP_HTTP_CURL_OPT_STRING_EX(K+lenof("CURLOPT_KEY")+ldiff, OPTION, obdc); \ - } -#define PHP_HTTP_CURL_OPT_STRING_EX(keyname, optname, obdc) \ - if (!strcasecmp(key.str, keyname)) { \ - zval *copy = php_http_request_option_cache(request, keyname, strlen(keyname)+1, 0, php_http_zsep(IS_STRING, *param)); \ - if (obdc) { \ - if (SUCCESS != php_check_open_basedir(Z_STRVAL_P(copy) TSRMLS_CC)) { \ - return FAILURE; \ - } \ - } \ - PHP_HTTP_CURL_OPT(optname, Z_STRVAL_P(copy)); \ - zval_ptr_dtor(©); \ - continue; \ - } -#define PHP_HTTP_CURL_OPT_LONG(OPTION, ldiff) \ - { \ - char *K = #OPTION; \ - PHP_HTTP_CURL_OPT_LONG_EX(K+lenof("CURLOPT_KEY")+ldiff, OPTION); \ - } -#define PHP_HTTP_CURL_OPT_LONG_EX(keyname, optname) \ - if (!strcasecmp(key.str, keyname)) { \ - zval *copy = php_http_zsep(IS_LONG, *param); \ - PHP_HTTP_CURL_OPT(optname, Z_LVAL_P(copy)); \ - zval_ptr_dtor(©); \ - continue; \ - } - #endif - /* * Local variables: * tab-width: 4