X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_api.h;h=fc4faacb2818b90b3bd2af05d4a966c8019d8790;hp=0cc0a47b5eddef5a95893df57db239f2e11aff81;hb=a19a05825d04d634834f7898ec1a5247fdd6095c;hpb=5be9a548c1e57fdc0960740ca6580d0023845ed4 diff --git a/php_http_api.h b/php_http_api.h index 0cc0a47..fc4faac 100644 --- a/php_http_api.h +++ b/php_http_api.h @@ -28,6 +28,65 @@ # include "php_http_build_query.h" #endif +#define RETURN_SUCCESS(v) RETURN_BOOL(SUCCESS == (v)) +#define HASH_ORNULL(z) ((z) ? Z_ARRVAL_P(z) : NULL) +#define NO_ARGS if (ZEND_NUM_ARGS()) WRONG_PARAM_COUNT + +#define array_copy(src, dst) zend_hash_copy(Z_ARRVAL_P(dst), Z_ARRVAL_P(src), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)) +#define array_merge(src, dst) zend_hash_merge(Z_ARRVAL_P(dst), Z_ARRVAL_P(src), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *), 1) + +#ifdef ZEND_ENGINE_2 + +# define HTTP_REGISTER_CLASS_EX(classname, name, parent, flags) \ + { \ + zend_class_entry ce; \ + INIT_CLASS_ENTRY(ce, #classname, name## _class_methods); \ + ce.create_object = name## _new_object; \ + name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \ + name## _ce->ce_flags |= flags; \ + memcpy(& name## _object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); \ + name## _object_handlers.clone_obj = NULL; \ + name## _declare_default_properties(name## _ce); \ + } + +# define HTTP_REGISTER_CLASS(classname, name, parent, flags) \ + { \ + zend_class_entry ce; \ + INIT_CLASS_ENTRY(ce, #classname, name## _class_methods); \ + ce.create_object = NULL; \ + name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \ + name## _ce->ce_flags |= flags; \ + } + +# define getObject(t, o) t * o = ((t *) zend_object_store_get_object(getThis() TSRMLS_CC)) +# define OBJ_PROP(o) o->zo.properties +# define DCL_PROP(a, t, n, v) zend_declare_property_ ##t(ce, (#n), sizeof(#n), (v), (ZEND_ACC_ ##a) TSRMLS_CC) +# define DCL_PROP_Z(a, n, v) zend_declare_property(ce, (#n), sizeof(#n), (v), (ZEND_ACC_ ##a) TSRMLS_CC) +# define DCL_PROP_N(a, n) zend_declare_property_null(ce, (#n), sizeof(#n), (ZEND_ACC_ ##a) TSRMLS_CC) +# define UPD_PROP(o, t, n, v) zend_update_property_ ##t(o->zo.ce, getThis(), (#n), sizeof(#n), (v) TSRMLS_CC) +# define SET_PROP(o, n, z) zend_update_property(o->zo.ce, getThis(), (#n), sizeof(#n), (z) TSRMLS_CC) +# define GET_PROP(o, n) zend_read_property(o->zo.ce, getThis(), (#n), sizeof(#n), 0 TSRMLS_CC) + +# define INIT_PARR(o, n) \ + { \ + zval *__tmp; \ + MAKE_STD_ZVAL(__tmp); \ + array_init(__tmp); \ + SET_PROP(o, n, __tmp); \ + } + +# define FREE_PARR(o, p) \ + { \ + zval *__tmp = NULL; \ + if (__tmp = GET_PROP(o, p)) { \ + zval_dtor(__tmp); \ + FREE_ZVAL(__tmp); \ + __tmp = NULL; \ + } \ + } + +#endif /* ZEND_ENGINE_2 */ + /* make functions that return SUCCESS|FAILURE more obvious */ typedef int STATUS; @@ -61,23 +120,6 @@ typedef enum { /* server vars shorthand */ #define HTTP_SERVER_VARS Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]) -/* {{{ HAVE_CURL */ -#ifdef HTTP_HAVE_CURL -#include - -/* CURL buffer size */ -#define HTTP_CURLBUF_BODYSIZE 16384 -#define HTTP_CURLBUF_HDRSSIZE 4096 - -/* {{{ http_curlbuf_member */ -typedef enum { - CURLBUF_BODY = 1, - CURLBUF_HDRS = 2, - CURLBUF_EVRY = 3 -} http_curlbuf_member; -/* }}} */ -#endif -/* }}} HAVE_CURL */ /* {{{ HTTP_GSC(var, name, ret) */ #define HTTP_GSC(var, name, ret) HTTP_GSP(var, name, return ret) @@ -93,12 +135,7 @@ typedef enum { } /* }}} */ -#define http_etag(p, l, m) _http_etag((p), (l), (m) TSRMLS_CC) -inline char *_http_etag(const void *data_ptr, const size_t data_len, const http_send_mode data_mode TSRMLS_DC); -#define http_lmod(p, m) _http_lmod((p), (m) TSRMLS_CC) -inline time_t _http_lmod(const void *data_ptr, const http_send_mode data_mode TSRMLS_DC); -#define http_is_range_request() _http_is_range_request(TSRMLS_C) -inline int _http_is_range_request(TSRMLS_D); +char *pretty_key(char *key, int key_len, int uctitle, int xhyphen); /* {{{ public API */ #define http_date(t) _http_date((t) TSRMLS_CC) @@ -119,6 +156,15 @@ PHP_HTTP_API inline STATUS _http_send_status_header(const int status, const char #define http_get_server_var(v) _http_get_server_var((v) TSRMLS_CC) PHP_HTTP_API inline zval *_http_get_server_var(const char *key TSRMLS_DC); +#define http_etag(p, l, m) _http_etag((p), (l), (m) TSRMLS_CC) +PHP_HTTP_API inline char *_http_etag(const void *data_ptr, const size_t data_len, const http_send_mode data_mode TSRMLS_DC); + +#define http_lmod(p, m) _http_lmod((p), (m) TSRMLS_CC) +PHP_HTTP_API inline time_t _http_lmod(const void *data_ptr, const http_send_mode data_mode TSRMLS_DC); + +#define http_is_range_request() _http_is_range_request(TSRMLS_C) +PHP_HTTP_API inline int _http_is_range_request(TSRMLS_D); + #define http_ob_etaghandler(o, l, ho, hl, m) _http_ob_etaghandler((o), (l), (ho), (hl), (m) TSRMLS_CC) PHP_HTTP_API void _http_ob_etaghandler(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC); @@ -144,7 +190,7 @@ PHP_HTTP_API STATUS _http_send_cache_control(const char *cache_control, const si PHP_HTTP_API STATUS _http_send_content_type(const char *content_type, const size_t ct_len TSRMLS_DC); #define http_send_content_disposition(f, l, i) _http_send_content_disposition((f), (l), (i) TSRMLS_CC) -PHP_HTTP_API STATUS _http_send_content_disposition(const char *filename, const size_t f_len, const zend_bool send_inline TSRMLS_DC); +PHP_HTTP_API STATUS _http_send_content_disposition(const char *filename, const size_t f_len, const int send_inline TSRMLS_DC); #define http_cache_last_modified(l, s, cc, ccl) _http_cache_last_modified((l), (s), (cc), (ccl) TSRMLS_CC) PHP_HTTP_API STATUS _http_cache_last_modified(const time_t last_modified, const time_t send_modified, const char *cache_control, const size_t cc_len TSRMLS_DC); @@ -181,8 +227,9 @@ PHP_HTTP_API STATUS _http_send_file(const zval *zfile TSRMLS_DC); #define http_chunked_decode(e, el, d, dl) _http_chunked_decode((e), (el), (d), (dl) TSRMLS_CC) PHP_HTTP_API STATUS _http_chunked_decode(const char *encoded, const size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC); -#define http_split_response(r, h, b) _http_split_response((r), (h), (b) TSRMLS_CC) -PHP_HTTP_API STATUS _http_split_response(const zval *zresponse, zval *zheaders, zval *zbody TSRMLS_DC); +#define http_split_response(r, h, b) _http_split_response_ex(Z_STRVAL_P(r), Z_STRLEN_P(r), (h), (b) TSRMLS_CC) +#define http_split_response_ex(r, l, h, b) _http_split_response_ex((r), (l), (h), (b) TSRMLS_CC) +PHP_HTTP_API STATUS _http_split_response_ex(char *response, size_t repsonse_len, zval *zheaders, zval *zbody TSRMLS_DC); #define http_parse_headers(h, l, a) _http_parse_headers((h), (l), (a) TSRMLS_CC) PHP_HTTP_API STATUS _http_parse_headers(char *header, int header_len, zval *array TSRMLS_DC); @@ -190,30 +237,6 @@ PHP_HTTP_API STATUS _http_parse_headers(char *header, int header_len, zval *arra #define http_get_request_headers(h) _http_get_request_headers((h) TSRMLS_CC) PHP_HTTP_API void _http_get_request_headers(zval *array TSRMLS_DC); -/* {{{ HAVE_CURL */ -#ifdef HTTP_HAVE_CURL - -#define http_get(u, o, i, d, l) _http_get((u), (o), (i), (d), (l) TSRMLS_CC) -PHP_HTTP_API STATUS _http_get(const char *URL, HashTable *options, HashTable *info, char **data, size_t *data_len TSRMLS_DC); -#define http_get_ex(c, u, o, i, d, l) _http_get_ex((c), (u), (o), (i), (d), (l) TSRMLS_CC) -PHP_HTTP_API STATUS _http_get_ex(CURL *ch, const char *URL, HashTable *options, HashTable *info, char **data, size_t *data_len TSRMLS_DC); - -#define http_head(u, o, i, d, l) _http_head((u), (o), (i), (d), (l) TSRMLS_CC) -PHP_HTTP_API STATUS _http_head(const char *URL, HashTable *options, HashTable *info, char **data, size_t *data_len TSRMLS_DC); -#define http_head_ex(c, u, o, i, d, l) _http_head_ex((c), (u), (o), (i), (d), (l) TSRMLS_CC) -PHP_HTTP_API STATUS _http_head_ex(CURL *ch, const char *URL, HashTable *options, HashTable *info, char **data, size_t *data_len TSRMLS_DC); - -#define http_post_data(u, pd, pl, o, i, d, l) _http_post_data((u), (pd), (pl), (o), (i), (d), (l) TSRMLS_CC) -PHP_HTTP_API STATUS _http_post_data(const char *URL, char *postdata, size_t postdata_len, HashTable *options, HashTable *info, char **data, size_t *data_len TSRMLS_DC); -#define http_post_data_ex(c, u, pd, pl, o, i, d, l) _http_post_data_ex((c), (u), (pd), (pl), (o), (i), (d), (l) TSRMLS_CC) -PHP_HTTP_API STATUS _http_post_data_ex(CURL *ch, const char *URL, char *postdata, size_t postdata_len, HashTable *options, HashTable *info, char **data, size_t *data_len TSRMLS_DC); - -#define http_post_array(u, p, o, i, d, l) _http_post_array((u), (p), (o), (i), (d), (l) TSRMLS_CC) -PHP_HTTP_API STATUS _http_post_array(const char *URL, HashTable *postarray, HashTable *options, HashTable *info, char **data, size_t *data_len TSRMLS_DC); - -#endif -/* }}} HAVE_CURL */ - #define http_auth_credentials(u, p) _http_auth_credentials((u), (p) TSRMLS_CC) PHP_HTTP_API STATUS _http_auth_credentials(char **user, char **pass TSRMLS_DC);