From 4a881fb37338bfeacd40c42a97f334c9faed299a Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Tue, 12 Apr 2005 13:58:59 +0000 Subject: [PATCH] - split object code into separate files --- config.m4 | 1 + config.w32 | 10 +- http.c | 627 +------------------------------------ http_message_object.c | 361 +++++++++++++++++++++ http_methods.c | 10 +- http_request_object.c | 172 ++++++++++ http_response_object.c | 134 ++++++++ http_util_object.c | 93 ++++++ php_http.h | 170 ++-------- php_http_message_object.h | 53 ++++ php_http_request_object.h | 101 ++++++ php_http_response_object.h | 68 ++++ php_http_std_defs.h | 14 +- php_http_util_object.h | 65 ++++ 14 files changed, 1108 insertions(+), 771 deletions(-) create mode 100644 http_message_object.c create mode 100644 http_request_object.c create mode 100644 http_response_object.c create mode 100644 http_util_object.c create mode 100644 php_http_message_object.h create mode 100644 php_http_request_object.h create mode 100644 php_http_response_object.h create mode 100644 php_http_util_object.h diff --git a/config.m4 b/config.m4 index d442090..9fb219f 100644 --- a/config.m4 +++ b/config.m4 @@ -72,6 +72,7 @@ dnl ---- dnl DONE dnl ---- PHP_HTTP_SOURCES="http.c http_functions.c http_methods.c phpstr/phpstr.c \ + http_util_object.c http_message_object.c http_request_object.c http_response_object.c \ http_api.c http_auth_api.c http_cache_api.c http_curl_api.c http_date_api.c \ http_headers_api.c http_message_api.c http_send_api.c http_url_api.c" PHP_NEW_EXTENSION([http], $PHP_HTTP_SOURCES, [$ext_shared]) diff --git a/config.w32 b/config.w32 index 6d1d0df..93e5330 100644 --- a/config.w32 +++ b/config.w32 @@ -4,11 +4,13 @@ ARG_ENABLE("http", "whether to enable extended HTTP support", "no"); if (PHP_HTTP != "no") { - EXTENSION("http", - "http.c http_functions.c http_methods.c "+ + EXTENSION("http", + "http.c http_functions.c http_methods.c "+ + "http_util_object.c http_message_object.c "+ + "http_request_object.c http_response_object.c "+ "http_api.c http_auth_api.c http_cache_api.c "+ "http_curl_api.c http_date_api.c http_headers_api.c "+ - "http_message_api.c http_send_api.c http_url_api.c ", + "http_message_api.c http_send_api.c http_url_api.c ", null, "/I\"" + configure_module_dirname + "/phpstr\""); ADD_SOURCES(configure_module_dirname + "/phpstr", "phpstr.c", "http"); @@ -23,4 +25,4 @@ if (PHP_HTTP != "no") { } else { WARNING("curl convenience functions not enabled; libraries and headers not found"); } -} \ No newline at end of file +} diff --git a/http.c b/http.c index 6b11586..991e84e 100644 --- a/http.c +++ b/http.c @@ -29,50 +29,42 @@ #include "php.h" #include "php_ini.h" -#include "snprintf.h" #include "ext/standard/info.h" -#include "ext/session/php_session.h" -#include "ext/standard/php_string.h" -#include "ext/standard/php_smart_str.h" #include "SAPI.h" #include "php_http.h" #include "php_http_std_defs.h" -#include "php_http_api.h" -#include "php_http_auth_api.h" -#include "php_http_curl_api.h" -#include "php_http_cache_api.h" -#include "php_http_curl_api.h" -#include "php_http_date_api.h" -#include "php_http_headers_api.h" -#include "php_http_message_api.h" + #include "php_http_send_api.h" -#include "php_http_url_api.h" + +#include "php_http_util_object.h" +#include "php_http_message_object.h" +#include "php_http_response_object.h" +#include "php_http_request_object.h" #include "phpstr/phpstr.h" #ifdef HTTP_HAVE_CURL -/* {{{ ARG_INFO */ -# ifdef ZEND_BEGIN_ARG_INFO +#ifdef ZEND_ENGINE_2 +static ZEND_BEGIN_ARG_INFO(http_request_info_ref_3, 0) ZEND_ARG_PASS_INFO(0) ZEND_ARG_PASS_INFO(0) ZEND_ARG_PASS_INFO(1) ZEND_END_ARG_INFO(); +static ZEND_BEGIN_ARG_INFO(http_request_info_ref_4, 0) ZEND_ARG_PASS_INFO(0) ZEND_ARG_PASS_INFO(0) ZEND_ARG_PASS_INFO(0) ZEND_ARG_PASS_INFO(1) ZEND_END_ARG_INFO(); -# else +#else static unsigned char http_request_info_ref_3[] = {3, BYREF_NONE, BYREF_NONE, BYREF_FORCE}; static unsigned char http_request_info_ref_4[] = {4, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_FORCE}; -# endif -/* }}} ARG_INFO */ - +#endif /* ZEND_ENGINE_2 */ #endif /* HTTP_HAVE_CURL */ ZEND_DECLARE_MODULE_GLOBALS(http) @@ -120,581 +112,6 @@ function_entry http_functions[] = { }; /* }}} */ - -#ifdef ZEND_ENGINE_2 - -/* {{{ HttpUtil */ - -zend_class_entry *http_util_ce; - -#define HTTP_UTIL_ME(me, al, ai) ZEND_FENTRY(me, ZEND_FN(al), ai, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - -zend_function_entry http_util_class_methods[] = { - HTTP_UTIL_ME(date, http_date, NULL) - HTTP_UTIL_ME(absoluteURI, http_absolute_uri, NULL) - HTTP_UTIL_ME(negotiateLanguage, http_negotiate_language, NULL) - HTTP_UTIL_ME(negotiateCharset, http_negotiate_charset, NULL) - HTTP_UTIL_ME(redirect, http_redirect, NULL) - HTTP_UTIL_ME(sendStatus, http_send_status, NULL) - HTTP_UTIL_ME(sendLastModified, http_send_last_modified, NULL) - HTTP_UTIL_ME(sendContentType, http_send_content_type, NULL) - HTTP_UTIL_ME(sendContentDisposition, http_send_content_disposition, NULL) - HTTP_UTIL_ME(matchModified, http_match_modified, NULL) - HTTP_UTIL_ME(matchEtag, http_match_etag, NULL) - HTTP_UTIL_ME(cacheLastModified, http_cache_last_modified, NULL) - HTTP_UTIL_ME(cacheEtag, http_cache_etag, NULL) - HTTP_UTIL_ME(chunkedDecode, http_chunked_decode, NULL) - HTTP_UTIL_ME(splitResponse, http_split_response, NULL) - HTTP_UTIL_ME(parseHeaders, http_parse_headers, NULL) - HTTP_UTIL_ME(getRequestHeaders, http_get_request_headers, NULL) -#ifdef HTTP_HAVE_CURL - HTTP_UTIL_ME(get, http_get, http_request_info_ref_3) - HTTP_UTIL_ME(head, http_head, http_request_info_ref_3) - HTTP_UTIL_ME(postData, http_post_data, http_request_info_ref_4) - HTTP_UTIL_ME(postArray, http_post_array, http_request_info_ref_4) -#endif - HTTP_UTIL_ME(authBasic, http_auth_basic, NULL) - HTTP_UTIL_ME(authBasicCallback, http_auth_basic_cb, NULL) - {NULL, NULL, NULL} -}; -/* }}} HttpUtil */ - -/* {{{ HttpMessage */ -zend_class_entry *http_message_ce; -static zend_object_handlers http_message_object_handlers; - -#define HTTP_MSG_PROPHASH_TYPE 276192743LU -#define HTTP_MSG_PROPHASH_HTTP_VERSION 1138628683LU -#define HTTP_MSG_PROPHASH_RAW 2090679983LU -#define HTTP_MSG_PROPHASH_BODY 254474387LU -#define HTTP_MSG_PROPHASH_HEADERS 3199929089LU -#define HTTP_MSG_PROPHASH_NESTED_MESSAGE 3652857165LU -#define HTTP_MSG_PROPHASH_REQUEST_METHOD 1669022159LU -#define HTTP_MSG_PROPHASH_REQUEST_URI 3208695486LU -#define HTTP_MSG_PROPHASH_RESPONSE_STATUS 3857097400LU - -#define http_message_object_read_prop _http_message_object_read_prop -static zval *_http_message_object_read_prop(zval *object, zval *member, int type TSRMLS_DC) -{ - getObjectEx(http_message_object, obj, object); - http_message *msg = obj->message; - zval *return_value; - - if (!EG(scope) || !instanceof_function(EG(scope), obj->zo.ce TSRMLS_CC)) { - zend_error(E_WARNING, "Cannot access protected property %s::$%s", obj->zo.ce->name, Z_STRVAL_P(member)); - return EG(uninitialized_zval_ptr); - } - - ALLOC_ZVAL(return_value); - return_value->refcount = 0; - -#if 0 - fprintf(stderr, "Reading property: %s(%d==%d) (%lu)\n", Z_STRVAL_P(member), Z_STRLEN_P(member), strlen(Z_STRVAL_P(member)), - zend_get_hash_value(Z_STRVAL_P(member), strlen(Z_STRVAL_P(member)) + 1) - ); -#endif - - switch (zend_get_hash_value(Z_STRVAL_P(member), strlen(Z_STRVAL_P(member)) + 1)) - { - case HTTP_MSG_PROPHASH_TYPE: - RETVAL_LONG(msg->type); - break; - - case HTTP_MSG_PROPHASH_HTTP_VERSION: - switch (msg->type) - { - case HTTP_MSG_NONE: - RETVAL_NULL(); - break; - - case HTTP_MSG_REQUEST: - RETVAL_DOUBLE(msg->info.request.http_version); - break; - - case HTTP_MSG_RESPONSE: - RETVAL_DOUBLE(msg->info.response.http_version); - break; - } - break; - - case HTTP_MSG_PROPHASH_RAW: - if (msg->raw) { - if (msg->len) { - RETVAL_STRINGL(msg->raw, msg->len, 1); - } else { - RETVAL_STRINGL(empty_string, 0, 0); - } - } else { - RETVAL_NULL(); - } - break; - - case HTTP_MSG_PROPHASH_BODY: - phpstr_fix(PHPSTR(msg)); - RETVAL_PHPSTR(PHPSTR(msg), 0, 1); - break; - - case HTTP_MSG_PROPHASH_HEADERS: - Z_TYPE_P(return_value) = IS_ARRAY; - Z_ARRVAL_P(return_value) = &msg->hdrs; - break; - - case HTTP_MSG_PROPHASH_NESTED_MESSAGE: - RETVAL_NULL(); - break; - - case HTTP_MSG_PROPHASH_REQUEST_METHOD: - if (msg->type == HTTP_MSG_REQUEST && msg->info.request.method) { - RETVAL_STRING(msg->info.request.method, 1); - } else { - RETVAL_NULL(); - } - break; - - case HTTP_MSG_PROPHASH_REQUEST_URI: - if (msg->type == HTTP_MSG_REQUEST && msg->info.request.URI) { - RETVAL_STRING(msg->info.request.URI, 1); - } else { - RETVAL_NULL(); - } - break; - - case HTTP_MSG_PROPHASH_RESPONSE_STATUS: - if (msg->type == HTTP_MSG_RESPONSE) { - RETVAL_LONG(msg->info.response.status); - } else { - RETVAL_NULL(); - } - break; - - default: - RETVAL_NULL(); - break; - } - - return return_value; -} - -#define http_message_object_write_prop _http_message_object_write_prop -static void _http_message_object_write_prop(zval *object, zval *member, zval *value TSRMLS_DC) -{ - getObjectEx(http_message_object, obj, object); - http_message *msg = obj->message; - - if (!EG(scope) || !instanceof_function(EG(scope), obj->zo.ce TSRMLS_CC)) { - zend_error(E_WARNING, "Cannot access protected property %s::$%s", obj->zo.ce->name, Z_STRVAL_P(member)); - } - -#if 0 - fprintf(stderr, "Writing property: %s(%d==%d) (%lu)\n", Z_STRVAL_P(member), Z_STRLEN_P(member), strlen(Z_STRVAL_P(member)), - zend_get_hash_value(Z_STRVAL_P(member), strlen(Z_STRVAL_P(member)) + 1) - ); -#endif - - switch (zend_get_hash_value(Z_STRVAL_P(member), strlen(Z_STRVAL_P(member)) + 1)) - { - case HTTP_MSG_PROPHASH_TYPE: - msg->type = Z_LVAL_P(value); - break; - - case HTTP_MSG_PROPHASH_HTTP_VERSION: - switch (msg->type) - { - case HTTP_MSG_REQUEST: - msg->info.request.http_version = (float) Z_DVAL_P(value); - break; - - case HTTP_MSG_RESPONSE: - msg->info.response.http_version = (float) Z_DVAL_P(value); - break; - } - break; - - case HTTP_MSG_PROPHASH_RAW: - http_message_dtor(msg); - http_message_parse_ex(msg, Z_STRVAL_P(value), Z_STRLEN_P(value), 1); - break; - - case HTTP_MSG_PROPHASH_BODY: - phpstr_dtor(PHPSTR(msg)); - phpstr_from_string_ex(PHPSTR(msg), Z_STRVAL_P(value), Z_STRLEN_P(value)); - break; - - case HTTP_MSG_PROPHASH_HEADERS: - zend_hash_clean(&msg->hdrs); - zend_hash_copy(&msg->hdrs, Z_ARRVAL_P(value), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); - break; - - case HTTP_MSG_PROPHASH_NESTED_MESSAGE: - break; - - case HTTP_MSG_PROPHASH_REQUEST_METHOD: - if (msg->type == HTTP_MSG_REQUEST) { - if (msg->info.request.method) { - efree(msg->info.request.method); - } - msg->info.request.method = estrndup(Z_STRVAL_P(value), Z_STRLEN_P(value)); - } - break; - - case HTTP_MSG_PROPHASH_REQUEST_URI: - if (msg->type == HTTP_MSG_REQUEST) { - if (msg->info.request.URI) { - efree(msg->info.request.URI); - } - msg->info.request.URI = estrndup(Z_STRVAL_P(value), Z_STRLEN_P(value)); - } - break; - - case HTTP_MSG_PROPHASH_RESPONSE_STATUS: - if (msg->type == HTTP_MSG_RESPONSE) { - msg->info.response.status = Z_LVAL_P(value); - } - break; - } -} - -#define http_message_object_get_props _http_message_object_get_props -static HashTable *_http_message_object_get_props(zval *object TSRMLS_DC) -{ - zval *headers; - getObjectEx(http_message_object, obj, object); - http_message *msg = obj->message; - -#define ASSOC_PROP(obj, ptype, name, val) \ - { \ - zval array; \ - char *m_prop_name; \ - int m_prop_len; \ - Z_ARRVAL(array) = OBJ_PROP(obj); \ - zend_mangle_property_name(&m_prop_name, &m_prop_len, "*", 1, name, lenof(name), 1); \ - add_assoc_ ##ptype## _ex(&array, m_prop_name, sizeof(name)+4, val); \ - } -#define ASSOC_STRING(obj, name, val) ASSOC_STRINGL(obj, name, val, strlen(val)) -#define ASSOC_STRINGL(obj, name, val, len) \ - { \ - zval array; \ - char *m_prop_name; \ - int m_prop_len; \ - Z_ARRVAL(array) = OBJ_PROP(obj); \ - zend_mangle_property_name(&m_prop_name, &m_prop_len, "*", 1, name, lenof(name), 1); \ - add_assoc_stringl_ex(&array, m_prop_name, sizeof(name)+4, val, len, val != empty_string); \ - } - - zend_hash_clean(OBJ_PROP(obj)); - - ASSOC_PROP(obj, long, "type", msg->type); - ASSOC_STRINGL(obj, "raw", msg->raw, msg->len) - ASSOC_STRINGL(obj, "body", PHPSTR_VAL(msg), PHPSTR_LEN(msg)); - - MAKE_STD_ZVAL(headers); - array_init(headers); - - zend_hash_copy(Z_ARRVAL_P(headers), &msg->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); - ASSOC_PROP(obj, zval, "headers", headers); - - switch (msg->type) - { - case HTTP_MSG_REQUEST: - ASSOC_PROP(obj, double, "httpVersion", msg->info.request.http_version); - ASSOC_PROP(obj, long, "responseStatus", 0); - ASSOC_STRING(obj, "requestMethod", msg->info.request.method); - ASSOC_STRING(obj, "requestUri", msg->info.request.URI); - break; - - case HTTP_MSG_RESPONSE: - ASSOC_PROP(obj, double, "httpVersion", msg->info.response.http_version); - ASSOC_PROP(obj, long, "responseStatus", msg->info.response.status); - ASSOC_STRING(obj, "requestMethod", empty_string); - ASSOC_STRING(obj, "requestUri", empty_string); - break; - - case HTTP_MSG_NONE: - default: - ASSOC_PROP(obj, double, "httpVersion", 0.0); - ASSOC_PROP(obj, long, "responseStatus", 0); - ASSOC_STRING(obj, "requestMethod", empty_string); - ASSOC_STRING(obj, "requestUri", empty_string); - break; - } - - return OBJ_PROP(obj); -} - -#define http_message_global_init() _http_message_global_init(TSRMLS_C) -static inline void _http_message_global_init(TSRMLS_D) -{ - http_message_object_handlers.read_property = http_message_object_read_prop; - http_message_object_handlers.write_property = http_message_object_write_prop; - http_message_object_handlers.get_properties = http_message_object_get_props; -} - -#define http_message_declare_default_properties(ce) _http_message_declare_default_properties(ce TSRMLS_CC) -static inline void _http_message_declare_default_properties(zend_class_entry *ce TSRMLS_DC) -{ - DCL_PROP(PROTECTED, long, type, HTTP_MSG_NONE); - - DCL_PROP(PROTECTED, string, raw, ""); - DCL_PROP(PROTECTED, string, body, ""); - - DCL_PROP(PROTECTED, string, requestMethod, ""); - DCL_PROP(PROTECTED, string, requestUri, ""); - DCL_PROP(PROTECTED, long, responseStatus, 0); - - DCL_PROP_N(PROTECTED, httpVersion); - DCL_PROP_N(PROTECTED, headers); - DCL_PROP_N(PROTECTED, nestedMessage); -} - -#define http_message_free_object _http_message_free_object -void _http_message_free_object(zend_object *object TSRMLS_DC) -{ - http_message_object *o = (http_message_object *) object; - - if (OBJ_PROP(o)) { - zend_hash_destroy(OBJ_PROP(o)); - FREE_HASHTABLE(OBJ_PROP(o)); - } - if (o->message) { - http_message_free(o->message); - } - efree(o); -} - -#define http_message_new_object _http_message_new_object -zend_object_value _http_message_new_object(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value ov; - http_message_object *o; - - o = ecalloc(1, sizeof(http_message_object)); - o->zo.ce = ce; - o->message = http_message_new(); - - ALLOC_HASHTABLE(OBJ_PROP(o)); - zend_hash_init(OBJ_PROP(o), 0, NULL, ZVAL_PTR_DTOR, 0); - - ov.handle = zend_objects_store_put(o, (zend_objects_store_dtor_t) zend_objects_destroy_object, http_message_free_object, NULL TSRMLS_CC); - ov.handlers = &http_message_object_handlers; - - return ov; -} - -zend_function_entry http_message_class_methods[] = { - PHP_ME(HttpMessage, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) - PHP_ME(HttpMessage, __destruct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR) - {NULL, NULL, NULL} -}; -/* }}} */ - -/* {{{ HttpResponse */ - -zend_class_entry *http_response_ce; -static zend_object_handlers http_response_object_handlers; - -#define http_response_declare_default_properties(ce) _http_response_declare_default_properties(ce TSRMLS_CC) -static inline void _http_response_declare_default_properties(zend_class_entry *ce TSRMLS_DC) -{ - DCL_PROP(PROTECTED, string, contentType, "application/x-octetstream"); - DCL_PROP(PROTECTED, string, eTag, ""); - DCL_PROP(PROTECTED, string, dispoFile, ""); - DCL_PROP(PROTECTED, string, cacheControl, "public"); - DCL_PROP(PROTECTED, string, data, ""); - DCL_PROP(PROTECTED, string, file, ""); - DCL_PROP(PROTECTED, long, stream, 0); - DCL_PROP(PROTECTED, long, lastModified, 0); - DCL_PROP(PROTECTED, long, dispoInline, 0); - DCL_PROP(PROTECTED, long, cache, 0); - DCL_PROP(PROTECTED, long, gzip, 0); - - DCL_PROP(PRIVATE, long, raw_cache_header, 0); - DCL_PROP(PRIVATE, long, send_mode, -1); -} - -#define http_response_destroy_object _http_response_destroy_object -void _http_response_destroy_object(void *object, zend_object_handle handle TSRMLS_DC) -{ - http_response_object *o = object; - if (OBJ_PROP(o)) { - zend_hash_destroy(OBJ_PROP(o)); - FREE_HASHTABLE(OBJ_PROP(o)); - } - efree(o); -} - -#define http_response_new_object _http_response_new_object -zend_object_value _http_response_new_object(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value ov; - http_response_object *o; - - o = ecalloc(1, sizeof(http_response_object)); - o->zo.ce = ce; - - ALLOC_HASHTABLE(OBJ_PROP(o)); - zend_hash_init(OBJ_PROP(o), 0, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); - - ov.handle = zend_objects_store_put(o, http_response_destroy_object, NULL, NULL TSRMLS_CC); - ov.handlers = &http_response_object_handlers; - - return ov; -} - -zend_function_entry http_response_class_methods[] = { - PHP_ME(HttpResponse, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) -/* PHP_ME(HttpResponse, __destruct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR) -*/ - PHP_ME(HttpResponse, setETag, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpResponse, getETag, NULL, ZEND_ACC_PUBLIC) - - PHP_ME(HttpResponse, setContentDisposition, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpResponse, getContentDisposition, NULL, ZEND_ACC_PUBLIC) - - PHP_ME(HttpResponse, setContentType, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpResponse, getContentType, NULL, ZEND_ACC_PUBLIC) - - PHP_ME(HttpResponse, setCache, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpResponse, getCache, NULL, ZEND_ACC_PUBLIC) - - PHP_ME(HttpResponse, setCacheControl, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpResponse, getCacheControl, NULL, ZEND_ACC_PUBLIC) - - PHP_ME(HttpResponse, setGzip, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpResponse, getGzip, NULL, ZEND_ACC_PUBLIC) - - PHP_ME(HttpResponse, setData, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpResponse, getData, NULL, ZEND_ACC_PUBLIC) - - PHP_ME(HttpResponse, setFile, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpResponse, getFile, NULL, ZEND_ACC_PUBLIC) - - PHP_ME(HttpResponse, setStream, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpResponse, getStream, NULL, ZEND_ACC_PUBLIC) - - PHP_ME(HttpResponse, send, NULL, ZEND_ACC_PUBLIC) - - {NULL, NULL, NULL} -}; -/* }}} */ - -/* {{{ HttpRequest */ -#ifdef HTTP_HAVE_CURL - -zend_class_entry *http_request_ce; -static zend_object_handlers http_request_object_handlers; - -#define http_request_declare_default_properties(ce) _http_request_declare_default_properties(ce TSRMLS_CC) -static inline void _http_request_declare_default_properties(zend_class_entry *ce TSRMLS_DC) -{ - DCL_PROP_N(PROTECTED, options); - DCL_PROP_N(PROTECTED, responseInfo); - DCL_PROP_N(PROTECTED, responseData); - DCL_PROP_N(PROTECTED, postData); - DCL_PROP_N(PROTECTED, postFiles); - - DCL_PROP(PROTECTED, long, method, HTTP_GET); - - DCL_PROP(PROTECTED, string, url, ""); - DCL_PROP(PROTECTED, string, contentType, ""); - DCL_PROP(PROTECTED, string, queryData, ""); - DCL_PROP(PROTECTED, string, postData, ""); -} - -#define http_request_free_object _http_request_free_object -void _http_request_free_object(zend_object /* void */ *object TSRMLS_DC) -{ - http_request_object *o = (http_request_object *) object; - - if (OBJ_PROP(o)) { - zend_hash_destroy(OBJ_PROP(o)); - FREE_HASHTABLE(OBJ_PROP(o)); - } - if (o->ch) { - curl_easy_cleanup(o->ch); - o->ch = NULL; - } - efree(o); -} - -#define http_request_new_object _http_request_new_object -zend_object_value _http_request_new_object(zend_class_entry *ce TSRMLS_DC) -{ - zend_object_value ov; - http_request_object *o; - - o = ecalloc(1, sizeof(http_request_object)); - o->zo.ce = ce; - o->ch = curl_easy_init(); - - ALLOC_HASHTABLE(OBJ_PROP(o)); - zend_hash_init(OBJ_PROP(o), 0, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); - - ov.handle = zend_objects_store_put(o, (zend_objects_store_dtor_t) zend_objects_destroy_object, http_request_free_object, NULL TSRMLS_CC); - ov.handlers = &http_request_object_handlers; - - return ov; -} - -zend_function_entry http_request_class_methods[] = { - PHP_ME(HttpRequest, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) - PHP_ME(HttpRequest, __destruct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR) - - PHP_ME(HttpRequest, setOptions, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, getOptions, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, unsetOptions, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, setSslOptions, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, getSslOptions, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, unsetSslOptions, NULL, ZEND_ACC_PUBLIC) - - PHP_ME(HttpRequest, addHeaders, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, getHeaders, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, unsetHeaders, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, addCookies, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, getCookies, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, unsetCookies, NULL, ZEND_ACC_PUBLIC) - - PHP_ME(HttpRequest, setMethod, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, getMethod, NULL, ZEND_ACC_PUBLIC) - - PHP_ME(HttpRequest, setURL, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, getURL, NULL, ZEND_ACC_PUBLIC) - - PHP_ME(HttpRequest, setContentType, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, getContentType, NULL, ZEND_ACC_PUBLIC) - - PHP_ME(HttpRequest, setQueryData, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, getQueryData, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, addQueryData, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, unsetQueryData, NULL, ZEND_ACC_PUBLIC) - - PHP_ME(HttpRequest, setPostData, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, getPostData, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, addPostData, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, unsetPostData, NULL, ZEND_ACC_PUBLIC) - - PHP_ME(HttpRequest, addPostFile, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, getPostFiles, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, unsetPostFiles, NULL, ZEND_ACC_PUBLIC) - - PHP_ME(HttpRequest, send, NULL, ZEND_ACC_PUBLIC) - - PHP_ME(HttpRequest, getResponseData, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, getResponseHeader, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, getResponseCookie, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, getResponseCode, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, getResponseBody, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, getResponseInfo, NULL, ZEND_ACC_PUBLIC) - - {NULL, NULL, NULL} -}; - -#endif /* HTTP_HAVE_CURL */ -/* }}} */ - -#endif /* ZEND_ENGINE_2 */ - /* {{{ http_module_entry */ zend_module_entry http_module_entry = { #if ZEND_MODULE_API_NO >= 20010901 @@ -804,29 +221,17 @@ PHP_MINIT_FUNCTION(http) return FAILURE; } # endif /* HTTP_CURL_USE_ZEND_MM */ - -# if LIBCURL_VERSION_NUM >= 0x070a05 - REGISTER_LONG_CONSTANT("HTTP_AUTH_BASIC", CURLAUTH_BASIC, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_AUTH_DIGEST", CURLAUTH_DIGEST, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_AUTH_NTLM", CURLAUTH_NTLM, CONST_CS | CONST_PERSISTENT); -# endif /* LIBCURL_VERSION_NUM */ #endif /* HTTP_HAVE_CURL */ #ifdef ZEND_ENGINE_2 - HTTP_REGISTER_CLASS(HttpUtil, http_util, NULL, ZEND_ACC_FINAL_CLASS); - HTTP_REGISTER_CLASS_EX(HttpMessage, http_message, NULL, 0); - HTTP_REGISTER_CLASS_EX(HttpResponse, http_response, NULL, 0); + http_util_object_init(INIT_FUNC_ARGS_PASSTHRU); + http_message_object_init(INIT_FUNC_ARGS_PASSTHRU); + http_response_object_init(INIT_FUNC_ARGS_PASSTHRU); # ifdef HTTP_HAVE_CURL - HTTP_REGISTER_CLASS_EX(HttpRequest, http_request, NULL, 0); - - REGISTER_LONG_CONSTANT("HTTP_GET", HTTP_GET, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_HEAD", HTTP_HEAD, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("HTTP_POST", HTTP_POST, CONST_CS | CONST_PERSISTENT); + http_request_object_init(INIT_FUNC_ARGS_PASSTHRU); # endif /* HTTP_HAVE_CURL */ - - http_message_global_init(); - #endif /* ZEND_ENGINE_2 */ + return SUCCESS; } /* }}} */ diff --git a/http_message_object.c b/http_message_object.c new file mode 100644 index 0000000..08dc0dd --- /dev/null +++ b/http_message_object.c @@ -0,0 +1,361 @@ +/* + +----------------------------------------------------------------------+ + | PECL :: http | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.0 of the PHP license, that | + | is bundled with this package in the file LICENSE, and is available | + | through the world-wide-web at http://www.php.net/license/3_0.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Copyright (c) 2004-2005 Michael Wallner | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "php.h" + +#include "php_http_std_defs.h" +#include "php_http_message_object.h" + +#ifdef ZEND_ENGINE_2 + +#define http_message_object_declare_default_properties() _http_message_object_declare_default_properties(TSRMLS_C) +static inline void _http_message_object_declare_default_properties(TSRMLS_D); +#define http_message_object_read_prop _http_message_object_read_prop +static zval *_http_message_object_read_prop(zval *object, zval *member, int type TSRMLS_DC); +#define http_message_object_write_prop _http_message_object_write_prop +static void _http_message_object_write_prop(zval *object, zval *member, zval *value TSRMLS_DC); +#define http_message_object_get_props _http_message_object_get_props +static HashTable *_http_message_object_get_props(zval *object TSRMLS_DC); + +zend_class_entry *http_message_object_ce; +zend_function_entry http_message_object_fe[] = { + PHP_ME(HttpMessage, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(HttpMessage, __destruct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR) + {NULL, NULL, NULL} +}; +static zend_object_handlers http_message_object_handlers; + +void _http_message_object_init(INIT_FUNC_ARGS) +{ + HTTP_REGISTER_CLASS_EX(HttpMessage, http_message_object, NULL, 0); + + http_message_object_handlers.read_property = http_message_object_read_prop; + http_message_object_handlers.write_property = http_message_object_write_prop; + http_message_object_handlers.get_properties = http_message_object_get_props; +} + +zend_object_value _http_message_object_new(zend_class_entry *ce TSRMLS_DC) +{ + zend_object_value ov; + http_message_object *o; + + o = ecalloc(1, sizeof(http_message_object)); + o->zo.ce = ce; + o->message = http_message_new(); + + ALLOC_HASHTABLE(OBJ_PROP(o)); + zend_hash_init(OBJ_PROP(o), 0, NULL, ZVAL_PTR_DTOR, 0); + + ov.handle = zend_objects_store_put(o, (zend_objects_store_dtor_t) zend_objects_destroy_object, http_message_object_free, NULL TSRMLS_CC); + ov.handlers = &http_message_object_handlers; + + return ov; +} + +static inline void _http_message_object_declare_default_properties(TSRMLS_D) +{ + zend_class_entry *ce = http_message_object_ce; + + DCL_PROP(PROTECTED, long, type, HTTP_MSG_NONE); + + DCL_PROP(PROTECTED, string, raw, ""); + DCL_PROP(PROTECTED, string, body, ""); + + DCL_PROP(PROTECTED, string, requestMethod, ""); + DCL_PROP(PROTECTED, string, requestUri, ""); + DCL_PROP(PROTECTED, long, responseStatus, 0); + + DCL_PROP_N(PROTECTED, httpVersion); + DCL_PROP_N(PROTECTED, headers); + DCL_PROP_N(PROTECTED, nestedMessage); +} + +static void _http_message_object_free(zend_object *object TSRMLS_DC) +{ + http_message_object *o = (http_message_object *) object; + + if (OBJ_PROP(o)) { + zend_hash_destroy(OBJ_PROP(o)); + FREE_HASHTABLE(OBJ_PROP(o)); + } + if (o->message) { + http_message_free(o->message); + } + efree(o); +} + +static zval *_http_message_object_read_prop(zval *object, zval *member, int type TSRMLS_DC) +{ + getObjectEx(http_message_object, obj, object); + http_message *msg = obj->message; + zval *return_value; + + if (!EG(scope) || !instanceof_function(EG(scope), obj->zo.ce TSRMLS_CC)) { + zend_error(E_WARNING, "Cannot access protected property %s::$%s", obj->zo.ce->name, Z_STRVAL_P(member)); + return EG(uninitialized_zval_ptr); + } + + ALLOC_ZVAL(return_value); + return_value->refcount = 0; + +#if 0 + fprintf(stderr, "Reading property: %s(%d==%d) (%lu)\n", Z_STRVAL_P(member), Z_STRLEN_P(member), strlen(Z_STRVAL_P(member)), + zend_get_hash_value(Z_STRVAL_P(member), strlen(Z_STRVAL_P(member)) + 1) + ); +#endif + + switch (zend_get_hash_value(Z_STRVAL_P(member), strlen(Z_STRVAL_P(member)) + 1)) + { + case HTTP_MSG_PROPHASH_TYPE: + RETVAL_LONG(msg->type); + break; + + case HTTP_MSG_PROPHASH_HTTP_VERSION: + switch (msg->type) + { + case HTTP_MSG_NONE: + RETVAL_NULL(); + break; + + case HTTP_MSG_REQUEST: + RETVAL_DOUBLE(msg->info.request.http_version); + break; + + case HTTP_MSG_RESPONSE: + RETVAL_DOUBLE(msg->info.response.http_version); + break; + } + break; + + case HTTP_MSG_PROPHASH_RAW: + if (msg->raw) { + if (msg->len) { + RETVAL_STRINGL(msg->raw, msg->len, 1); + } else { + RETVAL_STRINGL(empty_string, 0, 0); + } + } else { + RETVAL_NULL(); + } + break; + + case HTTP_MSG_PROPHASH_BODY: + phpstr_fix(PHPSTR(msg)); + RETVAL_PHPSTR(PHPSTR(msg), 0, 1); + break; + + case HTTP_MSG_PROPHASH_HEADERS: + Z_TYPE_P(return_value) = IS_ARRAY; + Z_ARRVAL_P(return_value) = &msg->hdrs; + break; + + case HTTP_MSG_PROPHASH_NESTED_MESSAGE: + RETVAL_NULL(); + break; + + case HTTP_MSG_PROPHASH_REQUEST_METHOD: + if (msg->type == HTTP_MSG_REQUEST && msg->info.request.method) { + RETVAL_STRING(msg->info.request.method, 1); + } else { + RETVAL_NULL(); + } + break; + + case HTTP_MSG_PROPHASH_REQUEST_URI: + if (msg->type == HTTP_MSG_REQUEST && msg->info.request.URI) { + RETVAL_STRING(msg->info.request.URI, 1); + } else { + RETVAL_NULL(); + } + break; + + case HTTP_MSG_PROPHASH_RESPONSE_STATUS: + if (msg->type == HTTP_MSG_RESPONSE) { + RETVAL_LONG(msg->info.response.status); + } else { + RETVAL_NULL(); + } + break; + + default: + RETVAL_NULL(); + break; + } + + return return_value; +} + +static void _http_message_object_write_prop(zval *object, zval *member, zval *value TSRMLS_DC) +{ + getObjectEx(http_message_object, obj, object); + http_message *msg = obj->message; + + if (!EG(scope) || !instanceof_function(EG(scope), obj->zo.ce TSRMLS_CC)) { + zend_error(E_WARNING, "Cannot access protected property %s::$%s", obj->zo.ce->name, Z_STRVAL_P(member)); + } + +#if 0 + fprintf(stderr, "Writing property: %s(%d==%d) (%lu)\n", Z_STRVAL_P(member), Z_STRLEN_P(member), strlen(Z_STRVAL_P(member)), + zend_get_hash_value(Z_STRVAL_P(member), strlen(Z_STRVAL_P(member)) + 1) + ); +#endif + + switch (zend_get_hash_value(Z_STRVAL_P(member), strlen(Z_STRVAL_P(member)) + 1)) + { + case HTTP_MSG_PROPHASH_TYPE: + msg->type = Z_LVAL_P(value); + break; + + case HTTP_MSG_PROPHASH_HTTP_VERSION: + switch (msg->type) + { + case HTTP_MSG_REQUEST: + msg->info.request.http_version = (float) Z_DVAL_P(value); + break; + + case HTTP_MSG_RESPONSE: + msg->info.response.http_version = (float) Z_DVAL_P(value); + break; + } + break; + + case HTTP_MSG_PROPHASH_RAW: + http_message_dtor(msg); + http_message_parse_ex(msg, Z_STRVAL_P(value), Z_STRLEN_P(value), 1); + break; + + case HTTP_MSG_PROPHASH_BODY: + phpstr_dtor(PHPSTR(msg)); + phpstr_from_string_ex(PHPSTR(msg), Z_STRVAL_P(value), Z_STRLEN_P(value)); + break; + + case HTTP_MSG_PROPHASH_HEADERS: + zend_hash_clean(&msg->hdrs); + zend_hash_copy(&msg->hdrs, Z_ARRVAL_P(value), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); + break; + + case HTTP_MSG_PROPHASH_NESTED_MESSAGE: + break; + + case HTTP_MSG_PROPHASH_REQUEST_METHOD: + if (msg->type == HTTP_MSG_REQUEST) { + if (msg->info.request.method) { + efree(msg->info.request.method); + } + msg->info.request.method = estrndup(Z_STRVAL_P(value), Z_STRLEN_P(value)); + } + break; + + case HTTP_MSG_PROPHASH_REQUEST_URI: + if (msg->type == HTTP_MSG_REQUEST) { + if (msg->info.request.URI) { + efree(msg->info.request.URI); + } + msg->info.request.URI = estrndup(Z_STRVAL_P(value), Z_STRLEN_P(value)); + } + break; + + case HTTP_MSG_PROPHASH_RESPONSE_STATUS: + if (msg->type == HTTP_MSG_RESPONSE) { + msg->info.response.status = Z_LVAL_P(value); + } + break; + } +} + +static HashTable *_http_message_object_get_props(zval *object TSRMLS_DC) +{ + zval *headers; + getObjectEx(http_message_object, obj, object); + http_message *msg = obj->message; + +#define ASSOC_PROP(obj, ptype, name, val) \ + { \ + zval array; \ + char *m_prop_name; \ + int m_prop_len; \ + Z_ARRVAL(array) = OBJ_PROP(obj); \ + zend_mangle_property_name(&m_prop_name, &m_prop_len, "*", 1, name, lenof(name), 1); \ + add_assoc_ ##ptype## _ex(&array, m_prop_name, sizeof(name)+4, val); \ + } +#define ASSOC_STRING(obj, name, val) ASSOC_STRINGL(obj, name, val, strlen(val)) +#define ASSOC_STRINGL(obj, name, val, len) \ + { \ + zval array; \ + char *m_prop_name; \ + int m_prop_len; \ + Z_ARRVAL(array) = OBJ_PROP(obj); \ + zend_mangle_property_name(&m_prop_name, &m_prop_len, "*", 1, name, lenof(name), 1); \ + add_assoc_stringl_ex(&array, m_prop_name, sizeof(name)+4, val, len, val != empty_string); \ + } + + zend_hash_clean(OBJ_PROP(obj)); + + ASSOC_PROP(obj, long, "type", msg->type); + ASSOC_STRINGL(obj, "raw", msg->raw, msg->len) + ASSOC_STRINGL(obj, "body", PHPSTR_VAL(msg), PHPSTR_LEN(msg)); + + MAKE_STD_ZVAL(headers); + array_init(headers); + + zend_hash_copy(Z_ARRVAL_P(headers), &msg->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); + ASSOC_PROP(obj, zval, "headers", headers); + + switch (msg->type) + { + case HTTP_MSG_REQUEST: + ASSOC_PROP(obj, double, "httpVersion", msg->info.request.http_version); + ASSOC_PROP(obj, long, "responseStatus", 0); + ASSOC_STRING(obj, "requestMethod", msg->info.request.method); + ASSOC_STRING(obj, "requestUri", msg->info.request.URI); + break; + + case HTTP_MSG_RESPONSE: + ASSOC_PROP(obj, double, "httpVersion", msg->info.response.http_version); + ASSOC_PROP(obj, long, "responseStatus", msg->info.response.status); + ASSOC_STRING(obj, "requestMethod", empty_string); + ASSOC_STRING(obj, "requestUri", empty_string); + break; + + case HTTP_MSG_NONE: + default: + ASSOC_PROP(obj, double, "httpVersion", 0.0); + ASSOC_PROP(obj, long, "responseStatus", 0); + ASSOC_STRING(obj, "requestMethod", empty_string); + ASSOC_STRING(obj, "requestUri", empty_string); + break; + } + + return OBJ_PROP(obj); +} + +#endif /* ZEND_ENGINE_2 */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ + diff --git a/http_methods.c b/http_methods.c index 8d11982..6812d7d 100644 --- a/http_methods.c +++ b/http_methods.c @@ -30,6 +30,10 @@ #include "php_http_send_api.h" #include "php_http_url_api.h" +#include "php_http_message_object.h" +#include "php_http_response_object.h" +#include "php_http_request_object.h" + #ifdef ZEND_ENGINE_2 /* {{{ HttpResponse */ @@ -526,7 +530,7 @@ PHP_METHOD(HttpMessage, __construct) int message_len; getObject(http_message_object, obj); http_message *msg = obj->message; - + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z/", &message)) { return; } @@ -541,9 +545,9 @@ PHP_METHOD(HttpMessage, __construct) PHP_METHOD(HttpMessage, __destruct) { getObject(http_message_object, obj); - + NO_ARGS; - + } /* }}} */ diff --git a/http_request_object.c b/http_request_object.c new file mode 100644 index 0000000..5887bf2 --- /dev/null +++ b/http_request_object.c @@ -0,0 +1,172 @@ +/* + +----------------------------------------------------------------------+ + | PECL :: http | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.0 of the PHP license, that | + | is bundled with this package in the file LICENSE, and is available | + | through the world-wide-web at http://www.php.net/license/3_0.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Copyright (c) 2004-2005 Michael Wallner | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#ifdef HTTP_HAVE_CURL +# ifdef PHP_WIN32 +# include +# endif +# include +#endif + +#include "php.h" + +#include "php_http_std_defs.h" +#include "php_http_request_object.h" + +#ifdef ZEND_ENGINE_2 +#ifdef HTTP_HAVE_CURL + +#define http_request_object_declare_default_properties() _http_request_object_declare_default_properties(TSRMLS_C) +static inline void _http_request_object_declare_default_properties(TSRMLS_D); + +zend_class_entry *http_request_object_ce; +zend_function_entry http_request_object_fe[] = { + PHP_ME(HttpRequest, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(HttpRequest, __destruct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR) + + PHP_ME(HttpRequest, setOptions, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, getOptions, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, unsetOptions, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, setSslOptions, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, getSslOptions, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, unsetSslOptions, NULL, ZEND_ACC_PUBLIC) + + PHP_ME(HttpRequest, addHeaders, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, getHeaders, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, unsetHeaders, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, addCookies, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, getCookies, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, unsetCookies, NULL, ZEND_ACC_PUBLIC) + + PHP_ME(HttpRequest, setMethod, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, getMethod, NULL, ZEND_ACC_PUBLIC) + + PHP_ME(HttpRequest, setURL, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, getURL, NULL, ZEND_ACC_PUBLIC) + + PHP_ME(HttpRequest, setContentType, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, getContentType, NULL, ZEND_ACC_PUBLIC) + + PHP_ME(HttpRequest, setQueryData, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, getQueryData, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, addQueryData, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, unsetQueryData, NULL, ZEND_ACC_PUBLIC) + + PHP_ME(HttpRequest, setPostData, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, getPostData, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, addPostData, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, unsetPostData, NULL, ZEND_ACC_PUBLIC) + + PHP_ME(HttpRequest, addPostFile, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, getPostFiles, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, unsetPostFiles, NULL, ZEND_ACC_PUBLIC) + + PHP_ME(HttpRequest, send, NULL, ZEND_ACC_PUBLIC) + + PHP_ME(HttpRequest, getResponseData, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, getResponseHeader, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, getResponseCookie, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, getResponseCode, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, getResponseBody, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, getResponseInfo, NULL, ZEND_ACC_PUBLIC) + + {NULL, NULL, NULL} +}; +static zend_object_handlers http_request_object_handlers; + +void _http_request_object_init(INIT_FUNC_ARGS) +{ + HTTP_REGISTER_CLASS_EX(HttpRequest, http_request_object, NULL, 0); + HTTP_LONG_CONSTANT("HTTP_GET", HTTP_GET); + HTTP_LONG_CONSTANT("HTTP_HEAD", HTTP_HEAD); + HTTP_LONG_CONSTANT("HTTP_POST", HTTP_POST); +# if LIBCURL_VERSION_NUM >= 0x070a05 + HTTP_LONG_CONSTANT("HTTP_AUTH_BASIC", CURLAUTH_BASIC); + HTTP_LONG_CONSTANT("HTTP_AUTH_DIGEST", CURLAUTH_DIGEST); + HTTP_LONG_CONSTANT("HTTP_AUTH_NTLM", CURLAUTH_NTLM); +# endif /* LIBCURL_VERSION_NUM */ +} + +zend_object_value _http_request_object_new(zend_class_entry *ce TSRMLS_DC) +{ + zend_object_value ov; + http_request_object *o; + + o = ecalloc(1, sizeof(http_request_object)); + o->zo.ce = ce; + o->ch = curl_easy_init(); + + ALLOC_HASHTABLE(OBJ_PROP(o)); + zend_hash_init(OBJ_PROP(o), 0, NULL, ZVAL_PTR_DTOR, 0); + zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); + + ov.handle = zend_objects_store_put(o, (zend_objects_store_dtor_t) zend_objects_destroy_object, http_request_object_free, NULL TSRMLS_CC); + ov.handlers = &http_request_object_handlers; + + return ov; +} + +static inline void _http_request_object_declare_default_properties(TSRMLS_D) +{ + zend_class_entry *ce = http_request_object_ce; + + DCL_PROP_N(PROTECTED, options); + DCL_PROP_N(PROTECTED, responseInfo); + DCL_PROP_N(PROTECTED, responseData); + DCL_PROP_N(PROTECTED, postData); + DCL_PROP_N(PROTECTED, postFiles); + + DCL_PROP(PROTECTED, long, method, HTTP_GET); + + DCL_PROP(PROTECTED, string, url, ""); + DCL_PROP(PROTECTED, string, contentType, ""); + DCL_PROP(PROTECTED, string, queryData, ""); + DCL_PROP(PROTECTED, string, postData, ""); +} + +void _http_request_object_free(zend_object *object TSRMLS_DC) +{ + http_request_object *o = (http_request_object *) object; + + if (OBJ_PROP(o)) { + zend_hash_destroy(OBJ_PROP(o)); + FREE_HASHTABLE(OBJ_PROP(o)); + } + if (o->ch) { + curl_easy_cleanup(o->ch); + o->ch = NULL; + } + efree(o); +} + +#endif /* HTTP_HAVE_CURL */ +#endif /* ZEND_ENGINE_2 */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ + diff --git a/http_response_object.c b/http_response_object.c new file mode 100644 index 0000000..aaa51f5 --- /dev/null +++ b/http_response_object.c @@ -0,0 +1,134 @@ +/* + +----------------------------------------------------------------------+ + | PECL :: http | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.0 of the PHP license, that | + | is bundled with this package in the file LICENSE, and is available | + | through the world-wide-web at http://www.php.net/license/3_0.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Copyright (c) 2004-2005 Michael Wallner | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "php.h" + +#include "php_http_std_defs.h" +#include "php_http_response_object.h" + +#ifdef ZEND_ENGINE_2 + +#define http_response_object_declare_default_properties() _http_response_object_declare_default_properties(TSRMLS_C) +static inline void _http_response_object_declare_default_properties(TSRMLS_D); + +zend_class_entry *http_response_object_ce; +zend_function_entry http_response_object_fe[] = { + PHP_ME(HttpResponse, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + + PHP_ME(HttpResponse, setETag, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpResponse, getETag, NULL, ZEND_ACC_PUBLIC) + + PHP_ME(HttpResponse, setContentDisposition, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpResponse, getContentDisposition, NULL, ZEND_ACC_PUBLIC) + + PHP_ME(HttpResponse, setContentType, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpResponse, getContentType, NULL, ZEND_ACC_PUBLIC) + + PHP_ME(HttpResponse, setCache, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpResponse, getCache, NULL, ZEND_ACC_PUBLIC) + + PHP_ME(HttpResponse, setCacheControl, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpResponse, getCacheControl, NULL, ZEND_ACC_PUBLIC) + + PHP_ME(HttpResponse, setGzip, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpResponse, getGzip, NULL, ZEND_ACC_PUBLIC) + + PHP_ME(HttpResponse, setData, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpResponse, getData, NULL, ZEND_ACC_PUBLIC) + + PHP_ME(HttpResponse, setFile, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpResponse, getFile, NULL, ZEND_ACC_PUBLIC) + + PHP_ME(HttpResponse, setStream, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpResponse, getStream, NULL, ZEND_ACC_PUBLIC) + + PHP_ME(HttpResponse, send, NULL, ZEND_ACC_PUBLIC) + + {NULL, NULL, NULL} +}; +static zend_object_handlers http_response_object_handlers; + +void _http_response_object_init(INIT_FUNC_ARGS) +{ + HTTP_REGISTER_CLASS_EX(HttpResponse, http_response_object, NULL, 0); +} + +zend_object_value _http_response_object_new(zend_class_entry *ce TSRMLS_DC) +{ + zend_object_value ov; + http_response_object *o; + + o = ecalloc(1, sizeof(http_response_object)); + o->zo.ce = ce; + + ALLOC_HASHTABLE(OBJ_PROP(o)); + zend_hash_init(OBJ_PROP(o), 0, NULL, ZVAL_PTR_DTOR, 0); + zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); + + ov.handle = zend_objects_store_put(o, (zend_objects_store_dtor_t) zend_objects_destroy_object, http_response_object_free, NULL TSRMLS_CC); + ov.handlers = &http_response_object_handlers; + + return ov; +} + +static inline void _http_response_object_declare_default_properties(TSRMLS_D) +{ + zend_class_entry *ce = http_response_object_ce; + + DCL_PROP(PROTECTED, string, contentType, "application/x-octetstream"); + DCL_PROP(PROTECTED, string, eTag, ""); + DCL_PROP(PROTECTED, string, dispoFile, ""); + DCL_PROP(PROTECTED, string, cacheControl, "public"); + DCL_PROP(PROTECTED, string, data, ""); + DCL_PROP(PROTECTED, string, file, ""); + DCL_PROP(PROTECTED, long, stream, 0); + DCL_PROP(PROTECTED, long, lastModified, 0); + DCL_PROP(PROTECTED, long, dispoInline, 0); + DCL_PROP(PROTECTED, long, cache, 0); + DCL_PROP(PROTECTED, long, gzip, 0); + + DCL_PROP(PRIVATE, long, raw_cache_header, 0); + DCL_PROP(PRIVATE, long, send_mode, -1); +} + +void _http_response_object_free(zend_object *object TSRMLS_DC) +{ + http_response_object *o = (http_response_object *) object; + + if (OBJ_PROP(o)) { + zend_hash_destroy(OBJ_PROP(o)); + FREE_HASHTABLE(OBJ_PROP(o)); + } + efree(o); +} + +#endif /* ZEND_ENGINE_2 */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ + diff --git a/http_util_object.c b/http_util_object.c new file mode 100644 index 0000000..0c6ccf7 --- /dev/null +++ b/http_util_object.c @@ -0,0 +1,93 @@ +/* + +----------------------------------------------------------------------+ + | PECL :: http | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.0 of the PHP license, that | + | is bundled with this package in the file LICENSE, and is available | + | through the world-wide-web at http://www.php.net/license/3_0.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Copyright (c) 2004-2005 Michael Wallner | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "php.h" +#include "php_http.h" +#include "php_http_std_defs.h" +#include "php_http_util_object.h" + +#ifdef ZEND_ENGINE_2 + +#ifdef HTTP_HAVE_CURL +static +ZEND_BEGIN_ARG_INFO(http_request_info_ref_3, 0) + ZEND_ARG_PASS_INFO(0) + ZEND_ARG_PASS_INFO(0) + ZEND_ARG_PASS_INFO(1) +ZEND_END_ARG_INFO(); + +static +ZEND_BEGIN_ARG_INFO(http_request_info_ref_4, 0) + ZEND_ARG_PASS_INFO(0) + ZEND_ARG_PASS_INFO(0) + ZEND_ARG_PASS_INFO(0) + ZEND_ARG_PASS_INFO(1) +ZEND_END_ARG_INFO(); +#endif /* HTTP_HAVE_CURL */ + +zend_class_entry *http_util_object_ce; +zend_function_entry http_util_object_fe[] = { +#define HTTP_UTIL_ME(me, al, ai) ZEND_FENTRY(me, ZEND_FN(al), ai, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + HTTP_UTIL_ME(date, http_date, NULL) + HTTP_UTIL_ME(absoluteURI, http_absolute_uri, NULL) + HTTP_UTIL_ME(negotiateLanguage, http_negotiate_language, NULL) + HTTP_UTIL_ME(negotiateCharset, http_negotiate_charset, NULL) + HTTP_UTIL_ME(redirect, http_redirect, NULL) + HTTP_UTIL_ME(sendStatus, http_send_status, NULL) + HTTP_UTIL_ME(sendLastModified, http_send_last_modified, NULL) + HTTP_UTIL_ME(sendContentType, http_send_content_type, NULL) + HTTP_UTIL_ME(sendContentDisposition, http_send_content_disposition, NULL) + HTTP_UTIL_ME(matchModified, http_match_modified, NULL) + HTTP_UTIL_ME(matchEtag, http_match_etag, NULL) + HTTP_UTIL_ME(cacheLastModified, http_cache_last_modified, NULL) + HTTP_UTIL_ME(cacheEtag, http_cache_etag, NULL) + HTTP_UTIL_ME(chunkedDecode, http_chunked_decode, NULL) + HTTP_UTIL_ME(splitResponse, http_split_response, NULL) + HTTP_UTIL_ME(parseHeaders, http_parse_headers, NULL) + HTTP_UTIL_ME(getRequestHeaders, http_get_request_headers, NULL) +#ifdef HTTP_HAVE_CURL + HTTP_UTIL_ME(get, http_get, http_request_info_ref_3) + HTTP_UTIL_ME(head, http_head, http_request_info_ref_3) + HTTP_UTIL_ME(postData, http_post_data, http_request_info_ref_4) + HTTP_UTIL_ME(postArray, http_post_array, http_request_info_ref_4) +#endif /* HTTP_HAVE_CURL */ + HTTP_UTIL_ME(authBasic, http_auth_basic, NULL) + HTTP_UTIL_ME(authBasicCallback, http_auth_basic_cb, NULL) + {NULL, NULL, NULL} +}; + +void _http_util_object_init(INIT_FUNC_ARGS) +{ + HTTP_REGISTER_CLASS(HttpUtil, http_util_object, NULL, ZEND_ACC_FINAL_CLASS); +} + +#endif /* ZEND_ENGINE_2 */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ + diff --git a/php_http.h b/php_http.h index 571be37..ca29137 100644 --- a/php_http.h +++ b/php_http.h @@ -21,14 +21,35 @@ #define HTTP_PEXT_VERSION "0.8.0-dev" /* make compile on Win32 */ -#include "php_streams.h" +#ifdef HTTP_HAVE_CURL +# ifdef PHP_WIN32 +# include +# endif +# include +#endif #include "ext/standard/md5.h" #include "phpstr/phpstr.h" -#include "php_http_message_api.h" extern zend_module_entry http_module_entry; #define phpext_http_ptr &http_module_entry +ZEND_BEGIN_MODULE_GLOBALS(http) + zend_bool etag_started; + PHP_MD5_CTX etag_md5; + php_stream_statbuf ssb; + char *ctype; + char *etag; + time_t lmod; + char *allowed_methods; +#ifdef HTTP_HAVE_CURL + phpstr curlbuf; +# if LIBCURL_VERSION_NUM < 0x070c00 + char curlerr[CURL_ERROR_SIZE + 1]; +# endif + zend_llist to_free; +#endif /* HTTP_HAVE_CURL */ +ZEND_END_MODULE_GLOBALS(http) + #ifdef ZTS # include "TSRM.h" # define HTTP_G(v) TSRMG(http_globals_id, zend_http_globals *, v) @@ -36,134 +57,6 @@ extern zend_module_entry http_module_entry; # define HTTP_G(v) (http_globals.v) #endif -#ifdef ZEND_ENGINE_2 - -typedef struct { - zend_object zo; - http_message *message; -} http_message_object; - -typedef struct { - zend_object zo; -} http_response_object; - -#ifdef HTTP_HAVE_CURL - -#ifdef PHP_WIN32 -# include -#endif - -#include - -typedef struct { - zend_object zo; - CURL *ch; -} http_request_object; - -typedef enum { - HTTP_GET = 1, - HTTP_HEAD, - HTTP_POST, -} http_request_method; - -#endif /* HTTP_HAVE _CURL */ - -PHP_METHOD(HttpUtil, date); -PHP_METHOD(HttpUtil, absoluteURI); -PHP_METHOD(HttpUtil, negotiateLanguage); -PHP_METHOD(HttpUtil, negotiateCharset); -PHP_METHOD(HttpUtil, redirect); -PHP_METHOD(HttpUtil, sendStatus); -PHP_METHOD(HttpUtil, sendLastModified); -PHP_METHOD(HttpUtil, sendContentType); -PHP_METHOD(HttpUtil, sendContentDisposition); -PHP_METHOD(HttpUtil, matchModified); -PHP_METHOD(HttpUtil, matchEtag); -PHP_METHOD(HttpUtil, cacheLastModified); -PHP_METHOD(HttpUtil, cacheEtag); -PHP_METHOD(HttpUtil, chunkedDecode); -PHP_METHOD(HttpUtil, splitResponse); -PHP_METHOD(HttpUtil, parseHeaders); -PHP_METHOD(HttpUtil, getRequestHeaders); -#ifdef HTTP_HAVE_CURL -PHP_METHOD(HttpUtil, get); -PHP_METHOD(HttpUtil, head); -PHP_METHOD(HttpUtil, postData); -PHP_METHOD(HttpUtil, postArray); -#endif /* HTTP_HAVE_CURL */ -PHP_METHOD(HttpUtil, authBasic); -PHP_METHOD(HttpUtil, authBasicCallback); - -PHP_METHOD(HttpMessage, __construct); -PHP_METHOD(HttpMessage, __destruct); - -PHP_METHOD(HttpResponse, __construct);/* -PHP_METHOD(HttpResponse, __destruct);*/ -PHP_METHOD(HttpResponse, setETag); -PHP_METHOD(HttpResponse, getETag); -PHP_METHOD(HttpResponse, setContentDisposition); -PHP_METHOD(HttpResponse, getContentDisposition); -PHP_METHOD(HttpResponse, setContentType); -PHP_METHOD(HttpResponse, getContentType); -PHP_METHOD(HttpResponse, setCache); -PHP_METHOD(HttpResponse, getCache); -PHP_METHOD(HttpResponse, setCacheControl); -PHP_METHOD(HttpResponse, getCacheControl); -PHP_METHOD(HttpResponse, setGzip); -PHP_METHOD(HttpResponse, getGzip); -PHP_METHOD(HttpResponse, setData); -PHP_METHOD(HttpResponse, getData); -PHP_METHOD(HttpResponse, setFile); -PHP_METHOD(HttpResponse, getFile); -PHP_METHOD(HttpResponse, setStream); -PHP_METHOD(HttpResponse, getStream); -PHP_METHOD(HttpResponse, send); - -#ifdef HTTP_HAVE_CURL - -PHP_METHOD(HttpRequest, __construct); -PHP_METHOD(HttpRequest, __destruct); -PHP_METHOD(HttpRequest, setOptions); -PHP_METHOD(HttpRequest, getOptions); -PHP_METHOD(HttpRequest, unsetOptions); -PHP_METHOD(HttpRequest, setSslOptions); -PHP_METHOD(HttpRequest, getSslOptions); -PHP_METHOD(HttpRequest, unsetSslOptions); -PHP_METHOD(HttpRequest, addHeaders); -PHP_METHOD(HttpRequest, getHeaders); -PHP_METHOD(HttpRequest, unsetHeaders); -PHP_METHOD(HttpRequest, addCookies); -PHP_METHOD(HttpRequest, getCookies); -PHP_METHOD(HttpRequest, unsetCookies); -PHP_METHOD(HttpRequest, setMethod); -PHP_METHOD(HttpRequest, getMethod); -PHP_METHOD(HttpRequest, setURL); -PHP_METHOD(HttpRequest, getURL); -PHP_METHOD(HttpRequest, setContentType); -PHP_METHOD(HttpRequest, getContentType); -PHP_METHOD(HttpRequest, setQueryData); -PHP_METHOD(HttpRequest, getQueryData); -PHP_METHOD(HttpRequest, addQueryData); -PHP_METHOD(HttpRequest, unsetQueryData); -PHP_METHOD(HttpRequest, setPostData); -PHP_METHOD(HttpRequest, getPostData); -PHP_METHOD(HttpRequest, addPostData); -PHP_METHOD(HttpRequest, unsetPostData); -PHP_METHOD(HttpRequest, addPostFile); -PHP_METHOD(HttpRequest, getPostFiles); -PHP_METHOD(HttpRequest, unsetPostFiles); -PHP_METHOD(HttpRequest, send); -PHP_METHOD(HttpRequest, getResponseData); -PHP_METHOD(HttpRequest, getResponseHeader); -PHP_METHOD(HttpRequest, getResponseCookie); -PHP_METHOD(HttpRequest, getResponseCode); -PHP_METHOD(HttpRequest, getResponseBody); -PHP_METHOD(HttpRequest, getResponseInfo); - -#endif /* HTTP_HAVE_CURL */ - -#endif /* ZEND_ENGINE_2 */ - PHP_FUNCTION(http_test); PHP_FUNCTION(http_date); PHP_FUNCTION(http_absolute_uri); @@ -204,23 +97,6 @@ PHP_RINIT_FUNCTION(http); PHP_RSHUTDOWN_FUNCTION(http); PHP_MINFO_FUNCTION(http); -ZEND_BEGIN_MODULE_GLOBALS(http) - zend_bool etag_started; - PHP_MD5_CTX etag_md5; - php_stream_statbuf ssb; - char *ctype; - char *etag; - time_t lmod; - char *allowed_methods; -#ifdef HTTP_HAVE_CURL - phpstr curlbuf; -# if LIBCURL_VERSION_NUM < 0x070c00 - char curlerr[CURL_ERROR_SIZE + 1]; -# endif - zend_llist to_free; -#endif /* HTTP_HAVE_CURL */ -ZEND_END_MODULE_GLOBALS(http) - #endif /* PHP_HTTP_H */ /* diff --git a/php_http_message_object.h b/php_http_message_object.h new file mode 100644 index 0000000..1d1a5ec --- /dev/null +++ b/php_http_message_object.h @@ -0,0 +1,53 @@ +/* + +----------------------------------------------------------------------+ + | PECL :: http | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.0 of the PHP license, that | + | is bundled with this package in the file LICENSE, and is available | + | through the world-wide-web at http://www.php.net/license/3_0.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Copyright (c) 2004-2005 Michael Wallner | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + +#ifndef PHP_HTTP_MESSAGE_OBJECT_H +#define PHP_HTTP_MESSAGE_OBJECT_H +#ifdef ZEND_ENGINE_2 + +#include "php_http_message_api.h" + +typedef struct { + zend_object zo; + http_message *message; +} http_message_object; + +extern zend_class_entry *http_message_object_ce; +extern zend_function_entry http_message_object_fe[]; + +#define http_message_object_init _http_message_object_init +extern void _http_message_object_init(INIT_FUNC_ARGS); +#define http_message_object_new _http_message_object_new +extern zend_object_value _http_message_object_new(zend_class_entry *ce TSRMLS_DC); +#define http_message_object_free _http_message_object_free +extern void _http_message_object_free(zend_object *object TSRMLS_DC); + +#define HTTP_MSG_PROPHASH_TYPE 276192743LU +#define HTTP_MSG_PROPHASH_HTTP_VERSION 1138628683LU +#define HTTP_MSG_PROPHASH_RAW 2090679983LU +#define HTTP_MSG_PROPHASH_BODY 254474387LU +#define HTTP_MSG_PROPHASH_HEADERS 3199929089LU +#define HTTP_MSG_PROPHASH_NESTED_MESSAGE 3652857165LU +#define HTTP_MSG_PROPHASH_REQUEST_METHOD 1669022159LU +#define HTTP_MSG_PROPHASH_REQUEST_URI 3208695486LU +#define HTTP_MSG_PROPHASH_RESPONSE_STATUS 3857097400LU + +PHP_METHOD(HttpMessage, __construct); +PHP_METHOD(HttpMessage, __destruct); + +#endif +#endif diff --git a/php_http_request_object.h b/php_http_request_object.h new file mode 100644 index 0000000..7cd3e74 --- /dev/null +++ b/php_http_request_object.h @@ -0,0 +1,101 @@ +/* + +----------------------------------------------------------------------+ + | PECL :: http | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.0 of the PHP license, that | + | is bundled with this package in the file LICENSE, and is available | + | through the world-wide-web at http://www.php.net/license/3_0.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Copyright (c) 2004-2005 Michael Wallner | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + +#ifndef PHP_HTTP_REQUEST_OBJECT_H +#define PHP_HTTP_REQUEST_OBJECT_H +#ifdef HTTP_HAVE_CURL +#ifdef ZEND_ENGINE_2 + +#ifdef PHP_WIN32 +# include +#endif + +#include + +typedef struct { + zend_object zo; + CURL *ch; +} http_request_object; + +typedef enum { + HTTP_GET = 1, + HTTP_HEAD, + HTTP_POST, +} http_request_method; + +extern zend_class_entry *http_request_object_ce; +extern zend_function_entry http_request_object_fe[]; + +#define http_request_object_init _http_request_object_init +extern void _http_request_object_init(INIT_FUNC_ARGS); +#define http_request_object_new _http_request_object_new +extern zend_object_value _http_request_object_new(zend_class_entry *ce TSRMLS_DC); +#define http_request_object_free _http_request_object_free +extern void _http_request_object_free(zend_object *object TSRMLS_DC); + +PHP_METHOD(HttpRequest, __construct); +PHP_METHOD(HttpRequest, __destruct); +PHP_METHOD(HttpRequest, setOptions); +PHP_METHOD(HttpRequest, getOptions); +PHP_METHOD(HttpRequest, unsetOptions); +PHP_METHOD(HttpRequest, setSslOptions); +PHP_METHOD(HttpRequest, getSslOptions); +PHP_METHOD(HttpRequest, unsetSslOptions); +PHP_METHOD(HttpRequest, addHeaders); +PHP_METHOD(HttpRequest, getHeaders); +PHP_METHOD(HttpRequest, unsetHeaders); +PHP_METHOD(HttpRequest, addCookies); +PHP_METHOD(HttpRequest, getCookies); +PHP_METHOD(HttpRequest, unsetCookies); +PHP_METHOD(HttpRequest, setMethod); +PHP_METHOD(HttpRequest, getMethod); +PHP_METHOD(HttpRequest, setURL); +PHP_METHOD(HttpRequest, getURL); +PHP_METHOD(HttpRequest, setContentType); +PHP_METHOD(HttpRequest, getContentType); +PHP_METHOD(HttpRequest, setQueryData); +PHP_METHOD(HttpRequest, getQueryData); +PHP_METHOD(HttpRequest, addQueryData); +PHP_METHOD(HttpRequest, unsetQueryData); +PHP_METHOD(HttpRequest, setPostData); +PHP_METHOD(HttpRequest, getPostData); +PHP_METHOD(HttpRequest, addPostData); +PHP_METHOD(HttpRequest, unsetPostData); +PHP_METHOD(HttpRequest, addPostFile); +PHP_METHOD(HttpRequest, getPostFiles); +PHP_METHOD(HttpRequest, unsetPostFiles); +PHP_METHOD(HttpRequest, send); +PHP_METHOD(HttpRequest, getResponseData); +PHP_METHOD(HttpRequest, getResponseHeader); +PHP_METHOD(HttpRequest, getResponseCookie); +PHP_METHOD(HttpRequest, getResponseCode); +PHP_METHOD(HttpRequest, getResponseBody); +PHP_METHOD(HttpRequest, getResponseInfo); + +#endif +#endif +#endif + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ + diff --git a/php_http_response_object.h b/php_http_response_object.h new file mode 100644 index 0000000..9767b5a --- /dev/null +++ b/php_http_response_object.h @@ -0,0 +1,68 @@ +/* + +----------------------------------------------------------------------+ + | PECL :: http | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.0 of the PHP license, that | + | is bundled with this package in the file LICENSE, and is available | + | through the world-wide-web at http://www.php.net/license/3_0.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Copyright (c) 2004-2005 Michael Wallner | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + +#ifndef PHP_HTTP_RESPONSE_OBJECT_H +#define PHP_HTTP_RESPONSE_OBJECT_H +#ifdef ZEND_ENGINE_2 + +typedef struct { + zend_object zo; +} http_response_object; + +extern zend_class_entry *http_response_object_ce; +extern zend_function_entry http_response_object_fe[]; + +#define http_response_object_init _http_response_object_init +extern void _http_response_object_init(INIT_FUNC_ARGS); +#define http_response_object_new _http_response_object_new +extern zend_object_value _http_response_object_new(zend_class_entry *ce TSRMLS_DC); +#define http_response_object_free _http_response_object_free +extern void _http_response_object_free(zend_object *object TSRMLS_DC); + +PHP_METHOD(HttpResponse, __construct); +PHP_METHOD(HttpResponse, setETag); +PHP_METHOD(HttpResponse, getETag); +PHP_METHOD(HttpResponse, setContentDisposition); +PHP_METHOD(HttpResponse, getContentDisposition); +PHP_METHOD(HttpResponse, setContentType); +PHP_METHOD(HttpResponse, getContentType); +PHP_METHOD(HttpResponse, setCache); +PHP_METHOD(HttpResponse, getCache); +PHP_METHOD(HttpResponse, setCacheControl); +PHP_METHOD(HttpResponse, getCacheControl); +PHP_METHOD(HttpResponse, setGzip); +PHP_METHOD(HttpResponse, getGzip); +PHP_METHOD(HttpResponse, setData); +PHP_METHOD(HttpResponse, getData); +PHP_METHOD(HttpResponse, setFile); +PHP_METHOD(HttpResponse, getFile); +PHP_METHOD(HttpResponse, setStream); +PHP_METHOD(HttpResponse, getStream); +PHP_METHOD(HttpResponse, send); + +#endif +#endif + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ + diff --git a/php_http_std_defs.h b/php_http_std_defs.h index 4d9523d..e79a9b0 100644 --- a/php_http_std_defs.h +++ b/php_http_std_defs.h @@ -83,25 +83,27 @@ typedef int STATUS; #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) /* }}} */ +#define HTTP_LONG_CONSTANT(name, const) REGISTER_LONG_CONSTANT(name, const, CONST_CS | CONST_PERSISTENT); + /* {{{ objects & properties */ #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; \ + INIT_CLASS_ENTRY(ce, #classname, name## _fe); \ + ce.create_object = name## _new; \ 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); \ + memcpy(& name## _handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); \ + name## _declare_default_properties(); \ } # define HTTP_REGISTER_CLASS(classname, name, parent, flags) \ { \ zend_class_entry ce; \ - INIT_CLASS_ENTRY(ce, #classname, name## _class_methods); \ + INIT_CLASS_ENTRY(ce, #classname, name## _fe); \ ce.create_object = NULL; \ name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \ name## _ce->ce_flags |= flags; \ diff --git a/php_http_util_object.h b/php_http_util_object.h new file mode 100644 index 0000000..08f42b6 --- /dev/null +++ b/php_http_util_object.h @@ -0,0 +1,65 @@ +/* + +----------------------------------------------------------------------+ + | PECL :: http | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.0 of the PHP license, that | + | is bundled with this package in the file LICENSE, and is available | + | through the world-wide-web at http://www.php.net/license/3_0.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Copyright (c) 2004-2005 Michael Wallner | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + +#ifndef PHP_HTTP_UTIL_OBJECT_H +#define PHP_HTTP_UTIL_OBJECT_H +#ifdef ZEND_ENGINE_2 + +extern zend_class_entry *http_util_object_ce; +extern zend_function_entry http_util_object_fe[]; + +#define http_util_object_init _http_util_object_init +extern void _http_util_object_init(INIT_FUNC_ARGS); + +PHP_METHOD(HttpUtil, date); +PHP_METHOD(HttpUtil, absoluteURI); +PHP_METHOD(HttpUtil, negotiateLanguage); +PHP_METHOD(HttpUtil, negotiateCharset); +PHP_METHOD(HttpUtil, redirect); +PHP_METHOD(HttpUtil, sendStatus); +PHP_METHOD(HttpUtil, sendLastModified); +PHP_METHOD(HttpUtil, sendContentType); +PHP_METHOD(HttpUtil, sendContentDisposition); +PHP_METHOD(HttpUtil, matchModified); +PHP_METHOD(HttpUtil, matchEtag); +PHP_METHOD(HttpUtil, cacheLastModified); +PHP_METHOD(HttpUtil, cacheEtag); +PHP_METHOD(HttpUtil, chunkedDecode); +PHP_METHOD(HttpUtil, splitResponse); +PHP_METHOD(HttpUtil, parseHeaders); +PHP_METHOD(HttpUtil, getRequestHeaders); +#ifdef HTTP_HAVE_CURL +PHP_METHOD(HttpUtil, get); +PHP_METHOD(HttpUtil, head); +PHP_METHOD(HttpUtil, postData); +PHP_METHOD(HttpUtil, postArray); +#endif /* HTTP_HAVE_CURL */ +PHP_METHOD(HttpUtil, authBasic); +PHP_METHOD(HttpUtil, authBasicCallback); + +#endif +#endif + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ + -- 2.30.2