- use OBJ_PROP_CE macro
[m6w6/ext-http] / http_request_object.c
index c5fd2936b76688d74f0e1ed7e3e3bd2b969b8e88..6dc29b8cf5175de8268b8592da71a2c991ca1367 100644 (file)
@@ -220,9 +220,6 @@ HTTP_BEGIN_ARGS(methodExists, 1)
        HTTP_ARG_VAL(method, 0)
 HTTP_END_ARGS;
 
-#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);
-
 #define OBJ_PROP_CE http_request_object_ce
 zend_class_entry *http_request_object_ce;
 zend_function_entry http_request_object_fe[] = {
@@ -310,60 +307,6 @@ PHP_MINIT_FUNCTION(http_request_object)
 {
        HTTP_REGISTER_CLASS_EX(HttpRequest, http_request_object, NULL, 0);
        http_request_object_handlers.clone_obj = _http_request_object_clone_obj;
-       return SUCCESS;
-}
-
-zend_object_value _http_request_object_new(zend_class_entry *ce TSRMLS_DC)
-{
-       return http_request_object_new_ex(ce, NULL, NULL);
-}
-
-zend_object_value _http_request_object_new_ex(zend_class_entry *ce, CURL *ch, http_request_object **ptr TSRMLS_DC)
-{
-       zend_object_value ov;
-       http_request_object *o;
-
-       o = ecalloc(1, sizeof(http_request_object));
-       o->zo.ce = ce;
-       o->request = http_request_init_ex(NULL, ch, 0, NULL);
-       
-       if (ptr) {
-               *ptr = o;
-       }
-
-       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 = putObject(http_request_object, o);
-       ov.handlers = &http_request_object_handlers;
-
-       return ov;
-}
-
-zend_object_value _http_request_object_clone_obj(zval *this_ptr TSRMLS_DC)
-{
-       zend_object *old_zo;
-       zend_object_value new_ov;
-       http_request_object *new_obj;
-       getObject(http_request_object, old_obj);
-       
-       old_zo = zend_objects_get_address(this_ptr TSRMLS_CC);
-       new_ov = http_request_object_new_ex(old_zo->ce, NULL, &new_obj);
-       if (old_obj->request->ch) {
-               http_curl_init_ex(curl_easy_duphandle(old_obj->request->ch), new_obj->request);
-       }
-       
-       zend_objects_clone_members(&new_obj->zo, new_ov, old_zo, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);
-       phpstr_append(&new_obj->request->conv.request, old_obj->request->conv.request.data, old_obj->request->conv.request.used);
-       phpstr_append(&new_obj->request->conv.response, old_obj->request->conv.response.data, old_obj->request->conv.response.used);
-       
-       return new_ov;
-}
-
-static inline void _http_request_object_declare_default_properties(TSRMLS_D)
-{
-       zend_class_entry *ce = http_request_object_ce;
 
        DCL_PROP_N(PRIVATE, options);
        DCL_PROP_N(PRIVATE, postFields);
@@ -386,7 +329,7 @@ static inline void _http_request_object_declare_default_properties(TSRMLS_D)
 #ifndef WONKY
        /*
         * Request Method Constants
-        */
+       */
        /* HTTP/1.1 */
        DCL_CONST(long, "METH_GET", HTTP_GET);
        DCL_CONST(long, "METH_HEAD", HTTP_HEAD);
@@ -419,19 +362,80 @@ static inline void _http_request_object_declare_default_properties(TSRMLS_D)
        /* WebDAV Access Control - RFC 3744 */
        DCL_CONST(long, "METH_ACL", HTTP_ACL);
 
-       /* cURL HTTP protocol versions */
+       /*
+       * HTTP Protocol Version Constants
+       */
        DCL_CONST(long, "VERSION_1_0", CURL_HTTP_VERSION_1_0);
        DCL_CONST(long, "VERSION_1_1", CURL_HTTP_VERSION_1_1);
        DCL_CONST(long, "VERSION_NONE", CURL_HTTP_VERSION_NONE);
 
        /*
-        * Auth Constants
-        */
+       * Auth Constants
+       */
        DCL_CONST(long, "AUTH_BASIC", CURLAUTH_BASIC);
        DCL_CONST(long, "AUTH_DIGEST", CURLAUTH_DIGEST);
        DCL_CONST(long, "AUTH_NTLM", CURLAUTH_NTLM);
        DCL_CONST(long, "AUTH_ANY", CURLAUTH_ANY);
+       
+       /*
+       * Proxy Type Constants
+       */
+#      if HTTP_CURL_VERSION(7,15,2)
+       DCL_CONST(long, "PROXY_SOCKS4", CURLPROXY_SOCKS4);
+#      endif
+       DCL_CONST(long, "PROXY_SOCKS5", CURLPROXY_SOCKS5);
+       DCL_CONST(long, "PROXY_HTTP", CURLPROXY_HTTP);
 #endif /* WONKY */
+       
+       return SUCCESS;
+}
+
+zend_object_value _http_request_object_new(zend_class_entry *ce TSRMLS_DC)
+{
+       return http_request_object_new_ex(ce, NULL, NULL);
+}
+
+zend_object_value _http_request_object_new_ex(zend_class_entry *ce, CURL *ch, http_request_object **ptr TSRMLS_DC)
+{
+       zend_object_value ov;
+       http_request_object *o;
+
+       o = ecalloc(1, sizeof(http_request_object));
+       o->zo.ce = ce;
+       o->request = http_request_init_ex(NULL, ch, 0, NULL);
+       
+       if (ptr) {
+               *ptr = o;
+       }
+
+       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 = putObject(http_request_object, o);
+       ov.handlers = &http_request_object_handlers;
+
+       return ov;
+}
+
+zend_object_value _http_request_object_clone_obj(zval *this_ptr TSRMLS_DC)
+{
+       zend_object *old_zo;
+       zend_object_value new_ov;
+       http_request_object *new_obj;
+       getObject(http_request_object, old_obj);
+       
+       old_zo = zend_objects_get_address(this_ptr TSRMLS_CC);
+       new_ov = http_request_object_new_ex(old_zo->ce, NULL, &new_obj);
+       if (old_obj->request->ch) {
+               http_curl_init_ex(curl_easy_duphandle(old_obj->request->ch), new_obj->request);
+       }
+       
+       zend_objects_clone_members(&new_obj->zo, new_ov, old_zo, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);
+       phpstr_append(&new_obj->request->conv.request, old_obj->request->conv.request.data, old_obj->request->conv.request.used);
+       phpstr_append(&new_obj->request->conv.response, old_obj->request->conv.response.data, old_obj->request->conv.response.used);
+       
+       return new_ov;
 }
 
 void _http_request_object_free(zend_object *object TSRMLS_DC)