let the ctor honor the options array too
[m6w6/ext-http] / php_http_request_factory.c
index f0e6680e6b19207c6ba76b1b1009aec037432213..8d18ab1d4b8a52b189cc12def483e2bc70b9658a 100644 (file)
@@ -1,9 +1,18 @@
+/*
+    +--------------------------------------------------------------------+
+    | PECL :: http                                                       |
+    +--------------------------------------------------------------------+
+    | Redistribution and use in source and binary forms, with or without |
+    | modification, are permitted provided that the conditions mentioned |
+    | in the accompanying LICENSE file are met.                          |
+    +--------------------------------------------------------------------+
+    | Copyright (c) 2004-2011, Michael Wallner <mike@php.net>            |
+    +--------------------------------------------------------------------+
+*/
+
+#include "php_http_api.h"
 
-#include "php_http.h"
-
-#include <ext/standard/php_string.h>
 #include <ext/spl/spl_observer.h>
-#include <Zend/zend_interfaces.h>
 
 /*
  * array of name => php_http_request_factory_driver_t*
@@ -64,7 +73,6 @@ PHP_HTTP_BEGIN_ARGS(createDataShare, 0)
        PHP_HTTP_ARG_OBJ(http\\Request, request2, 1)
        PHP_HTTP_ARG_OBJ(http\\Request, requestN, 1)
 PHP_HTTP_END_ARGS;
-PHP_HTTP_EMPTY_ARGS(getGlobalDataShareInstance);
 PHP_HTTP_EMPTY_ARGS(getDriver);
 PHP_HTTP_EMPTY_ARGS(getAvailableDrivers);
 
@@ -74,7 +82,6 @@ zend_function_entry php_http_request_factory_method_entry[] = {
        PHP_HTTP_REQUEST_FACTORY_ME(createRequest, ZEND_ACC_PUBLIC)
        PHP_HTTP_REQUEST_FACTORY_ME(createPool, ZEND_ACC_PUBLIC)
        PHP_HTTP_REQUEST_FACTORY_ME(createDataShare, ZEND_ACC_PUBLIC)
-       PHP_HTTP_REQUEST_FACTORY_ME(getGlobalDataShareInstance, ZEND_ACC_PUBLIC)
        PHP_HTTP_REQUEST_FACTORY_ME(getDriver, ZEND_ACC_PUBLIC)
        PHP_HTTP_REQUEST_FACTORY_ME(getAvailableDrivers, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
 
@@ -106,24 +113,23 @@ PHP_METHOD(HttpRequestFactory, __construct)
 
 PHP_METHOD(HttpRequestFactory, createRequest)
 {
-       char *url_str = NULL;
-       int url_len;
-       long meth = -1;
+       char *meth_str = NULL, *url_str = NULL;
+       int meth_len, url_len;
        zval *options = NULL;
 
        with_error_handling(EH_THROW, php_http_exception_class_entry) {
-               if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!la!", &url_str, &url_len, &meth, &options)) {
+               if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!a!", &url_str, &url_len, &meth_str, &meth_len, &options)) {
                        with_error_handling(EH_THROW, php_http_exception_class_entry) {
                                zval *zdriver, *os;
                                zend_object_value ov;
                                zend_class_entry *class_entry = NULL;
-                               php_http_request_t *req = NULL;
+                               php_http_client_t *req = NULL;
                                php_http_request_factory_driver_t driver;
 
                                class_entry = php_http_request_factory_get_class_entry(getThis(), ZEND_STRL("requestClass") TSRMLS_CC);
 
                                if (!class_entry) {
-                                       class_entry = php_http_request_class_entry;
+                                       class_entry = php_http_client_class_entry;
                                }
 
                                zdriver = zend_read_property(php_http_request_factory_class_entry, getThis(), ZEND_STRL("driver"), 0 TSRMLS_CC);
@@ -140,39 +146,33 @@ PHP_METHOD(HttpRequestFactory, createRequest)
                                                name_len = spprintf(&name_str, 0, "http_request.%s", Z_STRVAL_P(zdriver));
 
                                                if ((pf = php_http_persistent_handle_concede(NULL , name_str, name_len, Z_STRVAL_P(phi), Z_STRLEN_P(phi) TSRMLS_CC))) {
-                                                       php_http_resource_factory_ops_t ops = {
-                                                                       (php_http_resource_factory_handle_ctor_t) php_http_persistent_handle_acquire,
-                                                                       (php_http_resource_factory_handle_copy_t) php_http_persistent_handle_accrete,
-                                                                       (php_http_resource_factory_handle_dtor_t) php_http_persistent_handle_release
-                                                       };
-
-                                                       rf = php_http_resource_factory_init(NULL, &ops, pf, (void (*)(void *)) php_http_persistent_handle_abandon);
+                                                       rf = php_http_resource_factory_init(NULL, php_http_persistent_handle_resource_factory_ops(), pf, (void (*)(void *)) php_http_persistent_handle_abandon);
                                                }
 
                                                efree(name_str);
                                        }
 
-                                       req = php_http_request_init(NULL, driver.request_ops, rf, NULL TSRMLS_CC);
+                                       req = php_http_client_init(NULL, driver.request_ops, rf, NULL TSRMLS_CC);
                                        if (req) {
-                                               if (SUCCESS == php_http_new(&ov, class_entry, (php_http_new_t) php_http_request_object_new_ex, php_http_request_class_entry, req, NULL TSRMLS_CC)) {
+                                               if (SUCCESS == php_http_new(&ov, class_entry, (php_http_new_t) php_http_client_object_new_ex, php_http_client_class_entry, req, NULL TSRMLS_CC)) {
                                                        ZVAL_OBJVAL(return_value, ov, 0);
 
                                                        MAKE_STD_ZVAL(os);
                                                        object_init_ex(os, spl_ce_SplObjectStorage);
-                                                       zend_update_property(php_http_request_class_entry, return_value, ZEND_STRL("observers"), os TSRMLS_CC);
+                                                       zend_update_property(php_http_client_class_entry, return_value, ZEND_STRL("observers"), os TSRMLS_CC);
                                                        zval_ptr_dtor(&os);
 
                                                        if (url_str) {
-                                                               zend_update_property_stringl(php_http_request_class_entry, return_value, ZEND_STRL("url"), url_str, url_len TSRMLS_CC);
+                                                               zend_update_property_stringl(php_http_client_class_entry, return_value, ZEND_STRL("url"), url_str, url_len TSRMLS_CC);
                                                        }
-                                                       if (meth > 0) {
-                                                               zend_update_property_long(php_http_request_class_entry, return_value, ZEND_STRL("method"), meth TSRMLS_CC);
+                                                       if (meth_str) {
+                                                               zend_update_property_stringl(php_http_client_class_entry, return_value, ZEND_STRL("method"), meth_str, meth_len TSRMLS_CC);
                                                        }
                                                        if (options) {
                                                                zend_call_method_with_1_params(&return_value, Z_OBJCE_P(return_value), NULL, "setoptions", NULL, options);
                                                        }
                                                } else {
-                                                       php_http_request_free(&req);
+                                                       php_http_client_free(&req);
                                                }
                                        }
 
@@ -217,13 +217,7 @@ PHP_METHOD(HttpRequestFactory, createPool)
                                                name_len = spprintf(&name_str, 0, "http_request_pool.%s", Z_STRVAL_P(zdriver));
 
                                                if ((pf = php_http_persistent_handle_concede(NULL , name_str, name_len, Z_STRVAL_P(phi), Z_STRLEN_P(phi) TSRMLS_CC))) {
-                                                       php_http_resource_factory_ops_t ops = {
-                                                                       (php_http_resource_factory_handle_ctor_t) php_http_persistent_handle_acquire,
-                                                                       (php_http_resource_factory_handle_copy_t) php_http_persistent_handle_accrete,
-                                                                       (php_http_resource_factory_handle_dtor_t) php_http_persistent_handle_release
-                                                       };
-
-                                                       rf = php_http_resource_factory_init(NULL, &ops, pf, (void (*)(void *)) php_http_persistent_handle_abandon);
+                                                       rf = php_http_resource_factory_init(NULL, php_http_persistent_handle_resource_factory_ops(), pf, (void (*)(void *)) php_http_persistent_handle_abandon);
                                                }
 
                                                efree(name_str);
@@ -234,7 +228,7 @@ PHP_METHOD(HttpRequestFactory, createPool)
                                                if (SUCCESS == php_http_new(&ov, class_entry, (php_http_new_t) php_http_request_pool_object_new_ex, php_http_request_pool_class_entry, pool, NULL TSRMLS_CC)) {
                                                        ZVAL_OBJVAL(return_value, ov, 0);
                                                        for (i = 0; i < argc; ++i) {
-                                                               if (Z_TYPE_PP(argv[i]) == IS_OBJECT && instanceof_function(Z_OBJCE_PP(argv[i]), php_http_request_class_entry TSRMLS_CC)) {
+                                                               if (Z_TYPE_PP(argv[i]) == IS_OBJECT && instanceof_function(Z_OBJCE_PP(argv[i]), php_http_client_class_entry TSRMLS_CC)) {
                                                                        php_http_request_pool_attach(pool, *(argv[i]));
                                                                }
                                                        }
@@ -264,7 +258,7 @@ PHP_METHOD(HttpRequestFactory, createDataShare)
                                zval *zdriver;
                                zend_object_value ov;
                                zend_class_entry *class_entry;
-                               php_http_request_datashare_t *share = NULL;
+                               php_http_client_datashare_t *share = NULL;
                                php_http_request_factory_driver_t driver;
 
                                if (!(class_entry = php_http_request_factory_get_class_entry(getThis(), ZEND_STRL("requestDataShareClass") TSRMLS_CC))) {
@@ -284,24 +278,18 @@ PHP_METHOD(HttpRequestFactory, createDataShare)
                                                name_len = spprintf(&name_str, 0, "http_request_datashare.%s", Z_STRVAL_P(zdriver));
 
                                                if ((pf = php_http_persistent_handle_concede(NULL , name_str, name_len, Z_STRVAL_P(phi), Z_STRLEN_P(phi) TSRMLS_CC))) {
-                                                       php_http_resource_factory_ops_t ops = {
-                                                                       (php_http_resource_factory_handle_ctor_t) php_http_persistent_handle_acquire,
-                                                                       (php_http_resource_factory_handle_copy_t) php_http_persistent_handle_accrete,
-                                                                       (php_http_resource_factory_handle_dtor_t) php_http_persistent_handle_release
-                                                       };
-
-                                                       rf = php_http_resource_factory_init(NULL, &ops, pf, (void (*)(void *)) php_http_persistent_handle_abandon);
+                                                       rf = php_http_resource_factory_init(NULL, php_http_persistent_handle_resource_factory_ops(), pf, (void (*)(void *)) php_http_persistent_handle_abandon);
                                                }
 
                                                efree(name_str);
                                        }
 
-                                       share = php_http_request_datashare_init(NULL, driver.request_datashare_ops, rf, NULL, 0 TSRMLS_CC);
+                                       share = php_http_client_datashare_init(NULL, driver.request_datashare_ops, rf, NULL TSRMLS_CC);
                                        if (share) {
                                                if (SUCCESS == php_http_new(&ov, class_entry, (php_http_new_t) php_http_request_datashare_object_new_ex, php_http_request_datashare_class_entry, share, NULL TSRMLS_CC)) {
                                                        ZVAL_OBJVAL(return_value, ov, 0);
                                                        for (i = 0; i < argc; ++i) {
-                                                               if (Z_TYPE_PP(argv[i]) == IS_OBJECT && instanceof_function(Z_OBJCE_PP(argv[i]), php_http_request_class_entry TSRMLS_CC)) {
+                                                               if (Z_TYPE_PP(argv[i]) == IS_OBJECT && instanceof_function(Z_OBJCE_PP(argv[i]), php_http_client_class_entry TSRMLS_CC)) {
                                                                        php_http_request_datashare_attach(share, *(argv[i]));
                                                                }
                                                        }
@@ -319,48 +307,6 @@ PHP_METHOD(HttpRequestFactory, createDataShare)
        } end_error_handling();
 }
 
-PHP_METHOD(HttpRequestFactory, getGlobalDataShareInstance)
-{
-       with_error_handling(EH_THROW, php_http_exception_class_entry) {
-               if (SUCCESS == zend_parse_parameters_none()) {
-                       with_error_handling(EH_THROW, php_http_exception_class_entry) {
-                               zval *instance = *zend_std_get_static_property(php_http_request_datashare_class_entry, ZEND_STRL("instance"), 0, NULL TSRMLS_CC);
-
-                               if (Z_TYPE_P(instance) != IS_OBJECT) {
-                                       zval *zdriver;
-                                       zend_object_value ov;
-                                       zend_class_entry *class_entry;
-                                       php_http_request_datashare_t *share;
-
-                                       if (!(class_entry = php_http_request_factory_get_class_entry(getThis(), ZEND_STRL("requestDataShareClass") TSRMLS_CC))) {
-                                               class_entry = php_http_request_datashare_class_entry;
-                                       }
-
-                                       if ((zdriver = zend_read_property(php_http_request_factory_class_entry, getThis(), ZEND_STRL("driver"), 0 TSRMLS_CC))
-                                       &&      (IS_STRING == Z_TYPE_P(zdriver))
-                                       &&      (share = php_http_request_datashare_global_get(Z_STRVAL_P(zdriver), Z_STRLEN_P(zdriver) TSRMLS_CC))
-                                       &&      (SUCCESS == php_http_new(&ov, class_entry, (php_http_new_t) php_http_request_datashare_object_new_ex, php_http_request_datashare_class_entry, share, NULL TSRMLS_CC))
-                                       ) {
-                                               MAKE_STD_ZVAL(instance);
-                                               ZVAL_OBJVAL(instance, ov, 0);
-                                               zend_update_static_property(php_http_request_datashare_class_entry, ZEND_STRL("instance"), instance TSRMLS_CC);
-
-                                               if (PHP_HTTP_G->request_datashare.cookie) {
-                                                       zend_update_property_bool(php_http_request_datashare_class_entry, instance, ZEND_STRL("cookie"), PHP_HTTP_G->request_datashare.cookie TSRMLS_CC);
-                                               }
-                                               if (PHP_HTTP_G->request_datashare.dns) {
-                                                       zend_update_property_bool(php_http_request_datashare_class_entry, instance, ZEND_STRL("dns"), PHP_HTTP_G->request_datashare.dns TSRMLS_CC);
-                                               }
-                                       }
-                               }
-
-                               RETVAL_ZVAL(instance, 1, 0);
-                       } end_error_handling();
-               }
-       } end_error_handling();
-}
-
-
 PHP_METHOD(HttpRequestFactory, getDriver)
 {
        if (SUCCESS == zend_parse_parameters_none()) {
@@ -407,3 +353,13 @@ PHP_MSHUTDOWN_FUNCTION(http_request_factory)
        return SUCCESS;
 }
 
+
+/*
+ * 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
+ */
+