From 222c90f27100777fcf3388c5e9cb30998137961c Mon Sep 17 00:00:00 2001 From: Bogdan Padalko Date: Thu, 22 Jan 2015 09:29:06 +0200 Subject: [PATCH] Fix reported memory leaks when php built with --enbale-debug --- Vagrantfile | 6 +- amqp.c | 14 +- amqp_channel.c | 45 ++-- amqp_connection.c | 4 +- amqp_connection_resource.c | 28 ++- amqp_envelope.c | 7 +- amqp_exchange.c | 157 ++++++------ amqp_queue.c | 97 ++++---- php_amqp.h | 17 +- tests/amqpexchange_declare_existent.phpt | 1 + .../amqpexchange_publish_with_properties.phpt | 79 ++++-- ...ties_ignore_unsupported_header_values.phpt | 2 +- tests/amqpqueue_consume_basic.phpt | 173 +++++++++----- tests/amqpqueue_get_basic.phpt | 226 ++++++++++++------ 14 files changed, 526 insertions(+), 330 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index fdf1d276..de02cb78 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -10,8 +10,10 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # please see the online documentation at vagrantup.com. # Every Vagrant virtual environment requires a box to build off of. - config.vm.box = "trusty64" - config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box" + #config.vm.box = "trusty64" + config.vm.box = "utopic64" + #config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box" + config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/utopic/current/utopic-server-cloudimg-amd64-vagrant-disk1.box" # Disable automatic box update checking. If you disable this, then # boxes will only be checked for updates when the user runs diff --git a/amqp.c b/amqp.c index 0faf3c51..361e9a91 100644 --- a/amqp.c +++ b/amqp.c @@ -471,15 +471,15 @@ zend_function_entry amqp_connection_class_functions[] = { PHP_ME(amqp_connection_class, getTimeout, arginfo_amqp_connection_class_getTimeout, ZEND_ACC_PUBLIC) PHP_ME(amqp_connection_class, setTimeout, arginfo_amqp_connection_class_setTimeout, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, getReadTimeout, arginfo_amqp_connection_class_getReadTimeout, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, setReadTimeout, arginfo_amqp_connection_class_setReadTimeout, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, getReadTimeout, arginfo_amqp_connection_class_getReadTimeout, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, setReadTimeout, arginfo_amqp_connection_class_setReadTimeout, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, getWriteTimeout, arginfo_amqp_connection_class_getWriteTimeout, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, setWriteTimeout, arginfo_amqp_connection_class_setWriteTimeout, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, getWriteTimeout, arginfo_amqp_connection_class_getWriteTimeout, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, setWriteTimeout, arginfo_amqp_connection_class_setWriteTimeout, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, getUsedChannels, arginfo_amqp_connection_class_getUsedChannels, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, getMaxChannels, arginfo_amqp_connection_class_getMaxChannels, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, isPersistent, arginfo_amqp_connection_class_isPersistent, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, getUsedChannels, arginfo_amqp_connection_class_getUsedChannels, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, getMaxChannels, arginfo_amqp_connection_class_getMaxChannels, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, isPersistent, arginfo_amqp_connection_class_isPersistent, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} /* Must be the last line in amqp_functions[] */ }; diff --git a/amqp_channel.c b/amqp_channel.c index c1403539..2afabd72 100644 --- a/amqp_channel.c +++ b/amqp_channel.c @@ -120,11 +120,12 @@ void php_amqp_close_channel(amqp_channel_object *channel TSRMLS_DC) if (res.reply_type != AMQP_RESPONSE_NORMAL) { PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } @@ -230,11 +231,12 @@ PHP_METHOD(amqp_channel_class, __construct) PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } @@ -259,11 +261,12 @@ PHP_METHOD(amqp_channel_class, __construct) if (res.reply_type != AMQP_RESPONSE_NORMAL) { PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } @@ -351,11 +354,12 @@ PHP_METHOD(amqp_channel_class, setPrefetchCount) if (res.reply_type != AMQP_RESPONSE_NORMAL) { PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } @@ -422,11 +426,12 @@ PHP_METHOD(amqp_channel_class, setPrefetchSize) if (res.reply_type != AMQP_RESPONSE_NORMAL) { PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } @@ -501,11 +506,12 @@ PHP_METHOD(amqp_channel_class, qos) if (res.reply_type != AMQP_RESPONSE_NORMAL) { PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } @@ -548,11 +554,12 @@ PHP_METHOD(amqp_channel_class, startTransaction) if (res.reply_type != AMQP_RESPONSE_NORMAL) { PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } @@ -594,11 +601,12 @@ PHP_METHOD(amqp_channel_class, commitTransaction) if (res.reply_type != AMQP_RESPONSE_NORMAL) { PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } @@ -639,11 +647,12 @@ PHP_METHOD(amqp_channel_class, rollbackTransaction) if (res.reply_type != AMQP_RESPONSE_NORMAL) { PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } diff --git a/amqp_connection.c b/amqp_connection.c index 6e0f0be1..edb003b6 100644 --- a/amqp_connection.c +++ b/amqp_connection.c @@ -118,7 +118,7 @@ HashTable *amqp_connection_object_get_debug_info(zval *object, int *is_temp TSRM if (connection && connection->connection_resource) { ZVAL_RESOURCE(value, connection->connection_resource->resource_id); - zend_list_addref(connection->connection_resource->resource_id); + zend_list_addref(connection->connection_resource->resource_id); } else { ZVAL_NULL(value); } @@ -242,7 +242,7 @@ int php_amqp_connect(amqp_connection_object *connection, int persistent TSRMLS_D if (persistent) { zend_rsrc_list_entry *le; /* Look for an established resource */ - key_len = spprintf(&key, 0, "amqp_conn_res_%s_%d_%s_%s_%s", connection->host, connection->port, connection->vhost, connection->login, connection->password); + key_len = spprintf(&key, 0, "amqp_conn_res_%s_%d_%s_%s_%s", connection->host, connection->port, connection->vhost, connection->login, connection->password); if (zend_hash_find(&EG(persistent_list), key, key_len + 1, (void **)&le) == SUCCESS) { efree(key); diff --git a/amqp_connection_resource.c b/amqp_connection_resource.c index 849b28c3..9d4ccd15 100644 --- a/amqp_connection_resource.c +++ b/amqp_connection_resource.c @@ -221,8 +221,8 @@ amqp_channel_t php_amqp_connection_resource_get_available_channel_id(amqp_connec /* Check if there are any open slots */ if (resource->used_slots >= PHP_AMQP_MAX_CHANNELS + 1) { - return 0; - } + return 0; + } amqp_channel_t slot; @@ -274,11 +274,11 @@ amqp_connection_resource *connection_resource_constructor(amqp_connection_object struct timeval *tv_ptr = &tv; char *std_datetime; - amqp_table_entry_t client_properties_entries[5]; - amqp_table_t client_properties_table; + amqp_table_entry_t client_properties_entries[5]; + amqp_table_t client_properties_table; - amqp_table_entry_t custom_properties_entries[1]; - amqp_table_t custom_properties_table; + amqp_table_entry_t custom_properties_entries[1]; + amqp_table_t custom_properties_table; amqp_connection_resource *resource; @@ -350,8 +350,8 @@ amqp_connection_resource *connection_resource_constructor(amqp_connection_object client_properties_entries[4].value.kind = AMQP_FIELD_KIND_UTF8; client_properties_entries[4].value.value.bytes = amqp_cstring_bytes(std_datetime); - client_properties_table.entries = client_properties_entries; - client_properties_table.num_entries = sizeof(client_properties_entries) / sizeof(amqp_table_entry_t); + client_properties_table.entries = client_properties_entries; + client_properties_table.num_entries = sizeof(client_properties_entries) / sizeof(amqp_table_entry_t); custom_properties_entries[0].key = amqp_cstring_bytes("client"); custom_properties_entries[0].value.kind = AMQP_FIELD_KIND_TABLE; @@ -377,12 +377,16 @@ amqp_connection_resource *connection_resource_constructor(amqp_connection_object efree(std_datetime); if (res.reply_type != AMQP_RESPONSE_NORMAL) { - PHP_AMQP_INIT_ERROR_MESSAGE(); + char *message, *long_message; + + php_amqp_connection_resource_error(res, &message, resource, 0 TSRMLS_CC); + + spprintf(&long_message, 0, "%s - Potential login failure.", message); + zend_throw_exception(amqp_connection_exception_class_entry, long_message, 0 TSRMLS_CC); - php_amqp_connection_resource_error(res, message, resource, 0 TSRMLS_CC); + efree(message); + efree(long_message); - strcat(*message, " - Potential login failure."); - zend_throw_exception(amqp_connection_exception_class_entry, *message, 0 TSRMLS_CC); /* https://www.rabbitmq.com/resources/specs/amqp0-9-1.pdf * * 2.2.4 The Connection Class: diff --git a/amqp_envelope.c b/amqp_envelope.c index a62dc9cd..b7ec4179 100644 --- a/amqp_envelope.c +++ b/amqp_envelope.c @@ -579,11 +579,8 @@ PHP_METHOD(amqp_envelope_class, getHeaders) /* Get the envelope object out of the store */ envelope = (amqp_envelope_object *)zend_object_store_get_object(id TSRMLS_CC); - *return_value = *envelope->headers; - zval_copy_ctor(return_value); - - /* Increment the ref count */ - Z_ADDREF_P(envelope->headers); + zval_dtor(return_value); + MAKE_COPY_ZVAL(&envelope->headers, return_value); } /* }}} */ diff --git a/amqp_exchange.c b/amqp_exchange.c index 965ac01f..a5729167 100644 --- a/amqp_exchange.c +++ b/amqp_exchange.c @@ -358,11 +358,8 @@ PHP_METHOD(amqp_exchange_class, getArguments) exchange = (amqp_exchange_object *)zend_object_store_get_object(id TSRMLS_CC); - *return_value = *exchange->arguments; - zval_copy_ctor(return_value); - - /* Increment the ref count */ - Z_ADDREF_P(exchange->arguments); + zval_dtor(return_value); + MAKE_COPY_ZVAL(&exchange->arguments, return_value); } /* }}} */ @@ -504,11 +501,12 @@ PHP_METHOD(amqp_exchange_class, declareExchange) if (res.reply_type != AMQP_RESPONSE_NORMAL) { PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_exchange_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_exchange_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } @@ -559,10 +557,12 @@ PHP_METHOD(amqp_exchange_class, delete) if (res.reply_type != AMQP_RESPONSE_NORMAL) { PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_exchange_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_exchange_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); + + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } @@ -580,8 +580,9 @@ PHP_METHOD(amqp_exchange_class, publish) { zval *id; zval *ini_arr = NULL; - zval** zdata; - zval *ztmp; + zval** ppztmp; + zval *ini_arr_tmp = NULL; + amqp_exchange_object *exchange; amqp_channel_object *channel; @@ -614,119 +615,110 @@ PHP_METHOD(amqp_exchange_class, publish) props.headers.entries = 0; - ALLOC_ZVAL(ztmp); + if (ini_arr) { + ALLOC_ZVAL(ini_arr_tmp); + MAKE_COPY_ZVAL(&ini_arr, ini_arr_tmp); + } { - if (ini_arr && SUCCESS == zend_hash_find(HASH_OF (ini_arr), "content_type", sizeof("content_type"), (void*)&zdata)) { - MAKE_COPY_ZVAL(zdata, ztmp); - convert_to_string(ztmp); + if (ini_arr_tmp && SUCCESS == zend_hash_find(HASH_OF (ini_arr_tmp), "content_type", sizeof("content_type"), (void*)&ppztmp)) { + convert_to_string(*ppztmp); - if (Z_STRLEN_P(ztmp) > 0) { - props.content_type = amqp_cstring_bytes((char *)Z_STRVAL_P(ztmp)); + if (Z_STRLEN_PP(ppztmp) > 0) { + props.content_type = amqp_cstring_bytes((char *)Z_STRVAL_PP(ppztmp)); props._flags |= AMQP_BASIC_CONTENT_TYPE_FLAG; } } - if (ini_arr && SUCCESS == zend_hash_find(HASH_OF (ini_arr), "content_encoding", sizeof("content_encoding"), (void*)&zdata)) { - MAKE_COPY_ZVAL(zdata, ztmp); - convert_to_string(ztmp); + if (ini_arr_tmp && SUCCESS == zend_hash_find(HASH_OF (ini_arr_tmp), "content_encoding", sizeof("content_encoding"), (void*)&ppztmp)) { + convert_to_string(*ppztmp); - if (Z_STRLEN_P(ztmp) > 0) { - props.content_encoding = amqp_cstring_bytes((char *)Z_STRVAL_P(ztmp)); + if (Z_STRLEN_PP(ppztmp) > 0) { + props.content_encoding = amqp_cstring_bytes((char *)Z_STRVAL_PP(ppztmp)); props._flags |= AMQP_BASIC_CONTENT_ENCODING_FLAG; } } - if (ini_arr && SUCCESS == zend_hash_find(HASH_OF (ini_arr), "message_id", sizeof("message_id"), (void*)&zdata)) { - MAKE_COPY_ZVAL(zdata, ztmp); - convert_to_string(ztmp); + if (ini_arr_tmp && SUCCESS == zend_hash_find(HASH_OF (ini_arr_tmp), "message_id", sizeof("message_id"), (void*)&ppztmp)) { + convert_to_string(*ppztmp); - if (Z_STRLEN_P(ztmp) > 0) { - props.message_id = amqp_cstring_bytes((char *)Z_STRVAL_P(ztmp)); + if (Z_STRLEN_PP(ppztmp) > 0) { + props.message_id = amqp_cstring_bytes((char *)Z_STRVAL_PP(ppztmp)); props._flags |= AMQP_BASIC_MESSAGE_ID_FLAG; } } - if (ini_arr && SUCCESS == zend_hash_find(HASH_OF (ini_arr), "user_id", sizeof("user_id"), (void*)&zdata)) { - MAKE_COPY_ZVAL(zdata, ztmp); - convert_to_string(ztmp); + if (ini_arr_tmp && SUCCESS == zend_hash_find(HASH_OF (ini_arr_tmp), "user_id", sizeof("user_id"), (void*)&ppztmp)) { + convert_to_string(*ppztmp); - if (Z_STRLEN_P(ztmp) > 0) { - props.user_id = amqp_cstring_bytes((char *)Z_STRVAL_P(ztmp)); + if (Z_STRLEN_PP(ppztmp) > 0) { + props.user_id = amqp_cstring_bytes((char *)Z_STRVAL_PP(ppztmp)); props._flags |= AMQP_BASIC_USER_ID_FLAG; } } - if (ini_arr && SUCCESS == zend_hash_find(HASH_OF (ini_arr), "app_id", sizeof("app_id"), (void*)&zdata)) { - MAKE_COPY_ZVAL(zdata, ztmp); - convert_to_string(ztmp); + if (ini_arr_tmp && SUCCESS == zend_hash_find(HASH_OF (ini_arr_tmp), "app_id", sizeof("app_id"), (void*)&ppztmp)) { + convert_to_string(*ppztmp); - if (Z_STRLEN_P(ztmp) > 0) { - props.app_id = amqp_cstring_bytes((char *)Z_STRVAL_P(ztmp)); + if (Z_STRLEN_PP(ppztmp) > 0) { + props.app_id = amqp_cstring_bytes((char *)Z_STRVAL_PP(ppztmp)); props._flags |= AMQP_BASIC_APP_ID_FLAG; } } - if (ini_arr && SUCCESS == zend_hash_find(HASH_OF (ini_arr), "delivery_mode", sizeof("delivery_mode"), (void*)&zdata)) { - MAKE_COPY_ZVAL(zdata, ztmp); - convert_to_long(ztmp); + if (ini_arr_tmp && SUCCESS == zend_hash_find(HASH_OF (ini_arr_tmp), "delivery_mode", sizeof("delivery_mode"), (void*)&ppztmp)) { + convert_to_long(*ppztmp); - props.delivery_mode = (uint8_t)Z_LVAL_P(ztmp); + props.delivery_mode = (uint8_t)Z_LVAL_PP(ppztmp); props._flags |= AMQP_BASIC_DELIVERY_MODE_FLAG; } - if (ini_arr && SUCCESS == zend_hash_find(HASH_OF (ini_arr), "priority", sizeof("priority"), (void*)&zdata)) { - MAKE_COPY_ZVAL(zdata, ztmp); - convert_to_long(ztmp); + if (ini_arr_tmp && SUCCESS == zend_hash_find(HASH_OF (ini_arr_tmp), "priority", sizeof("priority"), (void*)&ppztmp)) { + convert_to_long(*ppztmp); - props.priority = (uint8_t)Z_LVAL_P(ztmp); + props.priority = (uint8_t)Z_LVAL_PP(ppztmp); props._flags |= AMQP_BASIC_PRIORITY_FLAG; } - if (ini_arr && SUCCESS == zend_hash_find(HASH_OF (ini_arr), "timestamp", sizeof("timestamp"), (void*)&zdata)) { - MAKE_COPY_ZVAL(zdata, ztmp); - convert_to_long(ztmp); + if (ini_arr_tmp && SUCCESS == zend_hash_find(HASH_OF (ini_arr_tmp), "timestamp", sizeof("timestamp"), (void*)&ppztmp)) { + convert_to_long(*ppztmp); - props.timestamp = (uint64_t)Z_LVAL_P(ztmp); + props.timestamp = (uint64_t)Z_LVAL_PP(ppztmp); props._flags |= AMQP_BASIC_TIMESTAMP_FLAG; } - if (ini_arr && SUCCESS == zend_hash_find(HASH_OF (ini_arr), "expiration", sizeof("expiration"), (void*)&zdata)) { - MAKE_COPY_ZVAL(zdata, ztmp); - convert_to_string(ztmp); + if (ini_arr_tmp && SUCCESS == zend_hash_find(HASH_OF (ini_arr_tmp), "expiration", sizeof("expiration"), (void*)&ppztmp)) { + convert_to_string(*ppztmp); - if (Z_STRLEN_P(ztmp) > 0) { - props.expiration = amqp_cstring_bytes((char *)Z_STRVAL_P(ztmp)); + if (Z_STRLEN_PP(ppztmp) > 0) { + props.expiration = amqp_cstring_bytes((char *)Z_STRVAL_PP(ppztmp)); props._flags |= AMQP_BASIC_EXPIRATION_FLAG; } } - if (ini_arr && SUCCESS == zend_hash_find(HASH_OF (ini_arr), "type", sizeof("type"), (void*)&zdata)) { - MAKE_COPY_ZVAL(zdata, ztmp); - convert_to_string(ztmp); + if (ini_arr_tmp && SUCCESS == zend_hash_find(HASH_OF (ini_arr_tmp), "type", sizeof("type"), (void*)&ppztmp)) { + convert_to_string(*ppztmp); - if (Z_STRLEN_P(ztmp) > 0) { - props.type = amqp_cstring_bytes((char *)Z_STRVAL_P(ztmp)); + if (Z_STRLEN_PP(ppztmp) > 0) { + props.type = amqp_cstring_bytes((char *)Z_STRVAL_PP(ppztmp)); props._flags |= AMQP_BASIC_TYPE_FLAG; } } - if (ini_arr && SUCCESS == zend_hash_find(HASH_OF (ini_arr), "reply_to", sizeof("reply_to"), (void*)&zdata)) { - MAKE_COPY_ZVAL(zdata, ztmp); - convert_to_string(ztmp); + if (ini_arr_tmp && SUCCESS == zend_hash_find(HASH_OF (ini_arr_tmp), "reply_to", sizeof("reply_to"), (void*)&ppztmp)) { + convert_to_string(*ppztmp); - if (Z_STRLEN_P(ztmp) > 0) { - props.reply_to = amqp_cstring_bytes((char *)Z_STRVAL_P(ztmp)); + if (Z_STRLEN_PP(ppztmp) > 0) { + props.reply_to = amqp_cstring_bytes((char *)Z_STRVAL_PP(ppztmp)); props._flags |= AMQP_BASIC_REPLY_TO_FLAG; } } - if (ini_arr && SUCCESS == zend_hash_find(HASH_OF (ini_arr), "correlation_id", sizeof("correlation_id"), (void*)&zdata)) { - MAKE_COPY_ZVAL(zdata, ztmp); - convert_to_string(ztmp); + if (ini_arr_tmp && SUCCESS == zend_hash_find(HASH_OF (ini_arr_tmp), "correlation_id", sizeof("correlation_id"), (void*)&ppztmp)) { + convert_to_string(*ppztmp); - if (Z_STRLEN_P(ztmp) > 0) { - props.correlation_id = amqp_cstring_bytes((char *)Z_STRVAL_P(ztmp)); + if (Z_STRLEN_PP(ppztmp) > 0) { + props.correlation_id = amqp_cstring_bytes((char *)Z_STRVAL_PP(ppztmp)); props._flags |= AMQP_BASIC_CORRELATION_ID_FLAG; } } @@ -735,11 +727,10 @@ PHP_METHOD(amqp_exchange_class, publish) amqp_table_t *headers = NULL; - if (ini_arr && SUCCESS == zend_hash_find(HASH_OF(ini_arr), "headers", sizeof("headers"), (void*)&zdata)) { - MAKE_COPY_ZVAL(zdata, ztmp); - convert_to_array(ztmp); + if (ini_arr_tmp && SUCCESS == zend_hash_find(HASH_OF(ini_arr_tmp), "headers", sizeof("headers"), (void*)&ppztmp)) { + convert_to_array(*ppztmp); - headers = convert_zval_to_amqp_table(ztmp TSRMLS_CC); + headers = convert_zval_to_amqp_table(*ppztmp TSRMLS_CC); props._flags |= AMQP_BASIC_HEADERS_FLAG; props.headers = *headers; @@ -772,7 +763,10 @@ PHP_METHOD(amqp_exchange_class, publish) php_amqp_free_amqp_table(headers); } - FREE_ZVAL(ztmp); + if (ini_arr_tmp) { + zval_dtor(ini_arr_tmp); + FREE_ZVAL(ini_arr_tmp); + } #ifndef PHP_WIN32 /* End ignoring of SIGPIPEs */ @@ -787,11 +781,12 @@ PHP_METHOD(amqp_exchange_class, publish) PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } @@ -854,11 +849,12 @@ PHP_METHOD(amqp_exchange_class, bind) if (res.reply_type != AMQP_RESPONSE_NORMAL) { PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_exchange_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_exchange_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } @@ -922,11 +918,12 @@ PHP_METHOD(amqp_exchange_class, unbind) if (res.reply_type != AMQP_RESPONSE_NORMAL) { PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_exchange_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_exchange_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } diff --git a/amqp_queue.c b/amqp_queue.c index 585f767c..94801606 100644 --- a/amqp_queue.c +++ b/amqp_queue.c @@ -155,12 +155,14 @@ zend_object_value amqp_queue_ctor(zend_class_entry *ce TSRMLS_DC) void parse_amqp_table(amqp_table_t *table, zval *result) { int i; - array_init(result); + zval *value; + + assert(Z_TYPE_P(result) == IS_ARRAY); for (i = 0; i < table->num_entries; i++) { - zval *value; - amqp_table_entry_t *entry = &(table->entries[i]); MAKE_STD_ZVAL(value); + + amqp_table_entry_t *entry = &(table->entries[i]); switch (entry->value.kind) { case AMQP_FIELD_KIND_BOOLEAN: ZVAL_BOOL(value, entry->value.value.boolean); @@ -217,6 +219,7 @@ void parse_amqp_table(amqp_table_t *table, zval *result) { zval *subtable; MAKE_STD_ZVAL(subtable); + array_init(subtable); parse_amqp_table( &(entry->value.value.array.entries[j].value.table), subtable @@ -229,7 +232,7 @@ void parse_amqp_table(amqp_table_t *table, zval *result) } break; case AMQP_FIELD_KIND_TABLE: - array_init(value); + array_init(value); parse_amqp_table(&(entry->value.value.table), value); break; case AMQP_FIELD_KIND_TIMESTAMP: @@ -239,7 +242,9 @@ void parse_amqp_table(amqp_table_t *table, zval *result) case AMQP_FIELD_KIND_DECIMAL: default: ZVAL_NULL(value); + break; } + if (Z_TYPE_P(value) != IS_NULL) { char *key = estrndup(entry->key.bytes, entry->key.len); add_assoc_zval(result, key, value); @@ -316,7 +321,6 @@ void convert_amqp_envelope_to_zval(amqp_envelope_t *amqp_envelope, zval *envelop } if (p->_flags & AMQP_BASIC_HEADERS_FLAG) { - zval_dtor(envelope->headers); parse_amqp_table(&(p->headers), envelope->headers); } @@ -493,11 +497,8 @@ PHP_METHOD(amqp_queue_class, getArguments) queue = (amqp_queue_object *)zend_object_store_get_object(id TSRMLS_CC); - *return_value = *queue->arguments; - zval_copy_ctor(return_value); - - /* Increment the ref count */ - Z_ADDREF_P(queue->arguments); + zval_dtor(return_value); + MAKE_COPY_ZVAL(&queue->arguments, return_value); } /* }}} */ @@ -520,10 +521,7 @@ PHP_METHOD(amqp_queue_class, setArguments) zval_ptr_dtor(&queue->arguments); } - queue->arguments = arguments; - - /* Increment the ref count */ - Z_ADDREF_P(queue->arguments); + MAKE_COPY_ZVAL(&arguments, queue->arguments); RETURN_TRUE; } @@ -618,11 +616,12 @@ PHP_METHOD(amqp_queue_class, declareQueue) PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } @@ -693,11 +692,12 @@ PHP_METHOD(amqp_queue_class, bind) if (res.reply_type != AMQP_RESPONSE_NORMAL) { PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } @@ -715,7 +715,7 @@ return array (messages) PHP_METHOD(amqp_queue_class, get) { zval *id; - amqp_queue_object *queue; + amqp_queue_object *queue; amqp_channel_object *channel; amqp_connection_object *connection; zval *message; @@ -745,11 +745,12 @@ PHP_METHOD(amqp_queue_class, get) if (res.reply_type != AMQP_RESPONSE_NORMAL) { PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } @@ -759,7 +760,7 @@ PHP_METHOD(amqp_queue_class, get) assert(AMQP_BASIC_GET_OK_METHOD == res.reply.id); - /* Fill the envelope from response */ + /* Fill the envelope from response */ amqp_basic_get_ok_t *get_ok_method = res.reply.decoded; amqp_envelope_t envelope; @@ -783,12 +784,13 @@ PHP_METHOD(amqp_queue_class, get) if (AMQP_RESPONSE_NORMAL != res.reply_type) { PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); amqp_destroy_envelope(&envelope); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } @@ -859,10 +861,12 @@ PHP_METHOD(amqp_queue_class, consume) PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - zend_throw_exception(amqp_queue_exception_class_entry, *message, 0 TSRMLS_CC); + zend_throw_exception(amqp_queue_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); + + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } @@ -903,19 +907,21 @@ PHP_METHOD(amqp_queue_class, consume) amqp_destroy_envelope(&envelope); php_amqp_maybe_release_buffers_on_channel(connection, channel); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } if (AMQP_RESPONSE_NORMAL != res.reply_type) { PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); amqp_destroy_envelope(&envelope); php_amqp_maybe_release_buffers_on_channel(connection, channel); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } @@ -1008,11 +1014,12 @@ PHP_METHOD(amqp_queue_class, ack) PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } @@ -1063,11 +1070,12 @@ PHP_METHOD(amqp_queue_class, nack) PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } @@ -1117,11 +1125,12 @@ PHP_METHOD(amqp_queue_class, reject) PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } @@ -1163,11 +1172,12 @@ PHP_METHOD(amqp_queue_class, purge) PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } @@ -1217,11 +1227,12 @@ PHP_METHOD(amqp_queue_class, cancel) PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } @@ -1283,11 +1294,12 @@ PHP_METHOD(amqp_queue_class, unbind) if (res.reply_type != AMQP_RESPONSE_NORMAL) { PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } @@ -1337,11 +1349,12 @@ PHP_METHOD(amqp_queue_class, delete) PHP_AMQP_INIT_ERROR_MESSAGE(); - php_amqp_error(res, message, connection, channel TSRMLS_CC); + php_amqp_error(res, PHP_AMQP_ERROR_MESSAGE_PTR, connection, channel TSRMLS_CC); - php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, *message, 0 TSRMLS_CC); + php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, PHP_AMQP_ERROR_MESSAGE, 0 TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(connection, channel); + PHP_AMQP_DESTROY_ERROR_MESSAGE(); return; } diff --git a/php_amqp.h b/php_amqp.h index e304ef59..e0a4146d 100644 --- a/php_amqp.h +++ b/php_amqp.h @@ -189,7 +189,7 @@ extern zend_class_entry *amqp_exception_class_entry, #define DEFAULT_TIMEOUT "" #define DEFAULT_READ_TIMEOUT "0" #define DEFAULT_WRITE_TIMEOUT "0" -#define DEFAULT_CONNECT_TIMEOUT "0" +#define DEFAULT_CONNECT_TIMEOUT "0" #define DEFAULT_VHOST "/" #define DEFAULT_LOGIN "guest" #define DEFAULT_PASSWORD "guest" @@ -292,9 +292,14 @@ extern zend_class_entry *amqp_exception_class_entry, AMQP_VERIFY_CONNECTION_ERROR(error, "No connection available.") \ } \ +#define PHP_AMQP_ERROR_MESSAGE_PTR &php_amqp_internal_error_message +#define PHP_AMQP_ERROR_MESSAGE php_amqp_internal_error_message + #define PHP_AMQP_INIT_ERROR_MESSAGE()\ - char __internal_message[256]; \ - char ** message = (char **) &__internal_message; \ + char *PHP_AMQP_ERROR_MESSAGE = NULL; + +#define PHP_AMQP_DESTROY_ERROR_MESSAGE()\ + if (PHP_AMQP_ERROR_MESSAGE != NULL) { efree(PHP_AMQP_ERROR_MESSAGE); } #if ZEND_MODULE_API_NO >= 20100000 #define AMQP_OBJECT_PROPERTIES_INIT(obj, ce) object_properties_init(&obj, ce); @@ -322,7 +327,7 @@ typedef struct _amqp_connection_resource { zend_bool is_connected; int resource_id; amqp_channel_t used_slots; - amqp_channel_object **slots; + amqp_channel_object **slots; char *resource_key; int resource_key_len; amqp_connection_state_t connection_state; @@ -334,13 +339,9 @@ typedef struct _amqp_connection_object { char is_connected; char is_persistent; char *login; - int login_len; char *password; - int password_len; char *host; - int host_len; char *vhost; - int vhost_len; int port; double read_timeout; double write_timeout; diff --git a/tests/amqpexchange_declare_existent.phpt b/tests/amqpexchange_declare_existent.phpt index dfa5cabd..b49de66c 100644 --- a/tests/amqpexchange_declare_existent.phpt +++ b/tests/amqpexchange_declare_existent.phpt @@ -23,6 +23,7 @@ try { $ex->setName($exchangge_name); $ex->setType(AMQP_EX_TYPE_TOPIC); $ex->declareExchange(); + echo 'exchange ', $ex->getName(), ' declared', PHP_EOL; } catch (AMQPException $e) { echo get_class($e), ': ', $e->getMessage(), PHP_EOL; } diff --git a/tests/amqpexchange_publish_with_properties.phpt b/tests/amqpexchange_publish_with_properties.phpt index b42ad27e..ccf5d3d9 100644 --- a/tests/amqpexchange_publish_with_properties.phpt +++ b/tests/amqpexchange_publish_with_properties.phpt @@ -58,25 +58,48 @@ echo 'Message attributes are ', $attrs == $attrs_control ? 'the same' : 'not the $msg = $q->get(AMQP_AUTOACK); -function dump_message(AMQPEnvelope $msg) { +function dump_message($msg) { + if (!$msg) { + var_dump($msg); + return; + } + echo get_class($msg), PHP_EOL; + echo " getBody:", PHP_EOL, " "; var_dump($msg->getBody()); + echo " getContentType:", PHP_EOL, " "; var_dump($msg->getContentType()); + echo " getRoutingKey:", PHP_EOL, " "; var_dump($msg->getRoutingKey()); + echo " getDeliveryTag:", PHP_EOL, " "; var_dump($msg->getDeliveryTag()); + echo " getDeliveryMode:", PHP_EOL, " "; var_dump($msg->getDeliveryMode()); + echo " getExchangeName:", PHP_EOL, " "; var_dump($msg->getExchangeName()); + echo " isRedelivery:", PHP_EOL, " "; var_dump($msg->isRedelivery()); + echo " getContentEncoding:", PHP_EOL, " "; var_dump($msg->getContentEncoding()); + echo " getType:", PHP_EOL, " "; var_dump($msg->getType()); + echo " getTimeStamp:", PHP_EOL, " "; var_dump($msg->getTimeStamp()); + echo " getPriority:", PHP_EOL, " "; var_dump($msg->getPriority()); + echo " getExpiration:", PHP_EOL, " "; var_dump($msg->getExpiration()); + echo " getUserId:", PHP_EOL, " "; var_dump($msg->getUserId()); + echo " getAppId:", PHP_EOL, " "; var_dump($msg->getAppId()); + echo " getMessageId:", PHP_EOL, " "; var_dump($msg->getMessageId()); + echo " getReplyTo:", PHP_EOL, " "; var_dump($msg->getReplyTo()); + echo " getCorrelationId:", PHP_EOL, " "; var_dump($msg->getCorrelationId()); + echo " getHeaders:", PHP_EOL, " "; var_dump($msg->getHeaders()); } @@ -91,22 +114,40 @@ $q->delete(); true Message attributes are the same AMQPEnvelope -string(7) "message" -string(1) "1" -string(11) "routing.key" -int(1) -int(1) -string(%d) "exchange-%f" -bool(false) -string(1) "2" -string(1) "7" -int(123) -int(2) -string(9) "100000000" -string(0) "" -string(1) "5" -string(1) "3" -string(1) "8" -string(1) "9" -array(0) { + getBody: + string(7) "message" + getContentType: + string(1) "1" + getRoutingKey: + string(11) "routing.key" + getDeliveryTag: + int(1) + getDeliveryMode: + int(1) + getExchangeName: + string(%d) "exchange-%f" + isRedelivery: + bool(false) + getContentEncoding: + string(1) "2" + getType: + string(1) "7" + getTimeStamp: + int(123) + getPriority: + int(2) + getExpiration: + string(9) "100000000" + getUserId: + string(0) "" + getAppId: + string(1) "5" + getMessageId: + string(1) "3" + getReplyTo: + string(1) "8" + getCorrelationId: + string(1) "9" + getHeaders: + array(0) { } \ No newline at end of file diff --git a/tests/amqpexchange_publish_with_properties_ignore_unsupported_header_values.phpt b/tests/amqpexchange_publish_with_properties_ignore_unsupported_header_values.phpt index 66450804..d5bd88fb 100644 --- a/tests/amqpexchange_publish_with_properties_ignore_unsupported_header_values.phpt +++ b/tests/amqpexchange_publish_with_properties_ignore_unsupported_header_values.phpt @@ -17,7 +17,7 @@ $ex->declareExchange(); $attrs = array( 'headers' => array( 'null' => null, - 'object' => new DateTime(), + 'object' => new stdClass(), 'resource' => fopen(__FILE__, 'r'), ), ); diff --git a/tests/amqpqueue_consume_basic.phpt b/tests/amqpqueue_consume_basic.phpt index 72e10c66..514d8fdc 100644 --- a/tests/amqpqueue_consume_basic.phpt +++ b/tests/amqpqueue_consume_basic.phpt @@ -30,26 +30,49 @@ $ex->publish('message3', 'routing.3', AMQP_DURABLE); // this is wrong way to mak $count = 0; -function dump_message(AMQPEnvelope $msg) { - echo get_class($msg), PHP_EOL; - var_dump($msg->getBody()); - var_dump($msg->getContentType()); - var_dump($msg->getRoutingKey()); - var_dump($msg->getDeliveryTag()); - var_dump($msg->getDeliveryMode()); - var_dump($msg->getExchangeName()); - var_dump($msg->isRedelivery()); - var_dump($msg->getContentEncoding()); - var_dump($msg->getType()); - var_dump($msg->getTimeStamp()); - var_dump($msg->getPriority()); - var_dump($msg->getExpiration()); - var_dump($msg->getUserId()); - var_dump($msg->getAppId()); - var_dump($msg->getMessageId()); - var_dump($msg->getReplyTo()); - var_dump($msg->getCorrelationId()); - var_dump($msg->getHeaders()); +function dump_message($msg) { + if (!$msg) { + var_dump($msg); + return; + } + + echo get_class($msg), PHP_EOL; + echo " getBody:", PHP_EOL, " "; + var_dump($msg->getBody()); + echo " getContentType:", PHP_EOL, " "; + var_dump($msg->getContentType()); + echo " getRoutingKey:", PHP_EOL, " "; + var_dump($msg->getRoutingKey()); + echo " getDeliveryTag:", PHP_EOL, " "; + var_dump($msg->getDeliveryTag()); + echo " getDeliveryMode:", PHP_EOL, " "; + var_dump($msg->getDeliveryMode()); + echo " getExchangeName:", PHP_EOL, " "; + var_dump($msg->getExchangeName()); + echo " isRedelivery:", PHP_EOL, " "; + var_dump($msg->isRedelivery()); + echo " getContentEncoding:", PHP_EOL, " "; + var_dump($msg->getContentEncoding()); + echo " getType:", PHP_EOL, " "; + var_dump($msg->getType()); + echo " getTimeStamp:", PHP_EOL, " "; + var_dump($msg->getTimeStamp()); + echo " getPriority:", PHP_EOL, " "; + var_dump($msg->getPriority()); + echo " getExpiration:", PHP_EOL, " "; + var_dump($msg->getExpiration()); + echo " getUserId:", PHP_EOL, " "; + var_dump($msg->getUserId()); + echo " getAppId:", PHP_EOL, " "; + var_dump($msg->getAppId()); + echo " getMessageId:", PHP_EOL, " "; + var_dump($msg->getMessageId()); + echo " getReplyTo:", PHP_EOL, " "; + var_dump($msg->getReplyTo()); + echo " getCorrelationId:", PHP_EOL, " "; + var_dump($msg->getCorrelationId()); + echo " getHeaders:", PHP_EOL, " "; + var_dump($msg->getHeaders()); } function consumeThings($message, $queue) { @@ -78,46 +101,82 @@ $ex->delete(); --EXPECTF-- call #0 AMQPEnvelope -string(8) "message1" -string(10) "plain/test" -string(9) "routing.1" -int(1) -int(0) -string(%d) "exchange-%f" -bool(false) -string(0) "" -string(0) "" -int(0) -int(0) -string(0) "" -string(0) "" -string(0) "" -string(0) "" -string(0) "" -string(0) "" -array(1) { + getBody: + string(8) "message1" + getContentType: + string(10) "plain/test" + getRoutingKey: + string(9) "routing.1" + getDeliveryTag: + int(1) + getDeliveryMode: + int(0) + getExchangeName: + string(%d) "exchange-%f" + isRedelivery: + bool(false) + getContentEncoding: + string(0) "" + getType: + string(0) "" + getTimeStamp: + int(0) + getPriority: + int(0) + getExpiration: + string(0) "" + getUserId: + string(0) "" + getAppId: + string(0) "" + getMessageId: + string(0) "" + getReplyTo: + string(0) "" + getCorrelationId: + string(0) "" + getHeaders: + array(1) { ["foo"]=> string(3) "bar" } call #1 AMQPEnvelope -string(8) "message2" -string(10) "text/plain" -string(9) "routing.2" -int(2) -int(2) -string(%d) "exchange-%f" -bool(false) -string(0) "" -string(0) "" -int(0) -int(0) -string(0) "" -string(0) "" -string(0) "" -string(0) "" -string(0) "" -string(0) "" -array(0) { -} + getBody: + string(8) "message2" + getContentType: + string(10) "text/plain" + getRoutingKey: + string(9) "routing.2" + getDeliveryTag: + int(2) + getDeliveryMode: + int(2) + getExchangeName: + string(%d) "exchange-%f" + isRedelivery: + bool(false) + getContentEncoding: + string(0) "" + getType: + string(0) "" + getTimeStamp: + int(0) + getPriority: + int(0) + getExpiration: + string(0) "" + getUserId: + string(0) "" + getAppId: + string(0) "" + getMessageId: + string(0) "" + getReplyTo: + string(0) "" + getCorrelationId: + string(0) "" + getHeaders: + array(0) { +} \ No newline at end of file diff --git a/tests/amqpqueue_get_basic.phpt b/tests/amqpqueue_get_basic.phpt index c9e49ed1..0b065985 100644 --- a/tests/amqpqueue_get_basic.phpt +++ b/tests/amqpqueue_get_basic.phpt @@ -28,30 +28,48 @@ $ex->publish('message2', 'routing.2', AMQP_DURABLE); $ex->publish('message3', 'routing.3'); function dump_message($msg) { - if (!$msg) { - var_dump($msg); - return; - } + if (!$msg) { + var_dump($msg); + return; + } - echo get_class($msg), PHP_EOL; - var_dump($msg->getBody()); - var_dump($msg->getContentType()); - var_dump($msg->getRoutingKey()); - var_dump($msg->getDeliveryTag()); - var_dump($msg->getDeliveryMode()); - var_dump($msg->getExchangeName()); - var_dump($msg->isRedelivery()); - var_dump($msg->getContentEncoding()); - var_dump($msg->getType()); - var_dump($msg->getTimeStamp()); - var_dump($msg->getPriority()); - var_dump($msg->getExpiration()); - var_dump($msg->getUserId()); - var_dump($msg->getAppId()); - var_dump($msg->getMessageId()); - var_dump($msg->getReplyTo()); - var_dump($msg->getCorrelationId()); - var_dump($msg->getHeaders()); + echo get_class($msg), PHP_EOL; + echo " getBody:", PHP_EOL, " "; + var_dump($msg->getBody()); + echo " getContentType:", PHP_EOL, " "; + var_dump($msg->getContentType()); + echo " getRoutingKey:", PHP_EOL, " "; + var_dump($msg->getRoutingKey()); + echo " getDeliveryTag:", PHP_EOL, " "; + var_dump($msg->getDeliveryTag()); + echo " getDeliveryMode:", PHP_EOL, " "; + var_dump($msg->getDeliveryMode()); + echo " getExchangeName:", PHP_EOL, " "; + var_dump($msg->getExchangeName()); + echo " isRedelivery:", PHP_EOL, " "; + var_dump($msg->isRedelivery()); + echo " getContentEncoding:", PHP_EOL, " "; + var_dump($msg->getContentEncoding()); + echo " getType:", PHP_EOL, " "; + var_dump($msg->getType()); + echo " getTimeStamp:", PHP_EOL, " "; + var_dump($msg->getTimeStamp()); + echo " getPriority:", PHP_EOL, " "; + var_dump($msg->getPriority()); + echo " getExpiration:", PHP_EOL, " "; + var_dump($msg->getExpiration()); + echo " getUserId:", PHP_EOL, " "; + var_dump($msg->getUserId()); + echo " getAppId:", PHP_EOL, " "; + var_dump($msg->getAppId()); + echo " getMessageId:", PHP_EOL, " "; + var_dump($msg->getMessageId()); + echo " getReplyTo:", PHP_EOL, " "; + var_dump($msg->getReplyTo()); + echo " getCorrelationId:", PHP_EOL, " "; + var_dump($msg->getCorrelationId()); + echo " getHeaders:", PHP_EOL, " "; + var_dump($msg->getHeaders()); } for ($i = 0; $i < 4; $i++) { @@ -66,70 +84,124 @@ for ($i = 0; $i < 4; $i++) { --EXPECTF-- call #0 AMQPEnvelope -string(8) "message1" -string(10) "plain/test" -string(9) "routing.1" -int(1) -int(0) -string(%d) "exchange-%f" -bool(false) -string(0) "" -string(0) "" -int(0) -int(0) -string(0) "" -string(0) "" -string(0) "" -string(0) "" -string(0) "" -string(0) "" -array(1) { + getBody: + string(8) "message1" + getContentType: + string(10) "plain/test" + getRoutingKey: + string(9) "routing.1" + getDeliveryTag: + int(1) + getDeliveryMode: + int(0) + getExchangeName: + string(%d) "exchange-%f" + isRedelivery: + bool(false) + getContentEncoding: + string(0) "" + getType: + string(0) "" + getTimeStamp: + int(0) + getPriority: + int(0) + getExpiration: + string(0) "" + getUserId: + string(0) "" + getAppId: + string(0) "" + getMessageId: + string(0) "" + getReplyTo: + string(0) "" + getCorrelationId: + string(0) "" + getHeaders: + array(1) { ["foo"]=> string(3) "bar" } call #1 AMQPEnvelope -string(8) "message2" -string(10) "text/plain" -string(9) "routing.2" -int(2) -int(0) -string(%d) "exchange-%f" -bool(false) -string(0) "" -string(0) "" -int(0) -int(0) -string(0) "" -string(0) "" -string(0) "" -string(0) "" -string(0) "" -string(0) "" -array(0) { + getBody: + string(8) "message2" + getContentType: + string(10) "text/plain" + getRoutingKey: + string(9) "routing.2" + getDeliveryTag: + int(2) + getDeliveryMode: + int(0) + getExchangeName: + string(%d) "exchange-%f" + isRedelivery: + bool(false) + getContentEncoding: + string(0) "" + getType: + string(0) "" + getTimeStamp: + int(0) + getPriority: + int(0) + getExpiration: + string(0) "" + getUserId: + string(0) "" + getAppId: + string(0) "" + getMessageId: + string(0) "" + getReplyTo: + string(0) "" + getCorrelationId: + string(0) "" + getHeaders: + array(0) { } call #2 AMQPEnvelope -string(8) "message3" -string(10) "text/plain" -string(9) "routing.3" -int(3) -int(0) -string(%d) "exchange-%f" -bool(false) -string(0) "" -string(0) "" -int(0) -int(0) -string(0) "" -string(0) "" -string(0) "" -string(0) "" -string(0) "" -string(0) "" -array(0) { + getBody: + string(8) "message3" + getContentType: + string(10) "text/plain" + getRoutingKey: + string(9) "routing.3" + getDeliveryTag: + int(3) + getDeliveryMode: + int(0) + getExchangeName: + string(%d) "exchange-%f" + isRedelivery: + bool(false) + getContentEncoding: + string(0) "" + getType: + string(0) "" + getTimeStamp: + int(0) + getPriority: + int(0) + getExpiration: + string(0) "" + getUserId: + string(0) "" + getAppId: + string(0) "" + getMessageId: + string(0) "" + getReplyTo: + string(0) "" + getCorrelationId: + string(0) "" + getHeaders: + array(0) { } call #3