don't crash if user extends abstract classes
authorMichael Wallner <mike@php.net>
Thu, 29 Mar 2012 08:22:46 +0000 (08:22 +0000)
committerMichael Wallner <mike@php.net>
Thu, 29 Mar 2012 08:22:46 +0000 (08:22 +0000)
12 files changed:
php_http_client.c
php_http_client.h
php_http_client_curl.c
php_http_client_datashare.c
php_http_client_datashare.h
php_http_client_datashare_curl.c
php_http_client_factory.c
php_http_client_pool.c
php_http_client_pool.h
php_http_client_pool_curl.c
php_http_env.c
php_http_message.c

index 9c4589b922de9ad3dedcf5869d17b9e0caefba92..4bf7d8849e428efb76cb03948c8a745a93aa4401 100644 (file)
@@ -24,7 +24,11 @@ PHP_HTTP_API php_http_client_t *php_http_client_init(php_http_client_t *h, php_h
        memset(h, 0, sizeof(*h));
 
        h->ops = ops;
-       h->rf = rf ? rf : php_http_resource_factory_init(NULL, h->ops->rsrc, h, NULL);
+       if (rf) {
+               h->rf = rf;
+       } else if (ops->rsrc) {
+               h->rf = php_http_resource_factory_init(NULL, h->ops->rsrc, h, NULL);
+       }
        h->buffer = php_http_buffer_init(NULL);
        h->parser = php_http_message_parser_init(NULL TSRMLS_CC);
        h->message = php_http_message_init(NULL, 0 TSRMLS_CC);
@@ -81,7 +85,7 @@ PHP_HTTP_API php_http_client_t *php_http_client_copy(php_http_client_t *from, ph
                if (from->rf) {
                        php_http_resource_factory_addref(from->rf);
                        to->rf = from->rf;
-               } else {
+               } else if (to->ops->rsrc){
                        to->rf = php_http_resource_factory_init(NULL, to->ops->rsrc, to, NULL);
                }
                to->buffer = php_http_buffer_init(NULL);
@@ -180,10 +184,6 @@ PHP_HTTP_BEGIN_ARGS(setRequest, 1)
 PHP_HTTP_END_ARGS;
 PHP_HTTP_EMPTY_ARGS(getRequest);
 
-PHP_HTTP_BEGIN_ARGS(send, 1)
-       PHP_HTTP_ARG_VAL(request, 0)
-PHP_HTTP_END_ARGS;
-
 PHP_HTTP_EMPTY_ARGS(getObservers);
 PHP_HTTP_BEGIN_ARGS(attach, 1)
        PHP_HTTP_ARG_OBJ(SplObserver, observer, 0)
@@ -198,8 +198,14 @@ PHP_HTTP_BEGIN_ARGS(getTransferInfo, 0)
 PHP_HTTP_END_ARGS;
 
 
-zend_class_entry *php_http_client_class_entry;
-zend_function_entry php_http_client_method_entry[] = {
+static zend_class_entry *php_http_client_class_entry;
+
+zend_class_entry *php_http_client_get_class_entry(void)
+{
+       return php_http_client_class_entry;
+}
+
+static zend_function_entry php_http_client_method_entry[] = {
        PHP_HTTP_CLIENT_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
        PHP_HTTP_CLIENT_ME(getObservers, ZEND_ACC_PUBLIC)
        PHP_HTTP_CLIENT_ME(notify, ZEND_ACC_PUBLIC)
@@ -224,7 +230,6 @@ zend_function_entry php_http_client_method_entry[] = {
 
        PHP_HTTP_CLIENT_ME(setRequest, ZEND_ACC_PUBLIC)
        PHP_HTTP_CLIENT_ME(getRequest, ZEND_ACC_PUBLIC)
-       PHP_HTTP_CLIENT_ME(send, ZEND_ACC_PUBLIC)
 
        PHP_HTTP_CLIENT_ME(getResponseMessage, ZEND_ACC_PUBLIC)
        PHP_HTTP_CLIENT_ME(getRequestMessage, ZEND_ACC_PUBLIC)
@@ -244,6 +249,19 @@ zend_object_handlers *php_http_client_get_object_handlers(void)
        return &php_http_client_object_handlers;
 }
 
+static php_http_client_ops_t php_http_client_user_ops = {
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       (php_http_new_t) php_http_client_object_new_ex,
+       php_http_client_get_class_entry
+};
+
 zend_object_value php_http_client_object_new(zend_class_entry *ce TSRMLS_DC)
 {
        return php_http_client_object_new_ex(ce, NULL, NULL TSRMLS_CC);
@@ -254,21 +272,21 @@ zend_object_value php_http_client_object_new_ex(zend_class_entry *ce, php_http_c
        zend_object_value ov;
        php_http_client_object_t *o;
 
-       o = ecalloc(1, sizeof(php_http_client_object_t));
+       o = ecalloc(1, sizeof(*o));
        zend_object_std_init((zend_object *) o, ce TSRMLS_CC);
        object_properties_init((zend_object *) o, ce);
 
+       ov.handle = zend_objects_store_put(o, NULL, php_http_client_object_free, NULL TSRMLS_CC);
+       ov.handlers = &php_http_client_object_handlers;
+
        if (!(o->client = r)) {
-               o->client = php_http_client_init(NULL, NULL, NULL, NULL TSRMLS_CC);
+               o->client = php_http_client_init(NULL, &php_http_client_user_ops, NULL, &ov TSRMLS_CC);
        }
 
        if (ptr) {
                *ptr = o;
        }
 
-       ov.handle = zend_objects_store_put(o, NULL, php_http_client_object_free, NULL TSRMLS_CC);
-       ov.handlers = &php_http_client_object_handlers;
-
        return ov;
 }
 
@@ -292,51 +310,6 @@ void php_http_client_object_free(void *object TSRMLS_DC)
        efree(o);
 }
 
-static inline void php_http_client_object_check_request_content_type(zval *this_ptr TSRMLS_DC)
-{
-       zval *ctype = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("contentType"), 0 TSRMLS_CC);
-
-       if (Z_STRLEN_P(ctype)) {
-               zval **headers, *opts = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("options"), 0 TSRMLS_CC);
-
-               if (    (Z_TYPE_P(opts) == IS_ARRAY) &&
-                               (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), ZEND_STRS("headers"), (void *) &headers)) &&
-                               (Z_TYPE_PP(headers) == IS_ARRAY)) {
-                       zval **ct_header;
-
-                       /* only override if not already set */
-                       if ((SUCCESS != zend_hash_find(Z_ARRVAL_PP(headers), ZEND_STRS("Content-Type"), (void *) &ct_header))) {
-                               add_assoc_stringl(*headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
-                       } else
-                       /* or not a string, zero length string or a string of spaces */
-                       if ((Z_TYPE_PP(ct_header) != IS_STRING) || !Z_STRLEN_PP(ct_header)) {
-                               add_assoc_stringl(*headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
-                       } else {
-                               int i, only_space = 1;
-
-                               /* check for spaces only */
-                               for (i = 0; i < Z_STRLEN_PP(ct_header); ++i) {
-                                       if (!PHP_HTTP_IS_CTYPE(space, Z_STRVAL_PP(ct_header)[i])) {
-                                               only_space = 0;
-                                               break;
-                                       }
-                               }
-                               if (only_space) {
-                                       add_assoc_stringl(*headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
-                               }
-                       }
-               } else {
-                       zval *headers;
-
-                       MAKE_STD_ZVAL(headers);
-                       array_init(headers);
-                       add_assoc_stringl(headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
-                       zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "addheaders", NULL, headers);
-                       zval_ptr_dtor(&headers);
-               }
-       }
-}
-
 static inline zend_object_value php_http_client_object_message(zval *this_ptr, php_http_message_t *msg TSRMLS_DC)
 {
        zend_object_value ov;
@@ -405,72 +378,6 @@ STATUS php_http_client_object_handle_request(zval *zclient, zval **zreq TSRMLS_D
        return SUCCESS;
 }
 
-STATUS php_http_client_object_requesthandler(php_http_client_object_t *obj, zval *this_ptr, char **meth, char **url, php_http_message_body_t **body TSRMLS_DC)
-{
-       zval *zoptions;
-       php_http_client_progress_t *progress;
-
-       /* reset request handle */
-       php_http_client_reset(obj->client);
-       /* reset transfer info */
-       zend_update_property_null(php_http_client_class_entry, getThis(), ZEND_STRL("info") TSRMLS_CC);
-
-       if (meth) {
-               *meth = Z_STRVAL_P(zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("method"), 0 TSRMLS_CC));
-       }
-
-       if (url) {
-               php_url *tmp, qdu = {NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL};
-               zval *zurl = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("url"), 0 TSRMLS_CC);
-               zval *zqdata = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("queryData"), 0 TSRMLS_CC);
-
-               if (Z_STRLEN_P(zqdata)) {
-                       qdu.query = Z_STRVAL_P(zqdata);
-               }
-               php_http_url(0, tmp = php_url_parse(Z_STRVAL_P(zurl)), &qdu, NULL, url, NULL TSRMLS_CC);
-               php_url_free(tmp);
-       }
-
-       if (body) {
-               zval *zbody = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("requestBody"), 0 TSRMLS_CC);
-
-               if (Z_TYPE_P(zbody) == IS_OBJECT) {
-                       *body = ((php_http_message_body_object_t *)zend_object_store_get_object(zbody TSRMLS_CC))->body;
-                       if (*body) {
-                               php_stream_rewind(php_http_message_body_stream(*body));
-                       }
-               }
-       }
-
-       php_http_client_object_check_request_content_type(getThis() TSRMLS_CC);
-       zoptions = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("options"), 0 TSRMLS_CC);
-       php_http_client_setopt(obj->client, PHP_HTTP_CLIENT_OPT_SETTINGS, Z_ARRVAL_P(zoptions));
-
-       if (SUCCESS == php_http_client_getopt(obj->client, PHP_HTTP_CLIENT_OPT_PROGRESS_INFO, &progress)) {
-               if (!progress->callback) {
-                       php_http_client_progress_callback_t *callback = emalloc(sizeof(*callback));
-
-                       callback->type = PHP_HTTP_CLIENT_PROGRESS_CALLBACK_USER;
-                       callback->pass_state = 0;
-                       MAKE_STD_ZVAL(callback->func.user);
-                       array_init(callback->func.user);
-                       Z_ADDREF_P(getThis());
-                       add_next_index_zval(callback->func.user, getThis());
-                       add_next_index_stringl(callback->func.user, ZEND_STRL("notify"), 1);
-
-                       php_http_client_setopt(obj->client, PHP_HTTP_CLIENT_OPT_PROGRESS_CALLBACK, callback);
-               }
-               progress->state.info = "start";
-               php_http_client_progress_notify(progress TSRMLS_CC);
-               progress->state.started = 1;
-       }
-       return SUCCESS;
-}
-
-static inline void empty_response(zval *this_ptr TSRMLS_DC)
-{
-       zend_update_property_null(php_http_client_class_entry, getThis(), ZEND_STRL("responseMessage") TSRMLS_CC);
-}
 
 STATUS php_http_client_object_handle_response(zval *zclient TSRMLS_DC)
 {
@@ -546,78 +453,6 @@ STATUS php_http_client_object_handle_response(zval *zclient TSRMLS_DC)
        return SUCCESS;
 }
 
-STATUS php_http_client_object_responsehandler(php_http_client_object_t *obj, zval *this_ptr TSRMLS_DC)
-{
-       STATUS ret = SUCCESS;
-       zval *info;
-       php_http_message_t *msg;
-       php_http_client_progress_t *progress;
-
-       /* always fetch info */
-       MAKE_STD_ZVAL(info);
-       array_init(info);
-       php_http_client_getopt(obj->client, PHP_HTTP_CLIENT_OPT_TRANSFER_INFO, Z_ARRVAL_P(info));
-       zend_update_property(php_http_client_class_entry, getThis(), ZEND_STRL("transferInfo"), info TSRMLS_CC);
-       zval_ptr_dtor(&info);
-
-       if ((msg = obj->client->message)) {
-               /* update history */
-               if (i_zend_is_true(zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("recordHistory"), 0 TSRMLS_CC))) {
-                       zval *new_hist, *old_hist = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("history"), 0 TSRMLS_CC);
-                       zend_object_value ov = php_http_client_object_message(getThis(), php_http_message_copy(msg, NULL) TSRMLS_CC);
-
-                       MAKE_STD_ZVAL(new_hist);
-                       ZVAL_OBJVAL(new_hist, ov, 0);
-
-                       if (Z_TYPE_P(old_hist) == IS_OBJECT) {
-                               php_http_message_object_prepend(new_hist, old_hist, 1 TSRMLS_CC);
-                       }
-
-                       zend_update_property(php_http_client_class_entry, getThis(), ZEND_STRL("history"), new_hist TSRMLS_CC);
-                       zval_ptr_dtor(&new_hist);
-               }
-
-               /* update response info */
-               if (PHP_HTTP_MESSAGE_TYPE(RESPONSE, msg)) {
-                       zval *message;
-
-                       MAKE_STD_ZVAL(message);
-                       ZVAL_OBJVAL(message, php_http_client_object_message(getThis(), msg TSRMLS_CC), 0);
-                       zend_update_property(php_http_client_class_entry, getThis(), ZEND_STRL("responseMessage"), message TSRMLS_CC);
-                       zval_ptr_dtor(&message);
-
-                       obj->client->message = php_http_message_init(NULL, 0 TSRMLS_CC);
-                       msg = msg->parent;
-               } else {
-                       empty_response(getThis() TSRMLS_CC);
-               }
-       } else {
-               /* update properties with empty values */
-               empty_response(getThis() TSRMLS_CC);
-       }
-
-       while (msg && !PHP_HTTP_MESSAGE_TYPE(REQUEST, msg)) {
-               msg = msg->parent;
-       }
-       if (PHP_HTTP_MESSAGE_TYPE(REQUEST, msg)) {
-               zval *message;
-
-               MAKE_STD_ZVAL(message);
-               ZVAL_OBJVAL(message, php_http_client_object_message(getThis(), php_http_message_copy_ex(msg, NULL, 0) TSRMLS_CC), 0);
-               zend_update_property(php_http_client_class_entry, getThis(), ZEND_STRL("requestMessage"), message TSRMLS_CC);
-               zval_ptr_dtor(&message);
-       }
-
-       if (SUCCESS == php_http_client_getopt(obj->client, PHP_HTTP_CLIENT_OPT_PROGRESS_INFO, &progress)) {
-               progress->state.info = "finished";
-               progress->state.finished = 1;
-               php_http_client_progress_notify(progress TSRMLS_CC);
-       }
-       php_http_client_setopt(obj->client, PHP_HTTP_CLIENT_OPT_PROGRESS_CALLBACK, NULL);
-
-       return ret;
-}
-
 static int apply_pretty_key(void *pDest TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
 {
        zval **zpp = pDest, *arr = va_arg(args, zval *);
@@ -830,17 +665,18 @@ PHP_METHOD(HttpClient, getProgress)
 {
        if (SUCCESS == zend_parse_parameters_none()) {
                php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-               php_http_client_progress_t *progress;
-
-               php_http_client_getopt(obj->client, PHP_HTTP_CLIENT_OPT_PROGRESS_INFO, &progress);
-               object_init(return_value);
-               add_property_bool(return_value, "started", progress->state.started);
-               add_property_bool(return_value, "finished", progress->state.finished);
-               add_property_string(return_value, "info", STR_PTR(progress->state.info), 1);
-               add_property_double(return_value, "dltotal", progress->state.dl.total);
-               add_property_double(return_value, "dlnow", progress->state.dl.now);
-               add_property_double(return_value, "ultotal", progress->state.ul.total);
-               add_property_double(return_value, "ulnow", progress->state.ul.now);
+               php_http_client_progress_t *progress = NULL;
+
+               if (SUCCESS == php_http_client_getopt(obj->client, PHP_HTTP_CLIENT_OPT_PROGRESS_INFO, &progress)) {
+                       object_init(return_value);
+                       add_property_bool(return_value, "started", progress->state.started);
+                       add_property_bool(return_value, "finished", progress->state.finished);
+                       add_property_string(return_value, "info", STR_PTR(progress->state.info), 1);
+                       add_property_double(return_value, "dltotal", progress->state.dl.total);
+                       add_property_double(return_value, "dlnow", progress->state.dl.now);
+                       add_property_double(return_value, "ultotal", progress->state.ul.total);
+                       add_property_double(return_value, "ulnow", progress->state.ul.now);
+               }
        }
 }
 
@@ -1077,7 +913,7 @@ PHP_METHOD(HttpClient, send)
 PHP_MINIT_FUNCTION(http_client)
 {
        PHP_HTTP_REGISTER_CLASS(http\\Client, AbstractClient, http_client, php_http_object_class_entry, ZEND_ACC_ABSTRACT);
-       php_http_client_class_entry->create_object = php_http_object_new;//php_http_client_object_new;
+       php_http_client_class_entry->create_object = php_http_client_object_new;
        memcpy(&php_http_client_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
        php_http_client_object_handlers.clone_obj = php_http_client_object_clone;
 
index 12e557eef59cc9dfa6cad73b5e286c3234840c56..e6428704872cc1a4bcdcb3e0fe3ee44ad13f3fa3 100644 (file)
@@ -166,21 +166,19 @@ typedef struct php_http_client_object {
        php_http_client_t *client;
 } php_http_client_object_t;
 
-extern zend_class_entry *php_http_client_class_entry;
-extern zend_function_entry php_http_client_method_entry[];
+zend_object_value php_http_client_object_new(zend_class_entry *ce TSRMLS_DC);
+zend_object_value php_http_client_object_new_ex(zend_class_entry *ce, php_http_client_t *r, php_http_client_object_t **ptr TSRMLS_DC);
+zend_object_value php_http_client_object_clone(zval *zobject TSRMLS_DC);
+void php_http_client_object_free(void *object TSRMLS_DC);
 
-extern zend_object_value php_http_client_object_new(zend_class_entry *ce TSRMLS_DC);
-extern zend_object_value php_http_client_object_new_ex(zend_class_entry *ce, php_http_client_t *r, php_http_client_object_t **ptr TSRMLS_DC);
-extern zend_object_value php_http_client_object_clone(zval *zobject TSRMLS_DC);
-extern void php_http_client_object_free(void *object TSRMLS_DC);
+zend_class_entry *php_http_client_get_class_entry(void);
+zend_object_handlers *php_http_client_get_object_handlers(void);
 
-extern zend_object_handlers *php_http_client_get_object_handlers(void);
+STATUS php_http_client_object_handle_request(zval *zclient, zval **zreq TSRMLS_DC);
+STATUS php_http_client_object_handle_response(zval *zclient TSRMLS_DC);
 
-extern STATUS php_http_client_object_handle_request(zval *zclient, zval **zreq TSRMLS_DC);
-extern STATUS php_http_client_object_handle_response(zval *zclient TSRMLS_DC);
-
-extern STATUS php_http_client_object_requesthandler(php_http_client_object_t *obj, zval *this_ptr, char **meth, char **url, php_http_message_body_t **body TSRMLS_DC);
-extern STATUS php_http_client_object_responsehandler(php_http_client_object_t *obj, zval *this_ptr TSRMLS_DC);
+STATUS php_http_client_object_requesthandler(php_http_client_object_t *obj, zval *this_ptr, char **meth, char **url, php_http_message_body_t **body TSRMLS_DC);
+STATUS php_http_client_object_responsehandler(php_http_client_object_t *obj, zval *this_ptr TSRMLS_DC);
 
 PHP_METHOD(HttpClient, __construct);
 PHP_METHOD(HttpClient, getObservers);
@@ -210,7 +208,7 @@ PHP_METHOD(HttpClient, clearHistory);
 PHP_METHOD(HttpClient, getResponseMessageClass);
 PHP_METHOD(HttpClient, setResponseMessageClass);
 
-extern PHP_MINIT_FUNCTION(http_client);
+PHP_MINIT_FUNCTION(http_client);
 
 #endif
 
index 554b57c77360ef97eacd08dd9f6a82de5c2105e3..e878e1ea4ca5029bd41bf43bfb67e148480f80df 100644 (file)
@@ -1267,15 +1267,18 @@ PHP_HTTP_API php_http_client_ops_t *php_http_client_curl_get_ops(void)
 }
 
 
-#define PHP_HTTP_BEGIN_ARGS(method, req_args)  PHP_HTTP_BEGIN_ARGS_EX(HttpClientCURL, method, 0, req_args)
-#define PHP_HTTP_EMPTY_ARGS(method)                            PHP_HTTP_EMPTY_ARGS_EX(HttpClientCURL, method, 0)
-#define PHP_HTTP_CURL_ME(method, visibility)   PHP_ME(HttpClientCURL, method, PHP_HTTP_ARGS(HttpClientCURL, method), visibility)
-#define PHP_HTTP_CURL_ALIAS(method, func)      PHP_HTTP_STATIC_ME_ALIAS(method, func, PHP_HTTP_ARGS(HttpClientCURL, method))
-#define PHP_HTTP_CURL_MALIAS(me, al, vis)      ZEND_FENTRY(me, ZEND_MN(HttpClientCURL_##al), PHP_HTTP_ARGS(HttpClientCURL, al), vis)
+#define PHP_HTTP_BEGIN_ARGS(method, req_args)          PHP_HTTP_BEGIN_ARGS_EX(HttpClientCURL, method, 0, req_args)
+#define PHP_HTTP_EMPTY_ARGS(method)                                    PHP_HTTP_EMPTY_ARGS_EX(HttpClientCURL, method, 0)
+#define PHP_HTTP_CLIENT_CURL_ME(method, visibility)    PHP_ME(HttpClientCURL, method, PHP_HTTP_ARGS(HttpClientCURL, method), visibility)
+#define PHP_HTTP_CLIENT_CURL_CLIENT_MALIAS(me, vis)    ZEND_FENTRY(me, ZEND_MN(HttpClient_##me), PHP_HTTP_ARGS(HttpClientCURL, me), vis)
 
+PHP_HTTP_BEGIN_ARGS(send, 1)
+       PHP_HTTP_ARG_VAL(request, 0)
+PHP_HTTP_END_ARGS;
 
 zend_class_entry *php_http_client_curl_class_entry;
 zend_function_entry php_http_client_curl_method_entry[] = {
+       PHP_HTTP_CLIENT_CURL_CLIENT_MALIAS(send, ZEND_ACC_PUBLIC)
        EMPTY_FUNCTION_ENTRY
 };
 
@@ -1314,7 +1317,7 @@ PHP_MINIT_FUNCTION(http_client_curl)
                return FAILURE;
        }
 
-       PHP_HTTP_REGISTER_CLASS(http\\Client, CURL, http_client_curl, php_http_client_class_entry, 0);
+       PHP_HTTP_REGISTER_CLASS(http\\Client, CURL, http_client_curl, php_http_client_get_class_entry(), 0);
        php_http_client_curl_class_entry->create_object = php_http_client_curl_object_new;
 
        /*
index 6cbef6b30b7317ad6161923558d34f2a1c2c5c32..38719ece014916e8311d06e9d28cec8c3e4ba248 100644 (file)
@@ -26,7 +26,11 @@ PHP_HTTP_API php_http_client_datashare_t *php_http_client_datashare_init(php_htt
 
        zend_llist_init(&h->clients, sizeof(zval *), ZVAL_PTR_DTOR, 0);
        h->ops = ops;
-       h->rf = rf ? rf : php_http_resource_factory_init(NULL, h->ops->rsrc, NULL, NULL);
+       if (rf) {
+               h->rf = rf;
+       } else if (ops->rsrc) {
+               h->rf = php_http_resource_factory_init(NULL, h->ops->rsrc, h, NULL);
+       }
        TSRMLS_SET_CTX(h->ts);
 
        if (h->ops->init) {
@@ -145,8 +149,14 @@ PHP_HTTP_END_ARGS;
 
 static void php_http_client_datashare_object_write_prop(zval *object, zval *member, zval *value, const zend_literal *literal_key TSRMLS_DC);
 
-zend_class_entry *php_http_client_datashare_class_entry;
-zend_function_entry php_http_client_datashare_method_entry[] = {
+static zend_class_entry *php_http_client_datashare_class_entry;
+
+zend_class_entry *php_http_client_datashare_get_class_entry(void)
+{
+       return php_http_client_datashare_class_entry;
+}
+
+static zend_function_entry php_http_client_datashare_method_entry[] = {
        PHP_HTTP_RSHARE_ME(__destruct, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR)
        PHP_HTTP_RSHARE_ME(count, ZEND_ACC_PUBLIC)
        PHP_HTTP_RSHARE_ME(attach, ZEND_ACC_PUBLIC)
@@ -161,7 +171,24 @@ zend_object_handlers *php_http_client_datashare_get_object_handlers(void)
 {
        return &php_http_client_datashare_object_handlers;
 }
+static STATUS setopt(struct php_http_client_datashare *h, php_http_client_datashare_setopt_opt_t opt, void *arg)
+{
+       return SUCCESS;
+}
 
+static php_http_client_datashare_ops_t php_http_client_datashare_user_ops = {
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       setopt,
+       (php_http_new_t) php_http_client_datashare_object_new_ex,
+       php_http_client_datashare_get_class_entry
+
+};
 zend_object_value php_http_client_datashare_object_new(zend_class_entry *ce TSRMLS_DC)
 {
        return php_http_client_datashare_object_new_ex(ce, NULL, NULL TSRMLS_CC);
@@ -176,19 +203,17 @@ zend_object_value php_http_client_datashare_object_new_ex(zend_class_entry *ce,
        zend_object_std_init((zend_object *) o, ce TSRMLS_CC);
        object_properties_init((zend_object *) o, ce);
 
-       if (share) {
-               o->share = share;
-       } else {
-               o->share = php_http_client_datashare_init(NULL, NULL, NULL, NULL TSRMLS_CC);
+       ov.handle = zend_objects_store_put(o, NULL, php_http_client_datashare_object_free, NULL TSRMLS_CC);
+       ov.handlers = &php_http_client_datashare_object_handlers;
+
+       if (!(o->share = share)) {
+               o->share = php_http_client_datashare_init(NULL, &php_http_client_datashare_user_ops, NULL, &ov TSRMLS_CC);
        }
 
        if (ptr) {
                *ptr = o;
        }
 
-       ov.handle = zend_objects_store_put(o, NULL, php_http_client_datashare_object_free, NULL TSRMLS_CC);
-       ov.handlers = &php_http_client_datashare_object_handlers;
-
        return ov;
 }
 
@@ -266,7 +291,7 @@ PHP_METHOD(HttpClientDataShare, attach)
 {
        zval *client;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &client, php_http_client_class_entry)) {
+       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &client, php_http_client_get_class_entry())) {
                php_http_client_datashare_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
                RETURN_SUCCESS(php_http_client_datashare_attach(obj->share, client));
@@ -279,7 +304,7 @@ PHP_METHOD(HttpClientDataShare, detach)
 {
        zval *client;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &client, php_http_client_class_entry)) {
+       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &client, php_http_client_get_class_entry())) {
                php_http_client_datashare_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
                RETURN_SUCCESS(php_http_client_datashare_detach(obj->share, client));
@@ -301,7 +326,7 @@ PHP_METHOD(HttpClientDataShare, reset)
 PHP_MINIT_FUNCTION(http_client_datashare)
 {
        PHP_HTTP_REGISTER_CLASS(http\\Client\\DataShare, AbstractDataShare, http_client_datashare, php_http_object_class_entry, 0);
-       php_http_client_datashare_class_entry->create_object = php_http_object_new;//php_http_client_datashare_object_new;
+       php_http_client_datashare_class_entry->create_object = php_http_client_datashare_object_new;
        memcpy(&php_http_client_datashare_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
        php_http_client_datashare_object_handlers.clone_obj = NULL;
        php_http_client_datashare_object_handlers.write_property = php_http_client_datashare_object_write_prop;
index fb3fc5542c983a8efb6a369a43139dd457f7b942..c60ff393746f29b39e9caa4595fe1c110d813e55 100644 (file)
@@ -50,7 +50,7 @@ typedef struct php_http_client_datashare {
 #endif
 } php_http_client_datashare_t;
 
-extern PHP_MINIT_FUNCTION(http_client_datashare);
+PHP_MINIT_FUNCTION(http_client_datashare);
 
 PHP_HTTP_API php_http_client_datashare_t *php_http_client_datashare_init(php_http_client_datashare_t *h, php_http_client_datashare_ops_t *ops, php_http_resource_factory_t *rf, void *init_arg TSRMLS_DC);
 PHP_HTTP_API php_http_client_datashare_t *php_http_client_datashare_copy(php_http_client_datashare_t *from, php_http_client_datashare_t *to);
@@ -66,14 +66,12 @@ typedef struct php_http_client_datashare_object {
        php_http_client_datashare_t *share;
 } php_http_client_datashare_object_t;
 
-extern zend_class_entry *php_http_client_datashare_class_entry;
-extern zend_function_entry php_http_client_datashare_method_entry[];
+zend_object_value php_http_client_datashare_object_new(zend_class_entry *ce TSRMLS_DC);
+zend_object_value php_http_client_datashare_object_new_ex(zend_class_entry *ce, php_http_client_datashare_t *share, php_http_client_datashare_object_t **ptr TSRMLS_DC);
+void php_http_client_datashare_object_free(void *object TSRMLS_DC);
 
-extern zend_object_value php_http_client_datashare_object_new(zend_class_entry *ce TSRMLS_DC);
-extern zend_object_value php_http_client_datashare_object_new_ex(zend_class_entry *ce, php_http_client_datashare_t *share, php_http_client_datashare_object_t **ptr TSRMLS_DC);
-extern void php_http_client_datashare_object_free(void *object TSRMLS_DC);
-
-extern zend_object_handlers *php_http_client_datashare_get_object_handlers(void);
+zend_class_entry *php_http_client_datashare_get_class_entry();
+zend_object_handlers *php_http_client_datashare_get_object_handlers(void);
 
 PHP_METHOD(HttpClientDataShare, __destruct);
 PHP_METHOD(HttpClientDataShare, count);
index c5201f8a800e836c822c6ca9a0e8f3bf745a1cff..161b510f1afadd4c6351346ead6d093883d26d64 100644 (file)
@@ -205,7 +205,7 @@ PHP_MINIT_FUNCTION(http_client_datashare_curl)
                return FAILURE;
        }
 
-       PHP_HTTP_REGISTER_CLASS(http\\Client\\DataShare, CURL, http_client_datashare_curl, php_http_client_datashare_class_entry, 0);
+       PHP_HTTP_REGISTER_CLASS(http\\Client\\DataShare, CURL, http_client_datashare_curl, php_http_client_datashare_get_class_entry(), 0);
        php_http_client_datashare_curl_class_entry->create_object = php_http_client_datashare_curl_object_new;
        return SUCCESS;
 }
index d1586f19754ea5f9083cb7e2f199fc200046f2d6..aba4b6444b9848d0049f7e90b18dc7703b8b9511 100644 (file)
@@ -116,7 +116,7 @@ PHP_METHOD(HttpClientFactory, createClient)
        with_error_handling(EH_THROW, php_http_exception_class_entry) {
                if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!", &options)) {
                        with_error_handling(EH_THROW, php_http_exception_class_entry) {
-                               zval *zdriver, *os;
+                               zval *zdriver;
                                zend_object_value ov;
                                zend_class_entry *class_entry = NULL;
                                php_http_client_t *req = NULL;
@@ -208,7 +208,7 @@ PHP_METHOD(HttpClientFactory, createPool)
                                                if (SUCCESS == php_http_new(&ov, class_entry, driver.client_pool_ops->create_object, driver.client_pool_ops->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_client_class_entry TSRMLS_CC)) {
+                                                               if (Z_TYPE_PP(argv[i]) == IS_OBJECT && instanceof_function(Z_OBJCE_PP(argv[i]), php_http_client_get_class_entry() TSRMLS_CC)) {
                                                                        php_http_client_pool_attach(pool, *(argv[i]));
                                                                }
                                                        }
@@ -269,7 +269,7 @@ PHP_METHOD(HttpClientFactory, createDataShare)
                                                if (SUCCESS == php_http_new(&ov, class_entry, driver.client_datashare_ops->create_object, driver.client_datashare_ops->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_client_class_entry TSRMLS_CC)) {
+                                                               if (Z_TYPE_PP(argv[i]) == IS_OBJECT && instanceof_function(Z_OBJCE_PP(argv[i]), php_http_client_get_class_entry() TSRMLS_CC)) {
                                                                        php_http_client_datashare_attach(share, *(argv[i]));
                                                                }
                                                        }
index 9c86e12c1ff4b556b50e48232cd9b80a2fc7c6c3..a3fbf5e5ca3f57e3000fbd9743d7a960db92e1c3 100644 (file)
@@ -22,7 +22,11 @@ PHP_HTTP_API php_http_client_pool_t *php_http_client_pool_init(php_http_client_p
        memset(h, 0, sizeof(*h));
 
        h->ops = ops;
-       h->rf = rf ? rf : php_http_resource_factory_init(NULL, h->ops->rsrc, NULL, NULL);
+       if (rf) {
+               h->rf = rf;
+       } else if (ops->rsrc) {
+               h->rf = php_http_resource_factory_init(NULL, h->ops->rsrc, h, NULL);
+       }
        zend_llist_init(&h->clients.attached, sizeof(zval *), (llist_dtor_func_t) ZVAL_PTR_DTOR, 0);
        zend_llist_init(&h->clients.finished, sizeof(zval *), (llist_dtor_func_t) ZVAL_PTR_DTOR, 0);
        TSRMLS_SET_CTX(h->ts);
@@ -246,8 +250,14 @@ PHP_HTTP_BEGIN_ARGS(enableEvents, 0)
        PHP_HTTP_ARG_VAL(enable, 0)
 PHP_HTTP_END_ARGS;
 
-zend_class_entry *php_http_client_pool_class_entry;
-zend_function_entry php_http_client_pool_method_entry[] = {
+static zend_class_entry *php_http_client_pool_class_entry;
+
+zend_class_entry *php_http_client_pool_get_class_entry(void)
+{
+       return php_http_client_pool_class_entry;
+}
+
+static zend_function_entry php_http_client_pool_method_entry[] = {
        PHP_HTTP_CLIENT_POOL_ME(__destruct, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR)
        PHP_HTTP_CLIENT_POOL_ME(attach, ZEND_ACC_PUBLIC)
        PHP_HTTP_CLIENT_POOL_ME(detach, ZEND_ACC_PUBLIC)
@@ -283,6 +293,22 @@ extern zend_object_handlers *php_http_client_pool_get_object_handlers(void)
        return &php_http_client_pool_object_handlers;
 }
 
+static php_http_client_pool_ops_t php_http_client_pool_user_ops = {
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       (php_http_new_t) php_http_client_pool_object_new_ex,
+       php_http_client_pool_get_class_entry
+};
+
 zend_object_value php_http_client_pool_object_new(zend_class_entry *ce TSRMLS_DC)
 {
        return php_http_client_pool_object_new_ex(ce, NULL, NULL TSRMLS_CC);
@@ -298,7 +324,7 @@ zend_object_value php_http_client_pool_object_new_ex(zend_class_entry *ce, php_h
        object_properties_init((zend_object *) o, ce);
 
        if (!(o->pool = p)) {
-               o->pool = php_http_client_pool_init(NULL, NULL, NULL, NULL TSRMLS_CC);
+               o->pool = php_http_client_pool_init(NULL, &php_http_client_pool_user_ops, NULL, NULL TSRMLS_CC);
        }
 
        if (ptr) {
@@ -353,7 +379,7 @@ PHP_METHOD(HttpClientPool, attach)
        with_error_handling(EH_THROW, php_http_exception_class_entry) {
                zval *request;
 
-               if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, php_http_client_class_entry)) {
+               if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, php_http_client_get_class_entry())) {
                        with_error_handling(EH_THROW, php_http_exception_class_entry) {
                                php_http_client_pool_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
@@ -376,7 +402,7 @@ PHP_METHOD(HttpClientPool, detach)
        with_error_handling(EH_THROW, php_http_exception_class_entry) {
                zval *request;
 
-               if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, php_http_client_class_entry)) {
+               if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, php_http_client_get_class_entry())) {
                        with_error_handling(EH_THROW, php_http_exception_class_entry) {
                                php_http_client_pool_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
@@ -557,11 +583,10 @@ PHP_METHOD(HttpClientPool, enableEvents)
 PHP_MINIT_FUNCTION(http_client_pool)
 {
        PHP_HTTP_REGISTER_CLASS(http\\Client\\Pool, AbstractPool, http_client_pool, php_http_object_class_entry, 0);
-       php_http_client_pool_class_entry->create_object = php_http_object_new; //php_http_client_pool_object_new;
+       php_http_client_pool_class_entry->create_object = php_http_client_pool_object_new;
        memcpy(&php_http_client_pool_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
        php_http_client_pool_object_handlers.clone_obj = NULL;
 
-       zend_declare_property_null(php_http_client_pool_class_entry, ZEND_STRL("client"), ZEND_ACC_PRIVATE TSRMLS_CC);
        zend_class_implements(php_http_client_pool_class_entry TSRMLS_CC, 2, spl_ce_Countable, zend_ce_iterator);
 
        return SUCCESS;
index 68ba369c611836d8221433f4da0cc1ede7a59fe1..071042d85f296f04cc8e82508a0a7efb46903fb4 100644 (file)
@@ -83,14 +83,12 @@ typedef struct php_http_client_pool_object {
        } iterator;
 } php_http_client_pool_object_t;
 
-extern zend_class_entry *php_http_client_pool_class_entry;
-extern zend_function_entry php_http_client_pool_method_entry[];
+zend_object_value php_http_client_pool_object_new(zend_class_entry *ce TSRMLS_DC);
+zend_object_value php_http_client_pool_object_new_ex(zend_class_entry *ce, php_http_client_pool_t *p, php_http_client_pool_object_t **ptr TSRMLS_DC);
+void php_http_client_pool_object_free(void *object TSRMLS_DC);
 
-extern zend_object_value php_http_client_pool_object_new(zend_class_entry *ce TSRMLS_DC);
-extern zend_object_value php_http_client_pool_object_new_ex(zend_class_entry *ce, php_http_client_pool_t *p, php_http_client_pool_object_t **ptr TSRMLS_DC);
-extern void php_http_client_pool_object_free(void *object TSRMLS_DC);
-
-extern zend_object_handlers *php_http_client_pool_get_object_handlers(void);
+zend_class_entry *php_http_client_pool_get_class_entry(void);
+zend_object_handlers *php_http_client_pool_get_object_handlers(void);
 
 PHP_METHOD(HttpClientPool, __destruct);
 PHP_METHOD(HttpClientPool, attach);
index b6d39e31ce3d22de9367d856fb40fd93909a5df2..12d9454d9f0781e478d6fba3f52368fda8be6c0c 100644 (file)
@@ -532,7 +532,7 @@ PHP_MINIT_FUNCTION(http_client_pool_curl)
                return FAILURE;
        }
 
-       PHP_HTTP_REGISTER_CLASS(http\\Client\\Pool, CURL, http_client_pool_curl, php_http_client_pool_class_entry, 0);
+       PHP_HTTP_REGISTER_CLASS(http\\Client\\Pool, CURL, http_client_pool_curl, php_http_client_pool_get_class_entry(), 0);
        php_http_client_pool_curl_class_entry->create_object = php_http_client_pool_curl_object_new;
 
        return SUCCESS;
index 2fb6e33915fa1eb453fd1fc791bcc43502e4a187..f1ebf1c30e124668d8d05b37304942ae95ede547 100644 (file)
@@ -32,7 +32,6 @@ PHP_RINIT_FUNCTION(http_env)
 
                ZEND_INIT_SYMTABLE(&params);
                if (php_http_params_parse(&params, &opts TSRMLS_CC)) {
-                       zval **zct;
                        char *key_str;
                        uint key_len;
                        ulong key_num;
index 8ba4f498eea952f632ade56b85eb4fd78eb63404..685aba146c5935a19b324264a780cbc458e64a25 100644 (file)
@@ -1739,9 +1739,7 @@ PHP_METHOD(HttpMessage, toStream)
 
 PHP_METHOD(HttpMessage, toCallback)
 {
-       zend_bool include_parent = 0;
        php_http_pass_fcall_arg_t fcd;
-       long offset = 0, forlen = 0;
 
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f", &fcd.fci, &fcd.fcc)) {
                php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);