From 618e06ad2ef867598831cdd3faadba0dd65be917 Mon Sep 17 00:00:00 2001 From: Liviu-Ionut Iosif Date: Sat, 18 Feb 2023 16:03:49 +0200 Subject: [PATCH 001/147] Fix deprecation issue in PHP 8.1 for $consumerTag argument to AMQPQueue::consume() method (#421) Deprecation occurs because the $consumerTag argument is not defined as nullable but it defaults to NULL when nothing is passed to it. PHP 8.1 deprecation release notes: https://www.php.net/releases/8.1/en.php#deprecations_and_bc_breaks --- stubs/AMQPQueue.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stubs/AMQPQueue.php b/stubs/AMQPQueue.php index a46b7829..af2af82f 100644 --- a/stubs/AMQPQueue.php +++ b/stubs/AMQPQueue.php @@ -105,7 +105,7 @@ public function __construct(AMQPChannel $amqp_channel) * `basic.consume` request and just run $callback * if it provided. Calling method with empty $callback * and AMQP_JUST_CONSUME makes no sense. - * @param string $consumerTag A string describing this consumer. Used + * @param string | null $consumerTag A string describing this consumer. Used * for canceling subscriptions with cancel(). * * @throws AMQPChannelException If the channel is not open. @@ -118,7 +118,7 @@ public function __construct(AMQPChannel $amqp_channel) public function consume( callable $callback = null, $flags = AMQP_NOPARAM, - $consumerTag = null + ?$consumerTag = null ) { } From eb9101666e9f939e1c8df7de54c999009623aad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Heleno?= Date: Mon, 19 Jun 2023 11:11:08 -0300 Subject: [PATCH 002/147] Expose Delivery Mode through constants (#420) --- amqp.c | 3 +++ stubs/AMQP.php | 8 ++++++++ stubs/AMQPBasicProperties.php | 2 +- tests/amqpqueue_consume_basic.phpt | 2 +- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/amqp.c b/amqp.c index e004f5a9..6f6e1c1a 100644 --- a/amqp.c +++ b/amqp.c @@ -183,6 +183,9 @@ static PHP_MINIT_FUNCTION(amqp) /* {{{ */ REGISTER_LONG_CONSTANT("AMQP_SASL_METHOD_PLAIN", AMQP_SASL_METHOD_PLAIN, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("AMQP_SASL_METHOD_EXTERNAL", AMQP_SASL_METHOD_EXTERNAL, CONST_CS | CONST_PERSISTENT); + + REGISTER_LONG_CONSTANT("AMQP_DELIVERY_MODE_TRANSIENT", AMQP_DELIVERY_NONPERSISTENT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("AMQP_DELIVERY_MODE_PERSISTENT", AMQP_DELIVERY_PERSISTENT, CONST_CS | CONST_PERSISTENT); return SUCCESS; } /* }}} */ diff --git a/stubs/AMQP.php b/stubs/AMQP.php index a366d6f9..7cfabeff 100644 --- a/stubs/AMQP.php +++ b/stubs/AMQP.php @@ -133,3 +133,11 @@ * */ define('AMQP_SASL_METHOD_EXTERNAL', 1); +/** + * Default delivery mode, keeps the message in memory when the message is placed in a queue. + */ +define('AMQP_DELIVERY_MODE_TRANSIENT', 1); +/** + * Writes the message to the disk when the message is placed in a durable queue. + */ +define('AMQP_DELIVERY_MODE_PERSISTENT', 2) diff --git a/stubs/AMQPBasicProperties.php b/stubs/AMQPBasicProperties.php index 947db8b9..6b14af49 100644 --- a/stubs/AMQPBasicProperties.php +++ b/stubs/AMQPBasicProperties.php @@ -25,7 +25,7 @@ public function __construct( $content_type = "", $content_encoding = "", array $headers = [], - $delivery_mode = 2, + $delivery_mode = AMQP_DELIVERY_MODE_TRANSIENT, $priority = 0, $correlation_id = "", $reply_to = "", diff --git a/tests/amqpqueue_consume_basic.phpt b/tests/amqpqueue_consume_basic.phpt index f06891b8..c7e67749 100644 --- a/tests/amqpqueue_consume_basic.phpt +++ b/tests/amqpqueue_consume_basic.phpt @@ -27,7 +27,7 @@ $q->bind($ex->getName(), 'routing.*'); // Publish a message to the exchange with a routing key $ex->publish('message1', 'routing.1', AMQP_NOPARAM, array('content_type' => 'plain/test', 'headers' => array('foo' => 'bar'))); -$ex->publish('message2', 'routing.2', AMQP_NOPARAM, array('delivery_mode' => AMQP_DURABLE)); +$ex->publish('message2', 'routing.2', AMQP_NOPARAM, array('delivery_mode' => AMQP_DELIVERY_MODE_PERSISTENT)); $ex->publish('message3', 'routing.3', AMQP_DURABLE); // this is wrong way to make messages persistent $count = 0; From 7e5e7626491911df2e1b74c5ef33a8d068a35b9d Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Sat, 8 Jul 2023 14:09:49 +0200 Subject: [PATCH 003/147] Document custom connection name in stubs --- stubs/AMQPConnection.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/stubs/AMQPConnection.php b/stubs/AMQPConnection.php index 960a019e..532eed2e 100644 --- a/stubs/AMQPConnection.php +++ b/stubs/AMQPConnection.php @@ -50,6 +50,8 @@ public function connect() * 'key' => Path to the client key in PEM format. * 'verify' => Enable or disable peer verification. If peer verification is enabled then the common name in the * server certificate must match the server name. Peer verification is enabled by default. + * + * 'connection_name' => A user determined name for the connection * ) * * @param array $credentials Optional array of credential information for @@ -480,4 +482,18 @@ public function setSaslMethod($method) public function getSaslMethod() { } + + /** + * @param string|null $connection_name + */ + public function setConnectionName($connection_name) + { + } + + /** + * @return string|null + */ + public function getConnectionName() + { + } } From d84d0812f5be11f312231622613537a016cc63d0 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 19 Jul 2023 11:07:59 +0200 Subject: [PATCH 004/147] Fix stub exception class (closes #427) --- stubs/AMQPDecimal.php | 2 +- stubs/AMQPTimestamp.php | 2 +- stubs/AMQPValueException.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/stubs/AMQPDecimal.php b/stubs/AMQPDecimal.php index a4d2741a..caf836e0 100644 --- a/stubs/AMQPDecimal.php +++ b/stubs/AMQPDecimal.php @@ -14,7 +14,7 @@ final class AMQPDecimal * @param $exponent * @param $significand * - * @throws AMQPExchangeValue + * @throws AMQPValueException */ public function __construct($exponent, $significand) { diff --git a/stubs/AMQPTimestamp.php b/stubs/AMQPTimestamp.php index 4b8d9897..f58561ef 100644 --- a/stubs/AMQPTimestamp.php +++ b/stubs/AMQPTimestamp.php @@ -11,7 +11,7 @@ final class AMQPTimestamp /** * @param string $timestamp * - * @throws AMQPExchangeValue + * @throws AMQPValueException */ public function __construct($timestamp) { diff --git a/stubs/AMQPValueException.php b/stubs/AMQPValueException.php index 2cfacf7e..5a72e8a9 100644 --- a/stubs/AMQPValueException.php +++ b/stubs/AMQPValueException.php @@ -1,8 +1,8 @@ Date: Tue, 25 Jul 2023 16:03:24 +0300 Subject: [PATCH 005/147] Fix php version check for static building (#425) When built statically (`--with-amqp`) configuration script should not depend on `php-config`, since it might refer to previous version of php or be not yet installed at all. `$PHP_VERSION` and `$PHP_VERSION_ID` can be used instead. --- config.m4 | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/config.m4 b/config.m4 index 3e30d485..43877c87 100644 --- a/config.m4 +++ b/config.m4 @@ -10,9 +10,16 @@ dnl Set test wrapper binary to ignore any local ini settings PHP_EXECUTABLE="$PWD/php-test-bin" if test "$PHP_AMQP" != "no"; then - AC_MSG_CHECKING([for supported PHP versions]) - PHP_REF_FOUND_VERSION=`${PHP_CONFIG} --version` - PHP_REF_FOUND_VERNUM=`${PHP_CONFIG} --vernum` + AC_MSG_CHECKING([for supported PHP versions]) + PHP_REF_FOUND_VERSION=$PHP_VERSION + PHP_REF_FOUND_VERNUM=$PHP_VERSION_ID + if test -z "$PHP_REF_FOUND_VERNUM"; then + if test -z "$PHP_CONFIG"; then + AC_MSG_ERROR([php-config not found]) + fi + PHP_REF_FOUND_VERSION=`${PHP_CONFIG} --version` + PHP_REF_FOUND_VERNUM=`${PHP_CONFIG} --vernum` + fi if test "$PHP_REF_FOUND_VERNUM" -lt "50600"; then AC_MSG_ERROR([PHP version not supported, >= 5.6 required, but $PHP_REF_FOUND_VERSION found]) From 5dab45a0d2f55784ec1ad14f5770fa843c543987 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Tue, 25 Jul 2023 18:30:33 +0200 Subject: [PATCH 006/147] PHP 8.2 refactorings (#430) --- .github/dependabot.yml | 7 + .github/workflows/test.yaml | 134 ++++++--------- README.md | 4 +- amqp.c | 25 ++- amqp_basic_properties.c | 255 +++++++++++++-------------- amqp_channel.c | 189 +++++--------------- amqp_connection.c | 331 +++++++++++++++++------------------- amqp_connection_resource.c | 13 +- amqp_connection_resource.h | 6 +- amqp_decimal.c | 20 +-- amqp_envelope.c | 52 +++--- amqp_envelope.h | 6 +- amqp_exchange.c | 213 ++++++++++++----------- amqp_methods_handling.c | 86 ++++------ amqp_methods_handling.h | 8 +- amqp_queue.c | 251 +++++++++++++-------------- amqp_timestamp.c | 24 +-- amqp_type.c | 100 +++++------ amqp_type.h | 10 +- config.m4 | 36 +++- package.xml | 4 +- php5_support.h | 123 -------------- php7_support.h | 133 --------------- php_amqp.h | 92 +++++----- 24 files changed, 860 insertions(+), 1262 deletions(-) create mode 100644 .github/dependabot.yml delete mode 100644 php5_support.h delete mode 100644 php7_support.h diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..1a2f2fc5 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: daily + open-pull-requests-limit: 30 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 7e117477..c36b2622 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -12,9 +12,7 @@ env: jobs: test: name: php-${{ matrix.php-version }} librabbitmq-${{ matrix.librabbitmq-version }} ${{ matrix.test-php-args == '-m' && 'memory leaks' || '' }} - - runs-on: ubuntu-latest - + runs-on: ${{ matrix.os }} continue-on-error: ${{ matrix.experimental }} env: @@ -24,117 +22,93 @@ jobs: fail-fast: false matrix: include: - - php-version: '8.1' + - php-version: '8.2' librabbitmq-version: 'master' experimental: false - - php-version: '8.1' + os: ubuntu-22.04 + - php-version: '8.2' librabbitmq-version: 'master' test-php-args: '-m' - experimental: true - - php-version: '8.1' - librabbitmq-version: 'v0.11.0' - experimental: false - - php-version: '8.1' - librabbitmq-version: 'v0.9.0' experimental: false - - - php-version: '8.0' - librabbitmq-version: 'master' + os: ubuntu-22.04 + - php-version: '8.2' + librabbitmq-version: 'v0.13.0' experimental: false - - php-version: '8.0' - librabbitmq-version: 'master' - test-php-args: '-m' - experimental: true - - php-version: '8.0' + os: ubuntu-22.04 + - php-version: '8.2' librabbitmq-version: 'v0.11.0' experimental: false - - php-version: '8.0' - librabbitmq-version: 'v0.9.0' + os: ubuntu-22.04 + - php-version: '8.2' + librabbitmq-version: 'v0.10.0' experimental: false + os: ubuntu-20.04 - - php-version: '7.4' + - php-version: '8.1' librabbitmq-version: 'master' experimental: false - - php-version: '7.4' - librabbitmq-version: 'v0.11.0' - experimental: false - - php-version: '7.4' - librabbitmq-version: 'v0.11.0' + os: ubuntu-22.04 + - php-version: '8.1' + librabbitmq-version: 'master' test-php-args: '-m' - experimental: true - - php-version: '7.4' - librabbitmq-version: 'v0.9.0' experimental: false - - - php-version: '7.3' - librabbitmq-version: 'master' + os: ubuntu-22.04 + - php-version: '8.1' + librabbitmq-version: 'v0.13.0' experimental: false - - php-version: '7.3' + os: ubuntu-22.04 + - php-version: '8.1' librabbitmq-version: 'v0.11.0' experimental: false - - php-version: '7.3' - librabbitmq-version: 'v0.9.0' + os: ubuntu-22.04 + - php-version: '8.1' + librabbitmq-version: 'v0.10.0' experimental: false - - php-version: '7.3' - librabbitmq-version: 'v0.9.0' - test-php-args: '-m' - experimental: true + os: ubuntu-20.04 - - php-version: '7.2' + - php-version: '8.0' librabbitmq-version: 'master' experimental: false - - php-version: '7.2' + os: ubuntu-22.04 + - php-version: '8.0' librabbitmq-version: 'master' test-php-args: '-m' experimental: true - - php-version: '7.2' - librabbitmq-version: 'v0.11.0' - experimental: false - - php-version: '7.2' - librabbitmq-version: 'v0.9.0' - experimental: false - - - php-version: '7.1' - librabbitmq-version: 'master' + os: ubuntu-22.04 + - php-version: '8.0' + librabbitmq-version: 'v0.13.0' experimental: false - - php-version: '7.1' + os: ubuntu-22.04 + - php-version: '8.0' librabbitmq-version: 'v0.11.0' experimental: false - - php-version: '7.1' - librabbitmq-version: 'v0.11.0' - test-php-args: '-m' - experimental: true - - php-version: '7.1' - librabbitmq-version: 'v0.9.0' + os: ubuntu-22.04 + - php-version: '8.0' + librabbitmq-version: 'v0.10.0' experimental: false + os: ubuntu-20.04 - - php-version: '7.0' + - php-version: '7.4' librabbitmq-version: 'master' experimental: false - - php-version: '7.0' - librabbitmq-version: 'v0.11.0' - experimental: false - - php-version: '7.0' - librabbitmq-version: 'v0.9.0' - experimental: false - - php-version: '7.0' - librabbitmq-version: 'v0.9.0' - test-php-args: '-m' - experimental: true - - - php-version: '5.6' - librabbitmq-version: 'master' + os: ubuntu-22.04 + - php-version: '7.4' + librabbitmq-version: 'v0.13.0' experimental: false - - php-version: '5.6' - librabbitmq-version: 'master' + os: ubuntu-22.04 + - php-version: '7.4' + librabbitmq-version: 'v0.13.0' test-php-args: '-m' experimental: true - - php-version: '5.6' + os: ubuntu-22.04 + - php-version: '7.4' librabbitmq-version: 'v0.11.0' experimental: false - - php-version: '5.6' - librabbitmq-version: 'v0.9.0' + os: ubuntu-22.04 + - php-version: '7.4' + librabbitmq-version: 'v0.10.0' experimental: false + os: ubuntu-20.04 services: rabbitmq: @@ -147,13 +121,13 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3.5.3 - name: Install packages run: sudo apt-get install -y cmake valgrind - name: Setup PHP - uses: shivammathur/setup-php@v2 + uses: shivammathur/setup-php@2.25.3 with: php-version: ${{ matrix.php-version }} coverage: none @@ -165,6 +139,8 @@ jobs: run: pkg-config librabbitmq --debug - name: Build PHP extension + env: + CFLAGS: -D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror run: phpize && ./configure && make - name: Test PHP extension diff --git a/README.md b/README.md index c67d919e..76b1f12f 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ Object-oriented PHP bindings for the AMQP C library (https://github.com/alanxz/r ### Requirements: - - PHP >= 5.6 (PHP 7 included) with either ZTS or non-ZTS version. + - PHP >= 7.4 with either ZTS or non-ZTS version. - [RabbitMQ C library](https://github.com/alanxz/rabbitmq-c), commonly known as librabbitmq - (since php-amqp>=1.9.4 librabbitmq >= 0.7.1, + (since php-amqp >= 1.12.0 librabbitmq >= 0.10.0, see [release notes](https://pecl.php.net/package-changelog.php?package=amqp)). - to run tests [RabbitMQ server](https://www.rabbitmq.com/) >= 3.4.0 required. diff --git a/amqp.c b/amqp.c index 6f6e1c1a..bca75bf4 100644 --- a/amqp.c +++ b/amqp.c @@ -41,8 +41,14 @@ # include # include #endif + +#if HAVE_LIBRABBITMQ_NEW_LAYOUT +#include +#include +#else #include #include +#endif #include "php_amqp.h" #include "amqp_connection.h" @@ -106,7 +112,7 @@ PHP_INI_BEGIN() PHP_INI_ENTRY("amqp.sasl_method", DEFAULT_SASL_METHOD, PHP_INI_ALL, NULL) PHP_INI_END() -ZEND_DECLARE_MODULE_GLOBALS(amqp); +ZEND_DECLARE_MODULE_GLOBALS(amqp) static PHP_GINIT_FUNCTION(amqp) /* {{{ */ { @@ -133,26 +139,26 @@ static PHP_MINIT_FUNCTION(amqp) /* {{{ */ /* Class Exceptions */ INIT_CLASS_ENTRY(ce, "AMQPException", NULL); - amqp_exception_class_entry = PHP5to7_zend_register_internal_class_ex(&ce, zend_exception_get_default(TSRMLS_C)); + amqp_exception_class_entry = zend_register_internal_class_ex(&ce, zend_exception_get_default(TSRMLS_C)); INIT_CLASS_ENTRY(ce, "AMQPConnectionException", NULL); - amqp_connection_exception_class_entry = PHP5to7_zend_register_internal_class_ex(&ce, amqp_exception_class_entry); + amqp_connection_exception_class_entry = zend_register_internal_class_ex(&ce, amqp_exception_class_entry); INIT_CLASS_ENTRY(ce, "AMQPChannelException", NULL); - amqp_channel_exception_class_entry = PHP5to7_zend_register_internal_class_ex(&ce, amqp_exception_class_entry); + amqp_channel_exception_class_entry = zend_register_internal_class_ex(&ce, amqp_exception_class_entry); INIT_CLASS_ENTRY(ce, "AMQPQueueException", NULL); - amqp_queue_exception_class_entry = PHP5to7_zend_register_internal_class_ex(&ce, amqp_exception_class_entry); + amqp_queue_exception_class_entry = zend_register_internal_class_ex(&ce, amqp_exception_class_entry); INIT_CLASS_ENTRY(ce, "AMQPEnvelopeException", NULL); - amqp_envelope_exception_class_entry = PHP5to7_zend_register_internal_class_ex(&ce, amqp_exception_class_entry); + amqp_envelope_exception_class_entry = zend_register_internal_class_ex(&ce, amqp_exception_class_entry); zend_declare_property_null(amqp_envelope_exception_class_entry, ZEND_STRL("envelope"), ZEND_ACC_PUBLIC TSRMLS_CC); INIT_CLASS_ENTRY(ce, "AMQPExchangeException", NULL); - amqp_exchange_exception_class_entry = PHP5to7_zend_register_internal_class_ex(&ce, amqp_exception_class_entry); + amqp_exchange_exception_class_entry = zend_register_internal_class_ex(&ce, amqp_exception_class_entry); INIT_CLASS_ENTRY(ce, "AMQPValueException", NULL); - amqp_value_exception_class_entry = PHP5to7_zend_register_internal_class_ex(&ce, amqp_exception_class_entry); + amqp_value_exception_class_entry = zend_register_internal_class_ex(&ce, amqp_exception_class_entry); REGISTER_INI_ENTRIES(); @@ -186,6 +192,7 @@ static PHP_MINIT_FUNCTION(amqp) /* {{{ */ REGISTER_LONG_CONSTANT("AMQP_DELIVERY_MODE_TRANSIENT", AMQP_DELIVERY_NONPERSISTENT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("AMQP_DELIVERY_MODE_PERSISTENT", AMQP_DELIVERY_PERSISTENT, CONST_CS | CONST_PERSISTENT); + return SUCCESS; } /* }}} */ @@ -302,7 +309,7 @@ void php_amqp_zend_throw_exception_short(amqp_rpc_reply_t reply, zend_class_entr php_amqp_zend_throw_exception(reply, exception_ce, PHP_AMQP_G(error_message), PHP_AMQP_G(error_code) TSRMLS_CC); } -void php_amqp_zend_throw_exception(amqp_rpc_reply_t reply, zend_class_entry *exception_ce, const char *message, PHP5to7_param_long_type_t code TSRMLS_DC) +void php_amqp_zend_throw_exception(amqp_rpc_reply_t reply, zend_class_entry *exception_ce, const char *message, zend_long code TSRMLS_DC) { switch (reply.reply_type) { case AMQP_RESPONSE_NORMAL: diff --git a/amqp_basic_properties.c b/amqp_basic_properties.c index dd46426c..8f5f4340 100644 --- a/amqp_basic_properties.c +++ b/amqp_basic_properties.c @@ -31,8 +31,13 @@ #include "zend_exceptions.h" #include "Zend/zend_interfaces.h" +#if HAVE_LIBRABBITMQ_NEW_LAYOUT +#include +#include +#else #include #include +#endif #ifdef PHP_WIN32 # include "win32/unistd.h" @@ -69,39 +74,39 @@ void php_amqp_basic_properties_convert_to_zval(amqp_basic_properties_t *props, z } void php_amqp_basic_properties_set_empty_headers(zval *obj TSRMLS_DC) { - PHP5to7_zval_t headers PHP5to7_MAYBE_SET_TO_NULL; + zval headers; - PHP5to7_MAYBE_INIT(headers); - PHP5to7_ARRAY_INIT(headers); + ZVAL_UNDEF(&headers); + array_init(&headers); - zend_update_property(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("headers"), PHP5to7_MAYBE_PTR(headers) TSRMLS_CC); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("headers"), &headers TSRMLS_CC); - PHP5to7_MAYBE_DESTROY(headers); + zval_ptr_dtor(&headers); } /* {{{ proto AMQPBasicProperties::__construct() */ static PHP_METHOD(AMQPBasicProperties, __construct) { - char *content_type = NULL; PHP5to7_param_str_len_type_t content_type_len = 0; - char *content_encoding = NULL; PHP5to7_param_str_len_type_t content_encoding_len = 0; + char *content_type = NULL; size_t content_type_len = 0; + char *content_encoding = NULL; size_t content_encoding_len = 0; zval *headers = NULL; - PHP5to7_param_long_type_t delivery_mode = AMQP_DELIVERY_NONPERSISTENT; - PHP5to7_param_long_type_t priority = 0; + zend_long delivery_mode = AMQP_DELIVERY_NONPERSISTENT; + zend_long priority = 0; - char *correlation_id = NULL; PHP5to7_param_str_len_type_t correlation_id_len = 0; - char *reply_to = NULL; PHP5to7_param_str_len_type_t reply_to_len = 0; - char *expiration = NULL; PHP5to7_param_str_len_type_t expiration_len = 0; - char *message_id = NULL; PHP5to7_param_str_len_type_t message_id_len = 0; + char *correlation_id = NULL; size_t correlation_id_len = 0; + char *reply_to = NULL; size_t reply_to_len = 0; + char *expiration = NULL; size_t expiration_len = 0; + char *message_id = NULL; size_t message_id_len = 0; - PHP5to7_param_long_type_t timestamp = 0; + zend_long timestamp = 0; - char *type = NULL; PHP5to7_param_str_len_type_t type_len = 0; - char *user_id = NULL; PHP5to7_param_str_len_type_t user_id_len = 0; - char *app_id = NULL; PHP5to7_param_str_len_type_t app_id_len = 0; - char *cluster_id = NULL; PHP5to7_param_str_len_type_t cluster_id_len = 0; + char *type = NULL; size_t type_len = 0; + char *user_id = NULL; size_t user_id_len = 0; + char *app_id = NULL; size_t app_id_len = 0; + char *cluster_id = NULL; size_t cluster_id_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ssallsssslssss", @@ -122,35 +127,35 @@ static PHP_METHOD(AMQPBasicProperties, __construct) { ) == FAILURE) { return; } - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("content_type"), content_type, content_type_len TSRMLS_CC); - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("content_encoding"), content_encoding, content_encoding_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("content_type"), content_type, content_type_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("content_encoding"), content_encoding, content_encoding_len TSRMLS_CC); if (headers != NULL) { - zend_update_property(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("headers"), headers TSRMLS_CC); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("headers"), headers TSRMLS_CC); } else { php_amqp_basic_properties_set_empty_headers(getThis() TSRMLS_CC); } - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("delivery_mode"), delivery_mode TSRMLS_CC); - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("priority"), priority TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("delivery_mode"), delivery_mode TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("priority"), priority TSRMLS_CC); - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("correlation_id"), correlation_id, correlation_id_len TSRMLS_CC); - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("reply_to"), reply_to, reply_to_len TSRMLS_CC); - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("expiration"), expiration, expiration_len TSRMLS_CC); - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("message_id"), message_id, message_id_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("correlation_id"), correlation_id, correlation_id_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("reply_to"), reply_to, reply_to_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("expiration"), expiration, expiration_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("message_id"), message_id, message_id_len TSRMLS_CC); - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("timestamp"), timestamp TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("timestamp"), timestamp TSRMLS_CC); - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("type"), type, type_len TSRMLS_CC); - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("user_id"), user_id, user_id_len TSRMLS_CC); - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("app_id"), app_id, app_id_len TSRMLS_CC); - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("cluster_id"), cluster_id, cluster_id_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("type"), type, type_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("user_id"), user_id, user_id_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("app_id"), app_id, app_id_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("cluster_id"), cluster_id, cluster_id_len TSRMLS_CC); } /* }}} */ /* {{{ proto AMQPBasicProperties::getContentType() */ static PHP_METHOD(AMQPBasicProperties, getContentType) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("content_type"); } @@ -158,7 +163,7 @@ static PHP_METHOD(AMQPBasicProperties, getContentType) { /* {{{ proto AMQPBasicProperties::getContentEncoding() */ static PHP_METHOD(AMQPBasicProperties, getContentEncoding) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("content_encoding"); } @@ -166,7 +171,7 @@ static PHP_METHOD(AMQPBasicProperties, getContentEncoding) { /* {{{ proto AMQPBasicProperties::getCorrelationId() */ static PHP_METHOD(AMQPBasicProperties, getHeaders) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("headers"); } @@ -174,7 +179,7 @@ static PHP_METHOD(AMQPBasicProperties, getHeaders) { /* {{{ proto AMQPBasicProperties::getDeliveryMode() */ static PHP_METHOD(AMQPBasicProperties, getDeliveryMode) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("delivery_mode"); } @@ -182,7 +187,7 @@ static PHP_METHOD(AMQPBasicProperties, getDeliveryMode) { /* {{{ proto AMQPBasicProperties::getPriority() */ static PHP_METHOD(AMQPBasicProperties, getPriority) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("priority"); } @@ -190,7 +195,7 @@ static PHP_METHOD(AMQPBasicProperties, getPriority) { /* {{{ proto AMQPBasicProperties::getCorrelationId() */ static PHP_METHOD(AMQPBasicProperties, getCorrelationId) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("correlation_id"); } @@ -198,7 +203,7 @@ static PHP_METHOD(AMQPBasicProperties, getCorrelationId) { /* {{{ proto AMQPBasicProperties::getReplyTo() */ static PHP_METHOD(AMQPBasicProperties, getReplyTo) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("reply_to"); } @@ -207,7 +212,7 @@ static PHP_METHOD(AMQPBasicProperties, getReplyTo) { /* {{{ proto AMQPBasicProperties::getExpiration() check amqp envelope */ static PHP_METHOD(AMQPBasicProperties, getExpiration) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("expiration"); } @@ -215,7 +220,7 @@ static PHP_METHOD(AMQPBasicProperties, getExpiration) { /* {{{ proto AMQPBasicProperties::getMessageId() */ static PHP_METHOD(AMQPBasicProperties, getMessageId) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("message_id"); } @@ -223,7 +228,7 @@ static PHP_METHOD(AMQPBasicProperties, getMessageId) { /* {{{ proto AMQPBasicProperties::getTimestamp() */ static PHP_METHOD(AMQPBasicProperties, getTimestamp) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("timestamp"); } @@ -231,7 +236,7 @@ static PHP_METHOD(AMQPBasicProperties, getTimestamp) { /* {{{ proto AMQPBasicProperties::getType() */ static PHP_METHOD(AMQPBasicProperties, getType) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("type"); } @@ -239,7 +244,7 @@ static PHP_METHOD(AMQPBasicProperties, getType) { /* {{{ proto AMQPBasicProperties::getUserId() */ static PHP_METHOD(AMQPBasicProperties, getUserId) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("user_id"); } @@ -247,7 +252,7 @@ static PHP_METHOD(AMQPBasicProperties, getUserId) { /* {{{ proto AMQPBasicProperties::getAppId() */ static PHP_METHOD(AMQPBasicProperties, getAppId) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("app_id"); } @@ -255,7 +260,7 @@ static PHP_METHOD(AMQPBasicProperties, getAppId) { /* {{{ proto AMQPBasicProperties::getClusterId() */ static PHP_METHOD(AMQPBasicProperties, getClusterId) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("cluster_id"); } @@ -368,79 +373,79 @@ void parse_amqp_table(amqp_table_t *table, zval *result TSRMLS_DC) { int i; zend_bool has_value = 0; - PHP5to7_zval_t value PHP5to7_MAYBE_SET_TO_NULL; + zval value; assert(Z_TYPE_P(result) == IS_ARRAY); for (i = 0; i < table->num_entries; i++) { - PHP5to7_MAYBE_INIT(value); + ZVAL_UNDEF(&value); has_value = 1; amqp_table_entry_t *entry = &(table->entries[i]); switch (entry->value.kind) { case AMQP_FIELD_KIND_BOOLEAN: - ZVAL_BOOL(PHP5to7_MAYBE_PTR(value), entry->value.value.boolean); + ZVAL_BOOL(&value, entry->value.value.boolean); break; case AMQP_FIELD_KIND_I8: - ZVAL_LONG(PHP5to7_MAYBE_PTR(value), entry->value.value.i8); + ZVAL_LONG(&value, entry->value.value.i8); break; case AMQP_FIELD_KIND_U8: - ZVAL_LONG(PHP5to7_MAYBE_PTR(value), entry->value.value.u8); + ZVAL_LONG(&value, entry->value.value.u8); break; case AMQP_FIELD_KIND_I16: - ZVAL_LONG(PHP5to7_MAYBE_PTR(value), entry->value.value.i16); + ZVAL_LONG(&value, entry->value.value.i16); break; case AMQP_FIELD_KIND_U16: - ZVAL_LONG(PHP5to7_MAYBE_PTR(value), entry->value.value.u16); + ZVAL_LONG(&value, entry->value.value.u16); break; case AMQP_FIELD_KIND_I32: - ZVAL_LONG(PHP5to7_MAYBE_PTR(value), entry->value.value.i32); + ZVAL_LONG(&value, entry->value.value.i32); break; case AMQP_FIELD_KIND_U32: - ZVAL_LONG(PHP5to7_MAYBE_PTR(value), entry->value.value.u32); + ZVAL_LONG(&value, entry->value.value.u32); break; case AMQP_FIELD_KIND_I64: - ZVAL_LONG(PHP5to7_MAYBE_PTR(value), entry->value.value.i64); + ZVAL_LONG(&value, entry->value.value.i64); break; case AMQP_FIELD_KIND_U64: if (entry->value.value.u64 > LONG_MAX) { - ZVAL_DOUBLE(PHP5to7_MAYBE_PTR(value), entry->value.value.u64); + ZVAL_DOUBLE(&value, entry->value.value.u64); } else { - ZVAL_LONG(PHP5to7_MAYBE_PTR(value), entry->value.value.u64); + ZVAL_LONG(&value, entry->value.value.u64); } break; case AMQP_FIELD_KIND_F32: - ZVAL_DOUBLE(PHP5to7_MAYBE_PTR(value), entry->value.value.f32); + ZVAL_DOUBLE(&value, entry->value.value.f32); break; case AMQP_FIELD_KIND_F64: - ZVAL_DOUBLE(PHP5to7_MAYBE_PTR(value), entry->value.value.f64); + ZVAL_DOUBLE(&value, entry->value.value.f64); break; case AMQP_FIELD_KIND_UTF8: case AMQP_FIELD_KIND_BYTES: - PHP5to7_ZVAL_STRINGL_DUP(PHP5to7_MAYBE_PTR(value), entry->value.value.bytes.bytes, entry->value.value.bytes.len); + ZVAL_STRINGL(&value, entry->value.value.bytes.bytes, entry->value.value.bytes.len); break; case AMQP_FIELD_KIND_ARRAY: { int j; - array_init(PHP5to7_MAYBE_PTR(value)); + array_init(&value); for (j = 0; j < entry->value.value.array.num_entries; ++j) { switch (entry->value.value.array.entries[j].kind) { case AMQP_FIELD_KIND_UTF8: - PHP5to7_ADD_NEXT_INDEX_STRINGL_DUP( - PHP5to7_MAYBE_PTR(value), + add_next_index_stringl( + &value, entry->value.value.array.entries[j].value.bytes.bytes, - (unsigned) entry->value.value.array.entries[j].value.bytes.len + entry->value.value.array.entries[j].value.bytes.len ); break; case AMQP_FIELD_KIND_TABLE: { - PHP5to7_zval_t subtable PHP5to7_MAYBE_SET_TO_NULL; - PHP5to7_MAYBE_INIT(subtable); - PHP5to7_ARRAY_INIT(subtable); + zval subtable; + ZVAL_UNDEF(&subtable); + array_init(&subtable); parse_amqp_table( &(entry->value.value.array.entries[j].value.table), - PHP5to7_MAYBE_PTR(subtable) TSRMLS_CC + &subtable TSRMLS_CC ); - add_next_index_zval(PHP5to7_MAYBE_PTR(value), PHP5to7_MAYBE_PTR(subtable)); + add_next_index_zval(&value, &subtable); } break; default: @@ -450,59 +455,59 @@ void parse_amqp_table(amqp_table_t *table, zval *result TSRMLS_DC) { } break; case AMQP_FIELD_KIND_TABLE: - PHP5to7_ARRAY_INIT(value); - parse_amqp_table(&(entry->value.value.table), PHP5to7_MAYBE_PTR(value) TSRMLS_CC); + array_init(&value); + parse_amqp_table(&(entry->value.value.table), &value TSRMLS_CC); break; case AMQP_FIELD_KIND_TIMESTAMP: { char timestamp_str[20]; - PHP5to7_zval_t timestamp PHP5to7_MAYBE_SET_TO_NULL; - PHP5to7_MAYBE_INIT(timestamp); + zval timestamp; + ZVAL_UNDEF(×tamp); int length = snprintf(timestamp_str, sizeof(timestamp_str), ZEND_ULONG_FMT, entry->value.value.u64); - PHP5to7_ZVAL_STRINGL_DUP(PHP5to7_MAYBE_PTR(timestamp), (char *)timestamp_str, length); - object_init_ex(PHP5to7_MAYBE_PTR(value), amqp_timestamp_class_entry); + ZVAL_STRINGL(×tamp, (char *)timestamp_str, length); + object_init_ex(&value, amqp_timestamp_class_entry); zend_call_method_with_1_params( - PHP5to8_OBJ_PROP(&value), + PHP_AMQP_COMPAT_OBJ_P(&value), amqp_timestamp_class_entry, NULL, "__construct", NULL, - PHP5to7_MAYBE_PTR(timestamp) + ×tamp ); - PHP5to7_MAYBE_DESTROY(timestamp); + zval_ptr_dtor(×tamp); break; } case AMQP_FIELD_KIND_VOID: - ZVAL_NULL(PHP5to7_MAYBE_PTR(value)); + ZVAL_NULL(&value); break; case AMQP_FIELD_KIND_DECIMAL: { - PHP5to7_zval_t e PHP5to7_MAYBE_SET_TO_NULL; - PHP5to7_zval_t n PHP5to7_MAYBE_SET_TO_NULL; - PHP5to7_MAYBE_INIT(e); - PHP5to7_MAYBE_INIT(n); + zval e; + zval n; + ZVAL_UNDEF(&e); + ZVAL_UNDEF(&n); - ZVAL_LONG(PHP5to7_MAYBE_PTR(e), entry->value.value.decimal.decimals); - ZVAL_LONG(PHP5to7_MAYBE_PTR(n), entry->value.value.decimal.value); + ZVAL_LONG(&e, entry->value.value.decimal.decimals); + ZVAL_LONG(&n, entry->value.value.decimal.value); - object_init_ex(PHP5to7_MAYBE_PTR(value), amqp_decimal_class_entry); + object_init_ex(&value, amqp_decimal_class_entry); zend_call_method_with_2_params( - PHP5to8_OBJ_PROP(&value), + PHP_AMQP_COMPAT_OBJ_P(&value), amqp_decimal_class_entry, NULL, "__construct", NULL, - PHP5to7_MAYBE_PTR(e), - PHP5to7_MAYBE_PTR(n) + &e, + &n ); - PHP5to7_MAYBE_DESTROY(e); - PHP5to7_MAYBE_DESTROY(n); + zval_ptr_dtor(&e); + zval_ptr_dtor(&n); break; } default: @@ -512,10 +517,12 @@ void parse_amqp_table(amqp_table_t *table, zval *result TSRMLS_DC) { if (has_value) { char *key = estrndup(entry->key.bytes, (unsigned) entry->key.len); - add_assoc_zval(result, key, PHP5to7_MAYBE_PTR(value)); + add_assoc_zval(result, key, &value); efree(key); } else { - PHP5to7_MAYBE_DESTROY(value); + if (!Z_ISUNDEF(value)) { + zval_ptr_dtor(&value); + } } } return; @@ -523,102 +530,102 @@ void parse_amqp_table(amqp_table_t *table, zval *result TSRMLS_DC) { void php_amqp_basic_properties_extract(amqp_basic_properties_t *p, zval *obj TSRMLS_DC) { - PHP5to7_zval_t headers PHP5to7_MAYBE_SET_TO_NULL; + zval headers; - PHP5to7_MAYBE_INIT(headers); - PHP5to7_ARRAY_INIT(headers); + ZVAL_UNDEF(&headers); + array_init(&headers); if (p->_flags & AMQP_BASIC_CONTENT_TYPE_FLAG) { - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("content_type"), (const char *) p->content_type.bytes, (PHP5to7_param_str_len_type_t) p->content_type.len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("content_type"), (const char *) p->content_type.bytes, (size_t) p->content_type.len TSRMLS_CC); } else { /* BC */ - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("content_type"), "", 0 TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("content_type"), "", 0 TSRMLS_CC); } if (p->_flags & AMQP_BASIC_CONTENT_ENCODING_FLAG) { - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("content_encoding"), (const char *) p->content_encoding.bytes, (PHP5to7_param_str_len_type_t) p->content_encoding.len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("content_encoding"), (const char *) p->content_encoding.bytes, (size_t) p->content_encoding.len TSRMLS_CC); } else { /* BC */ - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("content_encoding"), "", 0 TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("content_encoding"), "", 0 TSRMLS_CC); } if (p->_flags & AMQP_BASIC_HEADERS_FLAG) { - parse_amqp_table(&(p->headers), PHP5to7_MAYBE_PTR(headers) TSRMLS_CC); + parse_amqp_table(&(p->headers), &headers TSRMLS_CC); } - zend_update_property(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("headers"), PHP5to7_MAYBE_PTR(headers) TSRMLS_CC); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("headers"), &headers TSRMLS_CC); if (p->_flags & AMQP_BASIC_DELIVERY_MODE_FLAG) { - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("delivery_mode"), (PHP5to7_param_long_type_t) p->delivery_mode TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("delivery_mode"), (zend_long) p->delivery_mode TSRMLS_CC); } else { /* BC */ - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("delivery_mode"), AMQP_DELIVERY_NONPERSISTENT TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("delivery_mode"), AMQP_DELIVERY_NONPERSISTENT TSRMLS_CC); } if (p->_flags & AMQP_BASIC_PRIORITY_FLAG) { - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("priority"), (PHP5to7_param_long_type_t) p->priority TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("priority"), (zend_long) p->priority TSRMLS_CC); } else { /* BC */ - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("priority"), 0 TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("priority"), 0 TSRMLS_CC); } if (p->_flags & AMQP_BASIC_CORRELATION_ID_FLAG) { - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("correlation_id"), (const char *) p->correlation_id.bytes, (PHP5to7_param_str_len_type_t) p->correlation_id.len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("correlation_id"), (const char *) p->correlation_id.bytes, (size_t) p->correlation_id.len TSRMLS_CC); } else { /* BC */ - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("correlation_id"), "", 0 TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("correlation_id"), "", 0 TSRMLS_CC); } if (p->_flags & AMQP_BASIC_REPLY_TO_FLAG) { - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("reply_to"), (const char *) p->reply_to.bytes, (PHP5to7_param_str_len_type_t) p->reply_to.len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("reply_to"), (const char *) p->reply_to.bytes, (size_t) p->reply_to.len TSRMLS_CC); } else { /* BC */ - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("reply_to"), "", 0 TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("reply_to"), "", 0 TSRMLS_CC); } if (p->_flags & AMQP_BASIC_EXPIRATION_FLAG) { - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("expiration"), (const char *) p->expiration.bytes, (PHP5to7_param_str_len_type_t) p->expiration.len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("expiration"), (const char *) p->expiration.bytes, (size_t) p->expiration.len TSRMLS_CC); } else { /* BC */ - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("expiration"), "", 0 TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("expiration"), "", 0 TSRMLS_CC); } if (p->_flags & AMQP_BASIC_MESSAGE_ID_FLAG) { - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("message_id"), (const char *) p->message_id.bytes, (PHP5to7_param_str_len_type_t) p->message_id.len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("message_id"), (const char *) p->message_id.bytes, (size_t) p->message_id.len TSRMLS_CC); } else { /* BC */ - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("message_id"), "", 0 TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("message_id"), "", 0 TSRMLS_CC); } if (p->_flags & AMQP_BASIC_TIMESTAMP_FLAG) { - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("timestamp"), (PHP5to7_param_long_type_t) p->timestamp TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("timestamp"), (zend_long) p->timestamp TSRMLS_CC); } else { /* BC */ - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("timestamp"), 0 TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("timestamp"), 0 TSRMLS_CC); } if (p->_flags & AMQP_BASIC_TYPE_FLAG) { - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("type"), (const char *) p->type.bytes, (PHP5to7_param_str_len_type_t) p->type.len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("type"), (const char *) p->type.bytes, (size_t) p->type.len TSRMLS_CC); } else { /* BC */ - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("type"), "", 0 TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("type"), "", 0 TSRMLS_CC); } if (p->_flags & AMQP_BASIC_USER_ID_FLAG) { - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("user_id"), (const char *) p->user_id.bytes, (PHP5to7_param_str_len_type_t) p->user_id.len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("user_id"), (const char *) p->user_id.bytes, (size_t) p->user_id.len TSRMLS_CC); } else { /* BC */ - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("user_id"), "", 0 TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("user_id"), "", 0 TSRMLS_CC); } if (p->_flags & AMQP_BASIC_APP_ID_FLAG) { - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("app_id"), (const char *) p->app_id.bytes, (PHP5to7_param_str_len_type_t) p->app_id.len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("app_id"), (const char *) p->app_id.bytes, (size_t) p->app_id.len TSRMLS_CC); } else { /* BC */ - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(obj), ZEND_STRL("app_id"), "", 0 TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("app_id"), "", 0 TSRMLS_CC); } - PHP5to7_MAYBE_DESTROY(headers); + zval_ptr_dtor(&headers); } diff --git a/amqp_channel.c b/amqp_channel.c index cac84ab1..2c0d1956 100644 --- a/amqp_channel.c +++ b/amqp_channel.c @@ -41,8 +41,13 @@ # include #endif +#if HAVE_LIBRABBITMQ_NEW_LAYOUT +#include +#include +#else #include #include +#endif #ifdef PHP_WIN32 # include "win32/unistd.h" @@ -99,17 +104,11 @@ void php_amqp_close_channel(amqp_channel_resource *channel_resource, zend_bool c } } -#if PHP_MAJOR_VERSION >= 7 - static void php_amqp_destroy_fci(zend_fcall_info *fci) { if (fci->size > 0) { zval_ptr_dtor(&fci->function_name); if (fci->object != NULL) { -#if PHP_VERSION_ID >= 70300 GC_DELREF(fci->object); -#else - GC_REFCOUNT(fci->object)--; -#endif } fci->size = 0; } @@ -120,11 +119,7 @@ static void php_amqp_duplicate_fci(zend_fcall_info *source) { zval_add_ref(&source->function_name); if (source->object != NULL) { -#if PHP_VERSION_ID >= 70300 GC_ADDREF(source->object); -#else - GC_REFCOUNT(source->object)++; -#endif } } } @@ -188,81 +183,6 @@ static HashTable *amqp_channel_gc(zend_object *object, zval **table, int *n) /* return zend_std_get_properties(object TSRMLS_CC); } /* }}} */ -#else -static void php_amqp_destroy_fci(zend_fcall_info *fci) { - if (fci->size > 0) { - zval_ptr_dtor(&fci->function_name); - if (fci->object_ptr != NULL) { - zval_ptr_dtor(&fci->object_ptr); - } - fci->size = 0; - } -} - -static void php_amqp_duplicate_fci(zend_fcall_info *source) { - if (source->size > 0) { - - zval_add_ref(&source->function_name); - if (source->object_ptr != NULL) { - zval_add_ref(&source->object_ptr); - } - } -} - -static int php_amqp_get_fci_gc_data_count(zend_fcall_info *fci) { - int cnt = 0; - - if (fci->size > 0) { - cnt ++; - - if (fci->object_ptr != NULL) { - cnt++; - } - } - - return cnt; -} - -static int php_amqp_get_fci_gc_data(zend_fcall_info *fci, zval **gc_data, int offset) { - - if (ZEND_FCI_INITIALIZED(*fci)) { - gc_data[offset++] = fci->function_name; - - if (fci->object_ptr != NULL) { - gc_data[offset++] = fci->object_ptr; - } - } - - return offset; -} - -static HashTable *amqp_channel_gc(zval *object, zval ***table, int *n TSRMLS_DC) /* {{{ */ -{ - amqp_channel_object *channel = PHP_AMQP_GET_CHANNEL(object); - - int basic_return_cnt = php_amqp_get_fci_gc_data_count(&channel->callbacks.basic_return.fci); - int basic_ack_cnt = php_amqp_get_fci_gc_data_count(&channel->callbacks.basic_ack.fci); - int basic_nack_cnt = php_amqp_get_fci_gc_data_count(&channel->callbacks.basic_nack.fci); - - int cnt = basic_return_cnt + basic_ack_cnt + basic_nack_cnt; - - if (cnt > channel->gc_data_count) { - channel->gc_data_count = cnt; - channel->gc_data = (zval **) erealloc(channel->gc_data, sizeof(zval *) * channel->gc_data_count); - } - - php_amqp_get_fci_gc_data(&channel->callbacks.basic_return.fci, channel->gc_data, 0); - php_amqp_get_fci_gc_data(&channel->callbacks.basic_ack.fci, channel->gc_data, basic_return_cnt); - php_amqp_get_fci_gc_data(&channel->callbacks.basic_nack.fci, channel->gc_data, basic_return_cnt + basic_ack_cnt); - - *table = channel->gc_data; - *n = cnt; - - return zend_std_get_properties(PHP5to8_OBJ_PROP(object) TSRMLS_CC); -} /* }}} */ - -#endif - static void php_amqp_clean_callbacks(amqp_channel_callbacks *callbacks) { php_amqp_destroy_fci(&callbacks->basic_return.fci); php_amqp_destroy_fci(&callbacks->basic_ack.fci); @@ -270,7 +190,7 @@ static void php_amqp_clean_callbacks(amqp_channel_callbacks *callbacks) { } -void amqp_channel_free(PHP5to7_obj_free_zend_object *object TSRMLS_DC) +void amqp_channel_free(zend_object *object TSRMLS_DC) { amqp_channel_object *channel = PHP_AMQP_FETCH_CHANNEL(object); @@ -288,20 +208,12 @@ void amqp_channel_free(PHP5to7_obj_free_zend_object *object TSRMLS_DC) php_amqp_clean_callbacks(&channel->callbacks); zend_object_std_dtor(&channel->zo TSRMLS_CC); - -#if PHP_MAJOR_VERSION < 7 - if (channel->this_ptr) { - channel->this_ptr = NULL; - } - - efree(object); -#endif } -PHP5to7_zend_object_value amqp_channel_ctor(zend_class_entry *ce TSRMLS_DC) +zend_object *amqp_channel_ctor(zend_class_entry *ce TSRMLS_DC) { - amqp_channel_object *channel = PHP5to7_ECALLOC_CHANNEL_OBJECT(ce); + amqp_channel_object *channel = (amqp_channel_object*) ecalloc(1, sizeof(amqp_channel_object) + zend_object_properties_size(ce)); zend_object_std_init(&channel->zo, ce TSRMLS_CC); AMQP_OBJECT_PROPERTIES_INIT(channel->zo, ce); @@ -311,7 +223,7 @@ PHP5to7_zend_object_value amqp_channel_ctor(zend_class_entry *ce TSRMLS_DC) return &channel->zo; #else - PHP5to7_zend_object_value new_value; + zend_object *new_value; new_value.handle = zend_objects_store_put( channel, @@ -331,7 +243,7 @@ PHP5to7_zend_object_value amqp_channel_ctor(zend_class_entry *ce TSRMLS_DC) */ static PHP_METHOD(amqp_channel_class, __construct) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; zval *connection_object = NULL; @@ -345,31 +257,28 @@ static PHP_METHOD(amqp_channel_class, __construct) RETURN_NULL(); } - PHP5to7_zval_t consumers PHP5to7_MAYBE_SET_TO_NULL; + zval consumers; - PHP5to7_MAYBE_INIT(consumers); - PHP5to7_ARRAY_INIT(consumers); + ZVAL_UNDEF(&consumers); + array_init(&consumers); - zend_update_property(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("consumers"), PHP5to7_MAYBE_PTR(consumers) TSRMLS_CC); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("consumers"), &consumers TSRMLS_CC); - PHP5to7_MAYBE_DESTROY(consumers); + zval_ptr_dtor(&consumers); channel = PHP_AMQP_GET_CHANNEL(getThis()); -#if PHP_MAJOR_VERSION < 7 - channel->this_ptr = getThis(); -#endif /* Set the prefetch count */ - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("prefetch_count"), INI_INT("amqp.prefetch_count") TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("prefetch_count"), INI_INT("amqp.prefetch_count") TSRMLS_CC); /* Set the prefetch size */ - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("prefetch_size"), INI_INT("amqp.prefetch_size") TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("prefetch_size"), INI_INT("amqp.prefetch_size") TSRMLS_CC); /* Set the global prefetch count */ - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("global_prefetch_count"), INI_INT("amqp.global_prefetch_count") TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("global_prefetch_count"), INI_INT("amqp.global_prefetch_count") TSRMLS_CC); /* Set the global prefetch size */ - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("global_prefetch_size"), INI_INT("amqp.global_prefetch_size") TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("global_prefetch_size"), INI_INT("amqp.global_prefetch_size") TSRMLS_CC); /* Pull out and verify the connection */ connection = PHP_AMQP_GET_CONNECTION(connection_object); @@ -385,7 +294,7 @@ static PHP_METHOD(amqp_channel_class, __construct) return; } - zend_update_property(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("connection"), connection_object TSRMLS_CC); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connection"), connection_object TSRMLS_CC); channel_resource = (amqp_channel_resource*)ecalloc(1, sizeof(amqp_channel_resource)); channel->channel_resource = channel_resource; @@ -530,10 +439,10 @@ static PHP_METHOD(amqp_channel_class, getChannelId) set the number of prefetches */ static PHP_METHOD(amqp_channel_class, setPrefetchCount) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; amqp_channel_resource *channel_resource; - PHP5to7_param_long_type_t prefetch_count; + zend_long prefetch_count; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &prefetch_count) == FAILURE) { return; @@ -589,8 +498,8 @@ static PHP_METHOD(amqp_channel_class, setPrefetchCount) } /* Set the prefetch count - the implication is to disable the size */ - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("prefetch_count"), prefetch_count TSRMLS_CC); - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("prefetch_size"), 0 TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("prefetch_count"), prefetch_count TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("prefetch_size"), 0 TSRMLS_CC); RETURN_TRUE; } @@ -600,7 +509,7 @@ static PHP_METHOD(amqp_channel_class, setPrefetchCount) get the number of prefetches */ static PHP_METHOD(amqp_channel_class, getPrefetchCount) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("prefetch_count") } @@ -610,10 +519,10 @@ static PHP_METHOD(amqp_channel_class, getPrefetchCount) set the number of prefetches */ static PHP_METHOD(amqp_channel_class, setPrefetchSize) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; amqp_channel_resource *channel_resource; - PHP5to7_param_long_type_t prefetch_size; + zend_long prefetch_size; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &prefetch_size) == FAILURE) { return; @@ -668,8 +577,8 @@ static PHP_METHOD(amqp_channel_class, setPrefetchSize) } /* Set the prefetch size - the implication is to disable the count */ - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("prefetch_count"), 0 TSRMLS_CC); - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("prefetch_size"), prefetch_size TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("prefetch_count"), 0 TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("prefetch_size"), prefetch_size TSRMLS_CC); RETURN_TRUE; } @@ -679,7 +588,7 @@ static PHP_METHOD(amqp_channel_class, setPrefetchSize) get the number of prefetches */ static PHP_METHOD(amqp_channel_class, getPrefetchSize) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("prefetch_size") } @@ -689,10 +598,8 @@ static PHP_METHOD(amqp_channel_class, getPrefetchSize) set the number of prefetches */ static PHP_METHOD(amqp_channel_class, setGlobalPrefetchCount) { - PHP5to7_READ_PROP_RV_PARAM_DECL; - amqp_channel_resource *channel_resource; - PHP5to7_param_long_type_t global_prefetch_count; + zend_long global_prefetch_count; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &global_prefetch_count) == FAILURE) { return; @@ -724,8 +631,8 @@ static PHP_METHOD(amqp_channel_class, setGlobalPrefetchCount) } /* Set the global prefetch count - the implication is to disable the size */ - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("global_prefetch_count"), global_prefetch_count TSRMLS_CC); - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("global_prefetch_size"), 0 TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("global_prefetch_count"), global_prefetch_count TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("global_prefetch_size"), 0 TSRMLS_CC); RETURN_TRUE; } @@ -735,7 +642,7 @@ static PHP_METHOD(amqp_channel_class, setGlobalPrefetchCount) get the number of prefetches */ static PHP_METHOD(amqp_channel_class, getGlobalPrefetchCount) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("global_prefetch_count") } @@ -745,10 +652,8 @@ static PHP_METHOD(amqp_channel_class, getGlobalPrefetchCount) set the number of prefetches */ static PHP_METHOD(amqp_channel_class, setGlobalPrefetchSize) { - PHP5to7_READ_PROP_RV_PARAM_DECL; - amqp_channel_resource *channel_resource; - PHP5to7_param_long_type_t global_prefetch_size; + zend_long global_prefetch_size; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &global_prefetch_size) == FAILURE) { return; @@ -780,8 +685,8 @@ static PHP_METHOD(amqp_channel_class, setGlobalPrefetchSize) } /* Set the global prefetch size - the implication is to disable the count */ - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("global_prefetch_count"), 0 TSRMLS_CC); - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("global_prefetch_size"), global_prefetch_size TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("global_prefetch_count"), 0 TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("global_prefetch_size"), global_prefetch_size TSRMLS_CC); RETURN_TRUE; } @@ -791,7 +696,7 @@ static PHP_METHOD(amqp_channel_class, setGlobalPrefetchSize) get the number of prefetches */ static PHP_METHOD(amqp_channel_class, getGlobalPrefetchSize) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("global_prefetch_size") } @@ -801,11 +706,11 @@ static PHP_METHOD(amqp_channel_class, getGlobalPrefetchSize) set the number of prefetches */ static PHP_METHOD(amqp_channel_class, qos) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; amqp_channel_resource *channel_resource; - PHP5to7_param_long_type_t prefetch_size; - PHP5to7_param_long_type_t prefetch_count; + zend_long prefetch_size; + zend_long prefetch_count; zend_bool global = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll|b", &prefetch_size, &prefetch_count, &global) == FAILURE) { @@ -817,11 +722,11 @@ static PHP_METHOD(amqp_channel_class, qos) /* Set the prefetch size and prefetch count */ if (global) { - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("global_prefetch_size"), prefetch_size TSRMLS_CC); - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("global_prefetch_count"), prefetch_count TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("global_prefetch_size"), prefetch_size TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("global_prefetch_count"), prefetch_count TSRMLS_CC); } else { - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("prefetch_size"), prefetch_size TSRMLS_CC); - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("prefetch_count"), prefetch_count TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("prefetch_size"), prefetch_size TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("prefetch_count"), prefetch_count TSRMLS_CC); } /* If we are already connected, set the new prefetch count */ @@ -983,7 +888,7 @@ static PHP_METHOD(amqp_channel_class, rollbackTransaction) Get the AMQPConnection object in use */ static PHP_METHOD(amqp_channel_class, getConnection) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("connection") } @@ -1319,7 +1224,7 @@ PHP_METHOD(amqp_channel_class, waitForConfirm) /* {{{ proto amqp::getConsumers() */ static PHP_METHOD(amqp_channel_class, getConsumers) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("consumers"); } diff --git a/amqp_connection.c b/amqp_connection.c index 897513c1..7c9f04ff 100644 --- a/amqp_connection.c +++ b/amqp_connection.c @@ -41,9 +41,15 @@ # include # include #endif +#if HAVE_LIBRABBITMQ_NEW_LAYOUT +#include +#include +#include +#else #include #include #include +#endif #ifdef PHP_WIN32 # include "win32/unistd.h" @@ -67,29 +73,29 @@ zend_object_handlers amqp_connection_object_handlers; #define PHP_AMQP_EXTRACT_CONNECTION_STR(name) \ zdata = NULL; \ - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), (name), sizeof(name), zdata)) { \ + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), (name), sizeof(name))) != NULL) { \ SEPARATE_ZVAL(zdata); \ - convert_to_string(PHP5to7_MAYBE_DEREF(zdata)); \ + convert_to_string(zdata); \ } \ - if (zdata && Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) > 0) { \ - zend_update_property_string(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL(name), Z_STRVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC); \ + if (zdata && Z_STRLEN_P(zdata) > 0) { \ + zend_update_property_string(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(name), Z_STRVAL_P(zdata) TSRMLS_CC); \ } else { \ - zend_update_property_string(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL(name), INI_STR("amqp." name) TSRMLS_CC); \ + zend_update_property_string(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(name), INI_STR("amqp." name) TSRMLS_CC); \ } #define PHP_AMQP_EXTRACT_CONNECTION_BOOL(name) \ zdata = NULL; \ - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), (name), sizeof(name), zdata)) { \ + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), (name), sizeof(name))) != NULL) { \ SEPARATE_ZVAL(zdata); \ - convert_to_long(PHP5to7_MAYBE_DEREF(zdata)); \ + convert_to_long(zdata); \ } \ if (zdata) { \ - zend_update_property_bool(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL(name), Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC); \ + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(name), Z_LVAL_P(zdata) TSRMLS_CC); \ } else { \ - zend_update_property_bool(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL(name), INI_INT("amqp." name) TSRMLS_CC); \ + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(name), INI_INT("amqp." name) TSRMLS_CC); \ } -static int php_amqp_connection_resource_deleter(PHP5to7_zend_resource_le_t *el, amqp_connection_resource *connection_resource TSRMLS_DC) +static int php_amqp_connection_resource_deleter(zval *el, amqp_connection_resource *connection_resource TSRMLS_DC) { if (Z_RES_P(el)->ptr == connection_resource) { return ZEND_HASH_APPLY_REMOVE | ZEND_HASH_APPLY_STOP; @@ -98,7 +104,7 @@ static int php_amqp_connection_resource_deleter(PHP5to7_zend_resource_le_t *el, return ZEND_HASH_APPLY_KEEP; } -static PHP5to7_param_str_len_type_t php_amqp_get_connection_hash(amqp_connection_params *params, char **hash) { +static size_t php_amqp_get_connection_hash(amqp_connection_params *params, char **hash) { return spprintf(hash, 0, "amqp_conn_res_h:%s_p:%d_v:%s_l:%s_p:%s_f:%d_c:%d_h:%d_cacert:%s_cert:%s_key:%s_sasl_method:%d_connection_name:%s", @@ -124,7 +130,7 @@ static void php_amqp_cleanup_connection_resource(amqp_connection_resource *conne return; } - PHP5to7_zend_resource_t resource = connection_resource->resource; + zend_resource *resource = connection_resource->resource; connection_resource->parent->connection_resource = NULL; connection_resource->parent = NULL; @@ -137,10 +143,10 @@ static void php_amqp_cleanup_connection_resource(amqp_connection_resource *conne zend_list_delete(resource); } else { if (connection_resource->is_persistent) { - connection_resource->resource = PHP5to7_ZEND_RESOURCE_EMPTY; + connection_resource->resource = NULL; } - if (connection_resource->resource != PHP5to7_ZEND_RESOURCE_EMPTY) { + if (connection_resource->resource != NULL) { zend_list_delete(resource); } } @@ -167,10 +173,10 @@ void php_amqp_disconnect_force(amqp_connection_resource *resource TSRMLS_DC) */ int php_amqp_connect(amqp_connection_object *connection, zend_bool persistent, INTERNAL_FUNCTION_PARAMETERS) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; char *key = NULL; - PHP5to7_param_str_len_type_t key_len = 0; + size_t key_len = 0; if (connection->connection_resource) { /* Clean up old memory allocations which are now invalid (new connection) */ @@ -201,12 +207,12 @@ int php_amqp_connect(amqp_connection_object *connection, zend_bool persistent, I connection_params.connection_name = PHP_AMQP_READ_THIS_PROP_STRLEN("connection_name") ? PHP_AMQP_READ_THIS_PROP_STR("connection_name") : NULL; if (persistent) { - PHP5to7_zend_resource_store_t *le = PHP5to7_ZEND_RESOURCE_EMPTY; + zend_resource *le = NULL; /* Look for an established resource */ key_len = php_amqp_get_connection_hash(&connection_params, &key); - if (PHP5to7_ZEND_HASH_STR_FIND_PTR(&EG(persistent_list), key, key_len, le)) { + if ((le = zend_hash_str_find_ptr(&EG(persistent_list), key, key_len)) != NULL) { efree(key); if (le->type != le_amqp_connection_resource_persistent) { @@ -218,7 +224,7 @@ int php_amqp_connect(amqp_connection_object *connection, zend_bool persistent, I /* Stash the connection resource in the connection */ connection->connection_resource = le->ptr; - if (connection->connection_resource->resource != PHP5to7_ZEND_RESOURCE_EMPTY) { + if (connection->connection_resource->resource != NULL) { /* resource in use! */ connection->connection_resource = NULL; @@ -226,7 +232,7 @@ int php_amqp_connect(amqp_connection_object *connection, zend_bool persistent, I return 0; } - connection->connection_resource->resource = PHP5to7_ZEND_REGISTER_RESOURCE(connection->connection_resource, persistent ? le_amqp_connection_resource_persistent : le_amqp_connection_resource); + connection->connection_resource->resource = zend_register_resource(connection->connection_resource, persistent ? le_amqp_connection_resource_persistent : le_amqp_connection_resource); connection->connection_resource->parent = connection; /* Set desired timeouts */ @@ -254,7 +260,7 @@ int php_amqp_connect(amqp_connection_object *connection, zend_bool persistent, I return 0; } - connection->connection_resource->resource = PHP5to7_ZEND_REGISTER_RESOURCE(connection->connection_resource, persistent ? le_amqp_connection_resource_persistent : le_amqp_connection_resource); + connection->connection_resource->resource = zend_register_resource(connection->connection_resource, persistent ? le_amqp_connection_resource_persistent : le_amqp_connection_resource); connection->connection_resource->parent = connection; /* Set connection status to connected */ @@ -265,13 +271,13 @@ int php_amqp_connect(amqp_connection_object *connection, zend_bool persistent, I key_len = php_amqp_get_connection_hash(&connection_params, &key); - PHP5to7_zend_resource_store_t new_le; + zend_resource new_le; /* Store a reference in the persistence list */ new_le.ptr = connection->connection_resource; new_le.type = persistent ? le_amqp_connection_resource_persistent : le_amqp_connection_resource; - if (!PHP5to7_ZEND_HASH_STR_UPD_MEM(&EG(persistent_list), key, key_len, new_le, sizeof(PHP5to7_zend_resource_store_t))) { + if (!zend_hash_str_update_mem(&EG(persistent_list), key, key_len, &new_le, sizeof(zend_resource))) { efree(key); php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC); return 0; @@ -282,7 +288,7 @@ int php_amqp_connect(amqp_connection_object *connection, zend_bool persistent, I return 1; } -void amqp_connection_free(PHP5to7_obj_free_zend_object *object TSRMLS_DC) +void amqp_connection_free(zend_object *object TSRMLS_DC) { amqp_connection_object *connection = PHP_AMQP_FETCH_CONNECTION(object); @@ -291,37 +297,18 @@ void amqp_connection_free(PHP5to7_obj_free_zend_object *object TSRMLS_DC) } zend_object_std_dtor(&connection->zo TSRMLS_CC); - -#if PHP_MAJOR_VERSION < 7 - efree(object); -#endif } -PHP5to7_zend_object_value amqp_connection_ctor(zend_class_entry *ce TSRMLS_DC) +zend_object *amqp_connection_ctor(zend_class_entry *ce TSRMLS_DC) { - amqp_connection_object* connection = PHP5to7_ECALLOC_CONNECTION_OBJECT(ce); + amqp_connection_object* connection = (amqp_connection_object*) ecalloc(1, sizeof(amqp_connection_object) + zend_object_properties_size(ce)); zend_object_std_init(&connection->zo, ce TSRMLS_CC); AMQP_OBJECT_PROPERTIES_INIT(connection->zo, ce); -#if PHP_MAJOR_VERSION >=7 connection->zo.handlers = &amqp_connection_object_handlers; return &connection->zo; -#else - PHP5to7_zend_object_value new_value; - - new_value.handle = zend_objects_store_put( - connection, - NULL, - (zend_objects_free_object_storage_t) amqp_connection_free, - NULL TSRMLS_CC - ); - - new_value.handlers = zend_get_std_object_handlers(); - - return new_value; -#endif } @@ -332,7 +319,7 @@ static PHP_METHOD(amqp_connection_class, __construct) { zval* ini_arr = NULL; - PHP5to7_zval_t *zdata = NULL; + zval *zdata = NULL; /* Parse out the method parameters */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a/", &ini_arr) == FAILURE) { @@ -341,111 +328,111 @@ static PHP_METHOD(amqp_connection_class, __construct) /* Pull the login out of the $params array */ zdata = NULL; - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "login", sizeof("login"), zdata)) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "login", sizeof("login") - 1)) != NULL) { SEPARATE_ZVAL(zdata); - convert_to_string(PHP5to7_MAYBE_DEREF(zdata)); + convert_to_string(zdata); } /* Validate the given login */ - if (zdata && Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) > 0) { - if (Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) < 128) { - zend_update_property(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("login"), PHP5to7_MAYBE_DEREF(zdata)TSRMLS_CC); + if (zdata && Z_STRLEN_P(zdata) > 0) { + if (Z_STRLEN_P(zdata) < 128) { + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("login"), zdata TSRMLS_CC); } else { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'login' exceeds 128 character limit.", 0 TSRMLS_CC); return; } } else { - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("login"), INI_STR("amqp.login"), (PHP5to7_param_str_len_type_t) (strlen(INI_STR("amqp.login")) > 128 ? 128 : strlen(INI_STR("amqp.login"))) TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("login"), INI_STR("amqp.login"), (size_t) (strlen(INI_STR("amqp.login")) > 128 ? 128 : strlen(INI_STR("amqp.login"))) TSRMLS_CC); } /* Pull the password out of the $params array */ zdata = NULL; - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "password", sizeof("password"), zdata)) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "password", sizeof("password") - 1)) != NULL) { SEPARATE_ZVAL(zdata); - convert_to_string(PHP5to7_MAYBE_DEREF(zdata)); + convert_to_string(zdata); } /* Validate the given password */ - if (zdata && Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) > 0) { - if (Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) < 128) { - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("password"), Z_STRVAL_P(PHP5to7_MAYBE_DEREF(zdata)), Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC); + if (zdata && Z_STRLEN_P(zdata) > 0) { + if (Z_STRLEN_P(zdata) < 128) { + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("password"), Z_STRVAL_P(zdata), Z_STRLEN_P(zdata) TSRMLS_CC); } else { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'password' exceeds 128 character limit.", 0 TSRMLS_CC); return; } } else { - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("password"), INI_STR("amqp.password"), (PHP5to7_param_str_len_type_t) (strlen(INI_STR("amqp.password")) > 128 ? 128 : strlen(INI_STR("amqp.password"))) TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("password"), INI_STR("amqp.password"), (size_t) (strlen(INI_STR("amqp.password")) > 128 ? 128 : strlen(INI_STR("amqp.password"))) TSRMLS_CC); } /* Pull the host out of the $params array */ zdata = NULL; - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "host", sizeof("host"), zdata)) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "host", sizeof("host") - 1)) != NULL) { SEPARATE_ZVAL(zdata); - convert_to_string(PHP5to7_MAYBE_DEREF(zdata)); + convert_to_string(zdata); } /* Validate the given host */ - if (zdata && Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) > 0) { - if (Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) < 128) { - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("host"), Z_STRVAL_P(PHP5to7_MAYBE_DEREF(zdata)), Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC); + if (zdata && Z_STRLEN_P(zdata) > 0) { + if (Z_STRLEN_P(zdata) < 128) { + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("host"), Z_STRVAL_P(zdata), Z_STRLEN_P(zdata) TSRMLS_CC); } else { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'host' exceeds 128 character limit.", 0 TSRMLS_CC); return; } } else { - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("host"), INI_STR("amqp.host"), (PHP5to7_param_str_len_type_t) (strlen(INI_STR("amqp.host")) > 128 ? 128 : strlen(INI_STR("amqp.host"))) TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("host"), INI_STR("amqp.host"), (size_t) (strlen(INI_STR("amqp.host")) > 128 ? 128 : strlen(INI_STR("amqp.host"))) TSRMLS_CC); } /* Pull the vhost out of the $params array */ zdata = NULL; - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "vhost", sizeof("vhost"), zdata)) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "vhost", sizeof("vhost") - 1)) != NULL) { SEPARATE_ZVAL(zdata); - convert_to_string(PHP5to7_MAYBE_DEREF(zdata)); + convert_to_string(zdata); } /* Validate the given vhost */ - if (zdata && Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) > 0) { - if (Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) < 128) { - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("vhost"), Z_STRVAL_P(PHP5to7_MAYBE_DEREF(zdata)), Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC); + if (zdata && Z_STRLEN_P(zdata) > 0) { + if (Z_STRLEN_P(zdata) < 128) { + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("vhost"), Z_STRVAL_P(zdata), Z_STRLEN_P(zdata) TSRMLS_CC); } else { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'vhost' exceeds 128 character limit.", 0 TSRMLS_CC); return; } } else { - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("vhost"), INI_STR("amqp.vhost"), (PHP5to7_param_str_len_type_t) (strlen(INI_STR("amqp.vhost")) > 128 ? 128 : strlen(INI_STR("amqp.vhost"))) TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("vhost"), INI_STR("amqp.vhost"), (size_t) (strlen(INI_STR("amqp.vhost")) > 128 ? 128 : strlen(INI_STR("amqp.vhost"))) TSRMLS_CC); } - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("port"), INI_INT("amqp.port") TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("port"), INI_INT("amqp.port") TSRMLS_CC); - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "port", sizeof("port"), zdata)) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "port", sizeof("port") - 1)) != NULL) { SEPARATE_ZVAL(zdata); - convert_to_long(PHP5to7_MAYBE_DEREF(zdata)); - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("port"), Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC); + convert_to_long(zdata); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("port"), Z_LVAL_P(zdata) TSRMLS_CC); } - zend_update_property_double(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("read_timeout"), INI_FLT("amqp.read_timeout") TSRMLS_CC); + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("read_timeout"), INI_FLT("amqp.read_timeout") TSRMLS_CC); - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "read_timeout", sizeof("read_timeout"), zdata)) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "read_timeout", sizeof("read_timeout") - 1)) != NULL) { SEPARATE_ZVAL(zdata); - convert_to_double(PHP5to7_MAYBE_DEREF(zdata)); - if (Z_DVAL_P(PHP5to7_MAYBE_DEREF(zdata)) < 0) { + convert_to_double(zdata); + if (Z_DVAL_P(zdata) < 0) { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'read_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC); } else { - zend_update_property_double(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("read_timeout"), Z_DVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC); + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("read_timeout"), Z_DVAL_P(zdata) TSRMLS_CC); } - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "timeout", sizeof("timeout"), zdata)) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "timeout", sizeof("timeout") - 1)) != NULL) { /* 'read_timeout' takes precedence on 'timeout' but users have to know this */ php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Parameter 'timeout' is deprecated, 'read_timeout' used instead"); } - } else if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "timeout", sizeof("timeout"), zdata)) { + } else if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "timeout", sizeof("timeout") - 1)) != NULL) { php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "Parameter 'timeout' is deprecated; use 'read_timeout' instead"); SEPARATE_ZVAL(zdata); - convert_to_double(PHP5to7_MAYBE_DEREF(zdata)); - if (Z_DVAL_P(PHP5to7_MAYBE_DEREF(zdata)) < 0) { + convert_to_double(zdata); + if (Z_DVAL_P(zdata) < 0) { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'timeout' must be greater than or equal to zero.", 0 TSRMLS_CC); } else { - zend_update_property_double(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("read_timeout"), Z_DVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC); + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("read_timeout"), Z_DVAL_P(zdata) TSRMLS_CC); } } else { @@ -454,103 +441,103 @@ static PHP_METHOD(amqp_connection_class, __construct) php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "INI setting 'amqp.timeout' is deprecated; use 'amqp.read_timeout' instead"); if (strcmp(DEFAULT_READ_TIMEOUT, INI_STR("amqp.read_timeout")) == 0) { - zend_update_property_double(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("read_timeout"), INI_FLT("amqp.timeout") TSRMLS_CC); + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("read_timeout"), INI_FLT("amqp.timeout") TSRMLS_CC); } else { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "INI setting 'amqp.read_timeout' will be used instead of 'amqp.timeout'"); - zend_update_property_double(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("read_timeout"), INI_FLT("amqp.read_timeout") TSRMLS_CC); + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("read_timeout"), INI_FLT("amqp.read_timeout") TSRMLS_CC); } } else { - zend_update_property_double(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("read_timeout"), INI_FLT("amqp.read_timeout") TSRMLS_CC); + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("read_timeout"), INI_FLT("amqp.read_timeout") TSRMLS_CC); } } - zend_update_property_double(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("write_timeout"), INI_FLT("amqp.write_timeout") TSRMLS_CC); + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("write_timeout"), INI_FLT("amqp.write_timeout") TSRMLS_CC); - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "write_timeout", sizeof("write_timeout"), zdata)) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "write_timeout", sizeof("write_timeout") - 1)) != NULL) { SEPARATE_ZVAL(zdata); - convert_to_double(PHP5to7_MAYBE_DEREF(zdata)); - if (Z_DVAL_P(PHP5to7_MAYBE_DEREF(zdata)) < 0) { + convert_to_double(zdata); + if (Z_DVAL_P(zdata) < 0) { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'write_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC); } else { - zend_update_property_double(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("write_timeout"), Z_DVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC); + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("write_timeout"), Z_DVAL_P(zdata) TSRMLS_CC); } } - zend_update_property_double(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("rpc_timeout"), INI_FLT("amqp.rpc_timeout") TSRMLS_CC); + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("rpc_timeout"), INI_FLT("amqp.rpc_timeout") TSRMLS_CC); - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "rpc_timeout", sizeof("rpc_timeout"), zdata)) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "rpc_timeout", sizeof("rpc_timeout") - 1)) != NULL) { SEPARATE_ZVAL(zdata); - convert_to_double(PHP5to7_MAYBE_DEREF(zdata)); - if (Z_DVAL_P(PHP5to7_MAYBE_DEREF(zdata)) < 0) { + convert_to_double(zdata); + if (Z_DVAL_P(zdata) < 0) { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'rpc_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC); } else { - zend_update_property_double(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("rpc_timeout"), Z_DVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC); + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("rpc_timeout"), Z_DVAL_P(zdata) TSRMLS_CC); } } - zend_update_property_double(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("connect_timeout"), INI_FLT("amqp.connect_timeout") TSRMLS_CC); + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connect_timeout"), INI_FLT("amqp.connect_timeout") TSRMLS_CC); - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "connect_timeout", sizeof("connect_timeout"), zdata)) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "connect_timeout", sizeof("connect_timeout") - 1)) != NULL) { SEPARATE_ZVAL(zdata); - convert_to_double(PHP5to7_MAYBE_DEREF(zdata)); - if (Z_DVAL_P(PHP5to7_MAYBE_DEREF(zdata)) < 0) { + convert_to_double(zdata); + if (Z_DVAL_P(zdata) < 0) { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'connect_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC); } else { - zend_update_property_double(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("connect_timeout"), Z_DVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC); + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connect_timeout"), Z_DVAL_P(zdata) TSRMLS_CC); } } - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("channel_max"), INI_INT("amqp.channel_max") TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("channel_max"), INI_INT("amqp.channel_max") TSRMLS_CC); - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "channel_max", sizeof("channel_max"), zdata)) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "channel_max", sizeof("channel_max") - 1)) != NULL) { SEPARATE_ZVAL(zdata); - convert_to_long(PHP5to7_MAYBE_DEREF(zdata)); - if (Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) < 0 || Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) > PHP_AMQP_MAX_CHANNELS) { + convert_to_long(zdata); + if (Z_LVAL_P(zdata) < 0 || Z_LVAL_P(zdata) > PHP_AMQP_MAX_CHANNELS) { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'channel_max' is out of range.", 0 TSRMLS_CC); } else { - if(Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) == 0) { - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("channel_max"), PHP_AMQP_DEFAULT_CHANNEL_MAX TSRMLS_CC); + if(Z_LVAL_P(zdata) == 0) { + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("channel_max"), PHP_AMQP_DEFAULT_CHANNEL_MAX TSRMLS_CC); } else { - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("channel_max"), Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("channel_max"), Z_LVAL_P(zdata) TSRMLS_CC); } } } - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("frame_max"), INI_INT("amqp.frame_max") TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("frame_max"), INI_INT("amqp.frame_max") TSRMLS_CC); - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "frame_max", sizeof("frame_max"), zdata)) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "frame_max", sizeof("frame_max") - 1)) != NULL) { SEPARATE_ZVAL(zdata); - convert_to_long(PHP5to7_MAYBE_DEREF(zdata)); - if (Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) < 0 || Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) > PHP_AMQP_MAX_FRAME) { + convert_to_long(zdata); + if (Z_LVAL_P(zdata) < 0 || Z_LVAL_P(zdata) > PHP_AMQP_MAX_FRAME) { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'frame_max' is out of range.", 0 TSRMLS_CC); } else { - if(Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) == 0) { - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("frame_max"), PHP_AMQP_DEFAULT_FRAME_MAX TSRMLS_CC); + if(Z_LVAL_P(zdata) == 0) { + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("frame_max"), PHP_AMQP_DEFAULT_FRAME_MAX TSRMLS_CC); } else { - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("frame_max"), Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("frame_max"), Z_LVAL_P(zdata) TSRMLS_CC); } } } - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("heartbeat"), INI_INT("amqp.heartbeat") TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("heartbeat"), INI_INT("amqp.heartbeat") TSRMLS_CC); - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "heartbeat", sizeof("heartbeat"), zdata)) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "heartbeat", sizeof("heartbeat") - 1)) != NULL) { SEPARATE_ZVAL(zdata); - convert_to_long(PHP5to7_MAYBE_DEREF(zdata)); - if (Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) < 0 || Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) > PHP_AMQP_MAX_HEARTBEAT) { + convert_to_long(zdata); + if (Z_LVAL_P(zdata) < 0 || Z_LVAL_P(zdata) > PHP_AMQP_MAX_HEARTBEAT) { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'heartbeat' is out of range.", 0 TSRMLS_CC); } else { - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("heartbeat"), Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("heartbeat"), Z_LVAL_P(zdata) TSRMLS_CC); } } - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("sasl_method"), INI_INT("amqp.sasl_method") TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("sasl_method"), INI_INT("amqp.sasl_method") TSRMLS_CC); - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "sasl_method", sizeof("sasl_method"), zdata)) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "sasl_method", sizeof("sasl_method") - 1)) != NULL) { SEPARATE_ZVAL(zdata); - convert_to_long(PHP5to7_MAYBE_DEREF(zdata)); - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("sasl_method"), Z_LVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC); + convert_to_long(zdata); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("sasl_method"), Z_LVAL_P(zdata) TSRMLS_CC); } @@ -562,12 +549,12 @@ static PHP_METHOD(amqp_connection_class, __construct) /* Pull the connection_name out of the $params array */ zdata = NULL; - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "connection_name", sizeof("connection_name"), zdata)) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "connection_name", sizeof("connection_name") - 1)) != NULL) { SEPARATE_ZVAL(zdata); - convert_to_string(PHP5to7_MAYBE_DEREF(zdata)); + convert_to_string(zdata); } - if (zdata && Z_STRLEN_P(PHP5to7_MAYBE_DEREF(zdata)) > 0) { - zend_update_property_string(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("connection_name"), Z_STRVAL_P(PHP5to7_MAYBE_DEREF(zdata)) TSRMLS_CC); + if (zdata && Z_STRLEN_P(zdata) > 0) { + zend_update_property_string(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connection_name"), Z_STRVAL_P(zdata) TSRMLS_CC); } } /* }}} */ @@ -769,7 +756,7 @@ static PHP_METHOD(amqp_connection_class, preconnect) get the login */ static PHP_METHOD(amqp_connection_class, getLogin) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("login"); } @@ -780,7 +767,7 @@ static PHP_METHOD(amqp_connection_class, getLogin) set the login */ static PHP_METHOD(amqp_connection_class, setLogin) { - char *login = NULL; PHP5to7_param_str_len_type_t login_len = 0; + char *login = NULL; size_t login_len = 0; /* Get the login from the method params */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &login, &login_len) == FAILURE) { @@ -793,7 +780,7 @@ static PHP_METHOD(amqp_connection_class, setLogin) return; } - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("login"), login, login_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("login"), login, login_len TSRMLS_CC); RETURN_TRUE; } @@ -803,7 +790,7 @@ static PHP_METHOD(amqp_connection_class, setLogin) get the password */ static PHP_METHOD(amqp_connection_class, getPassword) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("password"); } @@ -814,7 +801,7 @@ static PHP_METHOD(amqp_connection_class, getPassword) set the password */ static PHP_METHOD(amqp_connection_class, setPassword) { - char *password = NULL; PHP5to7_param_str_len_type_t password_len = 0; + char *password = NULL; size_t password_len = 0; /* Get the password from the method params */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &password, &password_len) == FAILURE) { @@ -827,7 +814,7 @@ static PHP_METHOD(amqp_connection_class, setPassword) return; } - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("password"), password, password_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("password"), password, password_len TSRMLS_CC); RETURN_TRUE; } @@ -838,7 +825,7 @@ static PHP_METHOD(amqp_connection_class, setPassword) get the host */ static PHP_METHOD(amqp_connection_class, getHost) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("host"); } @@ -849,7 +836,7 @@ static PHP_METHOD(amqp_connection_class, getHost) set the host */ static PHP_METHOD(amqp_connection_class, setHost) { - char *host = NULL; PHP5to7_param_str_len_type_t host_len = 0; + char *host = NULL; size_t host_len = 0; /* Get the host from the method params */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &host, &host_len) == FAILURE) { @@ -862,7 +849,7 @@ static PHP_METHOD(amqp_connection_class, setHost) return; } - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("host"), host, host_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("host"), host, host_len TSRMLS_CC); RETURN_TRUE; } @@ -873,7 +860,7 @@ static PHP_METHOD(amqp_connection_class, setHost) get the port */ static PHP_METHOD(amqp_connection_class, getPort) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("port"); } @@ -914,7 +901,7 @@ static PHP_METHOD(amqp_connection_class, setPort) return; } - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("port"), port TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("port"), port TSRMLS_CC); RETURN_TRUE; } @@ -924,7 +911,7 @@ static PHP_METHOD(amqp_connection_class, setPort) get the vhost */ static PHP_METHOD(amqp_connection_class, getVhost) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("vhost"); } @@ -935,7 +922,7 @@ static PHP_METHOD(amqp_connection_class, getVhost) set the vhost */ static PHP_METHOD(amqp_connection_class, setVhost) { - char *vhost = NULL; PHP5to7_param_str_len_type_t vhost_len = 0; + char *vhost = NULL; size_t vhost_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &vhost, &vhost_len) == FAILURE) { return; @@ -947,7 +934,7 @@ static PHP_METHOD(amqp_connection_class, setVhost) return; } - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("vhost"), vhost, vhost_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("vhost"), vhost, vhost_len TSRMLS_CC); RETURN_TRUE; } @@ -960,7 +947,7 @@ static PHP_METHOD(amqp_connection_class, getTimeout) { php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "AMQPConnection::getTimeout() method is deprecated; use AMQPConnection::getReadTimeout() instead"); - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("read_timeout"); } @@ -990,7 +977,7 @@ static PHP_METHOD(amqp_connection_class, setTimeout) /* Get the connection object out of the store */ connection = PHP_AMQP_GET_CONNECTION(getThis()); - zend_update_property_double(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("read_timeout"), read_timeout TSRMLS_CC); + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("read_timeout"), read_timeout TSRMLS_CC); if (connection->connection_resource && connection->connection_resource->is_connected) { if (php_amqp_set_resource_read_timeout(connection->connection_resource, read_timeout TSRMLS_CC) == 0) { @@ -1009,7 +996,7 @@ static PHP_METHOD(amqp_connection_class, setTimeout) get the read timeout */ static PHP_METHOD(amqp_connection_class, getReadTimeout) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("read_timeout"); } @@ -1036,7 +1023,7 @@ static PHP_METHOD(amqp_connection_class, setReadTimeout) /* Get the connection object out of the store */ connection = PHP_AMQP_GET_CONNECTION(getThis()); - zend_update_property_double(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("read_timeout"), read_timeout TSRMLS_CC); + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("read_timeout"), read_timeout TSRMLS_CC); if (connection->connection_resource && connection->connection_resource->is_connected) { if (php_amqp_set_resource_read_timeout(connection->connection_resource, read_timeout TSRMLS_CC) == 0) { @@ -1055,7 +1042,7 @@ static PHP_METHOD(amqp_connection_class, setReadTimeout) get write timeout */ static PHP_METHOD(amqp_connection_class, getWriteTimeout) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("write_timeout"); } @@ -1082,7 +1069,7 @@ static PHP_METHOD(amqp_connection_class, setWriteTimeout) /* Get the connection object out of the store */ connection = PHP_AMQP_GET_CONNECTION(getThis()); - zend_update_property_double(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("write_timeout"), write_timeout TSRMLS_CC); + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("write_timeout"), write_timeout TSRMLS_CC); if (connection->connection_resource && connection->connection_resource->is_connected) { if (php_amqp_set_resource_write_timeout(connection->connection_resource, write_timeout TSRMLS_CC) == 0) { @@ -1101,7 +1088,7 @@ static PHP_METHOD(amqp_connection_class, setWriteTimeout) get rpc timeout */ static PHP_METHOD(amqp_connection_class, getRpcTimeout) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("rpc_timeout"); } @@ -1128,7 +1115,7 @@ static PHP_METHOD(amqp_connection_class, setRpcTimeout) /* Get the connection object out of the store */ connection = PHP_AMQP_GET_CONNECTION(getThis()); - zend_update_property_double(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("rpc_timeout"), rpc_timeout TSRMLS_CC); + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("rpc_timeout"), rpc_timeout TSRMLS_CC); if (connection->connection_resource && connection->connection_resource->is_connected) { if (php_amqp_set_resource_rpc_timeout(connection->connection_resource, rpc_timeout TSRMLS_CC) == 0) { @@ -1169,7 +1156,7 @@ static PHP_METHOD(amqp_connection_class, getUsedChannels) Get max supported channels number per connection */ PHP_METHOD(amqp_connection_class, getMaxChannels) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; amqp_connection_object *connection; PHP_AMQP_NOPARAMS(); @@ -1189,7 +1176,7 @@ PHP_METHOD(amqp_connection_class, getMaxChannels) Get max supported frame size per connection in bytes */ static PHP_METHOD(amqp_connection_class, getMaxFrameSize) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; amqp_connection_object *connection; PHP_AMQP_NOPARAMS(); @@ -1209,7 +1196,7 @@ static PHP_METHOD(amqp_connection_class, getMaxFrameSize) Get number of seconds between heartbeats of the connection in seconds */ static PHP_METHOD(amqp_connection_class, getHeartbeatInterval) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; amqp_connection_object *connection; PHP_AMQP_NOPARAMS(); @@ -1244,7 +1231,7 @@ static PHP_METHOD(amqp_connection_class, isPersistent) /* {{{ proto amqp::getCACert() */ static PHP_METHOD(amqp_connection_class, getCACert) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("cacert"); } @@ -1253,13 +1240,13 @@ static PHP_METHOD(amqp_connection_class, getCACert) /* {{{ proto amqp::setCACert(string cacert) */ static PHP_METHOD(amqp_connection_class, setCACert) { - char *str = NULL; PHP5to7_param_str_len_type_t str_len = 0; + char *str = NULL; size_t str_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { return; } - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("cacert"), str, str_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("cacert"), str, str_len TSRMLS_CC); RETURN_TRUE; } @@ -1268,7 +1255,7 @@ static PHP_METHOD(amqp_connection_class, setCACert) /* {{{ proto amqp::getCert() */ static PHP_METHOD(amqp_connection_class, getCert) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("cert"); } @@ -1277,13 +1264,13 @@ static PHP_METHOD(amqp_connection_class, getCert) /* {{{ proto amqp::setCert(string cert) */ static PHP_METHOD(amqp_connection_class, setCert) { - char *str = NULL; PHP5to7_param_str_len_type_t str_len = 0; + char *str = NULL; size_t str_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { return; } - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("cert"), str, str_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("cert"), str, str_len TSRMLS_CC); RETURN_TRUE; } @@ -1292,7 +1279,7 @@ static PHP_METHOD(amqp_connection_class, setCert) /* {{{ proto amqp::getKey() */ static PHP_METHOD(amqp_connection_class, getKey) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("key"); } @@ -1301,13 +1288,13 @@ static PHP_METHOD(amqp_connection_class, getKey) /* {{{ proto amqp::setKey(string key) */ static PHP_METHOD(amqp_connection_class, setKey) { - char *str = NULL; PHP5to7_param_str_len_type_t str_len = 0; + char *str = NULL; size_t str_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { return; } - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("key"), str, str_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("key"), str, str_len TSRMLS_CC); RETURN_TRUE; } @@ -1317,7 +1304,7 @@ static PHP_METHOD(amqp_connection_class, setKey) /* {{{ proto amqp::getVerify() */ static PHP_METHOD(amqp_connection_class, getVerify) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("verify"); } @@ -1332,7 +1319,7 @@ static PHP_METHOD(amqp_connection_class, setVerify) return; } - zend_update_property_bool(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("verify"), verify TSRMLS_CC); + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("verify"), verify TSRMLS_CC); RETURN_TRUE; } @@ -1342,7 +1329,7 @@ static PHP_METHOD(amqp_connection_class, setVerify) get sasl method */ static PHP_METHOD(amqp_connection_class, getSaslMethod) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("sasl_method"); } @@ -1365,7 +1352,7 @@ static PHP_METHOD(amqp_connection_class, setSaslMethod) return; } - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("sasl_method"), method TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("sasl_method"), method TSRMLS_CC); RETURN_TRUE; } @@ -1374,7 +1361,7 @@ static PHP_METHOD(amqp_connection_class, setSaslMethod) /* {{{ proto amqp::getConnectionName() */ static PHP_METHOD(amqp_connection_class, getConnectionName) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("connection_name"); } @@ -1383,15 +1370,15 @@ static PHP_METHOD(amqp_connection_class, getConnectionName) /* {{{ proto amqp::setConnectionName(string connectionName) */ static PHP_METHOD(amqp_connection_class, setConnectionName) { - char *str = NULL; PHP5to7_param_str_len_type_t str_len = 0; + char *str = NULL; size_t str_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &str, &str_len) == FAILURE) { return; } if (str == NULL) { - zend_update_property_null(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("connection_name") TSRMLS_CC); + zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connection_name") TSRMLS_CC); } else { - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("connection_name"), str, str_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connection_name"), str, str_len TSRMLS_CC); } @@ -1643,12 +1630,10 @@ PHP_MINIT_FUNCTION(amqp_connection) zend_declare_property_null(this_ce, ZEND_STRL("connection_name"), ZEND_ACC_PRIVATE TSRMLS_CC); -#if PHP_MAJOR_VERSION >=7 memcpy(&amqp_connection_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); amqp_connection_object_handlers.offset = XtOffsetOf(amqp_connection_object, zo); amqp_connection_object_handlers.free_obj = amqp_connection_free; -#endif return SUCCESS; } diff --git a/amqp_connection_resource.c b/amqp_connection_resource.c index ce9f0aa4..b45c3d43 100644 --- a/amqp_connection_resource.c +++ b/amqp_connection_resource.c @@ -43,10 +43,17 @@ # include #endif +#if HAVE_LIBRABBITMQ_NEW_LAYOUT +#include +#include +#include +#include +#else #include -#include #include +#include #include +#endif #ifdef PHP_WIN32 # include "win32/unistd.h" @@ -596,14 +603,14 @@ amqp_connection_resource *connection_resource_constructor(amqp_connection_params ZEND_RSRC_DTOR_FUNC(amqp_connection_resource_dtor_persistent) { - amqp_connection_resource *resource = (amqp_connection_resource *)PHP5to7_ZEND_RESOURCE_DTOR_ARG->ptr; + amqp_connection_resource *resource = (amqp_connection_resource *)res->ptr; connection_resource_destructor(resource, 1 TSRMLS_CC); } ZEND_RSRC_DTOR_FUNC(amqp_connection_resource_dtor) { - amqp_connection_resource *resource = (amqp_connection_resource *)PHP5to7_ZEND_RESOURCE_DTOR_ARG->ptr; + amqp_connection_resource *resource = (amqp_connection_resource *)res->ptr; connection_resource_destructor(resource, 0 TSRMLS_CC); } diff --git a/amqp_connection_resource.h b/amqp_connection_resource.h index ee81319f..59d424a0 100644 --- a/amqp_connection_resource.h +++ b/amqp_connection_resource.h @@ -33,7 +33,11 @@ extern int le_amqp_connection_resource; extern int le_amqp_connection_resource_persistent; #include "php_amqp.h" -#include "amqp.h" +#if HAVE_LIBRABBITMQ_NEW_LAYOUT +#include +#else +#include +#endif void php_amqp_prepare_for_disconnect(amqp_connection_resource *resource TSRMLS_DC); diff --git a/amqp_decimal.c b/amqp_decimal.c index 8fd92c13..78ad5590 100644 --- a/amqp_decimal.c +++ b/amqp_decimal.c @@ -31,17 +31,17 @@ zend_class_entry *amqp_decimal_class_entry; #define this_ce amqp_decimal_class_entry -static const PHP5to7_param_long_type_t AMQP_DECIMAL_EXPONENT_MIN = 0; -static const PHP5to7_param_long_type_t AMQP_DECIMAL_EXPONENT_MAX = UINT8_MAX; -static const PHP5to7_param_long_type_t AMQP_DECIMAL_SIGNIFICAND_MIN = 0; -static const PHP5to7_param_long_type_t AMQP_DECIMAL_SIGNIFICAND_MAX = UINT32_MAX; +static const zend_long AMQP_DECIMAL_EXPONENT_MIN = 0; +static const zend_long AMQP_DECIMAL_EXPONENT_MAX = UINT8_MAX; +static const zend_long AMQP_DECIMAL_SIGNIFICAND_MIN = 0; +static const zend_long AMQP_DECIMAL_SIGNIFICAND_MAX = UINT32_MAX; /* {{{ proto AMQPDecimal::__construct(int $e, int $n) */ static PHP_METHOD(amqp_decimal_class, __construct) { - PHP5to7_param_long_type_t exponent, significand; + zend_long exponent, significand; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &exponent, &significand) == FAILURE) { return; @@ -66,8 +66,8 @@ static PHP_METHOD(amqp_decimal_class, __construct) return; } - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("exponent"), exponent TSRMLS_CC); - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("significand"), significand TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("exponent"), exponent TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("significand"), significand TSRMLS_CC); } /* }}} */ @@ -75,7 +75,7 @@ static PHP_METHOD(amqp_decimal_class, __construct) Get exponent */ static PHP_METHOD(amqp_decimal_class, getExponent) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("exponent"); @@ -86,7 +86,7 @@ static PHP_METHOD(amqp_decimal_class, getExponent) Get E */ static PHP_METHOD(amqp_decimal_class, getSignificand) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("significand"); @@ -121,7 +121,7 @@ PHP_MINIT_FUNCTION(amqp_decimal) INIT_CLASS_ENTRY(ce, "AMQPDecimal", amqp_decimal_class_functions); this_ce = zend_register_internal_class(&ce TSRMLS_CC); - this_ce->ce_flags = this_ce->ce_flags | PHP5to7_ZEND_ACC_FINAL_CLASS; + this_ce->ce_flags = this_ce->ce_flags | ZEND_ACC_FINAL; zend_declare_class_constant_long(this_ce, ZEND_STRL("EXPONENT_MIN"), AMQP_DECIMAL_EXPONENT_MIN TSRMLS_CC); zend_declare_class_constant_long(this_ce, ZEND_STRL("EXPONENT_MAX"), AMQP_DECIMAL_EXPONENT_MAX TSRMLS_CC); diff --git a/amqp_envelope.c b/amqp_envelope.c index 7d7e4d4d..47daccf0 100644 --- a/amqp_envelope.c +++ b/amqp_envelope.c @@ -43,8 +43,13 @@ #endif +#if HAVE_LIBRABBITMQ_NEW_LAYOUT +#include +#include +#else #include #include +#endif #ifdef PHP_WIN32 # include "win32/unistd.h" @@ -71,13 +76,13 @@ void convert_amqp_envelope_to_zval(amqp_envelope_t *amqp_envelope, zval *envelop amqp_basic_properties_t *p = &amqp_envelope->message.properties; amqp_message_t *message = &amqp_envelope->message; - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(envelope), ZEND_STRL("body"), (const char *) message->body.bytes, (PHP5to7_param_str_len_type_t) message->body.len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(envelope), ZEND_STRL("body"), (const char *) message->body.bytes, (size_t) message->body.len TSRMLS_CC); - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(envelope), ZEND_STRL("consumer_tag"), (const char *) amqp_envelope->consumer_tag.bytes, (PHP5to7_param_str_len_type_t) amqp_envelope->consumer_tag.len TSRMLS_CC); - zend_update_property_long(this_ce, PHP5to8_OBJ_PROP(envelope), ZEND_STRL("delivery_tag"), (PHP5to7_param_long_type_t) amqp_envelope->delivery_tag TSRMLS_CC); - zend_update_property_bool(this_ce, PHP5to8_OBJ_PROP(envelope), ZEND_STRL("is_redelivery"), (PHP5to7_param_long_type_t) amqp_envelope->redelivered TSRMLS_CC); - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(envelope), ZEND_STRL("exchange_name"), (const char *) amqp_envelope->exchange.bytes, (PHP5to7_param_str_len_type_t) amqp_envelope->exchange.len TSRMLS_CC); - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(envelope), ZEND_STRL("routing_key"), (const char *) amqp_envelope->routing_key.bytes, (PHP5to7_param_str_len_type_t) amqp_envelope->routing_key.len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(envelope), ZEND_STRL("consumer_tag"), (const char *) amqp_envelope->consumer_tag.bytes, (size_t) amqp_envelope->consumer_tag.len TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(envelope), ZEND_STRL("delivery_tag"), (zend_long) amqp_envelope->delivery_tag TSRMLS_CC); + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(envelope), ZEND_STRL("is_redelivery"), (zend_long) amqp_envelope->redelivered TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(envelope), ZEND_STRL("exchange_name"), (const char *) amqp_envelope->exchange.bytes, (size_t) amqp_envelope->exchange.len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(envelope), ZEND_STRL("routing_key"), (const char *) amqp_envelope->routing_key.bytes, (size_t) amqp_envelope->routing_key.len TSRMLS_CC); php_amqp_basic_properties_extract(p, envelope TSRMLS_CC); } @@ -94,7 +99,7 @@ static PHP_METHOD(amqp_envelope_class, __construct) { /* {{{ proto AMQPEnvelope::getBody()*/ static PHP_METHOD(amqp_envelope_class, getBody) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); @@ -111,7 +116,7 @@ static PHP_METHOD(amqp_envelope_class, getBody) { /* {{{ proto AMQPEnvelope::getRoutingKey() */ static PHP_METHOD(amqp_envelope_class, getRoutingKey) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("routing_key"); } @@ -119,7 +124,7 @@ static PHP_METHOD(amqp_envelope_class, getRoutingKey) { /* {{{ proto AMQPEnvelope::getDeliveryTag() */ static PHP_METHOD(amqp_envelope_class, getDeliveryTag) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("delivery_tag"); } @@ -127,7 +132,7 @@ static PHP_METHOD(amqp_envelope_class, getDeliveryTag) { /* {{{ proto AMQPEnvelope::getConsumerTag() */ static PHP_METHOD(amqp_envelope_class, getConsumerTag) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("consumer_tag"); } @@ -135,7 +140,7 @@ static PHP_METHOD(amqp_envelope_class, getConsumerTag) { /* {{{ proto AMQPEnvelope::getExchangeName() */ static PHP_METHOD(amqp_envelope_class, getExchangeName) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("exchange_name"); } @@ -143,7 +148,7 @@ static PHP_METHOD(amqp_envelope_class, getExchangeName) { /* {{{ proto AMQPEnvelope::isRedelivery() */ static PHP_METHOD(amqp_envelope_class, isRedelivery) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("is_redelivery"); } @@ -152,44 +157,43 @@ static PHP_METHOD(amqp_envelope_class, isRedelivery) { /* {{{ proto AMQPEnvelope::getHeader(string name) */ static PHP_METHOD(amqp_envelope_class, getHeader) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; - char *key; PHP5to7_param_str_len_type_t key_len; - PHP5to7_zval_t *tmp = NULL; + char *key; + size_t key_len; + zval *tmp = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { return; } zval* zv = PHP_AMQP_READ_THIS_PROP_CE("headers", amqp_basic_properties_class_entry); - //zval* zv = PHP_AMQP_READ_THIS_PROP("headers"); /* Look for the hash key */ - if (!PHP5to7_ZEND_HASH_FIND(HASH_OF(zv), key, key_len + 1, tmp)) { + if ((tmp = zend_hash_str_find(HASH_OF(zv), key, key_len)) == NULL) { RETURN_FALSE; } - RETURN_ZVAL(PHP5to7_MAYBE_DEREF(tmp), 1, 0); + RETURN_ZVAL(tmp, 1, 0); } /* }}} */ /* {{{ proto AMQPEnvelope::hasHeader(string name) */ static PHP_METHOD(amqp_envelope_class, hasHeader) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; - char *key; PHP5to7_param_str_len_type_t key_len; - PHP5to7_zval_t *tmp = NULL; + char *key; + size_t key_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { return; } zval* zv = PHP_AMQP_READ_THIS_PROP_CE("headers", amqp_basic_properties_class_entry); - //zval* zv = PHP_AMQP_READ_THIS_PROP("headers"); /* Look for the hash key */ - if (!PHP5to7_ZEND_HASH_FIND(HASH_OF(zv), key, key_len + 1, tmp)) { + if (zend_hash_str_find(HASH_OF(zv), key, key_len) == NULL) { RETURN_FALSE; } @@ -251,7 +255,7 @@ PHP_MINIT_FUNCTION (amqp_envelope) { zend_class_entry ce; INIT_CLASS_ENTRY(ce, "AMQPEnvelope", amqp_envelope_class_functions); - this_ce = zend_register_internal_class_ex(&ce, amqp_basic_properties_class_entry PHP5to7_PARENT_CLASS_NAME_C(NULL) TSRMLS_CC); + this_ce = zend_register_internal_class_ex(&ce, amqp_basic_properties_class_entry TSRMLS_CC); zend_declare_property_null(this_ce, ZEND_STRL("body"), ZEND_ACC_PRIVATE TSRMLS_CC); diff --git a/amqp_envelope.h b/amqp_envelope.h index e315682b..792c5854 100644 --- a/amqp_envelope.h +++ b/amqp_envelope.h @@ -21,11 +21,7 @@ +----------------------------------------------------------------------+ */ -#if PHP_MAJOR_VERSION >= 7 - #include "php7_support.h" -#else - #include "php5_support.h" -#endif +#include "php_amqp.h" extern zend_class_entry *amqp_envelope_class_entry; diff --git a/amqp_exchange.c b/amqp_exchange.c index e4cd6b1c..55ac28b2 100644 --- a/amqp_exchange.c +++ b/amqp_exchange.c @@ -40,8 +40,13 @@ # include # include #endif +#if HAVE_LIBRABBITMQ_NEW_LAYOUT +#include +#include +#else #include #include +#endif #ifdef PHP_WIN32 # include "win32/unistd.h" @@ -62,9 +67,9 @@ zend_class_entry *amqp_exchange_class_entry; create Exchange */ static PHP_METHOD(amqp_exchange_class, __construct) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; - PHP5to7_zval_t arguments PHP5to7_MAYBE_SET_TO_NULL; + zval arguments; zval *channelObj; amqp_channel_resource *channel_resource; @@ -73,16 +78,16 @@ static PHP_METHOD(amqp_exchange_class, __construct) return; } - PHP5to7_MAYBE_INIT(arguments); - PHP5to7_ARRAY_INIT(arguments); - zend_update_property(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("arguments"), PHP5to7_MAYBE_PTR(arguments) TSRMLS_CC); - PHP5to7_MAYBE_DESTROY(arguments); + ZVAL_UNDEF(&arguments); + array_init(&arguments); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("arguments"), &arguments TSRMLS_CC); + zval_ptr_dtor(&arguments); channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(channelObj); PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not create exchange."); - zend_update_property(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("channel"), channelObj TSRMLS_CC); - zend_update_property(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("connection"), PHP_AMQP_READ_OBJ_PROP(amqp_channel_class_entry, channelObj, "connection") TSRMLS_CC); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("channel"), channelObj TSRMLS_CC); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connection"), PHP_AMQP_READ_OBJ_PROP(amqp_channel_class_entry, channelObj, "connection") TSRMLS_CC); } /* }}} */ @@ -91,7 +96,7 @@ static PHP_METHOD(amqp_exchange_class, __construct) Get the exchange name */ static PHP_METHOD(amqp_exchange_class, getName) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); @@ -110,7 +115,7 @@ Set the exchange name */ static PHP_METHOD(amqp_exchange_class, setName) { char *name = NULL; - PHP5to7_param_str_len_type_t name_len = 0; + size_t name_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { return; @@ -123,7 +128,7 @@ static PHP_METHOD(amqp_exchange_class, setName) } /* Set the exchange name */ - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("name"), name, name_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("name"), name, name_len TSRMLS_CC); } /* }}} */ @@ -132,9 +137,9 @@ static PHP_METHOD(amqp_exchange_class, setName) Get the exchange parameters */ static PHP_METHOD(amqp_exchange_class, getFlags) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; - PHP5to7_param_long_type_t flags = AMQP_NOPARAM; + zend_long flags = AMQP_NOPARAM; PHP_AMQP_NOPARAMS(); @@ -163,7 +168,7 @@ static PHP_METHOD(amqp_exchange_class, getFlags) Set the exchange parameters */ static PHP_METHOD(amqp_exchange_class, setFlags) { - PHP5to7_param_long_type_t flags = AMQP_NOPARAM; + zend_long flags = AMQP_NOPARAM; zend_bool flags_is_null = 1; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l!", &flags, &flags_is_null) == FAILURE) { @@ -173,10 +178,10 @@ static PHP_METHOD(amqp_exchange_class, setFlags) /* Set the flags based on the bitmask we were given */ flags = flags ? flags & PHP_AMQP_EXCHANGE_FLAGS : flags; - zend_update_property_bool(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("passive"), IS_PASSIVE(flags) TSRMLS_CC); - zend_update_property_bool(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("durable"), IS_DURABLE(flags) TSRMLS_CC); - zend_update_property_bool(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("auto_delete"), IS_AUTODELETE(flags) TSRMLS_CC); - zend_update_property_bool(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("internal"), IS_INTERNAL(flags) TSRMLS_CC); + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("passive"), IS_PASSIVE(flags) TSRMLS_CC); + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("durable"), IS_DURABLE(flags) TSRMLS_CC); + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("auto_delete"), IS_AUTODELETE(flags) TSRMLS_CC); + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("internal"), IS_INTERNAL(flags) TSRMLS_CC); } /* }}} */ @@ -185,7 +190,7 @@ static PHP_METHOD(amqp_exchange_class, setFlags) Get the exchange type */ static PHP_METHOD(amqp_exchange_class, getType) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); @@ -203,13 +208,13 @@ static PHP_METHOD(amqp_exchange_class, getType) Set the exchange type */ static PHP_METHOD(amqp_exchange_class, setType) { - char *type = NULL; PHP5to7_param_str_len_type_t type_len = 0; + char *type = NULL; size_t type_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &type, &type_len) == FAILURE) { return; } - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("type"), type, type_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("type"), type, type_len TSRMLS_CC); } /* }}} */ @@ -218,38 +223,37 @@ static PHP_METHOD(amqp_exchange_class, setType) Get the exchange argument referenced by key */ static PHP_METHOD(amqp_exchange_class, getArgument) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; - PHP5to7_zval_t *tmp = NULL; + zval *tmp = NULL; - char *key; PHP5to7_param_str_len_type_t key_len; + char *key; size_t key_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { return; } - if (!PHP5to7_ZEND_HASH_FIND(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len + 1, tmp)) { + if ((tmp = zend_hash_str_find(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len)) == NULL) { RETURN_FALSE; } - RETURN_ZVAL(PHP5to7_MAYBE_DEREF(tmp), 1, 0); + RETURN_ZVAL(tmp, 1, 0); } /* }}} */ /* {{{ proto AMQPExchange::hasArgument(string key) */ static PHP_METHOD(amqp_exchange_class, hasArgument) { - PHP5to7_READ_PROP_RV_PARAM_DECL; - - PHP5to7_zval_t *tmp = NULL; - - char *key; PHP5to7_param_str_len_type_t key_len; + zval rv; + zval *tmp = NULL; + char *key; + size_t key_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { return; } - if (!PHP5to7_ZEND_HASH_FIND(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, (unsigned)(key_len + 1), tmp)) { + if ((tmp = zend_hash_str_find(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len)) == NULL) { RETURN_FALSE; } @@ -261,7 +265,7 @@ static PHP_METHOD(amqp_exchange_class, hasArgument) Get the exchange arguments */ static PHP_METHOD(amqp_exchange_class, getArguments) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("arguments"); } @@ -278,7 +282,7 @@ static PHP_METHOD(amqp_exchange_class, setArguments) return; } - zend_update_property(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("arguments"), zvalArguments TSRMLS_CC); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("arguments"), zvalArguments TSRMLS_CC); RETURN_TRUE; } @@ -288,9 +292,9 @@ static PHP_METHOD(amqp_exchange_class, setArguments) /* {{{ proto AMQPExchange::setArgument(key, value) */ static PHP_METHOD(amqp_exchange_class, setArgument) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; - char *key= NULL; PHP5to7_param_str_len_type_t key_len = 0; + char *key= NULL; size_t key_len = 0; zval *value = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", @@ -301,13 +305,14 @@ static PHP_METHOD(amqp_exchange_class, setArgument) switch (Z_TYPE_P(value)) { case IS_NULL: - PHP5to7_ZEND_HASH_DEL(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, (unsigned) (key_len + 1)); + zend_hash_str_del_ind(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len); break; - PHP5to7_CASE_IS_BOOL: + case IS_TRUE: + case IS_FALSE: case IS_LONG: case IS_DOUBLE: case IS_STRING: - PHP5to7_ZEND_HASH_ADD(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, (unsigned) (key_len + 1), value, sizeof(zval *)); + zend_hash_str_add(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len, value); Z_TRY_ADDREF_P(value); break; default: @@ -325,7 +330,7 @@ declare Exchange */ static PHP_METHOD(amqp_exchange_class, declareExchange) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; amqp_channel_resource *channel_resource; amqp_table_t *arguments; @@ -383,13 +388,13 @@ delete Exchange */ static PHP_METHOD(amqp_exchange_class, delete) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; amqp_channel_resource *channel_resource; char *name = NULL; - PHP5to7_param_str_len_type_t name_len = 0; - PHP5to7_param_long_type_t flags = AMQP_NOPARAM; + size_t name_len = 0; + zend_long flags = AMQP_NOPARAM; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sl", &name, &name_len, @@ -427,18 +432,18 @@ publish into Exchange */ static PHP_METHOD(amqp_exchange_class, publish) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; zval *ini_arr = NULL; - PHP5to7_zval_t *tmp = NULL; + zval *tmp = NULL; amqp_channel_resource *channel_resource; char *key_name = NULL; - PHP5to7_param_str_len_type_t key_len = 0; + size_t key_len = 0; char *msg = NULL; - PHP5to7_param_str_len_type_t msg_len = 0; - PHP5to7_param_long_type_t flags = AMQP_NOPARAM; + size_t msg_len = 0; + zend_long flags = AMQP_NOPARAM; #ifndef PHP_WIN32 /* Storage for previous signal handler during SIGPIPE override */ @@ -462,115 +467,115 @@ static PHP_METHOD(amqp_exchange_class, publish) props.headers.entries = 0; { - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF (ini_arr), "content_type", sizeof("content_type"), tmp)) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "content_type", sizeof("content_type") - 1)) != NULL) { SEPARATE_ZVAL(tmp); - convert_to_string(PHP5to7_MAYBE_DEREF(tmp)); + convert_to_string(tmp); - if (Z_STRLEN_P(PHP5to7_MAYBE_DEREF(tmp)) > 0) { - props.content_type = amqp_cstring_bytes(Z_STRVAL_P(PHP5to7_MAYBE_DEREF(tmp))); + if (Z_STRLEN_P(tmp) > 0) { + props.content_type = amqp_cstring_bytes(Z_STRVAL_P(tmp)); props._flags |= AMQP_BASIC_CONTENT_TYPE_FLAG; } } - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF (ini_arr), "content_encoding", sizeof("content_encoding"), tmp)) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "content_encoding", sizeof("content_encoding") - 1)) != NULL) { SEPARATE_ZVAL(tmp); - convert_to_string(PHP5to7_MAYBE_DEREF(tmp)); + convert_to_string(tmp); - if (Z_STRLEN_P(PHP5to7_MAYBE_DEREF(tmp)) > 0) { - props.content_encoding = amqp_cstring_bytes(Z_STRVAL_P(PHP5to7_MAYBE_DEREF(tmp))); + if (Z_STRLEN_P(tmp) > 0) { + props.content_encoding = amqp_cstring_bytes(Z_STRVAL_P(tmp)); props._flags |= AMQP_BASIC_CONTENT_ENCODING_FLAG; } } - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF (ini_arr), "message_id", sizeof("message_id"), tmp)) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "message_id", sizeof("message_id") - 1)) != NULL) { SEPARATE_ZVAL(tmp); - convert_to_string(PHP5to7_MAYBE_DEREF(tmp)); + convert_to_string(tmp); - if (Z_STRLEN_P(PHP5to7_MAYBE_DEREF(tmp)) > 0) { - props.message_id = amqp_cstring_bytes(Z_STRVAL_P(PHP5to7_MAYBE_DEREF(tmp))); + if (Z_STRLEN_P(tmp) > 0) { + props.message_id = amqp_cstring_bytes(Z_STRVAL_P(tmp)); props._flags |= AMQP_BASIC_MESSAGE_ID_FLAG; } } - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF (ini_arr), "user_id", sizeof("user_id"), tmp)) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "user_id", sizeof("user_id") - 1)) != NULL) { SEPARATE_ZVAL(tmp); - convert_to_string(PHP5to7_MAYBE_DEREF(tmp)); + convert_to_string(tmp); - if (Z_STRLEN_P(PHP5to7_MAYBE_DEREF(tmp)) > 0) { - props.user_id = amqp_cstring_bytes(Z_STRVAL_P(PHP5to7_MAYBE_DEREF(tmp))); + if (Z_STRLEN_P(tmp) > 0) { + props.user_id = amqp_cstring_bytes(Z_STRVAL_P(tmp)); props._flags |= AMQP_BASIC_USER_ID_FLAG; } } - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF (ini_arr), "app_id", sizeof("app_id"), tmp)) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "app_id", sizeof("app_id") - 1)) != NULL) { SEPARATE_ZVAL(tmp); - convert_to_string(PHP5to7_MAYBE_DEREF(tmp)); + convert_to_string(tmp); - if (Z_STRLEN_P(PHP5to7_MAYBE_DEREF(tmp)) > 0) { - props.app_id = amqp_cstring_bytes(Z_STRVAL_P(PHP5to7_MAYBE_DEREF(tmp))); + if (Z_STRLEN_P(tmp) > 0) { + props.app_id = amqp_cstring_bytes(Z_STRVAL_P(tmp)); props._flags |= AMQP_BASIC_APP_ID_FLAG; } } - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF (ini_arr), "delivery_mode", sizeof("delivery_mode"), tmp)) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "delivery_mode", sizeof("delivery_mode") - 1)) != NULL) { SEPARATE_ZVAL(tmp); - convert_to_long(PHP5to7_MAYBE_DEREF(tmp)); + convert_to_long(tmp); - props.delivery_mode = (uint8_t)Z_LVAL_P(PHP5to7_MAYBE_DEREF(tmp)); + props.delivery_mode = (uint8_t)Z_LVAL_P(tmp); props._flags |= AMQP_BASIC_DELIVERY_MODE_FLAG; } - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF (ini_arr), "priority", sizeof("priority"), tmp)) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "priority", sizeof("priority") - 1)) != NULL) { SEPARATE_ZVAL(tmp); - convert_to_long(PHP5to7_MAYBE_DEREF(tmp)); + convert_to_long(tmp); - props.priority = (uint8_t)Z_LVAL_P(PHP5to7_MAYBE_DEREF(tmp)); + props.priority = (uint8_t)Z_LVAL_P(tmp); props._flags |= AMQP_BASIC_PRIORITY_FLAG; } - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF (ini_arr), "timestamp", sizeof("timestamp"), tmp)) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "timestamp", sizeof("timestamp") - 1)) != NULL) { SEPARATE_ZVAL(tmp); - convert_to_long(PHP5to7_MAYBE_DEREF(tmp)); + convert_to_long(tmp); - props.timestamp = (uint64_t)Z_LVAL_P(PHP5to7_MAYBE_DEREF(tmp)); + props.timestamp = (uint64_t)Z_LVAL_P(tmp); props._flags |= AMQP_BASIC_TIMESTAMP_FLAG; } - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF (ini_arr), "expiration", sizeof("expiration"), tmp)) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "expiration", sizeof("expiration") - 1)) != NULL) { SEPARATE_ZVAL(tmp); - convert_to_string(PHP5to7_MAYBE_DEREF(tmp)); + convert_to_string(tmp); - if (Z_STRLEN_P(PHP5to7_MAYBE_DEREF(tmp)) > 0) { - props.expiration = amqp_cstring_bytes(Z_STRVAL_P(PHP5to7_MAYBE_DEREF(tmp))); + if (Z_STRLEN_P(tmp) > 0) { + props.expiration = amqp_cstring_bytes(Z_STRVAL_P(tmp)); props._flags |= AMQP_BASIC_EXPIRATION_FLAG; } } - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF (ini_arr), "type", sizeof("type"), tmp)) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "type", sizeof("type") - 1)) != NULL) { SEPARATE_ZVAL(tmp); - convert_to_string(PHP5to7_MAYBE_DEREF(tmp)); + convert_to_string(tmp); - if (Z_STRLEN_P(PHP5to7_MAYBE_DEREF(tmp)) > 0) { - props.type = amqp_cstring_bytes(Z_STRVAL_P(PHP5to7_MAYBE_DEREF(tmp))); + if (Z_STRLEN_P(tmp) > 0) { + props.type = amqp_cstring_bytes(Z_STRVAL_P(tmp)); props._flags |= AMQP_BASIC_TYPE_FLAG; } } - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF (ini_arr), "reply_to", sizeof("reply_to"), tmp)) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "reply_to", sizeof("reply_to") - 1)) != NULL) { SEPARATE_ZVAL(tmp); - convert_to_string(PHP5to7_MAYBE_DEREF(tmp)); + convert_to_string(tmp); - if (Z_STRLEN_P(PHP5to7_MAYBE_DEREF(tmp)) > 0) { - props.reply_to = amqp_cstring_bytes(Z_STRVAL_P(PHP5to7_MAYBE_DEREF(tmp))); + if (Z_STRLEN_P(tmp) > 0) { + props.reply_to = amqp_cstring_bytes(Z_STRVAL_P(tmp)); props._flags |= AMQP_BASIC_REPLY_TO_FLAG; } } - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF (ini_arr), "correlation_id", sizeof("correlation_id"), tmp)) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "correlation_id", sizeof("correlation_id") - 1)) != NULL) { SEPARATE_ZVAL(tmp); - convert_to_string(PHP5to7_MAYBE_DEREF(tmp)); + convert_to_string(tmp); - if (Z_STRLEN_P(PHP5to7_MAYBE_DEREF(tmp)) > 0) { - props.correlation_id = amqp_cstring_bytes(Z_STRVAL_P(PHP5to7_MAYBE_DEREF(tmp))); + if (Z_STRLEN_P(tmp) > 0) { + props.correlation_id = amqp_cstring_bytes(Z_STRVAL_P(tmp)); props._flags |= AMQP_BASIC_CORRELATION_ID_FLAG; } } @@ -579,11 +584,11 @@ static PHP_METHOD(amqp_exchange_class, publish) amqp_table_t *headers = NULL; - if (ini_arr && PHP5to7_ZEND_HASH_FIND(HASH_OF(ini_arr), "headers", sizeof("headers"), tmp)) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "headers", sizeof("headers") - 1)) != NULL) { SEPARATE_ZVAL(tmp); - convert_to_array(PHP5to7_MAYBE_DEREF(tmp)); + convert_to_array(tmp); - headers = php_amqp_type_convert_zval_to_amqp_table(PHP5to7_MAYBE_DEREF(tmp) TSRMLS_CC); + headers = php_amqp_type_convert_zval_to_amqp_table(tmp TSRMLS_CC); props._flags |= AMQP_BASIC_HEADERS_FLAG; props.headers = *headers; @@ -643,16 +648,16 @@ bind exchange to exchange by routing key */ static PHP_METHOD(amqp_exchange_class, bind) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; zval *zvalArguments = NULL; amqp_channel_resource *channel_resource; char *src_name; - PHP5to7_param_str_len_type_t src_name_len = 0; + size_t src_name_len = 0; char *keyname = NULL; - PHP5to7_param_str_len_type_t keyname_len = 0; + size_t keyname_len = 0; amqp_table_t *arguments = NULL; @@ -702,16 +707,16 @@ remove exchange to exchange binding by routing key */ static PHP_METHOD(amqp_exchange_class, unbind) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; zval *zvalArguments = NULL; amqp_channel_resource *channel_resource; char *src_name; - PHP5to7_param_str_len_type_t src_name_len = 0; + size_t src_name_len = 0; char *keyname = NULL; - PHP5to7_param_str_len_type_t keyname_len = 0; + size_t keyname_len = 0; amqp_table_t *arguments = NULL; @@ -760,7 +765,7 @@ static PHP_METHOD(amqp_exchange_class, unbind) Get the AMQPChannel object in use */ static PHP_METHOD(amqp_exchange_class, getChannel) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("channel"); } @@ -770,7 +775,7 @@ static PHP_METHOD(amqp_exchange_class, getChannel) Get the AMQPConnection object in use */ static PHP_METHOD(amqp_exchange_class, getConnection) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("connection"); } diff --git a/amqp_methods_handling.c b/amqp_methods_handling.c index 3bad23d2..aa471cfc 100644 --- a/amqp_methods_handling.c +++ b/amqp_methods_handling.c @@ -36,28 +36,6 @@ static int amqp_id_in_reply_list(amqp_method_number_t expected, amqp_method_numb return 0; } -/* taken from rabbbitmq-c */ -static int amqp_simple_wait_method_list(amqp_connection_state_t state, - amqp_channel_t expected_channel, - amqp_method_number_t *expected_methods, - amqp_method_t *output) { - amqp_frame_t frame; - int res = amqp_simple_wait_frame(state, &frame); - - if (AMQP_STATUS_OK != res) { - return res; - } - - if (AMQP_FRAME_METHOD != frame.frame_type || - expected_channel != frame.channel || - !amqp_id_in_reply_list(frame.payload.method.id, expected_methods)) { - return AMQP_STATUS_WRONG_METHOD; - } - - *output = frame.payload.method; - return AMQP_STATUS_OK; -} - /* taken from rabbbitmq-c */ int amqp_simple_wait_method_list_noblock(amqp_connection_state_t state, amqp_channel_t expected_channel, @@ -131,38 +109,37 @@ int php_amqp_handle_basic_return(char **message, amqp_connection_resource *resou } int php_amqp_call_basic_return_callback(amqp_basic_return_t *m, amqp_message_t *msg, amqp_callback_bucket *cb TSRMLS_DC) { - PHP5to7_zval_t params PHP5to7_MAYBE_SET_TO_NULL; - PHP5to7_zval_t basic_properties PHP5to7_MAYBE_SET_TO_NULL; + zval params; + zval basic_properties; int status = PHP_AMQP_RESOURCE_RESPONSE_OK; - PHP5to7_MAYBE_INIT(params); - PHP5to7_ARRAY_INIT(params); + ZVAL_UNDEF(¶ms); + array_init(¶ms); - PHP5to7_MAYBE_INIT(basic_properties); + ZVAL_UNDEF(&basic_properties); /* callback(int $reply_code, string $reply_text, string $exchange, string $routing_key, AMQPBasicProperties $properties, string $body); */ - add_next_index_long(PHP5to7_MAYBE_PTR(params), (PHP5to7_param_long_type_t) m->reply_code); - PHP5to7_ADD_NEXT_INDEX_STRINGL_DUP(PHP5to7_MAYBE_PTR(params), (const char *) m->reply_text.bytes, (PHP5to7_param_str_len_type_t) m->reply_text.len); - PHP5to7_ADD_NEXT_INDEX_STRINGL_DUP(PHP5to7_MAYBE_PTR(params), (const char *) m->exchange.bytes, (PHP5to7_param_str_len_type_t) m->exchange.len); - PHP5to7_ADD_NEXT_INDEX_STRINGL_DUP(PHP5to7_MAYBE_PTR(params), (const char *) m->routing_key.bytes, (PHP5to7_param_str_len_type_t) m->routing_key.len); + add_next_index_long(¶ms, (zend_long) m->reply_code); + add_next_index_stringl(¶ms, m->reply_text.bytes, m->reply_text.len); + add_next_index_stringl(¶ms, m->exchange.bytes, m->exchange.len); + add_next_index_stringl(¶ms, m->routing_key.bytes, m->routing_key.len); - php_amqp_basic_properties_convert_to_zval(&msg->properties, PHP5to7_MAYBE_PTR(basic_properties) TSRMLS_CC); - add_next_index_zval(PHP5to7_MAYBE_PTR(params), PHP5to7_MAYBE_PTR(basic_properties)); - Z_ADDREF_P(PHP5to7_MAYBE_PTR(basic_properties)); + php_amqp_basic_properties_convert_to_zval(&msg->properties, &basic_properties TSRMLS_CC); + add_next_index_zval(¶ms, &basic_properties); + Z_ADDREF_P(&basic_properties); - PHP5to7_ADD_NEXT_INDEX_STRINGL_DUP(PHP5to7_MAYBE_PTR(params), (const char *) msg->body.bytes, (PHP5to7_param_str_len_type_t) msg->body.len); + add_next_index_stringl(¶ms, msg->body.bytes, msg->body.len); status = php_amqp_call_callback_with_params(params, cb TSRMLS_CC); - PHP5to7_MAYBE_DESTROY(basic_properties); + zval_ptr_dtor(&basic_properties); return status; } int php_amqp_handle_basic_ack(char **message, amqp_connection_resource *resource, amqp_channel_t channel_id, amqp_channel_object *channel, amqp_method_t *method TSRMLS_DC) { - amqp_rpc_reply_t ret; int status = PHP_AMQP_RESOURCE_RESPONSE_OK; assert(AMQP_BASIC_ACK_METHOD == method->id); @@ -180,20 +157,19 @@ int php_amqp_handle_basic_ack(char **message, amqp_connection_resource *resource } int php_amqp_call_basic_ack_callback(amqp_basic_ack_t *m, amqp_callback_bucket *cb TSRMLS_DC) { - PHP5to7_zval_t params PHP5to7_MAYBE_SET_TO_NULL; + zval params; - PHP5to7_MAYBE_INIT(params); - PHP5to7_ARRAY_INIT(params); + ZVAL_UNDEF(¶ms); + array_init(¶ms); /* callback(int $delivery_tag, bool $multiple); */ - add_next_index_long(PHP5to7_MAYBE_PTR(params), (PHP5to7_param_long_type_t) m->delivery_tag); - add_next_index_bool(PHP5to7_MAYBE_PTR(params), m->multiple); + add_next_index_long(¶ms, (zend_long) m->delivery_tag); + add_next_index_bool(¶ms, m->multiple); return php_amqp_call_callback_with_params(params, cb TSRMLS_CC); } int php_amqp_handle_basic_nack(char **message, amqp_connection_resource *resource, amqp_channel_t channel_id, amqp_channel_object *channel, amqp_method_t *method TSRMLS_DC) { - amqp_rpc_reply_t ret; int status = PHP_AMQP_RESOURCE_RESPONSE_OK; assert(AMQP_BASIC_NACK_METHOD == method->id); @@ -211,20 +187,20 @@ int php_amqp_handle_basic_nack(char **message, amqp_connection_resource *resourc } int php_amqp_call_basic_nack_callback(amqp_basic_nack_t *m, amqp_callback_bucket *cb TSRMLS_DC) { - PHP5to7_zval_t params PHP5to7_MAYBE_SET_TO_NULL; + zval params; - PHP5to7_MAYBE_INIT(params); - PHP5to7_ARRAY_INIT(params); + ZVAL_UNDEF(¶ms); + array_init(¶ms); /* callback(int $delivery_tag, bool $multiple, bool $requeue); */ - add_next_index_long(PHP5to7_MAYBE_PTR(params), (PHP5to7_param_long_type_t) m->delivery_tag); - add_next_index_bool(PHP5to7_MAYBE_PTR(params), m->multiple); - add_next_index_bool(PHP5to7_MAYBE_PTR(params), m->requeue); + add_next_index_long(¶ms, (zend_long) m->delivery_tag); + add_next_index_bool(¶ms, m->multiple); + add_next_index_bool(¶ms, m->requeue); return php_amqp_call_callback_with_params(params, cb TSRMLS_CC); } -int php_amqp_call_callback_with_params(PHP5to7_zval_t params, amqp_callback_bucket *cb TSRMLS_DC) +int php_amqp_call_callback_with_params(zval params, amqp_callback_bucket *cb TSRMLS_DC) { zval retval; zval *retval_ptr = &retval; @@ -234,22 +210,22 @@ int php_amqp_call_callback_with_params(PHP5to7_zval_t params, amqp_callback_buck ZVAL_NULL(&retval); /* Convert everything to be callable */ - zend_fcall_info_args(&cb->fci, PHP5to7_MAYBE_PTR(params) TSRMLS_CC); + zend_fcall_info_args(&cb->fci, ¶ms TSRMLS_CC); /* Initialize the return value pointer */ - PHP5to7_SET_FCI_RETVAL_PTR(cb->fci, retval_ptr); + cb->fci.retval = retval_ptr; zend_call_function(&cb->fci, &cb->fcc TSRMLS_CC); /* Check if user land function wants to bail */ - if (EG(exception) || PHP5to7_IS_FALSE_P(retval_ptr)) { + if (EG(exception) || Z_TYPE_P(retval_ptr) == IS_FALSE) { status = PHP_AMQP_RESOURCE_RESPONSE_BREAK; } /* Clean up our mess */ zend_fcall_info_args_clear(&cb->fci, 1); - PHP5to7_MAYBE_DESTROY(params); - PHP5to7_MAYBE_DESTROY2(retval, retval_ptr); + zval_ptr_dtor(¶ms); + zval_ptr_dtor(retval_ptr); return status; } diff --git a/amqp_methods_handling.h b/amqp_methods_handling.h index 25d1e1a0..5ebf9c8b 100644 --- a/amqp_methods_handling.h +++ b/amqp_methods_handling.h @@ -24,7 +24,11 @@ #define PHP_AMQP_METHODS_HANDLING_H #include "php_amqp.h" -#include "amqp.h" +#if HAVE_LIBRABBITMQ_NEW_LAYOUT +#include +#else +#include +#endif #include "php.h" int amqp_simple_wait_method_list_noblock(amqp_connection_state_t state, @@ -39,7 +43,7 @@ int amqp_simple_wait_method_noblock(amqp_connection_state_t state, amqp_method_t *output, struct timeval *timeout); -int php_amqp_call_callback_with_params(PHP5to7_zval_t params, amqp_callback_bucket *cb TSRMLS_DC); +int php_amqp_call_callback_with_params(zval params, amqp_callback_bucket *cb TSRMLS_DC); int php_amqp_call_basic_return_callback(amqp_basic_return_t *m, amqp_message_t *msg, amqp_callback_bucket *cb TSRMLS_DC); int php_amqp_handle_basic_return(char **message, amqp_connection_resource *resource, amqp_channel_t channel_id, amqp_channel_object *channel, amqp_method_t *method TSRMLS_DC); diff --git a/amqp_queue.c b/amqp_queue.c index 422f6f81..c3060de1 100644 --- a/amqp_queue.c +++ b/amqp_queue.c @@ -40,8 +40,13 @@ # include # include #endif +#if HAVE_LIBRABBITMQ_NEW_LAYOUT +#include +#include +#else #include #include +#endif #ifdef PHP_WIN32 # include "win32/unistd.h" @@ -65,9 +70,9 @@ AMQPQueue constructor */ static PHP_METHOD(amqp_queue_class, __construct) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; - PHP5to7_zval_t arguments PHP5to7_MAYBE_SET_TO_NULL; + zval arguments; zval *channelObj; amqp_channel_resource *channel_resource; @@ -76,16 +81,16 @@ static PHP_METHOD(amqp_queue_class, __construct) return; } - PHP5to7_MAYBE_INIT(arguments); - PHP5to7_ARRAY_INIT(arguments); - zend_update_property(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("arguments"), PHP5to7_MAYBE_PTR(arguments) TSRMLS_CC); - PHP5to7_MAYBE_DESTROY(arguments); + ZVAL_UNDEF(&arguments); + array_init(&arguments); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("arguments"), &arguments TSRMLS_CC); + zval_ptr_dtor(&arguments); channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(channelObj); PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not create queue."); - zend_update_property(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("channel"), channelObj TSRMLS_CC); - zend_update_property(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("connection"), PHP_AMQP_READ_OBJ_PROP(amqp_channel_class_entry, channelObj, "connection") TSRMLS_CC); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("channel"), channelObj TSRMLS_CC); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connection"), PHP_AMQP_READ_OBJ_PROP(amqp_channel_class_entry, channelObj, "connection") TSRMLS_CC); } /* }}} */ @@ -95,7 +100,7 @@ static PHP_METHOD(amqp_queue_class, __construct) Get the queue name */ static PHP_METHOD(amqp_queue_class, getName) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); @@ -113,7 +118,7 @@ static PHP_METHOD(amqp_queue_class, getName) Set the queue name */ static PHP_METHOD(amqp_queue_class, setName) { - char *name = NULL; PHP5to7_param_str_len_type_t name_len = 0; + char *name = NULL; size_t name_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { return; @@ -126,7 +131,7 @@ static PHP_METHOD(amqp_queue_class, setName) } /* Set the queue name */ - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("name"), name, name_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("name"), name, name_len TSRMLS_CC); /* BC */ RETURN_TRUE; @@ -139,9 +144,9 @@ static PHP_METHOD(amqp_queue_class, setName) Get the queue parameters */ static PHP_METHOD(amqp_queue_class, getFlags) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; - PHP5to7_param_long_type_t flags = 0; + zend_long flags = 0; PHP_AMQP_NOPARAMS(); @@ -170,7 +175,7 @@ static PHP_METHOD(amqp_queue_class, getFlags) Set the queue parameters */ static PHP_METHOD(amqp_queue_class, setFlags) { - PHP5to7_param_long_type_t flags; + zend_long flags; zend_bool flags_is_null = 1; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l!", &flags, &flags_is_null) == FAILURE) { @@ -180,10 +185,10 @@ static PHP_METHOD(amqp_queue_class, setFlags) /* Set the flags based on the bitmask we were given */ flags = flags ? flags & PHP_AMQP_QUEUE_FLAGS : flags; - zend_update_property_bool(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("passive"), IS_PASSIVE(flags) TSRMLS_CC); - zend_update_property_bool(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("durable"), IS_DURABLE(flags) TSRMLS_CC); - zend_update_property_bool(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("exclusive"), IS_EXCLUSIVE(flags) TSRMLS_CC); - zend_update_property_bool(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("auto_delete"), IS_AUTODELETE(flags) TSRMLS_CC); + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("passive"), IS_PASSIVE(flags) TSRMLS_CC); + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("durable"), IS_DURABLE(flags) TSRMLS_CC); + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("exclusive"), IS_EXCLUSIVE(flags) TSRMLS_CC); + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("auto_delete"), IS_AUTODELETE(flags) TSRMLS_CC); /* BC */ RETURN_TRUE; @@ -195,38 +200,37 @@ static PHP_METHOD(amqp_queue_class, setFlags) Get the queue argument referenced by key */ static PHP_METHOD(amqp_queue_class, getArgument) { - PHP5to7_READ_PROP_RV_PARAM_DECL; - - PHP5to7_zval_t *tmp = NULL; - - char *key; PHP5to7_param_str_len_type_t key_len; + zval rv; + zval *tmp = NULL; + char *key; + size_t key_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { return; } - if (!PHP5to7_ZEND_HASH_FIND(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, (unsigned)(key_len + 1), tmp)) { + if ((tmp = zend_hash_str_find(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len)) == NULL) { RETURN_FALSE; } - RETURN_ZVAL(PHP5to7_MAYBE_DEREF(tmp), 1, 0); + RETURN_ZVAL(tmp, 1, 0); } /* }}} */ /* {{{ proto AMQPQueue::hasArgument(string key) */ static PHP_METHOD(amqp_queue_class, hasArgument) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; - PHP5to7_zval_t *tmp = NULL; + zval *tmp = NULL; - char *key; PHP5to7_param_str_len_type_t key_len; + char *key; size_t key_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { return; } - if (!PHP5to7_ZEND_HASH_FIND(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, (unsigned)(key_len + 1), tmp)) { + if ((tmp = zend_hash_str_find(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len)) == NULL) { RETURN_FALSE; } @@ -239,7 +243,7 @@ static PHP_METHOD(amqp_queue_class, hasArgument) Get the queue arguments */ static PHP_METHOD(amqp_queue_class, getArguments) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("arguments"); } @@ -255,7 +259,7 @@ static PHP_METHOD(amqp_queue_class, setArguments) return; } - zend_update_property(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("arguments"), zvalArguments TSRMLS_CC); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("arguments"), zvalArguments TSRMLS_CC); RETURN_TRUE; } @@ -266,9 +270,9 @@ static PHP_METHOD(amqp_queue_class, setArguments) Get the queue name */ static PHP_METHOD(amqp_queue_class, setArgument) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; - char *key= NULL; PHP5to7_param_str_len_type_t key_len = 0; + char *key= NULL; size_t key_len = 0; zval *value = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", @@ -279,13 +283,14 @@ static PHP_METHOD(amqp_queue_class, setArgument) switch (Z_TYPE_P(value)) { case IS_NULL: - PHP5to7_ZEND_HASH_DEL(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, (unsigned) (key_len + 1)); + zend_hash_str_del_ind(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len); break; - PHP5to7_CASE_IS_BOOL: + case IS_TRUE: + case IS_FALSE: case IS_LONG: case IS_DOUBLE: case IS_STRING: - PHP5to7_ZEND_HASH_ADD(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, (unsigned) (key_len + 1), value, sizeof(zval *)); + zend_hash_str_add(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len, value); Z_TRY_ADDREF_P(value); break; default: @@ -303,13 +308,13 @@ declare queue */ static PHP_METHOD(amqp_queue_class, declareQueue) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; amqp_channel_resource *channel_resource; char *name; amqp_table_t *arguments; - PHP5to7_param_long_type_t message_count; + zend_long message_count; if (zend_parse_parameters_none() == FAILURE) { return; @@ -347,7 +352,7 @@ static PHP_METHOD(amqp_queue_class, declareQueue) /* Set the queue name, in case it is an autogenerated queue name */ name = php_amqp_type_amqp_bytes_to_char(r->queue); - zend_update_property_string(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("name"), name TSRMLS_CC); + zend_update_property_string(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("name"), name TSRMLS_CC); efree(name); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); @@ -362,14 +367,14 @@ bind queue to exchange by routing key */ static PHP_METHOD(amqp_queue_class, bind) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; zval *zvalArguments = NULL; amqp_channel_resource *channel_resource; - char *exchange_name; PHP5to7_param_str_len_type_t exchange_name_len; - char *keyname = NULL; PHP5to7_param_str_len_type_t keyname_len = 0; + char *exchange_name; size_t exchange_name_len; + char *keyname = NULL; size_t keyname_len = 0; amqp_table_t *arguments = NULL; @@ -421,14 +426,13 @@ return array (messages) */ static PHP_METHOD(amqp_queue_class, get) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; amqp_channel_resource *channel_resource; - PHP5to7_zval_t message PHP5to7_MAYBE_SET_TO_NULL; - PHP5to7_zval_t retval PHP5to7_MAYBE_SET_TO_NULL; + zval message; - PHP5to7_param_long_type_t flags = INI_INT("amqp.auto_ack") ? AMQP_AUTOACK : AMQP_NOPARAM; + zend_long flags = INI_INT("amqp.auto_ack") ? AMQP_AUTOACK : AMQP_NOPARAM; /* Parse out the method parameters */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags) == FAILURE) { @@ -486,15 +490,15 @@ static PHP_METHOD(amqp_queue_class, get) return; } - PHP5to7_MAYBE_INIT(message); + ZVAL_UNDEF(&message); - convert_amqp_envelope_to_zval(&envelope, PHP5to7_MAYBE_PTR(message) TSRMLS_CC); + convert_amqp_envelope_to_zval(&envelope, &message TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); amqp_destroy_envelope(&envelope); - RETVAL_ZVAL(PHP5to7_MAYBE_PTR(message), 1, 0); - PHP5to7_MAYBE_DESTROY(message); + RETVAL_ZVAL(&message, 1, 0); + zval_ptr_dtor(&message); } /* }}} */ @@ -504,12 +508,11 @@ consume the message */ static PHP_METHOD(amqp_queue_class, consume) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; - PHP5to7_zval_t *consumer_tag_zv = NULL; - PHP5to7_zval_t current_channel_zv PHP5to7_MAYBE_SET_TO_NULL; + zval current_channel_zv; - PHP5to7_zval_t *current_queue_zv = NULL; + zval *current_queue_zv = NULL; amqp_channel_resource *channel_resource; amqp_channel_resource *current_channel_resource; @@ -519,8 +522,8 @@ static PHP_METHOD(amqp_queue_class, consume) amqp_table_t *arguments; - char *consumer_tag = NULL; PHP5to7_param_str_len_type_t consumer_tag_len = 0; - PHP5to7_param_long_type_t flags = INI_INT("amqp.auto_ack") ? AMQP_AUTOACK : AMQP_NOPARAM; + char *consumer_tag = NULL; size_t consumer_tag_len = 0; + zend_long flags = INI_INT("amqp.auto_ack") ? AMQP_AUTOACK : AMQP_NOPARAM; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|f!ls", &fci, &fci_cache, @@ -530,7 +533,7 @@ static PHP_METHOD(amqp_queue_class, consume) } zval *channel_zv = PHP_AMQP_READ_THIS_PROP("channel"); - zval *consumers = zend_read_property(amqp_channel_class_entry, PHP5to8_OBJ_PROP(channel_zv), ZEND_STRL("consumers"), 0 PHP5to7_READ_PROP_RV_PARAM_CC TSRMLS_CC); + zval *consumers = zend_read_property(amqp_channel_class_entry, PHP_AMQP_COMPAT_OBJ_P(channel_zv), ZEND_STRL("consumers"), 0 , &rv TSRMLS_CC); if (IS_ARRAY != Z_TYPE_P(consumers)) { zend_throw_exception(amqp_queue_exception_class_entry, "Invalid channel consumers, forgot to call channel constructor?", 0 TSRMLS_CC); @@ -572,34 +575,23 @@ static PHP_METHOD(amqp_queue_class, consume) char *key; key = estrndup((char *) r->consumer_tag.bytes, (unsigned) r->consumer_tag.len); - if (PHP5to7_ZEND_HASH_FIND(Z_ARRVAL_P(consumers), (const char *) key, PHP5to7_ZEND_HASH_STRLEN(r->consumer_tag.len), consumer_tag_zv)) { + if (zend_hash_str_find(Z_ARRVAL_P(consumers), key, r->consumer_tag.len) != NULL) { // This should never happen as AMQP server guarantees that consumer tag is unique within channel zend_throw_exception(amqp_exception_class_entry, "Duplicate consumer tag", 0 TSRMLS_CC); efree(key); return; } - PHP5to7_zval_t tmp PHP5to7_MAYBE_SET_TO_NULL; + zval tmp; -#if PHP_MAJOR_VERSION >= 7 - PHP5to7_MAYBE_INIT(tmp); - ZVAL_COPY(PHP5to7_MAYBE_PTR(tmp), getThis()); -#else - tmp = getThis(); - Z_ADDREF_P(tmp); -#endif - - PHP5to7_ZEND_HASH_ADD(Z_ARRVAL_P(consumers), - (const char *) key, - PHP5to7_ZEND_HASH_STRLEN(r->consumer_tag.len), - PHP5to7_MAYBE_PTR(tmp), - sizeof(PHP5to7_MAYBE_PTR_TYPE) - ); + ZVAL_UNDEF(&tmp); + ZVAL_COPY(&tmp, getThis()); + zend_hash_str_add(Z_ARRVAL_P(consumers), key, r->consumer_tag.len, &tmp); efree(key); /* Set the consumer tag name, in case it is an autogenerated consumer tag name */ - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("consumer_tag"), (const char *) r->consumer_tag.bytes, (PHP5to7_param_str_len_type_t) r->consumer_tag.len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("consumer_tag"), (const char *) r->consumer_tag.bytes, (size_t) r->consumer_tag.len TSRMLS_CC); } if (!ZEND_FCI_INITIALIZED(fci)) { @@ -621,7 +613,7 @@ static PHP_METHOD(amqp_queue_class, consume) while(1) { /* Initialize the message */ - PHP5to7_zval_t message PHP5to7_MAYBE_SET_TO_NULL; + zval message; amqp_envelope_t envelope; @@ -660,8 +652,8 @@ static PHP_METHOD(amqp_queue_class, consume) return; } - PHP5to7_MAYBE_INIT(message); - convert_amqp_envelope_to_zval(&envelope, PHP5to7_MAYBE_PTR(message) TSRMLS_CC); + ZVAL_UNDEF(&message); + convert_amqp_envelope_to_zval(&envelope, &message TSRMLS_CC); current_channel_resource = channel_resource->connection_resource->slots[envelope.channel - 1]; @@ -672,14 +664,10 @@ static PHP_METHOD(amqp_queue_class, consume) break; } -#if PHP_MAJOR_VERSION >= 7 - PHP5to7_MAYBE_INIT(current_channel_zv); + ZVAL_UNDEF(¤t_channel_zv); ZVAL_OBJ(¤t_channel_zv, ¤t_channel_resource->parent->zo); -#else - current_channel_zv = current_channel_resource->parent->this_ptr; -#endif - consumers = zend_read_property(amqp_channel_class_entry, PHP5to8_OBJ_PROP(PHP5to7_MAYBE_PTR(current_channel_zv)), ZEND_STRL("consumers"), 0 PHP5to7_READ_PROP_RV_PARAM_CC TSRMLS_CC); + consumers = zend_read_property(amqp_channel_class_entry, PHP_AMQP_COMPAT_OBJ_P(¤t_channel_zv), ZEND_STRL("consumers"), 0 , &rv TSRMLS_CC); if (IS_ARRAY != Z_TYPE_P(consumers)) { zend_throw_exception(amqp_queue_exception_class_entry, "Invalid channel consumers, forgot to call channel constructor?", 0 TSRMLS_CC); @@ -690,16 +678,16 @@ static PHP_METHOD(amqp_queue_class, consume) char *key; key = estrndup((char *)envelope.consumer_tag.bytes, (unsigned) envelope.consumer_tag.len); - if (!PHP5to7_ZEND_HASH_FIND(Z_ARRVAL_P(consumers), key, PHP5to7_ZEND_HASH_STRLEN(envelope.consumer_tag.len), current_queue_zv)) { - PHP5to7_zval_t exception PHP5to7_MAYBE_SET_TO_NULL; - PHP5to7_MAYBE_INIT(exception); - object_init_ex(PHP5to7_MAYBE_PTR(exception), amqp_envelope_exception_class_entry); - zend_update_property_string(zend_exception_get_default(TSRMLS_C), PHP5to8_OBJ_PROP(PHP5to7_MAYBE_PTR(exception)), ZEND_STRL("message"), "Orphaned envelope" TSRMLS_CC); - zend_update_property(amqp_envelope_exception_class_entry, PHP5to8_OBJ_PROP(PHP5to7_MAYBE_PTR(exception)), ZEND_STRL("envelope"), PHP5to7_MAYBE_PTR(message) TSRMLS_CC); + if ((current_queue_zv = zend_hash_str_find(Z_ARRVAL_P(consumers), key, envelope.consumer_tag.len)) == NULL) { + zval exception; + ZVAL_UNDEF(&exception); + object_init_ex(&exception, amqp_envelope_exception_class_entry); + zend_update_property_string(zend_exception_get_default(TSRMLS_C), PHP_AMQP_COMPAT_OBJ_P(&exception), ZEND_STRL("message"), "Orphaned envelope" TSRMLS_CC); + zend_update_property(amqp_envelope_exception_class_entry, PHP_AMQP_COMPAT_OBJ_P(&exception), ZEND_STRL("envelope"), &message TSRMLS_CC); - zend_throw_exception_object(PHP5to7_MAYBE_PTR(exception) TSRMLS_CC); + zend_throw_exception_object(&exception TSRMLS_CC); - PHP5to7_MAYBE_DESTROY(message); + zval_ptr_dtor(&message); amqp_destroy_envelope(&envelope); efree(key); @@ -710,40 +698,40 @@ static PHP_METHOD(amqp_queue_class, consume) amqp_destroy_envelope(&envelope); /* Make the callback */ - PHP5to7_zval_t params PHP5to7_MAYBE_SET_TO_NULL; - PHP5to7_zval_t retval PHP5to7_MAYBE_SET_TO_NULL; + zval params; + zval retval; /* Build the parameter array */ - PHP5to7_MAYBE_INIT(params); - PHP5to7_ARRAY_INIT(params); + ZVAL_UNDEF(¶ms); + array_init(¶ms); /* Dump it into the params array */ - add_index_zval(PHP5to7_MAYBE_PTR(params), 0, PHP5to7_MAYBE_PTR(message)); - Z_ADDREF_P( PHP5to7_MAYBE_PTR(message)); + add_index_zval(¶ms, 0, &message); + Z_ADDREF_P( &message); /* Add a pointer to the queue: */ - add_index_zval(PHP5to7_MAYBE_PTR(params), 1, PHP5to7_MAYBE_DEREF(current_queue_zv)); - Z_ADDREF_P(PHP5to7_MAYBE_DEREF(current_queue_zv)); + add_index_zval(¶ms, 1, current_queue_zv); + Z_ADDREF_P(current_queue_zv); /* Convert everything to be callable */ - zend_fcall_info_args(&fci, PHP5to7_MAYBE_PTR(params) TSRMLS_CC); + zend_fcall_info_args(&fci, ¶ms TSRMLS_CC); /* Initialize the return value pointer */ - PHP5to7_SET_FCI_RETVAL_PTR(fci, PHP5to7_MAYBE_PTR(retval)); + fci.retval = &retval; /* Call the function, and track the return value */ - if (zend_call_function(&fci, &fci_cache TSRMLS_CC) == SUCCESS && PHP5to7_CHECK_FCI_RETVAL_PTR(fci)) { - RETVAL_ZVAL(PHP5to7_MAYBE_PTR(retval), 1, 1); + if (zend_call_function(&fci, &fci_cache TSRMLS_CC) == SUCCESS && fci.retval) { + RETVAL_ZVAL(&retval, 1, 1); } /* Clean up our mess */ zend_fcall_info_args_clear(&fci, 1); - PHP5to7_MAYBE_DESTROY(params); - PHP5to7_MAYBE_DESTROY(message); + zval_ptr_dtor(¶ms); + zval_ptr_dtor(&message); /* Check if user land function wants to bail */ - if (EG(exception) || PHP5to7_IS_FALSE_P(return_value)) { + if (EG(exception) || Z_TYPE_P(return_value) == IS_FALSE) { break; } } @@ -759,12 +747,12 @@ static PHP_METHOD(amqp_queue_class, consume) */ static PHP_METHOD(amqp_queue_class, ack) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; amqp_channel_resource *channel_resource; - PHP5to7_param_long_type_t deliveryTag = 0; - PHP5to7_param_long_type_t flags = AMQP_NOPARAM; + zend_long deliveryTag = 0; + zend_long flags = AMQP_NOPARAM; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &deliveryTag, &flags ) == FAILURE) { return; @@ -804,12 +792,12 @@ static PHP_METHOD(amqp_queue_class, ack) */ static PHP_METHOD(amqp_queue_class, nack) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; amqp_channel_resource *channel_resource; - PHP5to7_param_long_type_t deliveryTag = 0; - PHP5to7_param_long_type_t flags = AMQP_NOPARAM; + zend_long deliveryTag = 0; + zend_long flags = AMQP_NOPARAM; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &deliveryTag, &flags ) == FAILURE) { return; @@ -850,12 +838,12 @@ static PHP_METHOD(amqp_queue_class, nack) */ static PHP_METHOD(amqp_queue_class, reject) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; amqp_channel_resource *channel_resource; - PHP5to7_param_long_type_t deliveryTag = 0; - PHP5to7_param_long_type_t flags = AMQP_NOPARAM; + zend_long deliveryTag = 0; + zend_long flags = AMQP_NOPARAM; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &deliveryTag, &flags) == FAILURE) { return; @@ -895,7 +883,7 @@ purge queue */ static PHP_METHOD(amqp_queue_class, purge) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; amqp_channel_resource *channel_resource; @@ -939,19 +927,19 @@ cancel queue to consumer */ static PHP_METHOD(amqp_queue_class, cancel) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; amqp_channel_resource *channel_resource; - PHP5to7_zval_t *tmp = NULL; - char *consumer_tag = NULL; PHP5to7_param_str_len_type_t consumer_tag_len = 0; + char *consumer_tag = NULL; + size_t consumer_tag_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &consumer_tag, &consumer_tag_len) == FAILURE) { return; } zval *channel_zv = PHP_AMQP_READ_THIS_PROP("channel"); - zval *consumers = zend_read_property(amqp_channel_class_entry, PHP5to8_OBJ_PROP(channel_zv), ZEND_STRL("consumers"), 0 PHP5to7_READ_PROP_RV_PARAM_CC TSRMLS_CC); + zval *consumers = zend_read_property(amqp_channel_class_entry, PHP_AMQP_COMPAT_OBJ_P(channel_zv), ZEND_STRL("consumers"), 0 , &rv TSRMLS_CC); zend_bool has_consumer_tag = (zend_bool) (IS_STRING == Z_TYPE_P(PHP_AMQP_READ_THIS_PROP("consumer_tag"))); if (IS_ARRAY != Z_TYPE_P(consumers)) { @@ -983,12 +971,13 @@ static PHP_METHOD(amqp_queue_class, cancel) } if (!consumer_tag_len || (has_consumer_tag && strcmp(consumer_tag, PHP_AMQP_READ_THIS_PROP_STR("consumer_tag")) != 0)) { - zend_update_property_null(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("consumer_tag") TSRMLS_CC); + zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("consumer_tag") TSRMLS_CC); } char *key; key = estrndup((char *)r->consumer_tag.bytes, (unsigned) r->consumer_tag.len); - PHP5to7_ZEND_HASH_DEL(Z_ARRVAL_P(consumers), (const char *) key, PHP5to7_ZEND_HASH_STRLEN(r->consumer_tag.len)); + + zend_hash_str_del_ind(Z_ARRVAL_P(consumers), key, r->consumer_tag.len); efree(key); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); @@ -1003,13 +992,13 @@ unbind queue from exchange */ static PHP_METHOD(amqp_queue_class, unbind) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; zval *zvalArguments = NULL; amqp_channel_resource *channel_resource; - char *exchange_name; PHP5to7_param_str_len_type_t exchange_name_len; - char *keyname = NULL; PHP5to7_param_str_len_type_t keyname_len = 0; + char *exchange_name; size_t exchange_name_len; + char *keyname = NULL; size_t keyname_len = 0; amqp_table_t *arguments = NULL; @@ -1060,13 +1049,13 @@ delete queue and return the number of messages deleted in it */ static PHP_METHOD(amqp_queue_class, delete) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; amqp_channel_resource *channel_resource; - PHP5to7_param_long_type_t flags = AMQP_NOPARAM; + zend_long flags = AMQP_NOPARAM; - PHP5to7_param_long_type_t message_count; + zend_long message_count; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags) == FAILURE) { return; @@ -1105,7 +1094,7 @@ static PHP_METHOD(amqp_queue_class, delete) Get the AMQPChannel object in use */ static PHP_METHOD(amqp_queue_class, getChannel) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("channel"); } @@ -1115,7 +1104,7 @@ static PHP_METHOD(amqp_queue_class, getChannel) Get the AMQPConnection object in use */ static PHP_METHOD(amqp_queue_class, getConnection) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("connection"); } @@ -1125,7 +1114,7 @@ static PHP_METHOD(amqp_queue_class, getConnection) Get latest consumer tag*/ static PHP_METHOD(amqp_queue_class, getConsumerTag) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("consumer_tag"); } diff --git a/amqp_timestamp.c b/amqp_timestamp.c index ed07ab6f..079a3e01 100644 --- a/amqp_timestamp.c +++ b/amqp_timestamp.c @@ -41,7 +41,6 @@ static const double AMQP_TIMESTAMP_MIN = 0; static PHP_METHOD(amqp_timestamp_class, __construct) { double timestamp; - zval *timestamp_value; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", ×tamp) == FAILURE) { return; @@ -57,19 +56,10 @@ static PHP_METHOD(amqp_timestamp_class, __construct) return; } - { - #if PHP_MAJOR_VERSION >= 7 - zend_string *str; - str = _php_math_number_format_ex(timestamp, 0, "", 0, "", 0); - zend_update_property_str(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("timestamp"), str); - zend_string_delref(str); - #else - char *str; - str = _php_math_number_format_ex(timestamp, 0, "", 0, "", 0); - zend_update_property_string(this_ce, getThis(), ZEND_STRL("timestamp"), str TSRMLS_CC); - efree(str); - #endif - } + zend_string *str; + str = _php_math_number_format_ex(timestamp, 0, "", 0, "", 0); + zend_update_property_str(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("timestamp"), str); + zend_string_delref(str); } /* }}} */ @@ -78,7 +68,7 @@ static PHP_METHOD(amqp_timestamp_class, __construct) Get timestamp */ static PHP_METHOD(amqp_timestamp_class, getTimestamp) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("timestamp"); @@ -90,7 +80,7 @@ static PHP_METHOD(amqp_timestamp_class, getTimestamp) Return timestamp as string */ static PHP_METHOD(amqp_timestamp_class, __toString) { - PHP5to7_READ_PROP_RV_PARAM_DECL; + zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("timestamp"); @@ -128,7 +118,7 @@ PHP_MINIT_FUNCTION(amqp_timestamp) INIT_CLASS_ENTRY(ce, "AMQPTimestamp", amqp_timestamp_class_functions); this_ce = zend_register_internal_class(&ce TSRMLS_CC); - this_ce->ce_flags = this_ce->ce_flags | PHP5to7_ZEND_ACC_FINAL_CLASS; + this_ce->ce_flags = this_ce->ce_flags | ZEND_ACC_FINAL; zend_declare_property_null(this_ce, ZEND_STRL("timestamp"), ZEND_ACC_PRIVATE TSRMLS_CC); diff --git a/amqp_type.c b/amqp_type.c index 5f1ab914..53e3cd91 100644 --- a/amqp_type.c +++ b/amqp_type.c @@ -20,8 +20,16 @@ | - Jonathan Tansavatdi | +----------------------------------------------------------------------+ */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include +#if HAVE_LIBRABBITMQ_NEW_LAYOUT +#include +#else #include +#endif #include "Zend/zend_interfaces.h" #include "amqp_type.h" #include "amqp_timestamp.h" @@ -34,7 +42,7 @@ static void php_amqp_type_internal_free_amqp_array(amqp_array_t *array); static void php_amqp_type_internal_free_amqp_table(amqp_table_t *object, zend_bool clear_root); -amqp_bytes_t php_amqp_type_char_to_amqp_long(char const *cstr, PHP5to7_param_str_len_type_t len) +amqp_bytes_t php_amqp_type_char_to_amqp_long(char const *cstr, size_t len) { amqp_bytes_t result; @@ -74,28 +82,18 @@ char *php_amqp_type_amqp_bytes_to_char(amqp_bytes_t bytes) void php_amqp_type_internal_convert_zval_array(zval *php_array, amqp_field_value_t **field, zend_bool allow_int_keys TSRMLS_DC) { HashTable *ht; - HashPosition pos; - - zval *value; - zval **data; - - PHP5to7_ZEND_REAL_HASH_KEY_T *real_key; + zend_string *key; - char *key; - unsigned key_len; - - zend_ulong index; ht = Z_ARRVAL_P(php_array); zend_bool is_amqp_array = 1; - PHP5to7_ZEND_HASH_FOREACH_KEY_VAL(ht, index, real_key, key, key_len, data, value, pos) { - if (PHP5to7_ZEND_HASH_KEY_IS_STRING(ht, real_key, key, key_len, index, pos)) { + ZEND_HASH_FOREACH_STR_KEY(ht, key) { + if (key) { is_amqp_array = 0; break; } - - } PHP5to7_ZEND_HASH_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); if (is_amqp_array) { (*field)->kind = AMQP_FIELD_KIND_ARRAY; @@ -109,33 +107,23 @@ void php_amqp_type_internal_convert_zval_array(zval *php_array, amqp_field_value void php_amqp_type_internal_convert_zval_to_amqp_table(zval *php_array, amqp_table_t *amqp_table, zend_bool allow_int_keys TSRMLS_DC) { HashTable *ht; - HashPosition pos; - zval *value; - zval **data; - - PHP5to7_ZEND_REAL_HASH_KEY_T *real_key; - + zend_string *zkey; + zend_ulong index; char *key; unsigned key_len; - - zend_ulong index; - - ht = Z_ARRVAL_P(php_array); amqp_table->entries = (amqp_table_entry_t *)ecalloc((size_t)zend_hash_num_elements(ht), sizeof(amqp_table_entry_t)); amqp_table->num_entries = 0; - PHP5to7_ZEND_HASH_FOREACH_KEY_VAL(ht, index, real_key, key, key_len, data, value, pos) { + ZEND_HASH_FOREACH_KEY_VAL(ht, index, zkey, value) { char *string_key; amqp_table_entry_t *table_entry; amqp_field_value_t *field; - /* Now pull the key */ - - if (!PHP5to7_ZEND_HASH_KEY_IS_STRING(ht, real_key, key, key_len, index, pos)) { + if (!zkey) { if (allow_int_keys) { /* Convert to strings non-string keys */ char str[32]; @@ -149,7 +137,8 @@ void php_amqp_type_internal_convert_zval_to_amqp_table(zval *php_array, amqp_tab continue; } } else { - PHP5to7_ZEND_HASH_KEY_MAYBE_UNPACK(real_key, key, key_len); + key_len = ZSTR_LEN(zkey); + key = ZSTR_VAL(zkey); } /* Build the value */ @@ -166,42 +155,33 @@ void php_amqp_type_internal_convert_zval_to_amqp_table(zval *php_array, amqp_tab string_key = estrndup(key, key_len); table_entry->key = amqp_cstring_bytes(string_key); - } PHP5to7_ZEND_HASH_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } -void php_amqp_type_internal_convert_zval_to_amqp_array(zval *zvalArguments, amqp_array_t *arguments TSRMLS_DC) +void php_amqp_type_internal_convert_zval_to_amqp_array(zval *zval_arguments, amqp_array_t *arguments TSRMLS_DC) { HashTable *ht; - HashPosition pos; zval *value; - zval **data; - PHP5to7_ZEND_REAL_HASH_KEY_T *real_key; + zend_string *zkey; - char *key; - unsigned key_len; - - zend_ulong index; - - char type[16]; - - ht = Z_ARRVAL_P(zvalArguments); + ht = Z_ARRVAL_P(zval_arguments); /* Allocate all the memory necessary for storing the arguments */ arguments->entries = (amqp_field_value_t *)ecalloc((size_t)zend_hash_num_elements(ht), sizeof(amqp_field_value_t)); arguments->num_entries = 0; - PHP5to7_ZEND_HASH_FOREACH_KEY_VAL(ht, index, real_key, key, key_len, data, value, pos) { + ZEND_HASH_FOREACH_STR_KEY_VAL(ht, zkey, value) { amqp_field_value_t *field = &arguments->entries[arguments->num_entries++]; - if (!php_amqp_type_internal_convert_php_to_amqp_field_value(value, &field, key TSRMLS_CC)) { + if (!php_amqp_type_internal_convert_php_to_amqp_field_value(value, &field, ZSTR_VAL(zkey) TSRMLS_CC)) { /* Reset entries counter back */ arguments->num_entries --; continue; } - } PHP5to7_ZEND_HASH_FOREACH_END(); + } ZEND_HASH_FOREACH_END(); } zend_bool php_amqp_type_internal_convert_php_to_amqp_field_value(zval *value, amqp_field_value_t **fieldPtr, char *key TSRMLS_DC) @@ -214,9 +194,10 @@ zend_bool php_amqp_type_internal_convert_php_to_amqp_field_value(zval *value, am field = *fieldPtr; switch (Z_TYPE_P(value)) { - PHP5to7_CASE_IS_BOOL: + case IS_TRUE: + case IS_FALSE: field->kind = AMQP_FIELD_KIND_BOOLEAN; - field->value.boolean = (amqp_boolean_t) !PHP5to7_IS_FALSE_P(value); + field->value.boolean = (amqp_boolean_t) Z_TYPE_P(value) != IS_FALSE; break; case IS_DOUBLE: field->kind = AMQP_FIELD_KIND_F64; @@ -248,28 +229,27 @@ zend_bool php_amqp_type_internal_convert_php_to_amqp_field_value(zval *value, am break; case IS_OBJECT: if (instanceof_function(Z_OBJCE_P(value), amqp_timestamp_class_entry TSRMLS_CC)) { - PHP5to7_zval_t result_zv PHP5to7_MAYBE_SET_TO_NULL; + zval result_zv; - zend_call_method_with_0_params(PHP5to8_OBJ_PROP(PHP5to7_MAYBE_PARAM_PTR(value)), amqp_timestamp_class_entry, NULL, "gettimestamp", &result_zv); + zend_call_method_with_0_params(PHP_AMQP_COMPAT_OBJ_P(value), amqp_timestamp_class_entry, NULL, "gettimestamp", &result_zv); field->kind = AMQP_FIELD_KIND_TIMESTAMP; - field->value.u64 = strtoimax(Z_STRVAL(PHP5to7_MAYBE_DEREF(result_zv)), NULL, 10); + field->value.u64 = strtoimax(Z_STRVAL(result_zv), NULL, 10); - PHP5to7_MAYBE_DESTROY(result_zv); + zval_ptr_dtor(&result_zv); break; } else if (instanceof_function(Z_OBJCE_P(value), amqp_decimal_class_entry TSRMLS_CC)) { field->kind = AMQP_FIELD_KIND_DECIMAL; - PHP5to7_zval_t result_zv PHP5to7_MAYBE_SET_TO_NULL; - - zend_call_method_with_0_params(PHP5to8_OBJ_PROP(PHP5to7_MAYBE_PARAM_PTR(value)), amqp_decimal_class_entry, NULL, "getexponent", &result_zv); - field->value.decimal.decimals = (uint8_t)Z_LVAL(PHP5to7_MAYBE_DEREF(result_zv)); - PHP5to7_MAYBE_DESTROY(result_zv); + zval result_zv; - zend_call_method_with_0_params(PHP5to8_OBJ_PROP(PHP5to7_MAYBE_PARAM_PTR(value)), amqp_decimal_class_entry, NULL, "getsignificand", &result_zv); - field->value.decimal.value = (uint32_t)Z_LVAL(PHP5to7_MAYBE_DEREF(result_zv)); + zend_call_method_with_0_params(PHP_AMQP_COMPAT_OBJ_P(value), amqp_decimal_class_entry, NULL, "getexponent", &result_zv); + field->value.decimal.decimals = (uint8_t)Z_LVAL(result_zv); + zval_ptr_dtor(&result_zv); - PHP5to7_MAYBE_DESTROY(result_zv); + zend_call_method_with_0_params(PHP_AMQP_COMPAT_OBJ_P(value), amqp_decimal_class_entry, NULL, "getsignificand", &result_zv); + field->value.decimal.value = (uint32_t)Z_LVAL(result_zv); + zval_ptr_dtor(&result_zv); break; } diff --git a/amqp_type.h b/amqp_type.h index 90787770..c7715c6d 100644 --- a/amqp_type.h +++ b/amqp_type.h @@ -26,17 +26,17 @@ #include "php.h" -#include -#if PHP_MAJOR_VERSION >= 7 - #include "php7_support.h" +#if AMQP_VERSION_MINOR >= 13 +#include #else - #include "php5_support.h" +#include #endif +#include "php_amqp.h" PHP_MINIT_FUNCTION(amqp_type); char *php_amqp_type_amqp_bytes_to_char(amqp_bytes_t bytes); -amqp_bytes_t php_amqp_type_char_to_amqp_long(char const *cstr, PHP5to7_param_str_len_type_t len); +amqp_bytes_t php_amqp_type_char_to_amqp_long(char const *cstr, size_t len); amqp_table_t *php_amqp_type_convert_zval_to_amqp_table(zval *php_array TSRMLS_DC); void php_amqp_type_free_amqp_table(amqp_table_t *object); diff --git a/config.m4 b/config.m4 index 43877c87..cdbba9cf 100644 --- a/config.m4 +++ b/config.m4 @@ -31,9 +31,12 @@ if test "$PHP_AMQP" != "no"; then dnl # --with-amqp -> check with-path - SEARCH_FOR="amqp_framing.h" + NEW_LAYOUT=rabbitmq-c/framing.h + OLD_LAYOUT=amqp_framing.h AC_PATH_PROG(PKG_CONFIG, pkg-config, no) + HAVE_LIBRABBITMQ_NEW_LAYOUT=0 + if test "$PHP_LIBRABBITMQ_DIR" = "yes" -a -x $PKG_CONFIG; then AC_MSG_CHECKING([for amqp using pkg-config]) @@ -44,8 +47,12 @@ if test "$PHP_AMQP" != "no"; then PHP_AMQP_VERSION=`$PKG_CONFIG librabbitmq --modversion` AC_MSG_RESULT([found version $PHP_AMQP_VERSION]) - if ! $PKG_CONFIG librabbitmq --atleast-version 0.7.1 ; then - AC_MSG_ERROR([librabbitmq must be version 0.7.1 or greater]) + if ! $PKG_CONFIG librabbitmq --atleast-version 0.10.0 ; then + AC_MSG_ERROR([librabbitmq must be version 0.10.0 or greater]) + fi + + if test -r `$PKG_CONFIG librabbitmq --variable=includedir`/$NEW_LAYOUT; then + HAVE_LIBRABBITMQ_NEW_LAYOUT=1 fi PHP_AMQP_LIBS=`$PKG_CONFIG librabbitmq --libs` @@ -58,8 +65,13 @@ if test "$PHP_AMQP" != "no"; then AC_MSG_CHECKING([for amqp files in default path]) if test "$PHP_LIBRABBITMQ_DIR" != "no" && test "$PHP_LIBRABBITMQ_DIR" != "yes"; then for i in $PHP_LIBRABBITMQ_DIR; do - if test -r $i/include/$SEARCH_FOR; - then + if test -r $i/include/$NEW_LAYOUT; then + AMQP_DIR=$i + HAVE_LIBRABBITMQ_NEW_LAYOUT=1 + AC_MSG_RESULT(found in $i) + break + fi + if test -r $i/include/$OLD_LAYOUT; then AMQP_DIR=$i AC_MSG_RESULT(found in $i) break @@ -67,8 +79,13 @@ if test "$PHP_AMQP" != "no"; then done else for i in $PHP_AMQP /usr/local /usr ; do - if test -r $i/include/$SEARCH_FOR; - then + if test -r $i/include/$NEW_LAYOUT; then + AMQP_DIR=$i + HAVE_LIBRABBITMQ_NEW_LAYOUT=1 + AC_MSG_RESULT(found in $i) + break + fi + if test -r $i/include/$OLD_LAYOUT; then AMQP_DIR=$i AC_MSG_RESULT(found in $i) break @@ -134,6 +151,11 @@ if test "$PHP_AMQP" != "no"; then PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $AMQP_DIR/$PHP_LIBDIR, AMQP_SHARED_LIBADD) fi + + AC_MSG_CHECKING([for new librabbitmq layout]) + AC_MSG_RESULT([${HAVE_LIBRABBITMQ_NEW_LAYOUT}]) + AC_DEFINE_UNQUOTED(HAVE_LIBRABBITMQ_NEW_LAYOUT, ${HAVE_LIBRABBITMQ_NEW_LAYOUT}, ["Librabbitmq new layout"]) + PHP_SUBST(AMQP_SHARED_LIBADD) AMQP_SOURCES="amqp.c amqp_type.c amqp_exchange.c amqp_queue.c amqp_connection.c amqp_connection_resource.c amqp_channel.c amqp_envelope.c amqp_basic_properties.c amqp_methods_handling.c amqp_timestamp.c amqp_decimal.c" diff --git a/package.xml b/package.xml index dbd72198..6b130eec 100644 --- a/package.xml +++ b/package.xml @@ -69,8 +69,6 @@ https://github.com/php-amqp/php-amqp/compare/v1.11.0...master - - @@ -269,7 +267,7 @@ https://github.com/php-amqp/php-amqp/compare/v1.11.0...master - 5.6.0 + 7.4.0 1.4.0 diff --git a/php5_support.h b/php5_support.h deleted file mode 100644 index 25c2d963..00000000 --- a/php5_support.h +++ /dev/null @@ -1,123 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Alexandre Kalendarev akalend@mail.ru Copyright (c) 2009-2010 | - | Lead: | - | - Pieter de Zwart | - | Maintainers: | - | - Brad Rodriguez | - | - Jonathan Tansavatdi | - +----------------------------------------------------------------------+ -*/ - -#ifndef PHP_AMQP_PHP5_SUPPORT_H -#define PHP_AMQP_PHP5_SUPPORT_H - -typedef int PHP5to7_param_str_len_type_t; -typedef long PHP5to7_param_long_type_t; -typedef zval* PHP5to7_zval_t; - -#define PHP5to7_MAYBE_SET_TO_NULL = NULL - -#define PHP5to7_MAYBE_DEREF(zv) (*(zv)) -#define PHP5to7_MAYBE_PTR(zv) (zv) -#define PHP5to7_MAYBE_PTR_TYPE PHP5to7_zval_t -#define PHP5to7_MAYBE_PARAM_PTR(zv) (&(zv)) - -#define PHP5to7_MAYBE_INIT(zv) MAKE_STD_ZVAL(zv); -#define PHP5to7_ARRAY_INIT(zv) array_init(zv); -#define PHP5to7_MAYBE_DESTROY(zv) zval_ptr_dtor(&(zv)); -#define PHP5to7_MAYBE_DESTROY2(zv, pzv) zval_ptr_dtor(&pzv); - -#define PHP5to7_ZVAL_STRINGL_DUP(z, s, l) ZVAL_STRINGL((z), (s), (l), 1) - -#define PHP5to7_ADD_NEXT_INDEX_STRINGL_DUP(arg, str, length) add_next_index_stringl((arg), (str), (unsigned)(length), 1) - -#define PHP5to7_ZEND_HASH_FIND(ht, str, len, res) \ - (zend_hash_find((ht), (str), (unsigned)(len), (void **) &(res)) != FAILURE) - -#define PHP5to7_ZEND_HASH_STRLEN(len) (unsigned)((len) + 1) -#define PHP5to7_ZEND_HASH_DEL(ht, key, len) zend_hash_del_key_or_index((ht), (key), (unsigned)(len), 0, HASH_DEL_KEY); -#define PHP5to7_ZEND_HASH_ADD(ht, key, len, pData, nDataSize) (zend_hash_add((ht), (key), (unsigned)(len), &(pData), nDataSize, NULL) != FAILURE) -#define PHP5to7_ZEND_HASH_STR_UPD_MEM(ht, key, len, pData, nDataSize) PHP5to7_ZEND_HASH_ADD((ht), (key), (len), (pData), (nDataSize)) -#define PHP5to7_ZEND_HASH_STR_FIND_PTR(ht, key, len, res) PHP5to7_ZEND_HASH_FIND((ht), (key), (len), (res)) -#define PHP5to7_ZEND_HASH_STR_DEL(ht, key, len) PHP5to7_ZEND_HASH_DEL((ht), (key), (len)) - -#define PHP5to7_SET_FCI_RETVAL_PTR(fci, pzv) (fci).retval_ptr_ptr = &(pzv); -#define PHP5to7_CHECK_FCI_RETVAL_PTR(fci) ((fci).retval_ptr_ptr && *(fci).retval_ptr_ptr) - -#define PHP5to7_IS_FALSE_P(pzv) ((Z_TYPE_P(pzv) == IS_BOOL && !Z_BVAL_P(pzv))) - -#define PHP5to7_obj_free_zend_object void -#define PHP5to7_zend_object_value zend_object_value -#define PHP5to7_zend_register_internal_class_ex(ce, parent_ce) zend_register_internal_class_ex((ce), (parent_ce), NULL TSRMLS_CC) - -#define PHP5to7_ECALLOC_CONNECTION_OBJECT(ce) (amqp_connection_object*)ecalloc(1, sizeof(amqp_connection_object)) -#define PHP5to7_ECALLOC_CHANNEL_OBJECT(ce) (amqp_channel_object*)ecalloc(1, sizeof(amqp_channel_object)) - -#define PHP5to7_CASE_IS_BOOL case IS_BOOL - -#define PHP5to7_READ_PROP_RV_PARAM_DECL -#define PHP5to7_READ_PROP_RV_PARAM_CC - - -#define PHP5to7_ZEND_REAL_HASH_KEY_T void - -#define PHP5to7_ZEND_HASH_FOREACH_KEY_VAL(ht, num_key, real_key, key, key_len, data, val, pos) \ - for ( \ - zend_hash_internal_pointer_reset_ex((ht), &(pos)); \ - zend_hash_get_current_data_ex((ht), (void**) &(data), &(pos)) == SUCCESS && ((value) = *(data)); \ - zend_hash_move_forward_ex((ht), &(pos)) \ - ) - -#define PHP5to7_ZEND_HASH_KEY_IS_STRING(ht, real_key, key, key_len, num_key, pos) \ - (zend_hash_get_current_key_ex((ht), &(key), &(key_len), &(num_key), 0, &(pos)) == HASH_KEY_IS_STRING) - -#define PHP5to7_ZEND_HASH_KEY_MAYBE_UNPACK(real_key, key, key_len) - -#define PHP5to7_ZEND_HASH_FOREACH_END() - -#define Z_TRY_ADDREF_P(pz) Z_ADDREF_P(pz) - -/* Resources stuff */ - -typedef int PHP5to7_zend_resource_t; -typedef zend_rsrc_list_entry PHP5to7_zend_resource_store_t; -typedef zend_rsrc_list_entry PHP5to7_zend_resource_le_t; - -#define PHP5to7_ZEND_RESOURCE_DTOR_ARG rsrc -#define Z_RES_P(le) (le) - -#define PHP5to7_ZEND_RESOURCE_EMPTY 0 -#define PHP5to7_ZEND_RESOURCE_LE_EMPTY NULL -#define PHP5to7_ZEND_RSRC_TYPE_P(le) Z_TYPE_P(le) -#define PHP5to7_ZEND_REGISTER_RESOURCE(rsrc_pointer, rsrc_type) ZEND_REGISTER_RESOURCE(NULL, (rsrc_pointer), (rsrc_type)) - -#define PHP5to7_PARENT_CLASS_NAME_C(name) , (name) - -#define ZEND_ULONG_FMT "%" PRIu64 -#define PHP5to7_ZEND_ACC_FINAL_CLASS ZEND_ACC_FINAL_CLASS - -#define PHP5to8_OBJ_PROP(zv) (zv) - -#endif //PHP_AMQP_PHP5_SUPPORT_H - -/* -*Local variables: -*tab-width: 4 -*c-basic-offset: 4 -*End: -*vim600: noet sw=4 ts=4 fdm=marker -*vim<600: noet sw=4 ts=4 -*/ diff --git a/php7_support.h b/php7_support.h deleted file mode 100644 index 0dbd6b22..00000000 --- a/php7_support.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2007 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Alexandre Kalendarev akalend@mail.ru Copyright (c) 2009-2010 | - | Lead: | - | - Pieter de Zwart | - | Maintainers: | - | - Brad Rodriguez | - | - Jonathan Tansavatdi | - +----------------------------------------------------------------------+ -*/ - -#ifndef PHP_AMQP_PHP7_SUPPORT_H -#define PHP_AMQP_PHP7_SUPPORT_H - -typedef size_t PHP5to7_param_str_len_type_t; -typedef zend_long PHP5to7_param_long_type_t; -typedef zval PHP5to7_zval_t; - -#define PHP5to7_MAYBE_SET_TO_NULL - -#define PHP5to7_MAYBE_DEREF(zv) (zv) -#define PHP5to7_MAYBE_PTR(zv) (&(zv)) -#define PHP5to7_MAYBE_PTR_TYPE PHP5to7_zval_t * -#define PHP5to7_MAYBE_PARAM_PTR(zv) (zv) - -#define PHP5to7_MAYBE_INIT(zv) ZVAL_UNDEF(&(zv)) -#define PHP5to7_ARRAY_INIT(zv) array_init(&(zv)); -#define PHP5to7_MAYBE_DESTROY(zv) if (!Z_ISUNDEF(zv)) { zval_ptr_dtor(&(zv)); } -#define PHP5to7_MAYBE_DESTROY2(zv, pzv) if (!Z_ISUNDEF(zv)) { zval_ptr_dtor(pzv); } - -#define PHP5to7_ZVAL_STRINGL_DUP(z, s, l) ZVAL_STRINGL((z), (s), (l)) -#define PHP5to7_ADD_NEXT_INDEX_STRINGL_DUP(arg, str, length) add_next_index_stringl((arg), (str), (size_t)(length)) - -#define PHP5to7_ZEND_HASH_FIND(ht, str, len, res) \ - ((res = zend_hash_str_find((ht), (str), (size_t)(len - 1))) != NULL) - -#define PHP5to7_ZEND_HASH_STRLEN(len) (PHP5to7_param_str_len_type_t)((len) + 1) -#define PHP5to7_ZEND_HASH_DEL(ht, key, len) zend_hash_str_del_ind((ht), (key), (unsigned)(len - 1)) -#define PHP5to7_ZEND_HASH_ADD(ht, key, len, pData, nDataSize) zend_hash_str_add((ht), (key), (unsigned)(len - 1), (pData)) -#define PHP5to7_ZEND_HASH_STR_UPD_MEM(ht, key, len, pData, nDataSize) zend_hash_str_update_mem((ht), (key), (size_t)(len), &(pData), (nDataSize)) -#define PHP5to7_ZEND_HASH_STR_FIND_PTR(ht, key, len, res) ((res = zend_hash_str_find_ptr((ht), (key), (size_t)(len))) != NULL) -#define PHP5to7_ZEND_HASH_STR_DEL(ht, key, len) zend_hash_str_del_ind((ht), (key), (unsigned)(len)) - -#define PHP5to7_SET_FCI_RETVAL_PTR(fci, pzv) (fci).retval = (pzv); -#define PHP5to7_CHECK_FCI_RETVAL_PTR(fci) ((fci).retval) - -#define PHP5to7_IS_FALSE_P(pzv) (Z_TYPE_P(pzv) == IS_FALSE) - -#define PHP5to7_obj_free_zend_object zend_object -#define PHP5to7_zend_object_value zend_object * -#define PHP5to7_zend_register_internal_class_ex(ce, parent_ce) zend_register_internal_class_ex((ce), (parent_ce) TSRMLS_CC) - -#define PHP5to7_ECALLOC_CONNECTION_OBJECT(ce) (amqp_connection_object*)ecalloc(1, sizeof(amqp_connection_object) + zend_object_properties_size(ce)) -#define PHP5to7_ECALLOC_CHANNEL_OBJECT(ce) (amqp_channel_object*)ecalloc(1, sizeof(amqp_channel_object) + zend_object_properties_size(ce)) - -#define PHP5to7_CASE_IS_BOOL case IS_TRUE: case IS_FALSE - -#define PHP5to7_READ_PROP_RV_PARAM_DECL zval rv; -#define PHP5to7_READ_PROP_RV_PARAM_CC , (&rv) - -#define Z_BVAL_P(zval_p) (Z_TYPE_P(zval_p) == IS_TRUE) - -#define PHP5to7_ZEND_REAL_HASH_KEY_T zend_string - -#define PHP5to7_ZEND_HASH_FOREACH_KEY_VAL(ht, num_key, real_key, key, key_len, data, val, pos) \ - ZEND_HASH_FOREACH_KEY_VAL((ht), (num_key), (real_key), (val)) - -#define PHP5to7_ZEND_HASH_KEY_IS_STRING(ht, real_key, key, key_len, num_key, pos) \ - (real_key) - -#define PHP5to7_ZEND_HASH_KEY_MAYBE_UNPACK(real_key, key, key_len) \ - (key_len) = ZSTR_LEN(real_key); \ - (key) = ZSTR_VAL(real_key); - -#define PHP5to7_ZEND_HASH_FOREACH_END() ZEND_HASH_FOREACH_END(); - -/* Resources stuff */ -typedef zend_resource* PHP5to7_zend_resource_t; -typedef zend_resource PHP5to7_zend_resource_store_t; -typedef zval PHP5to7_zend_resource_le_t; - -#define PHP5to7_ZEND_RESOURCE_DTOR_ARG res -#define PHP5to7_ZEND_RESOURCE_EMPTY NULL -#define PHP5to7_ZEND_RESOURCE_LE_EMPTY NULL -#define PHP5to7_ZEND_RSRC_TYPE_P(le) (le)->type -#define PHP5to7_ZEND_REGISTER_RESOURCE(rsrc_pointer, rsrc_type) zend_register_resource((rsrc_pointer), (rsrc_type)) - -#define PHP5to7_PARENT_CLASS_NAME_C(name) - -#define PHP5to7_ZEND_ACC_FINAL_CLASS ZEND_ACC_FINAL - - -/* Small change to let it build after a major internal change for php8.0 - * More info: - * https://github.com/php/php-src/blob/php-8.0.0alpha3/UPGRADING.INTERNALS#L47 - */ -#if PHP_MAJOR_VERSION >= 8 - -# define TSRMLS_DC -# define TSRMLS_D -# define TSRMLS_CC -# define TSRMLS_C - -#define PHP5to8_OBJ_PROP(zv) Z_OBJ_P(zv) - -#else - -#define PHP5to8_OBJ_PROP(zv) (zv) - -# endif - -#endif //PHP_AMQP_PHP7_SUPPORT_H - -/* -*Local variables: -*tab-width: 4 -*c-basic-offset: 4 -*End: -*vim600: noet sw=4 ts=4 fdm=marker -*vim<600: noet sw=4 ts=4 -*/ diff --git a/php_amqp.h b/php_amqp.h index 78db65d3..9697e034 100644 --- a/php_amqp.h +++ b/php_amqp.h @@ -23,6 +23,10 @@ #ifndef PHP_AMQP_H #define PHP_AMQP_H +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + /* True global resources - no need for thread safety here */ extern zend_class_entry *amqp_exception_class_entry, *amqp_connection_exception_class_entry, @@ -45,15 +49,11 @@ typedef struct _amqp_callback_bucket amqp_callback_bucket; #error PHP >= 5.6 required #endif -#if PHP_MAJOR_VERSION >= 7 - #include "php7_support.h" +#if HAVE_LIBRABBITMQ_NEW_LAYOUT +#include #else - #include "php5_support.h" -#endif - -#include "amqp_connection_resource.h" - #include +#endif extern zend_module_entry amqp_module_entry; #define phpext_amqp_ptr &amqp_module_entry @@ -68,6 +68,22 @@ extern zend_module_entry amqp_module_entry; #include "TSRM.h" #endif +/* Small change to let it build after a major internal change for php8.0 + * More info: + * https://github.com/php/php-src/blob/php-8.0.0alpha3/UPGRADING.INTERNALS#L47 + */ +#if PHP_MAJOR_VERSION >= 8 +#define TSRMLS_DC +#define TSRMLS_D +#define TSRMLS_CC +#define TSRMLS_C +#define PHP_AMQP_COMPAT_OBJ_P(zv) Z_OBJ_P(zv) +#else +#define PHP_AMQP_COMPAT_OBJ_P(zv) (zv) +#endif + +#include "amqp_connection_resource.h" + #define AMQP_NOPARAM 0 /* Where is 1?*/ #define AMQP_JUST_CONSUME 1 @@ -121,27 +137,18 @@ struct _amqp_channel_callbacks { /* NOTE: due to how internally PHP works with custom object, zend_object position in structure matters */ struct _amqp_channel_object { -#if PHP_MAJOR_VERSION >= 7 amqp_channel_callbacks callbacks; zval *gc_data; int gc_data_count; amqp_channel_resource *channel_resource; zend_object zo; -#else - zend_object zo; - zval *this_ptr; - amqp_channel_resource *channel_resource; - amqp_channel_callbacks callbacks; - zval **gc_data; - long gc_data_count; -#endif }; struct _amqp_connection_resource { zend_bool is_connected; zend_bool is_persistent; zend_bool is_dirty; - PHP5to7_zend_resource_t resource; + zend_resource *resource; amqp_connection_object *parent; amqp_channel_t max_slots; amqp_channel_t used_slots; @@ -151,13 +158,8 @@ struct _amqp_connection_resource { }; struct _amqp_connection_object { -#if PHP_MAJOR_VERSION >= 7 amqp_connection_resource *connection_resource; zend_object zo; -#else - zend_object zo; - amqp_connection_resource *connection_resource; -#endif }; #define DEFAULT_PORT "5672" /* default AMQP port */ @@ -221,15 +223,15 @@ struct _amqp_connection_object { #define PHP_AMQP_NOPARAMS() if (zend_parse_parameters_none() == FAILURE) { return; } #define PHP_AMQP_RETURN_THIS_PROP(prop_name) \ - zval * _zv = zend_read_property(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL(prop_name), 0 PHP5to7_READ_PROP_RV_PARAM_CC TSRMLS_CC); \ + zval * _zv = zend_read_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(prop_name), 0 , &rv TSRMLS_CC); \ RETURN_ZVAL(_zv, 1, 0); -#define PHP_AMQP_READ_OBJ_PROP(cls, obj, name) zend_read_property((cls), PHP5to8_OBJ_PROP(obj), ZEND_STRL(name), 0 PHP5to7_READ_PROP_RV_PARAM_CC TSRMLS_CC) +#define PHP_AMQP_READ_OBJ_PROP(cls, obj, name) zend_read_property((cls), PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL(name), 0 , &rv TSRMLS_CC) #define PHP_AMQP_READ_OBJ_PROP_DOUBLE(cls, obj, name) Z_DVAL_P(PHP_AMQP_READ_OBJ_PROP((cls), (obj), (name))) -#define PHP_AMQP_READ_THIS_PROP_CE(name, ce) zend_read_property((ce), PHP5to8_OBJ_PROP(getThis()), ZEND_STRL(name), 0 PHP5to7_READ_PROP_RV_PARAM_CC TSRMLS_CC) -#define PHP_AMQP_READ_THIS_PROP(name) zend_read_property(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL(name), 0 PHP5to7_READ_PROP_RV_PARAM_CC TSRMLS_CC) -#define PHP_AMQP_READ_THIS_PROP_BOOL(name) Z_BVAL_P(PHP_AMQP_READ_THIS_PROP(name)) +#define PHP_AMQP_READ_THIS_PROP_CE(name, ce) zend_read_property((ce), PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(name), 0 , &rv TSRMLS_CC) +#define PHP_AMQP_READ_THIS_PROP(name) zend_read_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(name), 0 , &rv TSRMLS_CC) +#define PHP_AMQP_READ_THIS_PROP_BOOL(name) Z_TYPE_P(PHP_AMQP_READ_THIS_PROP(name)) == IS_TRUE #define PHP_AMQP_READ_THIS_PROP_STR(name) Z_STRVAL_P(PHP_AMQP_READ_THIS_PROP(name)) #define PHP_AMQP_READ_THIS_PROP_STRLEN(name) (Z_TYPE_P(PHP_AMQP_READ_THIS_PROP(name)) == IS_STRING ? Z_STRLEN_P(PHP_AMQP_READ_THIS_PROP(name)) : 0) #define PHP_AMQP_READ_THIS_PROP_ARR(name) Z_ARRVAL_P(PHP_AMQP_READ_THIS_PROP(name)) @@ -237,29 +239,19 @@ struct _amqp_connection_object { #define PHP_AMQP_READ_THIS_PROP_DOUBLE(name) Z_DVAL_P(PHP_AMQP_READ_THIS_PROP(name)) -#if PHP_MAJOR_VERSION >= 7 - static inline amqp_connection_object *php_amqp_connection_object_fetch(zend_object *obj) { - return (amqp_connection_object *)((char *)obj - XtOffsetOf(amqp_connection_object, zo)); - } - - static inline amqp_channel_object *php_amqp_channel_object_fetch(zend_object *obj) { - return (amqp_channel_object *)((char *)obj - XtOffsetOf(amqp_channel_object, zo)); - } - - #define PHP_AMQP_GET_CONNECTION(obj) php_amqp_connection_object_fetch(Z_OBJ_P(obj)) - #define PHP_AMQP_GET_CHANNEL(obj) php_amqp_channel_object_fetch(Z_OBJ_P(obj)) +static inline amqp_connection_object *php_amqp_connection_object_fetch(zend_object *obj) { + return (amqp_connection_object *)((char *)obj - XtOffsetOf(amqp_connection_object, zo)); +} - #define PHP_AMQP_FETCH_CONNECTION(obj) php_amqp_connection_object_fetch(obj) - #define PHP_AMQP_FETCH_CHANNEL(obj) php_amqp_channel_object_fetch(obj) +static inline amqp_channel_object *php_amqp_channel_object_fetch(zend_object *obj) { + return (amqp_channel_object *)((char *)obj - XtOffsetOf(amqp_channel_object, zo)); +} -#else - #define PHP_AMQP_GET_CONNECTION(obj) (amqp_connection_object *)zend_object_store_get_object((obj) TSRMLS_CC) - #define PHP_AMQP_GET_CHANNEL(obj) (amqp_channel_object *)zend_object_store_get_object((obj) TSRMLS_CC) - - #define PHP_AMQP_FETCH_CONNECTION(obj) (amqp_connection_object*)(obj) - #define PHP_AMQP_FETCH_CHANNEL(obj) (amqp_channel_object*)(obj) -#endif +#define PHP_AMQP_GET_CONNECTION(obj) php_amqp_connection_object_fetch(Z_OBJ_P(obj)) +#define PHP_AMQP_GET_CHANNEL(obj) php_amqp_channel_object_fetch(Z_OBJ_P(obj)) +#define PHP_AMQP_FETCH_CONNECTION(obj) php_amqp_connection_object_fetch(obj) +#define PHP_AMQP_FETCH_CHANNEL(obj) php_amqp_channel_object_fetch(obj) #define PHP_AMQP_GET_CHANNEL_RESOURCE(obj) (IS_OBJECT == Z_TYPE_P(obj) ? (PHP_AMQP_GET_CHANNEL(obj))->channel_resource : NULL) @@ -348,10 +340,10 @@ struct _amqp_connection_object { ZEND_BEGIN_MODULE_GLOBALS(amqp) char *error_message; - PHP5to7_param_long_type_t error_code; + zend_long error_code; ZEND_END_MODULE_GLOBALS(amqp) -ZEND_EXTERN_MODULE_GLOBALS(amqp); +ZEND_EXTERN_MODULE_GLOBALS(amqp) #ifdef ZEND_MODULE_GLOBALS_ACCESSOR #define PHP_AMQP_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(amqp, v) @@ -381,7 +373,7 @@ int php_amqp_error_advanced(amqp_rpc_reply_t reply, char **message, amqp_connect /** * @deprecated */ -void php_amqp_zend_throw_exception(amqp_rpc_reply_t reply, zend_class_entry *exception_ce, const char *message, PHP5to7_param_long_type_t code TSRMLS_DC); +void php_amqp_zend_throw_exception(amqp_rpc_reply_t reply, zend_class_entry *exception_ce, const char *message, zend_long code TSRMLS_DC); void php_amqp_zend_throw_exception_short(amqp_rpc_reply_t reply, zend_class_entry *exception_ce TSRMLS_DC); void php_amqp_maybe_release_buffers_on_channel(amqp_connection_resource *connection_resource, amqp_channel_resource *channel_resource); From 62b09cefe594b1ef3c05d261b29fef5277d1442b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 25 Jul 2023 20:45:34 +0200 Subject: [PATCH 007/147] Bump shivammathur/setup-php from 2.25.3 to 2.25.4 (#431) --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c36b2622..f4e486d8 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -127,7 +127,7 @@ jobs: run: sudo apt-get install -y cmake valgrind - name: Setup PHP - uses: shivammathur/setup-php@2.25.3 + uses: shivammathur/setup-php@2.25.4 with: php-version: ${{ matrix.php-version }} coverage: none From 7dc06468c7cfcc1e04d78a56d706afa9ef95699f Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Tue, 25 Jul 2023 22:08:29 +0200 Subject: [PATCH 008/147] Update branch name --- README.md | 20 ++++++++++---------- package.xml | 2 +- tools/functions.php | 4 ++-- tools/make-dev.php | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 76b1f12f..5c45560f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# PHP AMQP bindings [![Build Status](https://travis-ci.org/php-amqp/php-amqp.svg?branch=master)](https://travis-ci.org/php-amqp/php-amqp) [![Build status](https://ci.appveyor.com/api/projects/status/sv5o1id5oj63w9hu/branch/master?svg=true)](https://ci.appveyor.com/project/lstrojny/php-amqp-7lf47/branch/master) +# PHP AMQP bindings [![Test](https://github.com/php-amqp/php-amqp/actions/workflows/test.yaml/badge.svg)](https://github.com/php-amqp/php-amqp/actions/workflows/test.yaml) [![Build status](https://ci.appveyor.com/api/projects/status/sv5o1id5oj63w9hu/branch/latest?svg=true)](https://ci.appveyor.com/project/lstrojny/php-amqp-7lf47/branch/latest) Object-oriented PHP bindings for the AMQP C library (https://github.com/alanxz/rabbitmq-c) @@ -37,12 +37,12 @@ Object-oriented PHP bindings for the AMQP C library (https://github.com/alanxz/r ### Documentation View [RabbitMQ official tutorials](http://www.rabbitmq.com/getstarted.html) -and [php-amqp specific examples](https://github.com/rabbitmq/rabbitmq-tutorials/tree/master/php-amqp). +and [php-amqp specific examples](https://github.com/rabbitmq/rabbitmq-tutorials/tree/main/php-amqp). -There are also available [stub files](https://github.com/php-amqp/php-amqp/tree/master/stubs) with accurate PHPDoc which +There are also available [stub files](https://github.com/php-amqp/php-amqp/tree/latest/stubs) with accurate PHPDoc which may be also used in your IDE for code completion, navigation and documentation in-place. -Finally, check out the [tests](https://github.com/php-amqp/php-amqp/tree/master/tests) to see typical usage and edge cases. +Finally, check out the [tests](https://github.com/php-amqp/php-amqp/tree/latest/tests) to see typical usage and edge cases. ### Notes @@ -140,11 +140,11 @@ using `-Y amqp` attribute, just give a try - `tshark -i lo -Y amqp`. #### Configuring a RabbitMQ server -If you need to tweek RabbitMQ server params use default config -[rabbitmq.config.example](https://github.com/rabbitmq/rabbitmq-server/blob/master/docs/rabbitmq.config.example) -([raw](https://raw.githubusercontent.com/rabbitmq/rabbitmq-server/master/docs/rabbitmq.config.example)) -from [official RabbitmMQ repo](https://github.com/rabbitmq/rabbitmq-server), so it may looks like -`sudo curl https://raw.githubusercontent.com/rabbitmq/rabbitmq-server/master/docs/rabbitmq.config.example /etc/rabbitmq/rabbitmq.config` +If you need to tweak RabbitMQ server params use default config +[rabbitmq.conf.example](https://github.com/rabbitmq/rabbitmq-server/blob/main/deps/rabbit/docs/rabbitmq.conf.example) +([raw](https://raw.githubusercontent.com/rabbitmq/rabbitmq-server/main/deps/rabbit/docs/rabbitmq.conf.example)) +from [official RabbitmMQ repo](https://github.com/rabbitmq/rabbitmq-server), so it may look like +`sudo curl https://raw.githubusercontent.com/rabbitmq/rabbitmq-server/main/deps/rabbit/docs/rabbitmq.conf.example /etc/rabbitmq/rabbitmq.config` To reset RabbitMQ application run in CLI (as privileged user) `rabbitmqctl stop_app && rabbitmqctl reset && rabbitmqctl start_app`. @@ -161,4 +161,4 @@ To reset RabbitMQ application run in CLI (as privileged user) `rabbitmqctl stop_ Say we want to release "1.1000.0" next. We first run `php tools/make-release.php 1.1000.0`. This will update the version numbers and pre-populate the changelog with the latest git commits between the previous version and now. It will prompt you to edit the changelog in between. Once the release is done it tells you what to do next. -Run `php tools/make-dev.php 1.1000.1` to bring master back into development mode afterwards. +Run `php tools/make-dev.php 1.1000.1` to bring latest back into development mode afterwards. diff --git a/package.xml b/package.xml index 6b130eec..a8c42e60 100644 --- a/package.xml +++ b/package.xml @@ -36,7 +36,7 @@ diff --git a/tools/functions.php b/tools/functions.php index 5b338e7e..530de641 100644 --- a/tools/functions.php +++ b/tools/functions.php @@ -225,7 +225,7 @@ function buildChangelog(string $nextTag, string $previousTag): string $commits = array_filter( explode( "\n", - trim(executeCommand(sprintf('git log --oneline %s..origin/master --pretty=%%h --no-merges', $previousTag))) + trim(executeCommand(sprintf('git log --oneline %s..origin/latest --pretty=%%h --no-merges', $previousTag))) ) ); @@ -334,7 +334,7 @@ function gitCommit(int $step, string $nextVersion, string $message): void { sprintf('git commit -m "[RM] %s %s" %s %s', $message, $nextVersion, HEADER_VERSION_FILE, PACKAGE_XML) ); - printf("%d) Run \"git push origin master\"\n", $step); + printf("%d) Run \"git push origin latest\"\n", $step); } function gitTag(int $step, string $nextVersion): void { diff --git a/tools/make-dev.php b/tools/make-dev.php index 0071f9c5..1dafd26c 100644 --- a/tools/make-dev.php +++ b/tools/make-dev.php @@ -14,7 +14,7 @@ setSourceVersion($nextVersion); setStability($nextVersion); setDate(new DateTimeImmutable('NOW')); -setChangelog(buildChangelog('master', versionToTag(getPreviousVersion()))); +setChangelog(buildChangelog('latest', versionToTag(getPreviousVersion()))); savePackageXml(); validatePackage(); gitCommit(1, $nextVersion, 'back to dev'); From 25eea6698239d03af532228e55e7d6d222300661 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Tue, 25 Jul 2023 22:11:24 +0200 Subject: [PATCH 009/147] Ignore failures on experimental builds --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f4e486d8..43b3d2f6 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -13,7 +13,6 @@ jobs: test: name: php-${{ matrix.php-version }} librabbitmq-${{ matrix.librabbitmq-version }} ${{ matrix.test-php-args == '-m' && 'memory leaks' || '' }} runs-on: ${{ matrix.os }} - continue-on-error: ${{ matrix.experimental }} env: TEST_PHP_ARGS: ${{ matrix.test-php-args }} @@ -151,3 +150,4 @@ jobs: - name: Dump report run: sh test-report.sh + continue-on-error: ${{ matrix.experimental }} From 80953ca3426e556dcaf3986271d5bfcb7b551691 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Tue, 25 Jul 2023 23:25:11 +0200 Subject: [PATCH 010/147] Fix for #385 of #409 (#432) Clear the consumer tag if either the argument matches or the latest tag is used. --- amqp_queue.c | 12 ++++-------- stubs/AMQPQueue.php | 17 ++++++++++------- tests/bug_385.phpt | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 tests/bug_385.phpt diff --git a/amqp_queue.c b/amqp_queue.c index c3060de1..220bf258 100644 --- a/amqp_queue.c +++ b/amqp_queue.c @@ -940,7 +940,7 @@ static PHP_METHOD(amqp_queue_class, cancel) zval *channel_zv = PHP_AMQP_READ_THIS_PROP("channel"); zval *consumers = zend_read_property(amqp_channel_class_entry, PHP_AMQP_COMPAT_OBJ_P(channel_zv), ZEND_STRL("consumers"), 0 , &rv TSRMLS_CC); - zend_bool has_consumer_tag = (zend_bool) (IS_STRING == Z_TYPE_P(PHP_AMQP_READ_THIS_PROP("consumer_tag"))); + zend_bool previous_consumer_tag_exists = (zend_bool) (IS_STRING == Z_TYPE_P(PHP_AMQP_READ_THIS_PROP("consumer_tag"))); if (IS_ARRAY != Z_TYPE_P(consumers)) { zend_throw_exception(amqp_queue_exception_class_entry, "Invalid channel consumers, forgot to call channel constructor?", 0 TSRMLS_CC); @@ -950,7 +950,7 @@ static PHP_METHOD(amqp_queue_class, cancel) channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(channel_zv); PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not cancel queue."); - if (!consumer_tag_len && (!has_consumer_tag || !PHP_AMQP_READ_THIS_PROP_STRLEN("consumer_tag"))) { + if (!consumer_tag_len && (!previous_consumer_tag_exists || !PHP_AMQP_READ_THIS_PROP_STRLEN("consumer_tag"))) { return; } @@ -970,15 +970,11 @@ static PHP_METHOD(amqp_queue_class, cancel) return; } - if (!consumer_tag_len || (has_consumer_tag && strcmp(consumer_tag, PHP_AMQP_READ_THIS_PROP_STR("consumer_tag")) != 0)) { + if (!consumer_tag_len || (previous_consumer_tag_exists && strcmp(consumer_tag, PHP_AMQP_READ_THIS_PROP_STR("consumer_tag")) == 0)) { zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("consumer_tag") TSRMLS_CC); } - char *key; - key = estrndup((char *)r->consumer_tag.bytes, (unsigned) r->consumer_tag.len); - - zend_hash_str_del_ind(Z_ARRVAL_P(consumers), key, r->consumer_tag.len); - efree(key); + zend_hash_str_del_ind(Z_ARRVAL_P(consumers), r->consumer_tag.bytes, r->consumer_tag.len); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); diff --git a/stubs/AMQPQueue.php b/stubs/AMQPQueue.php index af2af82f..5b500907 100644 --- a/stubs/AMQPQueue.php +++ b/stubs/AMQPQueue.php @@ -45,14 +45,17 @@ public function bind($exchange_name, $routing_key = null, array $arguments = arr /** * Cancel a queue that is already bound to an exchange and routing key. * - * @param string $consumer_tag The consumer tag cancel. If no tag provided, + * @param string $consumer_tag The consumer tag to cancel. If no tag is provided, * or it is empty string, the latest consumer - * tag on this queue will be used and after - * successful request it will set to null. - * If it also empty, no `basic.cancel` - * request will be sent. When consumer_tag give - * and it equals to latest consumer_tag on queue, - * it will be interpreted as latest consumer_tag usage. + * tag on this queue will be taken and after + * the successful cancellation request it will set to null. + * If the consumer_tag parameter is empty and the latest + * consumer tag is empty, no `basic.cancel` request will be + * sent. + * If either the consumer tag passed matches the latest tag + * or no consumer tag was passed and the latest tag was used + * the internal consumer tag will be set to null, so that + * `AMQPQueue::getConsumerTag()` will return null afterwards. * * @throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. diff --git a/tests/bug_385.phpt b/tests/bug_385.phpt new file mode 100644 index 00000000..881b24b9 --- /dev/null +++ b/tests/bug_385.phpt @@ -0,0 +1,42 @@ +--TEST-- +#385 Testing consumer cleared on cancel +--SKIPIF-- + +--FILE-- +connect(); + +$channel = new AMQPChannel($conn); +$exchange = new AMQPExchange($channel); + +$queue = new AMQPQueue($channel); +$queue->declareQueue(); + +// Asynchronously consuming +$queue->consume(null, AMQP_NOPARAM, 'someid'); + +// Showing that current consumer tag is from last consume call +echo $queue->getConsumerTag() ?? 'none'; + +echo PHP_EOL; + +// Cancel by a different consumer tag than the latest one -> expecting the consumer tag to not clear +$queue->cancel('someotherid'); + +echo $queue->getConsumerTag() ?? 'none'; + +echo PHP_EOL; + +// Cancel by consumer tag -> expecting the current consumer tag to clear +$queue->cancel('someid'); + +// Current consumer tag should be null as consumer has been cancelled +echo $queue->getConsumerTag() ?? 'none'; +?> +--EXPECTF-- +someid +someid +none From b11ad1b700d90481a7a09e35d6ce5098253b4b01 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 26 Jul 2023 00:31:29 +0200 Subject: [PATCH 011/147] Increase credentials and identifier limits (#433) --- amqp_connection.c | 54 ++++++++++++++++++++++++++--------------------- php_amqp.h | 2 ++ 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/amqp_connection.c b/amqp_connection.c index 7c9f04ff..68fd0b36 100644 --- a/amqp_connection.c +++ b/amqp_connection.c @@ -66,6 +66,8 @@ #define E_DEPRECATED E_WARNING #endif +#define PHP_AMQP_INI_STR_MAX(name, length) (strlen(INI_STR((name))) > length ? length : strlen(INI_STR((name)))) + zend_class_entry *amqp_connection_class_entry; #define this_ce amqp_connection_class_entry @@ -334,14 +336,14 @@ static PHP_METHOD(amqp_connection_class, __construct) } /* Validate the given login */ if (zdata && Z_STRLEN_P(zdata) > 0) { - if (Z_STRLEN_P(zdata) < 128) { + if (Z_STRLEN_P(zdata) < PHP_AMQP_MAX_CREDENTIALS_LENGTH) { zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("login"), zdata TSRMLS_CC); } else { - zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'login' exceeds 128 character limit.", 0 TSRMLS_CC); + zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'login' exceeds %d character limit.", PHP_AMQP_MAX_CREDENTIALS_LENGTH); return; } } else { - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("login"), INI_STR("amqp.login"), (size_t) (strlen(INI_STR("amqp.login")) > 128 ? 128 : strlen(INI_STR("amqp.login"))) TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("login"), INI_STR("amqp.login"), PHP_AMQP_INI_STR_MAX("amqp.login", PHP_AMQP_MAX_CREDENTIALS_LENGTH) TSRMLS_CC); } /* Pull the password out of the $params array */ @@ -352,14 +354,14 @@ static PHP_METHOD(amqp_connection_class, __construct) } /* Validate the given password */ if (zdata && Z_STRLEN_P(zdata) > 0) { - if (Z_STRLEN_P(zdata) < 128) { + if (Z_STRLEN_P(zdata) < PHP_AMQP_MAX_CREDENTIALS_LENGTH) { zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("password"), Z_STRVAL_P(zdata), Z_STRLEN_P(zdata) TSRMLS_CC); } else { - zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'password' exceeds 128 character limit.", 0 TSRMLS_CC); + zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'password' exceeds %d character limit.", PHP_AMQP_MAX_CREDENTIALS_LENGTH); return; } } else { - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("password"), INI_STR("amqp.password"), (size_t) (strlen(INI_STR("amqp.password")) > 128 ? 128 : strlen(INI_STR("amqp.password"))) TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("password"), INI_STR("amqp.password"), PHP_AMQP_INI_STR_MAX("amqp.password", PHP_AMQP_MAX_CREDENTIALS_LENGTH) TSRMLS_CC); } /* Pull the host out of the $params array */ @@ -370,14 +372,14 @@ static PHP_METHOD(amqp_connection_class, __construct) } /* Validate the given host */ if (zdata && Z_STRLEN_P(zdata) > 0) { - if (Z_STRLEN_P(zdata) < 128) { + if (Z_STRLEN_P(zdata) < PHP_AMQP_MAX_IDENTIFIER_LENGTH) { zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("host"), Z_STRVAL_P(zdata), Z_STRLEN_P(zdata) TSRMLS_CC); } else { - zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'host' exceeds 128 character limit.", 0 TSRMLS_CC); + zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'host' exceeds %d character limit.", PHP_AMQP_MAX_IDENTIFIER_LENGTH); return; } } else { - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("host"), INI_STR("amqp.host"), (size_t) (strlen(INI_STR("amqp.host")) > 128 ? 128 : strlen(INI_STR("amqp.host"))) TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("host"), INI_STR("amqp.host"), PHP_AMQP_INI_STR_MAX("amqp.host" , PHP_AMQP_MAX_IDENTIFIER_LENGTH) TSRMLS_CC); } /* Pull the vhost out of the $params array */ @@ -388,14 +390,14 @@ static PHP_METHOD(amqp_connection_class, __construct) } /* Validate the given vhost */ if (zdata && Z_STRLEN_P(zdata) > 0) { - if (Z_STRLEN_P(zdata) < 128) { + if (Z_STRLEN_P(zdata) < PHP_AMQP_MAX_IDENTIFIER_LENGTH) { zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("vhost"), Z_STRVAL_P(zdata), Z_STRLEN_P(zdata) TSRMLS_CC); } else { - zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'vhost' exceeds 128 character limit.", 0 TSRMLS_CC); + zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'vhost' exceeds %d character limit.", PHP_AMQP_MAX_IDENTIFIER_LENGTH); return; } } else { - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("vhost"), INI_STR("amqp.vhost"), (size_t) (strlen(INI_STR("amqp.vhost")) > 128 ? 128 : strlen(INI_STR("amqp.vhost"))) TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("vhost"), INI_STR("amqp.vhost"), PHP_AMQP_INI_STR_MAX("amqp.vhost", PHP_AMQP_MAX_IDENTIFIER_LENGTH) TSRMLS_CC); } @@ -767,7 +769,8 @@ static PHP_METHOD(amqp_connection_class, getLogin) set the login */ static PHP_METHOD(amqp_connection_class, setLogin) { - char *login = NULL; size_t login_len = 0; + char *login = NULL; + size_t login_len = 0; /* Get the login from the method params */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &login, &login_len) == FAILURE) { @@ -775,8 +778,8 @@ static PHP_METHOD(amqp_connection_class, setLogin) } /* Validate login length */ - if (login_len > 128) { - zend_throw_exception(amqp_connection_exception_class_entry, "Invalid 'login' given, exceeds 128 characters limit.", 0 TSRMLS_CC); + if (login_len > PHP_AMQP_MAX_CREDENTIALS_LENGTH) { + zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Invalid 'login' given, exceeds %d characters limit.", PHP_AMQP_MAX_CREDENTIALS_LENGTH); return; } @@ -801,7 +804,8 @@ static PHP_METHOD(amqp_connection_class, getPassword) set the password */ static PHP_METHOD(amqp_connection_class, setPassword) { - char *password = NULL; size_t password_len = 0; + char *password = NULL; + size_t password_len = 0; /* Get the password from the method params */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &password, &password_len) == FAILURE) { @@ -809,8 +813,8 @@ static PHP_METHOD(amqp_connection_class, setPassword) } /* Validate password length */ - if (password_len > 128) { - zend_throw_exception(amqp_connection_exception_class_entry, "Invalid 'password' given, exceeds 128 characters limit.", 0 TSRMLS_CC); + if (password_len > PHP_AMQP_MAX_CREDENTIALS_LENGTH) { + zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Invalid 'password' given, exceeds %d characters limit.", PHP_AMQP_MAX_CREDENTIALS_LENGTH); return; } @@ -836,7 +840,8 @@ static PHP_METHOD(amqp_connection_class, getHost) set the host */ static PHP_METHOD(amqp_connection_class, setHost) { - char *host = NULL; size_t host_len = 0; + char *host = NULL; + size_t host_len = 0; /* Get the host from the method params */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &host, &host_len) == FAILURE) { @@ -844,8 +849,8 @@ static PHP_METHOD(amqp_connection_class, setHost) } /* Validate host length */ - if (host_len > 1024) { - zend_throw_exception(amqp_connection_exception_class_entry, "Invalid 'host' given, exceeds 1024 character limit.", 0 TSRMLS_CC); + if (host_len > PHP_AMQP_MAX_IDENTIFIER_LENGTH) { + zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Invalid 'host' given, exceeds %d character limit.", PHP_AMQP_MAX_IDENTIFIER_LENGTH); return; } @@ -922,15 +927,16 @@ static PHP_METHOD(amqp_connection_class, getVhost) set the vhost */ static PHP_METHOD(amqp_connection_class, setVhost) { - char *vhost = NULL; size_t vhost_len = 0; + char *vhost = NULL; + size_t vhost_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &vhost, &vhost_len) == FAILURE) { return; } /* Validate vhost length */ - if (vhost_len > 128) { - zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'vhost' exceeds 128 characters limit.", 0 TSRMLS_CC); + if (vhost_len > PHP_AMQP_MAX_IDENTIFIER_LENGTH) { + zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'vhost' exceeds %d characters limit.", PHP_AMQP_MAX_IDENTIFIER_LENGTH); return; } diff --git a/php_amqp.h b/php_amqp.h index 9697e034..891ffd67 100644 --- a/php_amqp.h +++ b/php_amqp.h @@ -195,6 +195,8 @@ struct _amqp_connection_object { #define PHP_AMQP_MAX_FRAME INT_MAX #define PHP_AMQP_MAX_HEARTBEAT INT_MAX +#define PHP_AMQP_MAX_CREDENTIALS_LENGTH 1024 +#define PHP_AMQP_MAX_IDENTIFIER_LENGTH 512 #define PHP_AMQP_DEFAULT_CHANNEL_MAX PHP_AMQP_MAX_CHANNELS #define PHP_AMQP_DEFAULT_FRAME_MAX AMQP_DEFAULT_FRAME_SIZE From 73bacd7185a82cc86e80d835be97354e659add99 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 26 Jul 2023 14:06:48 +0200 Subject: [PATCH 012/147] Fix parameter error handling in AMQPConnection and AMQPChannel (#434) --- .gitignore | 1 + amqp.c | 157 ++++++++++++++++++++--- amqp_channel.c | 38 ++++-- amqp_connection.c | 183 ++++++++++++++++----------- php_amqp.h | 19 ++- stubs/AMQPConnection.php | 9 ++ stubs/AMQPQueue.php | 32 ++--- tests/amqpchannel_validation.phpt | 68 ++++++++++ tests/amqpconnection_validation.phpt | 103 +++++++++++++++ tests/ini_validation_failure.phpt | 66 ++++++++++ 10 files changed, 558 insertions(+), 118 deletions(-) create mode 100644 tests/amqpchannel_validation.phpt create mode 100644 tests/amqpconnection_validation.phpt create mode 100644 tests/ini_validation_failure.phpt diff --git a/.gitignore b/.gitignore index 108619ac..e04d1daa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .deps +*.dep .libs/* .vagrant Makefile diff --git a/amqp.c b/amqp.c index bca75bf4..8a26eb4a 100644 --- a/amqp.c +++ b/amqp.c @@ -86,25 +86,148 @@ zend_function_entry amqp_functions[] = { }; /* }}} */ +zend_bool php_amqp_is_valid_identifier(zend_string *val) { + return ZSTR_LEN(val) > 0 && ZSTR_LEN(val) <= PHP_AMQP_MAX_IDENTIFIER_LENGTH; +} + +zend_bool php_amqp_is_valid_credential(zend_string *val) { + return ZSTR_LEN(val) > 0 && ZSTR_LEN(val) <= PHP_AMQP_MAX_CREDENTIALS_LENGTH; +} + +zend_bool php_amqp_is_valid_port(zend_long val) { + return val >= PHP_AMQP_MIN_PORT && val <= PHP_AMQP_MAX_PORT; +} + +zend_bool php_amqp_is_valid_timeout(double timeout) { + return timeout >= 0; +} + +zend_bool php_amqp_is_valid_channel_max(zend_long val) { + return val > 0 && val <= PHP_AMQP_DEFAULT_CHANNEL_MAX; +} + +zend_bool php_amqp_is_valid_frame_size_max(zend_long val) { + return val > 0 && val <= PHP_AMQP_MAX_FRAME_SIZE; +} + +zend_bool php_amqp_is_valid_heartbeat(zend_long val) { + return val > 0 && val <= PHP_AMQP_MAX_HEARTBEAT; +} + +zend_bool php_amqp_is_valid_prefetch_size(zend_long val) { + return val >= 0 && val <= PHP_AMQP_MAX_PREFETCH_SIZE; +} + +zend_bool php_amqp_is_valid_prefetch_count(zend_long val) { + return val >= 0 && val <= PHP_AMQP_MAX_PREFETCH_COUNT; +} + +static ZEND_INI_MH(onUpdateIdentifier) +{ + if (new_value != NULL && !php_amqp_is_valid_identifier(new_value)) { + return FAILURE; + } + + return SUCCESS; +} + +static ZEND_INI_MH(onUpdateCredentials) +{ + if (new_value != NULL && !php_amqp_is_valid_credential(new_value)) { + return FAILURE; + } + + return SUCCESS; +} + +static ZEND_INI_MH(onUpdatePort) +{ + zend_long val = zend_ini_parse_quantity_warn(new_value, entry->name); + if (!php_amqp_is_valid_port(val)) { + return FAILURE; + } + + return SUCCESS; +} + +static ZEND_INI_MH(onUpdateTimeout) +{ + if (!php_amqp_is_valid_timeout(zend_strtod(ZSTR_VAL(new_value), NULL))) { + return FAILURE; + } + + return SUCCESS; +} + +static ZEND_INI_MH(onUpdateChannelMax) +{ + zend_long val = zend_ini_parse_quantity_warn(new_value, entry->name); + if (!php_amqp_is_valid_channel_max(val)) { + return FAILURE; + } + + return SUCCESS; +} + +static ZEND_INI_MH(onUpdateFrameSizeMax) +{ + zend_long val = zend_ini_parse_quantity_warn(new_value, entry->name); + if (!php_amqp_is_valid_frame_size_max(val)) { + return FAILURE; + } + + return SUCCESS; +} + +static ZEND_INI_MH(onUpdateHeartbeat) +{ + zend_long val = zend_ini_parse_quantity_warn(new_value, entry->name); + if (!php_amqp_is_valid_heartbeat(val)) { + return FAILURE; + } + + return SUCCESS; +} + +static ZEND_INI_MH(onUpdatePrefetchCount) +{ + zend_long val = zend_ini_parse_quantity_warn(new_value, entry->name); + if (!php_amqp_is_valid_prefetch_count(val)) { + return FAILURE; + } + + return SUCCESS; +} + +static ZEND_INI_MH(onUpdatePrefetchSize) +{ + zend_long val = zend_ini_parse_quantity_warn(new_value, entry->name); + if (!php_amqp_is_valid_prefetch_size(val)) { + return FAILURE; + } + + return SUCCESS; +} + PHP_INI_BEGIN() - PHP_INI_ENTRY("amqp.host", DEFAULT_HOST, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("amqp.vhost", DEFAULT_VHOST, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("amqp.port", DEFAULT_PORT, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("amqp.timeout", DEFAULT_TIMEOUT, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("amqp.read_timeout", DEFAULT_READ_TIMEOUT, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("amqp.write_timeout", DEFAULT_WRITE_TIMEOUT, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("amqp.connect_timeout", DEFAULT_CONNECT_TIMEOUT, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("amqp.rpc_timeout", DEFAULT_RPC_TIMEOUT, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("amqp.login", DEFAULT_LOGIN, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("amqp.password", DEFAULT_PASSWORD, PHP_INI_ALL, NULL) + PHP_INI_ENTRY("amqp.host", DEFAULT_HOST, PHP_INI_ALL, onUpdateIdentifier) + PHP_INI_ENTRY("amqp.vhost", DEFAULT_VHOST, PHP_INI_ALL, onUpdateIdentifier) + PHP_INI_ENTRY("amqp.port", DEFAULT_PORT, PHP_INI_ALL, onUpdatePort) + PHP_INI_ENTRY("amqp.timeout", DEFAULT_TIMEOUT, PHP_INI_ALL, onUpdateTimeout) + PHP_INI_ENTRY("amqp.read_timeout", DEFAULT_READ_TIMEOUT, PHP_INI_ALL, onUpdateTimeout) + PHP_INI_ENTRY("amqp.write_timeout", DEFAULT_WRITE_TIMEOUT, PHP_INI_ALL, onUpdateTimeout) + PHP_INI_ENTRY("amqp.connect_timeout", DEFAULT_CONNECT_TIMEOUT, PHP_INI_ALL, onUpdateTimeout) + PHP_INI_ENTRY("amqp.rpc_timeout", DEFAULT_RPC_TIMEOUT, PHP_INI_ALL, onUpdateTimeout) + PHP_INI_ENTRY("amqp.login", DEFAULT_LOGIN, PHP_INI_ALL, onUpdateCredentials) + PHP_INI_ENTRY("amqp.password", DEFAULT_PASSWORD, PHP_INI_ALL, onUpdateCredentials) PHP_INI_ENTRY("amqp.auto_ack", DEFAULT_AUTOACK, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("amqp.prefetch_count", DEFAULT_PREFETCH_COUNT, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("amqp.prefetch_size", DEFAULT_PREFETCH_SIZE, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("amqp.global_prefetch_count", DEFAULT_GLOBAL_PREFETCH_COUNT, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("amqp.global_prefetch_size", DEFAULT_GLOBAL_PREFETCH_SIZE, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("amqp.channel_max", DEFAULT_CHANNEL_MAX, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("amqp.frame_max", DEFAULT_FRAME_MAX, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("amqp.heartbeat", DEFAULT_HEARTBEAT, PHP_INI_ALL, NULL) + PHP_INI_ENTRY("amqp.prefetch_count", DEFAULT_PREFETCH_COUNT, PHP_INI_ALL, onUpdatePrefetchCount) + PHP_INI_ENTRY("amqp.prefetch_size", DEFAULT_PREFETCH_SIZE, PHP_INI_ALL, onUpdatePrefetchSize) + PHP_INI_ENTRY("amqp.global_prefetch_count", DEFAULT_GLOBAL_PREFETCH_COUNT, PHP_INI_ALL, onUpdatePrefetchCount) + PHP_INI_ENTRY("amqp.global_prefetch_size", DEFAULT_GLOBAL_PREFETCH_SIZE, PHP_INI_ALL, onUpdatePrefetchSize) + PHP_INI_ENTRY("amqp.channel_max", DEFAULT_CHANNEL_MAX, PHP_INI_ALL, onUpdateChannelMax) + PHP_INI_ENTRY("amqp.frame_max", DEFAULT_FRAME_MAX, PHP_INI_ALL, onUpdateFrameSizeMax) + PHP_INI_ENTRY("amqp.heartbeat", DEFAULT_HEARTBEAT, PHP_INI_ALL, onUpdateHeartbeat) PHP_INI_ENTRY("amqp.cacert", DEFAULT_CACERT, PHP_INI_ALL, NULL) PHP_INI_ENTRY("amqp.cert", DEFAULT_CERT, PHP_INI_ALL, NULL) PHP_INI_ENTRY("amqp.key", DEFAULT_KEY, PHP_INI_ALL, NULL) diff --git a/amqp_channel.c b/amqp_channel.c index 2c0d1956..5405a693 100644 --- a/amqp_channel.c +++ b/amqp_channel.c @@ -325,7 +325,7 @@ static PHP_METHOD(amqp_channel_class, __construct) php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, PHP_AMQP_G(error_message), PHP_AMQP_G(error_code) TSRMLS_CC); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - /* Prevent double free, it may happens in case case channel resource was already freed due to some hard error. */ + /* Prevent double free, it may happen in case the channel resource was already freed due to some hard error. */ if (channel_resource->connection_resource) { php_amqp_connection_resource_unregister_channel(channel_resource->connection_resource, channel_resource->channel_id); channel_resource->channel_id = 0; @@ -334,7 +334,7 @@ static PHP_METHOD(amqp_channel_class, __construct) return; } - /* r->channel_id is a 16-bit channel number insibe amqp_bytes_t, assertion below will without converting to uint16_t*/ + /* r->channel_id is a 16-bit channel number inside amqp_bytes_t, assertion below will without converting to uint16_t*/ /* assert (r->channel_id == channel_resource->channel_id);*/ php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); @@ -360,7 +360,7 @@ static PHP_METHOD(amqp_channel_class, __construct) php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - uint16_t global_prefetch_size = (uint16_t)PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_size"); + uint32_t global_prefetch_size = (uint32_t)PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_size"); uint16_t global_prefetch_count = (uint16_t)PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_count"); /* Set the global prefetch settings (ignoring if 0 for backwards compatibility) */ @@ -448,6 +448,11 @@ static PHP_METHOD(amqp_channel_class, setPrefetchCount) return; } + if (!php_amqp_is_valid_prefetch_count(prefetch_count)) { + zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'prefetch_count' must be between 0 and %u.", PHP_AMQP_MAX_PREFETCH_COUNT); + return; + } + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); PHP_AMQP_VERIFY_CHANNEL_CONNECTION_RESOURCE(channel_resource, "Could not set prefetch count."); // TODO: verify that connection is active and resource exists. that is enough @@ -472,7 +477,7 @@ static PHP_METHOD(amqp_channel_class, setPrefetchCount) php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - uint16_t global_prefetch_size = (uint16_t)PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_size"); + uint32_t global_prefetch_size = (uint32_t)PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_size"); uint16_t global_prefetch_count = (uint16_t)PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_count"); /* Re-apply current global prefetch settings if set (writing consumer prefetch settings will clear global prefetch settings) */ @@ -528,6 +533,11 @@ static PHP_METHOD(amqp_channel_class, setPrefetchSize) return; } + if (!php_amqp_is_valid_prefetch_size(prefetch_size)) { + zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'prefetch_size' must be between 0 and %u.", PHP_AMQP_MAX_PREFETCH_SIZE); + return; + } + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); PHP_AMQP_VERIFY_CHANNEL_CONNECTION_RESOURCE(channel_resource, "Could not set prefetch size."); @@ -536,7 +546,7 @@ static PHP_METHOD(amqp_channel_class, setPrefetchSize) amqp_basic_qos( channel_resource->connection_resource->connection_state, channel_resource->channel_id, - (uint16_t)prefetch_size, + (uint32_t)prefetch_size, 0, 0 ); @@ -551,7 +561,7 @@ static PHP_METHOD(amqp_channel_class, setPrefetchSize) php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - uint16_t global_prefetch_size = (uint16_t)PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_size"); + uint32_t global_prefetch_size = (uint32_t)PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_size"); uint16_t global_prefetch_count = (uint16_t)PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_count"); /* Re-apply current global prefetch settings if set (writing consumer prefetch settings will clear global prefetch settings) */ @@ -605,6 +615,11 @@ static PHP_METHOD(amqp_channel_class, setGlobalPrefetchCount) return; } + if (!php_amqp_is_valid_prefetch_count(global_prefetch_count)) { + zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'global_prefetch_count' must be between 0 and %u.", PHP_AMQP_MAX_PREFETCH_COUNT); + return; + } + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); PHP_AMQP_VERIFY_CHANNEL_CONNECTION_RESOURCE(channel_resource, "Could not set global prefetch count."); @@ -659,6 +674,11 @@ static PHP_METHOD(amqp_channel_class, setGlobalPrefetchSize) return; } + if (!php_amqp_is_valid_prefetch_size(global_prefetch_size)) { + zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'global_prefetch_size' must be between 0 and %u.", PHP_AMQP_MAX_PREFETCH_SIZE); + return; + } + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); PHP_AMQP_VERIFY_CHANNEL_CONNECTION_RESOURCE(channel_resource, "Could not set prefetch size."); @@ -668,7 +688,7 @@ static PHP_METHOD(amqp_channel_class, setGlobalPrefetchSize) amqp_basic_qos( channel_resource->connection_resource->connection_state, channel_resource->channel_id, - (uint16_t)global_prefetch_size, + (uint32_t)global_prefetch_size, 0, 1 ); @@ -734,7 +754,7 @@ static PHP_METHOD(amqp_channel_class, qos) amqp_basic_qos( channel_resource->connection_resource->connection_state, channel_resource->channel_id, - (uint16_t)PHP_AMQP_READ_THIS_PROP_LONG("prefetch_size"), + (uint32_t)PHP_AMQP_READ_THIS_PROP_LONG("prefetch_size"), (uint16_t)PHP_AMQP_READ_THIS_PROP_LONG("prefetch_count"), /* NOTE that RabbitMQ has reinterpreted global flag field. See https://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.qos.global for details */ 0 /* Global flag - whether this change should affect every channel_resource */ @@ -750,7 +770,7 @@ static PHP_METHOD(amqp_channel_class, qos) php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - uint16_t global_prefetch_size = (uint16_t)PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_size"); + uint32_t global_prefetch_size = (uint32_t)PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_size"); uint16_t global_prefetch_count = (uint16_t)PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_count"); /* Re-apply current global prefetch settings if set (writing consumer prefetch settings will clear global prefetch settings) */ diff --git a/amqp_connection.c b/amqp_connection.c index 68fd0b36..6521038f 100644 --- a/amqp_connection.c +++ b/amqp_connection.c @@ -66,8 +66,6 @@ #define E_DEPRECATED E_WARNING #endif -#define PHP_AMQP_INI_STR_MAX(name, length) (strlen(INI_STR((name))) > length ? length : strlen(INI_STR((name)))) - zend_class_entry *amqp_connection_class_entry; #define this_ce amqp_connection_class_entry @@ -336,14 +334,14 @@ static PHP_METHOD(amqp_connection_class, __construct) } /* Validate the given login */ if (zdata && Z_STRLEN_P(zdata) > 0) { - if (Z_STRLEN_P(zdata) < PHP_AMQP_MAX_CREDENTIALS_LENGTH) { - zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("login"), zdata TSRMLS_CC); - } else { - zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'login' exceeds %d character limit.", PHP_AMQP_MAX_CREDENTIALS_LENGTH); - return; - } + if (!php_amqp_is_valid_credential(Z_STR_P(zdata))) { + zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'login' exceeds %d character limit.", PHP_AMQP_MAX_CREDENTIALS_LENGTH); + return; + } + + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("login"), zdata TSRMLS_CC); } else { - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("login"), INI_STR("amqp.login"), PHP_AMQP_INI_STR_MAX("amqp.login", PHP_AMQP_MAX_CREDENTIALS_LENGTH) TSRMLS_CC); + zend_update_property_string(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("login"), INI_STR("amqp.login") TSRMLS_CC); } /* Pull the password out of the $params array */ @@ -354,14 +352,14 @@ static PHP_METHOD(amqp_connection_class, __construct) } /* Validate the given password */ if (zdata && Z_STRLEN_P(zdata) > 0) { - if (Z_STRLEN_P(zdata) < PHP_AMQP_MAX_CREDENTIALS_LENGTH) { - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("password"), Z_STRVAL_P(zdata), Z_STRLEN_P(zdata) TSRMLS_CC); - } else { - zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'password' exceeds %d character limit.", PHP_AMQP_MAX_CREDENTIALS_LENGTH); - return; - } - } else { - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("password"), INI_STR("amqp.password"), PHP_AMQP_INI_STR_MAX("amqp.password", PHP_AMQP_MAX_CREDENTIALS_LENGTH) TSRMLS_CC); + if (!php_amqp_is_valid_credential(Z_STR_P(zdata))) { + zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'password' exceeds %d character limit.", PHP_AMQP_MAX_CREDENTIALS_LENGTH); + return; + } + + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("password"), Z_STRVAL_P(zdata), Z_STRLEN_P(zdata) TSRMLS_CC); + } else { + zend_update_property_string(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("password"), INI_STR("amqp.password") TSRMLS_CC); } /* Pull the host out of the $params array */ @@ -372,14 +370,14 @@ static PHP_METHOD(amqp_connection_class, __construct) } /* Validate the given host */ if (zdata && Z_STRLEN_P(zdata) > 0) { - if (Z_STRLEN_P(zdata) < PHP_AMQP_MAX_IDENTIFIER_LENGTH) { - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("host"), Z_STRVAL_P(zdata), Z_STRLEN_P(zdata) TSRMLS_CC); - } else { - zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'host' exceeds %d character limit.", PHP_AMQP_MAX_IDENTIFIER_LENGTH); - return; - } - } else { - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("host"), INI_STR("amqp.host"), PHP_AMQP_INI_STR_MAX("amqp.host" , PHP_AMQP_MAX_IDENTIFIER_LENGTH) TSRMLS_CC); + if (!php_amqp_is_valid_identifier(Z_STR_P(zdata))) { + zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'host' exceeds %d character limit.", PHP_AMQP_MAX_IDENTIFIER_LENGTH); + return; + } + + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("host"), Z_STRVAL_P(zdata), Z_STRLEN_P(zdata) TSRMLS_CC); + } else { + zend_update_property_string(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("host"), INI_STR("amqp.host") TSRMLS_CC); } /* Pull the vhost out of the $params array */ @@ -390,14 +388,14 @@ static PHP_METHOD(amqp_connection_class, __construct) } /* Validate the given vhost */ if (zdata && Z_STRLEN_P(zdata) > 0) { - if (Z_STRLEN_P(zdata) < PHP_AMQP_MAX_IDENTIFIER_LENGTH) { - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("vhost"), Z_STRVAL_P(zdata), Z_STRLEN_P(zdata) TSRMLS_CC); - } else { - zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'vhost' exceeds %d character limit.", PHP_AMQP_MAX_IDENTIFIER_LENGTH); - return; - } - } else { - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("vhost"), INI_STR("amqp.vhost"), PHP_AMQP_INI_STR_MAX("amqp.vhost", PHP_AMQP_MAX_IDENTIFIER_LENGTH) TSRMLS_CC); + if (!php_amqp_is_valid_identifier(Z_STR_P(zdata))) { + zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'vhost' exceeds %d character limit.", PHP_AMQP_MAX_IDENTIFIER_LENGTH); + return; + } + + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("vhost"), Z_STRVAL_P(zdata), Z_STRLEN_P(zdata) TSRMLS_CC); + } else { + zend_update_property_string(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("vhost"), INI_STR("amqp.vhost") TSRMLS_CC); } @@ -406,20 +404,28 @@ static PHP_METHOD(amqp_connection_class, __construct) if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "port", sizeof("port") - 1)) != NULL) { SEPARATE_ZVAL(zdata); convert_to_long(zdata); - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("port"), Z_LVAL_P(zdata) TSRMLS_CC); - } + + if (!php_amqp_is_valid_port(Z_LVAL_P(zdata))) { + zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'port' must be a valid port number between %d and %d.", PHP_AMQP_MIN_PORT, PHP_AMQP_MAX_PORT); + return; + } + + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("port"), Z_LVAL_P(zdata) TSRMLS_CC); + } zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("read_timeout"), INI_FLT("amqp.read_timeout") TSRMLS_CC); if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "read_timeout", sizeof("read_timeout") - 1)) != NULL) { SEPARATE_ZVAL(zdata); convert_to_double(zdata); - if (Z_DVAL_P(zdata) < 0) { + + if (!php_amqp_is_valid_timeout(Z_DVAL_P(zdata))) { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'read_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC); - } else { - zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("read_timeout"), Z_DVAL_P(zdata) TSRMLS_CC); + return; } + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("read_timeout"), Z_DVAL_P(zdata) TSRMLS_CC); + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "timeout", sizeof("timeout") - 1)) != NULL) { /* 'read_timeout' takes precedence on 'timeout' but users have to know this */ php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Parameter 'timeout' is deprecated, 'read_timeout' used instead"); @@ -431,11 +437,13 @@ static PHP_METHOD(amqp_connection_class, __construct) SEPARATE_ZVAL(zdata); convert_to_double(zdata); - if (Z_DVAL_P(zdata) < 0) { + + if (!php_amqp_is_valid_timeout(Z_DVAL_P(zdata))) { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'timeout' must be greater than or equal to zero.", 0 TSRMLS_CC); - } else { - zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("read_timeout"), Z_DVAL_P(zdata) TSRMLS_CC); + return; } + + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("read_timeout"), Z_DVAL_P(zdata) TSRMLS_CC); } else { assert(DEFAULT_TIMEOUT != NULL); @@ -458,11 +466,13 @@ static PHP_METHOD(amqp_connection_class, __construct) if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "write_timeout", sizeof("write_timeout") - 1)) != NULL) { SEPARATE_ZVAL(zdata); convert_to_double(zdata); - if (Z_DVAL_P(zdata) < 0) { + + if (!php_amqp_is_valid_timeout(Z_DVAL_P(zdata))) { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'write_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC); - } else { - zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("write_timeout"), Z_DVAL_P(zdata) TSRMLS_CC); + return; } + + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("write_timeout"), Z_DVAL_P(zdata) TSRMLS_CC); } zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("rpc_timeout"), INI_FLT("amqp.rpc_timeout") TSRMLS_CC); @@ -470,11 +480,13 @@ static PHP_METHOD(amqp_connection_class, __construct) if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "rpc_timeout", sizeof("rpc_timeout") - 1)) != NULL) { SEPARATE_ZVAL(zdata); convert_to_double(zdata); - if (Z_DVAL_P(zdata) < 0) { + + if (!php_amqp_is_valid_timeout(Z_DVAL_P(zdata))) { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'rpc_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC); - } else { - zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("rpc_timeout"), Z_DVAL_P(zdata) TSRMLS_CC); + return; } + + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("rpc_timeout"), Z_DVAL_P(zdata) TSRMLS_CC); } zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connect_timeout"), INI_FLT("amqp.connect_timeout") TSRMLS_CC); @@ -482,12 +494,13 @@ static PHP_METHOD(amqp_connection_class, __construct) if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "connect_timeout", sizeof("connect_timeout") - 1)) != NULL) { SEPARATE_ZVAL(zdata); convert_to_double(zdata); - if (Z_DVAL_P(zdata) < 0) { - zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'connect_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC); - } else { - zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connect_timeout"), Z_DVAL_P(zdata) TSRMLS_CC); + if (!php_amqp_is_valid_timeout(Z_DVAL_P(zdata))) { + zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'connect_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC); + return; } + + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connect_timeout"), Z_DVAL_P(zdata) TSRMLS_CC); } zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("channel_max"), INI_INT("amqp.channel_max") TSRMLS_CC); @@ -495,15 +508,17 @@ static PHP_METHOD(amqp_connection_class, __construct) if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "channel_max", sizeof("channel_max") - 1)) != NULL) { SEPARATE_ZVAL(zdata); convert_to_long(zdata); - if (Z_LVAL_P(zdata) < 0 || Z_LVAL_P(zdata) > PHP_AMQP_MAX_CHANNELS) { + + if (!php_amqp_is_valid_channel_max(Z_LVAL_P(zdata))) { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'channel_max' is out of range.", 0 TSRMLS_CC); - } else { - if(Z_LVAL_P(zdata) == 0) { - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("channel_max"), PHP_AMQP_DEFAULT_CHANNEL_MAX TSRMLS_CC); - } else { - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("channel_max"), Z_LVAL_P(zdata) TSRMLS_CC); - } + return; } + + if(Z_LVAL_P(zdata) == 0) { + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("channel_max"), PHP_AMQP_DEFAULT_CHANNEL_MAX TSRMLS_CC); + } else { + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("channel_max"), Z_LVAL_P(zdata) TSRMLS_CC); + } } zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("frame_max"), INI_INT("amqp.frame_max") TSRMLS_CC); @@ -511,15 +526,16 @@ static PHP_METHOD(amqp_connection_class, __construct) if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "frame_max", sizeof("frame_max") - 1)) != NULL) { SEPARATE_ZVAL(zdata); convert_to_long(zdata); - if (Z_LVAL_P(zdata) < 0 || Z_LVAL_P(zdata) > PHP_AMQP_MAX_FRAME) { + if (!php_amqp_is_valid_frame_size_max(Z_LVAL_P(zdata))) { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'frame_max' is out of range.", 0 TSRMLS_CC); - } else { - if(Z_LVAL_P(zdata) == 0) { - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("frame_max"), PHP_AMQP_DEFAULT_FRAME_MAX TSRMLS_CC); - } else { - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("frame_max"), Z_LVAL_P(zdata) TSRMLS_CC); - } + return; } + + if(Z_LVAL_P(zdata) == 0) { + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("frame_max"), PHP_AMQP_DEFAULT_FRAME_MAX TSRMLS_CC); + } else { + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("frame_max"), Z_LVAL_P(zdata) TSRMLS_CC); + } } zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("heartbeat"), INI_INT("amqp.heartbeat") TSRMLS_CC); @@ -527,11 +543,12 @@ static PHP_METHOD(amqp_connection_class, __construct) if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "heartbeat", sizeof("heartbeat") - 1)) != NULL) { SEPARATE_ZVAL(zdata); convert_to_long(zdata); - if (Z_LVAL_P(zdata) < 0 || Z_LVAL_P(zdata) > PHP_AMQP_MAX_HEARTBEAT) { + if (!php_amqp_is_valid_heartbeat(Z_LVAL_P(zdata))) { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'heartbeat' is out of range.", 0 TSRMLS_CC); - } else { - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("heartbeat"), Z_LVAL_P(zdata) TSRMLS_CC); + return; } + + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("heartbeat"), Z_LVAL_P(zdata) TSRMLS_CC); } zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("sasl_method"), INI_INT("amqp.sasl_method") TSRMLS_CC); @@ -779,7 +796,7 @@ static PHP_METHOD(amqp_connection_class, setLogin) /* Validate login length */ if (login_len > PHP_AMQP_MAX_CREDENTIALS_LENGTH) { - zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Invalid 'login' given, exceeds %d characters limit.", PHP_AMQP_MAX_CREDENTIALS_LENGTH); + zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'login' exceeds %d character limit.", PHP_AMQP_MAX_CREDENTIALS_LENGTH); return; } @@ -814,7 +831,7 @@ static PHP_METHOD(amqp_connection_class, setPassword) /* Validate password length */ if (password_len > PHP_AMQP_MAX_CREDENTIALS_LENGTH) { - zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Invalid 'password' given, exceeds %d characters limit.", PHP_AMQP_MAX_CREDENTIALS_LENGTH); + zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'password' exceeds %d character limit.", PHP_AMQP_MAX_CREDENTIALS_LENGTH); return; } @@ -850,7 +867,7 @@ static PHP_METHOD(amqp_connection_class, setHost) /* Validate host length */ if (host_len > PHP_AMQP_MAX_IDENTIFIER_LENGTH) { - zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Invalid 'host' given, exceeds %d character limit.", PHP_AMQP_MAX_IDENTIFIER_LENGTH); + zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'host' exceeds %d character limit.", PHP_AMQP_MAX_IDENTIFIER_LENGTH); return; } @@ -975,7 +992,7 @@ static PHP_METHOD(amqp_connection_class, setTimeout) } /* Validate timeout */ - if (read_timeout < 0) { + if (!php_amqp_is_valid_timeout(read_timeout)) { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'timeout' must be greater than or equal to zero.", 0 TSRMLS_CC); return; } @@ -1021,7 +1038,7 @@ static PHP_METHOD(amqp_connection_class, setReadTimeout) } /* Validate timeout */ - if (read_timeout < 0) { + if (!php_amqp_is_valid_timeout(read_timeout)) { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'read_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC); return; } @@ -1067,7 +1084,7 @@ static PHP_METHOD(amqp_connection_class, setWriteTimeout) } /* Validate timeout */ - if (write_timeout < 0) { + if (!php_amqp_is_valid_timeout(write_timeout)) { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'write_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC); return; } @@ -1090,6 +1107,16 @@ static PHP_METHOD(amqp_connection_class, setWriteTimeout) } /* }}} */ +/* {{{ proto amqp::getRpcTimeout() +get rpc timeout */ +static PHP_METHOD(amqp_connection_class, getConnectTimeout) +{ + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("connect_timeout"); +} +/* }}} */ + /* {{{ proto amqp::getRpcTimeout() get rpc timeout */ static PHP_METHOD(amqp_connection_class, getRpcTimeout) @@ -1113,7 +1140,7 @@ static PHP_METHOD(amqp_connection_class, setRpcTimeout) } /* Validate timeout */ - if (rpc_timeout < 0) { + if (!php_amqp_is_valid_timeout(rpc_timeout)) { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'rpc_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC); return; } @@ -1474,6 +1501,9 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setWriteTimeout, ZEND_SEND_ ZEND_ARG_INFO(0, timeout) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getConnectTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getRpcTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() @@ -1573,6 +1603,9 @@ zend_function_entry amqp_connection_class_functions[] = { 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, getConnectTimeout, arginfo_amqp_connection_class_getConnectTimeout, ZEND_ACC_PUBLIC) + /** setConnectTimeout intentionally left out */ + PHP_ME(amqp_connection_class, getRpcTimeout, arginfo_amqp_connection_class_getRpcTimeout, ZEND_ACC_PUBLIC) PHP_ME(amqp_connection_class, setRpcTimeout, arginfo_amqp_connection_class_setRpcTimeout, ZEND_ACC_PUBLIC) diff --git a/php_amqp.h b/php_amqp.h index 891ffd67..2c117720 100644 --- a/php_amqp.h +++ b/php_amqp.h @@ -81,6 +81,9 @@ extern zend_module_entry amqp_module_entry; #else #define PHP_AMQP_COMPAT_OBJ_P(zv) (zv) #endif +#if PHP_VERSION_ID < 80200 +#define zend_ini_parse_quantity_warn(v, name) (zend_atol(ZSTR_VAL(v), ZSTR_LEN(v))) +#endif #include "amqp_connection_resource.h" @@ -193,10 +196,14 @@ struct _amqp_connection_object { #define PHP_AMQP_MAX_CHANNELS 65535 // Note that the maximum number of channels the protocol supports is 65535 (2^16, with the 0-channel reserved) #endif -#define PHP_AMQP_MAX_FRAME INT_MAX +#define PHP_AMQP_MAX_FRAME_SIZE INT_MAX #define PHP_AMQP_MAX_HEARTBEAT INT_MAX #define PHP_AMQP_MAX_CREDENTIALS_LENGTH 1024 #define PHP_AMQP_MAX_IDENTIFIER_LENGTH 512 +#define PHP_AMQP_MIN_PORT 1 +#define PHP_AMQP_MAX_PORT 65535 +#define PHP_AMQP_MAX_PREFETCH_COUNT UINT16_MAX +#define PHP_AMQP_MAX_PREFETCH_SIZE UINT32_MAX #define PHP_AMQP_DEFAULT_CHANNEL_MAX PHP_AMQP_MAX_CHANNELS #define PHP_AMQP_DEFAULT_FRAME_MAX AMQP_DEFAULT_FRAME_SIZE @@ -379,6 +386,16 @@ void php_amqp_zend_throw_exception(amqp_rpc_reply_t reply, zend_class_entry *exc void php_amqp_zend_throw_exception_short(amqp_rpc_reply_t reply, zend_class_entry *exception_ce TSRMLS_DC); void php_amqp_maybe_release_buffers_on_channel(amqp_connection_resource *connection_resource, amqp_channel_resource *channel_resource); +zend_bool php_amqp_is_valid_identifier(zend_string *val); +zend_bool php_amqp_is_valid_credential(zend_string *val); +zend_bool php_amqp_is_valid_port(zend_long val); +zend_bool php_amqp_is_valid_timeout(double timeout); +zend_bool php_amqp_is_valid_channel_max(zend_long val); +zend_bool php_amqp_is_valid_frame_size_max(zend_long val); +zend_bool php_amqp_is_valid_heartbeat(zend_long val); +zend_bool php_amqp_is_valid_prefetch_count(zend_long val); +zend_bool php_amqp_is_valid_prefetch_size(zend_long val); + #endif /* PHP_AMQP_H */ diff --git a/stubs/AMQPConnection.php b/stubs/AMQPConnection.php index 532eed2e..8d630644 100644 --- a/stubs/AMQPConnection.php +++ b/stubs/AMQPConnection.php @@ -316,6 +316,15 @@ public function getWriteTimeout() { } + /** + * Get the configured timeout (in seconds) for connecting to the AMQP broker + * + * @return float + */ + public function getConnectTimeout() + { + } + /** * Sets the interval of time to wait (in seconds) for RPC activity to AMQP broker * diff --git a/stubs/AMQPQueue.php b/stubs/AMQPQueue.php index 5b500907..d7b4b20d 100644 --- a/stubs/AMQPQueue.php +++ b/stubs/AMQPQueue.php @@ -5,6 +5,19 @@ */ class AMQPQueue { + /** + * Create an instance of an AMQPQueue object. + * + * @param AMQPChannel $amqp_channel The amqp channel to use. + * + * @throws AMQPQueueException When amqp_channel is not connected to a + * broker. + * @throws AMQPConnectionException If the connection to the broker was lost. + */ + public function __construct(AMQPChannel $amqp_channel) + { + } + /** * Acknowledge the receipt of a message. * @@ -66,26 +79,13 @@ public function cancel($consumer_tag = '') { } - /** - * Create an instance of an AMQPQueue object. - * - * @param AMQPChannel $amqp_channel The amqp channel to use. - * - * @throws AMQPQueueException When amqp_channel is not connected to a - * broker. - * @throws AMQPConnectionException If the connection to the broker was lost. - */ - public function __construct(AMQPChannel $amqp_channel) - { - } - /** * Consume messages from a queue. * * Blocking function that will retrieve the next message from the queue as * it becomes available and will pass it off to the callback. * - * @param callable | null $callback A callback function to which the + * @param callable|null $callback A callback function to which the * consumed message will be passed. The * function must accept at a minimum * one parameter, an AMQPEnvelope object, @@ -108,7 +108,7 @@ public function __construct(AMQPChannel $amqp_channel) * `basic.consume` request and just run $callback * if it provided. Calling method with empty $callback * and AMQP_JUST_CONSUME makes no sense. - * @param string | null $consumerTag A string describing this consumer. Used + * @param string|null $consumerTag A string describing this consumer. Used * for canceling subscriptions with cancel(). * * @throws AMQPChannelException If the channel is not open. @@ -121,7 +121,7 @@ public function __construct(AMQPChannel $amqp_channel) public function consume( callable $callback = null, $flags = AMQP_NOPARAM, - ?$consumerTag = null + $consumerTag = null ) { } diff --git a/tests/amqpchannel_validation.phpt b/tests/amqpchannel_validation.phpt new file mode 100644 index 00000000..cfbc7dac --- /dev/null +++ b/tests/amqpchannel_validation.phpt @@ -0,0 +1,68 @@ +--TEST-- +AMQPChannel parameter validation +--SKIPIF-- + +--FILE-- +connect(); + +$chan = new AMQPChannel($con); +try { + $chan->setPrefetchSize(-1); +} catch (\Throwable $t) { + printf("%s: %s\n", get_class($t), $t->getMessage()); +} +try { + $chan->setPrefetchSize(PHP_INT_MAX); +} catch (\Throwable $t) { + printf("%s: %s\n", get_class($t), $t->getMessage()); +} +try { + $chan->setGlobalPrefetchSize(-1); +} catch (\Throwable $t) { + printf("%s: %s\n", get_class($t), $t->getMessage()); +} +try { + $chan->setGlobalPrefetchSize(PHP_INT_MAX); +} catch (\Throwable $t) { + printf("%s: %s\n", get_class($t), $t->getMessage()); +} +try { + $chan->setPrefetchCount(-1); +} catch (\Throwable $t) { + printf("%s: %s\n", get_class($t), $t->getMessage()); +} +try { + $chan->setPrefetchCount(PHP_INT_MAX); +} catch (\Throwable $t) { + printf("%s: %s\n", get_class($t), $t->getMessage()); +} +try { + $chan->setGlobalPrefetchCount(-1); +} catch (\Throwable $t) { + printf("%s: %s\n", get_class($t), $t->getMessage()); +} +try { + $chan->setGlobalPrefetchCount(PHP_INT_MAX); +} catch (\Throwable $t) { + printf("%s: %s\n", get_class($t), $t->getMessage()); +} +?> +==DONE== +--EXPECTF-- +AMQPConnectionException: Parameter 'prefetch_size' must be between 0 and 4294967295. +AMQPConnectionException: Parameter 'prefetch_size' must be between 0 and 4294967295. +AMQPConnectionException: Parameter 'global_prefetch_size' must be between 0 and 4294967295. +AMQPConnectionException: Parameter 'global_prefetch_size' must be between 0 and 4294967295. +AMQPConnectionException: Parameter 'prefetch_count' must be between 0 and 65535. +AMQPConnectionException: Parameter 'prefetch_count' must be between 0 and 65535. +AMQPConnectionException: Parameter 'global_prefetch_count' must be between 0 and 65535. +AMQPConnectionException: Parameter 'global_prefetch_count' must be between 0 and 65535. +==DONE== \ No newline at end of file diff --git a/tests/amqpconnection_validation.phpt b/tests/amqpconnection_validation.phpt new file mode 100644 index 00000000..afd43153 --- /dev/null +++ b/tests/amqpconnection_validation.phpt @@ -0,0 +1,103 @@ +--TEST-- +AMQPConnection parameter validation +--SKIPIF-- + +--FILE-- + $value]); + echo $getter . " after constructor: "; + echo $con1->{$getter}(); + echo PHP_EOL; + } catch (\Throwable $t) { + echo get_class($t); + echo ": "; + echo $t->getMessage(); + echo PHP_EOL; + } + if ($setter === null) { + continue; + } + $con2 = new AMQPConnection(); + try { + $con2->{$setter}($value); + echo $getter . " after setter: "; + echo $con2->{$getter}(); + echo PHP_EOL; + } catch (\Throwable $t) { + echo get_class($t); + echo ": "; + echo $t->getMessage(); + echo PHP_EOL; + } + } +} + +?> +==DONE== +--EXPECTF-- +AMQPConnectionException: Parameter 'login' exceeds 1024 character limit. +AMQPConnectionException: Parameter 'login' exceeds 1024 character limit. +getLogin after constructor: user +getLogin after setter: user +AMQPConnectionException: Parameter 'password' exceeds 1024 character limit. +AMQPConnectionException: Parameter 'password' exceeds 1024 character limit. +getPassword after constructor: pass +getPassword after setter: pass +AMQPConnectionException: Parameter 'host' exceeds 512 character limit. +AMQPConnectionException: Parameter 'host' exceeds 512 character limit. +getHost after constructor: host +getHost after setter: host +AMQPConnectionException: Parameter 'vhost' exceeds 512 character limit. +AMQPConnectionException: Parameter 'vhost' exceeds 512 characters limit. +getVhost after constructor: vhost +getVhost after setter: vhost +AMQPConnectionException: Parameter 'port' must be a valid port number between 1 and 65535. +AMQPConnectionException: Invalid port given. Value must be between 1 and 65535. +AMQPConnectionException: Parameter 'port' must be a valid port number between 1 and 65535. +AMQPConnectionException: Invalid port given. Value must be between 1 and 65535. +getPort after constructor: 1234 +getPort after setter: 1234 + +Deprecated: AMQPConnection::__construct(): Parameter 'timeout' is deprecated; use 'read_timeout' instead in %s on line %d +AMQPConnectionException: Parameter 'timeout' must be greater than or equal to zero. + +Deprecated: AMQPConnection::setTimeout(): AMQPConnection::setTimeout($timeout) method is deprecated; use AMQPConnection::setReadTimeout($timeout) instead in %s on line %d +AMQPConnectionException: Parameter 'timeout' must be greater than or equal to zero. +AMQPConnectionException: Parameter 'read_timeout' must be greater than or equal to zero. +AMQPConnectionException: Parameter 'read_timeout' must be greater than or equal to zero. +AMQPConnectionException: Parameter 'write_timeout' must be greater than or equal to zero. +AMQPConnectionException: Parameter 'write_timeout' must be greater than or equal to zero. +AMQPConnectionException: Parameter 'connect_timeout' must be greater than or equal to zero. +AMQPConnectionException: Parameter 'rpc_timeout' must be greater than or equal to zero. +AMQPConnectionException: Parameter 'rpc_timeout' must be greater than or equal to zero. +AMQPConnectionException: Parameter 'channel_max' is out of range. +AMQPConnectionException: Parameter 'channel_max' is out of range. +AMQPConnectionException: Parameter 'frame_max' is out of range. +AMQPConnectionException: Parameter 'frame_max' is out of range. +AMQPConnectionException: Parameter 'heartbeat' is out of range. +AMQPConnectionException: Parameter 'heartbeat' is out of range. +==DONE== \ No newline at end of file diff --git a/tests/ini_validation_failure.phpt b/tests/ini_validation_failure.phpt new file mode 100644 index 00000000..7c026de9 --- /dev/null +++ b/tests/ini_validation_failure.phpt @@ -0,0 +1,66 @@ +--TEST-- +Bad INI settings are rejected +--SKIPIF-- + +--INI-- +amqp.host=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +amqp.vhost=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +amqp.port=-1 +amqp.login=00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +amqp.password=00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +amqp.read_timeout=-1 +amqp.write_timeout=-1 +amqp.connect_timeout=-1 +amqp.rpc_timeout=-1 +amqp.timeout=-1 +amqp.prefetch_count=-1 +amqp.prefetch_size=-1 +amqp.global_prefetch_count=-1 +amqp.global_prefetch_size=-1 +amqp.heartbeat=-1 +amqp.channel_max=257 +amqp.frame_max=-1 +--FILE-- + +==DONE== +--EXPECT-- +string(9) "localhost" +string(1) "/" +string(4) "5672" +string(5) "guest" +string(5) "guest" +string(1) "0" +string(1) "0" +string(1) "0" +string(1) "0" +string(0) "" +string(1) "3" +string(1) "0" +string(1) "0" +string(1) "0" +string(1) "0" +string(3) "256" +string(6) "131072" +==DONE== \ No newline at end of file From cc1191019ebe2241402cfa8a618937c30a571f3f Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 26 Jul 2023 14:08:15 +0200 Subject: [PATCH 013/147] Update stubs --- amqp_timestamp.c | 2 +- stubs/AMQP.php | 2 +- stubs/AMQPChannel.php | 18 ++++++++++++++---- stubs/AMQPConnection.php | 6 ++++++ stubs/AMQPDecimal.php | 19 +++++++++++++++++-- stubs/AMQPTimestamp.php | 7 +++++++ 6 files changed, 46 insertions(+), 8 deletions(-) diff --git a/amqp_timestamp.c b/amqp_timestamp.c index 079a3e01..f63c85b8 100644 --- a/amqp_timestamp.c +++ b/amqp_timestamp.c @@ -64,7 +64,7 @@ static PHP_METHOD(amqp_timestamp_class, __construct) /* }}} */ -/* {{{ proto int AMQPTimestamp::getTimestamp() +/* {{{ proto string AMQPTimestamp::getTimestamp() Get timestamp */ static PHP_METHOD(amqp_timestamp_class, getTimestamp) { diff --git a/stubs/AMQP.php b/stubs/AMQP.php index 7cfabeff..33f26d97 100644 --- a/stubs/AMQP.php +++ b/stubs/AMQP.php @@ -140,4 +140,4 @@ /** * Writes the message to the disk when the message is placed in a durable queue. */ -define('AMQP_DELIVERY_MODE_PERSISTENT', 2) +define('AMQP_DELIVERY_MODE_PERSISTENT', 2); diff --git a/stubs/AMQPChannel.php b/stubs/AMQPChannel.php index d2e26ba6..c9d979c8 100644 --- a/stubs/AMQPChannel.php +++ b/stubs/AMQPChannel.php @@ -43,6 +43,8 @@ public function isConnected() /** * Closes the channel. + * + * @return void */ public function close() { @@ -235,6 +237,7 @@ public function getConnection() * Redeliver unacknowledged messages. * * @param bool $requeue + * @return bool */ public function basicRecover($requeue = true) { @@ -242,6 +245,8 @@ public function basicRecover($requeue = true) /** * Set the channel to use publisher acknowledgements. This can only used on a non-transactional channel. + * + * @return bool */ public function confirmSelect() { @@ -250,8 +255,6 @@ public function confirmSelect() /** * Set callback to process basic.ack and basic.nac AMQP server methods (applicable when channel in confirm mode). * - * @param callable|null $ack_callback - * @param callable|null $nack_callback * * Callback functions with all arguments have the following signature: * @@ -263,6 +266,9 @@ public function confirmSelect() * Note, basic.nack server method will only be delivered if an internal error occurs in the Erlang process * responsible for a queue (see https://www.rabbitmq.com/confirms.html for details). * + * @param callable|null $ack_callback + * @param callable|null $nack_callback + * @return void */ public function setConfirmCallback(callable $ack_callback=null, callable $nack_callback=null) { @@ -276,6 +282,8 @@ public function setConfirmCallback(callable $ack_callback=null, callable $nack_c * @param float $timeout Timeout in seconds. May be fractional. * * @throws AMQPQueueException If timeout occurs. + * + * @return void */ public function waitForConfirm($timeout = 0.0) { @@ -284,8 +292,6 @@ public function waitForConfirm($timeout = 0.0) /** * Set callback to process basic.return AMQP server method * - * @param callable|null $return_callback - * * Callback function with all arguments has the following signature: * * function callback(int $reply_code, @@ -297,6 +303,8 @@ public function waitForConfirm($timeout = 0.0) * * and should return boolean false when wait loop should be canceled. * + * @param callable|null $return_callback + * @return void */ public function setReturnCallback(callable $return_callback=null) { @@ -308,6 +316,8 @@ public function setReturnCallback(callable $return_callback=null) * @param float $timeout Timeout in seconds. May be fractional. * * @throws AMQPQueueException If timeout occurs. + * + * @return void */ public function waitForBasicReturn($timeout = 0.0) { diff --git a/stubs/AMQPConnection.php b/stubs/AMQPConnection.php index 8d630644..01e9a00a 100644 --- a/stubs/AMQPConnection.php +++ b/stubs/AMQPConnection.php @@ -417,6 +417,7 @@ public function getCACert() * Set path to the CA cert file in PEM format * * @param string $cacert + * @return bool */ public function setCACert($cacert) { @@ -435,6 +436,7 @@ public function getCert() * Set path to the client certificate in PEM format * * @param string $cert + * @return bool */ public function setCert($cert) { @@ -453,6 +455,7 @@ public function getKey() * Set path to the client key in PEM format * * @param string $key + * @return bool */ public function setKey($key) { @@ -471,6 +474,7 @@ public function getVerify() * Enable or disable peer verification * * @param bool $verify + * @return bool */ public function setVerify($verify) { @@ -480,6 +484,7 @@ public function setVerify($verify) * set authentication method * * @param int $method AMQP_SASL_METHOD_PLAIN | AMQP_SASL_METHOD_EXTERNAL + * @return bool */ public function setSaslMethod($method) { @@ -494,6 +499,7 @@ public function getSaslMethod() /** * @param string|null $connection_name + * @return bool */ public function setConnectionName($connection_name) { diff --git a/stubs/AMQPDecimal.php b/stubs/AMQPDecimal.php index caf836e0..0d563da8 100644 --- a/stubs/AMQPDecimal.php +++ b/stubs/AMQPDecimal.php @@ -5,14 +5,29 @@ */ final class AMQPDecimal { + /** + * @var int + */ const EXPONENT_MIN = 0; + + /** + * @var int + */ const EXPONENT_MAX = 255; + + /** + * @var int + */ const SIGNIFICAND_MIN = 0; + + /** + * @var int + */ const SIGNIFICAND_MAX = 4294967295; /** - * @param $exponent - * @param $significand + * @param int $exponent + * @param int $significand * * @throws AMQPValueException */ diff --git a/stubs/AMQPTimestamp.php b/stubs/AMQPTimestamp.php index f58561ef..b7073c69 100644 --- a/stubs/AMQPTimestamp.php +++ b/stubs/AMQPTimestamp.php @@ -5,7 +5,14 @@ */ final class AMQPTimestamp { + /** + * @var string + */ const MIN = "0"; + + /** + * @var string + */ const MAX = "18446744073709551616"; /** From 939d9afbb8c6a0cece9d6d57e779a487ea45a840 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 26 Jul 2023 15:37:48 +0200 Subject: [PATCH 014/147] More consistent return types for AMQPEnvelope (#435) * `AMQPEnvelope::getBody()` always returns a string now while previously it returned false for an empty body * `AMQPEnvelope::getHeader()` returns null for an unknown header instead of false * `AMQPEnvelope::getRoutingKey()` always returns a string now --- amqp_envelope.c | 8 +++--- stubs/AMQPEnvelope.php | 9 +++--- tests/amqpenvelope_construct.phpt | 4 +-- tests/amqpqueue_get_headers.phpt | 2 +- tests/bug_351.phpt | 47 +++++++++++++++++++++++++++++++ 5 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 tests/bug_351.phpt diff --git a/amqp_envelope.c b/amqp_envelope.c index 47daccf0..e39d33f1 100644 --- a/amqp_envelope.c +++ b/amqp_envelope.c @@ -107,7 +107,7 @@ static PHP_METHOD(amqp_envelope_class, getBody) { if (Z_STRLEN_P(zv) == 0) { /* BC */ - RETURN_FALSE; + RETURN_STRING(""); } RETURN_ZVAL(zv, 1, 0); @@ -171,7 +171,7 @@ static PHP_METHOD(amqp_envelope_class, getHeader) { /* Look for the hash key */ if ((tmp = zend_hash_str_find(HASH_OF(zv), key, key_len)) == NULL) { - RETURN_FALSE; + RETURN_NULL(); } RETURN_ZVAL(tmp, 1, 0); @@ -257,13 +257,13 @@ PHP_MINIT_FUNCTION (amqp_envelope) { INIT_CLASS_ENTRY(ce, "AMQPEnvelope", amqp_envelope_class_functions); this_ce = zend_register_internal_class_ex(&ce, amqp_basic_properties_class_entry TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("body"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_stringl(this_ce, ZEND_STRL("body"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_null(this_ce, ZEND_STRL("consumer_tag"), ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_null(this_ce, ZEND_STRL("delivery_tag"), ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_null(this_ce, ZEND_STRL("is_redelivery"), ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_null(this_ce, ZEND_STRL("exchange_name"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("routing_key"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_stringl(this_ce, ZEND_STRL("routing_key"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); return SUCCESS; } diff --git a/stubs/AMQPEnvelope.php b/stubs/AMQPEnvelope.php index 5a38a63a..d4046b9f 100644 --- a/stubs/AMQPEnvelope.php +++ b/stubs/AMQPEnvelope.php @@ -30,7 +30,7 @@ public function getRoutingKey() /** * Get the consumer tag of the message. * - * @return string The consumer tag of the message. + * @return string|null The consumer tag of the message. */ public function getConsumerTag() { @@ -39,7 +39,7 @@ public function getConsumerTag() /** * Get the delivery tag of the message. * - * @return integer The delivery tag of the message. + * @return integer|null The delivery tag of the message. */ public function getDeliveryTag() { @@ -48,7 +48,7 @@ public function getDeliveryTag() /** * Get the exchange name on which the message was published. * - * @return string The exchange name on which the message was published. + * @return string|null The exchange name on which the message was published. */ public function getExchangeName() { @@ -73,8 +73,7 @@ public function isRedelivery() * * @param string $header_key Name of the header to get the value from. * - * @return string|boolean The contents of the specified header or FALSE - * if not set. + * @return string|null The contents of the specified header or null if not set. */ public function getHeader($header_key) { diff --git a/tests/amqpenvelope_construct.phpt b/tests/amqpenvelope_construct.phpt index 6c634d80..5367e5fa 100644 --- a/tests/amqpenvelope_construct.phpt +++ b/tests/amqpenvelope_construct.phpt @@ -41,7 +41,7 @@ object(AMQPEnvelope)#1 (20) { ["cluster_id":"AMQPBasicProperties":private]=> string(0) "" ["body":"AMQPEnvelope":private]=> - NULL + string(0) "" ["consumer_tag":"AMQPEnvelope":private]=> NULL ["delivery_tag":"AMQPEnvelope":private]=> @@ -51,5 +51,5 @@ object(AMQPEnvelope)#1 (20) { ["exchange_name":"AMQPEnvelope":private]=> NULL ["routing_key":"AMQPEnvelope":private]=> - NULL + string(0) "" } diff --git a/tests/amqpqueue_get_headers.phpt b/tests/amqpqueue_get_headers.phpt index a0fe6e0f..cf60247f 100644 --- a/tests/amqpqueue_get_headers.phpt +++ b/tests/amqpqueue_get_headers.phpt @@ -59,4 +59,4 @@ bool(true) one 2 Has nonexistent header: false -Get nonexistent header: false +Get nonexistent header: NULL diff --git a/tests/bug_351.phpt b/tests/bug_351.phpt new file mode 100644 index 00000000..e272e111 --- /dev/null +++ b/tests/bug_351.phpt @@ -0,0 +1,47 @@ +--TEST-- +AMQPEnvelope::getBody returns false instead of empty string +--SKIPIF-- + +--FILE-- +connect(); + +$ch = new AMQPChannel($cnn); + +$ex = new AMQPExchange($ch); +$ex->setName('exchange' . microtime(true)); +$ex->setType(AMQP_EX_TYPE_FANOUT); +$ex->declareExchange(); + +$q = new AMQPQueue($ch); +$q->setName('queue1' . microtime(true)); +$q->declareQueue(); + +$q->bind($ex->getName(), '*'); + +$ex->publish(''); + +$msg = $q->get(AMQP_AUTOACK); +echo "MSG1\n"; +var_dump($msg->getBody(), $msg->getRoutingKey(), $msg->getConsumerTag(), $msg->getDeliveryTag(), $msg->getExchangeName()); + +$msg2 = new AMQPEnvelope(); +echo "MSG2\n"; +var_dump($msg2->getBody(), $msg2->getRoutingKey(), $msg2->getConsumerTag(), $msg2->getDeliveryTag(), $msg2->getExchangeName()); +?> +==DONE== +--EXPECTF-- +MSG1 +string(0) "" +string(0) "" +string(0) "" +int(%d) +string(%d) "exchange%s" +MSG2 +string(0) "" +string(0) "" +NULL +NULL +NULL +==DONE== \ No newline at end of file From 7b6a6443d6fea0dce155ab67cbd7640177a152ca Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 26 Jul 2023 18:03:29 +0200 Subject: [PATCH 015/147] Auto-format the codebase (#436) --- .clang-format | 85 ++ .github/workflows/test.yaml | 18 + README.md | 3 + amqp.c | 590 +++++----- amqp_basic_properties.c | 463 +++++--- amqp_basic_properties.h | 10 - amqp_channel.c | 1918 +++++++++++++++++-------------- amqp_channel.h | 9 - amqp_connection.c | 2144 +++++++++++++++++++++-------------- amqp_connection.h | 9 - amqp_connection_resource.c | 1006 ++++++++-------- amqp_connection_resource.h | 82 +- amqp_decimal.c | 88 +- amqp_decimal.h | 9 - amqp_envelope.c | 160 +-- amqp_envelope.h | 10 - amqp_exchange.c | 1248 ++++++++++---------- amqp_exchange.h | 9 - amqp_methods_handling.c | 313 ++--- amqp_methods_handling.h | 61 +- amqp_queue.c | 1916 +++++++++++++++++-------------- amqp_queue.h | 9 - amqp_timestamp.c | 109 +- amqp_timestamp.h | 9 - amqp_type.c | 584 +++++----- amqp_type.h | 26 +- php_amqp.h | 465 ++++---- tools/dev-build.sh | 5 + tools/dev-format.sh | 3 + 29 files changed, 6360 insertions(+), 5001 deletions(-) create mode 100644 .clang-format create mode 100755 tools/dev-build.sh create mode 100755 tools/dev-format.sh diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..33b9745a --- /dev/null +++ b/.clang-format @@ -0,0 +1,85 @@ +# Generated from CLion C/C++ Code Style settings +BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignConsecutiveAssignments: None +AlignOperands: Align + +AllowAllArgumentsOnNextLine: false +BinPackArguments: false +BinPackParameters: false +AlignAfterOpenBracket: BlockIndent +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false + +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterReturnType: None +AlwaysBreakTemplateDeclarations: Yes +BreakBeforeBraces: Custom +MacroBlockBegin: "(ZEND_BEGIN_ARG_INFO(_EX)?|PHP_INI_BEGIN)" +MacroBlockEnd: "(ZEND_END_ARG_INFO|PHP_INI_END)" +Macros: + - "PHP_ME(a, b, c, d)={a, b, c, d}," + - "PHP_MALIAS(a, b, c, d, e)={a, b, c, d, e}," + - "ZEND_HASH_FOREACH_KEY_VAL(a, b, c, d)=do {" + - "ZEND_HASH_FOREACH_STR_KEY(a, b)=do {" + - "ZEND_HASH_FOREACH_STR_KEY_VAL(a, b, c)=do {" + - "ZEND_HASH_FOREACH_END=} while(true)" +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: true +BreakBeforeBinaryOperators: None +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +ColumnLimit: 120 +CompactNamespaces: false +IndentCaseLabels: true +IndentPPDirectives: BeforeHash +IndentWidth: 4 +KeepEmptyLinesAtTheStartOfBlocks: true +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: All +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PointerAlignment: Right +ReferenceAlignment: Right +ReflowComments: false +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 0 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +TabWidth: 4 +UseTab: Never +AlignArrayOfStructures: Left +SortIncludes: Never +IndentWrappedFunctionNames: true +InsertNewlineAtEOF: true +PenaltyReturnTypeOnItsOwnLine: 9999 +PenaltyExcessCharacter: 100 \ No newline at end of file diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 43b3d2f6..e2a95abd 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,6 +10,24 @@ env: TEST_TIMEOUT: 120 jobs: + checkstyle: + name: Check coding style + runs-on: ubuntu-22.04 + steps: + - name: install clang-format + uses: myci-actions/add-deb-repo@11 + with: + repo: "deb https://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" + repo-name: llvm + keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key + install: clang-format-17 + + - name: Checkout + uses: actions/checkout@v3.5.3 + + - name: Check style + run: clang-format-17 --dry-run --Werror *.c *.h + test: name: php-${{ matrix.php-version }} librabbitmq-${{ matrix.librabbitmq-version }} ${{ matrix.test-php-args == '-m' && 'memory leaks' || '' }} runs-on: ${{ matrix.os }} diff --git a/README.md b/README.md index 5c45560f..d39315a6 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,9 @@ using `-Y amqp` attribute, just give a try - `tshark -i lo -Y amqp`. > NOTE: -w provides raw packet data, not text. If you want text output you need to redirect stdout (e.g. using '>'), don't use the -w option for this. +#### Formatting + +Run `./tools/dev-format.sh` to automatically format all `.c` and `.h` files. Note: this requires `clang-format` >=17. #### Configuring a RabbitMQ server diff --git a/amqp.c b/amqp.c index 8a26eb4a..36389622 100644 --- a/amqp.c +++ b/amqp.c @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H -#include "config.h" + #include "config.h" #endif #include "php.h" @@ -31,23 +31,23 @@ #include "zend_exceptions.h" #ifdef PHP_WIN32 -# if PHP_VERSION_ID >= 80000 -# include "main/php_stdint.h" -# else -# include "win32/php_stdint.h" -# endif -# include "win32/signal.h" + #if PHP_VERSION_ID >= 80000 + #include "main/php_stdint.h" + #else + #include "win32/php_stdint.h" + #endif + #include "win32/signal.h" #else -# include -# include + #include + #include #endif #if HAVE_LIBRABBITMQ_NEW_LAYOUT -#include -#include + #include + #include #else -#include -#include + #include + #include #endif #include "php_amqp.h" @@ -62,101 +62,85 @@ #include "amqp_decimal.h" #ifdef PHP_WIN32 -# include "win32/unistd.h" + #include "win32/unistd.h" #else -# include + #include #endif /* True global resources - no need for thread safety here */ -zend_class_entry *amqp_exception_class_entry, - *amqp_connection_exception_class_entry, - *amqp_channel_exception_class_entry, - *amqp_queue_exception_class_entry, - *amqp_exchange_exception_class_entry, - *amqp_envelope_exception_class_entry, - *amqp_value_exception_class_entry; +zend_class_entry *amqp_exception_class_entry, *amqp_connection_exception_class_entry, + *amqp_channel_exception_class_entry, *amqp_queue_exception_class_entry, *amqp_exchange_exception_class_entry, + *amqp_envelope_exception_class_entry, *amqp_value_exception_class_entry; /* {{{ amqp_functions[] * *Every user visible function must have an entry in amqp_functions[]. */ zend_function_entry amqp_functions[] = { - {NULL, NULL, NULL} + {NULL, NULL, NULL} }; /* }}} */ -zend_bool php_amqp_is_valid_identifier(zend_string *val) { +zend_bool php_amqp_is_valid_identifier(zend_string *val) +{ return ZSTR_LEN(val) > 0 && ZSTR_LEN(val) <= PHP_AMQP_MAX_IDENTIFIER_LENGTH; } -zend_bool php_amqp_is_valid_credential(zend_string *val) { +zend_bool php_amqp_is_valid_credential(zend_string *val) +{ return ZSTR_LEN(val) > 0 && ZSTR_LEN(val) <= PHP_AMQP_MAX_CREDENTIALS_LENGTH; } -zend_bool php_amqp_is_valid_port(zend_long val) { - return val >= PHP_AMQP_MIN_PORT && val <= PHP_AMQP_MAX_PORT; -} +zend_bool php_amqp_is_valid_port(zend_long val) { return val >= PHP_AMQP_MIN_PORT && val <= PHP_AMQP_MAX_PORT; } -zend_bool php_amqp_is_valid_timeout(double timeout) { - return timeout >= 0; -} +zend_bool php_amqp_is_valid_timeout(double timeout) { return timeout >= 0; } -zend_bool php_amqp_is_valid_channel_max(zend_long val) { - return val > 0 && val <= PHP_AMQP_DEFAULT_CHANNEL_MAX; -} +zend_bool php_amqp_is_valid_channel_max(zend_long val) { return val > 0 && val <= PHP_AMQP_DEFAULT_CHANNEL_MAX; } -zend_bool php_amqp_is_valid_frame_size_max(zend_long val) { - return val > 0 && val <= PHP_AMQP_MAX_FRAME_SIZE; -} +zend_bool php_amqp_is_valid_frame_size_max(zend_long val) { return val > 0 && val <= PHP_AMQP_MAX_FRAME_SIZE; } -zend_bool php_amqp_is_valid_heartbeat(zend_long val) { - return val > 0 && val <= PHP_AMQP_MAX_HEARTBEAT; -} +zend_bool php_amqp_is_valid_heartbeat(zend_long val) { return val > 0 && val <= PHP_AMQP_MAX_HEARTBEAT; } -zend_bool php_amqp_is_valid_prefetch_size(zend_long val) { - return val >= 0 && val <= PHP_AMQP_MAX_PREFETCH_SIZE; -} +zend_bool php_amqp_is_valid_prefetch_size(zend_long val) { return val >= 0 && val <= PHP_AMQP_MAX_PREFETCH_SIZE; } -zend_bool php_amqp_is_valid_prefetch_count(zend_long val) { - return val >= 0 && val <= PHP_AMQP_MAX_PREFETCH_COUNT; -} +zend_bool php_amqp_is_valid_prefetch_count(zend_long val) { return val >= 0 && val <= PHP_AMQP_MAX_PREFETCH_COUNT; } static ZEND_INI_MH(onUpdateIdentifier) { - if (new_value != NULL && !php_amqp_is_valid_identifier(new_value)) { - return FAILURE; - } + if (new_value != NULL && !php_amqp_is_valid_identifier(new_value)) { + return FAILURE; + } - return SUCCESS; + return SUCCESS; } static ZEND_INI_MH(onUpdateCredentials) { - if (new_value != NULL && !php_amqp_is_valid_credential(new_value)) { - return FAILURE; - } + if (new_value != NULL && !php_amqp_is_valid_credential(new_value)) { + return FAILURE; + } - return SUCCESS; + return SUCCESS; } static ZEND_INI_MH(onUpdatePort) { - zend_long val = zend_ini_parse_quantity_warn(new_value, entry->name); - if (!php_amqp_is_valid_port(val)) { - return FAILURE; - } + zend_long val = zend_ini_parse_quantity_warn(new_value, entry->name); + if (!php_amqp_is_valid_port(val)) { + return FAILURE; + } - return SUCCESS; + return SUCCESS; } static ZEND_INI_MH(onUpdateTimeout) { - if (!php_amqp_is_valid_timeout(zend_strtod(ZSTR_VAL(new_value), NULL))) { - return FAILURE; - } + if (!php_amqp_is_valid_timeout(zend_strtod(ZSTR_VAL(new_value), NULL))) { + return FAILURE; + } - return SUCCESS; + return SUCCESS; } static ZEND_INI_MH(onUpdateChannelMax) @@ -191,12 +175,12 @@ static ZEND_INI_MH(onUpdateHeartbeat) static ZEND_INI_MH(onUpdatePrefetchCount) { - zend_long val = zend_ini_parse_quantity_warn(new_value, entry->name); - if (!php_amqp_is_valid_prefetch_count(val)) { - return FAILURE; - } + zend_long val = zend_ini_parse_quantity_warn(new_value, entry->name); + if (!php_amqp_is_valid_prefetch_count(val)) { + return FAILURE; + } - return SUCCESS; + return SUCCESS; } static ZEND_INI_MH(onUpdatePrefetchSize) @@ -210,276 +194,302 @@ static ZEND_INI_MH(onUpdatePrefetchSize) } PHP_INI_BEGIN() - PHP_INI_ENTRY("amqp.host", DEFAULT_HOST, PHP_INI_ALL, onUpdateIdentifier) - PHP_INI_ENTRY("amqp.vhost", DEFAULT_VHOST, PHP_INI_ALL, onUpdateIdentifier) - PHP_INI_ENTRY("amqp.port", DEFAULT_PORT, PHP_INI_ALL, onUpdatePort) - PHP_INI_ENTRY("amqp.timeout", DEFAULT_TIMEOUT, PHP_INI_ALL, onUpdateTimeout) - PHP_INI_ENTRY("amqp.read_timeout", DEFAULT_READ_TIMEOUT, PHP_INI_ALL, onUpdateTimeout) - PHP_INI_ENTRY("amqp.write_timeout", DEFAULT_WRITE_TIMEOUT, PHP_INI_ALL, onUpdateTimeout) - PHP_INI_ENTRY("amqp.connect_timeout", DEFAULT_CONNECT_TIMEOUT, PHP_INI_ALL, onUpdateTimeout) - PHP_INI_ENTRY("amqp.rpc_timeout", DEFAULT_RPC_TIMEOUT, PHP_INI_ALL, onUpdateTimeout) - PHP_INI_ENTRY("amqp.login", DEFAULT_LOGIN, PHP_INI_ALL, onUpdateCredentials) - PHP_INI_ENTRY("amqp.password", DEFAULT_PASSWORD, PHP_INI_ALL, onUpdateCredentials) - PHP_INI_ENTRY("amqp.auto_ack", DEFAULT_AUTOACK, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("amqp.prefetch_count", DEFAULT_PREFETCH_COUNT, PHP_INI_ALL, onUpdatePrefetchCount) - PHP_INI_ENTRY("amqp.prefetch_size", DEFAULT_PREFETCH_SIZE, PHP_INI_ALL, onUpdatePrefetchSize) - PHP_INI_ENTRY("amqp.global_prefetch_count", DEFAULT_GLOBAL_PREFETCH_COUNT, PHP_INI_ALL, onUpdatePrefetchCount) - PHP_INI_ENTRY("amqp.global_prefetch_size", DEFAULT_GLOBAL_PREFETCH_SIZE, PHP_INI_ALL, onUpdatePrefetchSize) - PHP_INI_ENTRY("amqp.channel_max", DEFAULT_CHANNEL_MAX, PHP_INI_ALL, onUpdateChannelMax) - PHP_INI_ENTRY("amqp.frame_max", DEFAULT_FRAME_MAX, PHP_INI_ALL, onUpdateFrameSizeMax) - PHP_INI_ENTRY("amqp.heartbeat", DEFAULT_HEARTBEAT, PHP_INI_ALL, onUpdateHeartbeat) - PHP_INI_ENTRY("amqp.cacert", DEFAULT_CACERT, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("amqp.cert", DEFAULT_CERT, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("amqp.key", DEFAULT_KEY, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("amqp.verify", DEFAULT_VERIFY, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("amqp.sasl_method", DEFAULT_SASL_METHOD, PHP_INI_ALL, NULL) + PHP_INI_ENTRY("amqp.host", DEFAULT_HOST, PHP_INI_ALL, onUpdateIdentifier) + PHP_INI_ENTRY("amqp.vhost", DEFAULT_VHOST, PHP_INI_ALL, onUpdateIdentifier) + PHP_INI_ENTRY("amqp.port", DEFAULT_PORT, PHP_INI_ALL, onUpdatePort) + PHP_INI_ENTRY("amqp.timeout", DEFAULT_TIMEOUT, PHP_INI_ALL, onUpdateTimeout) + PHP_INI_ENTRY("amqp.read_timeout", DEFAULT_READ_TIMEOUT, PHP_INI_ALL, onUpdateTimeout) + PHP_INI_ENTRY("amqp.write_timeout", DEFAULT_WRITE_TIMEOUT, PHP_INI_ALL, onUpdateTimeout) + PHP_INI_ENTRY("amqp.connect_timeout", DEFAULT_CONNECT_TIMEOUT, PHP_INI_ALL, onUpdateTimeout) + PHP_INI_ENTRY("amqp.rpc_timeout", DEFAULT_RPC_TIMEOUT, PHP_INI_ALL, onUpdateTimeout) + PHP_INI_ENTRY("amqp.login", DEFAULT_LOGIN, PHP_INI_ALL, onUpdateCredentials) + PHP_INI_ENTRY("amqp.password", DEFAULT_PASSWORD, PHP_INI_ALL, onUpdateCredentials) + PHP_INI_ENTRY("amqp.auto_ack", DEFAULT_AUTOACK, PHP_INI_ALL, NULL) + PHP_INI_ENTRY("amqp.prefetch_count", DEFAULT_PREFETCH_COUNT, PHP_INI_ALL, onUpdatePrefetchCount) + PHP_INI_ENTRY("amqp.prefetch_size", DEFAULT_PREFETCH_SIZE, PHP_INI_ALL, onUpdatePrefetchSize) + PHP_INI_ENTRY("amqp.global_prefetch_count", DEFAULT_GLOBAL_PREFETCH_COUNT, PHP_INI_ALL, onUpdatePrefetchCount) + PHP_INI_ENTRY("amqp.global_prefetch_size", DEFAULT_GLOBAL_PREFETCH_SIZE, PHP_INI_ALL, onUpdatePrefetchSize) + PHP_INI_ENTRY("amqp.channel_max", DEFAULT_CHANNEL_MAX, PHP_INI_ALL, onUpdateChannelMax) + PHP_INI_ENTRY("amqp.frame_max", DEFAULT_FRAME_MAX, PHP_INI_ALL, onUpdateFrameSizeMax) + PHP_INI_ENTRY("amqp.heartbeat", DEFAULT_HEARTBEAT, PHP_INI_ALL, onUpdateHeartbeat) + PHP_INI_ENTRY("amqp.cacert", DEFAULT_CACERT, PHP_INI_ALL, NULL) + PHP_INI_ENTRY("amqp.cert", DEFAULT_CERT, PHP_INI_ALL, NULL) + PHP_INI_ENTRY("amqp.key", DEFAULT_KEY, PHP_INI_ALL, NULL) + PHP_INI_ENTRY("amqp.verify", DEFAULT_VERIFY, PHP_INI_ALL, NULL) + PHP_INI_ENTRY("amqp.sasl_method", DEFAULT_SASL_METHOD, PHP_INI_ALL, NULL) PHP_INI_END() ZEND_DECLARE_MODULE_GLOBALS(amqp) static PHP_GINIT_FUNCTION(amqp) /* {{{ */ { - amqp_globals->error_message = NULL; - amqp_globals->error_code = 0; + amqp_globals->error_message = NULL; + amqp_globals->error_code = 0; } /* }}} */ static PHP_MINIT_FUNCTION(amqp) /* {{{ */ { - zend_class_entry ce; - - /* Set up the connection resource */ - le_amqp_connection_resource = zend_register_list_destructors_ex(amqp_connection_resource_dtor, NULL, PHP_AMQP_CONNECTION_RES_NAME, module_number); - le_amqp_connection_resource_persistent = zend_register_list_destructors_ex(NULL, amqp_connection_resource_dtor_persistent, PHP_AMQP_CONNECTION_RES_NAME, module_number); - - PHP_MINIT(amqp_connection)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(amqp_channel)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(amqp_queue)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(amqp_exchange)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(amqp_basic_properties)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(amqp_envelope)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(amqp_timestamp)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(amqp_decimal)(INIT_FUNC_ARGS_PASSTHRU); - - /* Class Exceptions */ - INIT_CLASS_ENTRY(ce, "AMQPException", NULL); - amqp_exception_class_entry = zend_register_internal_class_ex(&ce, zend_exception_get_default(TSRMLS_C)); - - INIT_CLASS_ENTRY(ce, "AMQPConnectionException", NULL); - amqp_connection_exception_class_entry = zend_register_internal_class_ex(&ce, amqp_exception_class_entry); - - INIT_CLASS_ENTRY(ce, "AMQPChannelException", NULL); - amqp_channel_exception_class_entry = zend_register_internal_class_ex(&ce, amqp_exception_class_entry); - - INIT_CLASS_ENTRY(ce, "AMQPQueueException", NULL); - amqp_queue_exception_class_entry = zend_register_internal_class_ex(&ce, amqp_exception_class_entry); - - INIT_CLASS_ENTRY(ce, "AMQPEnvelopeException", NULL); - amqp_envelope_exception_class_entry = zend_register_internal_class_ex(&ce, amqp_exception_class_entry); - zend_declare_property_null(amqp_envelope_exception_class_entry, ZEND_STRL("envelope"), ZEND_ACC_PUBLIC TSRMLS_CC); - - INIT_CLASS_ENTRY(ce, "AMQPExchangeException", NULL); - amqp_exchange_exception_class_entry = zend_register_internal_class_ex(&ce, amqp_exception_class_entry); - - INIT_CLASS_ENTRY(ce, "AMQPValueException", NULL); - amqp_value_exception_class_entry = zend_register_internal_class_ex(&ce, amqp_exception_class_entry); - - REGISTER_INI_ENTRIES(); - - REGISTER_LONG_CONSTANT("AMQP_NOPARAM", AMQP_NOPARAM, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("AMQP_JUST_CONSUME", AMQP_JUST_CONSUME, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("AMQP_DURABLE", AMQP_DURABLE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("AMQP_PASSIVE", AMQP_PASSIVE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("AMQP_EXCLUSIVE", AMQP_EXCLUSIVE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("AMQP_AUTODELETE", AMQP_AUTODELETE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("AMQP_INTERNAL", AMQP_INTERNAL, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("AMQP_NOLOCAL", AMQP_NOLOCAL, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("AMQP_AUTOACK", AMQP_AUTOACK, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("AMQP_IFEMPTY", AMQP_IFEMPTY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("AMQP_IFUNUSED", AMQP_IFUNUSED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("AMQP_MANDATORY", AMQP_MANDATORY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("AMQP_IMMEDIATE", AMQP_IMMEDIATE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("AMQP_MULTIPLE", AMQP_MULTIPLE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("AMQP_NOWAIT", AMQP_NOWAIT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("AMQP_REQUEUE", AMQP_REQUEUE, CONST_CS | CONST_PERSISTENT); - - REGISTER_STRING_CONSTANT("AMQP_EX_TYPE_DIRECT", AMQP_EX_TYPE_DIRECT, CONST_CS | CONST_PERSISTENT); - REGISTER_STRING_CONSTANT("AMQP_EX_TYPE_FANOUT", AMQP_EX_TYPE_FANOUT, CONST_CS | CONST_PERSISTENT); - REGISTER_STRING_CONSTANT("AMQP_EX_TYPE_TOPIC", AMQP_EX_TYPE_TOPIC, CONST_CS | CONST_PERSISTENT); - REGISTER_STRING_CONSTANT("AMQP_EX_TYPE_HEADERS",AMQP_EX_TYPE_HEADERS, CONST_CS | CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("AMQP_OS_SOCKET_TIMEOUT_ERRNO", AMQP_OS_SOCKET_TIMEOUT_ERRNO, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PHP_AMQP_MAX_CHANNELS", PHP_AMQP_MAX_CHANNELS, CONST_CS | CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("AMQP_SASL_METHOD_PLAIN", AMQP_SASL_METHOD_PLAIN, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("AMQP_SASL_METHOD_EXTERNAL", AMQP_SASL_METHOD_EXTERNAL, CONST_CS | CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("AMQP_DELIVERY_MODE_TRANSIENT", AMQP_DELIVERY_NONPERSISTENT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("AMQP_DELIVERY_MODE_PERSISTENT", AMQP_DELIVERY_PERSISTENT, CONST_CS | CONST_PERSISTENT); - - return SUCCESS; + zend_class_entry ce; + + /* Set up the connection resource */ + le_amqp_connection_resource = zend_register_list_destructors_ex( + amqp_connection_resource_dtor, + NULL, + PHP_AMQP_CONNECTION_RES_NAME, + module_number + ); + le_amqp_connection_resource_persistent = zend_register_list_destructors_ex( + NULL, + amqp_connection_resource_dtor_persistent, + PHP_AMQP_CONNECTION_RES_NAME, + module_number + ); + + PHP_MINIT(amqp_connection)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(amqp_channel)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(amqp_queue)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(amqp_exchange)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(amqp_basic_properties)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(amqp_envelope)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(amqp_timestamp)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(amqp_decimal)(INIT_FUNC_ARGS_PASSTHRU); + + /* Class Exceptions */ + INIT_CLASS_ENTRY(ce, "AMQPException", NULL); + amqp_exception_class_entry = zend_register_internal_class_ex(&ce, zend_exception_get_default(TSRMLS_C)); + + INIT_CLASS_ENTRY(ce, "AMQPConnectionException", NULL); + amqp_connection_exception_class_entry = zend_register_internal_class_ex(&ce, amqp_exception_class_entry); + + INIT_CLASS_ENTRY(ce, "AMQPChannelException", NULL); + amqp_channel_exception_class_entry = zend_register_internal_class_ex(&ce, amqp_exception_class_entry); + + INIT_CLASS_ENTRY(ce, "AMQPQueueException", NULL); + amqp_queue_exception_class_entry = zend_register_internal_class_ex(&ce, amqp_exception_class_entry); + + INIT_CLASS_ENTRY(ce, "AMQPEnvelopeException", NULL); + amqp_envelope_exception_class_entry = zend_register_internal_class_ex(&ce, amqp_exception_class_entry); + zend_declare_property_null(amqp_envelope_exception_class_entry, ZEND_STRL("envelope"), ZEND_ACC_PUBLIC TSRMLS_CC); + + INIT_CLASS_ENTRY(ce, "AMQPExchangeException", NULL); + amqp_exchange_exception_class_entry = zend_register_internal_class_ex(&ce, amqp_exception_class_entry); + + INIT_CLASS_ENTRY(ce, "AMQPValueException", NULL); + amqp_value_exception_class_entry = zend_register_internal_class_ex(&ce, amqp_exception_class_entry); + + REGISTER_INI_ENTRIES(); + + REGISTER_LONG_CONSTANT("AMQP_NOPARAM", AMQP_NOPARAM, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("AMQP_JUST_CONSUME", AMQP_JUST_CONSUME, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("AMQP_DURABLE", AMQP_DURABLE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("AMQP_PASSIVE", AMQP_PASSIVE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("AMQP_EXCLUSIVE", AMQP_EXCLUSIVE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("AMQP_AUTODELETE", AMQP_AUTODELETE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("AMQP_INTERNAL", AMQP_INTERNAL, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("AMQP_NOLOCAL", AMQP_NOLOCAL, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("AMQP_AUTOACK", AMQP_AUTOACK, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("AMQP_IFEMPTY", AMQP_IFEMPTY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("AMQP_IFUNUSED", AMQP_IFUNUSED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("AMQP_MANDATORY", AMQP_MANDATORY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("AMQP_IMMEDIATE", AMQP_IMMEDIATE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("AMQP_MULTIPLE", AMQP_MULTIPLE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("AMQP_NOWAIT", AMQP_NOWAIT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("AMQP_REQUEUE", AMQP_REQUEUE, CONST_CS | CONST_PERSISTENT); + + REGISTER_STRING_CONSTANT("AMQP_EX_TYPE_DIRECT", AMQP_EX_TYPE_DIRECT, CONST_CS | CONST_PERSISTENT); + REGISTER_STRING_CONSTANT("AMQP_EX_TYPE_FANOUT", AMQP_EX_TYPE_FANOUT, CONST_CS | CONST_PERSISTENT); + REGISTER_STRING_CONSTANT("AMQP_EX_TYPE_TOPIC", AMQP_EX_TYPE_TOPIC, CONST_CS | CONST_PERSISTENT); + REGISTER_STRING_CONSTANT("AMQP_EX_TYPE_HEADERS", AMQP_EX_TYPE_HEADERS, CONST_CS | CONST_PERSISTENT); + + REGISTER_LONG_CONSTANT("AMQP_OS_SOCKET_TIMEOUT_ERRNO", AMQP_OS_SOCKET_TIMEOUT_ERRNO, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("PHP_AMQP_MAX_CHANNELS", PHP_AMQP_MAX_CHANNELS, CONST_CS | CONST_PERSISTENT); + + REGISTER_LONG_CONSTANT("AMQP_SASL_METHOD_PLAIN", AMQP_SASL_METHOD_PLAIN, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("AMQP_SASL_METHOD_EXTERNAL", AMQP_SASL_METHOD_EXTERNAL, CONST_CS | CONST_PERSISTENT); + + REGISTER_LONG_CONSTANT("AMQP_DELIVERY_MODE_TRANSIENT", AMQP_DELIVERY_NONPERSISTENT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("AMQP_DELIVERY_MODE_PERSISTENT", AMQP_DELIVERY_PERSISTENT, CONST_CS | CONST_PERSISTENT); + + return SUCCESS; } /* }}} */ static PHP_MSHUTDOWN_FUNCTION(amqp) /* {{{ */ { - UNREGISTER_INI_ENTRIES(); + UNREGISTER_INI_ENTRIES(); - return SUCCESS; + return SUCCESS; } /* }}} */ static PHP_RSHUTDOWN_FUNCTION(amqp) /* {{{ */ { - if (NULL != PHP_AMQP_G(error_message)) { - efree(PHP_AMQP_G(error_message)); - PHP_AMQP_G(error_message) = NULL; - } + if (NULL != PHP_AMQP_G(error_message)) { + efree(PHP_AMQP_G(error_message)); + PHP_AMQP_G(error_message) = NULL; + } - PHP_AMQP_G(error_code) = 0; + PHP_AMQP_G(error_code) = 0; - return SUCCESS; + return SUCCESS; } /* }}} */ static PHP_MINFO_FUNCTION(amqp) /* {{{ */ { - php_info_print_table_start(); - php_info_print_table_header(2, "Version", PHP_AMQP_VERSION); - php_info_print_table_header(2, "Revision", PHP_AMQP_REVISION); - php_info_print_table_header(2, "Compiled", __DATE__ " @ " __TIME__); - php_info_print_table_header(2, "AMQP protocol version", "0-9-1"); - php_info_print_table_header(2, "librabbitmq version", amqp_version()); - php_info_print_table_header(2, "Default max channels per connection", DEFAULT_CHANNEL_MAX); - php_info_print_table_header(2, "Default max frame size", DEFAULT_FRAME_MAX); - php_info_print_table_header(2, "Default heartbeats interval", DEFAULT_HEARTBEAT); - DISPLAY_INI_ENTRIES(); + php_info_print_table_start(); + php_info_print_table_header(2, "Version", PHP_AMQP_VERSION); + php_info_print_table_header(2, "Revision", PHP_AMQP_REVISION); + php_info_print_table_header(2, "Compiled", __DATE__ " @ " __TIME__); + php_info_print_table_header(2, "AMQP protocol version", "0-9-1"); + php_info_print_table_header(2, "librabbitmq version", amqp_version()); + php_info_print_table_header(2, "Default max channels per connection", DEFAULT_CHANNEL_MAX); + php_info_print_table_header(2, "Default max frame size", DEFAULT_FRAME_MAX); + php_info_print_table_header(2, "Default heartbeats interval", DEFAULT_HEARTBEAT); + DISPLAY_INI_ENTRIES(); } /* }}} */ /* {{{ amqp_module_entry */ zend_module_entry amqp_module_entry = { - STANDARD_MODULE_HEADER, - "amqp", - amqp_functions, - PHP_MINIT(amqp), - PHP_MSHUTDOWN(amqp), - NULL, - PHP_RSHUTDOWN(amqp), - PHP_MINFO(amqp), - PHP_AMQP_VERSION, - PHP_MODULE_GLOBALS(amqp), - PHP_GINIT(amqp), - NULL, - NULL, - STANDARD_MODULE_PROPERTIES_EX + STANDARD_MODULE_HEADER, + "amqp", + amqp_functions, + PHP_MINIT(amqp), + PHP_MSHUTDOWN(amqp), + NULL, + PHP_RSHUTDOWN(amqp), + PHP_MINFO(amqp), + PHP_AMQP_VERSION, + PHP_MODULE_GLOBALS(amqp), + PHP_GINIT(amqp), + NULL, + NULL, + STANDARD_MODULE_PROPERTIES_EX }; /* }}} */ #ifdef COMPILE_DL_AMQP - ZEND_GET_MODULE(amqp) +ZEND_GET_MODULE(amqp) #endif -int php_amqp_error(amqp_rpc_reply_t reply, char **message, amqp_connection_resource *connection_resource, amqp_channel_resource *channel_resource TSRMLS_DC) +int php_amqp_error( + amqp_rpc_reply_t reply, + char **message, + amqp_connection_resource *connection_resource, + amqp_channel_resource *channel_resource TSRMLS_DC +) { - return php_amqp_error_advanced(reply, message, connection_resource, channel_resource, 1 TSRMLS_CC); + return php_amqp_error_advanced(reply, message, connection_resource, channel_resource, 1 TSRMLS_CC); } -int php_amqp_error_advanced(amqp_rpc_reply_t reply, char **message, amqp_connection_resource *connection_resource, amqp_channel_resource *channel_resource, int fail_on_errors TSRMLS_DC) +int php_amqp_error_advanced( + amqp_rpc_reply_t reply, + char **message, + amqp_connection_resource *connection_resource, + amqp_channel_resource *channel_resource, + int fail_on_errors TSRMLS_DC +) { - assert(connection_resource != NULL); - - PHP_AMQP_G(error_code) = 0; - if (*message != NULL) { - efree(*message); - } - - int res = php_amqp_connection_resource_error(reply, message, connection_resource, (amqp_channel_t)(channel_resource ? channel_resource->channel_id : 0) TSRMLS_CC); - - switch (res) { - case PHP_AMQP_RESOURCE_RESPONSE_OK: - break; - case PHP_AMQP_RESOURCE_RESPONSE_ERROR: - if (!fail_on_errors) { - break; - } - /* Library or other non-protocol or even protocol related errors may be here. */ - /* In most cases it designate some underlying hard errors. Fail fast. */ - case PHP_AMQP_RESOURCE_RESPONSE_ERROR_CONNECTION_CLOSED: - /* Mark connection resource as closed to prevent sending any further requests */ - connection_resource->is_connected = '\0'; - - /* Close connection with all its channels */ - php_amqp_disconnect_force(connection_resource TSRMLS_CC); - - break; - case PHP_AMQP_RESOURCE_RESPONSE_ERROR_CHANNEL_CLOSED: - /* Mark channel as closed to prevent sending channel.close request */ - assert(channel_resource != NULL); - if (channel_resource) { - channel_resource->is_connected = '\0'; - - /* Close channel */ - php_amqp_close_channel(channel_resource, 1 TSRMLS_CC); - } - /* No more error handling necessary, returning. */ - break; - default: - spprintf(message, 0, "Unknown server error, method id 0x%08X (not handled by extension)", reply.reply.id); - break; - } - - return res; + assert(connection_resource != NULL); + + PHP_AMQP_G(error_code) = 0; + if (*message != NULL) { + efree(*message); + } + + int res = php_amqp_connection_resource_error( + reply, + message, + connection_resource, + (amqp_channel_t) (channel_resource ? channel_resource->channel_id : 0) TSRMLS_CC + ); + + switch (res) { + case PHP_AMQP_RESOURCE_RESPONSE_OK: + break; + case PHP_AMQP_RESOURCE_RESPONSE_ERROR: + if (!fail_on_errors) { + break; + } + /* Library or other non-protocol or even protocol related errors may be here. */ + /* In most cases it designate some underlying hard errors. Fail fast. */ + case PHP_AMQP_RESOURCE_RESPONSE_ERROR_CONNECTION_CLOSED: + /* Mark connection resource as closed to prevent sending any further requests */ + connection_resource->is_connected = '\0'; + + /* Close connection with all its channels */ + php_amqp_disconnect_force(connection_resource TSRMLS_CC); + + break; + case PHP_AMQP_RESOURCE_RESPONSE_ERROR_CHANNEL_CLOSED: + /* Mark channel as closed to prevent sending channel.close request */ + assert(channel_resource != NULL); + if (channel_resource) { + channel_resource->is_connected = '\0'; + + /* Close channel */ + php_amqp_close_channel(channel_resource, 1 TSRMLS_CC); + } + /* No more error handling necessary, returning. */ + break; + default: + spprintf(message, 0, "Unknown server error, method id 0x%08X (not handled by extension)", reply.reply.id); + break; + } + + return res; } -void php_amqp_zend_throw_exception_short(amqp_rpc_reply_t reply, zend_class_entry *exception_ce TSRMLS_DC) { - php_amqp_zend_throw_exception(reply, exception_ce, PHP_AMQP_G(error_message), PHP_AMQP_G(error_code) TSRMLS_CC); +void php_amqp_zend_throw_exception_short(amqp_rpc_reply_t reply, zend_class_entry *exception_ce TSRMLS_DC) +{ + php_amqp_zend_throw_exception(reply, exception_ce, PHP_AMQP_G(error_message), PHP_AMQP_G(error_code) TSRMLS_CC); } -void php_amqp_zend_throw_exception(amqp_rpc_reply_t reply, zend_class_entry *exception_ce, const char *message, zend_long code TSRMLS_DC) +void php_amqp_zend_throw_exception( + amqp_rpc_reply_t reply, + zend_class_entry *exception_ce, + const char *message, + zend_long code TSRMLS_DC +) { - switch (reply.reply_type) { - case AMQP_RESPONSE_NORMAL: - break; - case AMQP_RESPONSE_NONE: - exception_ce = amqp_exception_class_entry; - break; - case AMQP_RESPONSE_LIBRARY_EXCEPTION: - exception_ce = amqp_exception_class_entry; - break; - case AMQP_RESPONSE_SERVER_EXCEPTION: - switch (reply.reply.id) { - case AMQP_CONNECTION_CLOSE_METHOD: - /* Fatal errors - pass them to connection level */ - exception_ce = amqp_connection_exception_class_entry; - break; - case AMQP_CHANNEL_CLOSE_METHOD: - /* Most channel-level errors occurs due to previously known action and thus their kind can be predicted. */ - /* exception_ce = amqp_channel_exception_class_entry; */ - break; - } - break; - /* Default for the above switch should be handled by the below default. */ - default: - exception_ce = amqp_exception_class_entry; - break; - } - - zend_throw_exception(exception_ce, message, code TSRMLS_CC); + switch (reply.reply_type) { + case AMQP_RESPONSE_NORMAL: + break; + case AMQP_RESPONSE_NONE: + exception_ce = amqp_exception_class_entry; + break; + case AMQP_RESPONSE_LIBRARY_EXCEPTION: + exception_ce = amqp_exception_class_entry; + break; + case AMQP_RESPONSE_SERVER_EXCEPTION: + switch (reply.reply.id) { + case AMQP_CONNECTION_CLOSE_METHOD: + /* Fatal errors - pass them to connection level */ + exception_ce = amqp_connection_exception_class_entry; + break; + case AMQP_CHANNEL_CLOSE_METHOD: + /* Most channel-level errors occurs due to previously known action and thus their kind can be predicted. */ + /* exception_ce = amqp_channel_exception_class_entry; */ + break; + } + break; + /* Default for the above switch should be handled by the below default. */ + default: + exception_ce = amqp_exception_class_entry; + break; + } + + zend_throw_exception(exception_ce, message, code TSRMLS_CC); } -void php_amqp_maybe_release_buffers_on_channel(amqp_connection_resource *connection_resource, amqp_channel_resource *channel_resource) +void php_amqp_maybe_release_buffers_on_channel( + amqp_connection_resource *connection_resource, + amqp_channel_resource *channel_resource +) { - assert(channel_resource != NULL); - assert(channel_resource->channel_id > 0); + assert(channel_resource != NULL); + assert(channel_resource->channel_id > 0); - if (connection_resource) { - amqp_maybe_release_buffers_on_channel(connection_resource->connection_state, channel_resource->channel_id); - } + if (connection_resource) { + amqp_maybe_release_buffers_on_channel(connection_resource->connection_state, channel_resource->channel_id); + } } - -/* -*Local variables: -*tab-width: 4 -*c-basic-offset: 4 -*End: -*vim600: noet sw=4 ts=4 fdm=marker -*vim<600: noet sw=4 ts=4 -*/ diff --git a/amqp_basic_properties.c b/amqp_basic_properties.c index 8f5f4340..37ec67b6 100644 --- a/amqp_basic_properties.c +++ b/amqp_basic_properties.c @@ -22,7 +22,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" + #include "config.h" #endif #include "php.h" @@ -32,29 +32,29 @@ #include "Zend/zend_interfaces.h" #if HAVE_LIBRABBITMQ_NEW_LAYOUT -#include -#include + #include + #include #else -#include -#include + #include + #include #endif #ifdef PHP_WIN32 -# include "win32/unistd.h" -# if PHP_VERSION_ID >= 80000 -# include "main/php_stdint.h" -# else -# include "win32/php_stdint.h" -# endif -# include "win32/signal.h" + #include "win32/unistd.h" + #if PHP_VERSION_ID >= 80000 + #include "main/php_stdint.h" + #else + #include "win32/php_stdint.h" + #endif + #include "win32/signal.h" #else -# include -# include -# include + #include + #include + #include #endif #if HAVE_INTTYPES_H -# include + #include #endif #include "amqp_basic_properties.h" @@ -73,7 +73,8 @@ void php_amqp_basic_properties_convert_to_zval(amqp_basic_properties_t *props, z php_amqp_basic_properties_extract(props, obj TSRMLS_CC); } -void php_amqp_basic_properties_set_empty_headers(zval *obj TSRMLS_DC) { +void php_amqp_basic_properties_set_empty_headers(zval *obj TSRMLS_DC) +{ zval headers; ZVAL_UNDEF(&headers); @@ -81,54 +82,89 @@ void php_amqp_basic_properties_set_empty_headers(zval *obj TSRMLS_DC) { zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("headers"), &headers TSRMLS_CC); - zval_ptr_dtor(&headers); + zval_ptr_dtor(&headers); } /* {{{ proto AMQPBasicProperties::__construct() */ -static PHP_METHOD(AMQPBasicProperties, __construct) { +static PHP_METHOD(AMQPBasicProperties, __construct) +{ - char *content_type = NULL; size_t content_type_len = 0; - char *content_encoding = NULL; size_t content_encoding_len = 0; + char *content_type = NULL; + size_t content_type_len = 0; + char *content_encoding = NULL; + size_t content_encoding_len = 0; zval *headers = NULL; zend_long delivery_mode = AMQP_DELIVERY_NONPERSISTENT; zend_long priority = 0; - char *correlation_id = NULL; size_t correlation_id_len = 0; - char *reply_to = NULL; size_t reply_to_len = 0; - char *expiration = NULL; size_t expiration_len = 0; - char *message_id = NULL; size_t message_id_len = 0; + char *correlation_id = NULL; + size_t correlation_id_len = 0; + char *reply_to = NULL; + size_t reply_to_len = 0; + char *expiration = NULL; + size_t expiration_len = 0; + char *message_id = NULL; + size_t message_id_len = 0; zend_long timestamp = 0; - char *type = NULL; size_t type_len = 0; - char *user_id = NULL; size_t user_id_len = 0; - char *app_id = NULL; size_t app_id_len = 0; - char *cluster_id = NULL; size_t cluster_id_len = 0; - - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ssallsssslssss", - /* s */ &content_type, &content_type_len, - /* s */ &content_encoding, &content_encoding_len, - /* a */ &headers, - /* l */ &delivery_mode, - /* l */ &priority, - /* s */ &correlation_id, &correlation_id_len, - /* s */ &reply_to, &reply_to_len, - /* s */ &expiration, &expiration_len, - /* s */ &message_id, &message_id_len, - /* l */ ×tamp, - /* s */ &type, &type_len, - /* s */ &user_id, &user_id_len, - /* s */ &app_id, &app_id_len, - /* s */ &cluster_id, &cluster_id_len - ) == FAILURE) { + char *type = NULL; + size_t type_len = 0; + char *user_id = NULL; + size_t user_id_len = 0; + char *app_id = NULL; + size_t app_id_len = 0; + char *cluster_id = NULL; + size_t cluster_id_len = 0; + + + if (zend_parse_parameters( + ZEND_NUM_ARGS() TSRMLS_CC, + "|ssallsssslssss", + /* s */ &content_type, + &content_type_len, + /* s */ &content_encoding, + &content_encoding_len, + /* a */ &headers, + /* l */ &delivery_mode, + /* l */ &priority, + /* s */ &correlation_id, + &correlation_id_len, + /* s */ &reply_to, + &reply_to_len, + /* s */ &expiration, + &expiration_len, + /* s */ &message_id, + &message_id_len, + /* l */ ×tamp, + /* s */ &type, + &type_len, + /* s */ &user_id, + &user_id_len, + /* s */ &app_id, + &app_id_len, + /* s */ &cluster_id, + &cluster_id_len + ) == FAILURE) { return; } - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("content_type"), content_type, content_type_len TSRMLS_CC); - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("content_encoding"), content_encoding, content_encoding_len TSRMLS_CC); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("content_type"), + content_type, + content_type_len TSRMLS_CC + ); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("content_encoding"), + content_encoding, + content_encoding_len TSRMLS_CC + ); if (headers != NULL) { zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("headers"), headers TSRMLS_CC); @@ -136,25 +172,73 @@ static PHP_METHOD(AMQPBasicProperties, __construct) { php_amqp_basic_properties_set_empty_headers(getThis() TSRMLS_CC); } - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("delivery_mode"), delivery_mode TSRMLS_CC); + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("delivery_mode"), + delivery_mode TSRMLS_CC + ); zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("priority"), priority TSRMLS_CC); - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("correlation_id"), correlation_id, correlation_id_len TSRMLS_CC); - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("reply_to"), reply_to, reply_to_len TSRMLS_CC); - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("expiration"), expiration, expiration_len TSRMLS_CC); - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("message_id"), message_id, message_id_len TSRMLS_CC); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("correlation_id"), + correlation_id, + correlation_id_len TSRMLS_CC + ); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("reply_to"), + reply_to, + reply_to_len TSRMLS_CC + ); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("expiration"), + expiration, + expiration_len TSRMLS_CC + ); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("message_id"), + message_id, + message_id_len TSRMLS_CC + ); zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("timestamp"), timestamp TSRMLS_CC); zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("type"), type, type_len TSRMLS_CC); - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("user_id"), user_id, user_id_len TSRMLS_CC); - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("app_id"), app_id, app_id_len TSRMLS_CC); - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("cluster_id"), cluster_id, cluster_id_len TSRMLS_CC); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("user_id"), + user_id, + user_id_len TSRMLS_CC + ); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("app_id"), + app_id, + app_id_len TSRMLS_CC + ); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("cluster_id"), + cluster_id, + cluster_id_len TSRMLS_CC + ); } /* }}} */ /* {{{ proto AMQPBasicProperties::getContentType() */ -static PHP_METHOD(AMQPBasicProperties, getContentType) { +static PHP_METHOD(AMQPBasicProperties, getContentType) +{ zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("content_type"); @@ -162,7 +246,8 @@ static PHP_METHOD(AMQPBasicProperties, getContentType) { /* }}} */ /* {{{ proto AMQPBasicProperties::getContentEncoding() */ -static PHP_METHOD(AMQPBasicProperties, getContentEncoding) { +static PHP_METHOD(AMQPBasicProperties, getContentEncoding) +{ zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("content_encoding"); @@ -170,7 +255,8 @@ static PHP_METHOD(AMQPBasicProperties, getContentEncoding) { /* }}} */ /* {{{ proto AMQPBasicProperties::getCorrelationId() */ -static PHP_METHOD(AMQPBasicProperties, getHeaders) { +static PHP_METHOD(AMQPBasicProperties, getHeaders) +{ zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("headers"); @@ -178,7 +264,8 @@ static PHP_METHOD(AMQPBasicProperties, getHeaders) { /* }}} */ /* {{{ proto AMQPBasicProperties::getDeliveryMode() */ -static PHP_METHOD(AMQPBasicProperties, getDeliveryMode) { +static PHP_METHOD(AMQPBasicProperties, getDeliveryMode) +{ zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("delivery_mode"); @@ -186,7 +273,8 @@ static PHP_METHOD(AMQPBasicProperties, getDeliveryMode) { /* }}} */ /* {{{ proto AMQPBasicProperties::getPriority() */ -static PHP_METHOD(AMQPBasicProperties, getPriority) { +static PHP_METHOD(AMQPBasicProperties, getPriority) +{ zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("priority"); @@ -194,7 +282,8 @@ static PHP_METHOD(AMQPBasicProperties, getPriority) { /* }}} */ /* {{{ proto AMQPBasicProperties::getCorrelationId() */ -static PHP_METHOD(AMQPBasicProperties, getCorrelationId) { +static PHP_METHOD(AMQPBasicProperties, getCorrelationId) +{ zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("correlation_id"); @@ -202,7 +291,8 @@ static PHP_METHOD(AMQPBasicProperties, getCorrelationId) { /* }}} */ /* {{{ proto AMQPBasicProperties::getReplyTo() */ -static PHP_METHOD(AMQPBasicProperties, getReplyTo) { +static PHP_METHOD(AMQPBasicProperties, getReplyTo) +{ zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("reply_to"); @@ -211,7 +301,8 @@ static PHP_METHOD(AMQPBasicProperties, getReplyTo) { /* {{{ proto AMQPBasicProperties::getExpiration() check amqp envelope */ -static PHP_METHOD(AMQPBasicProperties, getExpiration) { +static PHP_METHOD(AMQPBasicProperties, getExpiration) +{ zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("expiration"); @@ -219,7 +310,8 @@ static PHP_METHOD(AMQPBasicProperties, getExpiration) { /* }}} */ /* {{{ proto AMQPBasicProperties::getMessageId() */ -static PHP_METHOD(AMQPBasicProperties, getMessageId) { +static PHP_METHOD(AMQPBasicProperties, getMessageId) +{ zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("message_id"); @@ -227,7 +319,8 @@ static PHP_METHOD(AMQPBasicProperties, getMessageId) { /* }}} */ /* {{{ proto AMQPBasicProperties::getTimestamp() */ -static PHP_METHOD(AMQPBasicProperties, getTimestamp) { +static PHP_METHOD(AMQPBasicProperties, getTimestamp) +{ zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("timestamp"); @@ -235,7 +328,8 @@ static PHP_METHOD(AMQPBasicProperties, getTimestamp) { /* }}} */ /* {{{ proto AMQPBasicProperties::getType() */ -static PHP_METHOD(AMQPBasicProperties, getType) { +static PHP_METHOD(AMQPBasicProperties, getType) +{ zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("type"); @@ -243,7 +337,8 @@ static PHP_METHOD(AMQPBasicProperties, getType) { /* }}} */ /* {{{ proto AMQPBasicProperties::getUserId() */ -static PHP_METHOD(AMQPBasicProperties, getUserId) { +static PHP_METHOD(AMQPBasicProperties, getUserId) +{ zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("user_id"); @@ -251,7 +346,8 @@ static PHP_METHOD(AMQPBasicProperties, getUserId) { /* }}} */ /* {{{ proto AMQPBasicProperties::getAppId() */ -static PHP_METHOD(AMQPBasicProperties, getAppId) { +static PHP_METHOD(AMQPBasicProperties, getAppId) +{ zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("app_id"); @@ -259,7 +355,8 @@ static PHP_METHOD(AMQPBasicProperties, getAppId) { /* }}} */ /* {{{ proto AMQPBasicProperties::getClusterId() */ -static PHP_METHOD(AMQPBasicProperties, getClusterId) { +static PHP_METHOD(AMQPBasicProperties, getClusterId) +{ zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("cluster_id"); @@ -335,11 +432,12 @@ zend_function_entry amqp_basic_properties_class_functions[] = { PHP_ME(AMQPBasicProperties, getAppId, arginfo_amqp_basic_properties_class_getAppId, ZEND_ACC_PUBLIC) PHP_ME(AMQPBasicProperties, getClusterId, arginfo_amqp_basic_properties_class_getClusterId, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} + {NULL, NULL, NULL} }; -PHP_MINIT_FUNCTION (amqp_basic_properties) { +PHP_MINIT_FUNCTION(amqp_basic_properties) +{ zend_class_entry ce; INIT_CLASS_ENTRY(ce, "AMQPBasicProperties", amqp_basic_properties_class_functions); @@ -350,7 +448,12 @@ PHP_MINIT_FUNCTION (amqp_basic_properties) { zend_declare_property_null(this_ce, ZEND_STRL("headers"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_long(this_ce, ZEND_STRL("delivery_mode"), AMQP_DELIVERY_NONPERSISTENT, ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_long( + this_ce, + ZEND_STRL("delivery_mode"), + AMQP_DELIVERY_NONPERSISTENT, + ZEND_ACC_PRIVATE TSRMLS_CC + ); zend_declare_property_long(this_ce, ZEND_STRL("priority"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_stringl(this_ce, ZEND_STRL("correlation_id"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); @@ -361,15 +464,16 @@ PHP_MINIT_FUNCTION (amqp_basic_properties) { zend_declare_property_long(this_ce, ZEND_STRL("timestamp"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_stringl(this_ce, ZEND_STRL("type"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_stringl(this_ce, ZEND_STRL("user_id"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_stringl(this_ce, ZEND_STRL("app_id"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_stringl(this_ce, ZEND_STRL("user_id"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_stringl(this_ce, ZEND_STRL("app_id"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); zend_declare_property_stringl(this_ce, ZEND_STRL("cluster_id"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); return SUCCESS; } -void parse_amqp_table(amqp_table_t *table, zval *result TSRMLS_DC) { +void parse_amqp_table(amqp_table_t *table, zval *result TSRMLS_DC) +{ int i; zend_bool has_value = 0; @@ -422,7 +526,7 @@ void parse_amqp_table(amqp_table_t *table, zval *result TSRMLS_DC) { break; case AMQP_FIELD_KIND_UTF8: case AMQP_FIELD_KIND_BYTES: - ZVAL_STRINGL(&value, entry->value.value.bytes.bytes, entry->value.value.bytes.len); + ZVAL_STRINGL(&value, entry->value.value.bytes.bytes, entry->value.value.bytes.len); break; case AMQP_FIELD_KIND_ARRAY: { int j; @@ -430,10 +534,10 @@ void parse_amqp_table(amqp_table_t *table, zval *result TSRMLS_DC) { for (j = 0; j < entry->value.value.array.num_entries; ++j) { switch (entry->value.value.array.entries[j].kind) { case AMQP_FIELD_KIND_UTF8: - add_next_index_stringl( - &value, - entry->value.value.array.entries[j].value.bytes.bytes, - entry->value.value.array.entries[j].value.bytes.len + add_next_index_stringl( + &value, + entry->value.value.array.entries[j].value.bytes.bytes, + entry->value.value.array.entries[j].value.bytes.len ); break; case AMQP_FIELD_KIND_TABLE: { @@ -441,45 +545,40 @@ void parse_amqp_table(amqp_table_t *table, zval *result TSRMLS_DC) { ZVAL_UNDEF(&subtable); array_init(&subtable); - parse_amqp_table( - &(entry->value.value.array.entries[j].value.table), - &subtable TSRMLS_CC - ); + parse_amqp_table(&(entry->value.value.array.entries[j].value.table), &subtable TSRMLS_CC); add_next_index_zval(&value, &subtable); - } - break; + } break; default: break; } } - } - break; + } break; case AMQP_FIELD_KIND_TABLE: array_init(&value); parse_amqp_table(&(entry->value.value.table), &value TSRMLS_CC); break; case AMQP_FIELD_KIND_TIMESTAMP: { - char timestamp_str[20]; - zval timestamp; - ZVAL_UNDEF(×tamp); - - int length = snprintf(timestamp_str, sizeof(timestamp_str), ZEND_ULONG_FMT, entry->value.value.u64); - ZVAL_STRINGL(×tamp, (char *)timestamp_str, length); - object_init_ex(&value, amqp_timestamp_class_entry); - - zend_call_method_with_1_params( - PHP_AMQP_COMPAT_OBJ_P(&value), - amqp_timestamp_class_entry, - NULL, - "__construct", - NULL, - ×tamp - ); - - zval_ptr_dtor(×tamp); - break; - } + char timestamp_str[20]; + zval timestamp; + ZVAL_UNDEF(×tamp); + + int length = snprintf(timestamp_str, sizeof(timestamp_str), ZEND_ULONG_FMT, entry->value.value.u64); + ZVAL_STRINGL(×tamp, (char *) timestamp_str, length); + object_init_ex(&value, amqp_timestamp_class_entry); + + zend_call_method_with_1_params( + PHP_AMQP_COMPAT_OBJ_P(&value), + amqp_timestamp_class_entry, + NULL, + "__construct", + NULL, + ×tamp + ); + + zval_ptr_dtor(×tamp); + break; + } case AMQP_FIELD_KIND_VOID: ZVAL_NULL(&value); @@ -497,17 +596,17 @@ void parse_amqp_table(amqp_table_t *table, zval *result TSRMLS_DC) { object_init_ex(&value, amqp_decimal_class_entry); zend_call_method_with_2_params( - PHP_AMQP_COMPAT_OBJ_P(&value), - amqp_decimal_class_entry, - NULL, - "__construct", - NULL, - &e, - &n + PHP_AMQP_COMPAT_OBJ_P(&value), + amqp_decimal_class_entry, + NULL, + "__construct", + NULL, + &e, + &n ); - zval_ptr_dtor(&e); - zval_ptr_dtor(&n); + zval_ptr_dtor(&e); + zval_ptr_dtor(&n); break; } default: @@ -520,9 +619,9 @@ void parse_amqp_table(amqp_table_t *table, zval *result TSRMLS_DC) { add_assoc_zval(result, key, &value); efree(key); } else { - if (!Z_ISUNDEF(value)) { - zval_ptr_dtor(&value); - } + if (!Z_ISUNDEF(value)) { + zval_ptr_dtor(&value); + } } } return; @@ -536,17 +635,35 @@ void php_amqp_basic_properties_extract(amqp_basic_properties_t *p, zval *obj TSR array_init(&headers); if (p->_flags & AMQP_BASIC_CONTENT_TYPE_FLAG) { - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("content_type"), (const char *) p->content_type.bytes, (size_t) p->content_type.len TSRMLS_CC); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(obj), + ZEND_STRL("content_type"), + (const char *) p->content_type.bytes, + (size_t) p->content_type.len TSRMLS_CC + ); } else { /* BC */ zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("content_type"), "", 0 TSRMLS_CC); } if (p->_flags & AMQP_BASIC_CONTENT_ENCODING_FLAG) { - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("content_encoding"), (const char *) p->content_encoding.bytes, (size_t) p->content_encoding.len TSRMLS_CC); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(obj), + ZEND_STRL("content_encoding"), + (const char *) p->content_encoding.bytes, + (size_t) p->content_encoding.len TSRMLS_CC + ); } else { /* BC */ - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("content_encoding"), "", 0 TSRMLS_CC); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(obj), + ZEND_STRL("content_encoding"), + "", + 0 TSRMLS_CC + ); } if (p->_flags & AMQP_BASIC_HEADERS_FLAG) { @@ -556,84 +673,136 @@ void php_amqp_basic_properties_extract(amqp_basic_properties_t *p, zval *obj TSR zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("headers"), &headers TSRMLS_CC); if (p->_flags & AMQP_BASIC_DELIVERY_MODE_FLAG) { - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("delivery_mode"), (zend_long) p->delivery_mode TSRMLS_CC); + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(obj), + ZEND_STRL("delivery_mode"), + (zend_long) p->delivery_mode TSRMLS_CC + ); } else { /* BC */ - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("delivery_mode"), AMQP_DELIVERY_NONPERSISTENT TSRMLS_CC); + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(obj), + ZEND_STRL("delivery_mode"), + AMQP_DELIVERY_NONPERSISTENT TSRMLS_CC + ); } if (p->_flags & AMQP_BASIC_PRIORITY_FLAG) { - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("priority"), (zend_long) p->priority TSRMLS_CC); + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(obj), + ZEND_STRL("priority"), + (zend_long) p->priority TSRMLS_CC + ); } else { /* BC */ zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("priority"), 0 TSRMLS_CC); } if (p->_flags & AMQP_BASIC_CORRELATION_ID_FLAG) { - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("correlation_id"), (const char *) p->correlation_id.bytes, (size_t) p->correlation_id.len TSRMLS_CC); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(obj), + ZEND_STRL("correlation_id"), + (const char *) p->correlation_id.bytes, + (size_t) p->correlation_id.len TSRMLS_CC + ); } else { /* BC */ zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("correlation_id"), "", 0 TSRMLS_CC); } if (p->_flags & AMQP_BASIC_REPLY_TO_FLAG) { - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("reply_to"), (const char *) p->reply_to.bytes, (size_t) p->reply_to.len TSRMLS_CC); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(obj), + ZEND_STRL("reply_to"), + (const char *) p->reply_to.bytes, + (size_t) p->reply_to.len TSRMLS_CC + ); } else { /* BC */ zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("reply_to"), "", 0 TSRMLS_CC); } if (p->_flags & AMQP_BASIC_EXPIRATION_FLAG) { - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("expiration"), (const char *) p->expiration.bytes, (size_t) p->expiration.len TSRMLS_CC); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(obj), + ZEND_STRL("expiration"), + (const char *) p->expiration.bytes, + (size_t) p->expiration.len TSRMLS_CC + ); } else { /* BC */ zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("expiration"), "", 0 TSRMLS_CC); } if (p->_flags & AMQP_BASIC_MESSAGE_ID_FLAG) { - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("message_id"), (const char *) p->message_id.bytes, (size_t) p->message_id.len TSRMLS_CC); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(obj), + ZEND_STRL("message_id"), + (const char *) p->message_id.bytes, + (size_t) p->message_id.len TSRMLS_CC + ); } else { /* BC */ zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("message_id"), "", 0 TSRMLS_CC); } if (p->_flags & AMQP_BASIC_TIMESTAMP_FLAG) { - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("timestamp"), (zend_long) p->timestamp TSRMLS_CC); + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(obj), + ZEND_STRL("timestamp"), + (zend_long) p->timestamp TSRMLS_CC + ); } else { /* BC */ zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("timestamp"), 0 TSRMLS_CC); } if (p->_flags & AMQP_BASIC_TYPE_FLAG) { - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("type"), (const char *) p->type.bytes, (size_t) p->type.len TSRMLS_CC); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(obj), + ZEND_STRL("type"), + (const char *) p->type.bytes, + (size_t) p->type.len TSRMLS_CC + ); } else { /* BC */ zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("type"), "", 0 TSRMLS_CC); } if (p->_flags & AMQP_BASIC_USER_ID_FLAG) { - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("user_id"), (const char *) p->user_id.bytes, (size_t) p->user_id.len TSRMLS_CC); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(obj), + ZEND_STRL("user_id"), + (const char *) p->user_id.bytes, + (size_t) p->user_id.len TSRMLS_CC + ); } else { /* BC */ zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("user_id"), "", 0 TSRMLS_CC); } if (p->_flags & AMQP_BASIC_APP_ID_FLAG) { - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("app_id"), (const char *) p->app_id.bytes, (size_t) p->app_id.len TSRMLS_CC); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(obj), + ZEND_STRL("app_id"), + (const char *) p->app_id.bytes, + (size_t) p->app_id.len TSRMLS_CC + ); } else { /* BC */ zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("app_id"), "", 0 TSRMLS_CC); } - zval_ptr_dtor(&headers); + zval_ptr_dtor(&headers); } - - -/* -*Local variables: -*tab-width: 4 -*c-basic-offset: 4 -*End: -*vim600: noet sw=4 ts=4 fdm=marker -*vim<600: noet sw=4 ts=4 -*/ diff --git a/amqp_basic_properties.h b/amqp_basic_properties.h index a1233627..a322ac67 100644 --- a/amqp_basic_properties.h +++ b/amqp_basic_properties.h @@ -35,13 +35,3 @@ void php_amqp_basic_properties_set_empty_headers(zval *obj TSRMLS_DC); PHP_MINIT_FUNCTION(amqp_basic_properties); - - -/* -*Local variables: -*tab-width: 4 -*c-basic-offset: 4 -*End: -*vim600: noet sw=4 ts=4 fdm=marker -*vim<600: noet sw=4 ts=4 -*/ diff --git a/amqp_channel.c b/amqp_channel.c index 5405a693..cd91dbb0 100644 --- a/amqp_channel.c +++ b/amqp_channel.c @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H -#include "config.h" + #include "config.h" #endif #include "php.h" @@ -30,29 +30,29 @@ #include "zend_exceptions.h" #ifdef PHP_WIN32 -# if PHP_VERSION_ID >= 80000 -# include "main/php_stdint.h" -# else -# include "win32/php_stdint.h" -# endif -# include "win32/signal.h" + #if PHP_VERSION_ID >= 80000 + #include "main/php_stdint.h" + #else + #include "win32/php_stdint.h" + #endif + #include "win32/signal.h" #else -# include -# include + #include + #include #endif #if HAVE_LIBRABBITMQ_NEW_LAYOUT -#include -#include + #include + #include #else -#include -#include + #include + #include #endif #ifdef PHP_WIN32 -# include "win32/unistd.h" + #include "win32/unistd.h" #else -# include + #include #endif #include "php_amqp.h" @@ -68,43 +68,44 @@ zend_object_handlers amqp_channel_object_handlers; void php_amqp_close_channel(amqp_channel_resource *channel_resource, zend_bool check_errors TSRMLS_DC) { - assert(channel_resource != NULL); + assert(channel_resource != NULL); - amqp_connection_resource *connection_resource = channel_resource->connection_resource; + amqp_connection_resource *connection_resource = channel_resource->connection_resource; - if (connection_resource != NULL) { - /* First, remove it from active channels table to prevent recursion in case of connection error */ + if (connection_resource != NULL) { + /* First, remove it from active channels table to prevent recursion in case of connection error */ php_amqp_connection_resource_unregister_channel(connection_resource, channel_resource->channel_id); - } else { - channel_resource->is_connected = '\0'; - } + } else { + channel_resource->is_connected = '\0'; + } - assert(channel_resource->connection_resource == NULL); + assert(channel_resource->connection_resource == NULL); - if (!channel_resource->is_connected) { - /* Nothing to do more - channel was previously marked as closed, possibly, due to channel-level error */ - return; - } + if (!channel_resource->is_connected) { + /* Nothing to do more - channel was previously marked as closed, possibly, due to channel-level error */ + return; + } - channel_resource->is_connected = '\0'; + channel_resource->is_connected = '\0'; - if (connection_resource && connection_resource->is_connected && channel_resource->channel_id > 0) { - assert(connection_resource != NULL); + if (connection_resource && connection_resource->is_connected && channel_resource->channel_id > 0) { + assert(connection_resource != NULL); - amqp_channel_close(connection_resource->connection_state, channel_resource->channel_id, AMQP_REPLY_SUCCESS); + amqp_channel_close(connection_resource->connection_state, channel_resource->channel_id, AMQP_REPLY_SUCCESS); - amqp_rpc_reply_t res = amqp_get_rpc_reply(connection_resource->connection_state); + amqp_rpc_reply_t res = amqp_get_rpc_reply(connection_resource->connection_state); - if (check_errors && PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); - return; - } + if (check_errors && PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + return; + } - php_amqp_maybe_release_buffers_on_channel(connection_resource, channel_resource); - } + php_amqp_maybe_release_buffers_on_channel(connection_resource, channel_resource); + } } -static void php_amqp_destroy_fci(zend_fcall_info *fci) { +static void php_amqp_destroy_fci(zend_fcall_info *fci) +{ if (fci->size > 0) { zval_ptr_dtor(&fci->function_name); if (fci->object != NULL) { @@ -114,7 +115,8 @@ static void php_amqp_destroy_fci(zend_fcall_info *fci) { } } -static void php_amqp_duplicate_fci(zend_fcall_info *source) { +static void php_amqp_duplicate_fci(zend_fcall_info *source) +{ if (source->size > 0) { zval_add_ref(&source->function_name); @@ -124,11 +126,12 @@ static void php_amqp_duplicate_fci(zend_fcall_info *source) { } } -static int php_amqp_get_fci_gc_data_count(zend_fcall_info *fci) { +static int php_amqp_get_fci_gc_data_count(zend_fcall_info *fci) +{ int cnt = 0; if (fci->size > 0) { - cnt ++; + cnt++; if (fci->object != NULL) { cnt++; @@ -138,17 +141,18 @@ static int php_amqp_get_fci_gc_data_count(zend_fcall_info *fci) { return cnt; } -static zval * php_amqp_get_fci_gc_data(zend_fcall_info *fci, zval *gc_data) { +static zval *php_amqp_get_fci_gc_data(zend_fcall_info *fci, zval *gc_data) +{ if (ZEND_FCI_INITIALIZED(*fci)) { - ZVAL_COPY_VALUE(gc_data++, &fci->function_name); + ZVAL_COPY_VALUE(gc_data++, &fci->function_name); if (fci->object != NULL) { ZVAL_OBJ(gc_data++, fci->object); } } - return gc_data; + return gc_data; } #if PHP_MAJOR_VERSION < 8 @@ -158,83 +162,81 @@ static HashTable *amqp_channel_gc(zval *object, zval **table, int *n) /* {{{ */ #else static HashTable *amqp_channel_gc(zend_object *object, zval **table, int *n) /* {{{ */ { - amqp_channel_object *channel = php_amqp_channel_object_fetch(object); + amqp_channel_object *channel = php_amqp_channel_object_fetch(object); #endif - int basic_return_cnt = php_amqp_get_fci_gc_data_count(&channel->callbacks.basic_return.fci); - int basic_ack_cnt = php_amqp_get_fci_gc_data_count(&channel->callbacks.basic_ack.fci); - int basic_nack_cnt = php_amqp_get_fci_gc_data_count(&channel->callbacks.basic_nack.fci); + int basic_return_cnt = php_amqp_get_fci_gc_data_count(&channel->callbacks.basic_return.fci); + int basic_ack_cnt = php_amqp_get_fci_gc_data_count(&channel->callbacks.basic_ack.fci); + int basic_nack_cnt = php_amqp_get_fci_gc_data_count(&channel->callbacks.basic_nack.fci); - int cnt = basic_return_cnt + basic_ack_cnt + basic_nack_cnt; + int cnt = basic_return_cnt + basic_ack_cnt + basic_nack_cnt; - if (cnt > channel->gc_data_count) { - channel->gc_data_count = cnt; - channel->gc_data = (zval *) erealloc(channel->gc_data, sizeof(zval) * cnt); - } + if (cnt > channel->gc_data_count) { + channel->gc_data_count = cnt; + channel->gc_data = (zval *) erealloc(channel->gc_data, sizeof(zval) * cnt); + } - zval *gc_data = channel->gc_data; + zval *gc_data = channel->gc_data; - gc_data = php_amqp_get_fci_gc_data(&channel->callbacks.basic_return.fci, gc_data); - gc_data = php_amqp_get_fci_gc_data(&channel->callbacks.basic_ack.fci, gc_data); - php_amqp_get_fci_gc_data(&channel->callbacks.basic_nack.fci, gc_data); + gc_data = php_amqp_get_fci_gc_data(&channel->callbacks.basic_return.fci, gc_data); + gc_data = php_amqp_get_fci_gc_data(&channel->callbacks.basic_ack.fci, gc_data); + php_amqp_get_fci_gc_data(&channel->callbacks.basic_nack.fci, gc_data); - *table = channel->gc_data; - *n = cnt; + *table = channel->gc_data; + *n = cnt; - return zend_std_get_properties(object TSRMLS_CC); + return zend_std_get_properties(object TSRMLS_CC); } /* }}} */ -static void php_amqp_clean_callbacks(amqp_channel_callbacks *callbacks) { - php_amqp_destroy_fci(&callbacks->basic_return.fci); - php_amqp_destroy_fci(&callbacks->basic_ack.fci); - php_amqp_destroy_fci(&callbacks->basic_nack.fci); +static void php_amqp_clean_callbacks(amqp_channel_callbacks *callbacks) +{ + php_amqp_destroy_fci(&callbacks->basic_return.fci); + php_amqp_destroy_fci(&callbacks->basic_ack.fci); + php_amqp_destroy_fci(&callbacks->basic_nack.fci); } void amqp_channel_free(zend_object *object TSRMLS_DC) { - amqp_channel_object *channel = PHP_AMQP_FETCH_CHANNEL(object); + amqp_channel_object *channel = PHP_AMQP_FETCH_CHANNEL(object); - if (channel->channel_resource != NULL) { - php_amqp_close_channel(channel->channel_resource, 0 TSRMLS_CC); + if (channel->channel_resource != NULL) { + php_amqp_close_channel(channel->channel_resource, 0 TSRMLS_CC); - efree(channel->channel_resource); - channel->channel_resource = NULL; - } + efree(channel->channel_resource); + channel->channel_resource = NULL; + } - if (channel->gc_data) { - efree(channel->gc_data); - } + if (channel->gc_data) { + efree(channel->gc_data); + } - php_amqp_clean_callbacks(&channel->callbacks); + php_amqp_clean_callbacks(&channel->callbacks); - zend_object_std_dtor(&channel->zo TSRMLS_CC); + zend_object_std_dtor(&channel->zo TSRMLS_CC); } zend_object *amqp_channel_ctor(zend_class_entry *ce TSRMLS_DC) { - amqp_channel_object *channel = (amqp_channel_object*) ecalloc(1, sizeof(amqp_channel_object) + zend_object_properties_size(ce)); + amqp_channel_object *channel = + (amqp_channel_object *) ecalloc(1, sizeof(amqp_channel_object) + zend_object_properties_size(ce)); - zend_object_std_init(&channel->zo, ce TSRMLS_CC); - AMQP_OBJECT_PROPERTIES_INIT(channel->zo, ce); + zend_object_std_init(&channel->zo, ce TSRMLS_CC); + AMQP_OBJECT_PROPERTIES_INIT(channel->zo, ce); -#if PHP_MAJOR_VERSION >=7 - channel->zo.handlers = &amqp_channel_object_handlers; +#if PHP_MAJOR_VERSION >= 7 + channel->zo.handlers = &amqp_channel_object_handlers; - return &channel->zo; + return &channel->zo; #else - zend_object *new_value; + zend_object *new_value; - new_value.handle = zend_objects_store_put( - channel, - NULL, - (zend_objects_free_object_storage_t) amqp_channel_free, - NULL TSRMLS_CC - ); + new_value.handle = + zend_objects_store_put(channel, NULL, (zend_objects_free_object_storage_t) amqp_channel_free, NULL TSRMLS_CC); - new_value.handlers = zend_get_std_object_handlers(); + new_value.handlers = zend_get_std_object_handlers(); - return new_value; + return new_value; #endif } @@ -243,146 +245,211 @@ zend_object *amqp_channel_ctor(zend_class_entry *ce TSRMLS_DC) */ static PHP_METHOD(amqp_channel_class, __construct) { - zval rv; - - zval *connection_object = NULL; + zval rv; - amqp_channel_resource *channel_resource; - amqp_channel_object *channel; - amqp_connection_object *connection; + zval *connection_object = NULL; - /* Parse out the method parameters */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &connection_object, amqp_connection_class_entry) == FAILURE) { - zend_throw_exception(amqp_channel_exception_class_entry, "Parameter must be an instance of AMQPConnection.", 0 TSRMLS_CC); - RETURN_NULL(); - } - - zval consumers; - - ZVAL_UNDEF(&consumers); - array_init(&consumers); - - zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("consumers"), &consumers TSRMLS_CC); - - zval_ptr_dtor(&consumers); - - channel = PHP_AMQP_GET_CHANNEL(getThis()); - - /* Set the prefetch count */ - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("prefetch_count"), INI_INT("amqp.prefetch_count") TSRMLS_CC); - - /* Set the prefetch size */ - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("prefetch_size"), INI_INT("amqp.prefetch_size") TSRMLS_CC); - - /* Set the global prefetch count */ - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("global_prefetch_count"), INI_INT("amqp.global_prefetch_count") TSRMLS_CC); - - /* Set the global prefetch size */ - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("global_prefetch_size"), INI_INT("amqp.global_prefetch_size") TSRMLS_CC); - - /* Pull out and verify the connection */ - connection = PHP_AMQP_GET_CONNECTION(connection_object); - PHP_AMQP_VERIFY_CONNECTION(connection, "Could not create channel."); + amqp_channel_resource *channel_resource; + amqp_channel_object *channel; + amqp_connection_object *connection; + + /* Parse out the method parameters */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &connection_object, amqp_connection_class_entry) == + FAILURE) { + zend_throw_exception( + amqp_channel_exception_class_entry, + "Parameter must be an instance of AMQPConnection.", + 0 TSRMLS_CC + ); + RETURN_NULL(); + } - if (!connection->connection_resource) { - zend_throw_exception(amqp_channel_exception_class_entry, "Could not create channel. No connection resource.", 0 TSRMLS_CC); - return; - } + zval consumers; + + ZVAL_UNDEF(&consumers); + array_init(&consumers); + + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("consumers"), &consumers TSRMLS_CC); + + zval_ptr_dtor(&consumers); + + channel = PHP_AMQP_GET_CHANNEL(getThis()); + + /* Set the prefetch count */ + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("prefetch_count"), + INI_INT("amqp.prefetch_count") TSRMLS_CC + ); + + /* Set the prefetch size */ + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("prefetch_size"), + INI_INT("amqp.prefetch_size") TSRMLS_CC + ); + + /* Set the global prefetch count */ + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("global_prefetch_count"), + INI_INT("amqp.global_prefetch_count") TSRMLS_CC + ); + + /* Set the global prefetch size */ + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("global_prefetch_size"), + INI_INT("amqp.global_prefetch_size") TSRMLS_CC + ); + + /* Pull out and verify the connection */ + connection = PHP_AMQP_GET_CONNECTION(connection_object); + PHP_AMQP_VERIFY_CONNECTION(connection, "Could not create channel."); + + if (!connection->connection_resource) { + zend_throw_exception( + amqp_channel_exception_class_entry, + "Could not create channel. No connection resource.", + 0 TSRMLS_CC + ); + return; + } - if (!connection->connection_resource->is_connected) { - zend_throw_exception(amqp_channel_exception_class_entry, "Could not create channel. Connection resource is not connected.", 0 TSRMLS_CC); - return; - } + if (!connection->connection_resource->is_connected) { + zend_throw_exception( + amqp_channel_exception_class_entry, + "Could not create channel. Connection resource is not connected.", + 0 TSRMLS_CC + ); + return; + } - zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connection"), connection_object TSRMLS_CC); + zend_update_property( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("connection"), + connection_object TSRMLS_CC + ); - channel_resource = (amqp_channel_resource*)ecalloc(1, sizeof(amqp_channel_resource)); - channel->channel_resource = channel_resource; + channel_resource = (amqp_channel_resource *) ecalloc(1, sizeof(amqp_channel_resource)); + channel->channel_resource = channel_resource; channel_resource->parent = channel; - /* Figure out what the next available channel is on this connection */ - channel_resource->channel_id = php_amqp_connection_resource_get_available_channel_id(connection->connection_resource); - - /* Check that we got a valid channel */ - if (!channel_resource->channel_id) { - zend_throw_exception(amqp_channel_exception_class_entry, "Could not create channel. Connection has no open channel slots remaining.", 0 TSRMLS_CC); - return; - } - - if (php_amqp_connection_resource_register_channel(connection->connection_resource, channel_resource, channel_resource->channel_id) == FAILURE) { - zend_throw_exception(amqp_channel_exception_class_entry, "Could not create channel. Failed to add channel to connection slot.", 0 TSRMLS_CC); - } - - /* Open up the channel for use */ - amqp_channel_open_ok_t *r = amqp_channel_open(channel_resource->connection_resource->connection_state, channel_resource->channel_id); - - - if (!r) { - amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - - php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource TSRMLS_CC); + /* Figure out what the next available channel is on this connection */ + channel_resource->channel_id = + php_amqp_connection_resource_get_available_channel_id(connection->connection_resource); + + /* Check that we got a valid channel */ + if (!channel_resource->channel_id) { + zend_throw_exception( + amqp_channel_exception_class_entry, + "Could not create channel. Connection has no open channel slots remaining.", + 0 TSRMLS_CC + ); + return; + } - php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, PHP_AMQP_G(error_message), PHP_AMQP_G(error_code) TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + if (php_amqp_connection_resource_register_channel( + connection->connection_resource, + channel_resource, + channel_resource->channel_id + ) == FAILURE) { + zend_throw_exception( + amqp_channel_exception_class_entry, + "Could not create channel. Failed to add channel to connection slot.", + 0 TSRMLS_CC + ); + } - /* Prevent double free, it may happen in case the channel resource was already freed due to some hard error. */ - if (channel_resource->connection_resource) { - php_amqp_connection_resource_unregister_channel(channel_resource->connection_resource, channel_resource->channel_id); - channel_resource->channel_id = 0; - } + /* Open up the channel for use */ + amqp_channel_open_ok_t *r = + amqp_channel_open(channel_resource->connection_resource->connection_state, channel_resource->channel_id); + + + if (!r) { + amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + + php_amqp_error( + res, + &PHP_AMQP_G(error_message), + channel_resource->connection_resource, + channel_resource TSRMLS_CC + ); + + php_amqp_zend_throw_exception( + res, + amqp_channel_exception_class_entry, + PHP_AMQP_G(error_message), + PHP_AMQP_G(error_code) TSRMLS_CC + ); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + + /* Prevent double free, it may happen in case the channel resource was already freed due to some hard error. */ + if (channel_resource->connection_resource) { + php_amqp_connection_resource_unregister_channel( + channel_resource->connection_resource, + channel_resource->channel_id + ); + channel_resource->channel_id = 0; + } - return; - } + return; + } - /* r->channel_id is a 16-bit channel number inside amqp_bytes_t, assertion below will without converting to uint16_t*/ - /* assert (r->channel_id == channel_resource->channel_id);*/ - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + /* r->channel_id is a 16-bit channel number inside amqp_bytes_t, assertion below will without converting to uint16_t*/ + /* assert (r->channel_id == channel_resource->channel_id);*/ + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - channel_resource->is_connected = '\1'; + channel_resource->is_connected = '\1'; - /* Set the prefetch count: */ - amqp_basic_qos( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - 0, /* prefetch window size */ - (uint16_t)PHP_AMQP_READ_THIS_PROP_LONG("prefetch_count"), /* prefetch message count */ - /* NOTE that RabbitMQ has reinterpreted global flag field. See https://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.qos.global for details */ - 0 /* global flag */ - ); + /* Set the prefetch count: */ + amqp_basic_qos( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + 0, /* prefetch window size */ + (uint16_t) PHP_AMQP_READ_THIS_PROP_LONG("prefetch_count"), /* prefetch message count */ + /* NOTE that RabbitMQ has reinterpreted global flag field. See https://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.qos.global for details */ + 0 /* global flag */ + ); - amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - uint32_t global_prefetch_size = (uint32_t)PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_size"); - uint16_t global_prefetch_count = (uint16_t)PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_count"); + uint32_t global_prefetch_size = (uint32_t) PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_size"); + uint16_t global_prefetch_count = (uint16_t) PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_count"); - /* Set the global prefetch settings (ignoring if 0 for backwards compatibility) */ - if (global_prefetch_size != 0 || global_prefetch_count != 0) { - amqp_basic_qos( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - global_prefetch_size, - global_prefetch_count, - 1 - ); + /* Set the global prefetch settings (ignoring if 0 for backwards compatibility) */ + if (global_prefetch_size != 0 || global_prefetch_count != 0) { + amqp_basic_qos( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + global_prefetch_size, + global_prefetch_count, + 1 + ); - res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - } + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + } } /* }}} */ @@ -391,13 +458,13 @@ static PHP_METHOD(amqp_channel_class, __construct) check amqp channel */ static PHP_METHOD(amqp_channel_class, isConnected) { - amqp_channel_resource *channel_resource; + amqp_channel_resource *channel_resource; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS(); - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); - RETURN_BOOL(channel_resource && channel_resource->is_connected); + RETURN_BOOL(channel_resource && channel_resource->is_connected); } /* }}} */ @@ -411,7 +478,7 @@ static PHP_METHOD(amqp_channel_class, close) channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); - if(channel_resource && channel_resource->is_connected) { + if (channel_resource && channel_resource->is_connected) { php_amqp_close_channel(channel_resource, 1 TSRMLS_CC); } } @@ -421,17 +488,17 @@ static PHP_METHOD(amqp_channel_class, close) get amqp channel ID */ static PHP_METHOD(amqp_channel_class, getChannelId) { - amqp_channel_resource *channel_resource; + amqp_channel_resource *channel_resource; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS(); - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); - if (!channel_resource) { - RETURN_NULL(); - } + if (!channel_resource) { + RETURN_NULL(); + } - RETURN_LONG(channel_resource->channel_id); + RETURN_LONG(channel_resource->channel_id); } /* }}} */ @@ -439,74 +506,84 @@ static PHP_METHOD(amqp_channel_class, getChannelId) set the number of prefetches */ static PHP_METHOD(amqp_channel_class, setPrefetchCount) { - zval rv; - - amqp_channel_resource *channel_resource; - zend_long prefetch_count; + zval rv; + + amqp_channel_resource *channel_resource; + zend_long prefetch_count; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &prefetch_count) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &prefetch_count) == FAILURE) { + return; + } if (!php_amqp_is_valid_prefetch_count(prefetch_count)) { - zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'prefetch_count' must be between 0 and %u.", PHP_AMQP_MAX_PREFETCH_COUNT); + zend_throw_exception_ex( + amqp_connection_exception_class_entry, + 0 TSRMLS_CC, + "Parameter 'prefetch_count' must be between 0 and %u.", + PHP_AMQP_MAX_PREFETCH_COUNT + ); return; } - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); - PHP_AMQP_VERIFY_CHANNEL_CONNECTION_RESOURCE(channel_resource, "Could not set prefetch count."); - // TODO: verify that connection is active and resource exists. that is enough - - /* If we are already connected, set the new prefetch count */ - if (channel_resource->is_connected) { - amqp_basic_qos( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - 0, - (uint16_t)prefetch_count, - 0 - ); - - amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } - - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - - uint32_t global_prefetch_size = (uint32_t)PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_size"); - uint16_t global_prefetch_count = (uint16_t)PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_count"); - - /* Re-apply current global prefetch settings if set (writing consumer prefetch settings will clear global prefetch settings) */ - if (global_prefetch_size != 0 || global_prefetch_count != 0) { - amqp_basic_qos( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - global_prefetch_size, - global_prefetch_count, - 1 - ); - - res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } - - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - } - } - - /* Set the prefetch count - the implication is to disable the size */ - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("prefetch_count"), prefetch_count TSRMLS_CC); - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("prefetch_size"), 0 TSRMLS_CC); - - RETURN_TRUE; + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); + PHP_AMQP_VERIFY_CHANNEL_CONNECTION_RESOURCE(channel_resource, "Could not set prefetch count."); + // TODO: verify that connection is active and resource exists. that is enough + + /* If we are already connected, set the new prefetch count */ + if (channel_resource->is_connected) { + amqp_basic_qos( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + 0, + (uint16_t) prefetch_count, + 0 + ); + + amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } + + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + + uint32_t global_prefetch_size = (uint32_t) PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_size"); + uint16_t global_prefetch_count = (uint16_t) PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_count"); + + /* Re-apply current global prefetch settings if set (writing consumer prefetch settings will clear global prefetch settings) */ + if (global_prefetch_size != 0 || global_prefetch_count != 0) { + amqp_basic_qos( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + global_prefetch_size, + global_prefetch_count, + 1 + ); + + res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } + + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + } + } + + /* Set the prefetch count - the implication is to disable the size */ + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("prefetch_count"), + prefetch_count TSRMLS_CC + ); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("prefetch_size"), 0 TSRMLS_CC); + + RETURN_TRUE; } /* }}} */ @@ -514,9 +591,9 @@ static PHP_METHOD(amqp_channel_class, setPrefetchCount) get the number of prefetches */ static PHP_METHOD(amqp_channel_class, getPrefetchCount) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("prefetch_count") + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("prefetch_count") } /* }}} */ @@ -524,73 +601,83 @@ static PHP_METHOD(amqp_channel_class, getPrefetchCount) set the number of prefetches */ static PHP_METHOD(amqp_channel_class, setPrefetchSize) { - zval rv; + zval rv; - amqp_channel_resource *channel_resource; - zend_long prefetch_size; + amqp_channel_resource *channel_resource; + zend_long prefetch_size; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &prefetch_size) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &prefetch_size) == FAILURE) { + return; + } if (!php_amqp_is_valid_prefetch_size(prefetch_size)) { - zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'prefetch_size' must be between 0 and %u.", PHP_AMQP_MAX_PREFETCH_SIZE); + zend_throw_exception_ex( + amqp_connection_exception_class_entry, + 0 TSRMLS_CC, + "Parameter 'prefetch_size' must be between 0 and %u.", + PHP_AMQP_MAX_PREFETCH_SIZE + ); return; } - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); - PHP_AMQP_VERIFY_CHANNEL_CONNECTION_RESOURCE(channel_resource, "Could not set prefetch size."); - - /* If we are already connected, set the new prefetch count */ - if (channel_resource->is_connected) { - amqp_basic_qos( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - (uint32_t)prefetch_size, - 0, - 0 - ); - - amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } - - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - - uint32_t global_prefetch_size = (uint32_t)PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_size"); - uint16_t global_prefetch_count = (uint16_t)PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_count"); - - /* Re-apply current global prefetch settings if set (writing consumer prefetch settings will clear global prefetch settings) */ - if (global_prefetch_size != 0 || global_prefetch_count != 0) { - amqp_basic_qos( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - global_prefetch_size, - global_prefetch_count, - 1 - ); - - res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } - - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - } - } - - /* Set the prefetch size - the implication is to disable the count */ - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("prefetch_count"), 0 TSRMLS_CC); - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("prefetch_size"), prefetch_size TSRMLS_CC); - - RETURN_TRUE; + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); + PHP_AMQP_VERIFY_CHANNEL_CONNECTION_RESOURCE(channel_resource, "Could not set prefetch size."); + + /* If we are already connected, set the new prefetch count */ + if (channel_resource->is_connected) { + amqp_basic_qos( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + (uint32_t) prefetch_size, + 0, + 0 + ); + + amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } + + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + + uint32_t global_prefetch_size = (uint32_t) PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_size"); + uint16_t global_prefetch_count = (uint16_t) PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_count"); + + /* Re-apply current global prefetch settings if set (writing consumer prefetch settings will clear global prefetch settings) */ + if (global_prefetch_size != 0 || global_prefetch_count != 0) { + amqp_basic_qos( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + global_prefetch_size, + global_prefetch_count, + 1 + ); + + res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } + + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + } + } + + /* Set the prefetch size - the implication is to disable the count */ + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("prefetch_count"), 0 TSRMLS_CC); + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("prefetch_size"), + prefetch_size TSRMLS_CC + ); + + RETURN_TRUE; } /* }}} */ @@ -598,9 +685,9 @@ static PHP_METHOD(amqp_channel_class, setPrefetchSize) get the number of prefetches */ static PHP_METHOD(amqp_channel_class, getPrefetchSize) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("prefetch_size") + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("prefetch_size") } /* }}} */ @@ -608,48 +695,58 @@ static PHP_METHOD(amqp_channel_class, getPrefetchSize) set the number of prefetches */ static PHP_METHOD(amqp_channel_class, setGlobalPrefetchCount) { - amqp_channel_resource *channel_resource; - zend_long global_prefetch_count; + amqp_channel_resource *channel_resource; + zend_long global_prefetch_count; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &global_prefetch_count) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &global_prefetch_count) == FAILURE) { + return; + } if (!php_amqp_is_valid_prefetch_count(global_prefetch_count)) { - zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'global_prefetch_count' must be between 0 and %u.", PHP_AMQP_MAX_PREFETCH_COUNT); + zend_throw_exception_ex( + amqp_connection_exception_class_entry, + 0 TSRMLS_CC, + "Parameter 'global_prefetch_count' must be between 0 and %u.", + PHP_AMQP_MAX_PREFETCH_COUNT + ); return; } - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); - PHP_AMQP_VERIFY_CHANNEL_CONNECTION_RESOURCE(channel_resource, "Could not set global prefetch count."); - - /* If we are already connected, set the new prefetch count */ - if (channel_resource->is_connected) { - /* Applying global prefetch settings retains existing consumer prefetch settings */ - amqp_basic_qos( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - 0, - (uint16_t)global_prefetch_count, - 1 - ); - - amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); + PHP_AMQP_VERIFY_CHANNEL_CONNECTION_RESOURCE(channel_resource, "Could not set global prefetch count."); + + /* If we are already connected, set the new prefetch count */ + if (channel_resource->is_connected) { + /* Applying global prefetch settings retains existing consumer prefetch settings */ + amqp_basic_qos( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + 0, + (uint16_t) global_prefetch_count, + 1 + ); + + amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - } + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + } - /* Set the global prefetch count - the implication is to disable the size */ - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("global_prefetch_count"), global_prefetch_count TSRMLS_CC); - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("global_prefetch_size"), 0 TSRMLS_CC); + /* Set the global prefetch count - the implication is to disable the size */ + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("global_prefetch_count"), + global_prefetch_count TSRMLS_CC + ); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("global_prefetch_size"), 0 TSRMLS_CC); - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -657,9 +754,9 @@ static PHP_METHOD(amqp_channel_class, setGlobalPrefetchCount) get the number of prefetches */ static PHP_METHOD(amqp_channel_class, getGlobalPrefetchCount) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("global_prefetch_count") + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("global_prefetch_count") } /* }}} */ @@ -667,48 +764,63 @@ static PHP_METHOD(amqp_channel_class, getGlobalPrefetchCount) set the number of prefetches */ static PHP_METHOD(amqp_channel_class, setGlobalPrefetchSize) { - amqp_channel_resource *channel_resource; - zend_long global_prefetch_size; + amqp_channel_resource *channel_resource; + zend_long global_prefetch_size; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &global_prefetch_size) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &global_prefetch_size) == FAILURE) { + return; + } if (!php_amqp_is_valid_prefetch_size(global_prefetch_size)) { - zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'global_prefetch_size' must be between 0 and %u.", PHP_AMQP_MAX_PREFETCH_SIZE); + zend_throw_exception_ex( + amqp_connection_exception_class_entry, + 0 TSRMLS_CC, + "Parameter 'global_prefetch_size' must be between 0 and %u.", + PHP_AMQP_MAX_PREFETCH_SIZE + ); return; } - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); - PHP_AMQP_VERIFY_CHANNEL_CONNECTION_RESOURCE(channel_resource, "Could not set prefetch size."); - - /* If we are already connected, set the new prefetch count */ - if (channel_resource->is_connected) { - /* Applying global prefetch settings retains existing consumer prefetch settings */ - amqp_basic_qos( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - (uint32_t)global_prefetch_size, - 0, - 1 - ); - - amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } - - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - } + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); + PHP_AMQP_VERIFY_CHANNEL_CONNECTION_RESOURCE(channel_resource, "Could not set prefetch size."); + + /* If we are already connected, set the new prefetch count */ + if (channel_resource->is_connected) { + /* Applying global prefetch settings retains existing consumer prefetch settings */ + amqp_basic_qos( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + (uint32_t) global_prefetch_size, + 0, + 1 + ); + + amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } - /* Set the global prefetch size - the implication is to disable the count */ - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("global_prefetch_count"), 0 TSRMLS_CC); - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("global_prefetch_size"), global_prefetch_size TSRMLS_CC); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + } - RETURN_TRUE; + /* Set the global prefetch size - the implication is to disable the count */ + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("global_prefetch_count"), + 0 TSRMLS_CC + ); + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("global_prefetch_size"), + global_prefetch_size TSRMLS_CC + ); + + RETURN_TRUE; } /* }}} */ @@ -716,9 +828,9 @@ static PHP_METHOD(amqp_channel_class, setGlobalPrefetchSize) get the number of prefetches */ static PHP_METHOD(amqp_channel_class, getGlobalPrefetchSize) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("global_prefetch_size") + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("global_prefetch_size") } /* }}} */ @@ -726,76 +838,96 @@ static PHP_METHOD(amqp_channel_class, getGlobalPrefetchSize) set the number of prefetches */ static PHP_METHOD(amqp_channel_class, qos) { - zval rv; - - amqp_channel_resource *channel_resource; - zend_long prefetch_size; - zend_long prefetch_count; - zend_bool global = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll|b", &prefetch_size, &prefetch_count, &global) == FAILURE) { - return; - } - - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); - PHP_AMQP_VERIFY_CHANNEL_CONNECTION_RESOURCE(channel_resource, "Could not set qos parameters."); - - /* Set the prefetch size and prefetch count */ - if (global) { - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("global_prefetch_size"), prefetch_size TSRMLS_CC); - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("global_prefetch_count"), prefetch_count TSRMLS_CC); - } else { - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("prefetch_size"), prefetch_size TSRMLS_CC); - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("prefetch_count"), prefetch_count TSRMLS_CC); - } - - /* If we are already connected, set the new prefetch count */ - if (channel_resource->is_connected) { - amqp_basic_qos( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - (uint32_t)PHP_AMQP_READ_THIS_PROP_LONG("prefetch_size"), - (uint16_t)PHP_AMQP_READ_THIS_PROP_LONG("prefetch_count"), - /* NOTE that RabbitMQ has reinterpreted global flag field. See https://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.qos.global for details */ - 0 /* Global flag - whether this change should affect every channel_resource */ - ); - - amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } - - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - - uint32_t global_prefetch_size = (uint32_t)PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_size"); - uint16_t global_prefetch_count = (uint16_t)PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_count"); - - /* Re-apply current global prefetch settings if set (writing consumer prefetch settings will clear global prefetch settings) */ - if (global_prefetch_size != 0 || global_prefetch_count != 0) { - amqp_basic_qos( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - global_prefetch_size, - global_prefetch_count, - 1 - ); - - res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } - - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - } - } - - RETURN_TRUE; + zval rv; + + amqp_channel_resource *channel_resource; + zend_long prefetch_size; + zend_long prefetch_count; + zend_bool global = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll|b", &prefetch_size, &prefetch_count, &global) == FAILURE) { + return; + } + + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); + PHP_AMQP_VERIFY_CHANNEL_CONNECTION_RESOURCE(channel_resource, "Could not set qos parameters."); + + /* Set the prefetch size and prefetch count */ + if (global) { + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("global_prefetch_size"), + prefetch_size TSRMLS_CC + ); + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("global_prefetch_count"), + prefetch_count TSRMLS_CC + ); + } else { + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("prefetch_size"), + prefetch_size TSRMLS_CC + ); + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("prefetch_count"), + prefetch_count TSRMLS_CC + ); + } + + /* If we are already connected, set the new prefetch count */ + if (channel_resource->is_connected) { + amqp_basic_qos( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + (uint32_t) PHP_AMQP_READ_THIS_PROP_LONG("prefetch_size"), + (uint16_t) PHP_AMQP_READ_THIS_PROP_LONG("prefetch_count"), + /* NOTE that RabbitMQ has reinterpreted global flag field. See https://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.qos.global for details */ + 0 /* Global flag - whether this change should affect every channel_resource */ + ); + + amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } + + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + + uint32_t global_prefetch_size = (uint32_t) PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_size"); + uint16_t global_prefetch_count = (uint16_t) PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_count"); + + /* Re-apply current global prefetch settings if set (writing consumer prefetch settings will clear global prefetch settings) */ + if (global_prefetch_size != 0 || global_prefetch_count != 0) { + amqp_basic_qos( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + global_prefetch_size, + global_prefetch_count, + 1 + ); + + res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } + + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + } + } + + RETURN_TRUE; } /* }}} */ @@ -804,33 +936,30 @@ static PHP_METHOD(amqp_channel_class, qos) start a transaction on the given channel */ static PHP_METHOD(amqp_channel_class, startTransaction) { - amqp_channel_resource *channel_resource; + amqp_channel_resource *channel_resource; - amqp_rpc_reply_t res; + amqp_rpc_reply_t res; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { + return; + } - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); - PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not start the transaction."); + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not start the transaction."); - amqp_tx_select( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id - ); + amqp_tx_select(channel_resource->connection_resource->connection_state, channel_resource->channel_id); - res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -839,33 +968,30 @@ static PHP_METHOD(amqp_channel_class, startTransaction) start a transaction on the given channel */ static PHP_METHOD(amqp_channel_class, commitTransaction) { - amqp_channel_resource *channel_resource; + amqp_channel_resource *channel_resource; - amqp_rpc_reply_t res; + amqp_rpc_reply_t res; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { + return; + } - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); - PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not start the transaction."); + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not start the transaction."); - amqp_tx_commit( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id - ); + amqp_tx_commit(channel_resource->connection_resource->connection_state, channel_resource->channel_id); - res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -873,34 +999,31 @@ static PHP_METHOD(amqp_channel_class, commitTransaction) start a transaction on the given channel */ static PHP_METHOD(amqp_channel_class, rollbackTransaction) { - amqp_channel_resource *channel_resource; + amqp_channel_resource *channel_resource; - amqp_rpc_reply_t res; + amqp_rpc_reply_t res; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { + return; + } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { - return; - } - - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); - PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not rollback the transaction."); + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not rollback the transaction."); - amqp_tx_rollback( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id - ); + amqp_tx_rollback(channel_resource->connection_resource->connection_state, channel_resource->channel_id); - res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -908,9 +1031,9 @@ static PHP_METHOD(amqp_channel_class, rollbackTransaction) Get the AMQPConnection object in use */ static PHP_METHOD(amqp_channel_class, getConnection) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("connection") + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("connection") } /* }}} */ @@ -918,36 +1041,36 @@ static PHP_METHOD(amqp_channel_class, getConnection) Redeliver unacknowledged messages */ static PHP_METHOD(amqp_channel_class, basicRecover) { - amqp_channel_resource *channel_resource; + amqp_channel_resource *channel_resource; - amqp_rpc_reply_t res; + amqp_rpc_reply_t res; - zend_bool requeue = 1; + zend_bool requeue = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &requeue) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &requeue) == FAILURE) { + return; + } - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); - PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not redeliver unacknowledged messages."); + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not redeliver unacknowledged messages."); - amqp_basic_recover( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - (amqp_boolean_t) requeue - ); + amqp_basic_recover( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + (amqp_boolean_t) requeue + ); - res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -955,32 +1078,29 @@ static PHP_METHOD(amqp_channel_class, basicRecover) Redeliver unacknowledged messages */ PHP_METHOD(amqp_channel_class, confirmSelect) { - amqp_channel_resource *channel_resource; - amqp_rpc_reply_t res; + amqp_channel_resource *channel_resource; + amqp_rpc_reply_t res; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { + return; + } - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); - PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not enable confirms mode."); + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not enable confirms mode."); - amqp_confirm_select( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id - ); + amqp_confirm_select(channel_resource->connection_resource->connection_state, channel_resource->channel_id); - res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -988,22 +1108,22 @@ PHP_METHOD(amqp_channel_class, confirmSelect) Set callback for basic.return server method handling */ PHP_METHOD(amqp_channel_class, setReturnCallback) { - zend_fcall_info fci = empty_fcall_info; - zend_fcall_info_cache fcc = empty_fcall_info_cache; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f!", &fci, &fcc) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f!", &fci, &fcc) == FAILURE) { + return; + } - amqp_channel_object *channel = PHP_AMQP_GET_CHANNEL(getThis()); + amqp_channel_object *channel = PHP_AMQP_GET_CHANNEL(getThis()); - php_amqp_destroy_fci(&channel->callbacks.basic_return.fci); + php_amqp_destroy_fci(&channel->callbacks.basic_return.fci); - if (ZEND_FCI_INITIALIZED(fci)) { - php_amqp_duplicate_fci(&fci); - channel->callbacks.basic_return.fci = fci; - channel->callbacks.basic_return.fcc = fcc; - } + if (ZEND_FCI_INITIALIZED(fci)) { + php_amqp_duplicate_fci(&fci); + channel->callbacks.basic_return.fci = fci; + channel->callbacks.basic_return.fcc = fcc; + } } /* }}} */ @@ -1011,91 +1131,127 @@ PHP_METHOD(amqp_channel_class, setReturnCallback) Wait for basic.return method from server */ PHP_METHOD(amqp_channel_class, waitForBasicReturn) { - amqp_channel_object *channel; - amqp_channel_resource *channel_resource; - amqp_method_t method; - - int status; - - double timeout = 0; - - struct timeval tv = {0}; - struct timeval *tv_ptr = &tv; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|d", &timeout) == FAILURE) { - return; - } - - if (timeout < 0) { - zend_throw_exception(amqp_channel_exception_class_entry, "Timeout must be greater than or equal to zero.", 0 TSRMLS_CC); - return; - } - - channel = PHP_AMQP_GET_CHANNEL(getThis()); + amqp_channel_object *channel; + amqp_channel_resource *channel_resource; + amqp_method_t method; - channel_resource = channel->channel_resource; - PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not start wait loop for basic.return method."); + int status; - if (timeout > 0) { - tv.tv_sec = (long int) timeout; - tv.tv_usec = (long int) ((timeout - tv.tv_sec) * 1000000); - } else { - tv_ptr = NULL; - } + double timeout = 0; - assert(channel_resource->channel_id > 0); + struct timeval tv = {0}; + struct timeval *tv_ptr = &tv; - while(1) { - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|d", &timeout) == FAILURE) { + return; + } - status = amqp_simple_wait_method_noblock(channel_resource->connection_resource->connection_state, channel_resource->channel_id, AMQP_BASIC_RETURN_METHOD, &method, tv_ptr); + if (timeout < 0) { + zend_throw_exception( + amqp_channel_exception_class_entry, + "Timeout must be greater than or equal to zero.", + 0 TSRMLS_CC + ); + return; + } - if (AMQP_STATUS_TIMEOUT == status) { - zend_throw_exception(amqp_queue_exception_class_entry, "Wait timeout exceed", 0 TSRMLS_CC); + channel = PHP_AMQP_GET_CHANNEL(getThis()); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } + channel_resource = channel->channel_resource; + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not start wait loop for basic.return method."); - if (status != AMQP_STATUS_OK) { - /* Emulate library error */ - amqp_rpc_reply_t res; + if (timeout > 0) { + tv.tv_sec = (long int) timeout; + tv.tv_usec = (long int) ((timeout - tv.tv_sec) * 1000000); + } else { + tv_ptr = NULL; + } - if (AMQP_RESPONSE_SERVER_EXCEPTION == status) { - res.reply_type = AMQP_RESPONSE_SERVER_EXCEPTION; - res.reply = method; - } else { - res.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; - res.library_error = status; - } + assert(channel_resource->channel_id > 0); - php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource TSRMLS_CC); + while (1) { + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, PHP_AMQP_G(error_message), PHP_AMQP_G(error_code) TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } + status = amqp_simple_wait_method_noblock( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + AMQP_BASIC_RETURN_METHOD, + &method, + tv_ptr + ); - status = php_amqp_handle_basic_return(&PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource->channel_id, channel, &method TSRMLS_CC); + if (AMQP_STATUS_TIMEOUT == status) { + zend_throw_exception(amqp_queue_exception_class_entry, "Wait timeout exceed", 0 TSRMLS_CC); - if (PHP_AMQP_RESOURCE_RESPONSE_BREAK == status) { - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - break; - } + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } - if (PHP_AMQP_RESOURCE_RESPONSE_OK != status) { - /* Emulate library error */ - amqp_rpc_reply_t res; - res.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; - res.library_error = status; + if (status != AMQP_STATUS_OK) { + /* Emulate library error */ + amqp_rpc_reply_t res; + + if (AMQP_RESPONSE_SERVER_EXCEPTION == status) { + res.reply_type = AMQP_RESPONSE_SERVER_EXCEPTION; + res.reply = method; + } else { + res.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; + res.library_error = status; + } + + php_amqp_error( + res, + &PHP_AMQP_G(error_message), + channel_resource->connection_resource, + channel_resource TSRMLS_CC + ); + + php_amqp_zend_throw_exception( + res, + amqp_queue_exception_class_entry, + PHP_AMQP_G(error_message), + PHP_AMQP_G(error_code) TSRMLS_CC + ); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } - php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource TSRMLS_CC); + status = php_amqp_handle_basic_return( + &PHP_AMQP_G(error_message), + channel_resource->connection_resource, + channel_resource->channel_id, + channel, + &method TSRMLS_CC + ); + + if (PHP_AMQP_RESOURCE_RESPONSE_BREAK == status) { + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + break; + } - php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, PHP_AMQP_G(error_message), PHP_AMQP_G(error_code) TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } - } + if (PHP_AMQP_RESOURCE_RESPONSE_OK != status) { + /* Emulate library error */ + amqp_rpc_reply_t res; + res.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; + res.library_error = status; + + php_amqp_error( + res, + &PHP_AMQP_G(error_message), + channel_resource->connection_resource, + channel_resource TSRMLS_CC + ); + + php_amqp_zend_throw_exception( + res, + amqp_channel_exception_class_entry, + PHP_AMQP_G(error_message), + PHP_AMQP_G(error_code) TSRMLS_CC + ); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } + } } /* }}} */ @@ -1103,33 +1259,34 @@ PHP_METHOD(amqp_channel_class, waitForBasicReturn) Set callback for basic.ack and, optionally, basic.nac server methods handling */ PHP_METHOD(amqp_channel_class, setConfirmCallback) { - zend_fcall_info ack_fci = empty_fcall_info; - zend_fcall_info_cache ack_fcc = empty_fcall_info_cache; + zend_fcall_info ack_fci = empty_fcall_info; + zend_fcall_info_cache ack_fcc = empty_fcall_info_cache; - zend_fcall_info nack_fci = empty_fcall_info; - zend_fcall_info_cache nack_fcc = empty_fcall_info_cache; + zend_fcall_info nack_fci = empty_fcall_info; + zend_fcall_info_cache nack_fcc = empty_fcall_info_cache; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f!|f!", &ack_fci, &ack_fcc, &nack_fci, &nack_fcc) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f!|f!", &ack_fci, &ack_fcc, &nack_fci, &nack_fcc) == + FAILURE) { + return; + } - amqp_channel_object *channel = PHP_AMQP_GET_CHANNEL(getThis()); + amqp_channel_object *channel = PHP_AMQP_GET_CHANNEL(getThis()); - php_amqp_destroy_fci(&channel->callbacks.basic_ack.fci); + php_amqp_destroy_fci(&channel->callbacks.basic_ack.fci); - if (ZEND_FCI_INITIALIZED(ack_fci)) { - php_amqp_duplicate_fci(&ack_fci); - channel->callbacks.basic_ack.fci = ack_fci; - channel->callbacks.basic_ack.fcc = ack_fcc; - } + if (ZEND_FCI_INITIALIZED(ack_fci)) { + php_amqp_duplicate_fci(&ack_fci); + channel->callbacks.basic_ack.fci = ack_fci; + channel->callbacks.basic_ack.fcc = ack_fcc; + } - php_amqp_destroy_fci(&channel->callbacks.basic_nack.fci); + php_amqp_destroy_fci(&channel->callbacks.basic_nack.fci); - if (ZEND_FCI_INITIALIZED(nack_fci)) { - php_amqp_duplicate_fci(&nack_fci); - channel->callbacks.basic_nack.fci = nack_fci; - channel->callbacks.basic_nack.fcc = nack_fcc; - } + if (ZEND_FCI_INITIALIZED(nack_fci)) { + php_amqp_duplicate_fci(&nack_fci); + channel->callbacks.basic_nack.fci = nack_fci; + channel->callbacks.basic_nack.fcc = nack_fcc; + } } /* }}} */ @@ -1138,121 +1295,170 @@ PHP_METHOD(amqp_channel_class, setConfirmCallback) Redeliver unacknowledged messages */ PHP_METHOD(amqp_channel_class, waitForConfirm) { - amqp_channel_object *channel; - amqp_channel_resource *channel_resource; - amqp_method_t method; - - int status; - - double timeout = 0; - - struct timeval tv = {0}; - struct timeval *tv_ptr = &tv; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|d", &timeout) == FAILURE) { - return; - } - - if (timeout < 0) { - zend_throw_exception(amqp_channel_exception_class_entry, "Timeout must be greater than or equal to zero.", 0 TSRMLS_CC); - return; - } - - channel = PHP_AMQP_GET_CHANNEL(getThis()); - - channel_resource = channel->channel_resource; - PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not start wait loop for basic.return method."); - - if (timeout > 0) { - tv.tv_sec = (long int) timeout; - tv.tv_usec = (long int) ((timeout - tv.tv_sec) * 1000000); - } else { - tv_ptr = NULL; - } - - assert(channel_resource->channel_id > 0); - - - amqp_method_number_t expected_methods[] = { AMQP_BASIC_ACK_METHOD, AMQP_BASIC_NACK_METHOD, AMQP_BASIC_RETURN_METHOD, 0 }; - - while(1) { - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - - status = amqp_simple_wait_method_list_noblock(channel_resource->connection_resource->connection_state, channel_resource->channel_id, expected_methods, &method, tv_ptr); - - if (AMQP_STATUS_TIMEOUT == status) { - zend_throw_exception(amqp_queue_exception_class_entry, "Wait timeout exceed", 0 TSRMLS_CC); - - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } - - if (status != AMQP_STATUS_OK) { - /* Emulate library error */ - amqp_rpc_reply_t res; - - if (AMQP_RESPONSE_SERVER_EXCEPTION == status) { - res.reply_type = AMQP_RESPONSE_SERVER_EXCEPTION; - res.reply = method; - } else { - res.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; - res.library_error = status; - } - - php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource TSRMLS_CC); - - php_amqp_zend_throw_exception(res, amqp_channel_exception_class_entry, PHP_AMQP_G(error_message), PHP_AMQP_G(error_code) TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } - - switch(method.id) { - case AMQP_BASIC_ACK_METHOD: - status = php_amqp_handle_basic_ack(&PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource->channel_id, channel, &method TSRMLS_CC); - break; - case AMQP_BASIC_NACK_METHOD: - status = php_amqp_handle_basic_nack(&PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource->channel_id, channel, &method TSRMLS_CC); - break; - case AMQP_BASIC_RETURN_METHOD: - status = php_amqp_handle_basic_return(&PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource->channel_id, channel, &method TSRMLS_CC); - break; - default: - status = AMQP_STATUS_WRONG_METHOD; - } - - if (PHP_AMQP_RESOURCE_RESPONSE_BREAK == status) { - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - break; - } - - if (PHP_AMQP_RESOURCE_RESPONSE_OK != status) { - /* Emulate library error */ - amqp_rpc_reply_t res; - res.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; - res.library_error = status; - - php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource TSRMLS_CC); - - php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, PHP_AMQP_G(error_message), PHP_AMQP_G(error_code) TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } - } + amqp_channel_object *channel; + amqp_channel_resource *channel_resource; + amqp_method_t method; + + int status; + + double timeout = 0; + + struct timeval tv = {0}; + struct timeval *tv_ptr = &tv; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|d", &timeout) == FAILURE) { + return; + } + + if (timeout < 0) { + zend_throw_exception( + amqp_channel_exception_class_entry, + "Timeout must be greater than or equal to zero.", + 0 TSRMLS_CC + ); + return; + } + + channel = PHP_AMQP_GET_CHANNEL(getThis()); + + channel_resource = channel->channel_resource; + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not start wait loop for basic.return method."); + + if (timeout > 0) { + tv.tv_sec = (long int) timeout; + tv.tv_usec = (long int) ((timeout - tv.tv_sec) * 1000000); + } else { + tv_ptr = NULL; + } + + assert(channel_resource->channel_id > 0); + + + amqp_method_number_t expected_methods[] = + {AMQP_BASIC_ACK_METHOD, AMQP_BASIC_NACK_METHOD, AMQP_BASIC_RETURN_METHOD, 0}; + + while (1) { + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + + status = amqp_simple_wait_method_list_noblock( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + expected_methods, + &method, + tv_ptr + ); + + if (AMQP_STATUS_TIMEOUT == status) { + zend_throw_exception(amqp_queue_exception_class_entry, "Wait timeout exceed", 0 TSRMLS_CC); + + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } + + if (status != AMQP_STATUS_OK) { + /* Emulate library error */ + amqp_rpc_reply_t res; + + if (AMQP_RESPONSE_SERVER_EXCEPTION == status) { + res.reply_type = AMQP_RESPONSE_SERVER_EXCEPTION; + res.reply = method; + } else { + res.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; + res.library_error = status; + } + + php_amqp_error( + res, + &PHP_AMQP_G(error_message), + channel_resource->connection_resource, + channel_resource TSRMLS_CC + ); + + php_amqp_zend_throw_exception( + res, + amqp_channel_exception_class_entry, + PHP_AMQP_G(error_message), + PHP_AMQP_G(error_code) TSRMLS_CC + ); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } + + switch (method.id) { + case AMQP_BASIC_ACK_METHOD: + status = php_amqp_handle_basic_ack( + &PHP_AMQP_G(error_message), + channel_resource->connection_resource, + channel_resource->channel_id, + channel, + &method TSRMLS_CC + ); + break; + case AMQP_BASIC_NACK_METHOD: + status = php_amqp_handle_basic_nack( + &PHP_AMQP_G(error_message), + channel_resource->connection_resource, + channel_resource->channel_id, + channel, + &method TSRMLS_CC + ); + break; + case AMQP_BASIC_RETURN_METHOD: + status = php_amqp_handle_basic_return( + &PHP_AMQP_G(error_message), + channel_resource->connection_resource, + channel_resource->channel_id, + channel, + &method TSRMLS_CC + ); + break; + default: + status = AMQP_STATUS_WRONG_METHOD; + } + + if (PHP_AMQP_RESOURCE_RESPONSE_BREAK == status) { + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + break; + } + + if (PHP_AMQP_RESOURCE_RESPONSE_OK != status) { + /* Emulate library error */ + amqp_rpc_reply_t res; + res.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; + res.library_error = status; + + php_amqp_error( + res, + &PHP_AMQP_G(error_message), + channel_resource->connection_resource, + channel_resource TSRMLS_CC + ); + + php_amqp_zend_throw_exception( + res, + amqp_queue_exception_class_entry, + PHP_AMQP_G(error_message), + PHP_AMQP_G(error_code) TSRMLS_CC + ); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } + } } /* }}} */ /* {{{ proto amqp::getConsumers() */ static PHP_METHOD(amqp_channel_class, getConsumers) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("consumers"); + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("consumers"); } /* }}} */ ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class__construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_OBJ_INFO(0, amqp_connection, AMQPConnection, 0) + ZEND_ARG_OBJ_INFO(0, amqp_connection, AMQPConnection, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_isConnected, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) @@ -1265,37 +1471,37 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_getChannelId, ZEND_SEND_BY_VAL ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_setPrefetchSize, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, size) + ZEND_ARG_INFO(0, size) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_getPrefetchSize, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_setPrefetchCount, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, count) + ZEND_ARG_INFO(0, count) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_getPrefetchCount, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_setGlobalPrefetchSize, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, size) + ZEND_ARG_INFO(0, size) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_getGlobalPrefetchSize, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_setGlobalPrefetchCount, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, count) + ZEND_ARG_INFO(0, count) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_getGlobalPrefetchCount, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_qos, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 2) - ZEND_ARG_INFO(0, size) - ZEND_ARG_INFO(0, count) - ZEND_ARG_INFO(0, global) + ZEND_ARG_INFO(0, size) + ZEND_ARG_INFO(0, count) + ZEND_ARG_INFO(0, global) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_startTransaction, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) @@ -1311,27 +1517,27 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_getConnection, ZEND_SEND_BY_VA ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_basicRecover, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) - ZEND_ARG_INFO(0, requeue) + ZEND_ARG_INFO(0, requeue) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_confirmSelect, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_setConfirmCallback, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, ack_callback) - ZEND_ARG_INFO(0, nack_callback) + ZEND_ARG_INFO(0, ack_callback) + ZEND_ARG_INFO(0, nack_callback) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_waitForConfirm, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) - ZEND_ARG_INFO(0, timeout) + ZEND_ARG_INFO(0, timeout) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_setReturnCallback, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, return_callback) + ZEND_ARG_INFO(0, return_callback) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_waitForBasicReturn, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) - ZEND_ARG_INFO(0, timeout) + ZEND_ARG_INFO(0, timeout) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_getConsumers, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) @@ -1341,77 +1547,69 @@ ZEND_END_ARG_INFO() zend_function_entry amqp_channel_class_functions[] = { - PHP_ME(amqp_channel_class, __construct, arginfo_amqp_channel_class__construct, ZEND_ACC_PUBLIC) - PHP_ME(amqp_channel_class, isConnected, arginfo_amqp_channel_class_isConnected, ZEND_ACC_PUBLIC) - PHP_ME(amqp_channel_class, close, arginfo_amqp_channel_class_close, ZEND_ACC_PUBLIC) + PHP_ME(amqp_channel_class, __construct, arginfo_amqp_channel_class__construct, ZEND_ACC_PUBLIC) + PHP_ME(amqp_channel_class, isConnected, arginfo_amqp_channel_class_isConnected, ZEND_ACC_PUBLIC) + PHP_ME(amqp_channel_class, close, arginfo_amqp_channel_class_close, ZEND_ACC_PUBLIC) - PHP_ME(amqp_channel_class, getChannelId, arginfo_amqp_channel_class_getChannelId, ZEND_ACC_PUBLIC) + PHP_ME(amqp_channel_class, getChannelId, arginfo_amqp_channel_class_getChannelId, ZEND_ACC_PUBLIC) - PHP_ME(amqp_channel_class, setPrefetchSize, arginfo_amqp_channel_class_setPrefetchSize, ZEND_ACC_PUBLIC) - PHP_ME(amqp_channel_class, getPrefetchSize, arginfo_amqp_channel_class_getPrefetchSize, ZEND_ACC_PUBLIC) - PHP_ME(amqp_channel_class, setPrefetchCount, arginfo_amqp_channel_class_setPrefetchCount, ZEND_ACC_PUBLIC) - PHP_ME(amqp_channel_class, getPrefetchCount, arginfo_amqp_channel_class_getPrefetchCount, ZEND_ACC_PUBLIC) - PHP_ME(amqp_channel_class, setGlobalPrefetchSize, arginfo_amqp_channel_class_setGlobalPrefetchSize, ZEND_ACC_PUBLIC) - PHP_ME(amqp_channel_class, getGlobalPrefetchSize, arginfo_amqp_channel_class_getGlobalPrefetchSize, ZEND_ACC_PUBLIC) - PHP_ME(amqp_channel_class, setGlobalPrefetchCount, arginfo_amqp_channel_class_setGlobalPrefetchCount, ZEND_ACC_PUBLIC) - PHP_ME(amqp_channel_class, getGlobalPrefetchCount, arginfo_amqp_channel_class_getGlobalPrefetchCount, ZEND_ACC_PUBLIC) - PHP_ME(amqp_channel_class, qos, arginfo_amqp_channel_class_qos, ZEND_ACC_PUBLIC) + PHP_ME(amqp_channel_class, setPrefetchSize, arginfo_amqp_channel_class_setPrefetchSize, ZEND_ACC_PUBLIC) + PHP_ME(amqp_channel_class, getPrefetchSize, arginfo_amqp_channel_class_getPrefetchSize, ZEND_ACC_PUBLIC) + PHP_ME(amqp_channel_class, setPrefetchCount, arginfo_amqp_channel_class_setPrefetchCount, ZEND_ACC_PUBLIC) + PHP_ME(amqp_channel_class, getPrefetchCount, arginfo_amqp_channel_class_getPrefetchCount, ZEND_ACC_PUBLIC) + PHP_ME(amqp_channel_class, setGlobalPrefetchSize, arginfo_amqp_channel_class_setGlobalPrefetchSize, ZEND_ACC_PUBLIC) + PHP_ME(amqp_channel_class, getGlobalPrefetchSize, arginfo_amqp_channel_class_getGlobalPrefetchSize, ZEND_ACC_PUBLIC) + PHP_ME(amqp_channel_class, setGlobalPrefetchCount, arginfo_amqp_channel_class_setGlobalPrefetchCount, ZEND_ACC_PUBLIC) + PHP_ME(amqp_channel_class, getGlobalPrefetchCount, arginfo_amqp_channel_class_getGlobalPrefetchCount, ZEND_ACC_PUBLIC) + PHP_ME(amqp_channel_class, qos, arginfo_amqp_channel_class_qos, ZEND_ACC_PUBLIC) - PHP_ME(amqp_channel_class, startTransaction, arginfo_amqp_channel_class_startTransaction, ZEND_ACC_PUBLIC) - PHP_ME(amqp_channel_class, commitTransaction, arginfo_amqp_channel_class_commitTransaction, ZEND_ACC_PUBLIC) - PHP_ME(amqp_channel_class, rollbackTransaction, arginfo_amqp_channel_class_rollbackTransaction, ZEND_ACC_PUBLIC) + PHP_ME(amqp_channel_class, startTransaction, arginfo_amqp_channel_class_startTransaction, ZEND_ACC_PUBLIC) + PHP_ME(amqp_channel_class, commitTransaction, arginfo_amqp_channel_class_commitTransaction, ZEND_ACC_PUBLIC) + PHP_ME(amqp_channel_class, rollbackTransaction, arginfo_amqp_channel_class_rollbackTransaction, ZEND_ACC_PUBLIC) - PHP_ME(amqp_channel_class, getConnection, arginfo_amqp_channel_class_getConnection, ZEND_ACC_PUBLIC) + PHP_ME(amqp_channel_class, getConnection, arginfo_amqp_channel_class_getConnection, ZEND_ACC_PUBLIC) - PHP_ME(amqp_channel_class, basicRecover, arginfo_amqp_channel_class_basicRecover, ZEND_ACC_PUBLIC) + PHP_ME(amqp_channel_class, basicRecover, arginfo_amqp_channel_class_basicRecover, ZEND_ACC_PUBLIC) - PHP_ME(amqp_channel_class, confirmSelect, arginfo_amqp_channel_class_confirmSelect, ZEND_ACC_PUBLIC) - PHP_ME(amqp_channel_class, waitForConfirm, arginfo_amqp_channel_class_waitForConfirm, ZEND_ACC_PUBLIC) - PHP_ME(amqp_channel_class, setConfirmCallback, arginfo_amqp_channel_class_setConfirmCallback, ZEND_ACC_PUBLIC) + PHP_ME(amqp_channel_class, confirmSelect, arginfo_amqp_channel_class_confirmSelect, ZEND_ACC_PUBLIC) + PHP_ME(amqp_channel_class, waitForConfirm, arginfo_amqp_channel_class_waitForConfirm, ZEND_ACC_PUBLIC) + PHP_ME(amqp_channel_class, setConfirmCallback, arginfo_amqp_channel_class_setConfirmCallback, ZEND_ACC_PUBLIC) - PHP_ME(amqp_channel_class, setReturnCallback, arginfo_amqp_channel_class_setReturnCallback, ZEND_ACC_PUBLIC) - PHP_ME(amqp_channel_class, waitForBasicReturn, arginfo_amqp_channel_class_waitForBasicReturn, ZEND_ACC_PUBLIC) + PHP_ME(amqp_channel_class, setReturnCallback, arginfo_amqp_channel_class_setReturnCallback, ZEND_ACC_PUBLIC) + PHP_ME(amqp_channel_class, waitForBasicReturn, arginfo_amqp_channel_class_waitForBasicReturn, ZEND_ACC_PUBLIC) - PHP_ME(amqp_channel_class, getConsumers, arginfo_amqp_channel_class_getConsumers, ZEND_ACC_PUBLIC) + PHP_ME(amqp_channel_class, getConsumers, arginfo_amqp_channel_class_getConsumers, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} + {NULL, NULL, NULL} }; PHP_MINIT_FUNCTION(amqp_channel) { - zend_class_entry ce; + zend_class_entry ce; - INIT_CLASS_ENTRY(ce, "AMQPChannel", amqp_channel_class_functions); - ce.create_object = amqp_channel_ctor; - amqp_channel_class_entry = zend_register_internal_class(&ce TSRMLS_CC); + INIT_CLASS_ENTRY(ce, "AMQPChannel", amqp_channel_class_functions); + ce.create_object = amqp_channel_ctor; + amqp_channel_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("connection"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("connection"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("prefetch_count"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_long(this_ce, ZEND_STRL("prefetch_size"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("global_prefetch_count"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("global_prefetch_size"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("prefetch_count"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_long(this_ce, ZEND_STRL("prefetch_size"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("global_prefetch_count"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("global_prefetch_size"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("consumers"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("consumers"), ZEND_ACC_PRIVATE TSRMLS_CC); -#if PHP_MAJOR_VERSION >=7 - memcpy(&amqp_channel_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); +#if PHP_MAJOR_VERSION >= 7 + memcpy(&amqp_channel_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); - amqp_channel_object_handlers.offset = XtOffsetOf(amqp_channel_object, zo); - amqp_channel_object_handlers.free_obj = amqp_channel_free; + amqp_channel_object_handlers.offset = XtOffsetOf(amqp_channel_object, zo); + amqp_channel_object_handlers.free_obj = amqp_channel_free; #endif #if ZEND_MODULE_API_NO >= 20100000 - amqp_channel_object_handlers.get_gc = amqp_channel_gc; + amqp_channel_object_handlers.get_gc = amqp_channel_gc; #endif - return SUCCESS; + 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 -*/ diff --git a/amqp_channel.h b/amqp_channel.h index 41691864..6e036cc5 100644 --- a/amqp_channel.h +++ b/amqp_channel.h @@ -25,12 +25,3 @@ extern zend_class_entry *amqp_channel_class_entry; void php_amqp_close_channel(amqp_channel_resource *channel_resource, zend_bool check_errors TSRMLS_DC); PHP_MINIT_FUNCTION(amqp_channel); - -/* -*Local variables: -*tab-width: 4 -*c-basic-offset: 4 -*End: -*vim600: noet sw=4 ts=4 fdm=marker -*vim<600: noet sw=4 ts=4 -*/ diff --git a/amqp_connection.c b/amqp_connection.c index 6521038f..a91dcdf2 100644 --- a/amqp_connection.c +++ b/amqp_connection.c @@ -23,7 +23,7 @@ #ifdef HAVE_CONFIG_H -#include "config.h" + #include "config.h" #endif #include "php.h" @@ -31,30 +31,30 @@ #include "zend_exceptions.h" #ifdef PHP_WIN32 -# if PHP_VERSION_ID >= 80000 -# include "main/php_stdint.h" -# else -# include "win32/php_stdint.h" -# endif -# include "win32/signal.h" + #if PHP_VERSION_ID >= 80000 + #include "main/php_stdint.h" + #else + #include "win32/php_stdint.h" + #endif + #include "win32/signal.h" #else -# include -# include + #include + #include #endif #if HAVE_LIBRABBITMQ_NEW_LAYOUT -#include -#include -#include + #include + #include + #include #else -#include -#include -#include + #include + #include + #include #endif #ifdef PHP_WIN32 -# include "win32/unistd.h" + #include "win32/unistd.h" #else -# include + #include #endif #include "php_amqp.h" @@ -63,7 +63,7 @@ #include "amqp_connection.h" #ifndef E_DEPRECATED -#define E_DEPRECATED E_WARNING + #define E_DEPRECATED E_WARNING #endif zend_class_entry *amqp_connection_class_entry; @@ -71,99 +71,126 @@ zend_class_entry *amqp_connection_class_entry; zend_object_handlers amqp_connection_object_handlers; -#define PHP_AMQP_EXTRACT_CONNECTION_STR(name) \ - zdata = NULL; \ - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), (name), sizeof(name))) != NULL) { \ - SEPARATE_ZVAL(zdata); \ - convert_to_string(zdata); \ - } \ - if (zdata && Z_STRLEN_P(zdata) > 0) { \ - zend_update_property_string(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(name), Z_STRVAL_P(zdata) TSRMLS_CC); \ - } else { \ - zend_update_property_string(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(name), INI_STR("amqp." name) TSRMLS_CC); \ - } - -#define PHP_AMQP_EXTRACT_CONNECTION_BOOL(name) \ - zdata = NULL; \ - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), (name), sizeof(name))) != NULL) { \ - SEPARATE_ZVAL(zdata); \ - convert_to_long(zdata); \ - } \ - if (zdata) { \ - zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(name), Z_LVAL_P(zdata) TSRMLS_CC); \ - } else { \ - zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(name), INI_INT("amqp." name) TSRMLS_CC); \ - } +#define PHP_AMQP_EXTRACT_CONNECTION_STR(name) \ + zdata = NULL; \ + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), (name), sizeof(name))) != NULL) { \ + SEPARATE_ZVAL(zdata); \ + convert_to_string(zdata); \ + } \ + if (zdata && Z_STRLEN_P(zdata) > 0) { \ + zend_update_property_string( \ + this_ce, \ + PHP_AMQP_COMPAT_OBJ_P(getThis()), \ + ZEND_STRL(name), \ + Z_STRVAL_P(zdata) TSRMLS_CC \ + ); \ + } else { \ + zend_update_property_string( \ + this_ce, \ + PHP_AMQP_COMPAT_OBJ_P(getThis()), \ + ZEND_STRL(name), \ + INI_STR("amqp." name) TSRMLS_CC \ + ); \ + } + +#define PHP_AMQP_EXTRACT_CONNECTION_BOOL(name) \ + zdata = NULL; \ + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), (name), sizeof(name))) != NULL) { \ + SEPARATE_ZVAL(zdata); \ + convert_to_long(zdata); \ + } \ + if (zdata) { \ + zend_update_property_bool( \ + this_ce, \ + PHP_AMQP_COMPAT_OBJ_P(getThis()), \ + ZEND_STRL(name), \ + Z_LVAL_P(zdata) TSRMLS_CC \ + ); \ + } else { \ + zend_update_property_bool( \ + this_ce, \ + PHP_AMQP_COMPAT_OBJ_P(getThis()), \ + ZEND_STRL(name), \ + INI_INT("amqp." name) TSRMLS_CC \ + ); \ + } static int php_amqp_connection_resource_deleter(zval *el, amqp_connection_resource *connection_resource TSRMLS_DC) { - if (Z_RES_P(el)->ptr == connection_resource) { - return ZEND_HASH_APPLY_REMOVE | ZEND_HASH_APPLY_STOP; - } + if (Z_RES_P(el)->ptr == connection_resource) { + return ZEND_HASH_APPLY_REMOVE | ZEND_HASH_APPLY_STOP; + } - return ZEND_HASH_APPLY_KEEP; + return ZEND_HASH_APPLY_KEEP; } -static size_t php_amqp_get_connection_hash(amqp_connection_params *params, char **hash) { - return spprintf(hash, - 0, - "amqp_conn_res_h:%s_p:%d_v:%s_l:%s_p:%s_f:%d_c:%d_h:%d_cacert:%s_cert:%s_key:%s_sasl_method:%d_connection_name:%s", - params->host, - params->port, - params->vhost, - params->login, - params->password, - params->frame_max, - params->channel_max, - params->heartbeat, - params->cacert, - params->cert, - params->key, - params->sasl_method, - params->connection_name - ); +static size_t php_amqp_get_connection_hash(amqp_connection_params *params, char **hash) +{ + return spprintf( + hash, + 0, + "amqp_conn_res_h:%s_p:%d_v:%s_l:%s_p:%s_f:%d_c:%d_h:%d_cacert:%s_cert:%s_key:%s_sasl_method:%d_connection_name:" + "%s", + params->host, + params->port, + params->vhost, + params->login, + params->password, + params->frame_max, + params->channel_max, + params->heartbeat, + params->cacert, + params->cert, + params->key, + params->sasl_method, + params->connection_name + ); } static void php_amqp_cleanup_connection_resource(amqp_connection_resource *connection_resource TSRMLS_DC) { - if (!connection_resource) { - return; - } - - zend_resource *resource = connection_resource->resource; - - connection_resource->parent->connection_resource = NULL; - connection_resource->parent = NULL; - - if (connection_resource->is_dirty) { - if (connection_resource->is_persistent) { - zend_hash_apply_with_argument(&EG(persistent_list), (apply_func_arg_t)php_amqp_connection_resource_deleter, (void*)connection_resource TSRMLS_CC); - } - - zend_list_delete(resource); - } else { - if (connection_resource->is_persistent) { - connection_resource->resource = NULL; - } - - if (connection_resource->resource != NULL) { - zend_list_delete(resource); - } - } + if (!connection_resource) { + return; + } + + zend_resource *resource = connection_resource->resource; + + connection_resource->parent->connection_resource = NULL; + connection_resource->parent = NULL; + + if (connection_resource->is_dirty) { + if (connection_resource->is_persistent) { + zend_hash_apply_with_argument( + &EG(persistent_list), + (apply_func_arg_t) php_amqp_connection_resource_deleter, + (void *) connection_resource TSRMLS_CC + ); + } + + zend_list_delete(resource); + } else { + if (connection_resource->is_persistent) { + connection_resource->resource = NULL; + } + + if (connection_resource->resource != NULL) { + zend_list_delete(resource); + } + } } static void php_amqp_disconnect(amqp_connection_resource *resource TSRMLS_DC) { - php_amqp_prepare_for_disconnect(resource TSRMLS_CC); - php_amqp_cleanup_connection_resource(resource TSRMLS_CC); + php_amqp_prepare_for_disconnect(resource TSRMLS_CC); + php_amqp_cleanup_connection_resource(resource TSRMLS_CC); } void php_amqp_disconnect_force(amqp_connection_resource *resource TSRMLS_DC) { - php_amqp_prepare_for_disconnect(resource TSRMLS_CC); - resource->is_dirty = '\1'; - php_amqp_cleanup_connection_resource(resource TSRMLS_CC); + php_amqp_prepare_for_disconnect(resource TSRMLS_CC); + resource->is_dirty = '\1'; + php_amqp_cleanup_connection_resource(resource TSRMLS_CC); } /** @@ -173,142 +200,163 @@ void php_amqp_disconnect_force(amqp_connection_resource *resource TSRMLS_DC) */ int php_amqp_connect(amqp_connection_object *connection, zend_bool persistent, INTERNAL_FUNCTION_PARAMETERS) { - zval rv; - - char *key = NULL; - size_t key_len = 0; - - if (connection->connection_resource) { - /* Clean up old memory allocations which are now invalid (new connection) */ - php_amqp_cleanup_connection_resource(connection->connection_resource TSRMLS_CC); - } - - assert(connection->connection_resource == NULL); - - amqp_connection_params connection_params; - - connection_params.host = PHP_AMQP_READ_THIS_PROP_STR("host"); - connection_params.port = (int)PHP_AMQP_READ_THIS_PROP_LONG("port"); - connection_params.vhost = PHP_AMQP_READ_THIS_PROP_STR("vhost"); - connection_params.login = PHP_AMQP_READ_THIS_PROP_STR("login"); - connection_params.password = PHP_AMQP_READ_THIS_PROP_STR("password"); - connection_params.frame_max = (int) PHP_AMQP_READ_THIS_PROP_LONG("frame_max"); - connection_params.channel_max = (int) PHP_AMQP_READ_THIS_PROP_LONG("channel_max"); - connection_params.heartbeat = (int) PHP_AMQP_READ_THIS_PROP_LONG("heartbeat"); - connection_params.read_timeout = PHP_AMQP_READ_THIS_PROP_DOUBLE("read_timeout"); - connection_params.write_timeout = PHP_AMQP_READ_THIS_PROP_DOUBLE("write_timeout"); - connection_params.connect_timeout = PHP_AMQP_READ_THIS_PROP_DOUBLE("connect_timeout"); - connection_params.rpc_timeout = PHP_AMQP_READ_THIS_PROP_DOUBLE("rpc_timeout"); - connection_params.cacert = PHP_AMQP_READ_THIS_PROP_STRLEN("cacert") ? PHP_AMQP_READ_THIS_PROP_STR("cacert") : NULL; - connection_params.cert = PHP_AMQP_READ_THIS_PROP_STRLEN("cert") ? PHP_AMQP_READ_THIS_PROP_STR("cert") : NULL; - connection_params.key = PHP_AMQP_READ_THIS_PROP_STRLEN("key") ? PHP_AMQP_READ_THIS_PROP_STR("key") : NULL; - connection_params.verify = (int) PHP_AMQP_READ_THIS_PROP_BOOL("verify"); - connection_params.sasl_method = (int) PHP_AMQP_READ_THIS_PROP_LONG("sasl_method"); - connection_params.connection_name = PHP_AMQP_READ_THIS_PROP_STRLEN("connection_name") ? PHP_AMQP_READ_THIS_PROP_STR("connection_name") : NULL; - - if (persistent) { - zend_resource *le = NULL; - - /* Look for an established resource */ - key_len = php_amqp_get_connection_hash(&connection_params, &key); - - if ((le = zend_hash_str_find_ptr(&EG(persistent_list), key, key_len)) != NULL) { - efree(key); - - if (le->type != le_amqp_connection_resource_persistent) { - /* hash conflict, given name associate with non-amqp persistent connection resource */ - return 0; - } - - /* An entry for this connection resource already exists */ - /* Stash the connection resource in the connection */ - connection->connection_resource = le->ptr; - - if (connection->connection_resource->resource != NULL) { - /* resource in use! */ - connection->connection_resource = NULL; - - zend_throw_exception(amqp_connection_exception_class_entry, "There are already established persistent connection to the same resource.", 0 TSRMLS_CC); - return 0; - } - - connection->connection_resource->resource = zend_register_resource(connection->connection_resource, persistent ? le_amqp_connection_resource_persistent : le_amqp_connection_resource); - connection->connection_resource->parent = connection; - - /* Set desired timeouts */ - if (php_amqp_set_resource_read_timeout(connection->connection_resource, PHP_AMQP_READ_THIS_PROP_DOUBLE("read_timeout") TSRMLS_CC) == 0 - || php_amqp_set_resource_write_timeout(connection->connection_resource, PHP_AMQP_READ_THIS_PROP_DOUBLE("write_timeout") TSRMLS_CC) == 0 - || php_amqp_set_resource_rpc_timeout(connection->connection_resource, PHP_AMQP_READ_THIS_PROP_DOUBLE("rpc_timeout") TSRMLS_CC) == 0) { + zval rv; - php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC); - return 0; - } + char *key = NULL; + size_t key_len = 0; - /* Set connection status to connected */ - connection->connection_resource->is_connected = '\1'; - connection->connection_resource->is_persistent = persistent; + if (connection->connection_resource) { + /* Clean up old memory allocations which are now invalid (new connection) */ + php_amqp_cleanup_connection_resource(connection->connection_resource TSRMLS_CC); + } - return 1; - } + assert(connection->connection_resource == NULL); + + amqp_connection_params connection_params; + + connection_params.host = PHP_AMQP_READ_THIS_PROP_STR("host"); + connection_params.port = (int) PHP_AMQP_READ_THIS_PROP_LONG("port"); + connection_params.vhost = PHP_AMQP_READ_THIS_PROP_STR("vhost"); + connection_params.login = PHP_AMQP_READ_THIS_PROP_STR("login"); + connection_params.password = PHP_AMQP_READ_THIS_PROP_STR("password"); + connection_params.frame_max = (int) PHP_AMQP_READ_THIS_PROP_LONG("frame_max"); + connection_params.channel_max = (int) PHP_AMQP_READ_THIS_PROP_LONG("channel_max"); + connection_params.heartbeat = (int) PHP_AMQP_READ_THIS_PROP_LONG("heartbeat"); + connection_params.read_timeout = PHP_AMQP_READ_THIS_PROP_DOUBLE("read_timeout"); + connection_params.write_timeout = PHP_AMQP_READ_THIS_PROP_DOUBLE("write_timeout"); + connection_params.connect_timeout = PHP_AMQP_READ_THIS_PROP_DOUBLE("connect_timeout"); + connection_params.rpc_timeout = PHP_AMQP_READ_THIS_PROP_DOUBLE("rpc_timeout"); + connection_params.cacert = PHP_AMQP_READ_THIS_PROP_STRLEN("cacert") ? PHP_AMQP_READ_THIS_PROP_STR("cacert") : NULL; + connection_params.cert = PHP_AMQP_READ_THIS_PROP_STRLEN("cert") ? PHP_AMQP_READ_THIS_PROP_STR("cert") : NULL; + connection_params.key = PHP_AMQP_READ_THIS_PROP_STRLEN("key") ? PHP_AMQP_READ_THIS_PROP_STR("key") : NULL; + connection_params.verify = (int) PHP_AMQP_READ_THIS_PROP_BOOL("verify"); + connection_params.sasl_method = (int) PHP_AMQP_READ_THIS_PROP_LONG("sasl_method"); + connection_params.connection_name = + PHP_AMQP_READ_THIS_PROP_STRLEN("connection_name") ? PHP_AMQP_READ_THIS_PROP_STR("connection_name") : NULL; + + if (persistent) { + zend_resource *le = NULL; + + /* Look for an established resource */ + key_len = php_amqp_get_connection_hash(&connection_params, &key); + + if ((le = zend_hash_str_find_ptr(&EG(persistent_list), key, key_len)) != NULL) { + efree(key); + + if (le->type != le_amqp_connection_resource_persistent) { + /* hash conflict, given name associate with non-amqp persistent connection resource */ + return 0; + } + + /* An entry for this connection resource already exists */ + /* Stash the connection resource in the connection */ + connection->connection_resource = le->ptr; + + if (connection->connection_resource->resource != NULL) { + /* resource in use! */ + connection->connection_resource = NULL; + + zend_throw_exception( + amqp_connection_exception_class_entry, + "There are already established persistent connection to the same resource.", + 0 TSRMLS_CC + ); + return 0; + } + + connection->connection_resource->resource = zend_register_resource( + connection->connection_resource, + persistent ? le_amqp_connection_resource_persistent : le_amqp_connection_resource + ); + connection->connection_resource->parent = connection; + + /* Set desired timeouts */ + if (php_amqp_set_resource_read_timeout( + connection->connection_resource, + PHP_AMQP_READ_THIS_PROP_DOUBLE("read_timeout") TSRMLS_CC + ) == 0 || + php_amqp_set_resource_write_timeout( + connection->connection_resource, + PHP_AMQP_READ_THIS_PROP_DOUBLE("write_timeout") TSRMLS_CC + ) == 0 || + php_amqp_set_resource_rpc_timeout( + connection->connection_resource, + PHP_AMQP_READ_THIS_PROP_DOUBLE("rpc_timeout") TSRMLS_CC + ) == 0) { + + php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC); + return 0; + } + + /* Set connection status to connected */ + connection->connection_resource->is_connected = '\1'; + connection->connection_resource->is_persistent = persistent; + + return 1; + } - efree(key); - } + efree(key); + } - connection->connection_resource = connection_resource_constructor(&connection_params, persistent TSRMLS_CC); + connection->connection_resource = connection_resource_constructor(&connection_params, persistent TSRMLS_CC); - if (connection->connection_resource == NULL) { - return 0; - } + if (connection->connection_resource == NULL) { + return 0; + } - connection->connection_resource->resource = zend_register_resource(connection->connection_resource, persistent ? le_amqp_connection_resource_persistent : le_amqp_connection_resource); - connection->connection_resource->parent = connection; + connection->connection_resource->resource = zend_register_resource( + connection->connection_resource, + persistent ? le_amqp_connection_resource_persistent : le_amqp_connection_resource + ); + connection->connection_resource->parent = connection; - /* Set connection status to connected */ - connection->connection_resource->is_connected = '\1'; + /* Set connection status to connected */ + connection->connection_resource->is_connected = '\1'; - if (persistent) { - connection->connection_resource->is_persistent = persistent; + if (persistent) { + connection->connection_resource->is_persistent = persistent; - key_len = php_amqp_get_connection_hash(&connection_params, &key); + key_len = php_amqp_get_connection_hash(&connection_params, &key); - zend_resource new_le; + zend_resource new_le; - /* Store a reference in the persistence list */ - new_le.ptr = connection->connection_resource; - new_le.type = persistent ? le_amqp_connection_resource_persistent : le_amqp_connection_resource; + /* Store a reference in the persistence list */ + new_le.ptr = connection->connection_resource; + new_le.type = persistent ? le_amqp_connection_resource_persistent : le_amqp_connection_resource; - if (!zend_hash_str_update_mem(&EG(persistent_list), key, key_len, &new_le, sizeof(zend_resource))) { - efree(key); - php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC); - return 0; - } - efree(key); - } + if (!zend_hash_str_update_mem(&EG(persistent_list), key, key_len, &new_le, sizeof(zend_resource))) { + efree(key); + php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC); + return 0; + } + efree(key); + } - return 1; + return 1; } void amqp_connection_free(zend_object *object TSRMLS_DC) { - amqp_connection_object *connection = PHP_AMQP_FETCH_CONNECTION(object); + amqp_connection_object *connection = PHP_AMQP_FETCH_CONNECTION(object); - if (connection->connection_resource) { - php_amqp_disconnect(connection->connection_resource TSRMLS_CC); - } + if (connection->connection_resource) { + php_amqp_disconnect(connection->connection_resource TSRMLS_CC); + } - zend_object_std_dtor(&connection->zo TSRMLS_CC); + zend_object_std_dtor(&connection->zo TSRMLS_CC); } zend_object *amqp_connection_ctor(zend_class_entry *ce TSRMLS_DC) { - amqp_connection_object* connection = (amqp_connection_object*) ecalloc(1, sizeof(amqp_connection_object) + zend_object_properties_size(ce)); + amqp_connection_object *connection = + (amqp_connection_object *) ecalloc(1, sizeof(amqp_connection_object) + zend_object_properties_size(ce)); - zend_object_std_init(&connection->zo, ce TSRMLS_CC); - AMQP_OBJECT_PROPERTIES_INIT(connection->zo, ce); + zend_object_std_init(&connection->zo, ce TSRMLS_CC); + AMQP_OBJECT_PROPERTIES_INIT(connection->zo, ce); - connection->zo.handlers = &amqp_connection_object_handlers; + connection->zo.handlers = &amqp_connection_object_handlers; - return &connection->zo; + return &connection->zo; } @@ -317,264 +365,495 @@ zend_object *amqp_connection_ctor(zend_class_entry *ce TSRMLS_DC) */ static PHP_METHOD(amqp_connection_class, __construct) { - zval* ini_arr = NULL; - - zval *zdata = NULL; - - /* Parse out the method parameters */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a/", &ini_arr) == FAILURE) { - return; - } - - /* Pull the login out of the $params array */ - zdata = NULL; - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "login", sizeof("login") - 1)) != NULL) { - SEPARATE_ZVAL(zdata); - convert_to_string(zdata); - } - /* Validate the given login */ - if (zdata && Z_STRLEN_P(zdata) > 0) { + zval *ini_arr = NULL; + + zval *zdata = NULL; + + /* Parse out the method parameters */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a/", &ini_arr) == FAILURE) { + return; + } + + /* Pull the login out of the $params array */ + zdata = NULL; + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "login", sizeof("login") - 1)) != NULL) { + SEPARATE_ZVAL(zdata); + convert_to_string(zdata); + } + /* Validate the given login */ + if (zdata && Z_STRLEN_P(zdata) > 0) { if (!php_amqp_is_valid_credential(Z_STR_P(zdata))) { - zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'login' exceeds %d character limit.", PHP_AMQP_MAX_CREDENTIALS_LENGTH); + zend_throw_exception_ex( + amqp_connection_exception_class_entry, + 0 TSRMLS_CC, + "Parameter 'login' exceeds %d character limit.", + PHP_AMQP_MAX_CREDENTIALS_LENGTH + ); return; } zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("login"), zdata TSRMLS_CC); - } else { - zend_update_property_string(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("login"), INI_STR("amqp.login") TSRMLS_CC); - } - - /* Pull the password out of the $params array */ - zdata = NULL; - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "password", sizeof("password") - 1)) != NULL) { - SEPARATE_ZVAL(zdata); - convert_to_string(zdata); - } - /* Validate the given password */ - if (zdata && Z_STRLEN_P(zdata) > 0) { - if (!php_amqp_is_valid_credential(Z_STR_P(zdata))) { - zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'password' exceeds %d character limit.", PHP_AMQP_MAX_CREDENTIALS_LENGTH); + } else { + zend_update_property_string( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("login"), + INI_STR("amqp.login") TSRMLS_CC + ); + } + + /* Pull the password out of the $params array */ + zdata = NULL; + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "password", sizeof("password") - 1)) != NULL) { + SEPARATE_ZVAL(zdata); + convert_to_string(zdata); + } + /* Validate the given password */ + if (zdata && Z_STRLEN_P(zdata) > 0) { + if (!php_amqp_is_valid_credential(Z_STR_P(zdata))) { + zend_throw_exception_ex( + amqp_connection_exception_class_entry, + 0 TSRMLS_CC, + "Parameter 'password' exceeds %d character limit.", + PHP_AMQP_MAX_CREDENTIALS_LENGTH + ); return; } - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("password"), Z_STRVAL_P(zdata), Z_STRLEN_P(zdata) TSRMLS_CC); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("password"), + Z_STRVAL_P(zdata), + Z_STRLEN_P(zdata) TSRMLS_CC + ); } else { - zend_update_property_string(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("password"), INI_STR("amqp.password") TSRMLS_CC); - } - - /* Pull the host out of the $params array */ - zdata = NULL; - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "host", sizeof("host") - 1)) != NULL) { - SEPARATE_ZVAL(zdata); - convert_to_string(zdata); - } - /* Validate the given host */ - if (zdata && Z_STRLEN_P(zdata) > 0) { - if (!php_amqp_is_valid_identifier(Z_STR_P(zdata))) { - zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'host' exceeds %d character limit.", PHP_AMQP_MAX_IDENTIFIER_LENGTH); + zend_update_property_string( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("password"), + INI_STR("amqp.password") TSRMLS_CC + ); + } + + /* Pull the host out of the $params array */ + zdata = NULL; + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "host", sizeof("host") - 1)) != NULL) { + SEPARATE_ZVAL(zdata); + convert_to_string(zdata); + } + /* Validate the given host */ + if (zdata && Z_STRLEN_P(zdata) > 0) { + if (!php_amqp_is_valid_identifier(Z_STR_P(zdata))) { + zend_throw_exception_ex( + amqp_connection_exception_class_entry, + 0 TSRMLS_CC, + "Parameter 'host' exceeds %d character limit.", + PHP_AMQP_MAX_IDENTIFIER_LENGTH + ); return; } - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("host"), Z_STRVAL_P(zdata), Z_STRLEN_P(zdata) TSRMLS_CC); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("host"), + Z_STRVAL_P(zdata), + Z_STRLEN_P(zdata) TSRMLS_CC + ); } else { - zend_update_property_string(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("host"), INI_STR("amqp.host") TSRMLS_CC); - } - - /* Pull the vhost out of the $params array */ - zdata = NULL; - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "vhost", sizeof("vhost") - 1)) != NULL) { - SEPARATE_ZVAL(zdata); - convert_to_string(zdata); - } - /* Validate the given vhost */ - if (zdata && Z_STRLEN_P(zdata) > 0) { + zend_update_property_string( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("host"), + INI_STR("amqp.host") TSRMLS_CC + ); + } + + /* Pull the vhost out of the $params array */ + zdata = NULL; + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "vhost", sizeof("vhost") - 1)) != NULL) { + SEPARATE_ZVAL(zdata); + convert_to_string(zdata); + } + /* Validate the given vhost */ + if (zdata && Z_STRLEN_P(zdata) > 0) { if (!php_amqp_is_valid_identifier(Z_STR_P(zdata))) { - zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'vhost' exceeds %d character limit.", PHP_AMQP_MAX_IDENTIFIER_LENGTH); + zend_throw_exception_ex( + amqp_connection_exception_class_entry, + 0 TSRMLS_CC, + "Parameter 'vhost' exceeds %d character limit.", + PHP_AMQP_MAX_IDENTIFIER_LENGTH + ); return; } - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("vhost"), Z_STRVAL_P(zdata), Z_STRLEN_P(zdata) TSRMLS_CC); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("vhost"), + Z_STRVAL_P(zdata), + Z_STRLEN_P(zdata) TSRMLS_CC + ); } else { - zend_update_property_string(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("vhost"), INI_STR("amqp.vhost") TSRMLS_CC); - - } + zend_update_property_string( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("vhost"), + INI_STR("amqp.vhost") TSRMLS_CC + ); + } - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("port"), INI_INT("amqp.port") TSRMLS_CC); + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("port"), + INI_INT("amqp.port") TSRMLS_CC + ); - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "port", sizeof("port") - 1)) != NULL) { - SEPARATE_ZVAL(zdata); - convert_to_long(zdata); + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "port", sizeof("port") - 1)) != NULL) { + SEPARATE_ZVAL(zdata); + convert_to_long(zdata); if (!php_amqp_is_valid_port(Z_LVAL_P(zdata))) { - zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'port' must be a valid port number between %d and %d.", PHP_AMQP_MIN_PORT, PHP_AMQP_MAX_PORT); + zend_throw_exception_ex( + amqp_connection_exception_class_entry, + 0 TSRMLS_CC, + "Parameter 'port' must be a valid port number between %d and %d.", + PHP_AMQP_MIN_PORT, + PHP_AMQP_MAX_PORT + ); return; } - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("port"), Z_LVAL_P(zdata) TSRMLS_CC); + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("port"), + Z_LVAL_P(zdata) TSRMLS_CC + ); } - zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("read_timeout"), INI_FLT("amqp.read_timeout") TSRMLS_CC); + zend_update_property_double( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("read_timeout"), + INI_FLT("amqp.read_timeout") TSRMLS_CC + ); - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "read_timeout", sizeof("read_timeout") - 1)) != NULL) { - SEPARATE_ZVAL(zdata); - convert_to_double(zdata); + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "read_timeout", sizeof("read_timeout") - 1)) != NULL) { + SEPARATE_ZVAL(zdata); + convert_to_double(zdata); if (!php_amqp_is_valid_timeout(Z_DVAL_P(zdata))) { - zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'read_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC); + zend_throw_exception( + amqp_connection_exception_class_entry, + "Parameter 'read_timeout' must be greater than or equal to zero.", + 0 TSRMLS_CC + ); return; - } + } - zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("read_timeout"), Z_DVAL_P(zdata) TSRMLS_CC); + zend_update_property_double( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("read_timeout"), + Z_DVAL_P(zdata) TSRMLS_CC + ); - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "timeout", sizeof("timeout") - 1)) != NULL) { - /* 'read_timeout' takes precedence on 'timeout' but users have to know this */ - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Parameter 'timeout' is deprecated, 'read_timeout' used instead"); - } + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "timeout", sizeof("timeout") - 1)) != NULL) { + /* 'read_timeout' takes precedence on 'timeout' but users have to know this */ + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Parameter 'timeout' is deprecated, 'read_timeout' used instead"); + } - } else if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "timeout", sizeof("timeout") - 1)) != NULL) { + } else if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "timeout", sizeof("timeout") - 1)) != NULL) { - php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "Parameter 'timeout' is deprecated; use 'read_timeout' instead"); + php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "Parameter 'timeout' is deprecated; use 'read_timeout' instead"); - SEPARATE_ZVAL(zdata); - convert_to_double(zdata); + SEPARATE_ZVAL(zdata); + convert_to_double(zdata); if (!php_amqp_is_valid_timeout(Z_DVAL_P(zdata))) { - zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'timeout' must be greater than or equal to zero.", 0 TSRMLS_CC); - return; - } - - zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("read_timeout"), Z_DVAL_P(zdata) TSRMLS_CC); - } else { - - assert(DEFAULT_TIMEOUT != NULL); - if (strcmp(DEFAULT_TIMEOUT, INI_STR("amqp.timeout")) != 0) { - php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "INI setting 'amqp.timeout' is deprecated; use 'amqp.read_timeout' instead"); - - if (strcmp(DEFAULT_READ_TIMEOUT, INI_STR("amqp.read_timeout")) == 0) { - zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("read_timeout"), INI_FLT("amqp.timeout") TSRMLS_CC); - } else { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "INI setting 'amqp.read_timeout' will be used instead of 'amqp.timeout'"); - zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("read_timeout"), INI_FLT("amqp.read_timeout") TSRMLS_CC); - } - } else { - zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("read_timeout"), INI_FLT("amqp.read_timeout") TSRMLS_CC); - } - } - - zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("write_timeout"), INI_FLT("amqp.write_timeout") TSRMLS_CC); - - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "write_timeout", sizeof("write_timeout") - 1)) != NULL) { - SEPARATE_ZVAL(zdata); - convert_to_double(zdata); - - if (!php_amqp_is_valid_timeout(Z_DVAL_P(zdata))) { - zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'write_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC); + zend_throw_exception( + amqp_connection_exception_class_entry, + "Parameter 'timeout' must be greater than or equal to zero.", + 0 TSRMLS_CC + ); return; - } + } - zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("write_timeout"), Z_DVAL_P(zdata) TSRMLS_CC); - } + zend_update_property_double( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("read_timeout"), + Z_DVAL_P(zdata) TSRMLS_CC + ); + } else { - zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("rpc_timeout"), INI_FLT("amqp.rpc_timeout") TSRMLS_CC); + assert(DEFAULT_TIMEOUT != NULL); + if (strcmp(DEFAULT_TIMEOUT, INI_STR("amqp.timeout")) != 0) { + php_error_docref( + NULL TSRMLS_CC, + E_DEPRECATED, + "INI setting 'amqp.timeout' is deprecated; use 'amqp.read_timeout' instead" + ); + + if (strcmp(DEFAULT_READ_TIMEOUT, INI_STR("amqp.read_timeout")) == 0) { + zend_update_property_double( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("read_timeout"), + INI_FLT("amqp.timeout") TSRMLS_CC + ); + } else { + php_error_docref( + NULL TSRMLS_CC, + E_NOTICE, + "INI setting 'amqp.read_timeout' will be used instead of 'amqp.timeout'" + ); + zend_update_property_double( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("read_timeout"), + INI_FLT("amqp.read_timeout") TSRMLS_CC + ); + } + } else { + zend_update_property_double( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("read_timeout"), + INI_FLT("amqp.read_timeout") TSRMLS_CC + ); + } + } + + zend_update_property_double( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("write_timeout"), + INI_FLT("amqp.write_timeout") TSRMLS_CC + ); - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "rpc_timeout", sizeof("rpc_timeout") - 1)) != NULL) { - SEPARATE_ZVAL(zdata); - convert_to_double(zdata); + if (ini_arr && + (zdata = zend_hash_str_find(HASH_OF(ini_arr), "write_timeout", sizeof("write_timeout") - 1)) != NULL) { + SEPARATE_ZVAL(zdata); + convert_to_double(zdata); - if (!php_amqp_is_valid_timeout(Z_DVAL_P(zdata))) { - zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'rpc_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC); + if (!php_amqp_is_valid_timeout(Z_DVAL_P(zdata))) { + zend_throw_exception( + amqp_connection_exception_class_entry, + "Parameter 'write_timeout' must be greater than or equal to zero.", + 0 TSRMLS_CC + ); return; - } + } - zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("rpc_timeout"), Z_DVAL_P(zdata) TSRMLS_CC); - } + zend_update_property_double( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("write_timeout"), + Z_DVAL_P(zdata) TSRMLS_CC + ); + } - zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connect_timeout"), INI_FLT("amqp.connect_timeout") TSRMLS_CC); + zend_update_property_double( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("rpc_timeout"), + INI_FLT("amqp.rpc_timeout") TSRMLS_CC + ); - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "connect_timeout", sizeof("connect_timeout") - 1)) != NULL) { - SEPARATE_ZVAL(zdata); - convert_to_double(zdata); + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "rpc_timeout", sizeof("rpc_timeout") - 1)) != NULL) { + SEPARATE_ZVAL(zdata); + convert_to_double(zdata); if (!php_amqp_is_valid_timeout(Z_DVAL_P(zdata))) { - zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'connect_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC); + zend_throw_exception( + amqp_connection_exception_class_entry, + "Parameter 'rpc_timeout' must be greater than or equal to zero.", + 0 TSRMLS_CC + ); return; - } + } - zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connect_timeout"), Z_DVAL_P(zdata) TSRMLS_CC); - } + zend_update_property_double( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("rpc_timeout"), + Z_DVAL_P(zdata) TSRMLS_CC + ); + } - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("channel_max"), INI_INT("amqp.channel_max") TSRMLS_CC); + zend_update_property_double( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("connect_timeout"), + INI_FLT("amqp.connect_timeout") TSRMLS_CC + ); - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "channel_max", sizeof("channel_max") - 1)) != NULL) { - SEPARATE_ZVAL(zdata); - convert_to_long(zdata); + if (ini_arr && + (zdata = zend_hash_str_find(HASH_OF(ini_arr), "connect_timeout", sizeof("connect_timeout") - 1)) != NULL) { + SEPARATE_ZVAL(zdata); + convert_to_double(zdata); - if (!php_amqp_is_valid_channel_max(Z_LVAL_P(zdata))) { - zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'channel_max' is out of range.", 0 TSRMLS_CC); + if (!php_amqp_is_valid_timeout(Z_DVAL_P(zdata))) { + zend_throw_exception( + amqp_connection_exception_class_entry, + "Parameter 'connect_timeout' must be greater than or equal to zero.", + 0 TSRMLS_CC + ); return; - } - - if(Z_LVAL_P(zdata) == 0) { - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("channel_max"), PHP_AMQP_DEFAULT_CHANNEL_MAX TSRMLS_CC); - } else { - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("channel_max"), Z_LVAL_P(zdata) TSRMLS_CC); } - } - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("frame_max"), INI_INT("amqp.frame_max") TSRMLS_CC); + zend_update_property_double( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("connect_timeout"), + Z_DVAL_P(zdata) TSRMLS_CC + ); + } - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "frame_max", sizeof("frame_max") - 1)) != NULL) { - SEPARATE_ZVAL(zdata); - convert_to_long(zdata); - if (!php_amqp_is_valid_frame_size_max(Z_LVAL_P(zdata))) { - zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'frame_max' is out of range.", 0 TSRMLS_CC); + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("channel_max"), + INI_INT("amqp.channel_max") TSRMLS_CC + ); + + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "channel_max", sizeof("channel_max") - 1)) != NULL) { + SEPARATE_ZVAL(zdata); + convert_to_long(zdata); + + if (!php_amqp_is_valid_channel_max(Z_LVAL_P(zdata))) { + zend_throw_exception( + amqp_connection_exception_class_entry, + "Parameter 'channel_max' is out of range.", + 0 TSRMLS_CC + ); return; - } + } - if(Z_LVAL_P(zdata) == 0) { - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("frame_max"), PHP_AMQP_DEFAULT_FRAME_MAX TSRMLS_CC); + if (Z_LVAL_P(zdata) == 0) { + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("channel_max"), + PHP_AMQP_DEFAULT_CHANNEL_MAX TSRMLS_CC + ); } else { - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("frame_max"), Z_LVAL_P(zdata) TSRMLS_CC); + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("channel_max"), + Z_LVAL_P(zdata) TSRMLS_CC + ); } - } - - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("heartbeat"), INI_INT("amqp.heartbeat") TSRMLS_CC); + } - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "heartbeat", sizeof("heartbeat") - 1)) != NULL) { - SEPARATE_ZVAL(zdata); - convert_to_long(zdata); - if (!php_amqp_is_valid_heartbeat(Z_LVAL_P(zdata))) { - zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'heartbeat' is out of range.", 0 TSRMLS_CC); + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("frame_max"), + INI_INT("amqp.frame_max") TSRMLS_CC + ); + + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "frame_max", sizeof("frame_max") - 1)) != NULL) { + SEPARATE_ZVAL(zdata); + convert_to_long(zdata); + if (!php_amqp_is_valid_frame_size_max(Z_LVAL_P(zdata))) { + zend_throw_exception( + amqp_connection_exception_class_entry, + "Parameter 'frame_max' is out of range.", + 0 TSRMLS_CC + ); return; - } + } + + if (Z_LVAL_P(zdata) == 0) { + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("frame_max"), + PHP_AMQP_DEFAULT_FRAME_MAX TSRMLS_CC + ); + } else { + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("frame_max"), + Z_LVAL_P(zdata) TSRMLS_CC + ); + } + } - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("heartbeat"), Z_LVAL_P(zdata) TSRMLS_CC); - } + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("heartbeat"), + INI_INT("amqp.heartbeat") TSRMLS_CC + ); + + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "heartbeat", sizeof("heartbeat") - 1)) != NULL) { + SEPARATE_ZVAL(zdata); + convert_to_long(zdata); + if (!php_amqp_is_valid_heartbeat(Z_LVAL_P(zdata))) { + zend_throw_exception( + amqp_connection_exception_class_entry, + "Parameter 'heartbeat' is out of range.", + 0 TSRMLS_CC + ); + return; + } - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("sasl_method"), INI_INT("amqp.sasl_method") TSRMLS_CC); + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("heartbeat"), + Z_LVAL_P(zdata) TSRMLS_CC + ); + } - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "sasl_method", sizeof("sasl_method") - 1)) != NULL) { - SEPARATE_ZVAL(zdata); - convert_to_long(zdata); - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("sasl_method"), Z_LVAL_P(zdata) TSRMLS_CC); - } + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("sasl_method"), + INI_INT("amqp.sasl_method") TSRMLS_CC + ); + + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "sasl_method", sizeof("sasl_method") - 1)) != NULL) { + SEPARATE_ZVAL(zdata); + convert_to_long(zdata); + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("sasl_method"), + Z_LVAL_P(zdata) TSRMLS_CC + ); + } - PHP_AMQP_EXTRACT_CONNECTION_STR("cacert"); - PHP_AMQP_EXTRACT_CONNECTION_STR("key"); - PHP_AMQP_EXTRACT_CONNECTION_STR("cert"); + PHP_AMQP_EXTRACT_CONNECTION_STR("cacert"); + PHP_AMQP_EXTRACT_CONNECTION_STR("key"); + PHP_AMQP_EXTRACT_CONNECTION_STR("cert"); - PHP_AMQP_EXTRACT_CONNECTION_BOOL("verify"); + PHP_AMQP_EXTRACT_CONNECTION_BOOL("verify"); - /* Pull the connection_name out of the $params array */ - zdata = NULL; - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "connection_name", sizeof("connection_name") - 1)) != NULL) { - SEPARATE_ZVAL(zdata); - convert_to_string(zdata); - } - if (zdata && Z_STRLEN_P(zdata) > 0) { - zend_update_property_string(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connection_name"), Z_STRVAL_P(zdata) TSRMLS_CC); - } + /* Pull the connection_name out of the $params array */ + zdata = NULL; + if (ini_arr && + (zdata = zend_hash_str_find(HASH_OF(ini_arr), "connection_name", sizeof("connection_name") - 1)) != NULL) { + SEPARATE_ZVAL(zdata); + convert_to_string(zdata); + } + if (zdata && Z_STRLEN_P(zdata) > 0) { + zend_update_property_string( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("connection_name"), + Z_STRVAL_P(zdata) TSRMLS_CC + ); + } } /* }}} */ @@ -583,20 +862,20 @@ static PHP_METHOD(amqp_connection_class, __construct) check amqp connection */ static PHP_METHOD(amqp_connection_class, isConnected) { - amqp_connection_object *connection; + amqp_connection_object *connection; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS(); - /* Get the connection object out of the store */ - connection = PHP_AMQP_GET_CONNECTION(getThis()); + /* Get the connection object out of the store */ + connection = PHP_AMQP_GET_CONNECTION(getThis()); - /* If the channel_connect is 1, we have a connection */ - if (connection->connection_resource != NULL && connection->connection_resource->is_connected) { - RETURN_TRUE; - } + /* If the channel_connect is 1, we have a connection */ + if (connection->connection_resource != NULL && connection->connection_resource->is_connected) { + RETURN_TRUE; + } - /* We have no connection */ - RETURN_FALSE; + /* We have no connection */ + RETURN_FALSE; } /* }}} */ @@ -605,23 +884,27 @@ static PHP_METHOD(amqp_connection_class, isConnected) create amqp connection */ static PHP_METHOD(amqp_connection_class, connect) { - amqp_connection_object *connection; + amqp_connection_object *connection; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS(); - /* Get the connection object out of the store */ - connection = PHP_AMQP_GET_CONNECTION(getThis()); + /* Get the connection object out of the store */ + connection = PHP_AMQP_GET_CONNECTION(getThis()); - if (connection->connection_resource && connection->connection_resource->is_connected) { - if (connection->connection_resource->is_persistent) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempt to start transient connection while persistent transient one already established. Continue."); - } + if (connection->connection_resource && connection->connection_resource->is_connected) { + if (connection->connection_resource->is_persistent) { + php_error_docref( + NULL TSRMLS_CC, + E_WARNING, + "Attempt to start transient connection while persistent transient one already established. Continue." + ); + } - RETURN_TRUE; - } + RETURN_TRUE; + } - /* Actually connect this resource to the broker */ - RETURN_BOOL(php_amqp_connect(connection, 0, INTERNAL_FUNCTION_PARAM_PASSTHRU)); + /* Actually connect this resource to the broker */ + RETURN_BOOL(php_amqp_connect(connection, 0, INTERNAL_FUNCTION_PARAM_PASSTHRU)); } /* }}} */ @@ -630,25 +913,29 @@ static PHP_METHOD(amqp_connection_class, connect) create amqp connection */ static PHP_METHOD(amqp_connection_class, pconnect) { - amqp_connection_object *connection; + amqp_connection_object *connection; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS(); - /* Get the connection object out of the store */ - connection = PHP_AMQP_GET_CONNECTION(getThis()); + /* Get the connection object out of the store */ + connection = PHP_AMQP_GET_CONNECTION(getThis()); - if (connection->connection_resource && connection->connection_resource->is_connected) { + if (connection->connection_resource && connection->connection_resource->is_connected) { - assert(connection->connection_resource != NULL); - if (!connection->connection_resource->is_persistent) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempt to start persistent connection while transient one already established. Continue."); - } + assert(connection->connection_resource != NULL); + if (!connection->connection_resource->is_persistent) { + php_error_docref( + NULL TSRMLS_CC, + E_WARNING, + "Attempt to start persistent connection while transient one already established. Continue." + ); + } - RETURN_TRUE; - } + RETURN_TRUE; + } - /* Actually connect this resource to the broker or use stored connection */ - RETURN_BOOL(php_amqp_connect(connection, 1, INTERNAL_FUNCTION_PARAM_PASSTHRU)); + /* Actually connect this resource to the broker or use stored connection */ + RETURN_BOOL(php_amqp_connect(connection, 1, INTERNAL_FUNCTION_PARAM_PASSTHRU)); } /* }}} */ @@ -657,28 +944,32 @@ static PHP_METHOD(amqp_connection_class, pconnect) destroy amqp persistent connection */ static PHP_METHOD(amqp_connection_class, pdisconnect) { - amqp_connection_object *connection; + amqp_connection_object *connection; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS(); - /* Get the connection object out of the store */ - connection = PHP_AMQP_GET_CONNECTION(getThis()); + /* Get the connection object out of the store */ + connection = PHP_AMQP_GET_CONNECTION(getThis()); - if (!connection->connection_resource || !connection->connection_resource->is_connected) { - RETURN_TRUE; - } + if (!connection->connection_resource || !connection->connection_resource->is_connected) { + RETURN_TRUE; + } - assert(connection->connection_resource != NULL); + assert(connection->connection_resource != NULL); - if (!connection->connection_resource->is_persistent) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempt to close persistent connection while transient one already established. Abort."); + if (!connection->connection_resource->is_persistent) { + php_error_docref( + NULL TSRMLS_CC, + E_WARNING, + "Attempt to close persistent connection while transient one already established. Abort." + ); - RETURN_FALSE; - } + RETURN_FALSE; + } - php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC); + php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC); - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -687,28 +978,32 @@ static PHP_METHOD(amqp_connection_class, pdisconnect) destroy amqp connection */ static PHP_METHOD(amqp_connection_class, disconnect) { - amqp_connection_object *connection; + amqp_connection_object *connection; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS(); - /* Get the connection object out of the store */ - connection = PHP_AMQP_GET_CONNECTION(getThis()); + /* Get the connection object out of the store */ + connection = PHP_AMQP_GET_CONNECTION(getThis()); - if (!connection->connection_resource || !connection->connection_resource->is_connected) { - RETURN_TRUE; - } + if (!connection->connection_resource || !connection->connection_resource->is_connected) { + RETURN_TRUE; + } - if (connection->connection_resource->is_persistent) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempt to close transient connection while persistent one already established. Abort."); + if (connection->connection_resource->is_persistent) { + php_error_docref( + NULL TSRMLS_CC, + E_WARNING, + "Attempt to close transient connection while persistent one already established. Abort." + ); - RETURN_FALSE; - } + RETURN_FALSE; + } - assert(connection->connection_resource != NULL); + assert(connection->connection_resource != NULL); - php_amqp_disconnect(connection->connection_resource TSRMLS_CC); + php_amqp_disconnect(connection->connection_resource TSRMLS_CC); - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -717,27 +1012,31 @@ static PHP_METHOD(amqp_connection_class, disconnect) recreate amqp connection */ static PHP_METHOD(amqp_connection_class, reconnect) { - amqp_connection_object *connection; + amqp_connection_object *connection; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS(); - /* Get the connection object out of the store */ - connection = PHP_AMQP_GET_CONNECTION(getThis()); + /* Get the connection object out of the store */ + connection = PHP_AMQP_GET_CONNECTION(getThis()); - if (connection->connection_resource && connection->connection_resource->is_connected) { + if (connection->connection_resource && connection->connection_resource->is_connected) { - assert(connection->connection_resource != NULL); + assert(connection->connection_resource != NULL); - if (connection->connection_resource->is_persistent) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempt to reconnect persistent connection while transient one already established. Abort."); + if (connection->connection_resource->is_persistent) { + php_error_docref( + NULL TSRMLS_CC, + E_WARNING, + "Attempt to reconnect persistent connection while transient one already established. Abort." + ); - RETURN_FALSE; - } + RETURN_FALSE; + } - php_amqp_disconnect(connection->connection_resource TSRMLS_CC); - } + php_amqp_disconnect(connection->connection_resource TSRMLS_CC); + } - RETURN_BOOL(php_amqp_connect(connection, 0, INTERNAL_FUNCTION_PARAM_PASSTHRU)); + RETURN_BOOL(php_amqp_connect(connection, 0, INTERNAL_FUNCTION_PARAM_PASSTHRU)); } /* }}} */ @@ -745,28 +1044,32 @@ static PHP_METHOD(amqp_connection_class, reconnect) recreate amqp connection */ static PHP_METHOD(amqp_connection_class, preconnect) { - amqp_connection_object *connection; + amqp_connection_object *connection; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS(); - /* Get the connection object out of the store */ - connection = PHP_AMQP_GET_CONNECTION(getThis()); + /* Get the connection object out of the store */ + connection = PHP_AMQP_GET_CONNECTION(getThis()); - if (connection->connection_resource && connection->connection_resource->is_connected) { + if (connection->connection_resource && connection->connection_resource->is_connected) { - assert(connection->connection_resource != NULL); + assert(connection->connection_resource != NULL); - if (!connection->connection_resource->is_persistent) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempt to reconnect transient connection while persistent one already established. Abort."); + if (!connection->connection_resource->is_persistent) { + php_error_docref( + NULL TSRMLS_CC, + E_WARNING, + "Attempt to reconnect transient connection while persistent one already established. Abort." + ); - RETURN_FALSE; - } + RETURN_FALSE; + } - php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC); - } + php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC); + } - RETURN_BOOL(php_amqp_connect(connection, 1, INTERNAL_FUNCTION_PARAM_PASSTHRU)); + RETURN_BOOL(php_amqp_connect(connection, 1, INTERNAL_FUNCTION_PARAM_PASSTHRU)); } /* }}} */ @@ -775,9 +1078,9 @@ static PHP_METHOD(amqp_connection_class, preconnect) get the login */ static PHP_METHOD(amqp_connection_class, getLogin) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("login"); + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("login"); } /* }}} */ @@ -786,23 +1089,34 @@ static PHP_METHOD(amqp_connection_class, getLogin) set the login */ static PHP_METHOD(amqp_connection_class, setLogin) { - char *login = NULL; - size_t login_len = 0; + char *login = NULL; + size_t login_len = 0; - /* Get the login from the method params */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &login, &login_len) == FAILURE) { - return; - } + /* Get the login from the method params */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &login, &login_len) == FAILURE) { + return; + } - /* Validate login length */ - if (login_len > PHP_AMQP_MAX_CREDENTIALS_LENGTH) { - zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'login' exceeds %d character limit.", PHP_AMQP_MAX_CREDENTIALS_LENGTH); - return; - } + /* Validate login length */ + if (login_len > PHP_AMQP_MAX_CREDENTIALS_LENGTH) { + zend_throw_exception_ex( + amqp_connection_exception_class_entry, + 0 TSRMLS_CC, + "Parameter 'login' exceeds %d character limit.", + PHP_AMQP_MAX_CREDENTIALS_LENGTH + ); + return; + } - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("login"), login, login_len TSRMLS_CC); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("login"), + login, + login_len TSRMLS_CC + ); - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -810,9 +1124,9 @@ static PHP_METHOD(amqp_connection_class, setLogin) get the password */ static PHP_METHOD(amqp_connection_class, getPassword) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("password"); + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("password"); } /* }}} */ @@ -821,23 +1135,34 @@ static PHP_METHOD(amqp_connection_class, getPassword) set the password */ static PHP_METHOD(amqp_connection_class, setPassword) { - char *password = NULL; - size_t password_len = 0; + char *password = NULL; + size_t password_len = 0; - /* Get the password from the method params */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &password, &password_len) == FAILURE) { - return; - } + /* Get the password from the method params */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &password, &password_len) == FAILURE) { + return; + } - /* Validate password length */ - if (password_len > PHP_AMQP_MAX_CREDENTIALS_LENGTH) { - zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'password' exceeds %d character limit.", PHP_AMQP_MAX_CREDENTIALS_LENGTH); - return; - } + /* Validate password length */ + if (password_len > PHP_AMQP_MAX_CREDENTIALS_LENGTH) { + zend_throw_exception_ex( + amqp_connection_exception_class_entry, + 0 TSRMLS_CC, + "Parameter 'password' exceeds %d character limit.", + PHP_AMQP_MAX_CREDENTIALS_LENGTH + ); + return; + } - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("password"), password, password_len TSRMLS_CC); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("password"), + password, + password_len TSRMLS_CC + ); - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -846,9 +1171,9 @@ static PHP_METHOD(amqp_connection_class, setPassword) get the host */ static PHP_METHOD(amqp_connection_class, getHost) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("host"); + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("host"); } /* }}} */ @@ -857,23 +1182,28 @@ static PHP_METHOD(amqp_connection_class, getHost) set the host */ static PHP_METHOD(amqp_connection_class, setHost) { - char *host = NULL; - size_t host_len = 0; + char *host = NULL; + size_t host_len = 0; - /* Get the host from the method params */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &host, &host_len) == FAILURE) { - return; - } + /* Get the host from the method params */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &host, &host_len) == FAILURE) { + return; + } - /* Validate host length */ - if (host_len > PHP_AMQP_MAX_IDENTIFIER_LENGTH) { - zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'host' exceeds %d character limit.", PHP_AMQP_MAX_IDENTIFIER_LENGTH); - return; - } + /* Validate host length */ + if (host_len > PHP_AMQP_MAX_IDENTIFIER_LENGTH) { + zend_throw_exception_ex( + amqp_connection_exception_class_entry, + 0 TSRMLS_CC, + "Parameter 'host' exceeds %d character limit.", + PHP_AMQP_MAX_IDENTIFIER_LENGTH + ); + return; + } - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("host"), host, host_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("host"), host, host_len TSRMLS_CC); - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -882,9 +1212,9 @@ static PHP_METHOD(amqp_connection_class, setHost) get the port */ static PHP_METHOD(amqp_connection_class, getPort) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("port"); + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("port"); } /* }}} */ @@ -893,39 +1223,43 @@ static PHP_METHOD(amqp_connection_class, getPort) set the port */ static PHP_METHOD(amqp_connection_class, setPort) { - zval *zvalPort; - int port; - - /* Get the port from the method params */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &zvalPort) == FAILURE) { - return; - } - - /* Parse out the port*/ - switch (Z_TYPE_P(zvalPort)) { - case IS_DOUBLE: - port = (int)Z_DVAL_P(zvalPort); - break; - case IS_LONG: - port = (int)Z_LVAL_P(zvalPort); - break; - case IS_STRING: - convert_to_long(zvalPort); - port = (int)Z_LVAL_P(zvalPort); - break; - default: - port = 0; - } - - /* Check the port value */ - if (port <= 0 || port > 65535) { - zend_throw_exception(amqp_connection_exception_class_entry, "Invalid port given. Value must be between 1 and 65535.", 0 TSRMLS_CC); - return; - } - - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("port"), port TSRMLS_CC); - - RETURN_TRUE; + zval *zvalPort; + int port; + + /* Get the port from the method params */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &zvalPort) == FAILURE) { + return; + } + + /* Parse out the port*/ + switch (Z_TYPE_P(zvalPort)) { + case IS_DOUBLE: + port = (int) Z_DVAL_P(zvalPort); + break; + case IS_LONG: + port = (int) Z_LVAL_P(zvalPort); + break; + case IS_STRING: + convert_to_long(zvalPort); + port = (int) Z_LVAL_P(zvalPort); + break; + default: + port = 0; + } + + /* Check the port value */ + if (port <= 0 || port > 65535) { + zend_throw_exception( + amqp_connection_exception_class_entry, + "Invalid port given. Value must be between 1 and 65535.", + 0 TSRMLS_CC + ); + return; + } + + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("port"), port TSRMLS_CC); + + RETURN_TRUE; } /* }}} */ @@ -933,9 +1267,9 @@ static PHP_METHOD(amqp_connection_class, setPort) get the vhost */ static PHP_METHOD(amqp_connection_class, getVhost) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("vhost"); + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("vhost"); } /* }}} */ @@ -944,22 +1278,33 @@ static PHP_METHOD(amqp_connection_class, getVhost) set the vhost */ static PHP_METHOD(amqp_connection_class, setVhost) { - char *vhost = NULL; - size_t vhost_len = 0; + char *vhost = NULL; + size_t vhost_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &vhost, &vhost_len) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &vhost, &vhost_len) == FAILURE) { + return; + } - /* Validate vhost length */ - if (vhost_len > PHP_AMQP_MAX_IDENTIFIER_LENGTH) { - zend_throw_exception_ex(amqp_connection_exception_class_entry, 0 TSRMLS_CC, "Parameter 'vhost' exceeds %d characters limit.", PHP_AMQP_MAX_IDENTIFIER_LENGTH); - return; - } + /* Validate vhost length */ + if (vhost_len > PHP_AMQP_MAX_IDENTIFIER_LENGTH) { + zend_throw_exception_ex( + amqp_connection_exception_class_entry, + 0 TSRMLS_CC, + "Parameter 'vhost' exceeds %d characters limit.", + PHP_AMQP_MAX_IDENTIFIER_LENGTH + ); + return; + } - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("vhost"), vhost, vhost_len TSRMLS_CC); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("vhost"), + vhost, + vhost_len TSRMLS_CC + ); - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -968,11 +1313,15 @@ static PHP_METHOD(amqp_connection_class, setVhost) get the timeout */ static PHP_METHOD(amqp_connection_class, getTimeout) { - php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "AMQPConnection::getTimeout() method is deprecated; use AMQPConnection::getReadTimeout() instead"); + php_error_docref( + NULL TSRMLS_CC, + E_DEPRECATED, + "AMQPConnection::getTimeout() method is deprecated; use AMQPConnection::getReadTimeout() instead" + ); - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("read_timeout"); + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("read_timeout"); } /* }}} */ @@ -981,37 +1330,51 @@ static PHP_METHOD(amqp_connection_class, getTimeout) set the timeout */ static PHP_METHOD(amqp_connection_class, setTimeout) { - amqp_connection_object *connection; - double read_timeout; - - php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "AMQPConnection::setTimeout($timeout) method is deprecated; use AMQPConnection::setReadTimeout($timeout) instead"); - - /* Get the timeout from the method params */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &read_timeout) == FAILURE) { - return; - } + amqp_connection_object *connection; + double read_timeout; + + php_error_docref( + NULL TSRMLS_CC, + E_DEPRECATED, + "AMQPConnection::setTimeout($timeout) method is deprecated; use AMQPConnection::setReadTimeout($timeout) " + "instead" + ); + + /* Get the timeout from the method params */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &read_timeout) == FAILURE) { + return; + } - /* Validate timeout */ + /* Validate timeout */ if (!php_amqp_is_valid_timeout(read_timeout)) { - zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'timeout' must be greater than or equal to zero.", 0 TSRMLS_CC); - return; - } + zend_throw_exception( + amqp_connection_exception_class_entry, + "Parameter 'timeout' must be greater than or equal to zero.", + 0 TSRMLS_CC + ); + return; + } - /* Get the connection object out of the store */ - connection = PHP_AMQP_GET_CONNECTION(getThis()); + /* Get the connection object out of the store */ + connection = PHP_AMQP_GET_CONNECTION(getThis()); - zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("read_timeout"), read_timeout TSRMLS_CC); + zend_update_property_double( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("read_timeout"), + read_timeout TSRMLS_CC + ); - if (connection->connection_resource && connection->connection_resource->is_connected) { - if (php_amqp_set_resource_read_timeout(connection->connection_resource, read_timeout TSRMLS_CC) == 0) { + if (connection->connection_resource && connection->connection_resource->is_connected) { + if (php_amqp_set_resource_read_timeout(connection->connection_resource, read_timeout TSRMLS_CC) == 0) { - php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC); + php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC); - RETURN_FALSE; - } - } + RETURN_FALSE; + } + } - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -1019,9 +1382,9 @@ static PHP_METHOD(amqp_connection_class, setTimeout) get the read timeout */ static PHP_METHOD(amqp_connection_class, getReadTimeout) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("read_timeout"); + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("read_timeout"); } /* }}} */ @@ -1029,35 +1392,44 @@ static PHP_METHOD(amqp_connection_class, getReadTimeout) set read timeout */ static PHP_METHOD(amqp_connection_class, setReadTimeout) { - amqp_connection_object *connection; - double read_timeout; + amqp_connection_object *connection; + double read_timeout; - /* Get the timeout from the method params */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &read_timeout) == FAILURE) { - return; - } + /* Get the timeout from the method params */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &read_timeout) == FAILURE) { + return; + } - /* Validate timeout */ + /* Validate timeout */ if (!php_amqp_is_valid_timeout(read_timeout)) { - zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'read_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC); - return; - } + zend_throw_exception( + amqp_connection_exception_class_entry, + "Parameter 'read_timeout' must be greater than or equal to zero.", + 0 TSRMLS_CC + ); + return; + } - /* Get the connection object out of the store */ - connection = PHP_AMQP_GET_CONNECTION(getThis()); + /* Get the connection object out of the store */ + connection = PHP_AMQP_GET_CONNECTION(getThis()); - zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("read_timeout"), read_timeout TSRMLS_CC); + zend_update_property_double( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("read_timeout"), + read_timeout TSRMLS_CC + ); - if (connection->connection_resource && connection->connection_resource->is_connected) { - if (php_amqp_set_resource_read_timeout(connection->connection_resource, read_timeout TSRMLS_CC) == 0) { + if (connection->connection_resource && connection->connection_resource->is_connected) { + if (php_amqp_set_resource_read_timeout(connection->connection_resource, read_timeout TSRMLS_CC) == 0) { - php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC); + php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC); - RETURN_FALSE; - } - } + RETURN_FALSE; + } + } - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -1065,9 +1437,9 @@ static PHP_METHOD(amqp_connection_class, setReadTimeout) get write timeout */ static PHP_METHOD(amqp_connection_class, getWriteTimeout) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("write_timeout"); + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("write_timeout"); } /* }}} */ @@ -1075,35 +1447,44 @@ static PHP_METHOD(amqp_connection_class, getWriteTimeout) set write timeout */ static PHP_METHOD(amqp_connection_class, setWriteTimeout) { - amqp_connection_object *connection; - double write_timeout; + amqp_connection_object *connection; + double write_timeout; - /* Get the timeout from the method params */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &write_timeout) == FAILURE) { - return; - } + /* Get the timeout from the method params */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &write_timeout) == FAILURE) { + return; + } - /* Validate timeout */ + /* Validate timeout */ if (!php_amqp_is_valid_timeout(write_timeout)) { - zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'write_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC); - return; - } + zend_throw_exception( + amqp_connection_exception_class_entry, + "Parameter 'write_timeout' must be greater than or equal to zero.", + 0 TSRMLS_CC + ); + return; + } - /* Get the connection object out of the store */ - connection = PHP_AMQP_GET_CONNECTION(getThis()); + /* Get the connection object out of the store */ + connection = PHP_AMQP_GET_CONNECTION(getThis()); - zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("write_timeout"), write_timeout TSRMLS_CC); + zend_update_property_double( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("write_timeout"), + write_timeout TSRMLS_CC + ); - if (connection->connection_resource && connection->connection_resource->is_connected) { - if (php_amqp_set_resource_write_timeout(connection->connection_resource, write_timeout TSRMLS_CC) == 0) { + if (connection->connection_resource && connection->connection_resource->is_connected) { + if (php_amqp_set_resource_write_timeout(connection->connection_resource, write_timeout TSRMLS_CC) == 0) { - php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC); + php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC); - RETURN_FALSE; - } - } + RETURN_FALSE; + } + } - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -1121,9 +1502,9 @@ static PHP_METHOD(amqp_connection_class, getConnectTimeout) get rpc timeout */ static PHP_METHOD(amqp_connection_class, getRpcTimeout) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("rpc_timeout"); + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("rpc_timeout"); } /* }}} */ @@ -1131,35 +1512,44 @@ static PHP_METHOD(amqp_connection_class, getRpcTimeout) set rpc timeout */ static PHP_METHOD(amqp_connection_class, setRpcTimeout) { - amqp_connection_object *connection; - double rpc_timeout; + amqp_connection_object *connection; + double rpc_timeout; - /* Get the timeout from the method params */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &rpc_timeout) == FAILURE) { - return; - } + /* Get the timeout from the method params */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &rpc_timeout) == FAILURE) { + return; + } - /* Validate timeout */ + /* Validate timeout */ if (!php_amqp_is_valid_timeout(rpc_timeout)) { - zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'rpc_timeout' must be greater than or equal to zero.", 0 TSRMLS_CC); - return; - } + zend_throw_exception( + amqp_connection_exception_class_entry, + "Parameter 'rpc_timeout' must be greater than or equal to zero.", + 0 TSRMLS_CC + ); + return; + } - /* Get the connection object out of the store */ - connection = PHP_AMQP_GET_CONNECTION(getThis()); + /* Get the connection object out of the store */ + connection = PHP_AMQP_GET_CONNECTION(getThis()); - zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("rpc_timeout"), rpc_timeout TSRMLS_CC); + zend_update_property_double( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("rpc_timeout"), + rpc_timeout TSRMLS_CC + ); - if (connection->connection_resource && connection->connection_resource->is_connected) { - if (php_amqp_set_resource_rpc_timeout(connection->connection_resource, rpc_timeout TSRMLS_CC) == 0) { + if (connection->connection_resource && connection->connection_resource->is_connected) { + if (php_amqp_set_resource_rpc_timeout(connection->connection_resource, rpc_timeout TSRMLS_CC) == 0) { - php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC); + php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC); - RETURN_FALSE; - } - } + RETURN_FALSE; + } + } - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -1167,21 +1557,21 @@ static PHP_METHOD(amqp_connection_class, setRpcTimeout) Get max used channels number */ static PHP_METHOD(amqp_connection_class, getUsedChannels) { - amqp_connection_object *connection; + amqp_connection_object *connection; - /* Get the timeout from the method params */ - PHP_AMQP_NOPARAMS(); + /* Get the timeout from the method params */ + PHP_AMQP_NOPARAMS(); - /* Get the connection object out of the store */ - connection = PHP_AMQP_GET_CONNECTION(getThis()); + /* Get the connection object out of the store */ + connection = PHP_AMQP_GET_CONNECTION(getThis()); - if (!connection->connection_resource || !connection->connection_resource->is_connected) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Connection is not connected."); + if (!connection->connection_resource || !connection->connection_resource->is_connected) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Connection is not connected."); - RETURN_LONG(0); - } + RETURN_LONG(0); + } - RETURN_LONG(connection->connection_resource->used_slots); + RETURN_LONG(connection->connection_resource->used_slots); } /* }}} */ @@ -1189,19 +1579,19 @@ static PHP_METHOD(amqp_connection_class, getUsedChannels) Get max supported channels number per connection */ PHP_METHOD(amqp_connection_class, getMaxChannels) { - zval rv; - amqp_connection_object *connection; + zval rv; + amqp_connection_object *connection; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS(); - /* Get the connection object out of the store */ - connection = PHP_AMQP_GET_CONNECTION(getThis()); + /* Get the connection object out of the store */ + connection = PHP_AMQP_GET_CONNECTION(getThis()); - if (connection->connection_resource && connection->connection_resource->is_connected) { - RETURN_LONG(connection->connection_resource->max_slots); - } + if (connection->connection_resource && connection->connection_resource->is_connected) { + RETURN_LONG(connection->connection_resource->max_slots); + } - PHP_AMQP_RETURN_THIS_PROP("channel_max"); + PHP_AMQP_RETURN_THIS_PROP("channel_max"); } /* }}} */ @@ -1209,19 +1599,19 @@ PHP_METHOD(amqp_connection_class, getMaxChannels) Get max supported frame size per connection in bytes */ static PHP_METHOD(amqp_connection_class, getMaxFrameSize) { - zval rv; - amqp_connection_object *connection; + zval rv; + amqp_connection_object *connection; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS(); - /* Get the connection object out of the store */ - connection = PHP_AMQP_GET_CONNECTION(getThis()); + /* Get the connection object out of the store */ + connection = PHP_AMQP_GET_CONNECTION(getThis()); - if (connection->connection_resource && connection->connection_resource->is_connected) { - RETURN_LONG(amqp_get_frame_max(connection->connection_resource->connection_state)); - } + if (connection->connection_resource && connection->connection_resource->is_connected) { + RETURN_LONG(amqp_get_frame_max(connection->connection_resource->connection_state)); + } - PHP_AMQP_RETURN_THIS_PROP("frame_max"); + PHP_AMQP_RETURN_THIS_PROP("frame_max"); } /* }}} */ @@ -1229,20 +1619,19 @@ static PHP_METHOD(amqp_connection_class, getMaxFrameSize) Get number of seconds between heartbeats of the connection in seconds */ static PHP_METHOD(amqp_connection_class, getHeartbeatInterval) { - zval rv; - amqp_connection_object *connection; + zval rv; + amqp_connection_object *connection; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS(); - /* Get the connection object out of the store */ - connection = PHP_AMQP_GET_CONNECTION(getThis()); + /* Get the connection object out of the store */ + connection = PHP_AMQP_GET_CONNECTION(getThis()); - if (connection->connection_resource != NULL - && connection->connection_resource->is_connected != '\0') { - RETURN_LONG(amqp_get_heartbeat(connection->connection_resource->connection_state)); - } + if (connection->connection_resource != NULL && connection->connection_resource->is_connected != '\0') { + RETURN_LONG(amqp_get_heartbeat(connection->connection_resource->connection_state)); + } - PHP_AMQP_RETURN_THIS_PROP("heartbeat"); + PHP_AMQP_RETURN_THIS_PROP("heartbeat"); } /* }}} */ @@ -1250,13 +1639,13 @@ static PHP_METHOD(amqp_connection_class, getHeartbeatInterval) check whether amqp connection is persistent */ static PHP_METHOD(amqp_connection_class, isPersistent) { - amqp_connection_object *connection; + amqp_connection_object *connection; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS(); - connection = PHP_AMQP_GET_CONNECTION(getThis()); + connection = PHP_AMQP_GET_CONNECTION(getThis()); - RETURN_BOOL(connection->connection_resource && connection->connection_resource->is_persistent); + RETURN_BOOL(connection->connection_resource && connection->connection_resource->is_persistent); } /* }}} */ @@ -1264,72 +1653,75 @@ static PHP_METHOD(amqp_connection_class, isPersistent) /* {{{ proto amqp::getCACert() */ static PHP_METHOD(amqp_connection_class, getCACert) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("cacert"); + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("cacert"); } /* }}} */ /* {{{ proto amqp::setCACert(string cacert) */ static PHP_METHOD(amqp_connection_class, setCACert) { - char *str = NULL; size_t str_len = 0; + char *str = NULL; + size_t str_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { + return; + } - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("cacert"), str, str_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("cacert"), str, str_len TSRMLS_CC); - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ /* {{{ proto amqp::getCert() */ static PHP_METHOD(amqp_connection_class, getCert) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("cert"); + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("cert"); } /* }}} */ /* {{{ proto amqp::setCert(string cert) */ static PHP_METHOD(amqp_connection_class, setCert) { - char *str = NULL; size_t str_len = 0; + char *str = NULL; + size_t str_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { + return; + } - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("cert"), str, str_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("cert"), str, str_len TSRMLS_CC); - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ /* {{{ proto amqp::getKey() */ static PHP_METHOD(amqp_connection_class, getKey) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("key"); + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("key"); } /* }}} */ /* {{{ proto amqp::setKey(string key) */ static PHP_METHOD(amqp_connection_class, setKey) { - char *str = NULL; size_t str_len = 0; + char *str = NULL; + size_t str_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { + return; + } - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("key"), str, str_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("key"), str, str_len TSRMLS_CC); - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -1337,24 +1729,24 @@ static PHP_METHOD(amqp_connection_class, setKey) /* {{{ proto amqp::getVerify() */ static PHP_METHOD(amqp_connection_class, getVerify) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("verify"); + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("verify"); } /* }}} */ /* {{{ proto amqp::setVerify(bool verify) */ static PHP_METHOD(amqp_connection_class, setVerify) { - zend_bool verify = 1; + zend_bool verify = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &verify) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &verify) == FAILURE) { + return; + } - zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("verify"), verify TSRMLS_CC); + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("verify"), verify TSRMLS_CC); - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -1362,9 +1754,9 @@ static PHP_METHOD(amqp_connection_class, setVerify) get sasl method */ static PHP_METHOD(amqp_connection_class, getSaslMethod) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("sasl_method"); + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("sasl_method"); } /* }}} */ @@ -1372,56 +1764,67 @@ static PHP_METHOD(amqp_connection_class, getSaslMethod) set sasl method */ static PHP_METHOD(amqp_connection_class, setSaslMethod) { - long method; + long method; - /* Get the port from the method params */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &method) == FAILURE) { - return; - } + /* Get the port from the method params */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &method) == FAILURE) { + return; + } - /* Check the method value */ - if (method != AMQP_SASL_METHOD_PLAIN && method != AMQP_SASL_METHOD_EXTERNAL) { - zend_throw_exception(amqp_connection_exception_class_entry, "Invalid SASL method given. Method must be AMQP_SASL_METHOD_PLAIN or AMQP_SASL_METHOD_EXTERNAL.", 0 TSRMLS_CC); - return; - } + /* Check the method value */ + if (method != AMQP_SASL_METHOD_PLAIN && method != AMQP_SASL_METHOD_EXTERNAL) { + zend_throw_exception( + amqp_connection_exception_class_entry, + "Invalid SASL method given. Method must be AMQP_SASL_METHOD_PLAIN or AMQP_SASL_METHOD_EXTERNAL.", + 0 TSRMLS_CC + ); + return; + } - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("sasl_method"), method TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("sasl_method"), method TSRMLS_CC); - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ /* {{{ proto amqp::getConnectionName() */ static PHP_METHOD(amqp_connection_class, getConnectionName) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("connection_name"); + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("connection_name"); } /* }}} */ /* {{{ proto amqp::setConnectionName(string connectionName) */ static PHP_METHOD(amqp_connection_class, setConnectionName) { - char *str = NULL; size_t str_len = 0; + char *str = NULL; + size_t str_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &str, &str_len) == FAILURE) { - return; - } - if (str == NULL) { - zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connection_name") TSRMLS_CC); - } else { - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connection_name"), str, str_len TSRMLS_CC); - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &str, &str_len) == FAILURE) { + return; + } + if (str == NULL) { + zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connection_name") TSRMLS_CC); + } else { + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("connection_name"), + str, + str_len TSRMLS_CC + ); + } - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ /* amqp_connection_class ARG_INFO definition */ ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class__construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) - ZEND_ARG_ARRAY_INFO(0, credentials, 0) + ZEND_ARG_ARRAY_INFO(0, credentials, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_isConnected, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) @@ -1449,56 +1852,56 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getLogin, ZEND_SEND_BY_VAL, ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setLogin, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, login) + ZEND_ARG_INFO(0, login) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getPassword, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setPassword, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, password) + ZEND_ARG_INFO(0, password) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getHost, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setHost, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, host) + ZEND_ARG_INFO(0, host) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getPort, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setPort, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, port) + ZEND_ARG_INFO(0, port) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getVhost, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setVhost, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, vhost) + ZEND_ARG_INFO(0, vhost) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, timeout) + ZEND_ARG_INFO(0, timeout) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getReadTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setReadTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, timeout) + ZEND_ARG_INFO(0, timeout) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getWriteTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setWriteTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, timeout) + ZEND_ARG_INFO(0, timeout) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getConnectTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) @@ -1508,7 +1911,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getRpcTimeout, ZEND_SEND_BY ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setRpcTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, timeout) + ZEND_ARG_INFO(0, timeout) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getUsedChannels, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) @@ -1530,158 +1933,149 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getCACert, ZEND_SEND_BY_VAL ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setCACert, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, cacert) + ZEND_ARG_INFO(0, cacert) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getCert, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setCert, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, cert) + ZEND_ARG_INFO(0, cert) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getKey, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setKey, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, key) + ZEND_ARG_INFO(0, key) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getVerify, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setVerify, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, verify) + ZEND_ARG_INFO(0, verify) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getSaslMethod, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setSaslMethod, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, sasl_method) + ZEND_ARG_INFO(0, sasl_method) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getConnectionName, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setConnectionName, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, connection_name) + ZEND_ARG_INFO(0, connection_name) ZEND_END_ARG_INFO() zend_function_entry amqp_connection_class_functions[] = { - PHP_ME(amqp_connection_class, __construct, arginfo_amqp_connection_class__construct, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, isConnected, arginfo_amqp_connection_class_isConnected, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, connect, arginfo_amqp_connection_class_connect, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, pconnect, arginfo_amqp_connection_class_pconnect, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, pdisconnect, arginfo_amqp_connection_class_pdisconnect, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, disconnect, arginfo_amqp_connection_class_disconnect, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, reconnect, arginfo_amqp_connection_class_reconnect, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, preconnect, arginfo_amqp_connection_class_preconnect, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, __construct, arginfo_amqp_connection_class__construct, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, isConnected, arginfo_amqp_connection_class_isConnected, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, connect, arginfo_amqp_connection_class_connect, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, pconnect, arginfo_amqp_connection_class_pconnect, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, pdisconnect, arginfo_amqp_connection_class_pdisconnect, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, disconnect, arginfo_amqp_connection_class_disconnect, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, reconnect, arginfo_amqp_connection_class_reconnect, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, preconnect, arginfo_amqp_connection_class_preconnect, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, getLogin, arginfo_amqp_connection_class_getLogin, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, setLogin, arginfo_amqp_connection_class_setLogin, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, getLogin, arginfo_amqp_connection_class_getLogin, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, setLogin, arginfo_amqp_connection_class_setLogin, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, getPassword, arginfo_amqp_connection_class_getPassword, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, setPassword, arginfo_amqp_connection_class_setPassword, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, getPassword, arginfo_amqp_connection_class_getPassword, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, setPassword, arginfo_amqp_connection_class_setPassword, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, getHost, arginfo_amqp_connection_class_getHost, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, setHost, arginfo_amqp_connection_class_setHost, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, getHost, arginfo_amqp_connection_class_getHost, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, setHost, arginfo_amqp_connection_class_setHost, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, getPort, arginfo_amqp_connection_class_getPort, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, setPort, arginfo_amqp_connection_class_setPort, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, getPort, arginfo_amqp_connection_class_getPort, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, setPort, arginfo_amqp_connection_class_setPort, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, getVhost, arginfo_amqp_connection_class_getVhost, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, setVhost, arginfo_amqp_connection_class_setVhost, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, getVhost, arginfo_amqp_connection_class_getVhost, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, setVhost, arginfo_amqp_connection_class_setVhost, ZEND_ACC_PUBLIC) - 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, 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, getConnectTimeout, arginfo_amqp_connection_class_getConnectTimeout, ZEND_ACC_PUBLIC) - /** setConnectTimeout intentionally left out */ + PHP_ME(amqp_connection_class, getConnectTimeout, arginfo_amqp_connection_class_getConnectTimeout, ZEND_ACC_PUBLIC) + /** setConnectTimeout intentionally left out */ - PHP_ME(amqp_connection_class, getRpcTimeout, arginfo_amqp_connection_class_getRpcTimeout, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, setRpcTimeout, arginfo_amqp_connection_class_setRpcTimeout, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, getRpcTimeout, arginfo_amqp_connection_class_getRpcTimeout, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, setRpcTimeout, arginfo_amqp_connection_class_setRpcTimeout, 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, getHeartbeatInterval, arginfo_amqp_connection_class_getHeartbeatInterval, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, getMaxFrameSize, arginfo_amqp_connection_class_getMaxFrameSize, 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, getHeartbeatInterval, arginfo_amqp_connection_class_getHeartbeatInterval, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, getMaxFrameSize, arginfo_amqp_connection_class_getMaxFrameSize, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, getCACert, arginfo_amqp_connection_class_getCACert, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, setCACert, arginfo_amqp_connection_class_setCACert, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, getCACert, arginfo_amqp_connection_class_getCACert, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, setCACert, arginfo_amqp_connection_class_setCACert, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, getCert, arginfo_amqp_connection_class_getCert, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, setCert, arginfo_amqp_connection_class_setCert, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, getCert, arginfo_amqp_connection_class_getCert, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, setCert, arginfo_amqp_connection_class_setCert, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, getKey, arginfo_amqp_connection_class_getKey, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, setKey, arginfo_amqp_connection_class_setKey, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, getKey, arginfo_amqp_connection_class_getKey, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, setKey, arginfo_amqp_connection_class_setKey, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, getVerify, arginfo_amqp_connection_class_getVerify, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, setVerify, arginfo_amqp_connection_class_setVerify, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, getVerify, arginfo_amqp_connection_class_getVerify, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, setVerify, arginfo_amqp_connection_class_setVerify, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, getSaslMethod, arginfo_amqp_connection_class_getSaslMethod, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, setSaslMethod, arginfo_amqp_connection_class_setSaslMethod, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, getSaslMethod, arginfo_amqp_connection_class_getSaslMethod, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, setSaslMethod, arginfo_amqp_connection_class_setSaslMethod, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, getConnectionName, arginfo_amqp_connection_class_getConnectionName, ZEND_ACC_PUBLIC) - PHP_ME(amqp_connection_class, setConnectionName, arginfo_amqp_connection_class_setConnectionName, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, getConnectionName, arginfo_amqp_connection_class_getConnectionName, ZEND_ACC_PUBLIC) + PHP_ME(amqp_connection_class, setConnectionName, arginfo_amqp_connection_class_setConnectionName, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} + {NULL, NULL, NULL} }; PHP_MINIT_FUNCTION(amqp_connection) { - zend_class_entry ce; + zend_class_entry ce; - INIT_CLASS_ENTRY(ce, "AMQPConnection", amqp_connection_class_functions); - ce.create_object = amqp_connection_ctor; - this_ce = zend_register_internal_class(&ce TSRMLS_CC); + INIT_CLASS_ENTRY(ce, "AMQPConnection", amqp_connection_class_functions); + ce.create_object = amqp_connection_ctor; + this_ce = zend_register_internal_class(&ce TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("login"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("password"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("host"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("vhost"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("port"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("login"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("password"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("host"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("vhost"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("port"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("read_timeout"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("write_timeout"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("connect_timeout"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("rpc_timeout"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("read_timeout"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("write_timeout"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("connect_timeout"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("rpc_timeout"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("channel_max"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("frame_max"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("heartbeat"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("channel_max"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("frame_max"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("heartbeat"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("cacert"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("key"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("cert"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("verify"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("cacert"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("key"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("cert"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("verify"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("sasl_method"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("sasl_method"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("connection_name"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("connection_name"), ZEND_ACC_PRIVATE TSRMLS_CC); - memcpy(&amqp_connection_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); + memcpy(&amqp_connection_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); - amqp_connection_object_handlers.offset = XtOffsetOf(amqp_connection_object, zo); - amqp_connection_object_handlers.free_obj = amqp_connection_free; + amqp_connection_object_handlers.offset = XtOffsetOf(amqp_connection_object, zo); + amqp_connection_object_handlers.free_obj = amqp_connection_free; - return SUCCESS; + return SUCCESS; } - -/* -*Local variables: -*tab-width: 4 -*c-basic-offset: 4 -*End: -*vim600: noet sw=4 ts=4 fdm=marker -*vim<6 -*/ diff --git a/amqp_connection.h b/amqp_connection.h index 0b8b5559..82dbd16c 100644 --- a/amqp_connection.h +++ b/amqp_connection.h @@ -29,12 +29,3 @@ void php_amqp_disconnect_force(amqp_connection_resource *resource TSRMLS_DC); PHP_MINIT_FUNCTION(amqp_connection); - -/* -*Local variables: -*tab-width: 4 -*c-basic-offset: 4 -*End: -*vim600: noet sw=4 ts=4 fdm=marker -*vim<600: noet sw=4 ts=4 -*/ diff --git a/amqp_connection_resource.c b/amqp_connection_resource.c index b45c3d43..85fe72d0 100644 --- a/amqp_connection_resource.c +++ b/amqp_connection_resource.c @@ -22,7 +22,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" + #include "config.h" #endif #include "php.h" @@ -32,33 +32,33 @@ #include "zend_exceptions.h" #ifdef PHP_WIN32 -# if PHP_VERSION_ID >= 80000 -# include "main/php_stdint.h" -# else -# include "win32/php_stdint.h" -# endif -# include "win32/signal.h" + #if PHP_VERSION_ID >= 80000 + #include "main/php_stdint.h" + #else + #include "win32/php_stdint.h" + #endif + #include "win32/signal.h" #else -# include -# include + #include + #include #endif #if HAVE_LIBRABBITMQ_NEW_LAYOUT -#include -#include -#include -#include + #include + #include + #include + #include #else -#include -#include -#include -#include + #include + #include + #include + #include #endif #ifdef PHP_WIN32 -# include "win32/unistd.h" + #include "win32/unistd.h" #else -# include + #include #endif //#include "amqp_basic_properties.h" @@ -68,119 +68,159 @@ #include "php_amqp.h" #ifndef E_DEPRECATED -#define E_DEPRECATED E_WARNING + #define E_DEPRECATED E_WARNING #endif int le_amqp_connection_resource; int le_amqp_connection_resource_persistent; static void connection_resource_destructor(amqp_connection_resource *resource, int persistent TSRMLS_DC); -static void php_amqp_close_connection_from_server(amqp_rpc_reply_t reply, char **message, amqp_connection_resource *resource TSRMLS_DC); -static void php_amqp_close_channel_from_server(amqp_rpc_reply_t reply, char **message, amqp_connection_resource *resource, amqp_channel_t channel_id TSRMLS_DC); +static void php_amqp_close_connection_from_server( + amqp_rpc_reply_t reply, + char **message, + amqp_connection_resource *resource TSRMLS_DC +); +static void php_amqp_close_channel_from_server( + amqp_rpc_reply_t reply, + char **message, + amqp_connection_resource *resource, + amqp_channel_t channel_id TSRMLS_DC +); /* Figure out what's going on connection and handle protocol exceptions, if any */ -int php_amqp_connection_resource_error(amqp_rpc_reply_t reply, char **message, amqp_connection_resource *resource, amqp_channel_t channel_id TSRMLS_DC) +int php_amqp_connection_resource_error( + amqp_rpc_reply_t reply, + char **message, + amqp_connection_resource *resource, + amqp_channel_t channel_id TSRMLS_DC +) { - assert (resource != NULL); - - switch (reply.reply_type) { - case AMQP_RESPONSE_NORMAL: - return PHP_AMQP_RESOURCE_RESPONSE_OK; - - case AMQP_RESPONSE_NONE: - spprintf(message, 0, "Missing RPC reply type."); - return PHP_AMQP_RESOURCE_RESPONSE_ERROR; - - case AMQP_RESPONSE_LIBRARY_EXCEPTION: - - spprintf(message, 0, "Library error: %s", amqp_error_string2(reply.library_error)); - return PHP_AMQP_RESOURCE_RESPONSE_ERROR; - - case AMQP_RESPONSE_SERVER_EXCEPTION: - switch (reply.reply.id) { - case AMQP_CONNECTION_CLOSE_METHOD: { - php_amqp_close_connection_from_server(reply, message, resource TSRMLS_CC); - return PHP_AMQP_RESOURCE_RESPONSE_ERROR_CONNECTION_CLOSED; - } - case AMQP_CHANNEL_CLOSE_METHOD: { - php_amqp_close_channel_from_server(reply, message, resource, channel_id TSRMLS_CC); - return PHP_AMQP_RESOURCE_RESPONSE_ERROR_CHANNEL_CLOSED; - } - } - /* Default for the above switch should be handled by the below default. */ - default: - spprintf(message, 0, "Unknown server error, method id 0x%08X", reply.reply.id); - return PHP_AMQP_RESOURCE_RESPONSE_ERROR; - } - - /* Should not never get here*/ + assert(resource != NULL); + + switch (reply.reply_type) { + case AMQP_RESPONSE_NORMAL: + return PHP_AMQP_RESOURCE_RESPONSE_OK; + + case AMQP_RESPONSE_NONE: + spprintf(message, 0, "Missing RPC reply type."); + return PHP_AMQP_RESOURCE_RESPONSE_ERROR; + + case AMQP_RESPONSE_LIBRARY_EXCEPTION: + spprintf(message, 0, "Library error: %s", amqp_error_string2(reply.library_error)); + return PHP_AMQP_RESOURCE_RESPONSE_ERROR; + + case AMQP_RESPONSE_SERVER_EXCEPTION: + switch (reply.reply.id) { + case AMQP_CONNECTION_CLOSE_METHOD: { + php_amqp_close_connection_from_server(reply, message, resource TSRMLS_CC); + return PHP_AMQP_RESOURCE_RESPONSE_ERROR_CONNECTION_CLOSED; + } + case AMQP_CHANNEL_CLOSE_METHOD: { + php_amqp_close_channel_from_server(reply, message, resource, channel_id TSRMLS_CC); + return PHP_AMQP_RESOURCE_RESPONSE_ERROR_CHANNEL_CLOSED; + } + } + /* Default for the above switch should be handled by the below default. */ + default: + spprintf(message, 0, "Unknown server error, method id 0x%08X", reply.reply.id); + return PHP_AMQP_RESOURCE_RESPONSE_ERROR; + } + + /* Should not never get here*/ } -static void php_amqp_close_connection_from_server(amqp_rpc_reply_t reply, char **message, amqp_connection_resource *resource TSRMLS_DC) { - amqp_connection_close_t *m = (amqp_connection_close_t *)reply.reply.decoded; - int result; - - if (!reply.reply.id) { - PHP_AMQP_G(error_code) = -1; - spprintf(message, 0, "Server connection error: %ld, message: %s", - (long)PHP_AMQP_G(error_code), - "unexpected response" - ); - } else { - PHP_AMQP_G(error_code) = m->reply_code; - spprintf(message, 0, "Server connection error: %d, message: %.*s", - m->reply_code, - (int) m->reply_text.len, - (char *) m->reply_text.bytes - ); - } - - /* +static void php_amqp_close_connection_from_server( + amqp_rpc_reply_t reply, + char **message, + amqp_connection_resource *resource TSRMLS_DC +) +{ + amqp_connection_close_t *m = (amqp_connection_close_t *) reply.reply.decoded; + int result; + + if (!reply.reply.id) { + PHP_AMQP_G(error_code) = -1; + spprintf( + message, + 0, + "Server connection error: %ld, message: %s", + (long) PHP_AMQP_G(error_code), + "unexpected response" + ); + } else { + PHP_AMQP_G(error_code) = m->reply_code; + spprintf( + message, + 0, + "Server connection error: %d, message: %.*s", + m->reply_code, + (int) m->reply_text.len, + (char *) m->reply_text.bytes + ); + } + + /* * - If r.reply.id == AMQP_CONNECTION_CLOSE_METHOD a connection exception * occurred, cast r.reply.decoded to amqp_connection_close_t* to see * details of the exception. The client amqp_send_method() a * amqp_connection_close_ok_t and disconnect from the broker. */ - amqp_connection_close_ok_t *decoded = (amqp_connection_close_ok_t *) NULL; - - result = amqp_send_method( - resource->connection_state, - 0, /* NOTE: 0-channel is reserved for things like this */ - AMQP_CONNECTION_CLOSE_OK_METHOD, - &decoded - ); - - if (result != AMQP_STATUS_OK) { - zend_throw_exception(amqp_channel_exception_class_entry, "An error occurred while closing the connection.", 0 TSRMLS_CC); - } - - /* Prevent finishing AMQP connection in connection resource destructor */ - resource->is_connected = '\0'; + amqp_connection_close_ok_t *decoded = (amqp_connection_close_ok_t *) NULL; + + result = amqp_send_method( + resource->connection_state, + 0, /* NOTE: 0-channel is reserved for things like this */ + AMQP_CONNECTION_CLOSE_OK_METHOD, + &decoded + ); + + if (result != AMQP_STATUS_OK) { + zend_throw_exception( + amqp_channel_exception_class_entry, + "An error occurred while closing the connection.", + 0 TSRMLS_CC + ); + } + + /* Prevent finishing AMQP connection in connection resource destructor */ + resource->is_connected = '\0'; } -static void php_amqp_close_channel_from_server(amqp_rpc_reply_t reply, char **message, amqp_connection_resource *resource, amqp_channel_t channel_id TSRMLS_DC) { - assert(channel_id > 0 && channel_id <= resource->max_slots); - - amqp_channel_close_t *m = (amqp_channel_close_t *) reply.reply.decoded; - - if (!reply.reply.id) { - PHP_AMQP_G(error_code) = -1; - spprintf(message, 0, "Server channel error: %ld, message: %s", - (long)PHP_AMQP_G(error_code), - "unexpected response" - ); - } else { - PHP_AMQP_G(error_code) = m->reply_code; - spprintf(message, 0, "Server channel error: %d, message: %.*s", - m->reply_code, - (int) m->reply_text.len, - (char *)m->reply_text.bytes - ); - } - - /* +static void php_amqp_close_channel_from_server( + amqp_rpc_reply_t reply, + char **message, + amqp_connection_resource *resource, + amqp_channel_t channel_id TSRMLS_DC +) +{ + assert(channel_id > 0 && channel_id <= resource->max_slots); + + amqp_channel_close_t *m = (amqp_channel_close_t *) reply.reply.decoded; + + if (!reply.reply.id) { + PHP_AMQP_G(error_code) = -1; + spprintf( + message, + 0, + "Server channel error: %ld, message: %s", + (long) PHP_AMQP_G(error_code), + "unexpected response" + ); + } else { + PHP_AMQP_G(error_code) = m->reply_code; + spprintf( + message, + 0, + "Server channel error: %d, message: %.*s", + m->reply_code, + (int) m->reply_text.len, + (char *) m->reply_text.bytes + ); + } + + /* * - If r.reply.id == AMQP_CHANNEL_CLOSE_METHOD a channel exception * occurred, cast r.reply.decoded to amqp_channel_close_t* to see details * of the exception. The client should amqp_send_method() a @@ -189,171 +229,223 @@ static void php_amqp_close_channel_from_server(amqp_rpc_reply_t reply, char **me * (auto-delete exchanges, auto-delete queues, consumers) are invalid * and must be recreated before attempting to use them again. */ - - if (resource) { - int result; - amqp_channel_close_ok_t *decoded = (amqp_channel_close_ok_t *) NULL; - - result = amqp_send_method( - resource->connection_state, - channel_id, - AMQP_CHANNEL_CLOSE_OK_METHOD, - &decoded - ); - if (result != AMQP_STATUS_OK) { - zend_throw_exception(amqp_channel_exception_class_entry, "An error occurred while closing channel.", 0 TSRMLS_CC); - } - } + if (resource) { + int result; + amqp_channel_close_ok_t *decoded = (amqp_channel_close_ok_t *) NULL; + + result = amqp_send_method(resource->connection_state, channel_id, AMQP_CHANNEL_CLOSE_OK_METHOD, &decoded); + if (result != AMQP_STATUS_OK) { + zend_throw_exception( + amqp_channel_exception_class_entry, + "An error occurred while closing channel.", + 0 TSRMLS_CC + ); + } + } } -int php_amqp_connection_resource_error_advanced(amqp_rpc_reply_t reply, char **message, amqp_connection_resource *resource, amqp_channel_t channel_id, amqp_channel_object *channel TSRMLS_DC) +int php_amqp_connection_resource_error_advanced( + amqp_rpc_reply_t reply, + char **message, + amqp_connection_resource *resource, + amqp_channel_t channel_id, + amqp_channel_object *channel TSRMLS_DC +) { - assert(resource != NULL); - - amqp_frame_t frame; - - assert(AMQP_RESPONSE_LIBRARY_EXCEPTION == reply.reply_type); - assert(AMQP_STATUS_UNEXPECTED_STATE == reply.library_error); - - if (channel_id < 0 || AMQP_STATUS_OK != amqp_simple_wait_frame(resource->connection_state, &frame)) { - if (*message != NULL) { - efree(*message); - } - - spprintf(message, 0, "Library error: %s", amqp_error_string2(reply.library_error)); - return PHP_AMQP_RESOURCE_RESPONSE_ERROR; - } - - if (channel_id != frame.channel) { - spprintf(message, 0, "Library error: channel mismatch"); - return PHP_AMQP_RESOURCE_RESPONSE_ERROR; - } - - if (AMQP_FRAME_METHOD == frame.frame_type) { - switch (frame.payload.method.id) { - case AMQP_CONNECTION_CLOSE_METHOD: { - php_amqp_close_connection_from_server(reply, message, resource TSRMLS_CC); - return PHP_AMQP_RESOURCE_RESPONSE_ERROR_CONNECTION_CLOSED; - } - case AMQP_CHANNEL_CLOSE_METHOD: { - php_amqp_close_channel_from_server(reply, message, resource, channel_id TSRMLS_CC); - return PHP_AMQP_RESOURCE_RESPONSE_ERROR_CHANNEL_CLOSED; - } - - case AMQP_BASIC_ACK_METHOD: - /* if we've turned publisher confirms on, and we've published a message + assert(resource != NULL); + + amqp_frame_t frame; + + assert(AMQP_RESPONSE_LIBRARY_EXCEPTION == reply.reply_type); + assert(AMQP_STATUS_UNEXPECTED_STATE == reply.library_error); + + if (channel_id < 0 || AMQP_STATUS_OK != amqp_simple_wait_frame(resource->connection_state, &frame)) { + if (*message != NULL) { + efree(*message); + } + + spprintf(message, 0, "Library error: %s", amqp_error_string2(reply.library_error)); + return PHP_AMQP_RESOURCE_RESPONSE_ERROR; + } + + if (channel_id != frame.channel) { + spprintf(message, 0, "Library error: channel mismatch"); + return PHP_AMQP_RESOURCE_RESPONSE_ERROR; + } + + if (AMQP_FRAME_METHOD == frame.frame_type) { + switch (frame.payload.method.id) { + case AMQP_CONNECTION_CLOSE_METHOD: { + php_amqp_close_connection_from_server(reply, message, resource TSRMLS_CC); + return PHP_AMQP_RESOURCE_RESPONSE_ERROR_CONNECTION_CLOSED; + } + case AMQP_CHANNEL_CLOSE_METHOD: { + php_amqp_close_channel_from_server(reply, message, resource, channel_id TSRMLS_CC); + return PHP_AMQP_RESOURCE_RESPONSE_ERROR_CHANNEL_CLOSED; + } + + case AMQP_BASIC_ACK_METHOD: + /* if we've turned publisher confirms on, and we've published a message * here is a message being confirmed */ - return php_amqp_handle_basic_ack(message, resource, channel_id, channel, &frame.payload.method TSRMLS_CC); - case AMQP_BASIC_NACK_METHOD: - /* if we've turned publisher confirms on, and we've published a message + return php_amqp_handle_basic_ack( + message, + resource, + channel_id, + channel, + &frame.payload.method TSRMLS_CC + ); + case AMQP_BASIC_NACK_METHOD: + /* if we've turned publisher confirms on, and we've published a message * here is a message being confirmed */ - return php_amqp_handle_basic_nack(message, resource, channel_id, channel, &frame.payload.method TSRMLS_CC); - case AMQP_BASIC_RETURN_METHOD: - /* if a published message couldn't be routed and the mandatory flag was set + return php_amqp_handle_basic_nack( + message, + resource, + channel_id, + channel, + &frame.payload.method TSRMLS_CC + ); + case AMQP_BASIC_RETURN_METHOD: + /* if a published message couldn't be routed and the mandatory flag was set * this is what would be returned. The message then needs to be read. */ - return php_amqp_handle_basic_return(message, resource, channel_id, channel, &frame.payload.method TSRMLS_CC); - default: - if (*message != NULL) { - efree(*message); - } - - spprintf(message, 0, "Library error: An unexpected method was received 0x%08X\n", frame.payload.method.id); - return PHP_AMQP_RESOURCE_RESPONSE_ERROR; - } - } - - if (*message != NULL) { - efree(*message); - } - - spprintf(message, 0, "Library error: %s", amqp_error_string2(reply.library_error)); - return PHP_AMQP_RESOURCE_RESPONSE_ERROR; + return php_amqp_handle_basic_return( + message, + resource, + channel_id, + channel, + &frame.payload.method TSRMLS_CC + ); + default: + if (*message != NULL) { + efree(*message); + } + + spprintf( + message, + 0, + "Library error: An unexpected method was received 0x%08X\n", + frame.payload.method.id + ); + return PHP_AMQP_RESOURCE_RESPONSE_ERROR; + } + } + + if (*message != NULL) { + efree(*message); + } + + spprintf(message, 0, "Library error: %s", amqp_error_string2(reply.library_error)); + return PHP_AMQP_RESOURCE_RESPONSE_ERROR; } /* Socket-related functions */ int php_amqp_set_resource_read_timeout(amqp_connection_resource *resource, double timeout TSRMLS_DC) { - assert(timeout >= 0.0); + assert(timeout >= 0.0); #ifdef PHP_WIN32 - DWORD read_timeout; - /* + DWORD read_timeout; + /* In Windows, setsockopt with SO_RCVTIMEO sets actual timeout to a value that's 500ms greater than specified value. Also, it's not possible to set timeout to any value below 500ms. Zero timeout works like it should, however. */ - if (timeout == 0.) { - read_timeout = 0; - } else { - read_timeout = (int) (max(timeout * 1.e+3 - .5e+3, 1.)); - } + if (timeout == 0.) { + read_timeout = 0; + } else { + read_timeout = (int) (max(timeout * 1.e+3 - .5e+3, 1.)); + } #else - struct timeval read_timeout; - read_timeout.tv_sec = (int) floor(timeout); - read_timeout.tv_usec = (int) ((timeout - floor(timeout)) * 1.e+6); + struct timeval read_timeout; + read_timeout.tv_sec = (int) floor(timeout); + read_timeout.tv_usec = (int) ((timeout - floor(timeout)) * 1.e+6); #endif - if (0 != setsockopt(amqp_get_sockfd(resource->connection_state), SOL_SOCKET, SO_RCVTIMEO, (char *)&read_timeout, sizeof(read_timeout))) { - zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: cannot setsockopt SO_RCVTIMEO", 0 TSRMLS_CC); - return 0; - } - - return 1; + if (0 != setsockopt( + amqp_get_sockfd(resource->connection_state), + SOL_SOCKET, + SO_RCVTIMEO, + (char *) &read_timeout, + sizeof(read_timeout) + )) { + zend_throw_exception( + amqp_connection_exception_class_entry, + "Socket error: cannot setsockopt SO_RCVTIMEO", + 0 TSRMLS_CC + ); + return 0; + } + + return 1; } int php_amqp_set_resource_rpc_timeout(amqp_connection_resource *resource, double timeout TSRMLS_DC) { - assert(timeout >= 0.0); + assert(timeout >= 0.0); #if AMQP_VERSION_MAJOR * 100 + AMQP_VERSION_MINOR * 10 + AMQP_VERSION_PATCH >= 90 - struct timeval rpc_timeout; - - if (timeout == 0.) return 1; - - rpc_timeout.tv_sec = (int) floor(timeout); - rpc_timeout.tv_usec = (int) ((timeout - floor(timeout)) * 1.e+6); - - if (AMQP_STATUS_OK != amqp_set_rpc_timeout(resource->connection_state, &rpc_timeout)) { - zend_throw_exception(amqp_connection_exception_class_entry, "Library error: cannot set rpc_timeout", 0 TSRMLS_CC); - return 0; - } + struct timeval rpc_timeout; + + if (timeout == 0.) + return 1; + + rpc_timeout.tv_sec = (int) floor(timeout); + rpc_timeout.tv_usec = (int) ((timeout - floor(timeout)) * 1.e+6); + + if (AMQP_STATUS_OK != amqp_set_rpc_timeout(resource->connection_state, &rpc_timeout)) { + zend_throw_exception( + amqp_connection_exception_class_entry, + "Library error: cannot set rpc_timeout", + 0 TSRMLS_CC + ); + return 0; + } #endif - return 1; + return 1; } int php_amqp_set_resource_write_timeout(amqp_connection_resource *resource, double timeout TSRMLS_DC) { - assert(timeout >= 0.0); + assert(timeout >= 0.0); #ifdef PHP_WIN32 - DWORD write_timeout; + DWORD write_timeout; - if (timeout == 0.) { - write_timeout = 0; - } else { - write_timeout = (int) (max(timeout * 1.e+3 - .5e+3, 1.)); - } + if (timeout == 0.) { + write_timeout = 0; + } else { + write_timeout = (int) (max(timeout * 1.e+3 - .5e+3, 1.)); + } #else - struct timeval write_timeout; - write_timeout.tv_sec = (int) floor(timeout); - write_timeout.tv_usec = (int) ((timeout - floor(timeout)) * 1.e+6); + struct timeval write_timeout; + write_timeout.tv_sec = (int) floor(timeout); + write_timeout.tv_usec = (int) ((timeout - floor(timeout)) * 1.e+6); #endif - if (0 != setsockopt(amqp_get_sockfd(resource->connection_state), SOL_SOCKET, SO_SNDTIMEO, (char *)&write_timeout, sizeof(write_timeout))) { - zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: cannot setsockopt SO_SNDTIMEO", 0 TSRMLS_CC); - return 0; - } - - return 1; + if (0 != setsockopt( + amqp_get_sockfd(resource->connection_state), + SOL_SOCKET, + SO_SNDTIMEO, + (char *) &write_timeout, + sizeof(write_timeout) + )) { + zend_throw_exception( + amqp_connection_exception_class_entry, + "Socket error: cannot setsockopt SO_SNDTIMEO", + 0 TSRMLS_CC + ); + return 0; + } + + return 1; } @@ -361,56 +453,60 @@ int php_amqp_set_resource_write_timeout(amqp_connection_resource *resource, doub amqp_channel_t php_amqp_connection_resource_get_available_channel_id(amqp_connection_resource *resource) { - assert(resource != NULL); - assert(resource->slots != NULL); + assert(resource != NULL); + assert(resource->slots != NULL); - /* Check if there are any open slots */ - if (resource->used_slots >= resource->max_slots) { - return 0; - } + /* Check if there are any open slots */ + if (resource->used_slots >= resource->max_slots) { + return 0; + } - amqp_channel_t slot; + amqp_channel_t slot; - for (slot = 0; slot < resource->max_slots; slot++) { - if (resource->slots[slot] == 0) { - return (amqp_channel_t) (slot + 1); - } - } + for (slot = 0; slot < resource->max_slots; slot++) { + if (resource->slots[slot] == 0) { + return (amqp_channel_t) (slot + 1); + } + } - return 0; + return 0; } -int php_amqp_connection_resource_register_channel(amqp_connection_resource *resource, amqp_channel_resource *channel_resource, amqp_channel_t channel_id) +int php_amqp_connection_resource_register_channel( + amqp_connection_resource *resource, + amqp_channel_resource *channel_resource, + amqp_channel_t channel_id +) { - assert(resource != NULL); - assert(resource->slots != NULL); - assert(channel_id > 0 && channel_id <= resource->max_slots); + assert(resource != NULL); + assert(resource->slots != NULL); + assert(channel_id > 0 && channel_id <= resource->max_slots); - if (resource->slots[channel_id - 1] != 0) { - return FAILURE; - } + if (resource->slots[channel_id - 1] != 0) { + return FAILURE; + } - resource->slots[channel_id - 1] = channel_resource; - channel_resource->connection_resource = resource; - resource->used_slots++; + resource->slots[channel_id - 1] = channel_resource; + channel_resource->connection_resource = resource; + resource->used_slots++; - return SUCCESS; + return SUCCESS; } int php_amqp_connection_resource_unregister_channel(amqp_connection_resource *resource, amqp_channel_t channel_id) { - assert(resource != NULL); - assert(resource->slots != NULL); - assert(channel_id > 0 && channel_id <= resource->max_slots); + assert(resource != NULL); + assert(resource->slots != NULL); + assert(channel_id > 0 && channel_id <= resource->max_slots); - if (resource->slots[channel_id - 1] != 0) { - resource->slots[channel_id - 1]->connection_resource = NULL; + if (resource->slots[channel_id - 1] != 0) { + resource->slots[channel_id - 1]->connection_resource = NULL; - resource->slots[channel_id - 1] = 0; - resource->used_slots--; - } + resource->slots[channel_id - 1] = 0; + resource->used_slots--; + } - return SUCCESS; + return SUCCESS; } @@ -418,165 +514,185 @@ int php_amqp_connection_resource_unregister_channel(amqp_connection_resource *re amqp_connection_resource *connection_resource_constructor(amqp_connection_params *params, zend_bool persistent TSRMLS_DC) { - struct timeval tv = {0}; - 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 custom_properties_entries[2]; - amqp_table_t custom_properties_table; - - amqp_connection_resource *resource; - - /* Allocate space for the connection resource */ - resource = (amqp_connection_resource *)pecalloc(1, sizeof(amqp_connection_resource), persistent); - - /* Create the connection */ - resource->connection_state = amqp_new_connection(); - - /* Create socket object */ - if (params->cacert) { - resource->socket = amqp_ssl_socket_new(resource->connection_state); - - if (!resource->socket) { - zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: could not create SSL socket.", 0 TSRMLS_CC); - - return NULL; - } - } else { - resource->socket = amqp_tcp_socket_new(resource->connection_state); - - if (!resource->socket) { - zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: could not create socket.", 0 TSRMLS_CC); - - return NULL; - } - } - - if (params->cacert && amqp_ssl_socket_set_cacert(resource->socket, params->cacert)) { - zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: could not set CA certificate.", 0 TSRMLS_CC); - - return NULL; - } - - if (params->cacert) { + struct timeval tv = {0}; + 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 custom_properties_entries[2]; + amqp_table_t custom_properties_table; + + amqp_connection_resource *resource; + + /* Allocate space for the connection resource */ + resource = (amqp_connection_resource *) pecalloc(1, sizeof(amqp_connection_resource), persistent); + + /* Create the connection */ + resource->connection_state = amqp_new_connection(); + + /* Create socket object */ + if (params->cacert) { + resource->socket = amqp_ssl_socket_new(resource->connection_state); + + if (!resource->socket) { + zend_throw_exception( + amqp_connection_exception_class_entry, + "Socket error: could not create SSL socket.", + 0 TSRMLS_CC + ); + + return NULL; + } + } else { + resource->socket = amqp_tcp_socket_new(resource->connection_state); + + if (!resource->socket) { + zend_throw_exception( + amqp_connection_exception_class_entry, + "Socket error: could not create socket.", + 0 TSRMLS_CC + ); + + return NULL; + } + } + + if (params->cacert && amqp_ssl_socket_set_cacert(resource->socket, params->cacert)) { + zend_throw_exception( + amqp_connection_exception_class_entry, + "Socket error: could not set CA certificate.", + 0 TSRMLS_CC + ); + + return NULL; + } + + if (params->cacert) { #if AMQP_VERSION_MAJOR * 100 + AMQP_VERSION_MINOR * 10 + AMQP_VERSION_PATCH >= 80 - amqp_ssl_socket_set_verify_peer(resource->socket, params->verify); - amqp_ssl_socket_set_verify_hostname(resource->socket, params->verify); + amqp_ssl_socket_set_verify_peer(resource->socket, params->verify); + amqp_ssl_socket_set_verify_hostname(resource->socket, params->verify); #else - amqp_ssl_socket_set_verify(resource->socket, params->verify); + amqp_ssl_socket_set_verify(resource->socket, params->verify); #endif - } - - if (params->cert && params->key && amqp_ssl_socket_set_key(resource->socket, params->cert, params->key)) { - zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: could not setting client cert.", 0 TSRMLS_CC); + } + + if (params->cert && params->key && amqp_ssl_socket_set_key(resource->socket, params->cert, params->key)) { + zend_throw_exception( + amqp_connection_exception_class_entry, + "Socket error: could not setting client cert.", + 0 TSRMLS_CC + ); - return NULL; - } + return NULL; + } - if (params->connect_timeout > 0) { - tv.tv_sec = (long int) params->connect_timeout; - tv.tv_usec = (long int) ((params->connect_timeout - tv.tv_sec) * 1000000); - } else { - tv_ptr = NULL; - } + if (params->connect_timeout > 0) { + tv.tv_sec = (long int) params->connect_timeout; + tv.tv_usec = (long int) ((params->connect_timeout - tv.tv_sec) * 1000000); + } else { + tv_ptr = NULL; + } - /* Try to connect and verify that no error occurred */ - if (amqp_socket_open_noblock(resource->socket, params->host, params->port, tv_ptr)) { + /* Try to connect and verify that no error occurred */ + if (amqp_socket_open_noblock(resource->socket, params->host, params->port, tv_ptr)) { - zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: could not connect to host.", 0 TSRMLS_CC); + zend_throw_exception( + amqp_connection_exception_class_entry, + "Socket error: could not connect to host.", + 0 TSRMLS_CC + ); - connection_resource_destructor(resource, persistent TSRMLS_CC); + connection_resource_destructor(resource, persistent TSRMLS_CC); - return NULL; - } + return NULL; + } - if (!php_amqp_set_resource_read_timeout(resource, params->read_timeout TSRMLS_CC)) { - connection_resource_destructor(resource, persistent TSRMLS_CC); - return NULL; - } + if (!php_amqp_set_resource_read_timeout(resource, params->read_timeout TSRMLS_CC)) { + connection_resource_destructor(resource, persistent TSRMLS_CC); + return NULL; + } - if (!php_amqp_set_resource_write_timeout(resource, params->write_timeout TSRMLS_CC)) { - connection_resource_destructor(resource, persistent TSRMLS_CC); - return NULL; - } + if (!php_amqp_set_resource_write_timeout(resource, params->write_timeout TSRMLS_CC)) { + connection_resource_destructor(resource, persistent TSRMLS_CC); + return NULL; + } - if (!php_amqp_set_resource_rpc_timeout(resource, params->rpc_timeout TSRMLS_CC)) { - connection_resource_destructor(resource, persistent TSRMLS_CC); - return NULL; - } + if (!php_amqp_set_resource_rpc_timeout(resource, params->rpc_timeout TSRMLS_CC)) { + connection_resource_destructor(resource, persistent TSRMLS_CC); + return NULL; + } - std_datetime = php_std_date(time(NULL) TSRMLS_CC); + std_datetime = php_std_date(time(NULL) TSRMLS_CC); - client_properties_entries[0].key = amqp_cstring_bytes("type"); - client_properties_entries[0].value.kind = AMQP_FIELD_KIND_UTF8; - client_properties_entries[0].value.value.bytes = amqp_cstring_bytes("php-amqp extension"); + client_properties_entries[0].key = amqp_cstring_bytes("type"); + client_properties_entries[0].value.kind = AMQP_FIELD_KIND_UTF8; + client_properties_entries[0].value.value.bytes = amqp_cstring_bytes("php-amqp extension"); - client_properties_entries[1].key = amqp_cstring_bytes("version"); - client_properties_entries[1].value.kind = AMQP_FIELD_KIND_UTF8; - client_properties_entries[1].value.value.bytes = amqp_cstring_bytes(PHP_AMQP_VERSION); + client_properties_entries[1].key = amqp_cstring_bytes("version"); + client_properties_entries[1].value.kind = AMQP_FIELD_KIND_UTF8; + client_properties_entries[1].value.value.bytes = amqp_cstring_bytes(PHP_AMQP_VERSION); - client_properties_entries[2].key = amqp_cstring_bytes("revision"); - client_properties_entries[2].value.kind = AMQP_FIELD_KIND_UTF8; - client_properties_entries[2].value.value.bytes = amqp_cstring_bytes(PHP_AMQP_REVISION); + client_properties_entries[2].key = amqp_cstring_bytes("revision"); + client_properties_entries[2].value.kind = AMQP_FIELD_KIND_UTF8; + client_properties_entries[2].value.value.bytes = amqp_cstring_bytes(PHP_AMQP_REVISION); - client_properties_entries[3].key = amqp_cstring_bytes("connection type"); - client_properties_entries[3].value.kind = AMQP_FIELD_KIND_UTF8; - client_properties_entries[3].value.value.bytes = amqp_cstring_bytes(persistent ? "persistent" : "transient"); + client_properties_entries[3].key = amqp_cstring_bytes("connection type"); + client_properties_entries[3].value.kind = AMQP_FIELD_KIND_UTF8; + client_properties_entries[3].value.value.bytes = amqp_cstring_bytes(persistent ? "persistent" : "transient"); - client_properties_entries[4].key = amqp_cstring_bytes("connection started"); - client_properties_entries[4].value.kind = AMQP_FIELD_KIND_UTF8; - client_properties_entries[4].value.value.bytes = amqp_cstring_bytes(std_datetime); + client_properties_entries[4].key = amqp_cstring_bytes("connection started"); + 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; - custom_properties_entries[0].value.value.table = client_properties_table; + custom_properties_entries[0].key = amqp_cstring_bytes("client"); + custom_properties_entries[0].value.kind = AMQP_FIELD_KIND_TABLE; + custom_properties_entries[0].value.value.table = client_properties_table; - if (params->connection_name) { - custom_properties_entries[1].key = amqp_cstring_bytes("connection_name"); - custom_properties_entries[1].value.kind = AMQP_FIELD_KIND_UTF8; - custom_properties_entries[1].value.value.bytes = amqp_cstring_bytes(params->connection_name); - } + if (params->connection_name) { + custom_properties_entries[1].key = amqp_cstring_bytes("connection_name"); + custom_properties_entries[1].value.kind = AMQP_FIELD_KIND_UTF8; + custom_properties_entries[1].value.value.bytes = amqp_cstring_bytes(params->connection_name); + } - custom_properties_table.entries = custom_properties_entries; - custom_properties_table.num_entries = params->connection_name ? 2 : 1; + custom_properties_table.entries = custom_properties_entries; + custom_properties_table.num_entries = params->connection_name ? 2 : 1; - /* We can assume that connection established here but it is not true, real handshake goes during login */ + /* We can assume that connection established here but it is not true, real handshake goes during login */ - assert(params->frame_max > 0); + assert(params->frame_max > 0); - amqp_rpc_reply_t res = amqp_login_with_properties( - resource->connection_state, - params->vhost, - params->channel_max, - params->frame_max, - params->heartbeat, - &custom_properties_table, - params->sasl_method, - params->login, - params->password - ); + amqp_rpc_reply_t res = amqp_login_with_properties( + resource->connection_state, + params->vhost, + params->channel_max, + params->frame_max, + params->heartbeat, + &custom_properties_table, + params->sasl_method, + params->login, + params->password + ); - efree(std_datetime); + efree(std_datetime); - if (AMQP_RESPONSE_NORMAL != res.reply_type) { - char *message = NULL, *long_message = NULL; + if (AMQP_RESPONSE_NORMAL != res.reply_type) { + char *message = NULL, *long_message = NULL; - php_amqp_connection_resource_error(res, &message, resource, 0 TSRMLS_CC); + 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, PHP_AMQP_G(error_code) TSRMLS_CC); + spprintf(&long_message, 0, "%s - Potential login failure.", message); + zend_throw_exception(amqp_connection_exception_class_entry, long_message, PHP_AMQP_G(error_code) TSRMLS_CC); - efree(message); - efree(long_message); + efree(message); + efree(long_message); - /* https://www.rabbitmq.com/resources/specs/amqp0-9-1.pdf + /* https://www.rabbitmq.com/resources/specs/amqp0-9-1.pdf * * 2.2.4 The Connection Class: * ... a peer that detects an error MUST close the socket without sending any further data. @@ -586,105 +702,105 @@ amqp_connection_resource *connection_resource_constructor(amqp_connection_params * (presumably a thread) for a period of several seconds and then to close the network connection. This * includes syntax errors, over-sized data, and failed attempts to authenticate. */ - connection_resource_destructor(resource, persistent TSRMLS_CC); - return NULL; - } + connection_resource_destructor(resource, persistent TSRMLS_CC); + return NULL; + } - /* Allocate space for the channel slots in the ring buffer */ - resource->max_slots = (amqp_channel_t) amqp_get_channel_max(resource->connection_state); - assert(resource->max_slots > 0); + /* Allocate space for the channel slots in the ring buffer */ + resource->max_slots = (amqp_channel_t) amqp_get_channel_max(resource->connection_state); + assert(resource->max_slots > 0); - resource->slots = (amqp_channel_resource **)pecalloc(resource->max_slots + 1, sizeof(amqp_channel_object*), persistent); + resource->slots = + (amqp_channel_resource **) pecalloc(resource->max_slots + 1, sizeof(amqp_channel_object *), persistent); - resource->is_connected = '\1'; + resource->is_connected = '\1'; - return resource; + return resource; } ZEND_RSRC_DTOR_FUNC(amqp_connection_resource_dtor_persistent) { - amqp_connection_resource *resource = (amqp_connection_resource *)res->ptr; + amqp_connection_resource *resource = (amqp_connection_resource *) res->ptr; - connection_resource_destructor(resource, 1 TSRMLS_CC); + connection_resource_destructor(resource, 1 TSRMLS_CC); } ZEND_RSRC_DTOR_FUNC(amqp_connection_resource_dtor) { - amqp_connection_resource *resource = (amqp_connection_resource *)res->ptr; + amqp_connection_resource *resource = (amqp_connection_resource *) res->ptr; - connection_resource_destructor(resource, 0 TSRMLS_CC); + connection_resource_destructor(resource, 0 TSRMLS_CC); } static void connection_resource_destructor(amqp_connection_resource *resource, int persistent TSRMLS_DC) { - assert(resource != NULL); + assert(resource != NULL); #ifndef PHP_WIN32 - void * old_handler; + void *old_handler; - /* + /* If we are trying to close the connection and the connection already closed, it will throw SIGPIPE, which is fine, so ignore all SIGPIPES */ - /* Start ignoring SIGPIPE */ - old_handler = signal(SIGPIPE, SIG_IGN); + /* Start ignoring SIGPIPE */ + old_handler = signal(SIGPIPE, SIG_IGN); #endif - if (resource->parent) { - resource->parent->connection_resource = NULL; - } + if (resource->parent) { + resource->parent->connection_resource = NULL; + } - if (resource->slots) { - php_amqp_prepare_for_disconnect(resource TSRMLS_CC); + if (resource->slots) { + php_amqp_prepare_for_disconnect(resource TSRMLS_CC); - pefree(resource->slots, persistent); - resource->slots = NULL; - } + pefree(resource->slots, persistent); + resource->slots = NULL; + } - /* connection may be closed in case of previous failure */ - if (resource->is_connected) { - amqp_connection_close(resource->connection_state, AMQP_REPLY_SUCCESS); - } + /* connection may be closed in case of previous failure */ + if (resource->is_connected) { + amqp_connection_close(resource->connection_state, AMQP_REPLY_SUCCESS); + } - amqp_destroy_connection(resource->connection_state); + amqp_destroy_connection(resource->connection_state); #ifndef PHP_WIN32 - /* End ignoring of SIGPIPEs */ - signal(SIGPIPE, old_handler); + /* End ignoring of SIGPIPEs */ + signal(SIGPIPE, old_handler); #endif - pefree(resource, persistent); + pefree(resource, persistent); } void php_amqp_prepare_for_disconnect(amqp_connection_resource *resource TSRMLS_DC) { - if (resource == NULL) { - return; - } + if (resource == NULL) { + return; + } - if(resource->slots != NULL) { - /* NOTE: when we have persistent connection we do not move channels between php requests + if (resource->slots != NULL) { + /* NOTE: when we have persistent connection we do not move channels between php requests * due to current php-amqp extension limitation in AMQPChannel where __construct == channel.open AMQP method call * and __destruct = channel.close AMQP method call */ - /* Clean up old memory allocations which are now invalid (new connection) */ - amqp_channel_t slot; + /* Clean up old memory allocations which are now invalid (new connection) */ + amqp_channel_t slot; - for (slot = 0; slot < resource->max_slots; slot++) { - if (resource->slots[slot] != 0) { - php_amqp_close_channel(resource->slots[slot], 0 TSRMLS_CC); - } - } - } + for (slot = 0; slot < resource->max_slots; slot++) { + if (resource->slots[slot] != 0) { + php_amqp_close_channel(resource->slots[slot], 0 TSRMLS_CC); + } + } + } - /* If it's persistent connection do not destroy connection resource (this keep connection alive) */ - if (resource->is_persistent) { - /* Cleanup buffers to reduce memory usage in idle mode */ - amqp_maybe_release_buffers(resource->connection_state); - } + /* If it's persistent connection do not destroy connection resource (this keep connection alive) */ + if (resource->is_persistent) { + /* Cleanup buffers to reduce memory usage in idle mode */ + amqp_maybe_release_buffers(resource->connection_state); + } - return; + return; } - diff --git a/amqp_connection_resource.h b/amqp_connection_resource.h index 59d424a0..754ba542 100644 --- a/amqp_connection_resource.h +++ b/amqp_connection_resource.h @@ -23,10 +23,10 @@ #ifndef PHP_AMQP_CONNECTION_RESOURCE_H #define PHP_AMQP_CONNECTION_RESOURCE_H -#define PHP_AMQP_RESOURCE_RESPONSE_BREAK 1 -#define PHP_AMQP_RESOURCE_RESPONSE_OK 0 -#define PHP_AMQP_RESOURCE_RESPONSE_ERROR -1 -#define PHP_AMQP_RESOURCE_RESPONSE_ERROR_CHANNEL_CLOSED -2 +#define PHP_AMQP_RESOURCE_RESPONSE_BREAK 1 +#define PHP_AMQP_RESOURCE_RESPONSE_OK 0 +#define PHP_AMQP_RESOURCE_RESPONSE_ERROR -1 +#define PHP_AMQP_RESOURCE_RESPONSE_ERROR_CHANNEL_CLOSED -2 #define PHP_AMQP_RESOURCE_RESPONSE_ERROR_CONNECTION_CLOSED -3 extern int le_amqp_connection_resource; @@ -34,37 +34,48 @@ extern int le_amqp_connection_resource_persistent; #include "php_amqp.h" #if HAVE_LIBRABBITMQ_NEW_LAYOUT -#include + #include #else -#include + #include #endif void php_amqp_prepare_for_disconnect(amqp_connection_resource *resource TSRMLS_DC); typedef struct _amqp_connection_params { - char *login; - char *password; - char *host; - char *vhost; - int port; - int channel_max; - int frame_max; - int heartbeat; - double read_timeout; - double write_timeout; - double connect_timeout; - double rpc_timeout; - char *cacert; - char *cert; - char *key; - int verify; - int sasl_method; - char *connection_name; + char *login; + char *password; + char *host; + char *vhost; + int port; + int channel_max; + int frame_max; + int heartbeat; + double read_timeout; + double write_timeout; + double connect_timeout; + double rpc_timeout; + char *cacert; + char *cert; + char *key; + int verify; + int sasl_method; + char *connection_name; } amqp_connection_params; /* Figure out what's going on connection and handle protocol exceptions, if any */ -int php_amqp_connection_resource_error(amqp_rpc_reply_t reply, char **message, amqp_connection_resource *resource, amqp_channel_t channel_id TSRMLS_DC); -int php_amqp_connection_resource_error_advanced(amqp_rpc_reply_t reply, char **message, amqp_connection_resource *resource, amqp_channel_t channel_id, amqp_channel_object *channel TSRMLS_DC); +int php_amqp_connection_resource_error( + amqp_rpc_reply_t reply, + char **message, + amqp_connection_resource *resource, + amqp_channel_t channel_id TSRMLS_DC +); +int php_amqp_connection_resource_error_advanced( + amqp_rpc_reply_t reply, + char **message, + amqp_connection_resource *resource, + amqp_channel_t channel_id, + amqp_channel_object *channel TSRMLS_DC +); /* Socket-related functions */ int php_amqp_set_resource_read_timeout(amqp_connection_resource *resource, double read_timeout TSRMLS_DC); @@ -76,19 +87,18 @@ int php_amqp_set_resource_rpc_timeout(amqp_connection_resource *resource, double /* Channel-related functions */ amqp_channel_t php_amqp_connection_resource_get_available_channel_id(amqp_connection_resource *resource); int php_amqp_connection_resource_unregister_channel(amqp_connection_resource *resource, amqp_channel_t channel_id); -int php_amqp_connection_resource_register_channel(amqp_connection_resource *resource, amqp_channel_resource *channel_resource, amqp_channel_t channel_id); +int php_amqp_connection_resource_register_channel( + amqp_connection_resource *resource, + amqp_channel_resource *channel_resource, + amqp_channel_t channel_id +); /* Creating and destroying resource */ -amqp_connection_resource *connection_resource_constructor(amqp_connection_params *params, zend_bool persistent TSRMLS_DC); +amqp_connection_resource *connection_resource_constructor( + amqp_connection_params *params, + zend_bool persistent TSRMLS_DC +); ZEND_RSRC_DTOR_FUNC(amqp_connection_resource_dtor_persistent); ZEND_RSRC_DTOR_FUNC(amqp_connection_resource_dtor); #endif -/* -*Local variables: -*tab-width: 4 -*c-basic-offset: 4 -*End: -*vim600: noet sw=4 ts=4 fdm=marker -*vim<600: noet sw=4 ts=4 -*/ diff --git a/amqp_decimal.c b/amqp_decimal.c index 78ad5590..b3750247 100644 --- a/amqp_decimal.c +++ b/amqp_decimal.c @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H -#include "config.h" + #include "config.h" #endif #include "php.h" @@ -43,31 +43,54 @@ static PHP_METHOD(amqp_decimal_class, __construct) { zend_long exponent, significand; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &exponent, &significand) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &exponent, &significand) == FAILURE) { + return; + } - if (exponent < AMQP_DECIMAL_EXPONENT_MIN) { - zend_throw_exception_ex(amqp_value_exception_class_entry, 0 TSRMLS_CC, "Decimal exponent value must be unsigned."); - return; - } + if (exponent < AMQP_DECIMAL_EXPONENT_MIN) { + zend_throw_exception_ex( + amqp_value_exception_class_entry, + 0 TSRMLS_CC, + "Decimal exponent value must be unsigned." + ); + return; + } - if (exponent > AMQP_DECIMAL_EXPONENT_MAX) { - zend_throw_exception_ex(amqp_value_exception_class_entry, 0 TSRMLS_CC, "Decimal exponent value must be less than %u.", (unsigned)AMQP_DECIMAL_EXPONENT_MAX); - return; - } + if (exponent > AMQP_DECIMAL_EXPONENT_MAX) { + zend_throw_exception_ex( + amqp_value_exception_class_entry, + 0 TSRMLS_CC, + "Decimal exponent value must be less than %u.", + (unsigned) AMQP_DECIMAL_EXPONENT_MAX + ); + return; + } if (significand < AMQP_DECIMAL_SIGNIFICAND_MIN) { - zend_throw_exception_ex(amqp_value_exception_class_entry, 0 TSRMLS_CC, "Decimal significand value must be unsigned."); + zend_throw_exception_ex( + amqp_value_exception_class_entry, + 0 TSRMLS_CC, + "Decimal significand value must be unsigned." + ); return; } if (significand > AMQP_DECIMAL_SIGNIFICAND_MAX) { - zend_throw_exception_ex(amqp_value_exception_class_entry, 0 TSRMLS_CC, "Decimal significand value must be less than %u.", (unsigned)AMQP_DECIMAL_SIGNIFICAND_MAX); + zend_throw_exception_ex( + amqp_value_exception_class_entry, + 0 TSRMLS_CC, + "Decimal significand value must be less than %u.", + (unsigned) AMQP_DECIMAL_SIGNIFICAND_MAX + ); return; } zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("exponent"), exponent TSRMLS_CC); - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("significand"), significand TSRMLS_CC); + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("significand"), + significand TSRMLS_CC + ); } /* }}} */ @@ -75,10 +98,10 @@ static PHP_METHOD(amqp_decimal_class, __construct) Get exponent */ static PHP_METHOD(amqp_decimal_class, getExponent) { - zval rv; - PHP_AMQP_NOPARAMS(); + zval rv; + PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("exponent"); + PHP_AMQP_RETURN_THIS_PROP("exponent"); } /* }}} */ @@ -95,8 +118,8 @@ static PHP_METHOD(amqp_decimal_class, getSignificand) ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_decimal_class_construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 2) - ZEND_ARG_INFO(0, exponent) - ZEND_ARG_INFO(0, significand) + ZEND_ARG_INFO(0, exponent) + ZEND_ARG_INFO(0, significand) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_decimal_class_getExponent, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) @@ -111,34 +134,25 @@ zend_function_entry amqp_decimal_class_functions[] = { PHP_ME(amqp_decimal_class, getExponent, arginfo_amqp_decimal_class_getExponent, ZEND_ACC_PUBLIC) PHP_ME(amqp_decimal_class, getSignificand, arginfo_amqp_decimal_class_getSignificand, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} + {NULL, NULL, NULL} }; PHP_MINIT_FUNCTION(amqp_decimal) { - zend_class_entry ce; + zend_class_entry ce; - INIT_CLASS_ENTRY(ce, "AMQPDecimal", amqp_decimal_class_functions); - this_ce = zend_register_internal_class(&ce TSRMLS_CC); - this_ce->ce_flags = this_ce->ce_flags | ZEND_ACC_FINAL; + INIT_CLASS_ENTRY(ce, "AMQPDecimal", amqp_decimal_class_functions); + this_ce = zend_register_internal_class(&ce TSRMLS_CC); + this_ce->ce_flags = this_ce->ce_flags | ZEND_ACC_FINAL; zend_declare_class_constant_long(this_ce, ZEND_STRL("EXPONENT_MIN"), AMQP_DECIMAL_EXPONENT_MIN TSRMLS_CC); zend_declare_class_constant_long(this_ce, ZEND_STRL("EXPONENT_MAX"), AMQP_DECIMAL_EXPONENT_MAX TSRMLS_CC); zend_declare_class_constant_long(this_ce, ZEND_STRL("SIGNIFICAND_MIN"), AMQP_DECIMAL_SIGNIFICAND_MIN TSRMLS_CC); zend_declare_class_constant_long(this_ce, ZEND_STRL("SIGNIFICAND_MAX"), AMQP_DECIMAL_SIGNIFICAND_MAX TSRMLS_CC); - zend_declare_property_long(this_ce, ZEND_STRL("exponent"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_long(this_ce, ZEND_STRL("significand"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_long(this_ce, ZEND_STRL("exponent"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_long(this_ce, ZEND_STRL("significand"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); - return SUCCESS; + return SUCCESS; } - -/* -*Local variables: -*tab-width: 4 -*c-basic-offset: 4 -*End: -*vim600: noet sw=4 ts=4 fdm=marker -*vim<6 -*/ diff --git a/amqp_decimal.h b/amqp_decimal.h index 6c41aa0d..c4c27e5e 100644 --- a/amqp_decimal.h +++ b/amqp_decimal.h @@ -25,12 +25,3 @@ extern zend_class_entry *amqp_decimal_class_entry; PHP_MINIT_FUNCTION(amqp_decimal); - -/* -*Local variables: -*tab-width: 4 -*c-basic-offset: 4 -*End: -*vim600: noet sw=4 ts=4 fdm=marker -*vim<600: noet sw=4 ts=4 -*/ diff --git a/amqp_envelope.c b/amqp_envelope.c index e39d33f1..c5ba803c 100644 --- a/amqp_envelope.c +++ b/amqp_envelope.c @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H -#include "config.h" + #include "config.h" #endif #include "php.h" @@ -30,33 +30,31 @@ #include "zend_exceptions.h" #ifdef PHP_WIN32 -# if PHP_VERSION_ID >= 80000 -# include "main/php_stdint.h" -# else -# include "win32/php_stdint.h" -# endif -# include "win32/signal.h" + #if PHP_VERSION_ID >= 80000 + #include "main/php_stdint.h" + #else + #include "win32/php_stdint.h" + #endif + #include "win32/signal.h" #else -# include -# include + #include + #include #endif #if HAVE_LIBRABBITMQ_NEW_LAYOUT -#include -#include + #include + #include #else -#include -#include + #include + #include #endif #ifdef PHP_WIN32 -# include "win32/unistd.h" + #include "win32/unistd.h" #else - -# include - + #include #endif #include "amqp_envelope.h" @@ -76,19 +74,54 @@ void convert_amqp_envelope_to_zval(amqp_envelope_t *amqp_envelope, zval *envelop amqp_basic_properties_t *p = &amqp_envelope->message.properties; amqp_message_t *message = &amqp_envelope->message; - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(envelope), ZEND_STRL("body"), (const char *) message->body.bytes, (size_t) message->body.len TSRMLS_CC); - - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(envelope), ZEND_STRL("consumer_tag"), (const char *) amqp_envelope->consumer_tag.bytes, (size_t) amqp_envelope->consumer_tag.len TSRMLS_CC); - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(envelope), ZEND_STRL("delivery_tag"), (zend_long) amqp_envelope->delivery_tag TSRMLS_CC); - zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(envelope), ZEND_STRL("is_redelivery"), (zend_long) amqp_envelope->redelivered TSRMLS_CC); - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(envelope), ZEND_STRL("exchange_name"), (const char *) amqp_envelope->exchange.bytes, (size_t) amqp_envelope->exchange.len TSRMLS_CC); - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(envelope), ZEND_STRL("routing_key"), (const char *) amqp_envelope->routing_key.bytes, (size_t) amqp_envelope->routing_key.len TSRMLS_CC); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(envelope), + ZEND_STRL("body"), + (const char *) message->body.bytes, + (size_t) message->body.len TSRMLS_CC + ); + + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(envelope), + ZEND_STRL("consumer_tag"), + (const char *) amqp_envelope->consumer_tag.bytes, + (size_t) amqp_envelope->consumer_tag.len TSRMLS_CC + ); + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(envelope), + ZEND_STRL("delivery_tag"), + (zend_long) amqp_envelope->delivery_tag TSRMLS_CC + ); + zend_update_property_bool( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(envelope), + ZEND_STRL("is_redelivery"), + (zend_long) amqp_envelope->redelivered TSRMLS_CC + ); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(envelope), + ZEND_STRL("exchange_name"), + (const char *) amqp_envelope->exchange.bytes, + (size_t) amqp_envelope->exchange.len TSRMLS_CC + ); + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(envelope), + ZEND_STRL("routing_key"), + (const char *) amqp_envelope->routing_key.bytes, + (size_t) amqp_envelope->routing_key.len TSRMLS_CC + ); php_amqp_basic_properties_extract(p, envelope TSRMLS_CC); } /* {{{ proto AMQPEnvelope::__construct() */ -static PHP_METHOD(amqp_envelope_class, __construct) { +static PHP_METHOD(amqp_envelope_class, __construct) +{ PHP_AMQP_NOPARAMS(); /* BC */ @@ -98,12 +131,13 @@ static PHP_METHOD(amqp_envelope_class, __construct) { /* {{{ proto AMQPEnvelope::getBody()*/ -static PHP_METHOD(amqp_envelope_class, getBody) { +static PHP_METHOD(amqp_envelope_class, getBody) +{ zval rv; PHP_AMQP_NOPARAMS(); - zval* zv = PHP_AMQP_READ_THIS_PROP("body"); + zval *zv = PHP_AMQP_READ_THIS_PROP("body"); if (Z_STRLEN_P(zv) == 0) { /* BC */ @@ -115,7 +149,8 @@ static PHP_METHOD(amqp_envelope_class, getBody) { /* }}} */ /* {{{ proto AMQPEnvelope::getRoutingKey() */ -static PHP_METHOD(amqp_envelope_class, getRoutingKey) { +static PHP_METHOD(amqp_envelope_class, getRoutingKey) +{ zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("routing_key"); @@ -123,7 +158,8 @@ static PHP_METHOD(amqp_envelope_class, getRoutingKey) { /* }}} */ /* {{{ proto AMQPEnvelope::getDeliveryTag() */ -static PHP_METHOD(amqp_envelope_class, getDeliveryTag) { +static PHP_METHOD(amqp_envelope_class, getDeliveryTag) +{ zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("delivery_tag"); @@ -131,7 +167,8 @@ static PHP_METHOD(amqp_envelope_class, getDeliveryTag) { /* }}} */ /* {{{ proto AMQPEnvelope::getConsumerTag() */ -static PHP_METHOD(amqp_envelope_class, getConsumerTag) { +static PHP_METHOD(amqp_envelope_class, getConsumerTag) +{ zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("consumer_tag"); @@ -139,7 +176,8 @@ static PHP_METHOD(amqp_envelope_class, getConsumerTag) { /* }}} */ /* {{{ proto AMQPEnvelope::getExchangeName() */ -static PHP_METHOD(amqp_envelope_class, getExchangeName) { +static PHP_METHOD(amqp_envelope_class, getExchangeName) +{ zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("exchange_name"); @@ -147,7 +185,8 @@ static PHP_METHOD(amqp_envelope_class, getExchangeName) { /* }}} */ /* {{{ proto AMQPEnvelope::isRedelivery() */ -static PHP_METHOD(amqp_envelope_class, isRedelivery) { +static PHP_METHOD(amqp_envelope_class, isRedelivery) +{ zval rv; PHP_AMQP_NOPARAMS(); PHP_AMQP_RETURN_THIS_PROP("is_redelivery"); @@ -156,18 +195,19 @@ static PHP_METHOD(amqp_envelope_class, isRedelivery) { /* {{{ proto AMQPEnvelope::getHeader(string name) */ -static PHP_METHOD(amqp_envelope_class, getHeader) { +static PHP_METHOD(amqp_envelope_class, getHeader) +{ zval rv; - char *key; - size_t key_len; + char *key; + size_t key_len; zval *tmp = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { return; } - zval* zv = PHP_AMQP_READ_THIS_PROP_CE("headers", amqp_basic_properties_class_entry); + zval *zv = PHP_AMQP_READ_THIS_PROP_CE("headers", amqp_basic_properties_class_entry); /* Look for the hash key */ if ((tmp = zend_hash_str_find(HASH_OF(zv), key, key_len)) == NULL) { @@ -180,20 +220,21 @@ static PHP_METHOD(amqp_envelope_class, getHeader) { /* {{{ proto AMQPEnvelope::hasHeader(string name) */ -static PHP_METHOD(amqp_envelope_class, hasHeader) { +static PHP_METHOD(amqp_envelope_class, hasHeader) +{ zval rv; - char *key; - size_t key_len; + char *key; + size_t key_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { return; } - zval* zv = PHP_AMQP_READ_THIS_PROP_CE("headers", amqp_basic_properties_class_entry); + zval *zv = PHP_AMQP_READ_THIS_PROP_CE("headers", amqp_basic_properties_class_entry); /* Look for the hash key */ - if (zend_hash_str_find(HASH_OF(zv), key, key_len) == NULL) { + if (zend_hash_str_find(HASH_OF(zv), key, key_len) == NULL) { RETURN_FALSE; } @@ -225,33 +266,34 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_isRedelivery, ZEND_SEND_BY_VA ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_getHeader, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, name) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_hasHeader, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, name) ZEND_END_ARG_INFO() zend_function_entry amqp_envelope_class_functions[] = { - PHP_ME(amqp_envelope_class, __construct, arginfo_amqp_envelope_class__construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) + PHP_ME(amqp_envelope_class, __construct, arginfo_amqp_envelope_class__construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) - PHP_ME(amqp_envelope_class, getBody, arginfo_amqp_envelope_class_getBody, ZEND_ACC_PUBLIC) + PHP_ME(amqp_envelope_class, getBody, arginfo_amqp_envelope_class_getBody, ZEND_ACC_PUBLIC) - PHP_ME(amqp_envelope_class, getRoutingKey, arginfo_amqp_envelope_class_getRoutingKey, ZEND_ACC_PUBLIC) - PHP_ME(amqp_envelope_class, getConsumerTag, arginfo_amqp_envelope_class_getConsumerTag, ZEND_ACC_PUBLIC) - PHP_ME(amqp_envelope_class, getDeliveryTag, arginfo_amqp_envelope_class_getDeliveryTag, ZEND_ACC_PUBLIC) - PHP_ME(amqp_envelope_class, getExchangeName, arginfo_amqp_envelope_class_getExchangeName, ZEND_ACC_PUBLIC) - PHP_ME(amqp_envelope_class, isRedelivery, arginfo_amqp_envelope_class_isRedelivery, ZEND_ACC_PUBLIC) + PHP_ME(amqp_envelope_class, getRoutingKey, arginfo_amqp_envelope_class_getRoutingKey, ZEND_ACC_PUBLIC) + PHP_ME(amqp_envelope_class, getConsumerTag, arginfo_amqp_envelope_class_getConsumerTag, ZEND_ACC_PUBLIC) + PHP_ME(amqp_envelope_class, getDeliveryTag, arginfo_amqp_envelope_class_getDeliveryTag, ZEND_ACC_PUBLIC) + PHP_ME(amqp_envelope_class, getExchangeName, arginfo_amqp_envelope_class_getExchangeName, ZEND_ACC_PUBLIC) + PHP_ME(amqp_envelope_class, isRedelivery, arginfo_amqp_envelope_class_isRedelivery, ZEND_ACC_PUBLIC) - PHP_ME(amqp_envelope_class, getHeader, arginfo_amqp_envelope_class_getHeader, ZEND_ACC_PUBLIC) - PHP_ME(amqp_envelope_class, hasHeader, arginfo_amqp_envelope_class_hasHeader, ZEND_ACC_PUBLIC) + PHP_ME(amqp_envelope_class, getHeader, arginfo_amqp_envelope_class_getHeader, ZEND_ACC_PUBLIC) + PHP_ME(amqp_envelope_class, hasHeader, arginfo_amqp_envelope_class_hasHeader, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} + {NULL, NULL, NULL} }; -PHP_MINIT_FUNCTION (amqp_envelope) { +PHP_MINIT_FUNCTION(amqp_envelope) +{ zend_class_entry ce; INIT_CLASS_ENTRY(ce, "AMQPEnvelope", amqp_envelope_class_functions); @@ -267,13 +309,3 @@ PHP_MINIT_FUNCTION (amqp_envelope) { 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 -*/ diff --git a/amqp_envelope.h b/amqp_envelope.h index 792c5854..c8adb94c 100644 --- a/amqp_envelope.h +++ b/amqp_envelope.h @@ -28,13 +28,3 @@ extern zend_class_entry *amqp_envelope_class_entry; void convert_amqp_envelope_to_zval(amqp_envelope_t *amqp_envelope, zval *envelope TSRMLS_DC); PHP_MINIT_FUNCTION(amqp_envelope); - - -/* -*Local variables: -*tab-width: 4 -*c-basic-offset: 4 -*End: -*vim600: noet sw=4 ts=4 fdm=marker -*vim<600: noet sw=4 ts=4 -*/ diff --git a/amqp_exchange.c b/amqp_exchange.c index 55ac28b2..1654c43c 100644 --- a/amqp_exchange.c +++ b/amqp_exchange.c @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H -#include "config.h" + #include "config.h" #endif #include "php.h" @@ -30,28 +30,28 @@ #include "zend_exceptions.h" #ifdef PHP_WIN32 -# if PHP_VERSION_ID >= 80000 -# include "main/php_stdint.h" -# else -# include "win32/php_stdint.h" -# endif -# include "win32/signal.h" + #if PHP_VERSION_ID >= 80000 + #include "main/php_stdint.h" + #else + #include "win32/php_stdint.h" + #endif + #include "win32/signal.h" #else -# include -# include + #include + #include #endif #if HAVE_LIBRABBITMQ_NEW_LAYOUT -#include -#include + #include + #include #else -#include -#include + #include + #include #endif #ifdef PHP_WIN32 -# include "win32/unistd.h" + #include "win32/unistd.h" #else -# include + #include #endif #include "php_amqp.h" @@ -67,27 +67,32 @@ zend_class_entry *amqp_exchange_class_entry; create Exchange */ static PHP_METHOD(amqp_exchange_class, __construct) { - zval rv; + zval rv; - zval arguments; + zval arguments; - zval *channelObj; - amqp_channel_resource *channel_resource; + zval *channelObj; + amqp_channel_resource *channel_resource; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &channelObj, amqp_channel_class_entry) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &channelObj, amqp_channel_class_entry) == FAILURE) { + return; + } - ZVAL_UNDEF(&arguments); - array_init(&arguments); - zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("arguments"), &arguments TSRMLS_CC); - zval_ptr_dtor(&arguments); + ZVAL_UNDEF(&arguments); + array_init(&arguments); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("arguments"), &arguments TSRMLS_CC); + zval_ptr_dtor(&arguments); - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(channelObj); - PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not create exchange."); + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(channelObj); + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not create exchange."); - zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("channel"), channelObj TSRMLS_CC); - zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connection"), PHP_AMQP_READ_OBJ_PROP(amqp_channel_class_entry, channelObj, "connection") TSRMLS_CC); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("channel"), channelObj TSRMLS_CC); + zend_update_property( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("connection"), + PHP_AMQP_READ_OBJ_PROP(amqp_channel_class_entry, channelObj, "connection") TSRMLS_CC + ); } /* }}} */ @@ -96,16 +101,16 @@ static PHP_METHOD(amqp_exchange_class, __construct) Get the exchange name */ static PHP_METHOD(amqp_exchange_class, getName) { - zval rv; + zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS(); - if (PHP_AMQP_READ_THIS_PROP_STRLEN("name") > 0) { - PHP_AMQP_RETURN_THIS_PROP("name"); - } else { - /* BC */ - RETURN_FALSE; - } + if (PHP_AMQP_READ_THIS_PROP_STRLEN("name") > 0) { + PHP_AMQP_RETURN_THIS_PROP("name"); + } else { + /* BC */ + RETURN_FALSE; + } } /* }}} */ @@ -114,21 +119,25 @@ static PHP_METHOD(amqp_exchange_class, getName) Set the exchange name */ static PHP_METHOD(amqp_exchange_class, setName) { - char *name = NULL; - size_t name_len = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { - return; - } - - /* Verify that the name is not null and not an empty string */ - if (name_len > 255) { - zend_throw_exception(amqp_exchange_exception_class_entry, "Invalid exchange name given, must be less than 255 characters long.", 0 TSRMLS_CC); - return; - } - - /* Set the exchange name */ - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("name"), name, name_len TSRMLS_CC); + char *name = NULL; + size_t name_len = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { + return; + } + + /* Verify that the name is not null and not an empty string */ + if (name_len > 255) { + zend_throw_exception( + amqp_exchange_exception_class_entry, + "Invalid exchange name given, must be less than 255 characters long.", + 0 TSRMLS_CC + ); + return; + } + + /* Set the exchange name */ + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("name"), name, name_len TSRMLS_CC); } /* }}} */ @@ -137,29 +146,29 @@ static PHP_METHOD(amqp_exchange_class, setName) Get the exchange parameters */ static PHP_METHOD(amqp_exchange_class, getFlags) { - zval rv; + zval rv; - zend_long flags = AMQP_NOPARAM; + zend_long flags = AMQP_NOPARAM; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS(); - if (PHP_AMQP_READ_THIS_PROP_BOOL("passive")) { - flags |= AMQP_PASSIVE; - } + if (PHP_AMQP_READ_THIS_PROP_BOOL("passive")) { + flags |= AMQP_PASSIVE; + } - if (PHP_AMQP_READ_THIS_PROP_BOOL("durable")) { - flags |= AMQP_DURABLE; - } + if (PHP_AMQP_READ_THIS_PROP_BOOL("durable")) { + flags |= AMQP_DURABLE; + } - if (PHP_AMQP_READ_THIS_PROP_BOOL("auto_delete")) { - flags |= AMQP_AUTODELETE; - } + if (PHP_AMQP_READ_THIS_PROP_BOOL("auto_delete")) { + flags |= AMQP_AUTODELETE; + } - if (PHP_AMQP_READ_THIS_PROP_BOOL("internal")) { - flags |= AMQP_INTERNAL; - } + if (PHP_AMQP_READ_THIS_PROP_BOOL("internal")) { + flags |= AMQP_INTERNAL; + } - RETURN_LONG(flags); + RETURN_LONG(flags); } /* }}} */ @@ -168,20 +177,40 @@ static PHP_METHOD(amqp_exchange_class, getFlags) Set the exchange parameters */ static PHP_METHOD(amqp_exchange_class, setFlags) { - zend_long flags = AMQP_NOPARAM; - zend_bool flags_is_null = 1; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l!", &flags, &flags_is_null) == FAILURE) { - return; - } - - /* Set the flags based on the bitmask we were given */ - flags = flags ? flags & PHP_AMQP_EXCHANGE_FLAGS : flags; - - zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("passive"), IS_PASSIVE(flags) TSRMLS_CC); - zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("durable"), IS_DURABLE(flags) TSRMLS_CC); - zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("auto_delete"), IS_AUTODELETE(flags) TSRMLS_CC); - zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("internal"), IS_INTERNAL(flags) TSRMLS_CC); + zend_long flags = AMQP_NOPARAM; + zend_bool flags_is_null = 1; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l!", &flags, &flags_is_null) == FAILURE) { + return; + } + + /* Set the flags based on the bitmask we were given */ + flags = flags ? flags & PHP_AMQP_EXCHANGE_FLAGS : flags; + + zend_update_property_bool( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("passive"), + IS_PASSIVE(flags) TSRMLS_CC + ); + zend_update_property_bool( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("durable"), + IS_DURABLE(flags) TSRMLS_CC + ); + zend_update_property_bool( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("auto_delete"), + IS_AUTODELETE(flags) TSRMLS_CC + ); + zend_update_property_bool( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("internal"), + IS_INTERNAL(flags) TSRMLS_CC + ); } /* }}} */ @@ -190,16 +219,16 @@ static PHP_METHOD(amqp_exchange_class, setFlags) Get the exchange type */ static PHP_METHOD(amqp_exchange_class, getType) { - zval rv; + zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS(); - if (PHP_AMQP_READ_THIS_PROP_STRLEN("type") > 0) { - PHP_AMQP_RETURN_THIS_PROP("type"); - } else { - /* BC */ - RETURN_FALSE; - } + if (PHP_AMQP_READ_THIS_PROP_STRLEN("type") > 0) { + PHP_AMQP_RETURN_THIS_PROP("type"); + } else { + /* BC */ + RETURN_FALSE; + } } /* }}} */ @@ -208,13 +237,14 @@ static PHP_METHOD(amqp_exchange_class, getType) Set the exchange type */ static PHP_METHOD(amqp_exchange_class, setType) { - char *type = NULL; size_t type_len = 0; + char *type = NULL; + size_t type_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &type, &type_len) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &type, &type_len) == FAILURE) { + return; + } - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("type"), type, type_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("type"), type, type_len TSRMLS_CC); } /* }}} */ @@ -223,41 +253,42 @@ static PHP_METHOD(amqp_exchange_class, setType) Get the exchange argument referenced by key */ static PHP_METHOD(amqp_exchange_class, getArgument) { - zval rv; + zval rv; - zval *tmp = NULL; + zval *tmp = NULL; - char *key; size_t key_len; + char *key; + size_t key_len; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { + return; + } - if ((tmp = zend_hash_str_find(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len)) == NULL) { - RETURN_FALSE; - } + if ((tmp = zend_hash_str_find(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len)) == NULL) { + RETURN_FALSE; + } - RETURN_ZVAL(tmp, 1, 0); + RETURN_ZVAL(tmp, 1, 0); } /* }}} */ /* {{{ proto AMQPExchange::hasArgument(string key) */ static PHP_METHOD(amqp_exchange_class, hasArgument) { - zval rv; - zval *tmp = NULL; - char *key; - size_t key_len; + zval rv; + zval *tmp = NULL; + char *key; + size_t key_len; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { + return; + } - if ((tmp = zend_hash_str_find(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len)) == NULL) { - RETURN_FALSE; - } + if ((tmp = zend_hash_str_find(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len)) == NULL) { + RETURN_FALSE; + } - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -265,9 +296,9 @@ static PHP_METHOD(amqp_exchange_class, hasArgument) Get the exchange arguments */ static PHP_METHOD(amqp_exchange_class, getArguments) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("arguments"); + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("arguments"); } /* }}} */ @@ -276,15 +307,15 @@ static PHP_METHOD(amqp_exchange_class, getArguments) Overwrite all exchange arguments with given args */ static PHP_METHOD(amqp_exchange_class, setArguments) { - zval *zvalArguments; + zval *zvalArguments; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &zvalArguments) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &zvalArguments) == FAILURE) { + return; + } - zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("arguments"), zvalArguments TSRMLS_CC); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("arguments"), zvalArguments TSRMLS_CC); - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -292,35 +323,38 @@ static PHP_METHOD(amqp_exchange_class, setArguments) /* {{{ proto AMQPExchange::setArgument(key, value) */ static PHP_METHOD(amqp_exchange_class, setArgument) { - zval rv; - - char *key= NULL; size_t key_len = 0; - zval *value = NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", - &key, &key_len, - &value) == FAILURE) { - return; - } - - switch (Z_TYPE_P(value)) { - case IS_NULL: - zend_hash_str_del_ind(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len); - break; - case IS_TRUE: - case IS_FALSE: - case IS_LONG: - case IS_DOUBLE: - case IS_STRING: - zend_hash_str_add(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len, value); - Z_TRY_ADDREF_P(value); - break; - default: - zend_throw_exception(amqp_exchange_exception_class_entry, "The value parameter must be of type NULL, int, double or string.", 0 TSRMLS_CC); - return; - } - - RETURN_TRUE; + zval rv; + + char *key = NULL; + size_t key_len = 0; + zval *value = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &key, &key_len, &value) == FAILURE) { + return; + } + + switch (Z_TYPE_P(value)) { + case IS_NULL: + zend_hash_str_del_ind(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len); + break; + case IS_TRUE: + case IS_FALSE: + case IS_LONG: + case IS_DOUBLE: + case IS_STRING: + zend_hash_str_add(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len, value); + Z_TRY_ADDREF_P(value); + break; + default: + zend_throw_exception( + amqp_exchange_exception_class_entry, + "The value parameter must be of type NULL, int, double or string.", + 0 TSRMLS_CC + ); + return; + } + + RETURN_TRUE; } /* }}} */ @@ -330,55 +364,63 @@ declare Exchange */ static PHP_METHOD(amqp_exchange_class, declareExchange) { - zval rv; - - amqp_channel_resource *channel_resource; - amqp_table_t *arguments; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); - PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not declare exchange."); - - /* Check that the exchange has a name */ - if (PHP_AMQP_READ_THIS_PROP_STRLEN("name") < 1) { - zend_throw_exception(amqp_exchange_exception_class_entry, "Could not declare exchange. Exchanges must have a name.", 0 TSRMLS_CC); - return; - } - - /* Check that the exchange has a name */ - if (PHP_AMQP_READ_THIS_PROP_STRLEN("type") < 1) { - zend_throw_exception(amqp_exchange_exception_class_entry, "Could not declare exchange. Exchanges must have a type.", 0 TSRMLS_CC); - return; - } - - arguments = php_amqp_type_convert_zval_to_amqp_table(PHP_AMQP_READ_THIS_PROP("arguments") TSRMLS_CC); - - amqp_exchange_declare( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), - amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("type")), - PHP_AMQP_READ_THIS_PROP_BOOL("passive"), - PHP_AMQP_READ_THIS_PROP_BOOL("durable"), - PHP_AMQP_READ_THIS_PROP_BOOL("auto_delete"), - PHP_AMQP_READ_THIS_PROP_BOOL("internal"), - *arguments - ); - - amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - - php_amqp_type_free_amqp_table(arguments); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_exchange_exception_class_entry TSRMLS_CC); - return; - } - - RETURN_TRUE; + zval rv; + + amqp_channel_resource *channel_resource; + amqp_table_t *arguments; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not declare exchange."); + + /* Check that the exchange has a name */ + if (PHP_AMQP_READ_THIS_PROP_STRLEN("name") < 1) { + zend_throw_exception( + amqp_exchange_exception_class_entry, + "Could not declare exchange. Exchanges must have a name.", + 0 TSRMLS_CC + ); + return; + } + + /* Check that the exchange has a name */ + if (PHP_AMQP_READ_THIS_PROP_STRLEN("type") < 1) { + zend_throw_exception( + amqp_exchange_exception_class_entry, + "Could not declare exchange. Exchanges must have a type.", + 0 TSRMLS_CC + ); + return; + } + + arguments = php_amqp_type_convert_zval_to_amqp_table(PHP_AMQP_READ_THIS_PROP("arguments") TSRMLS_CC); + + amqp_exchange_declare( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), + amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("type")), + PHP_AMQP_READ_THIS_PROP_BOOL("passive"), + PHP_AMQP_READ_THIS_PROP_BOOL("durable"), + PHP_AMQP_READ_THIS_PROP_BOOL("auto_delete"), + PHP_AMQP_READ_THIS_PROP_BOOL("internal"), + *arguments + ); + + amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + + php_amqp_type_free_amqp_table(arguments); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + php_amqp_zend_throw_exception_short(res, amqp_exchange_exception_class_entry TSRMLS_CC); + return; + } + + RETURN_TRUE; } /* }}} */ @@ -388,41 +430,39 @@ delete Exchange */ static PHP_METHOD(amqp_exchange_class, delete) { - zval rv; + zval rv; - amqp_channel_resource *channel_resource; + amqp_channel_resource *channel_resource; - char *name = NULL; - size_t name_len = 0; - zend_long flags = AMQP_NOPARAM; + char *name = NULL; + size_t name_len = 0; + zend_long flags = AMQP_NOPARAM; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sl", - &name, &name_len, - &flags) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sl", &name, &name_len, &flags) == FAILURE) { + return; + } - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); - PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not delete exchange."); + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not delete exchange."); - amqp_exchange_delete( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - amqp_cstring_bytes(name_len ? name : PHP_AMQP_READ_THIS_PROP_STR("name")), - (AMQP_IFUNUSED & flags) ? 1 : 0 - ); + amqp_exchange_delete( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + amqp_cstring_bytes(name_len ? name : PHP_AMQP_READ_THIS_PROP_STR("name")), + (AMQP_IFUNUSED & flags) ? 1 : 0 + ); - amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_exchange_exception_class_entry TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + php_amqp_zend_throw_exception_short(res, amqp_exchange_exception_class_entry TSRMLS_CC); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -432,213 +472,233 @@ publish into Exchange */ static PHP_METHOD(amqp_exchange_class, publish) { - zval rv; + zval rv; - zval *ini_arr = NULL; - zval *tmp = NULL; + zval *ini_arr = NULL; + zval *tmp = NULL; - amqp_channel_resource *channel_resource; + amqp_channel_resource *channel_resource; - char *key_name = NULL; - size_t key_len = 0; - char *msg = NULL; - size_t msg_len = 0; - zend_long flags = AMQP_NOPARAM; + char *key_name = NULL; + size_t key_len = 0; + char *msg = NULL; + size_t msg_len = 0; + zend_long flags = AMQP_NOPARAM; #ifndef PHP_WIN32 - /* Storage for previous signal handler during SIGPIPE override */ - void * old_handler; + /* Storage for previous signal handler during SIGPIPE override */ + void *old_handler; #endif - amqp_basic_properties_t props; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!la/", - &msg, &msg_len, - &key_name, &key_len, - &flags, - &ini_arr) == FAILURE) { - return; - } - - /* By default (and for BC) content type is text/plain (may be skipped at all, then set props._flags to 0) */ - props.content_type = amqp_cstring_bytes("text/plain"); - props._flags = AMQP_BASIC_CONTENT_TYPE_FLAG; - - props.headers.entries = 0; - - { - if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "content_type", sizeof("content_type") - 1)) != NULL) { - SEPARATE_ZVAL(tmp); - convert_to_string(tmp); - - if (Z_STRLEN_P(tmp) > 0) { - props.content_type = amqp_cstring_bytes(Z_STRVAL_P(tmp)); - props._flags |= AMQP_BASIC_CONTENT_TYPE_FLAG; - } - } - - if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "content_encoding", sizeof("content_encoding") - 1)) != NULL) { - SEPARATE_ZVAL(tmp); - convert_to_string(tmp); - - if (Z_STRLEN_P(tmp) > 0) { - props.content_encoding = amqp_cstring_bytes(Z_STRVAL_P(tmp)); - props._flags |= AMQP_BASIC_CONTENT_ENCODING_FLAG; - } - } - - if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "message_id", sizeof("message_id") - 1)) != NULL) { - SEPARATE_ZVAL(tmp); - convert_to_string(tmp); - - if (Z_STRLEN_P(tmp) > 0) { - props.message_id = amqp_cstring_bytes(Z_STRVAL_P(tmp)); - props._flags |= AMQP_BASIC_MESSAGE_ID_FLAG; - } - } - - if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "user_id", sizeof("user_id") - 1)) != NULL) { - SEPARATE_ZVAL(tmp); - convert_to_string(tmp); - - if (Z_STRLEN_P(tmp) > 0) { - props.user_id = amqp_cstring_bytes(Z_STRVAL_P(tmp)); - props._flags |= AMQP_BASIC_USER_ID_FLAG; - } - } - - if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "app_id", sizeof("app_id") - 1)) != NULL) { - SEPARATE_ZVAL(tmp); - convert_to_string(tmp); - - if (Z_STRLEN_P(tmp) > 0) { - props.app_id = amqp_cstring_bytes(Z_STRVAL_P(tmp)); - props._flags |= AMQP_BASIC_APP_ID_FLAG; - } - } - - if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "delivery_mode", sizeof("delivery_mode") - 1)) != NULL) { - SEPARATE_ZVAL(tmp); - convert_to_long(tmp); - - props.delivery_mode = (uint8_t)Z_LVAL_P(tmp); - props._flags |= AMQP_BASIC_DELIVERY_MODE_FLAG; - } - - if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "priority", sizeof("priority") - 1)) != NULL) { - SEPARATE_ZVAL(tmp); - convert_to_long(tmp); - - props.priority = (uint8_t)Z_LVAL_P(tmp); - props._flags |= AMQP_BASIC_PRIORITY_FLAG; - } - - if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "timestamp", sizeof("timestamp") - 1)) != NULL) { - SEPARATE_ZVAL(tmp); - convert_to_long(tmp); - - props.timestamp = (uint64_t)Z_LVAL_P(tmp); - props._flags |= AMQP_BASIC_TIMESTAMP_FLAG; - } - - if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "expiration", sizeof("expiration") - 1)) != NULL) { - SEPARATE_ZVAL(tmp); - convert_to_string(tmp); - - if (Z_STRLEN_P(tmp) > 0) { - props.expiration = amqp_cstring_bytes(Z_STRVAL_P(tmp)); - props._flags |= AMQP_BASIC_EXPIRATION_FLAG; - } - } - - if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "type", sizeof("type") - 1)) != NULL) { - SEPARATE_ZVAL(tmp); - convert_to_string(tmp); - - if (Z_STRLEN_P(tmp) > 0) { - props.type = amqp_cstring_bytes(Z_STRVAL_P(tmp)); - props._flags |= AMQP_BASIC_TYPE_FLAG; - } - } - - if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "reply_to", sizeof("reply_to") - 1)) != NULL) { - SEPARATE_ZVAL(tmp); - convert_to_string(tmp); - - if (Z_STRLEN_P(tmp) > 0) { - props.reply_to = amqp_cstring_bytes(Z_STRVAL_P(tmp)); - props._flags |= AMQP_BASIC_REPLY_TO_FLAG; - } - } - if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "correlation_id", sizeof("correlation_id") - 1)) != NULL) { - SEPARATE_ZVAL(tmp); - convert_to_string(tmp); - - if (Z_STRLEN_P(tmp) > 0) { - props.correlation_id = amqp_cstring_bytes(Z_STRVAL_P(tmp)); - props._flags |= AMQP_BASIC_CORRELATION_ID_FLAG; - } - } - - } - - amqp_table_t *headers = NULL; - - if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "headers", sizeof("headers") - 1)) != NULL) { - SEPARATE_ZVAL(tmp); - convert_to_array(tmp); - - headers = php_amqp_type_convert_zval_to_amqp_table(tmp TSRMLS_CC); - - props._flags |= AMQP_BASIC_HEADERS_FLAG; - props.headers = *headers; - } - - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); - PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not publish to exchange."); + amqp_basic_properties_t props; + + if (zend_parse_parameters( + ZEND_NUM_ARGS() TSRMLS_CC, + "s|s!la/", + &msg, + &msg_len, + &key_name, + &key_len, + &flags, + &ini_arr + ) == FAILURE) { + return; + } + + /* By default (and for BC) content type is text/plain (may be skipped at all, then set props._flags to 0) */ + props.content_type = amqp_cstring_bytes("text/plain"); + props._flags = AMQP_BASIC_CONTENT_TYPE_FLAG; + + props.headers.entries = 0; + + { + if (ini_arr && + (tmp = zend_hash_str_find(HASH_OF(ini_arr), "content_type", sizeof("content_type") - 1)) != NULL) { + SEPARATE_ZVAL(tmp); + convert_to_string(tmp); + + if (Z_STRLEN_P(tmp) > 0) { + props.content_type = amqp_cstring_bytes(Z_STRVAL_P(tmp)); + props._flags |= AMQP_BASIC_CONTENT_TYPE_FLAG; + } + } + + if (ini_arr && + (tmp = zend_hash_str_find(HASH_OF(ini_arr), "content_encoding", sizeof("content_encoding") - 1)) != NULL) { + SEPARATE_ZVAL(tmp); + convert_to_string(tmp); + + if (Z_STRLEN_P(tmp) > 0) { + props.content_encoding = amqp_cstring_bytes(Z_STRVAL_P(tmp)); + props._flags |= AMQP_BASIC_CONTENT_ENCODING_FLAG; + } + } + + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "message_id", sizeof("message_id") - 1)) != NULL) { + SEPARATE_ZVAL(tmp); + convert_to_string(tmp); + + if (Z_STRLEN_P(tmp) > 0) { + props.message_id = amqp_cstring_bytes(Z_STRVAL_P(tmp)); + props._flags |= AMQP_BASIC_MESSAGE_ID_FLAG; + } + } + + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "user_id", sizeof("user_id") - 1)) != NULL) { + SEPARATE_ZVAL(tmp); + convert_to_string(tmp); + + if (Z_STRLEN_P(tmp) > 0) { + props.user_id = amqp_cstring_bytes(Z_STRVAL_P(tmp)); + props._flags |= AMQP_BASIC_USER_ID_FLAG; + } + } + + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "app_id", sizeof("app_id") - 1)) != NULL) { + SEPARATE_ZVAL(tmp); + convert_to_string(tmp); + + if (Z_STRLEN_P(tmp) > 0) { + props.app_id = amqp_cstring_bytes(Z_STRVAL_P(tmp)); + props._flags |= AMQP_BASIC_APP_ID_FLAG; + } + } + + if (ini_arr && + (tmp = zend_hash_str_find(HASH_OF(ini_arr), "delivery_mode", sizeof("delivery_mode") - 1)) != NULL) { + SEPARATE_ZVAL(tmp); + convert_to_long(tmp); + + props.delivery_mode = (uint8_t) Z_LVAL_P(tmp); + props._flags |= AMQP_BASIC_DELIVERY_MODE_FLAG; + } + + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "priority", sizeof("priority") - 1)) != NULL) { + SEPARATE_ZVAL(tmp); + convert_to_long(tmp); + + props.priority = (uint8_t) Z_LVAL_P(tmp); + props._flags |= AMQP_BASIC_PRIORITY_FLAG; + } + + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "timestamp", sizeof("timestamp") - 1)) != NULL) { + SEPARATE_ZVAL(tmp); + convert_to_long(tmp); + + props.timestamp = (uint64_t) Z_LVAL_P(tmp); + props._flags |= AMQP_BASIC_TIMESTAMP_FLAG; + } + + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "expiration", sizeof("expiration") - 1)) != NULL) { + SEPARATE_ZVAL(tmp); + convert_to_string(tmp); + + if (Z_STRLEN_P(tmp) > 0) { + props.expiration = amqp_cstring_bytes(Z_STRVAL_P(tmp)); + props._flags |= AMQP_BASIC_EXPIRATION_FLAG; + } + } + + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "type", sizeof("type") - 1)) != NULL) { + SEPARATE_ZVAL(tmp); + convert_to_string(tmp); + + if (Z_STRLEN_P(tmp) > 0) { + props.type = amqp_cstring_bytes(Z_STRVAL_P(tmp)); + props._flags |= AMQP_BASIC_TYPE_FLAG; + } + } + + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "reply_to", sizeof("reply_to") - 1)) != NULL) { + SEPARATE_ZVAL(tmp); + convert_to_string(tmp); + + if (Z_STRLEN_P(tmp) > 0) { + props.reply_to = amqp_cstring_bytes(Z_STRVAL_P(tmp)); + props._flags |= AMQP_BASIC_REPLY_TO_FLAG; + } + } + if (ini_arr && + (tmp = zend_hash_str_find(HASH_OF(ini_arr), "correlation_id", sizeof("correlation_id") - 1)) != NULL) { + SEPARATE_ZVAL(tmp); + convert_to_string(tmp); + + if (Z_STRLEN_P(tmp) > 0) { + props.correlation_id = amqp_cstring_bytes(Z_STRVAL_P(tmp)); + props._flags |= AMQP_BASIC_CORRELATION_ID_FLAG; + } + } + } + + amqp_table_t *headers = NULL; + + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "headers", sizeof("headers") - 1)) != NULL) { + SEPARATE_ZVAL(tmp); + convert_to_array(tmp); + + headers = php_amqp_type_convert_zval_to_amqp_table(tmp TSRMLS_CC); + + props._flags |= AMQP_BASIC_HEADERS_FLAG; + props.headers = *headers; + } + + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not publish to exchange."); #ifndef PHP_WIN32 - /* Start ignoring SIGPIPE */ - old_handler = signal(SIGPIPE, SIG_IGN); + /* Start ignoring SIGPIPE */ + old_handler = signal(SIGPIPE, SIG_IGN); #endif - zval *exchange_name = PHP_AMQP_READ_THIS_PROP("name"); - - /* NOTE: basic.publish is asynchronous and thus will not indicate failure if something goes wrong on the broker */ - int status = amqp_basic_publish( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - (Z_TYPE_P(exchange_name) == IS_STRING && Z_STRLEN_P(exchange_name) > 0 ? amqp_cstring_bytes(Z_STRVAL_P(exchange_name)) : amqp_empty_bytes), /* exchange */ - (key_len > 0 ? amqp_cstring_bytes(key_name) : amqp_empty_bytes), /* routing key */ - (AMQP_MANDATORY & flags) ? 1 : 0, /* mandatory */ - (AMQP_IMMEDIATE & flags) ? 1 : 0, /* immediate */ - &props, - php_amqp_type_char_to_amqp_long(msg, msg_len) /* message body */ - ); - - if (headers) { - php_amqp_type_free_amqp_table(headers); - } + zval *exchange_name = PHP_AMQP_READ_THIS_PROP("name"); + + /* NOTE: basic.publish is asynchronous and thus will not indicate failure if something goes wrong on the broker */ + int status = amqp_basic_publish( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + (Z_TYPE_P(exchange_name) == IS_STRING && Z_STRLEN_P(exchange_name) > 0 + ? amqp_cstring_bytes(Z_STRVAL_P(exchange_name)) + : amqp_empty_bytes), /* exchange */ + (key_len > 0 ? amqp_cstring_bytes(key_name) : amqp_empty_bytes), /* routing key */ + (AMQP_MANDATORY & flags) ? 1 : 0, /* mandatory */ + (AMQP_IMMEDIATE & flags) ? 1 : 0, /* immediate */ + &props, + php_amqp_type_char_to_amqp_long(msg, msg_len) /* message body */ + ); + + if (headers) { + php_amqp_type_free_amqp_table(headers); + } #ifndef PHP_WIN32 - /* End ignoring of SIGPIPEs */ - signal(SIGPIPE, old_handler); + /* End ignoring of SIGPIPEs */ + signal(SIGPIPE, old_handler); #endif - if (status != AMQP_STATUS_OK) { - /* Emulate library error */ - amqp_rpc_reply_t res; - res.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; - res.library_error = status; - - php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource TSRMLS_CC); - - php_amqp_zend_throw_exception(res, amqp_exchange_exception_class_entry, PHP_AMQP_G(error_message), PHP_AMQP_G(error_code) TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } - - RETURN_TRUE; + if (status != AMQP_STATUS_OK) { + /* Emulate library error */ + amqp_rpc_reply_t res; + res.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; + res.library_error = status; + + php_amqp_error( + res, + &PHP_AMQP_G(error_message), + channel_resource->connection_resource, + channel_resource TSRMLS_CC + ); + + php_amqp_zend_throw_exception( + res, + amqp_exchange_exception_class_entry, + PHP_AMQP_G(error_message), + PHP_AMQP_G(error_code) TSRMLS_CC + ); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } + + RETURN_TRUE; } /* }}} */ @@ -648,57 +708,62 @@ bind exchange to exchange by routing key */ static PHP_METHOD(amqp_exchange_class, bind) { - zval rv; - - zval *zvalArguments = NULL; - - amqp_channel_resource *channel_resource; - - char *src_name; - size_t src_name_len = 0; - char *keyname = NULL; - size_t keyname_len = 0; - - amqp_table_t *arguments = NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!a", - &src_name, &src_name_len, - &keyname, &keyname_len, - &zvalArguments) == FAILURE) { - return; - } - - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); - PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not bind to exchange."); - - if (zvalArguments) { - arguments = php_amqp_type_convert_zval_to_amqp_table(zvalArguments TSRMLS_CC); - } - - amqp_exchange_bind( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), - (src_name_len > 0 ? amqp_cstring_bytes(src_name) : amqp_empty_bytes), - (keyname != NULL && keyname_len > 0 ? amqp_cstring_bytes(keyname) : amqp_empty_bytes), - (arguments ? *arguments : amqp_empty_table) - ); - - if (arguments) { - php_amqp_type_free_amqp_table(arguments); - } - - amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_exchange_exception_class_entry TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } - - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - - RETURN_TRUE; + zval rv; + + zval *zvalArguments = NULL; + + amqp_channel_resource *channel_resource; + + char *src_name; + size_t src_name_len = 0; + char *keyname = NULL; + size_t keyname_len = 0; + + amqp_table_t *arguments = NULL; + + if (zend_parse_parameters( + ZEND_NUM_ARGS() TSRMLS_CC, + "s|s!a", + &src_name, + &src_name_len, + &keyname, + &keyname_len, + &zvalArguments + ) == FAILURE) { + return; + } + + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not bind to exchange."); + + if (zvalArguments) { + arguments = php_amqp_type_convert_zval_to_amqp_table(zvalArguments TSRMLS_CC); + } + + amqp_exchange_bind( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), + (src_name_len > 0 ? amqp_cstring_bytes(src_name) : amqp_empty_bytes), + (keyname != NULL && keyname_len > 0 ? amqp_cstring_bytes(keyname) : amqp_empty_bytes), + (arguments ? *arguments : amqp_empty_table) + ); + + if (arguments) { + php_amqp_type_free_amqp_table(arguments); + } + + amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + php_amqp_zend_throw_exception_short(res, amqp_exchange_exception_class_entry TSRMLS_CC); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } + + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + + RETURN_TRUE; } /* }}} */ @@ -707,57 +772,62 @@ remove exchange to exchange binding by routing key */ static PHP_METHOD(amqp_exchange_class, unbind) { - zval rv; - - zval *zvalArguments = NULL; - - amqp_channel_resource *channel_resource; - - char *src_name; - size_t src_name_len = 0; - char *keyname = NULL; - size_t keyname_len = 0; - - amqp_table_t *arguments = NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!a", - &src_name, &src_name_len, - &keyname, &keyname_len, - &zvalArguments) == FAILURE) { - return; - } - - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); - PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not unbind from exchange."); - - if (zvalArguments) { - arguments = php_amqp_type_convert_zval_to_amqp_table(zvalArguments TSRMLS_CC); - } - - amqp_exchange_unbind( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), - (src_name_len > 0 ? amqp_cstring_bytes(src_name) : amqp_empty_bytes), - (keyname != NULL && keyname_len > 0 ? amqp_cstring_bytes(keyname) : amqp_empty_bytes), - (arguments ? *arguments : amqp_empty_table) - ); - - if (arguments) { - php_amqp_type_free_amqp_table(arguments); - } - - amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_exchange_exception_class_entry TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } - - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - - RETURN_TRUE; + zval rv; + + zval *zvalArguments = NULL; + + amqp_channel_resource *channel_resource; + + char *src_name; + size_t src_name_len = 0; + char *keyname = NULL; + size_t keyname_len = 0; + + amqp_table_t *arguments = NULL; + + if (zend_parse_parameters( + ZEND_NUM_ARGS() TSRMLS_CC, + "s|s!a", + &src_name, + &src_name_len, + &keyname, + &keyname_len, + &zvalArguments + ) == FAILURE) { + return; + } + + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not unbind from exchange."); + + if (zvalArguments) { + arguments = php_amqp_type_convert_zval_to_amqp_table(zvalArguments TSRMLS_CC); + } + + amqp_exchange_unbind( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), + (src_name_len > 0 ? amqp_cstring_bytes(src_name) : amqp_empty_bytes), + (keyname != NULL && keyname_len > 0 ? amqp_cstring_bytes(keyname) : amqp_empty_bytes), + (arguments ? *arguments : amqp_empty_table) + ); + + if (arguments) { + php_amqp_type_free_amqp_table(arguments); + } + + amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + php_amqp_zend_throw_exception_short(res, amqp_exchange_exception_class_entry TSRMLS_CC); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } + + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + + RETURN_TRUE; } /* }}} */ @@ -765,9 +835,9 @@ static PHP_METHOD(amqp_exchange_class, unbind) Get the AMQPChannel object in use */ static PHP_METHOD(amqp_exchange_class, getChannel) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("channel"); + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("channel"); } /* }}} */ @@ -775,83 +845,83 @@ static PHP_METHOD(amqp_exchange_class, getChannel) Get the AMQPConnection object in use */ static PHP_METHOD(amqp_exchange_class, getConnection) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("connection"); + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("connection"); } /* }}} */ /* amqp_exchange ARG_INFO definition */ ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class__construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_OBJ_INFO(0, amqp_channel, AMQPChannel, 0) + ZEND_ARG_OBJ_INFO(0, amqp_channel, AMQPChannel, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_getName, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_setName, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, exchange_name) + ZEND_ARG_INFO(0, exchange_name) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_getFlags, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_setFlags, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, flags) + ZEND_ARG_INFO(0, flags) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_getType, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_setType, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, exchange_type) + ZEND_ARG_INFO(0, exchange_type) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_getArgument, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, argument) + ZEND_ARG_INFO(0, argument) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_hasArgument, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, argument) + ZEND_ARG_INFO(0, argument) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_getArguments, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_setArgument, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 2) - ZEND_ARG_INFO(0, key) - ZEND_ARG_INFO(0, value) + ZEND_ARG_INFO(0, key) + ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_setArguments, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_ARRAY_INFO(0, arguments, 0) + ZEND_ARG_ARRAY_INFO(0, arguments, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_declareExchange, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_bind, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 2) - ZEND_ARG_INFO(0, exchange_name) - ZEND_ARG_INFO(0, routing_key) - ZEND_ARG_INFO(0, flags) + ZEND_ARG_INFO(0, exchange_name) + ZEND_ARG_INFO(0, routing_key) + ZEND_ARG_INFO(0, flags) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_unbind, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 2) - ZEND_ARG_INFO(0, exchange_name) - ZEND_ARG_INFO(0, routing_key) - ZEND_ARG_INFO(0, flags) + ZEND_ARG_INFO(0, exchange_name) + ZEND_ARG_INFO(0, routing_key) + ZEND_ARG_INFO(0, flags) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_delete, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) - ZEND_ARG_INFO(0, exchange_name) - ZEND_ARG_INFO(0, flags) + ZEND_ARG_INFO(0, exchange_name) + ZEND_ARG_INFO(0, flags) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_publish, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, message) - ZEND_ARG_INFO(0, routing_key) - ZEND_ARG_INFO(0, flags) - ZEND_ARG_ARRAY_INFO(0, headers, 0) + ZEND_ARG_INFO(0, message) + ZEND_ARG_INFO(0, routing_key) + ZEND_ARG_INFO(0, flags) + ZEND_ARG_ARRAY_INFO(0, headers, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_getChannel, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) @@ -861,62 +931,54 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_getConnection, ZEND_SEND_BY_V ZEND_END_ARG_INFO() zend_function_entry amqp_exchange_class_functions[] = { - PHP_ME(amqp_exchange_class, __construct, arginfo_amqp_exchange_class__construct, ZEND_ACC_PUBLIC) + PHP_ME(amqp_exchange_class, __construct, arginfo_amqp_exchange_class__construct, ZEND_ACC_PUBLIC) - PHP_ME(amqp_exchange_class, getName, arginfo_amqp_exchange_class_getName, ZEND_ACC_PUBLIC) - PHP_ME(amqp_exchange_class, setName, arginfo_amqp_exchange_class_setName, ZEND_ACC_PUBLIC) + PHP_ME(amqp_exchange_class, getName, arginfo_amqp_exchange_class_getName, ZEND_ACC_PUBLIC) + PHP_ME(amqp_exchange_class, setName, arginfo_amqp_exchange_class_setName, ZEND_ACC_PUBLIC) - PHP_ME(amqp_exchange_class, getFlags, arginfo_amqp_exchange_class_getFlags, ZEND_ACC_PUBLIC) - PHP_ME(amqp_exchange_class, setFlags, arginfo_amqp_exchange_class_setFlags, ZEND_ACC_PUBLIC) + PHP_ME(amqp_exchange_class, getFlags, arginfo_amqp_exchange_class_getFlags, ZEND_ACC_PUBLIC) + PHP_ME(amqp_exchange_class, setFlags, arginfo_amqp_exchange_class_setFlags, ZEND_ACC_PUBLIC) - PHP_ME(amqp_exchange_class, getType, arginfo_amqp_exchange_class_getType, ZEND_ACC_PUBLIC) - PHP_ME(amqp_exchange_class, setType, arginfo_amqp_exchange_class_setType, ZEND_ACC_PUBLIC) + PHP_ME(amqp_exchange_class, getType, arginfo_amqp_exchange_class_getType, ZEND_ACC_PUBLIC) + PHP_ME(amqp_exchange_class, setType, arginfo_amqp_exchange_class_setType, ZEND_ACC_PUBLIC) - PHP_ME(amqp_exchange_class, getArgument, arginfo_amqp_exchange_class_getArgument, ZEND_ACC_PUBLIC) - PHP_ME(amqp_exchange_class, getArguments, arginfo_amqp_exchange_class_getArguments, ZEND_ACC_PUBLIC) - PHP_ME(amqp_exchange_class, setArgument, arginfo_amqp_exchange_class_setArgument, ZEND_ACC_PUBLIC) - PHP_ME(amqp_exchange_class, setArguments, arginfo_amqp_exchange_class_setArguments, ZEND_ACC_PUBLIC) - PHP_ME(amqp_exchange_class, hasArgument, arginfo_amqp_exchange_class_hasArgument, ZEND_ACC_PUBLIC) + PHP_ME(amqp_exchange_class, getArgument, arginfo_amqp_exchange_class_getArgument, ZEND_ACC_PUBLIC) + PHP_ME(amqp_exchange_class, getArguments, arginfo_amqp_exchange_class_getArguments, ZEND_ACC_PUBLIC) + PHP_ME(amqp_exchange_class, setArgument, arginfo_amqp_exchange_class_setArgument, ZEND_ACC_PUBLIC) + PHP_ME(amqp_exchange_class, setArguments, arginfo_amqp_exchange_class_setArguments, ZEND_ACC_PUBLIC) + PHP_ME(amqp_exchange_class, hasArgument, arginfo_amqp_exchange_class_hasArgument, ZEND_ACC_PUBLIC) - PHP_ME(amqp_exchange_class, declareExchange,arginfo_amqp_exchange_class_declareExchange,ZEND_ACC_PUBLIC) - PHP_ME(amqp_exchange_class, bind, arginfo_amqp_exchange_class_bind, ZEND_ACC_PUBLIC) - PHP_ME(amqp_exchange_class, unbind, arginfo_amqp_exchange_class_unbind, ZEND_ACC_PUBLIC) - PHP_ME(amqp_exchange_class, delete, arginfo_amqp_exchange_class_delete, ZEND_ACC_PUBLIC) - PHP_ME(amqp_exchange_class, publish, arginfo_amqp_exchange_class_publish, ZEND_ACC_PUBLIC) + PHP_ME(amqp_exchange_class, declareExchange,arginfo_amqp_exchange_class_declareExchange,ZEND_ACC_PUBLIC) + PHP_ME(amqp_exchange_class, bind, arginfo_amqp_exchange_class_bind, ZEND_ACC_PUBLIC) + PHP_ME(amqp_exchange_class, unbind, arginfo_amqp_exchange_class_unbind, ZEND_ACC_PUBLIC) + PHP_ME(amqp_exchange_class, delete, arginfo_amqp_exchange_class_delete, ZEND_ACC_PUBLIC) + PHP_ME(amqp_exchange_class, publish, arginfo_amqp_exchange_class_publish, ZEND_ACC_PUBLIC) - PHP_ME(amqp_exchange_class, getChannel, arginfo_amqp_exchange_class_getChannel, ZEND_ACC_PUBLIC) - PHP_ME(amqp_exchange_class, getConnection, arginfo_amqp_exchange_class_getConnection, ZEND_ACC_PUBLIC) + PHP_ME(amqp_exchange_class, getChannel, arginfo_amqp_exchange_class_getChannel, ZEND_ACC_PUBLIC) + PHP_ME(amqp_exchange_class, getConnection, arginfo_amqp_exchange_class_getConnection, ZEND_ACC_PUBLIC) - PHP_MALIAS(amqp_exchange_class, declare, declareExchange, arginfo_amqp_exchange_class_declareExchange, ZEND_ACC_PUBLIC | ZEND_ACC_DEPRECATED) + PHP_MALIAS(amqp_exchange_class, declare, declareExchange, arginfo_amqp_exchange_class_declareExchange, ZEND_ACC_PUBLIC | ZEND_ACC_DEPRECATED) - {NULL, NULL, NULL} + {NULL, NULL, NULL} }; PHP_MINIT_FUNCTION(amqp_exchange) { - zend_class_entry ce; + zend_class_entry ce; - INIT_CLASS_ENTRY(ce, "AMQPExchange", amqp_exchange_class_functions); - this_ce = zend_register_internal_class(&ce TSRMLS_CC); + INIT_CLASS_ENTRY(ce, "AMQPExchange", amqp_exchange_class_functions); + this_ce = zend_register_internal_class(&ce TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("connection"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("channel"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("connection"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("channel"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_stringl(this_ce, ZEND_STRL("name"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("type"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_bool(this_ce, ZEND_STRL("passive"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_bool(this_ce, ZEND_STRL("durable"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_bool(this_ce, ZEND_STRL("auto_delete"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_bool(this_ce, ZEND_STRL("internal"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("arguments"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_stringl(this_ce, ZEND_STRL("name"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("type"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_bool(this_ce, ZEND_STRL("passive"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_bool(this_ce, ZEND_STRL("durable"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_bool(this_ce, ZEND_STRL("auto_delete"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_bool(this_ce, ZEND_STRL("internal"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("arguments"), ZEND_ACC_PRIVATE TSRMLS_CC); - return SUCCESS; + 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 -*/ diff --git a/amqp_exchange.h b/amqp_exchange.h index a1dbf05a..a590db89 100644 --- a/amqp_exchange.h +++ b/amqp_exchange.h @@ -24,12 +24,3 @@ extern zend_class_entry *amqp_exchange_class_entry; PHP_MINIT_FUNCTION(amqp_exchange); - -/* -*Local variables: -*tab-width: 4 -*c-basic-offset: 4 -*End: -*vim600: noet sw=4 ts=4 fdm=marker -*vim<600: noet sw=4 ts=4 -*/ diff --git a/amqp_methods_handling.c b/amqp_methods_handling.c index aa471cfc..9a6c39f0 100644 --- a/amqp_methods_handling.c +++ b/amqp_methods_handling.c @@ -25,217 +25,246 @@ #include "amqp_methods_handling.h" /* taken from rabbbitmq-c */ -static int amqp_id_in_reply_list(amqp_method_number_t expected, amqp_method_number_t *list) { - while (*list != 0) { - if (*list == expected) { - return 1; - } - list++; - } - - return 0; +static int amqp_id_in_reply_list(amqp_method_number_t expected, amqp_method_number_t *list) +{ + while (*list != 0) { + if (*list == expected) { + return 1; + } + list++; + } + + return 0; } /* taken from rabbbitmq-c */ -int amqp_simple_wait_method_list_noblock(amqp_connection_state_t state, - amqp_channel_t expected_channel, - amqp_method_number_t *expected_methods, - amqp_method_t *output, - struct timeval *timeout) { - amqp_frame_t frame; - int res = amqp_simple_wait_frame_noblock(state, &frame, timeout); +int amqp_simple_wait_method_list_noblock( + amqp_connection_state_t state, + amqp_channel_t expected_channel, + amqp_method_number_t *expected_methods, + amqp_method_t *output, + struct timeval *timeout +) +{ + amqp_frame_t frame; + int res = amqp_simple_wait_frame_noblock(state, &frame, timeout); - if (AMQP_STATUS_OK != res) { - return res; - } + if (AMQP_STATUS_OK != res) { + return res; + } - if (AMQP_FRAME_METHOD != frame.frame_type || - expected_channel != frame.channel || - !amqp_id_in_reply_list(frame.payload.method.id, expected_methods)) { + if (AMQP_FRAME_METHOD != frame.frame_type || expected_channel != frame.channel || + !amqp_id_in_reply_list(frame.payload.method.id, expected_methods)) { - if (AMQP_CHANNEL_CLOSE_METHOD == frame.payload.method.id || AMQP_CONNECTION_CLOSE_METHOD == frame.payload.method.id) { + if (AMQP_CHANNEL_CLOSE_METHOD == frame.payload.method.id || + AMQP_CONNECTION_CLOSE_METHOD == frame.payload.method.id) { - *output = frame.payload.method; + *output = frame.payload.method; - return AMQP_RESPONSE_SERVER_EXCEPTION; - } + return AMQP_RESPONSE_SERVER_EXCEPTION; + } - return AMQP_STATUS_WRONG_METHOD; - } + return AMQP_STATUS_WRONG_METHOD; + } - *output = frame.payload.method; - return AMQP_STATUS_OK; + *output = frame.payload.method; + return AMQP_STATUS_OK; } /* taken from rabbbitmq-c */ -int amqp_simple_wait_method_noblock(amqp_connection_state_t state, - amqp_channel_t expected_channel, - amqp_method_number_t expected_method, - amqp_method_t *output, - struct timeval *timeout) +int amqp_simple_wait_method_noblock( + amqp_connection_state_t state, + amqp_channel_t expected_channel, + amqp_method_number_t expected_method, + amqp_method_t *output, + struct timeval *timeout +) { - amqp_method_number_t expected_methods[] = { 0, 0 }; - expected_methods[0] = expected_method; + amqp_method_number_t expected_methods[] = {0, 0}; + expected_methods[0] = expected_method; - return amqp_simple_wait_method_list_noblock(state, expected_channel, expected_methods, output, timeout); + return amqp_simple_wait_method_list_noblock(state, expected_channel, expected_methods, output, timeout); } -int php_amqp_handle_basic_return(char **message, amqp_connection_resource *resource, amqp_channel_t channel_id, amqp_channel_object *channel, amqp_method_t *method TSRMLS_DC) { - amqp_rpc_reply_t ret; - amqp_message_t msg; - int status = PHP_AMQP_RESOURCE_RESPONSE_OK; +int php_amqp_handle_basic_return( + char **message, + amqp_connection_resource *resource, + amqp_channel_t channel_id, + amqp_channel_object *channel, + amqp_method_t *method TSRMLS_DC +) +{ + amqp_rpc_reply_t ret; + amqp_message_t msg; + int status = PHP_AMQP_RESOURCE_RESPONSE_OK; - assert(AMQP_BASIC_RETURN_METHOD == method->id); + assert(AMQP_BASIC_RETURN_METHOD == method->id); - amqp_basic_return_t *m = (amqp_basic_return_t *) method->decoded; + amqp_basic_return_t *m = (amqp_basic_return_t *) method->decoded; - ret = amqp_read_message(resource->connection_state, channel_id, &msg, 0); + ret = amqp_read_message(resource->connection_state, channel_id, &msg, 0); - if (AMQP_RESPONSE_NORMAL != ret.reply_type) { - return php_amqp_connection_resource_error(ret, message, resource, channel_id TSRMLS_CC); - } + if (AMQP_RESPONSE_NORMAL != ret.reply_type) { + return php_amqp_connection_resource_error(ret, message, resource, channel_id TSRMLS_CC); + } - if (channel->callbacks.basic_return.fci.size > 0) { - status = php_amqp_call_basic_return_callback(m, &msg, &channel->callbacks.basic_return TSRMLS_CC); - } else { - zend_error(E_NOTICE, "Unhandled basic.return method from server received. Use AMQPChannel::setReturnCallback() to process it."); - status = PHP_AMQP_RESOURCE_RESPONSE_BREAK; - } + if (channel->callbacks.basic_return.fci.size > 0) { + status = php_amqp_call_basic_return_callback(m, &msg, &channel->callbacks.basic_return TSRMLS_CC); + } else { + zend_error( + E_NOTICE, + "Unhandled basic.return method from server received. Use AMQPChannel::setReturnCallback() to process it." + ); + status = PHP_AMQP_RESOURCE_RESPONSE_BREAK; + } - amqp_destroy_message(&msg); + amqp_destroy_message(&msg); - return status; + return status; } -int php_amqp_call_basic_return_callback(amqp_basic_return_t *m, amqp_message_t *msg, amqp_callback_bucket *cb TSRMLS_DC) { - zval params; - zval basic_properties; +int php_amqp_call_basic_return_callback(amqp_basic_return_t *m, amqp_message_t *msg, amqp_callback_bucket *cb TSRMLS_DC) +{ + zval params; + zval basic_properties; - int status = PHP_AMQP_RESOURCE_RESPONSE_OK; + int status = PHP_AMQP_RESOURCE_RESPONSE_OK; - ZVAL_UNDEF(¶ms); - array_init(¶ms); + ZVAL_UNDEF(¶ms); + array_init(¶ms); - ZVAL_UNDEF(&basic_properties); + ZVAL_UNDEF(&basic_properties); - /* callback(int $reply_code, string $reply_text, string $exchange, string $routing_key, AMQPBasicProperties $properties, string $body); */ + /* callback(int $reply_code, string $reply_text, string $exchange, string $routing_key, AMQPBasicProperties $properties, string $body); */ - add_next_index_long(¶ms, (zend_long) m->reply_code); - add_next_index_stringl(¶ms, m->reply_text.bytes, m->reply_text.len); - add_next_index_stringl(¶ms, m->exchange.bytes, m->exchange.len); - add_next_index_stringl(¶ms, m->routing_key.bytes, m->routing_key.len); + add_next_index_long(¶ms, (zend_long) m->reply_code); + add_next_index_stringl(¶ms, m->reply_text.bytes, m->reply_text.len); + add_next_index_stringl(¶ms, m->exchange.bytes, m->exchange.len); + add_next_index_stringl(¶ms, m->routing_key.bytes, m->routing_key.len); - php_amqp_basic_properties_convert_to_zval(&msg->properties, &basic_properties TSRMLS_CC); - add_next_index_zval(¶ms, &basic_properties); - Z_ADDREF_P(&basic_properties); + php_amqp_basic_properties_convert_to_zval(&msg->properties, &basic_properties TSRMLS_CC); + add_next_index_zval(¶ms, &basic_properties); + Z_ADDREF_P(&basic_properties); - add_next_index_stringl(¶ms, msg->body.bytes, msg->body.len); + add_next_index_stringl(¶ms, msg->body.bytes, msg->body.len); - status = php_amqp_call_callback_with_params(params, cb TSRMLS_CC); + status = php_amqp_call_callback_with_params(params, cb TSRMLS_CC); - zval_ptr_dtor(&basic_properties); + zval_ptr_dtor(&basic_properties); - return status; + return status; } -int php_amqp_handle_basic_ack(char **message, amqp_connection_resource *resource, amqp_channel_t channel_id, amqp_channel_object *channel, amqp_method_t *method TSRMLS_DC) { - int status = PHP_AMQP_RESOURCE_RESPONSE_OK; +int php_amqp_handle_basic_ack( + char **message, + amqp_connection_resource *resource, + amqp_channel_t channel_id, + amqp_channel_object *channel, + amqp_method_t *method TSRMLS_DC +) +{ + int status = PHP_AMQP_RESOURCE_RESPONSE_OK; - assert(AMQP_BASIC_ACK_METHOD == method->id); + assert(AMQP_BASIC_ACK_METHOD == method->id); - amqp_basic_ack_t *m = (amqp_basic_ack_t *) method->decoded; + amqp_basic_ack_t *m = (amqp_basic_ack_t *) method->decoded; - if (channel->callbacks.basic_ack.fci.size > 0) { - status = php_amqp_call_basic_ack_callback(m, &channel->callbacks.basic_ack TSRMLS_CC); - } else { - zend_error(E_NOTICE, "Unhandled basic.ack method from server received. Use AMQPChannel::setConfirmCallback() to process it."); - status = PHP_AMQP_RESOURCE_RESPONSE_BREAK; - } + if (channel->callbacks.basic_ack.fci.size > 0) { + status = php_amqp_call_basic_ack_callback(m, &channel->callbacks.basic_ack TSRMLS_CC); + } else { + zend_error( + E_NOTICE, + "Unhandled basic.ack method from server received. Use AMQPChannel::setConfirmCallback() to process it." + ); + status = PHP_AMQP_RESOURCE_RESPONSE_BREAK; + } - return status; + return status; } -int php_amqp_call_basic_ack_callback(amqp_basic_ack_t *m, amqp_callback_bucket *cb TSRMLS_DC) { - zval params; +int php_amqp_call_basic_ack_callback(amqp_basic_ack_t *m, amqp_callback_bucket *cb TSRMLS_DC) +{ + zval params; - ZVAL_UNDEF(¶ms); - array_init(¶ms); + ZVAL_UNDEF(¶ms); + array_init(¶ms); - /* callback(int $delivery_tag, bool $multiple); */ - add_next_index_long(¶ms, (zend_long) m->delivery_tag); - add_next_index_bool(¶ms, m->multiple); + /* callback(int $delivery_tag, bool $multiple); */ + add_next_index_long(¶ms, (zend_long) m->delivery_tag); + add_next_index_bool(¶ms, m->multiple); - return php_amqp_call_callback_with_params(params, cb TSRMLS_CC); + return php_amqp_call_callback_with_params(params, cb TSRMLS_CC); } -int php_amqp_handle_basic_nack(char **message, amqp_connection_resource *resource, amqp_channel_t channel_id, amqp_channel_object *channel, amqp_method_t *method TSRMLS_DC) { - int status = PHP_AMQP_RESOURCE_RESPONSE_OK; +int php_amqp_handle_basic_nack( + char **message, + amqp_connection_resource *resource, + amqp_channel_t channel_id, + amqp_channel_object *channel, + amqp_method_t *method TSRMLS_DC +) +{ + int status = PHP_AMQP_RESOURCE_RESPONSE_OK; - assert(AMQP_BASIC_NACK_METHOD == method->id); + assert(AMQP_BASIC_NACK_METHOD == method->id); - amqp_basic_nack_t *m = (amqp_basic_nack_t *) method->decoded; + amqp_basic_nack_t *m = (amqp_basic_nack_t *) method->decoded; - if (channel->callbacks.basic_nack.fci.size > 0) { - status = php_amqp_call_basic_nack_callback(m, &channel->callbacks.basic_nack TSRMLS_CC); - } else { - zend_error(E_NOTICE, "Unhandled basic.nack method from server received. Use AMQPChannel::setConfirmCallback() to process it."); - status = PHP_AMQP_RESOURCE_RESPONSE_BREAK; - } + if (channel->callbacks.basic_nack.fci.size > 0) { + status = php_amqp_call_basic_nack_callback(m, &channel->callbacks.basic_nack TSRMLS_CC); + } else { + zend_error( + E_NOTICE, + "Unhandled basic.nack method from server received. Use AMQPChannel::setConfirmCallback() to process it." + ); + status = PHP_AMQP_RESOURCE_RESPONSE_BREAK; + } - return status; + return status; } -int php_amqp_call_basic_nack_callback(amqp_basic_nack_t *m, amqp_callback_bucket *cb TSRMLS_DC) { - zval params; +int php_amqp_call_basic_nack_callback(amqp_basic_nack_t *m, amqp_callback_bucket *cb TSRMLS_DC) +{ + zval params; - ZVAL_UNDEF(¶ms); - array_init(¶ms); + ZVAL_UNDEF(¶ms); + array_init(¶ms); - /* callback(int $delivery_tag, bool $multiple, bool $requeue); */ - add_next_index_long(¶ms, (zend_long) m->delivery_tag); - add_next_index_bool(¶ms, m->multiple); - add_next_index_bool(¶ms, m->requeue); + /* callback(int $delivery_tag, bool $multiple, bool $requeue); */ + add_next_index_long(¶ms, (zend_long) m->delivery_tag); + add_next_index_bool(¶ms, m->multiple); + add_next_index_bool(¶ms, m->requeue); - return php_amqp_call_callback_with_params(params, cb TSRMLS_CC); + return php_amqp_call_callback_with_params(params, cb TSRMLS_CC); } int php_amqp_call_callback_with_params(zval params, amqp_callback_bucket *cb TSRMLS_DC) { - zval retval; - zval *retval_ptr = &retval; + zval retval; + zval *retval_ptr = &retval; - int status = PHP_AMQP_RESOURCE_RESPONSE_OK; + int status = PHP_AMQP_RESOURCE_RESPONSE_OK; - ZVAL_NULL(&retval); + ZVAL_NULL(&retval); - /* Convert everything to be callable */ - zend_fcall_info_args(&cb->fci, ¶ms TSRMLS_CC); + /* Convert everything to be callable */ + zend_fcall_info_args(&cb->fci, ¶ms TSRMLS_CC); - /* Initialize the return value pointer */ - cb->fci.retval = retval_ptr; + /* Initialize the return value pointer */ + cb->fci.retval = retval_ptr; - zend_call_function(&cb->fci, &cb->fcc TSRMLS_CC); + zend_call_function(&cb->fci, &cb->fcc TSRMLS_CC); - /* Check if user land function wants to bail */ - if (EG(exception) || Z_TYPE_P(retval_ptr) == IS_FALSE) { - status = PHP_AMQP_RESOURCE_RESPONSE_BREAK; - } + /* Check if user land function wants to bail */ + if (EG(exception) || Z_TYPE_P(retval_ptr) == IS_FALSE) { + status = PHP_AMQP_RESOURCE_RESPONSE_BREAK; + } - /* Clean up our mess */ - zend_fcall_info_args_clear(&cb->fci, 1); - zval_ptr_dtor(¶ms); - zval_ptr_dtor(retval_ptr); + /* Clean up our mess */ + zend_fcall_info_args_clear(&cb->fci, 1); + zval_ptr_dtor(¶ms); + zval_ptr_dtor(retval_ptr); - return status; + return status; } - - -/* -*Local variables: -*tab-width: 4 -*c-basic-offset: 4 -*End: -*vim600: noet sw=4 ts=4 fdm=marker -*vim<600: noet sw=4 ts=4 -*/ diff --git a/amqp_methods_handling.h b/amqp_methods_handling.h index 5ebf9c8b..dc8ef58a 100644 --- a/amqp_methods_handling.h +++ b/amqp_methods_handling.h @@ -25,42 +25,55 @@ #include "php_amqp.h" #if HAVE_LIBRABBITMQ_NEW_LAYOUT -#include + #include #else -#include + #include #endif #include "php.h" -int amqp_simple_wait_method_list_noblock(amqp_connection_state_t state, - amqp_channel_t expected_channel, - amqp_method_number_t *expected_methods, - amqp_method_t *output, - struct timeval *timeout); +int amqp_simple_wait_method_list_noblock( + amqp_connection_state_t state, + amqp_channel_t expected_channel, + amqp_method_number_t *expected_methods, + amqp_method_t *output, + struct timeval *timeout +); -int amqp_simple_wait_method_noblock(amqp_connection_state_t state, - amqp_channel_t expected_channel, - amqp_method_number_t expected_method, - amqp_method_t *output, - struct timeval *timeout); +int amqp_simple_wait_method_noblock( + amqp_connection_state_t state, + amqp_channel_t expected_channel, + amqp_method_number_t expected_method, + amqp_method_t *output, + struct timeval *timeout +); int php_amqp_call_callback_with_params(zval params, amqp_callback_bucket *cb TSRMLS_DC); int php_amqp_call_basic_return_callback(amqp_basic_return_t *m, amqp_message_t *msg, amqp_callback_bucket *cb TSRMLS_DC); -int php_amqp_handle_basic_return(char **message, amqp_connection_resource *resource, amqp_channel_t channel_id, amqp_channel_object *channel, amqp_method_t *method TSRMLS_DC); +int php_amqp_handle_basic_return( + char **message, + amqp_connection_resource *resource, + amqp_channel_t channel_id, + amqp_channel_object *channel, + amqp_method_t *method TSRMLS_DC +); int php_amqp_call_basic_ack_callback(amqp_basic_ack_t *m, amqp_callback_bucket *cb TSRMLS_DC); -int php_amqp_handle_basic_ack(char **message, amqp_connection_resource *resource, amqp_channel_t channel_id, amqp_channel_object *channel, amqp_method_t *method TSRMLS_DC); +int php_amqp_handle_basic_ack( + char **message, + amqp_connection_resource *resource, + amqp_channel_t channel_id, + amqp_channel_object *channel, + amqp_method_t *method TSRMLS_DC +); int php_amqp_call_basic_nack_callback(amqp_basic_nack_t *m, amqp_callback_bucket *cb TSRMLS_DC); -int php_amqp_handle_basic_nack(char **message, amqp_connection_resource *resource, amqp_channel_t channel_id, amqp_channel_object *channel, amqp_method_t *method TSRMLS_DC); +int php_amqp_handle_basic_nack( + char **message, + amqp_connection_resource *resource, + amqp_channel_t channel_id, + amqp_channel_object *channel, + amqp_method_t *method TSRMLS_DC +); #endif - -/* -*Local variables: -*tab-width: 4 -*c-basic-offset: 4 -*End: -*vim600: noet sw=4 ts=4 fdm=marker -*vim<600: noet sw=4 ts=4 -*/ diff --git a/amqp_queue.c b/amqp_queue.c index 220bf258..f895474f 100644 --- a/amqp_queue.c +++ b/amqp_queue.c @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H -#include "config.h" + #include "config.h" #endif #include "php.h" @@ -30,36 +30,39 @@ #include "zend_exceptions.h" #ifdef PHP_WIN32 -# if PHP_VERSION_ID >= 80000 -# include "main/php_stdint.h" -# else -# include "win32/php_stdint.h" -# endif -# include "win32/signal.h" + #if PHP_VERSION_ID >= 80000 + #include "main/php_stdint.h" + #else + #include "win32/php_stdint.h" + #endif + #include "win32/signal.h" #else -# include -# include + #include + #include #endif #if HAVE_LIBRABBITMQ_NEW_LAYOUT -#include -#include + #include + #include #else -#include -#include + #include + #include #endif #ifdef PHP_WIN32 -# include "win32/unistd.h" + #include "win32/unistd.h" #else -# include + #include #endif #include "php_amqp.h" #include "amqp_envelope.h" #include "amqp_connection.h" #include "amqp_channel.h" +#include "amqp_connection.h" +#include "amqp_envelope.h" #include "amqp_queue.h" #include "amqp_type.h" +#include "php_amqp.h" zend_class_entry *amqp_queue_class_entry; #define this_ce amqp_queue_class_entry @@ -70,28 +73,32 @@ AMQPQueue constructor */ static PHP_METHOD(amqp_queue_class, __construct) { - zval rv; + zval rv; - zval arguments; + zval arguments; - zval *channelObj; - amqp_channel_resource *channel_resource; + zval *channelObj; + amqp_channel_resource *channel_resource; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &channelObj, amqp_channel_class_entry) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &channelObj, amqp_channel_class_entry) == FAILURE) { + return; + } - ZVAL_UNDEF(&arguments); - array_init(&arguments); - zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("arguments"), &arguments TSRMLS_CC); - zval_ptr_dtor(&arguments); + ZVAL_UNDEF(&arguments); + array_init(&arguments); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("arguments"), &arguments TSRMLS_CC); + zval_ptr_dtor(&arguments); - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(channelObj); - PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not create queue."); - - zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("channel"), channelObj TSRMLS_CC); - zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connection"), PHP_AMQP_READ_OBJ_PROP(amqp_channel_class_entry, channelObj, "connection") TSRMLS_CC); + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(channelObj); + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not create queue."); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("channel"), channelObj TSRMLS_CC); + zend_update_property( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("connection"), + PHP_AMQP_READ_OBJ_PROP(amqp_channel_class_entry, channelObj, "connection") TSRMLS_CC + ); } /* }}} */ @@ -100,16 +107,16 @@ static PHP_METHOD(amqp_queue_class, __construct) Get the queue name */ static PHP_METHOD(amqp_queue_class, getName) { - zval rv; + zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS(); - if (PHP_AMQP_READ_THIS_PROP_STRLEN("name") > 0) { - PHP_AMQP_RETURN_THIS_PROP("name"); - } else { - /* BC */ - RETURN_FALSE; - } + if (PHP_AMQP_READ_THIS_PROP_STRLEN("name") > 0) { + PHP_AMQP_RETURN_THIS_PROP("name"); + } else { + /* BC */ + RETURN_FALSE; + } } /* }}} */ @@ -118,55 +125,59 @@ static PHP_METHOD(amqp_queue_class, getName) Set the queue name */ static PHP_METHOD(amqp_queue_class, setName) { - char *name = NULL; size_t name_len = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { - return; - } - - if (name_len < 1 || name_len > 255) { - /* Verify that the name is not null and not an empty string */ - zend_throw_exception(amqp_queue_exception_class_entry, "Invalid queue name given, must be between 1 and 255 characters long.", 0 TSRMLS_CC); - return; - } - - /* Set the queue name */ - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("name"), name, name_len TSRMLS_CC); - - /* BC */ - RETURN_TRUE; + char *name = NULL; + size_t name_len = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { + return; + } + + if (name_len < 1 || name_len > 255) { + /* Verify that the name is not null and not an empty string */ + zend_throw_exception( + amqp_queue_exception_class_entry, + "Invalid queue name given, must be between 1 and 255 characters long.", + 0 TSRMLS_CC + ); + return; + } + + /* Set the queue name */ + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("name"), name, name_len TSRMLS_CC); + + /* BC */ + RETURN_TRUE; } /* }}} */ - /* {{{ proto AMQPQueue::getFlags() Get the queue parameters */ static PHP_METHOD(amqp_queue_class, getFlags) { - zval rv; + zval rv; - zend_long flags = 0; + zend_long flags = 0; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS(); - if (PHP_AMQP_READ_THIS_PROP_BOOL("passive")) { - flags |= AMQP_PASSIVE; - } + if (PHP_AMQP_READ_THIS_PROP_BOOL("passive")) { + flags |= AMQP_PASSIVE; + } - if (PHP_AMQP_READ_THIS_PROP_BOOL("durable")) { - flags |= AMQP_DURABLE; - } + if (PHP_AMQP_READ_THIS_PROP_BOOL("durable")) { + flags |= AMQP_DURABLE; + } - if (PHP_AMQP_READ_THIS_PROP_BOOL("exclusive")) { - flags |= AMQP_EXCLUSIVE; - } + if (PHP_AMQP_READ_THIS_PROP_BOOL("exclusive")) { + flags |= AMQP_EXCLUSIVE; + } - if (PHP_AMQP_READ_THIS_PROP_BOOL("auto_delete")) { - flags |= AMQP_AUTODELETE; - } + if (PHP_AMQP_READ_THIS_PROP_BOOL("auto_delete")) { + flags |= AMQP_AUTODELETE; + } - RETURN_LONG(flags); + RETURN_LONG(flags); } /* }}} */ @@ -175,23 +186,43 @@ static PHP_METHOD(amqp_queue_class, getFlags) Set the queue parameters */ static PHP_METHOD(amqp_queue_class, setFlags) { - zend_long flags; - zend_bool flags_is_null = 1; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l!", &flags, &flags_is_null) == FAILURE) { - return; - } - - /* Set the flags based on the bitmask we were given */ - flags = flags ? flags & PHP_AMQP_QUEUE_FLAGS : flags; - - zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("passive"), IS_PASSIVE(flags) TSRMLS_CC); - zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("durable"), IS_DURABLE(flags) TSRMLS_CC); - zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("exclusive"), IS_EXCLUSIVE(flags) TSRMLS_CC); - zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("auto_delete"), IS_AUTODELETE(flags) TSRMLS_CC); - - /* BC */ - RETURN_TRUE; + zend_long flags; + zend_bool flags_is_null = 1; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l!", &flags, &flags_is_null) == FAILURE) { + return; + } + + /* Set the flags based on the bitmask we were given */ + flags = flags ? flags & PHP_AMQP_QUEUE_FLAGS : flags; + + zend_update_property_bool( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("passive"), + IS_PASSIVE(flags) TSRMLS_CC + ); + zend_update_property_bool( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("durable"), + IS_DURABLE(flags) TSRMLS_CC + ); + zend_update_property_bool( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("exclusive"), + IS_EXCLUSIVE(flags) TSRMLS_CC + ); + zend_update_property_bool( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("auto_delete"), + IS_AUTODELETE(flags) TSRMLS_CC + ); + + /* BC */ + RETURN_TRUE; } /* }}} */ @@ -200,41 +231,42 @@ static PHP_METHOD(amqp_queue_class, setFlags) Get the queue argument referenced by key */ static PHP_METHOD(amqp_queue_class, getArgument) { - zval rv; - zval *tmp = NULL; - char *key; - size_t key_len; + zval rv; + zval *tmp = NULL; + char *key; + size_t key_len; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { + return; + } - if ((tmp = zend_hash_str_find(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len)) == NULL) { - RETURN_FALSE; - } + if ((tmp = zend_hash_str_find(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len)) == NULL) { + RETURN_FALSE; + } - RETURN_ZVAL(tmp, 1, 0); + RETURN_ZVAL(tmp, 1, 0); } /* }}} */ /* {{{ proto AMQPQueue::hasArgument(string key) */ static PHP_METHOD(amqp_queue_class, hasArgument) { - zval rv; + zval rv; - zval *tmp = NULL; + zval *tmp = NULL; - char *key; size_t key_len; + char *key; + size_t key_len; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { + return; + } - if ((tmp = zend_hash_str_find(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len)) == NULL) { - RETURN_FALSE; - } + if ((tmp = zend_hash_str_find(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len)) == NULL) { + RETURN_FALSE; + } - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -243,9 +275,9 @@ static PHP_METHOD(amqp_queue_class, hasArgument) Get the queue arguments */ static PHP_METHOD(amqp_queue_class, getArguments) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("arguments"); + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("arguments"); } /* }}} */ @@ -253,15 +285,15 @@ static PHP_METHOD(amqp_queue_class, getArguments) Overwrite all queue arguments with given args */ static PHP_METHOD(amqp_queue_class, setArguments) { - zval *zvalArguments; + zval *zvalArguments; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &zvalArguments) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &zvalArguments) == FAILURE) { + return; + } - zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("arguments"), zvalArguments TSRMLS_CC); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("arguments"), zvalArguments TSRMLS_CC); - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -270,35 +302,38 @@ static PHP_METHOD(amqp_queue_class, setArguments) Get the queue name */ static PHP_METHOD(amqp_queue_class, setArgument) { - zval rv; - - char *key= NULL; size_t key_len = 0; - zval *value = NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", - &key, &key_len, - &value) == FAILURE) { - return; - } - - switch (Z_TYPE_P(value)) { - case IS_NULL: - zend_hash_str_del_ind(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len); - break; - case IS_TRUE: - case IS_FALSE: - case IS_LONG: - case IS_DOUBLE: - case IS_STRING: - zend_hash_str_add(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len, value); - Z_TRY_ADDREF_P(value); - break; - default: - zend_throw_exception(amqp_exchange_exception_class_entry, "The value parameter must be of type NULL, int, double or string.", 0 TSRMLS_CC); - return; - } - - RETURN_TRUE; + zval rv; + + char *key = NULL; + size_t key_len = 0; + zval *value = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &key, &key_len, &value) == FAILURE) { + return; + } + + switch (Z_TYPE_P(value)) { + case IS_NULL: + zend_hash_str_del_ind(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len); + break; + case IS_TRUE: + case IS_FALSE: + case IS_LONG: + case IS_DOUBLE: + case IS_STRING: + zend_hash_str_add(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len, value); + Z_TRY_ADDREF_P(value); + break; + default: + zend_throw_exception( + amqp_exchange_exception_class_entry, + "The value parameter must be of type NULL, int, double or string.", + 0 TSRMLS_CC + ); + return; + } + + RETURN_TRUE; } /* }}} */ @@ -308,56 +343,66 @@ declare queue */ static PHP_METHOD(amqp_queue_class, declareQueue) { - zval rv; - - amqp_channel_resource *channel_resource; - - char *name; - amqp_table_t *arguments; - zend_long message_count; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); - PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not declare queue."); - - arguments = php_amqp_type_convert_zval_to_amqp_table(PHP_AMQP_READ_THIS_PROP("arguments") TSRMLS_CC); - - amqp_queue_declare_ok_t *r = amqp_queue_declare( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), - PHP_AMQP_READ_THIS_PROP_BOOL("passive"), - PHP_AMQP_READ_THIS_PROP_BOOL("durable"), - PHP_AMQP_READ_THIS_PROP_BOOL("exclusive"), - PHP_AMQP_READ_THIS_PROP_BOOL("auto_delete"), - *arguments - ); - - php_amqp_type_free_amqp_table(arguments); + zval rv; + + amqp_channel_resource *channel_resource; + + char *name; + amqp_table_t *arguments; + zend_long message_count; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not declare queue."); + + arguments = php_amqp_type_convert_zval_to_amqp_table(PHP_AMQP_READ_THIS_PROP("arguments") TSRMLS_CC); + + amqp_queue_declare_ok_t *r = amqp_queue_declare( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), + PHP_AMQP_READ_THIS_PROP_BOOL("passive"), + PHP_AMQP_READ_THIS_PROP_BOOL("durable"), + PHP_AMQP_READ_THIS_PROP_BOOL("exclusive"), + PHP_AMQP_READ_THIS_PROP_BOOL("auto_delete"), + *arguments + ); + + php_amqp_type_free_amqp_table(arguments); + + if (!r) { + amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + + php_amqp_error( + res, + &PHP_AMQP_G(error_message), + channel_resource->connection_resource, + channel_resource TSRMLS_CC + ); + + php_amqp_zend_throw_exception( + res, + amqp_queue_exception_class_entry, + PHP_AMQP_G(error_message), + PHP_AMQP_G(error_code) TSRMLS_CC + ); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } + + message_count = r->message_count; + + /* Set the queue name, in case it is an autogenerated queue name */ + name = php_amqp_type_amqp_bytes_to_char(r->queue); + zend_update_property_string(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("name"), name TSRMLS_CC); + efree(name); - if (!r) { - amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - - php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource TSRMLS_CC); - - php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, PHP_AMQP_G(error_message), PHP_AMQP_G(error_code) TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } - - message_count = r->message_count; - - /* Set the queue name, in case it is an autogenerated queue name */ - name = php_amqp_type_amqp_bytes_to_char(r->queue); - zend_update_property_string(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("name"), name TSRMLS_CC); - efree(name); - - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - RETURN_LONG(message_count); + RETURN_LONG(message_count); } /* }}} */ @@ -367,55 +412,62 @@ bind queue to exchange by routing key */ static PHP_METHOD(amqp_queue_class, bind) { - zval rv; - - zval *zvalArguments = NULL; - - amqp_channel_resource *channel_resource; - - char *exchange_name; size_t exchange_name_len; - char *keyname = NULL; size_t keyname_len = 0; - - amqp_table_t *arguments = NULL; + zval rv; + + zval *zvalArguments = NULL; + + amqp_channel_resource *channel_resource; + + char *exchange_name; + size_t exchange_name_len; + char *keyname = NULL; + size_t keyname_len = 0; + + amqp_table_t *arguments = NULL; + + if (zend_parse_parameters( + ZEND_NUM_ARGS() TSRMLS_CC, + "s|s!a", + &exchange_name, + &exchange_name_len, + &keyname, + &keyname_len, + &zvalArguments + ) == FAILURE) { + return; + } + + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not bind queue."); + + if (zvalArguments) { + arguments = php_amqp_type_convert_zval_to_amqp_table(zvalArguments TSRMLS_CC); + } + + amqp_queue_bind( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), + (exchange_name_len > 0 ? amqp_cstring_bytes(exchange_name) : amqp_empty_bytes), + (keyname_len > 0 ? amqp_cstring_bytes(keyname) : amqp_empty_bytes), + (arguments ? *arguments : amqp_empty_table) + ); + + if (arguments) { + php_amqp_type_free_amqp_table(arguments); + } + + amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry TSRMLS_CC); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!a", - &exchange_name, &exchange_name_len, - &keyname, &keyname_len, - &zvalArguments) == FAILURE) { - return; - } - - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); - PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not bind queue."); - - if (zvalArguments) { - arguments = php_amqp_type_convert_zval_to_amqp_table(zvalArguments TSRMLS_CC); - } - - amqp_queue_bind( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), - (exchange_name_len > 0 ? amqp_cstring_bytes(exchange_name) : amqp_empty_bytes), - (keyname_len > 0 ? amqp_cstring_bytes(keyname) : amqp_empty_bytes), - (arguments ? *arguments : amqp_empty_table) - ); - - if (arguments) { - php_amqp_type_free_amqp_table(arguments); - } - - amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } - - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -426,79 +478,79 @@ return array (messages) */ static PHP_METHOD(amqp_queue_class, get) { - zval rv; + zval rv; - amqp_channel_resource *channel_resource; + amqp_channel_resource *channel_resource; - zval message; + zval message; - zend_long flags = INI_INT("amqp.auto_ack") ? AMQP_AUTOACK : AMQP_NOPARAM; + zend_long flags = INI_INT("amqp.auto_ack") ? AMQP_AUTOACK : AMQP_NOPARAM; - /* Parse out the method parameters */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags) == FAILURE) { - return; - } + /* Parse out the method parameters */ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags) == FAILURE) { + return; + } - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); - PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not get messages from queue."); + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not get messages from queue."); - amqp_rpc_reply_t res = amqp_basic_get( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), - (AMQP_AUTOACK & flags) ? 1 : 0 - ); + amqp_rpc_reply_t res = amqp_basic_get( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), + (AMQP_AUTOACK & flags) ? 1 : 0 + ); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry TSRMLS_CC); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } - if (AMQP_BASIC_GET_EMPTY_METHOD == res.reply.id) { - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - RETURN_FALSE; - } + if (AMQP_BASIC_GET_EMPTY_METHOD == res.reply.id) { + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + RETURN_FALSE; + } - assert(AMQP_BASIC_GET_OK_METHOD == res.reply.id); + assert(AMQP_BASIC_GET_OK_METHOD == res.reply.id); - /* Fill the envelope from response */ - amqp_basic_get_ok_t *get_ok_method = res.reply.decoded; + /* Fill the envelope from response */ + amqp_basic_get_ok_t *get_ok_method = res.reply.decoded; - amqp_envelope_t envelope; + amqp_envelope_t envelope; - envelope.channel = channel_resource->channel_id; - envelope.consumer_tag = amqp_empty_bytes; - envelope.delivery_tag = get_ok_method->delivery_tag; - envelope.redelivered = get_ok_method->redelivered; - envelope.exchange = amqp_bytes_malloc_dup(get_ok_method->exchange); - envelope.routing_key = amqp_bytes_malloc_dup(get_ok_method->routing_key); + envelope.channel = channel_resource->channel_id; + envelope.consumer_tag = amqp_empty_bytes; + envelope.delivery_tag = get_ok_method->delivery_tag; + envelope.redelivered = get_ok_method->redelivered; + envelope.exchange = amqp_bytes_malloc_dup(get_ok_method->exchange); + envelope.routing_key = amqp_bytes_malloc_dup(get_ok_method->routing_key); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - res = amqp_read_message( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - &envelope.message, - 0 - ); + res = amqp_read_message( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + &envelope.message, + 0 + ); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - amqp_destroy_envelope(&envelope); - return; - } + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry TSRMLS_CC); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + amqp_destroy_envelope(&envelope); + return; + } - ZVAL_UNDEF(&message); + ZVAL_UNDEF(&message); - convert_amqp_envelope_to_zval(&envelope, &message TSRMLS_CC); + convert_amqp_envelope_to_zval(&envelope, &message TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - amqp_destroy_envelope(&envelope); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + amqp_destroy_envelope(&envelope); - RETVAL_ZVAL(&message, 1, 0); - zval_ptr_dtor(&message); + RETVAL_ZVAL(&message, 1, 0); + zval_ptr_dtor(&message); } /* }}} */ @@ -508,236 +560,297 @@ consume the message */ static PHP_METHOD(amqp_queue_class, consume) { - zval rv; - - zval current_channel_zv; - - zval *current_queue_zv = NULL; - - amqp_channel_resource *channel_resource; - amqp_channel_resource *current_channel_resource; - - zend_fcall_info fci = empty_fcall_info; - zend_fcall_info_cache fci_cache = empty_fcall_info_cache; - - amqp_table_t *arguments; - - char *consumer_tag = NULL; size_t consumer_tag_len = 0; - zend_long flags = INI_INT("amqp.auto_ack") ? AMQP_AUTOACK : AMQP_NOPARAM; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|f!ls", - &fci, &fci_cache, - &flags, - &consumer_tag, &consumer_tag_len) == FAILURE) { - return; - } - - zval *channel_zv = PHP_AMQP_READ_THIS_PROP("channel"); - zval *consumers = zend_read_property(amqp_channel_class_entry, PHP_AMQP_COMPAT_OBJ_P(channel_zv), ZEND_STRL("consumers"), 0 , &rv TSRMLS_CC); - - if (IS_ARRAY != Z_TYPE_P(consumers)) { - zend_throw_exception(amqp_queue_exception_class_entry, "Invalid channel consumers, forgot to call channel constructor?", 0 TSRMLS_CC); - return; - } - - amqp_channel_object *channel = PHP_AMQP_GET_CHANNEL(channel_zv); - - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(channel_zv); - PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not get channel."); - - if (!(AMQP_JUST_CONSUME & flags)) { - /* Setup the consume */ - arguments = php_amqp_type_convert_zval_to_amqp_table(PHP_AMQP_READ_THIS_PROP("arguments") TSRMLS_CC); - - amqp_basic_consume_ok_t *r = amqp_basic_consume( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), - (consumer_tag_len > 0 ? amqp_cstring_bytes(consumer_tag) : amqp_empty_bytes), /* Consumer tag */ - (AMQP_NOLOCAL & flags) ? 1 : 0, /* No local */ - (AMQP_AUTOACK & flags) ? 1 : 0, /* no_ack, aka AUTOACK */ - PHP_AMQP_READ_THIS_PROP_BOOL("exclusive"), - *arguments - ); - - php_amqp_type_free_amqp_table(arguments); - - if (!r) { - amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - - php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource TSRMLS_CC); - - zend_throw_exception(amqp_queue_exception_class_entry, PHP_AMQP_G(error_message), PHP_AMQP_G(error_code) TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } - - char *key; - key = estrndup((char *) r->consumer_tag.bytes, (unsigned) r->consumer_tag.len); - - if (zend_hash_str_find(Z_ARRVAL_P(consumers), key, r->consumer_tag.len) != NULL) { - // This should never happen as AMQP server guarantees that consumer tag is unique within channel - zend_throw_exception(amqp_exception_class_entry, "Duplicate consumer tag", 0 TSRMLS_CC); - efree(key); - return; - } - - zval tmp; - - ZVAL_UNDEF(&tmp); - ZVAL_COPY(&tmp, getThis()); - - zend_hash_str_add(Z_ARRVAL_P(consumers), key, r->consumer_tag.len, &tmp); - efree(key); - - /* Set the consumer tag name, in case it is an autogenerated consumer tag name */ - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("consumer_tag"), (const char *) r->consumer_tag.bytes, (size_t) r->consumer_tag.len TSRMLS_CC); - } - - if (!ZEND_FCI_INITIALIZED(fci)) { - /* Callback not set, we have nothing to do - real consuming may happens later */ - return; - } - - struct timeval tv = {0}; - struct timeval *tv_ptr = &tv; - - double read_timeout = PHP_AMQP_READ_OBJ_PROP_DOUBLE(amqp_connection_class_entry, PHP_AMQP_READ_THIS_PROP("connection"), "read_timeout"); - - if (read_timeout > 0) { - tv.tv_sec = (long int) read_timeout; - tv.tv_usec = (long int) ((read_timeout - tv.tv_sec) * 1000000); - } else { - tv_ptr = NULL; - } - - while(1) { - /* Initialize the message */ - zval message; - - amqp_envelope_t envelope; - - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - - amqp_rpc_reply_t res = amqp_consume_message(channel_resource->connection_resource->connection_state, &envelope, tv_ptr, 0); - - if (AMQP_RESPONSE_LIBRARY_EXCEPTION == res.reply_type && AMQP_STATUS_TIMEOUT == res.library_error) { - zend_throw_exception(amqp_queue_exception_class_entry, "Consumer timeout exceed", 0 TSRMLS_CC); - - amqp_destroy_envelope(&envelope); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } - - if (PHP_AMQP_MAYBE_ERROR_RECOVERABLE(res, channel_resource)) { - - if (PHP_AMQP_IS_ERROR_RECOVERABLE(res, channel_resource, channel)) { - /* In case no message was received, continue the loop */ - amqp_destroy_envelope(&envelope); - - continue; - } else { - /* Mark connection resource as closed to prevent sending any further requests */ - channel_resource->connection_resource->is_connected = '\0'; - - /* Close connection with all its channels */ - php_amqp_disconnect_force(channel_resource->connection_resource TSRMLS_CC); - } - - php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry TSRMLS_CC); - - amqp_destroy_envelope(&envelope); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - - return; - } + zval rv; + + zval current_channel_zv; + + zval *current_queue_zv = NULL; + + amqp_channel_resource *channel_resource; + amqp_channel_resource *current_channel_resource; + + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fci_cache = empty_fcall_info_cache; + + amqp_table_t *arguments; + + char *consumer_tag = NULL; + size_t consumer_tag_len = 0; + zend_long flags = INI_INT("amqp.auto_ack") ? AMQP_AUTOACK : AMQP_NOPARAM; + + if (zend_parse_parameters( + ZEND_NUM_ARGS() TSRMLS_CC, + "|f!ls", + &fci, + &fci_cache, + &flags, + &consumer_tag, + &consumer_tag_len + ) == FAILURE) { + return; + } + + zval *channel_zv = PHP_AMQP_READ_THIS_PROP("channel"); + zval *consumers = zend_read_property( + amqp_channel_class_entry, + PHP_AMQP_COMPAT_OBJ_P(channel_zv), + ZEND_STRL("consumers"), + 0, + &rv TSRMLS_CC + ); + + if (IS_ARRAY != Z_TYPE_P(consumers)) { + zend_throw_exception( + amqp_queue_exception_class_entry, + "Invalid channel consumers, forgot to call channel constructor?", + 0 TSRMLS_CC + ); + return; + } + + amqp_channel_object *channel = PHP_AMQP_GET_CHANNEL(channel_zv); + + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(channel_zv); + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not get channel."); + + if (!(AMQP_JUST_CONSUME & flags)) { + /* Setup the consume */ + arguments = php_amqp_type_convert_zval_to_amqp_table(PHP_AMQP_READ_THIS_PROP("arguments") TSRMLS_CC); + + amqp_basic_consume_ok_t *r = amqp_basic_consume( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), + (consumer_tag_len > 0 ? amqp_cstring_bytes(consumer_tag) : amqp_empty_bytes), /* Consumer tag */ + (AMQP_NOLOCAL & flags) ? 1 : 0, /* No local */ + (AMQP_AUTOACK & flags) ? 1 : 0, /* no_ack, aka AUTOACK */ + PHP_AMQP_READ_THIS_PROP_BOOL("exclusive"), + *arguments + ); + + php_amqp_type_free_amqp_table(arguments); + + if (!r) { + amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + + php_amqp_error( + res, + &PHP_AMQP_G(error_message), + channel_resource->connection_resource, + channel_resource TSRMLS_CC + ); + + zend_throw_exception( + amqp_queue_exception_class_entry, + PHP_AMQP_G(error_message), + PHP_AMQP_G(error_code) TSRMLS_CC + ); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } + + char *key; + key = estrndup((char *) r->consumer_tag.bytes, (unsigned) r->consumer_tag.len); + + if (zend_hash_str_find(Z_ARRVAL_P(consumers), key, r->consumer_tag.len) != NULL) { + // This should never happen as AMQP server guarantees that consumer tag is unique within channel + zend_throw_exception(amqp_exception_class_entry, "Duplicate consumer tag", 0 TSRMLS_CC); + efree(key); + return; + } + + zval tmp; + + ZVAL_UNDEF(&tmp); + ZVAL_COPY(&tmp, getThis()); + + zend_hash_str_add(Z_ARRVAL_P(consumers), key, r->consumer_tag.len, &tmp); + efree(key); + + /* Set the consumer tag name, in case it is an autogenerated consumer tag name */ + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("consumer_tag"), + (const char *) r->consumer_tag.bytes, + (size_t) r->consumer_tag.len TSRMLS_CC + ); + } + + if (!ZEND_FCI_INITIALIZED(fci)) { + /* Callback not set, we have nothing to do - real consuming may happens later */ + return; + } + + struct timeval tv = {0}; + struct timeval *tv_ptr = &tv; + + double read_timeout = PHP_AMQP_READ_OBJ_PROP_DOUBLE( + amqp_connection_class_entry, + PHP_AMQP_READ_THIS_PROP("connection"), + "read_timeout" + ); + + if (read_timeout > 0) { + tv.tv_sec = (long int) read_timeout; + tv.tv_usec = (long int) ((read_timeout - tv.tv_sec) * 1000000); + } else { + tv_ptr = NULL; + } + + while (1) { + /* Initialize the message */ + zval message; + + amqp_envelope_t envelope; + + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + + amqp_rpc_reply_t res = + amqp_consume_message(channel_resource->connection_resource->connection_state, &envelope, tv_ptr, 0); + + if (AMQP_RESPONSE_LIBRARY_EXCEPTION == res.reply_type && AMQP_STATUS_TIMEOUT == res.library_error) { + zend_throw_exception(amqp_queue_exception_class_entry, "Consumer timeout exceed", 0 TSRMLS_CC); + + amqp_destroy_envelope(&envelope); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } + + if (PHP_AMQP_MAYBE_ERROR_RECOVERABLE(res, channel_resource)) { + + if (PHP_AMQP_IS_ERROR_RECOVERABLE(res, channel_resource, channel)) { + /* In case no message was received, continue the loop */ + amqp_destroy_envelope(&envelope); + + continue; + } else { + /* Mark connection resource as closed to prevent sending any further requests */ + channel_resource->connection_resource->is_connected = '\0'; + + /* Close connection with all its channels */ + php_amqp_disconnect_force(channel_resource->connection_resource TSRMLS_CC); + } + + php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry TSRMLS_CC); + + amqp_destroy_envelope(&envelope); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + + return; + } + + ZVAL_UNDEF(&message); + convert_amqp_envelope_to_zval(&envelope, &message TSRMLS_CC); + + current_channel_resource = channel_resource->connection_resource->slots[envelope.channel - 1]; + + if (!current_channel_resource) { + // This should never happen, but just in case + php_amqp_zend_throw_exception( + res, + amqp_queue_exception_class_entry, + "Orphaned channel. Please, report a bug.", + 0 TSRMLS_CC + ); + amqp_destroy_envelope(&envelope); + break; + } + + ZVAL_UNDEF(¤t_channel_zv); + ZVAL_OBJ(¤t_channel_zv, ¤t_channel_resource->parent->zo); + + consumers = zend_read_property( + amqp_channel_class_entry, + PHP_AMQP_COMPAT_OBJ_P(¤t_channel_zv), + ZEND_STRL("consumers"), + 0, + &rv TSRMLS_CC + ); + + if (IS_ARRAY != Z_TYPE_P(consumers)) { + zend_throw_exception( + amqp_queue_exception_class_entry, + "Invalid channel consumers, forgot to call channel constructor?", + 0 TSRMLS_CC + ); + amqp_destroy_envelope(&envelope); + break; + } + + char *key; + key = estrndup((char *) envelope.consumer_tag.bytes, (unsigned) envelope.consumer_tag.len); + + if ((current_queue_zv = zend_hash_str_find(Z_ARRVAL_P(consumers), key, envelope.consumer_tag.len)) == NULL) { + zval exception; + ZVAL_UNDEF(&exception); + object_init_ex(&exception, amqp_envelope_exception_class_entry); + zend_update_property_string( + zend_exception_get_default(TSRMLS_C), + PHP_AMQP_COMPAT_OBJ_P(&exception), + ZEND_STRL("message"), + "Orphaned envelope" TSRMLS_CC + ); + zend_update_property( + amqp_envelope_exception_class_entry, + PHP_AMQP_COMPAT_OBJ_P(&exception), + ZEND_STRL("envelope"), + &message TSRMLS_CC + ); + + zend_throw_exception_object(&exception TSRMLS_CC); + + zval_ptr_dtor(&message); + + amqp_destroy_envelope(&envelope); + efree(key); + break; + } + + efree(key); + amqp_destroy_envelope(&envelope); + + /* Make the callback */ + zval params; + zval retval; + + /* Build the parameter array */ + ZVAL_UNDEF(¶ms); + array_init(¶ms); + + /* Dump it into the params array */ + add_index_zval(¶ms, 0, &message); + Z_ADDREF_P(&message); + + /* Add a pointer to the queue: */ + add_index_zval(¶ms, 1, current_queue_zv); + Z_ADDREF_P(current_queue_zv); + + + /* Convert everything to be callable */ + zend_fcall_info_args(&fci, ¶ms TSRMLS_CC); + /* Initialize the return value pointer */ + + fci.retval = &retval; + + /* Call the function, and track the return value */ + if (zend_call_function(&fci, &fci_cache TSRMLS_CC) == SUCCESS && fci.retval) { + RETVAL_ZVAL(&retval, 1, 1); + } + + /* Clean up our mess */ + zend_fcall_info_args_clear(&fci, 1); + zval_ptr_dtor(¶ms); + zval_ptr_dtor(&message); + + /* Check if user land function wants to bail */ + if (EG(exception) || Z_TYPE_P(return_value) == IS_FALSE) { + break; + } + } - ZVAL_UNDEF(&message); - convert_amqp_envelope_to_zval(&envelope, &message TSRMLS_CC); - - current_channel_resource = channel_resource->connection_resource->slots[envelope.channel - 1]; - - if (!current_channel_resource) { - // This should never happen, but just in case - php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, "Orphaned channel. Please, report a bug.", 0 TSRMLS_CC); - amqp_destroy_envelope(&envelope); - break; - } - - ZVAL_UNDEF(¤t_channel_zv); - ZVAL_OBJ(¤t_channel_zv, ¤t_channel_resource->parent->zo); - - consumers = zend_read_property(amqp_channel_class_entry, PHP_AMQP_COMPAT_OBJ_P(¤t_channel_zv), ZEND_STRL("consumers"), 0 , &rv TSRMLS_CC); - - if (IS_ARRAY != Z_TYPE_P(consumers)) { - zend_throw_exception(amqp_queue_exception_class_entry, "Invalid channel consumers, forgot to call channel constructor?", 0 TSRMLS_CC); - amqp_destroy_envelope(&envelope); - break; - } - - char *key; - key = estrndup((char *)envelope.consumer_tag.bytes, (unsigned) envelope.consumer_tag.len); - - if ((current_queue_zv = zend_hash_str_find(Z_ARRVAL_P(consumers), key, envelope.consumer_tag.len)) == NULL) { - zval exception; - ZVAL_UNDEF(&exception); - object_init_ex(&exception, amqp_envelope_exception_class_entry); - zend_update_property_string(zend_exception_get_default(TSRMLS_C), PHP_AMQP_COMPAT_OBJ_P(&exception), ZEND_STRL("message"), "Orphaned envelope" TSRMLS_CC); - zend_update_property(amqp_envelope_exception_class_entry, PHP_AMQP_COMPAT_OBJ_P(&exception), ZEND_STRL("envelope"), &message TSRMLS_CC); - - zend_throw_exception_object(&exception TSRMLS_CC); - - zval_ptr_dtor(&message); - - amqp_destroy_envelope(&envelope); - efree(key); - break; - } - - efree(key); - amqp_destroy_envelope(&envelope); - - /* Make the callback */ - zval params; - zval retval; - - /* Build the parameter array */ - ZVAL_UNDEF(¶ms); - array_init(¶ms); - - /* Dump it into the params array */ - add_index_zval(¶ms, 0, &message); - Z_ADDREF_P( &message); - - /* Add a pointer to the queue: */ - add_index_zval(¶ms, 1, current_queue_zv); - Z_ADDREF_P(current_queue_zv); - - - /* Convert everything to be callable */ - zend_fcall_info_args(&fci, ¶ms TSRMLS_CC); - /* Initialize the return value pointer */ - - fci.retval = &retval; - - /* Call the function, and track the return value */ - if (zend_call_function(&fci, &fci_cache TSRMLS_CC) == SUCCESS && fci.retval) { - RETVAL_ZVAL(&retval, 1, 1); - } - - /* Clean up our mess */ - zend_fcall_info_args_clear(&fci, 1); - zval_ptr_dtor(¶ms); - zval_ptr_dtor(&message); - - /* Check if user land function wants to bail */ - if (EG(exception) || Z_TYPE_P(return_value) == IS_FALSE) { - break; - } - } - - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; } /* }}} */ @@ -747,42 +860,52 @@ static PHP_METHOD(amqp_queue_class, consume) */ static PHP_METHOD(amqp_queue_class, ack) { - zval rv; - - amqp_channel_resource *channel_resource; - - zend_long deliveryTag = 0; - zend_long flags = AMQP_NOPARAM; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &deliveryTag, &flags ) == FAILURE) { - return; - } - - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); - PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not ack message."); - - /* NOTE: basic.ack is asynchronous and thus will not indicate failure if something goes wrong on the broker */ - int status = amqp_basic_ack( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - (uint64_t) deliveryTag, - (AMQP_MULTIPLE & flags) ? 1 : 0 - ); - - if (status != AMQP_STATUS_OK) { - /* Emulate library error */ - amqp_rpc_reply_t res; - res.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; - res.library_error = status; - - php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource TSRMLS_CC); - - php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, PHP_AMQP_G(error_message), PHP_AMQP_G(error_code) TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } - - RETURN_TRUE; + zval rv; + + amqp_channel_resource *channel_resource; + + zend_long deliveryTag = 0; + zend_long flags = AMQP_NOPARAM; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &deliveryTag, &flags) == FAILURE) { + return; + } + + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not ack message."); + + /* NOTE: basic.ack is asynchronous and thus will not indicate failure if something goes wrong on the broker */ + int status = amqp_basic_ack( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + (uint64_t) deliveryTag, + (AMQP_MULTIPLE & flags) ? 1 : 0 + ); + + if (status != AMQP_STATUS_OK) { + /* Emulate library error */ + amqp_rpc_reply_t res; + res.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; + res.library_error = status; + + php_amqp_error( + res, + &PHP_AMQP_G(error_message), + channel_resource->connection_resource, + channel_resource TSRMLS_CC + ); + + php_amqp_zend_throw_exception( + res, + amqp_queue_exception_class_entry, + PHP_AMQP_G(error_message), + PHP_AMQP_G(error_code) TSRMLS_CC + ); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } + + RETURN_TRUE; } /* }}} */ @@ -792,43 +915,53 @@ static PHP_METHOD(amqp_queue_class, ack) */ static PHP_METHOD(amqp_queue_class, nack) { - zval rv; - - amqp_channel_resource *channel_resource; - - zend_long deliveryTag = 0; - zend_long flags = AMQP_NOPARAM; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &deliveryTag, &flags ) == FAILURE) { - return; - } - - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); - PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not nack message."); - - /* NOTE: basic.nack is asynchronous and thus will not indicate failure if something goes wrong on the broker */ - int status = amqp_basic_nack( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - (uint64_t) deliveryTag, - (AMQP_MULTIPLE & flags) ? 1 : 0, - (AMQP_REQUEUE & flags) ? 1 : 0 - ); - - if (status != AMQP_STATUS_OK) { - /* Emulate library error */ - amqp_rpc_reply_t res; - res.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; - res.library_error = status; - - php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource TSRMLS_CC); - - php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, PHP_AMQP_G(error_message), PHP_AMQP_G(error_code) TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } - - RETURN_TRUE; + zval rv; + + amqp_channel_resource *channel_resource; + + zend_long deliveryTag = 0; + zend_long flags = AMQP_NOPARAM; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &deliveryTag, &flags) == FAILURE) { + return; + } + + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not nack message."); + + /* NOTE: basic.nack is asynchronous and thus will not indicate failure if something goes wrong on the broker */ + int status = amqp_basic_nack( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + (uint64_t) deliveryTag, + (AMQP_MULTIPLE & flags) ? 1 : 0, + (AMQP_REQUEUE & flags) ? 1 : 0 + ); + + if (status != AMQP_STATUS_OK) { + /* Emulate library error */ + amqp_rpc_reply_t res; + res.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; + res.library_error = status; + + php_amqp_error( + res, + &PHP_AMQP_G(error_message), + channel_resource->connection_resource, + channel_resource TSRMLS_CC + ); + + php_amqp_zend_throw_exception( + res, + amqp_queue_exception_class_entry, + PHP_AMQP_G(error_message), + PHP_AMQP_G(error_code) TSRMLS_CC + ); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } + + RETURN_TRUE; } /* }}} */ @@ -838,42 +971,52 @@ static PHP_METHOD(amqp_queue_class, nack) */ static PHP_METHOD(amqp_queue_class, reject) { - zval rv; - - amqp_channel_resource *channel_resource; - - zend_long deliveryTag = 0; - zend_long flags = AMQP_NOPARAM; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &deliveryTag, &flags) == FAILURE) { - return; - } - - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); - PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not reject message."); - - /* NOTE: basic.reject is asynchronous and thus will not indicate failure if something goes wrong on the broker */ - int status = amqp_basic_reject( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - (uint64_t) deliveryTag, - (AMQP_REQUEUE & flags) ? 1 : 0 - ); - - if (status != AMQP_STATUS_OK) { - /* Emulate library error */ - amqp_rpc_reply_t res; - res.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; - res.library_error = status; - - php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource TSRMLS_CC); - - php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, PHP_AMQP_G(error_message), PHP_AMQP_G(error_code) TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } - - RETURN_TRUE; + zval rv; + + amqp_channel_resource *channel_resource; + + zend_long deliveryTag = 0; + zend_long flags = AMQP_NOPARAM; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &deliveryTag, &flags) == FAILURE) { + return; + } + + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not reject message."); + + /* NOTE: basic.reject is asynchronous and thus will not indicate failure if something goes wrong on the broker */ + int status = amqp_basic_reject( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + (uint64_t) deliveryTag, + (AMQP_REQUEUE & flags) ? 1 : 0 + ); + + if (status != AMQP_STATUS_OK) { + /* Emulate library error */ + amqp_rpc_reply_t res; + res.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; + res.library_error = status; + + php_amqp_error( + res, + &PHP_AMQP_G(error_message), + channel_resource->connection_resource, + channel_resource TSRMLS_CC + ); + + php_amqp_zend_throw_exception( + res, + amqp_queue_exception_class_entry, + PHP_AMQP_G(error_message), + PHP_AMQP_G(error_code) TSRMLS_CC + ); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } + + RETURN_TRUE; } /* }}} */ @@ -883,41 +1026,51 @@ purge queue */ static PHP_METHOD(amqp_queue_class, purge) { - zval rv; + zval rv; - amqp_channel_resource *channel_resource; + amqp_channel_resource *channel_resource; - if (zend_parse_parameters_none() == FAILURE) { - return; - } + if (zend_parse_parameters_none() == FAILURE) { + return; + } - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); - PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not purge queue."); + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not purge queue."); - amqp_queue_purge_ok_t *r = amqp_queue_purge( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")) - ); + amqp_queue_purge_ok_t *r = amqp_queue_purge( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")) + ); - if (!r) { - amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + if (!r) { + amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource TSRMLS_CC); + php_amqp_error( + res, + &PHP_AMQP_G(error_message), + channel_resource->connection_resource, + channel_resource TSRMLS_CC + ); - php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, PHP_AMQP_G(error_message), PHP_AMQP_G(error_code) TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } + php_amqp_zend_throw_exception( + res, + amqp_queue_exception_class_entry, + PHP_AMQP_G(error_message), + PHP_AMQP_G(error_code) TSRMLS_CC + ); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } - /* long message_count = r->message_count; */ + /* long message_count = r->message_count; */ - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - /* RETURN_LONG(message_count) */; + /* RETURN_LONG(message_count) */; - /* BC */ - RETURN_TRUE; + /* BC */ + RETURN_TRUE; } /* }}} */ @@ -927,58 +1080,81 @@ cancel queue to consumer */ static PHP_METHOD(amqp_queue_class, cancel) { - zval rv; - - amqp_channel_resource *channel_resource; - - char *consumer_tag = NULL; - size_t consumer_tag_len = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &consumer_tag, &consumer_tag_len) == FAILURE) { - return; - } - - zval *channel_zv = PHP_AMQP_READ_THIS_PROP("channel"); - zval *consumers = zend_read_property(amqp_channel_class_entry, PHP_AMQP_COMPAT_OBJ_P(channel_zv), ZEND_STRL("consumers"), 0 , &rv TSRMLS_CC); - zend_bool previous_consumer_tag_exists = (zend_bool) (IS_STRING == Z_TYPE_P(PHP_AMQP_READ_THIS_PROP("consumer_tag"))); - - if (IS_ARRAY != Z_TYPE_P(consumers)) { - zend_throw_exception(amqp_queue_exception_class_entry, "Invalid channel consumers, forgot to call channel constructor?", 0 TSRMLS_CC); - return; - } - - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(channel_zv); - PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not cancel queue."); - - if (!consumer_tag_len && (!previous_consumer_tag_exists || !PHP_AMQP_READ_THIS_PROP_STRLEN("consumer_tag"))) { - return; - } - - amqp_basic_cancel_ok_t *r = amqp_basic_cancel( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - consumer_tag_len > 0 ? amqp_cstring_bytes(consumer_tag) : amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("consumer_tag")) - ); - - if (!r) { - amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - - php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource TSRMLS_CC); - - php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, PHP_AMQP_G(error_message), PHP_AMQP_G(error_code) TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } - - if (!consumer_tag_len || (previous_consumer_tag_exists && strcmp(consumer_tag, PHP_AMQP_READ_THIS_PROP_STR("consumer_tag")) == 0)) { - zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("consumer_tag") TSRMLS_CC); - } - - zend_hash_str_del_ind(Z_ARRVAL_P(consumers), r->consumer_tag.bytes, r->consumer_tag.len); + zval rv; + + amqp_channel_resource *channel_resource; + + char *consumer_tag = NULL; + size_t consumer_tag_len = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &consumer_tag, &consumer_tag_len) == FAILURE) { + return; + } + + zval *channel_zv = PHP_AMQP_READ_THIS_PROP("channel"); + zval *consumers = zend_read_property( + amqp_channel_class_entry, + PHP_AMQP_COMPAT_OBJ_P(channel_zv), + ZEND_STRL("consumers"), + 0, + &rv TSRMLS_CC + ); + zend_bool previous_consumer_tag_exists = + (zend_bool) (IS_STRING == Z_TYPE_P(PHP_AMQP_READ_THIS_PROP("consumer_tag"))); + + if (IS_ARRAY != Z_TYPE_P(consumers)) { + zend_throw_exception( + amqp_queue_exception_class_entry, + "Invalid channel consumers, forgot to call channel constructor?", + 0 TSRMLS_CC + ); + return; + } + + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(channel_zv); + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not cancel queue."); + + if (!consumer_tag_len && (!previous_consumer_tag_exists || !PHP_AMQP_READ_THIS_PROP_STRLEN("consumer_tag"))) { + return; + } + + amqp_basic_cancel_ok_t *r = amqp_basic_cancel( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + consumer_tag_len > 0 ? amqp_cstring_bytes(consumer_tag) + : amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("consumer_tag")) + ); + + if (!r) { + amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + + php_amqp_error( + res, + &PHP_AMQP_G(error_message), + channel_resource->connection_resource, + channel_resource TSRMLS_CC + ); + + php_amqp_zend_throw_exception( + res, + amqp_queue_exception_class_entry, + PHP_AMQP_G(error_message), + PHP_AMQP_G(error_code) TSRMLS_CC + ); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } + + if (!consumer_tag_len || + (previous_consumer_tag_exists && strcmp(consumer_tag, PHP_AMQP_READ_THIS_PROP_STR("consumer_tag")) == 0)) { + zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("consumer_tag") TSRMLS_CC); + } + + zend_hash_str_del_ind(Z_ARRVAL_P(consumers), r->consumer_tag.bytes, r->consumer_tag.len); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -988,54 +1164,61 @@ unbind queue from exchange */ static PHP_METHOD(amqp_queue_class, unbind) { - zval rv; - - zval *zvalArguments = NULL; - amqp_channel_resource *channel_resource; - - char *exchange_name; size_t exchange_name_len; - char *keyname = NULL; size_t keyname_len = 0; - - amqp_table_t *arguments = NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sa", - &exchange_name, &exchange_name_len, - &keyname, &keyname_len, - &zvalArguments) == FAILURE) { - return; - } - - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); - PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not unbind queue."); - - if (zvalArguments) { - arguments = php_amqp_type_convert_zval_to_amqp_table(zvalArguments TSRMLS_CC); - } + zval rv; + + zval *zvalArguments = NULL; + amqp_channel_resource *channel_resource; + + char *exchange_name; + size_t exchange_name_len; + char *keyname = NULL; + size_t keyname_len = 0; + + amqp_table_t *arguments = NULL; + + if (zend_parse_parameters( + ZEND_NUM_ARGS() TSRMLS_CC, + "s|sa", + &exchange_name, + &exchange_name_len, + &keyname, + &keyname_len, + &zvalArguments + ) == FAILURE) { + return; + } + + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not unbind queue."); + + if (zvalArguments) { + arguments = php_amqp_type_convert_zval_to_amqp_table(zvalArguments TSRMLS_CC); + } + + amqp_queue_unbind( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), + (exchange_name_len > 0 ? amqp_cstring_bytes(exchange_name) : amqp_empty_bytes), + (keyname_len > 0 ? amqp_cstring_bytes(keyname) : amqp_empty_bytes), + (arguments ? *arguments : amqp_empty_table) + ); + + if (arguments) { + php_amqp_type_free_amqp_table(arguments); + } + + amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry TSRMLS_CC); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } - amqp_queue_unbind( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), - (exchange_name_len > 0 ? amqp_cstring_bytes(exchange_name) : amqp_empty_bytes), - (keyname_len > 0 ? amqp_cstring_bytes(keyname) : amqp_empty_bytes), - (arguments ? *arguments : amqp_empty_table) - ); - - if (arguments) { - php_amqp_type_free_amqp_table(arguments); - } - - amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } - - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -1045,44 +1228,54 @@ delete queue and return the number of messages deleted in it */ static PHP_METHOD(amqp_queue_class, delete) { - zval rv; + zval rv; - amqp_channel_resource *channel_resource; + amqp_channel_resource *channel_resource; - zend_long flags = AMQP_NOPARAM; + zend_long flags = AMQP_NOPARAM; - zend_long message_count; + zend_long message_count; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags) == FAILURE) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags) == FAILURE) { + return; + } - channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); - PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not delete queue."); + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not delete queue."); - amqp_queue_delete_ok_t * r = amqp_queue_delete( - channel_resource->connection_resource->connection_state, - channel_resource->channel_id, - amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), - (AMQP_IFUNUSED & flags) ? 1 : 0, - (AMQP_IFEMPTY & flags) ? 1 : 0 - ); + amqp_queue_delete_ok_t *r = amqp_queue_delete( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), + (AMQP_IFUNUSED & flags) ? 1 : 0, + (AMQP_IFEMPTY & flags) ? 1 : 0 + ); - if (!r) { - amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + if (!r) { + amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource TSRMLS_CC); + php_amqp_error( + res, + &PHP_AMQP_G(error_message), + channel_resource->connection_resource, + channel_resource TSRMLS_CC + ); - php_amqp_zend_throw_exception(res, amqp_queue_exception_class_entry, PHP_AMQP_G(error_message), PHP_AMQP_G(error_code) TSRMLS_CC); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } + php_amqp_zend_throw_exception( + res, + amqp_queue_exception_class_entry, + PHP_AMQP_G(error_message), + PHP_AMQP_G(error_code) TSRMLS_CC + ); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } - message_count = r->message_count; + message_count = r->message_count; - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - RETURN_LONG(message_count); + RETURN_LONG(message_count); } /* }}} */ @@ -1090,9 +1283,9 @@ static PHP_METHOD(amqp_queue_class, delete) Get the AMQPChannel object in use */ static PHP_METHOD(amqp_queue_class, getChannel) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("channel"); + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("channel"); } /* }}} */ @@ -1100,9 +1293,9 @@ static PHP_METHOD(amqp_queue_class, getChannel) Get the AMQPConnection object in use */ static PHP_METHOD(amqp_queue_class, getConnection) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("connection"); + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("connection"); } /* }}} */ @@ -1110,100 +1303,100 @@ static PHP_METHOD(amqp_queue_class, getConnection) Get latest consumer tag*/ static PHP_METHOD(amqp_queue_class, getConsumerTag) { - zval rv; - PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("consumer_tag"); + zval rv; + PHP_AMQP_NOPARAMS(); + PHP_AMQP_RETURN_THIS_PROP("consumer_tag"); } /* }}} */ /* amqp_queue_class ARG_INFO definition */ ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class__construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_OBJ_INFO(0, amqp_channel, AMQPChannel, 0) + ZEND_ARG_OBJ_INFO(0, amqp_channel, AMQPChannel, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_getName, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_setName, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, queue_name) + ZEND_ARG_INFO(0, queue_name) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_getFlags, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_setFlags, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, flags) + ZEND_ARG_INFO(0, flags) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_getArgument, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, argument) + ZEND_ARG_INFO(0, argument) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_getArguments, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_setArgument, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 2) - ZEND_ARG_INFO(0, key) - ZEND_ARG_INFO(0, value) + ZEND_ARG_INFO(0, key) + ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_hasArgument, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, key) + ZEND_ARG_INFO(0, key) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_setArguments, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_ARRAY_INFO(0, arguments, 0) + ZEND_ARG_ARRAY_INFO(0, arguments, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_declareQueue, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_bind, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, exchange_name) - ZEND_ARG_INFO(0, routing_key) - ZEND_ARG_INFO(0, arguments) + ZEND_ARG_INFO(0, exchange_name) + ZEND_ARG_INFO(0, routing_key) + ZEND_ARG_INFO(0, arguments) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_get, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) - ZEND_ARG_INFO(0, flags) + ZEND_ARG_INFO(0, flags) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_consume, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, callback) - ZEND_ARG_INFO(0, flags) - ZEND_ARG_INFO(0, consumer_tag) + ZEND_ARG_INFO(0, callback) + ZEND_ARG_INFO(0, flags) + ZEND_ARG_INFO(0, consumer_tag) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_ack, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, delivery_tag) - ZEND_ARG_INFO(0, flags) + ZEND_ARG_INFO(0, delivery_tag) + ZEND_ARG_INFO(0, flags) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_nack, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, delivery_tag) - ZEND_ARG_INFO(0, flags) + ZEND_ARG_INFO(0, delivery_tag) + ZEND_ARG_INFO(0, flags) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_reject, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, delivery_tag) - ZEND_ARG_INFO(0, flags) + ZEND_ARG_INFO(0, delivery_tag) + ZEND_ARG_INFO(0, flags) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_purge, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_cancel, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) - ZEND_ARG_INFO(0, consumer_tag) + ZEND_ARG_INFO(0, consumer_tag) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_unbind, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, exchange_name) - ZEND_ARG_INFO(0, routing_key) - ZEND_ARG_INFO(0, arguments) + ZEND_ARG_INFO(0, exchange_name) + ZEND_ARG_INFO(0, routing_key) + ZEND_ARG_INFO(0, arguments) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_delete, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) - ZEND_ARG_INFO(0, flags) + ZEND_ARG_INFO(0, flags) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_getChannel, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) @@ -1216,75 +1409,64 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_getConsumerTag, ZEND_SEND_BY_VAL ZEND_END_ARG_INFO() zend_function_entry amqp_queue_class_functions[] = { - PHP_ME(amqp_queue_class, __construct, arginfo_amqp_queue_class__construct, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, __construct, arginfo_amqp_queue_class__construct, ZEND_ACC_PUBLIC) - PHP_ME(amqp_queue_class, getName, arginfo_amqp_queue_class_getName, ZEND_ACC_PUBLIC) - PHP_ME(amqp_queue_class, setName, arginfo_amqp_queue_class_setName, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, getName, arginfo_amqp_queue_class_getName, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, setName, arginfo_amqp_queue_class_setName, ZEND_ACC_PUBLIC) - PHP_ME(amqp_queue_class, getFlags, arginfo_amqp_queue_class_getFlags, ZEND_ACC_PUBLIC) - PHP_ME(amqp_queue_class, setFlags, arginfo_amqp_queue_class_setFlags, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, getFlags, arginfo_amqp_queue_class_getFlags, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, setFlags, arginfo_amqp_queue_class_setFlags, ZEND_ACC_PUBLIC) - PHP_ME(amqp_queue_class, getArgument, arginfo_amqp_queue_class_getArgument, ZEND_ACC_PUBLIC) - PHP_ME(amqp_queue_class, getArguments, arginfo_amqp_queue_class_getArguments, ZEND_ACC_PUBLIC) - PHP_ME(amqp_queue_class, setArgument, arginfo_amqp_queue_class_setArgument, ZEND_ACC_PUBLIC) - PHP_ME(amqp_queue_class, setArguments, arginfo_amqp_queue_class_setArguments, ZEND_ACC_PUBLIC) - PHP_ME(amqp_queue_class, hasArgument, arginfo_amqp_queue_class_hasArgument, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, getArgument, arginfo_amqp_queue_class_getArgument, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, getArguments, arginfo_amqp_queue_class_getArguments, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, setArgument, arginfo_amqp_queue_class_setArgument, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, setArguments, arginfo_amqp_queue_class_setArguments, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, hasArgument, arginfo_amqp_queue_class_hasArgument, ZEND_ACC_PUBLIC) - PHP_ME(amqp_queue_class, declareQueue, arginfo_amqp_queue_class_declareQueue, ZEND_ACC_PUBLIC) - PHP_ME(amqp_queue_class, bind, arginfo_amqp_queue_class_bind, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, declareQueue, arginfo_amqp_queue_class_declareQueue, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, bind, arginfo_amqp_queue_class_bind, ZEND_ACC_PUBLIC) - PHP_ME(amqp_queue_class, get, arginfo_amqp_queue_class_get, ZEND_ACC_PUBLIC) - PHP_ME(amqp_queue_class, consume, arginfo_amqp_queue_class_consume, ZEND_ACC_PUBLIC) - PHP_ME(amqp_queue_class, ack, arginfo_amqp_queue_class_ack, ZEND_ACC_PUBLIC) - PHP_ME(amqp_queue_class, nack, arginfo_amqp_queue_class_nack, ZEND_ACC_PUBLIC) - PHP_ME(amqp_queue_class, reject, arginfo_amqp_queue_class_reject, ZEND_ACC_PUBLIC) - PHP_ME(amqp_queue_class, purge, arginfo_amqp_queue_class_purge, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, get, arginfo_amqp_queue_class_get, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, consume, arginfo_amqp_queue_class_consume, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, ack, arginfo_amqp_queue_class_ack, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, nack, arginfo_amqp_queue_class_nack, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, reject, arginfo_amqp_queue_class_reject, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, purge, arginfo_amqp_queue_class_purge, ZEND_ACC_PUBLIC) - PHP_ME(amqp_queue_class, cancel, arginfo_amqp_queue_class_cancel, ZEND_ACC_PUBLIC) - PHP_ME(amqp_queue_class, delete, arginfo_amqp_queue_class_delete, ZEND_ACC_PUBLIC) - PHP_ME(amqp_queue_class, unbind, arginfo_amqp_queue_class_unbind, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, cancel, arginfo_amqp_queue_class_cancel, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, delete, arginfo_amqp_queue_class_delete, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, unbind, arginfo_amqp_queue_class_unbind, ZEND_ACC_PUBLIC) - PHP_ME(amqp_queue_class, getChannel, arginfo_amqp_queue_class_getChannel, ZEND_ACC_PUBLIC) - PHP_ME(amqp_queue_class, getConnection, arginfo_amqp_queue_class_getConnection, ZEND_ACC_PUBLIC) - PHP_ME(amqp_queue_class, getConsumerTag, arginfo_amqp_queue_class_getConsumerTag, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, getChannel, arginfo_amqp_queue_class_getChannel, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, getConnection, arginfo_amqp_queue_class_getConnection, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, getConsumerTag, arginfo_amqp_queue_class_getConsumerTag, ZEND_ACC_PUBLIC) - PHP_MALIAS(amqp_queue_class, declare, declareQueue, arginfo_amqp_queue_class_declareQueue, ZEND_ACC_PUBLIC | ZEND_ACC_DEPRECATED) + PHP_MALIAS(amqp_queue_class, declare, declareQueue, arginfo_amqp_queue_class_declareQueue, ZEND_ACC_PUBLIC | ZEND_ACC_DEPRECATED) - {NULL, NULL, NULL} + {NULL, NULL, NULL} }; PHP_MINIT_FUNCTION(amqp_queue) { - zend_class_entry ce; - - INIT_CLASS_ENTRY(ce, "AMQPQueue", amqp_queue_class_functions); - this_ce = zend_register_internal_class(&ce TSRMLS_CC); + zend_class_entry ce; - zend_declare_property_null(this_ce, ZEND_STRL("connection"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("channel"), ZEND_ACC_PRIVATE TSRMLS_CC); + INIT_CLASS_ENTRY(ce, "AMQPQueue", amqp_queue_class_functions); + this_ce = zend_register_internal_class(&ce TSRMLS_CC); - zend_declare_property_stringl(this_ce, ZEND_STRL("name"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("consumer_tag"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("connection"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("channel"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_bool(this_ce, ZEND_STRL("passive"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_bool(this_ce, ZEND_STRL("durable"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_bool(this_ce, ZEND_STRL("exclusive"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); - /* By default, the auto_delete flag should be set */ - zend_declare_property_bool(this_ce, ZEND_STRL("auto_delete"), 1, ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_stringl(this_ce, ZEND_STRL("name"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("consumer_tag"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_bool(this_ce, ZEND_STRL("passive"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_bool(this_ce, ZEND_STRL("durable"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_bool(this_ce, ZEND_STRL("exclusive"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); + /* By default, the auto_delete flag should be set */ + zend_declare_property_bool(this_ce, ZEND_STRL("auto_delete"), 1, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("arguments"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("arguments"), ZEND_ACC_PRIVATE TSRMLS_CC); - return SUCCESS; + return SUCCESS; } - -/* -*Local variables: -*tab-width: 4 -*tabstop: 4 -*c-basic-offset: 4 -*End: -*vim600: noet sw=4 ts=4 fdm=marker -*vim<600: noet sw=4 ts=4 -*/ diff --git a/amqp_queue.h b/amqp_queue.h index a8088d01..396d2140 100644 --- a/amqp_queue.h +++ b/amqp_queue.h @@ -24,12 +24,3 @@ extern zend_class_entry *amqp_queue_class_entry; PHP_MINIT_FUNCTION(amqp_queue); - -/* -*Local variables: -*tab-width: 4 -*c-basic-offset: 4 -*End: -*vim600: noet sw=4 ts=4 fdm=marker -*vim<600: noet sw=4 ts=4 -*/ diff --git a/amqp_timestamp.c b/amqp_timestamp.c index f63c85b8..c147193b 100644 --- a/amqp_timestamp.c +++ b/amqp_timestamp.c @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H -#include "config.h" + #include "config.h" #endif #include "php.h" @@ -40,26 +40,36 @@ static const double AMQP_TIMESTAMP_MIN = 0; */ static PHP_METHOD(amqp_timestamp_class, __construct) { - double timestamp; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", ×tamp) == FAILURE) { - return; - } - - if (timestamp < AMQP_TIMESTAMP_MIN) { - zend_throw_exception_ex(amqp_value_exception_class_entry, 0 TSRMLS_CC, "The timestamp parameter must be greater than %0.f.", AMQP_TIMESTAMP_MIN); - return; - } - - if (timestamp > AMQP_TIMESTAMP_MAX) { - zend_throw_exception_ex(amqp_value_exception_class_entry, 0 TSRMLS_CC, "The timestamp parameter must be less than %0.f.", AMQP_TIMESTAMP_MAX); - return; - } - - zend_string *str; - str = _php_math_number_format_ex(timestamp, 0, "", 0, "", 0); - zend_update_property_str(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("timestamp"), str); - zend_string_delref(str); + double timestamp; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", ×tamp) == FAILURE) { + return; + } + + if (timestamp < AMQP_TIMESTAMP_MIN) { + zend_throw_exception_ex( + amqp_value_exception_class_entry, + 0 TSRMLS_CC, + "The timestamp parameter must be greater than %0.f.", + AMQP_TIMESTAMP_MIN + ); + return; + } + + if (timestamp > AMQP_TIMESTAMP_MAX) { + zend_throw_exception_ex( + amqp_value_exception_class_entry, + 0 TSRMLS_CC, + "The timestamp parameter must be less than %0.f.", + AMQP_TIMESTAMP_MAX + ); + return; + } + + zend_string *str; + str = _php_math_number_format_ex(timestamp, 0, "", 0, "", 0); + zend_update_property_str(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("timestamp"), str); + zend_string_delref(str); } /* }}} */ @@ -68,10 +78,10 @@ static PHP_METHOD(amqp_timestamp_class, __construct) Get timestamp */ static PHP_METHOD(amqp_timestamp_class, getTimestamp) { - zval rv; - PHP_AMQP_NOPARAMS(); + zval rv; + PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("timestamp"); + PHP_AMQP_RETURN_THIS_PROP("timestamp"); } /* }}} */ @@ -80,15 +90,15 @@ static PHP_METHOD(amqp_timestamp_class, getTimestamp) Return timestamp as string */ static PHP_METHOD(amqp_timestamp_class, __toString) { - zval rv; - PHP_AMQP_NOPARAMS(); + zval rv; + PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("timestamp"); + PHP_AMQP_RETURN_THIS_PROP("timestamp"); } /* }}} */ ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_timestamp_class_construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) - ZEND_ARG_INFO(0, timestamp) + ZEND_ARG_INFO(0, timestamp) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_timestamp_class_getTimestamp, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) @@ -97,7 +107,13 @@ ZEND_END_ARG_INFO() #if PHP_MAJOR_VERSION < 8 ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_timestamp_class_toString, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) #else -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_timestamp_class_toString, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, IS_STRING, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX( + arginfo_amqp_timestamp_class_toString, + ZEND_SEND_BY_VAL, + ZEND_RETURN_VALUE, + IS_STRING, + 0 +) #endif ZEND_END_ARG_INFO() @@ -106,36 +122,27 @@ zend_function_entry amqp_timestamp_class_functions[] = { PHP_ME(amqp_timestamp_class, getTimestamp, arginfo_amqp_timestamp_class_getTimestamp, ZEND_ACC_PUBLIC) PHP_ME(amqp_timestamp_class, __toString, arginfo_amqp_timestamp_class_toString, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} + {NULL, NULL, NULL} }; PHP_MINIT_FUNCTION(amqp_timestamp) { - zend_class_entry ce; - char min[21], max[21]; - int min_len, max_len; + zend_class_entry ce; + char min[21], max[21]; + int min_len, max_len; - INIT_CLASS_ENTRY(ce, "AMQPTimestamp", amqp_timestamp_class_functions); - this_ce = zend_register_internal_class(&ce TSRMLS_CC); - this_ce->ce_flags = this_ce->ce_flags | ZEND_ACC_FINAL; + INIT_CLASS_ENTRY(ce, "AMQPTimestamp", amqp_timestamp_class_functions); + this_ce = zend_register_internal_class(&ce TSRMLS_CC); + this_ce->ce_flags = this_ce->ce_flags | ZEND_ACC_FINAL; - zend_declare_property_null(this_ce, ZEND_STRL("timestamp"), ZEND_ACC_PRIVATE TSRMLS_CC); + zend_declare_property_null(this_ce, ZEND_STRL("timestamp"), ZEND_ACC_PRIVATE TSRMLS_CC); - max_len = snprintf(max, sizeof(max), "%.0f", AMQP_TIMESTAMP_MAX); - zend_declare_class_constant_stringl(this_ce, ZEND_STRL("MAX"), max, max_len TSRMLS_CC); + max_len = snprintf(max, sizeof(max), "%.0f", AMQP_TIMESTAMP_MAX); + zend_declare_class_constant_stringl(this_ce, ZEND_STRL("MAX"), max, max_len TSRMLS_CC); - min_len = snprintf(min, sizeof(min), "%.0f", AMQP_TIMESTAMP_MIN); - zend_declare_class_constant_stringl(this_ce, ZEND_STRL("MIN"), min, min_len TSRMLS_CC); + min_len = snprintf(min, sizeof(min), "%.0f", AMQP_TIMESTAMP_MIN); + zend_declare_class_constant_stringl(this_ce, ZEND_STRL("MIN"), min, min_len TSRMLS_CC); - return SUCCESS; + return SUCCESS; } - -/* -*Local variables: -*tab-width: 4 -*c-basic-offset: 4 -*End: -*vim600: noet sw=4 ts=4 fdm=marker -*vim<6 -*/ diff --git a/amqp_timestamp.h b/amqp_timestamp.h index 5d94fc72..f854f5da 100644 --- a/amqp_timestamp.h +++ b/amqp_timestamp.h @@ -25,12 +25,3 @@ extern zend_class_entry *amqp_timestamp_class_entry; PHP_MINIT_FUNCTION(amqp_timestamp); - -/* -*Local variables: -*tab-width: 4 -*c-basic-offset: 4 -*End: -*vim600: noet sw=4 ts=4 fdm=marker -*vim<600: noet sw=4 ts=4 -*/ diff --git a/amqp_type.c b/amqp_type.c index 53e3cd91..68476f7a 100644 --- a/amqp_type.c +++ b/amqp_type.c @@ -21,22 +21,21 @@ +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H -#include "config.h" + #include "config.h" #endif -#include #if HAVE_LIBRABBITMQ_NEW_LAYOUT -#include + #include #else -#include + #include #endif #include "Zend/zend_interfaces.h" -#include "amqp_type.h" -#include "amqp_timestamp.h" #include "amqp_decimal.h" +#include "amqp_timestamp.h" +#include "amqp_type.h" #ifdef PHP_WIN32 -# define strtoimax _strtoi64 + #define strtoimax _strtoi64 #endif static void php_amqp_type_internal_free_amqp_array(amqp_array_t *array); @@ -44,319 +43,354 @@ static void php_amqp_type_internal_free_amqp_table(amqp_table_t *object, zend_bo amqp_bytes_t php_amqp_type_char_to_amqp_long(char const *cstr, size_t len) { - amqp_bytes_t result; + amqp_bytes_t result; - if (len < 1) { - return amqp_empty_bytes; - } + if (len < 1) { + return amqp_empty_bytes; + } - result.len = (size_t)len; - result.bytes = (void *) cstr; + result.len = (size_t) len; + result.bytes = (void *) cstr; - return result; + return result; } char *php_amqp_type_amqp_bytes_to_char(amqp_bytes_t bytes) { -/* We will need up to 4 chars per byte, plus the terminating 0 */ - char *res = emalloc(bytes.len * 4 + 1); - uint8_t *data = bytes.bytes; - char *p = res; - size_t i; - - for (i = 0; i < bytes.len; i++) { - if (data[i] >= 32 && data[i] != 127) { - *p++ = data[i]; - } else { - *p++ = '\\'; - *p++ = '0' + (data[i] >> 6); - *p++ = '0' + (data[i] >> 3 & 0x7); - *p++ = '0' + (data[i] & 0x7); - } - } - - *p = 0; - return res; + /* We will need up to 4 chars per byte, plus the terminating 0 */ + char *res = emalloc(bytes.len * 4 + 1); + uint8_t *data = bytes.bytes; + char *p = res; + size_t i; + + for (i = 0; i < bytes.len; i++) { + if (data[i] >= 32 && data[i] != 127) { + *p++ = data[i]; + } else { + *p++ = '\\'; + *p++ = '0' + (data[i] >> 6); + *p++ = '0' + (data[i] >> 3 & 0x7); + *p++ = '0' + (data[i] & 0x7); + } + } + + *p = 0; + return res; } -void php_amqp_type_internal_convert_zval_array(zval *php_array, amqp_field_value_t **field, zend_bool allow_int_keys TSRMLS_DC) +void php_amqp_type_internal_convert_zval_array( + zval *php_array, + amqp_field_value_t **field, + zend_bool allow_int_keys TSRMLS_DC +) { - HashTable *ht; - zend_string *key; - - ht = Z_ARRVAL_P(php_array); - - zend_bool is_amqp_array = 1; - - ZEND_HASH_FOREACH_STR_KEY(ht, key) { - if (key) { - is_amqp_array = 0; - break; - } - } ZEND_HASH_FOREACH_END(); - - if (is_amqp_array) { - (*field)->kind = AMQP_FIELD_KIND_ARRAY; - php_amqp_type_internal_convert_zval_to_amqp_array(php_array, &(*field)->value.array TSRMLS_CC); - } else { - (*field)->kind = AMQP_FIELD_KIND_TABLE; - php_amqp_type_internal_convert_zval_to_amqp_table(php_array, &(*field)->value.table, allow_int_keys TSRMLS_CC); - } + HashTable *ht; + zend_string *key; + + ht = Z_ARRVAL_P(php_array); + + zend_bool is_amqp_array = 1; + + ZEND_HASH_FOREACH_STR_KEY(ht, key) + if (key) { + is_amqp_array = 0; + break; + } + ZEND_HASH_FOREACH_END (); + + if (is_amqp_array) { + (*field)->kind = AMQP_FIELD_KIND_ARRAY; + php_amqp_type_internal_convert_zval_to_amqp_array(php_array, &(*field)->value.array TSRMLS_CC); + } else { + (*field)->kind = AMQP_FIELD_KIND_TABLE; + php_amqp_type_internal_convert_zval_to_amqp_table(php_array, &(*field)->value.table, allow_int_keys TSRMLS_CC); + } } -void php_amqp_type_internal_convert_zval_to_amqp_table(zval *php_array, amqp_table_t *amqp_table, zend_bool allow_int_keys TSRMLS_DC) +void php_amqp_type_internal_convert_zval_to_amqp_table( + zval *php_array, + amqp_table_t *amqp_table, + zend_bool allow_int_keys TSRMLS_DC +) { - HashTable *ht; - zval *value; - zend_string *zkey; - zend_ulong index; - char *key; - unsigned key_len; - ht = Z_ARRVAL_P(php_array); - - amqp_table->entries = (amqp_table_entry_t *)ecalloc((size_t)zend_hash_num_elements(ht), sizeof(amqp_table_entry_t)); - amqp_table->num_entries = 0; - - ZEND_HASH_FOREACH_KEY_VAL(ht, index, zkey, value) { - char *string_key; - amqp_table_entry_t *table_entry; - amqp_field_value_t *field; - - /* Now pull the key */ - if (!zkey) { - if (allow_int_keys) { - /* Convert to strings non-string keys */ - char str[32]; - - key_len = sprintf(str, "%lu", index); - key = str; - } else { - /* Skip things that are not strings */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Ignoring non-string header field '%lu'", index); - - continue; - } - } else { - key_len = ZSTR_LEN(zkey); - key = ZSTR_VAL(zkey); - } - - /* Build the value */ - table_entry = &amqp_table->entries[amqp_table->num_entries++]; - field = &table_entry->value; - - if (!php_amqp_type_internal_convert_php_to_amqp_field_value(value, &field, key TSRMLS_CC)) { - /* Reset entries counter back */ - amqp_table->num_entries --; - - continue; - } - - string_key = estrndup(key, key_len); - table_entry->key = amqp_cstring_bytes(string_key); - - } ZEND_HASH_FOREACH_END(); + HashTable *ht; + zval *value; + zend_string *zkey; + zend_ulong index; + char *key; + unsigned key_len; + ht = Z_ARRVAL_P(php_array); + + amqp_table->entries = + (amqp_table_entry_t *) ecalloc((size_t) zend_hash_num_elements(ht), sizeof(amqp_table_entry_t)); + amqp_table->num_entries = 0; + + ZEND_HASH_FOREACH_KEY_VAL(ht, index, zkey, value) + char *string_key; + amqp_table_entry_t *table_entry; + amqp_field_value_t *field; + + /* Now pull the key */ + if (!zkey) { + if (allow_int_keys) { + /* Convert to strings non-string keys */ + char str[32]; + + key_len = sprintf(str, "%lu", index); + key = str; + } else { + /* Skip things that are not strings */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Ignoring non-string header field '%lu'", index); + + continue; + } + } else { + key_len = ZSTR_LEN(zkey); + key = ZSTR_VAL(zkey); + } + + /* Build the value */ + table_entry = &amqp_table->entries[amqp_table->num_entries++]; + field = &table_entry->value; + + if (!php_amqp_type_internal_convert_php_to_amqp_field_value(value, &field, key TSRMLS_CC)) { + /* Reset entries counter back */ + amqp_table->num_entries--; + + continue; + } + + string_key = estrndup(key, key_len); + table_entry->key = amqp_cstring_bytes(string_key); + ZEND_HASH_FOREACH_END(); } void php_amqp_type_internal_convert_zval_to_amqp_array(zval *zval_arguments, amqp_array_t *arguments TSRMLS_DC) { - HashTable *ht; + HashTable *ht; - zval *value; + zval *value; - zend_string *zkey; + zend_string *zkey; - ht = Z_ARRVAL_P(zval_arguments); + ht = Z_ARRVAL_P(zval_arguments); - /* Allocate all the memory necessary for storing the arguments */ - arguments->entries = (amqp_field_value_t *)ecalloc((size_t)zend_hash_num_elements(ht), sizeof(amqp_field_value_t)); - arguments->num_entries = 0; + /* Allocate all the memory necessary for storing the arguments */ + arguments->entries = + (amqp_field_value_t *) ecalloc((size_t) zend_hash_num_elements(ht), sizeof(amqp_field_value_t)); + arguments->num_entries = 0; - ZEND_HASH_FOREACH_STR_KEY_VAL(ht, zkey, value) { - amqp_field_value_t *field = &arguments->entries[arguments->num_entries++]; + ZEND_HASH_FOREACH_STR_KEY_VAL(ht, zkey, value) + amqp_field_value_t *field = &arguments->entries[arguments->num_entries++]; - if (!php_amqp_type_internal_convert_php_to_amqp_field_value(value, &field, ZSTR_VAL(zkey) TSRMLS_CC)) { - /* Reset entries counter back */ - arguments->num_entries --; + if (!php_amqp_type_internal_convert_php_to_amqp_field_value(value, &field, ZSTR_VAL(zkey) TSRMLS_CC)) { + /* Reset entries counter back */ + arguments->num_entries--; - continue; - } - } ZEND_HASH_FOREACH_END(); + continue; + } + ZEND_HASH_FOREACH_END (); } -zend_bool php_amqp_type_internal_convert_php_to_amqp_field_value(zval *value, amqp_field_value_t **fieldPtr, char *key TSRMLS_DC) +zend_bool php_amqp_type_internal_convert_php_to_amqp_field_value( + zval *value, + amqp_field_value_t **fieldPtr, + char *key TSRMLS_DC +) { - zend_bool result; - char type[16]; - amqp_field_value_t *field; - - result = 1; - field = *fieldPtr; - - switch (Z_TYPE_P(value)) { - case IS_TRUE: - case IS_FALSE: - field->kind = AMQP_FIELD_KIND_BOOLEAN; - field->value.boolean = (amqp_boolean_t) Z_TYPE_P(value) != IS_FALSE; - break; - case IS_DOUBLE: - field->kind = AMQP_FIELD_KIND_F64; - field->value.f64 = Z_DVAL_P(value); - break; - case IS_LONG: - field->kind = AMQP_FIELD_KIND_I64; - field->value.i64 = Z_LVAL_P(value); - break; - case IS_STRING: - field->kind = AMQP_FIELD_KIND_UTF8; - - if (Z_STRLEN_P(value)) { - amqp_bytes_t bytes; - bytes.len = (size_t) Z_STRLEN_P(value); - bytes.bytes = estrndup(Z_STRVAL_P(value), (unsigned) Z_STRLEN_P(value)); - - field->value.bytes = bytes; - } else { - field->value.bytes = amqp_empty_bytes; - } - - break; - case IS_ARRAY: - php_amqp_type_internal_convert_zval_array(value, &field, 1 TSRMLS_CC); - break; - case IS_NULL: - field->kind = AMQP_FIELD_KIND_VOID; - break; - case IS_OBJECT: - if (instanceof_function(Z_OBJCE_P(value), amqp_timestamp_class_entry TSRMLS_CC)) { + zend_bool result; + char type[16]; + amqp_field_value_t *field; + + result = 1; + field = *fieldPtr; + + switch (Z_TYPE_P(value)) { + case IS_TRUE: + case IS_FALSE: + field->kind = AMQP_FIELD_KIND_BOOLEAN; + field->value.boolean = (amqp_boolean_t) Z_TYPE_P(value) != IS_FALSE; + break; + case IS_DOUBLE: + field->kind = AMQP_FIELD_KIND_F64; + field->value.f64 = Z_DVAL_P(value); + break; + case IS_LONG: + field->kind = AMQP_FIELD_KIND_I64; + field->value.i64 = Z_LVAL_P(value); + break; + case IS_STRING: + field->kind = AMQP_FIELD_KIND_UTF8; + + if (Z_STRLEN_P(value)) { + amqp_bytes_t bytes; + bytes.len = (size_t) Z_STRLEN_P(value); + bytes.bytes = estrndup(Z_STRVAL_P(value), (unsigned) Z_STRLEN_P(value)); + + field->value.bytes = bytes; + } else { + field->value.bytes = amqp_empty_bytes; + } + + break; + case IS_ARRAY: + php_amqp_type_internal_convert_zval_array(value, &field, 1 TSRMLS_CC); + break; + case IS_NULL: + field->kind = AMQP_FIELD_KIND_VOID; + break; + case IS_OBJECT: + if (instanceof_function(Z_OBJCE_P(value), amqp_timestamp_class_entry TSRMLS_CC)) { zval result_zv; - zend_call_method_with_0_params(PHP_AMQP_COMPAT_OBJ_P(value), amqp_timestamp_class_entry, NULL, "gettimestamp", &result_zv); + zend_call_method_with_0_params( + PHP_AMQP_COMPAT_OBJ_P(value), + amqp_timestamp_class_entry, + NULL, + "gettimestamp", + &result_zv + ); field->kind = AMQP_FIELD_KIND_TIMESTAMP; field->value.u64 = strtoimax(Z_STRVAL(result_zv), NULL, 10); - zval_ptr_dtor(&result_zv); - - break; - } else if (instanceof_function(Z_OBJCE_P(value), amqp_decimal_class_entry TSRMLS_CC)) { - field->kind = AMQP_FIELD_KIND_DECIMAL; - zval result_zv; - - zend_call_method_with_0_params(PHP_AMQP_COMPAT_OBJ_P(value), amqp_decimal_class_entry, NULL, "getexponent", &result_zv); - field->value.decimal.decimals = (uint8_t)Z_LVAL(result_zv); - zval_ptr_dtor(&result_zv); - - zend_call_method_with_0_params(PHP_AMQP_COMPAT_OBJ_P(value), amqp_decimal_class_entry, NULL, "getsignificand", &result_zv); - field->value.decimal.value = (uint32_t)Z_LVAL(result_zv); - zval_ptr_dtor(&result_zv); - - break; - } - default: - switch(Z_TYPE_P(value)) { - case IS_OBJECT: - strcpy(type, "object"); - break; - case IS_RESOURCE: - strcpy(type, "resource"); - break; - default: - strcpy(type, "unknown"); - break; - } - - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Ignoring field '%s' due to unsupported value type (%s)", key, type); - result = 0; - break; - } - - return result; + zval_ptr_dtor(&result_zv); + + break; + } else if (instanceof_function(Z_OBJCE_P(value), amqp_decimal_class_entry TSRMLS_CC)) { + field->kind = AMQP_FIELD_KIND_DECIMAL; + zval result_zv; + + zend_call_method_with_0_params( + PHP_AMQP_COMPAT_OBJ_P(value), + amqp_decimal_class_entry, + NULL, + "getexponent", + &result_zv + ); + field->value.decimal.decimals = (uint8_t) Z_LVAL(result_zv); + zval_ptr_dtor(&result_zv); + + zend_call_method_with_0_params( + PHP_AMQP_COMPAT_OBJ_P(value), + amqp_decimal_class_entry, + NULL, + "getsignificand", + &result_zv + ); + field->value.decimal.value = (uint32_t) Z_LVAL(result_zv); + zval_ptr_dtor(&result_zv); + + break; + } + default: + switch (Z_TYPE_P(value)) { + case IS_OBJECT: + strcpy(type, "object"); + break; + case IS_RESOURCE: + strcpy(type, "resource"); + break; + default: + strcpy(type, "unknown"); + break; + } + + php_error_docref( + NULL TSRMLS_CC, + E_WARNING, + "Ignoring field '%s' due to unsupported value type (%s)", + key, + type + ); + result = 0; + break; + } + + return result; } amqp_table_t *php_amqp_type_convert_zval_to_amqp_table(zval *php_array TSRMLS_DC) { - amqp_table_t *amqp_table; - /* In setArguments, we are overwriting all the existing values */ - amqp_table = (amqp_table_t *)emalloc(sizeof(amqp_table_t)); + amqp_table_t *amqp_table; + /* In setArguments, we are overwriting all the existing values */ + amqp_table = (amqp_table_t *) emalloc(sizeof(amqp_table_t)); - php_amqp_type_internal_convert_zval_to_amqp_table(php_array, amqp_table, 0 TSRMLS_CC); + php_amqp_type_internal_convert_zval_to_amqp_table(php_array, amqp_table, 0 TSRMLS_CC); - return amqp_table; + return amqp_table; } -static void php_amqp_type_internal_free_amqp_array(amqp_array_t *array) { - if (!array) { - return; - } - - int macroEntryCounter; - for (macroEntryCounter = 0; macroEntryCounter < array->num_entries; macroEntryCounter++) { - - amqp_field_value_t *entry = &array->entries[macroEntryCounter]; - - switch (entry->kind) { - case AMQP_FIELD_KIND_TABLE: - php_amqp_type_internal_free_amqp_table(&entry->value.table, 0); - break; - case AMQP_FIELD_KIND_ARRAY: - php_amqp_type_internal_free_amqp_array(&entry->value.array); - break; - case AMQP_FIELD_KIND_UTF8: - if (entry->value.bytes.bytes) { - efree(entry->value.bytes.bytes); - } - break; - // - default: - break; - } - } - - if (array->entries) { - efree(array->entries); - } +static void php_amqp_type_internal_free_amqp_array(amqp_array_t *array) +{ + if (!array) { + return; + } + + int macroEntryCounter; + for (macroEntryCounter = 0; macroEntryCounter < array->num_entries; macroEntryCounter++) { + + amqp_field_value_t *entry = &array->entries[macroEntryCounter]; + + switch (entry->kind) { + case AMQP_FIELD_KIND_TABLE: + php_amqp_type_internal_free_amqp_table(&entry->value.table, 0); + break; + case AMQP_FIELD_KIND_ARRAY: + php_amqp_type_internal_free_amqp_array(&entry->value.array); + break; + case AMQP_FIELD_KIND_UTF8: + if (entry->value.bytes.bytes) { + efree(entry->value.bytes.bytes); + } + break; + // + default: + break; + } + } + + if (array->entries) { + efree(array->entries); + } } static void php_amqp_type_internal_free_amqp_table(amqp_table_t *object, zend_bool clear_root) { - if (!object) { - return; - } - - if (object->entries) { - int macroEntryCounter; - for (macroEntryCounter = 0; macroEntryCounter < object->num_entries; macroEntryCounter++) { - - amqp_table_entry_t *entry = &object->entries[macroEntryCounter]; - efree(entry->key.bytes); - - switch (entry->value.kind) { - case AMQP_FIELD_KIND_TABLE: - php_amqp_type_internal_free_amqp_table(&entry->value.value.table, 0); - break; - case AMQP_FIELD_KIND_ARRAY: - php_amqp_type_internal_free_amqp_array(&entry->value.value.array); - break; - case AMQP_FIELD_KIND_UTF8: - if (entry->value.value.bytes.bytes) { - efree(entry->value.value.bytes.bytes); - } - break; - default: - break; - } - } - efree(object->entries); - } - - if (clear_root) { - efree(object); - } + if (!object) { + return; + } + + if (object->entries) { + int macroEntryCounter; + for (macroEntryCounter = 0; macroEntryCounter < object->num_entries; macroEntryCounter++) { + + amqp_table_entry_t *entry = &object->entries[macroEntryCounter]; + efree(entry->key.bytes); + + switch (entry->value.kind) { + case AMQP_FIELD_KIND_TABLE: + php_amqp_type_internal_free_amqp_table(&entry->value.value.table, 0); + break; + case AMQP_FIELD_KIND_ARRAY: + php_amqp_type_internal_free_amqp_array(&entry->value.value.array); + break; + case AMQP_FIELD_KIND_UTF8: + if (entry->value.value.bytes.bytes) { + efree(entry->value.value.bytes.bytes); + } + break; + default: + break; + } + } + efree(object->entries); + } + + if (clear_root) { + efree(object); + } } -void php_amqp_type_free_amqp_table(amqp_table_t *object) -{ - php_amqp_type_internal_free_amqp_table(object, 1); -} +void php_amqp_type_free_amqp_table(amqp_table_t *object) { php_amqp_type_internal_free_amqp_table(object, 1); } diff --git a/amqp_type.h b/amqp_type.h index c7715c6d..e0f4fe09 100644 --- a/amqp_type.h +++ b/amqp_type.h @@ -21,15 +21,15 @@ +----------------------------------------------------------------------+ */ #ifdef HAVE_CONFIG_H -#include "config.h" + #include "config.h" #endif #include "php.h" #if AMQP_VERSION_MINOR >= 13 -#include + #include #else -#include + #include #endif #include "php_amqp.h" @@ -42,7 +42,19 @@ amqp_table_t *php_amqp_type_convert_zval_to_amqp_table(zval *php_array TSRMLS_DC void php_amqp_type_free_amqp_table(amqp_table_t *object); /** Internal functions */ -zend_bool php_amqp_type_internal_convert_php_to_amqp_field_value(zval *value, amqp_field_value_t **fieldPtr, char *key TSRMLS_DC); -void php_amqp_type_internal_convert_zval_array(zval *php_array, amqp_field_value_t **field, zend_bool allow_int_keys TSRMLS_DC); -void php_amqp_type_internal_convert_zval_to_amqp_table(zval *php_array, amqp_table_t *amqp_table, zend_bool allow_int_keys TSRMLS_DC); -void php_amqp_type_internal_convert_zval_to_amqp_array(zval *php_array, amqp_array_t *amqp_array TSRMLS_DC); \ No newline at end of file +zend_bool php_amqp_type_internal_convert_php_to_amqp_field_value( + zval *value, + amqp_field_value_t **fieldPtr, + char *key TSRMLS_DC +); +void php_amqp_type_internal_convert_zval_array( + zval *php_array, + amqp_field_value_t **field, + zend_bool allow_int_keys TSRMLS_DC +); +void php_amqp_type_internal_convert_zval_to_amqp_table( + zval *php_array, + amqp_table_t *amqp_table, + zend_bool allow_int_keys TSRMLS_DC +); +void php_amqp_type_internal_convert_zval_to_amqp_array(zval *php_array, amqp_array_t *amqp_array TSRMLS_DC); diff --git a/php_amqp.h b/php_amqp.h index 2c117720..7f32cb45 100644 --- a/php_amqp.h +++ b/php_amqp.h @@ -24,17 +24,13 @@ #define PHP_AMQP_H #ifdef HAVE_CONFIG_H -#include "config.h" + #include "config.h" #endif /* True global resources - no need for thread safety here */ -extern zend_class_entry *amqp_exception_class_entry, - *amqp_connection_exception_class_entry, - *amqp_channel_exception_class_entry, - *amqp_exchange_exception_class_entry, - *amqp_queue_exception_class_entry, - *amqp_envelope_exception_class_entry, - *amqp_value_exception_class_entry; +extern zend_class_entry *amqp_exception_class_entry, *amqp_connection_exception_class_entry, + *amqp_channel_exception_class_entry, *amqp_exchange_exception_class_entry, *amqp_queue_exception_class_entry, + *amqp_envelope_exception_class_entry, *amqp_value_exception_class_entry; typedef struct _amqp_connection_resource amqp_connection_resource; @@ -45,27 +41,27 @@ typedef struct _amqp_channel_callbacks amqp_channel_callbacks; typedef struct _amqp_callback_bucket amqp_callback_bucket; #if PHP_VERSION_ID < 50600 -// should never get her, but just in case -#error PHP >= 5.6 required + // should never get her, but just in case + #error PHP >= 5.6 required #endif #if HAVE_LIBRABBITMQ_NEW_LAYOUT -#include + #include #else -#include + #include #endif extern zend_module_entry amqp_module_entry; #define phpext_amqp_ptr &amqp_module_entry #ifdef PHP_WIN32 -#define PHP_AMQP_API __declspec(dllexport) + #define PHP_AMQP_API __declspec(dllexport) #else -#define PHP_AMQP_API + #define PHP_AMQP_API #endif #ifdef ZTS -#include "TSRM.h" + #include "TSRM.h" #endif /* Small change to let it build after a major internal change for php8.0 @@ -73,114 +69,114 @@ extern zend_module_entry amqp_module_entry; * https://github.com/php/php-src/blob/php-8.0.0alpha3/UPGRADING.INTERNALS#L47 */ #if PHP_MAJOR_VERSION >= 8 -#define TSRMLS_DC -#define TSRMLS_D -#define TSRMLS_CC -#define TSRMLS_C -#define PHP_AMQP_COMPAT_OBJ_P(zv) Z_OBJ_P(zv) + #define TSRMLS_DC + #define TSRMLS_D + #define TSRMLS_CC + #define TSRMLS_C + #define PHP_AMQP_COMPAT_OBJ_P(zv) Z_OBJ_P(zv) #else -#define PHP_AMQP_COMPAT_OBJ_P(zv) (zv) + #define PHP_AMQP_COMPAT_OBJ_P(zv) (zv) #endif #if PHP_VERSION_ID < 80200 -#define zend_ini_parse_quantity_warn(v, name) (zend_atol(ZSTR_VAL(v), ZSTR_LEN(v))) + #define zend_ini_parse_quantity_warn(v, name) (zend_atol(ZSTR_VAL(v), ZSTR_LEN(v))) #endif #include "amqp_connection_resource.h" -#define AMQP_NOPARAM 0 +#define AMQP_NOPARAM 0 /* Where is 1?*/ -#define AMQP_JUST_CONSUME 1 -#define AMQP_DURABLE 2 -#define AMQP_PASSIVE 4 -#define AMQP_EXCLUSIVE 8 -#define AMQP_AUTODELETE 16 -#define AMQP_INTERNAL 32 -#define AMQP_NOLOCAL 64 -#define AMQP_AUTOACK 128 -#define AMQP_IFEMPTY 256 -#define AMQP_IFUNUSED 512 -#define AMQP_MANDATORY 1024 -#define AMQP_IMMEDIATE 2048 -#define AMQP_MULTIPLE 4096 -#define AMQP_NOWAIT 8192 -#define AMQP_REQUEUE 16384 +#define AMQP_JUST_CONSUME 1 +#define AMQP_DURABLE 2 +#define AMQP_PASSIVE 4 +#define AMQP_EXCLUSIVE 8 +#define AMQP_AUTODELETE 16 +#define AMQP_INTERNAL 32 +#define AMQP_NOLOCAL 64 +#define AMQP_AUTOACK 128 +#define AMQP_IFEMPTY 256 +#define AMQP_IFUNUSED 512 +#define AMQP_MANDATORY 1024 +#define AMQP_IMMEDIATE 2048 +#define AMQP_MULTIPLE 4096 +#define AMQP_NOWAIT 8192 +#define AMQP_REQUEUE 16384 /* passive, durable, auto-delete, internal, no-wait (see https://www.rabbitmq.com/amqp-0-9-1-reference.html#exchange.declare) */ -#define PHP_AMQP_EXCHANGE_FLAGS (AMQP_PASSIVE | AMQP_DURABLE | AMQP_AUTODELETE | AMQP_INTERNAL) +#define PHP_AMQP_EXCHANGE_FLAGS (AMQP_PASSIVE | AMQP_DURABLE | AMQP_AUTODELETE | AMQP_INTERNAL) /* passive, durable, exclusive, auto-delete, no-wait (see https://www.rabbitmq.com/amqp-0-9-1-reference.html#queue.declare) */ /* We don't support no-wait flag */ -#define PHP_AMQP_QUEUE_FLAGS (AMQP_PASSIVE | AMQP_DURABLE | AMQP_EXCLUSIVE | AMQP_AUTODELETE) +#define PHP_AMQP_QUEUE_FLAGS (AMQP_PASSIVE | AMQP_DURABLE | AMQP_EXCLUSIVE | AMQP_AUTODELETE) -#define AMQP_EX_TYPE_DIRECT "direct" -#define AMQP_EX_TYPE_FANOUT "fanout" -#define AMQP_EX_TYPE_TOPIC "topic" -#define AMQP_EX_TYPE_HEADERS "headers" +#define AMQP_EX_TYPE_DIRECT "direct" +#define AMQP_EX_TYPE_FANOUT "fanout" +#define AMQP_EX_TYPE_TOPIC "topic" +#define AMQP_EX_TYPE_HEADERS "headers" #define PHP_AMQP_CONNECTION_RES_NAME "AMQP Connection Resource" struct _amqp_channel_resource { - char is_connected; - amqp_channel_t channel_id; - amqp_connection_resource *connection_resource; + char is_connected; + amqp_channel_t channel_id; + amqp_connection_resource *connection_resource; amqp_channel_object *parent; }; struct _amqp_callback_bucket { - zend_fcall_info fci; - zend_fcall_info_cache fcc; + zend_fcall_info fci; + zend_fcall_info_cache fcc; }; struct _amqp_channel_callbacks { - amqp_callback_bucket basic_return; - amqp_callback_bucket basic_ack; - amqp_callback_bucket basic_nack; + amqp_callback_bucket basic_return; + amqp_callback_bucket basic_ack; + amqp_callback_bucket basic_nack; }; /* NOTE: due to how internally PHP works with custom object, zend_object position in structure matters */ struct _amqp_channel_object { - amqp_channel_callbacks callbacks; - zval *gc_data; - int gc_data_count; - amqp_channel_resource *channel_resource; - zend_object zo; + amqp_channel_callbacks callbacks; + zval *gc_data; + int gc_data_count; + amqp_channel_resource *channel_resource; + zend_object zo; }; struct _amqp_connection_resource { - zend_bool is_connected; - zend_bool is_persistent; - zend_bool is_dirty; - zend_resource *resource; - amqp_connection_object *parent; - amqp_channel_t max_slots; - amqp_channel_t used_slots; - amqp_channel_resource **slots; - amqp_connection_state_t connection_state; - amqp_socket_t *socket; + zend_bool is_connected; + zend_bool is_persistent; + zend_bool is_dirty; + zend_resource *resource; + amqp_connection_object *parent; + amqp_channel_t max_slots; + amqp_channel_t used_slots; + amqp_channel_resource **slots; + amqp_connection_state_t connection_state; + amqp_socket_t *socket; }; struct _amqp_connection_object { - amqp_connection_resource *connection_resource; - zend_object zo; + amqp_connection_resource *connection_resource; + zend_object zo; }; -#define DEFAULT_PORT "5672" /* default AMQP port */ -#define DEFAULT_HOST "localhost" -#define DEFAULT_TIMEOUT "" -#define DEFAULT_READ_TIMEOUT "0" -#define DEFAULT_WRITE_TIMEOUT "0" -#define DEFAULT_CONNECT_TIMEOUT "0" -#define DEFAULT_RPC_TIMEOUT "0" -#define DEFAULT_VHOST "/" -#define DEFAULT_LOGIN "guest" -#define DEFAULT_PASSWORD "guest" -#define DEFAULT_AUTOACK "0" /* These are all strings to facilitate setting default ini values */ -#define DEFAULT_PREFETCH_COUNT "3" -#define DEFAULT_PREFETCH_SIZE "0" -#define DEFAULT_GLOBAL_PREFETCH_COUNT "0" -#define DEFAULT_GLOBAL_PREFETCH_SIZE "0" -#define DEFAULT_SASL_METHOD "0" +#define DEFAULT_PORT "5672" /* default AMQP port */ +#define DEFAULT_HOST "localhost" +#define DEFAULT_TIMEOUT "" +#define DEFAULT_READ_TIMEOUT "0" +#define DEFAULT_WRITE_TIMEOUT "0" +#define DEFAULT_CONNECT_TIMEOUT "0" +#define DEFAULT_RPC_TIMEOUT "0" +#define DEFAULT_VHOST "/" +#define DEFAULT_LOGIN "guest" +#define DEFAULT_PASSWORD "guest" +#define DEFAULT_AUTOACK "0" /* These are all strings to facilitate setting default ini values */ +#define DEFAULT_PREFETCH_COUNT "3" +#define DEFAULT_PREFETCH_SIZE "0" +#define DEFAULT_GLOBAL_PREFETCH_COUNT "0" +#define DEFAULT_GLOBAL_PREFETCH_SIZE "0" +#define DEFAULT_SASL_METHOD "0" /* Usually, default is 0 which means 65535, but underlying rabbitmq-c library pool allocates minimal pool for each channel, * so it takes a lot of memory to keep all that channels. Even after channel closing that buffer still keep memory allocation. @@ -191,9 +187,10 @@ struct _amqp_connection_object { /* AMQP_DEFAULT_FRAME_SIZE 131072 */ #if PHP_AMQP_PROTOCOL_MAX_CHANNELS > 0 - #define PHP_AMQP_MAX_CHANNELS PHP_AMQP_PROTOCOL_MAX_CHANNELS + #define PHP_AMQP_MAX_CHANNELS PHP_AMQP_PROTOCOL_MAX_CHANNELS #else - #define PHP_AMQP_MAX_CHANNELS 65535 // Note that the maximum number of channels the protocol supports is 65535 (2^16, with the 0-channel reserved) + #define PHP_AMQP_MAX_CHANNELS \ + 65535// Note that the maximum number of channels the protocol supports is 65535 (2^16, with the 0-channel reserved) #endif #define PHP_AMQP_MAX_FRAME_SIZE INT_MAX @@ -213,47 +210,59 @@ struct _amqp_connection_object { #define PHP_AMQP_TO_STRING(value) #value -#define DEFAULT_CHANNEL_MAX PHP_AMQP_STRINGIFY(PHP_AMQP_MAX_CHANNELS) -#define DEFAULT_FRAME_MAX PHP_AMQP_STRINGIFY(PHP_AMQP_DEFAULT_FRAME_MAX) -#define DEFAULT_HEARTBEAT PHP_AMQP_STRINGIFY(PHP_AMQP_DEFAULT_HEARTBEAT) -#define DEFAULT_CACERT "" -#define DEFAULT_CERT "" -#define DEFAULT_KEY "" -#define DEFAULT_VERIFY "1" - - -#define IS_PASSIVE(bitmask) (AMQP_PASSIVE & (bitmask)) ? 1 : 0 -#define IS_DURABLE(bitmask) (AMQP_DURABLE & (bitmask)) ? 1 : 0 -#define IS_EXCLUSIVE(bitmask) (AMQP_EXCLUSIVE & (bitmask)) ? 1 : 0 -#define IS_AUTODELETE(bitmask) (AMQP_AUTODELETE & (bitmask)) ? 1 : 0 -#define IS_INTERNAL(bitmask) (AMQP_INTERNAL & (bitmask)) ? 1 : 0 -#define IS_NOWAIT(bitmask) (AMQP_NOWAIT & (bitmask)) ? 1 : 0 /* NOTE: always 0 in rabbitmq-c internals, so don't use it unless you are clearly understand aftermath*/ - -#define PHP_AMQP_NOPARAMS() if (zend_parse_parameters_none() == FAILURE) { return; } - -#define PHP_AMQP_RETURN_THIS_PROP(prop_name) \ - zval * _zv = zend_read_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(prop_name), 0 , &rv TSRMLS_CC); \ +#define DEFAULT_CHANNEL_MAX PHP_AMQP_STRINGIFY(PHP_AMQP_MAX_CHANNELS) +#define DEFAULT_FRAME_MAX PHP_AMQP_STRINGIFY(PHP_AMQP_DEFAULT_FRAME_MAX) +#define DEFAULT_HEARTBEAT PHP_AMQP_STRINGIFY(PHP_AMQP_DEFAULT_HEARTBEAT) +#define DEFAULT_CACERT "" +#define DEFAULT_CERT "" +#define DEFAULT_KEY "" +#define DEFAULT_VERIFY "1" + + +#define IS_PASSIVE(bitmask) (AMQP_PASSIVE & (bitmask)) ? 1 : 0 +#define IS_DURABLE(bitmask) (AMQP_DURABLE & (bitmask)) ? 1 : 0 +#define IS_EXCLUSIVE(bitmask) (AMQP_EXCLUSIVE & (bitmask)) ? 1 : 0 +#define IS_AUTODELETE(bitmask) (AMQP_AUTODELETE & (bitmask)) ? 1 : 0 +#define IS_INTERNAL(bitmask) (AMQP_INTERNAL & (bitmask)) ? 1 : 0 +#define IS_NOWAIT(bitmask) \ + (AMQP_NOWAIT & (bitmask)) \ + ? 1 \ + : 0 /* NOTE: always 0 in rabbitmq-c internals, so don't use it unless you are clearly understand aftermath*/ + +#define PHP_AMQP_NOPARAMS() \ + if (zend_parse_parameters_none() == FAILURE) { \ + return; \ + } + +#define PHP_AMQP_RETURN_THIS_PROP(prop_name) \ + zval *_zv = zend_read_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(prop_name), 0, &rv TSRMLS_CC); \ RETURN_ZVAL(_zv, 1, 0); -#define PHP_AMQP_READ_OBJ_PROP(cls, obj, name) zend_read_property((cls), PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL(name), 0 , &rv TSRMLS_CC) +#define PHP_AMQP_READ_OBJ_PROP(cls, obj, name) \ + zend_read_property((cls), PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL(name), 0, &rv TSRMLS_CC) #define PHP_AMQP_READ_OBJ_PROP_DOUBLE(cls, obj, name) Z_DVAL_P(PHP_AMQP_READ_OBJ_PROP((cls), (obj), (name))) -#define PHP_AMQP_READ_THIS_PROP_CE(name, ce) zend_read_property((ce), PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(name), 0 , &rv TSRMLS_CC) -#define PHP_AMQP_READ_THIS_PROP(name) zend_read_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(name), 0 , &rv TSRMLS_CC) +#define PHP_AMQP_READ_THIS_PROP_CE(name, ce) \ + zend_read_property((ce), PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(name), 0, &rv TSRMLS_CC) +#define PHP_AMQP_READ_THIS_PROP(name) \ + zend_read_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(name), 0, &rv TSRMLS_CC) #define PHP_AMQP_READ_THIS_PROP_BOOL(name) Z_TYPE_P(PHP_AMQP_READ_THIS_PROP(name)) == IS_TRUE #define PHP_AMQP_READ_THIS_PROP_STR(name) Z_STRVAL_P(PHP_AMQP_READ_THIS_PROP(name)) -#define PHP_AMQP_READ_THIS_PROP_STRLEN(name) (Z_TYPE_P(PHP_AMQP_READ_THIS_PROP(name)) == IS_STRING ? Z_STRLEN_P(PHP_AMQP_READ_THIS_PROP(name)) : 0) +#define PHP_AMQP_READ_THIS_PROP_STRLEN(name) \ + (Z_TYPE_P(PHP_AMQP_READ_THIS_PROP(name)) == IS_STRING ? Z_STRLEN_P(PHP_AMQP_READ_THIS_PROP(name)) : 0) #define PHP_AMQP_READ_THIS_PROP_ARR(name) Z_ARRVAL_P(PHP_AMQP_READ_THIS_PROP(name)) #define PHP_AMQP_READ_THIS_PROP_LONG(name) Z_LVAL_P(PHP_AMQP_READ_THIS_PROP(name)) #define PHP_AMQP_READ_THIS_PROP_DOUBLE(name) Z_DVAL_P(PHP_AMQP_READ_THIS_PROP(name)) -static inline amqp_connection_object *php_amqp_connection_object_fetch(zend_object *obj) { - return (amqp_connection_object *)((char *)obj - XtOffsetOf(amqp_connection_object, zo)); +static inline amqp_connection_object *php_amqp_connection_object_fetch(zend_object *obj) +{ + return (amqp_connection_object *) ((char *) obj - XtOffsetOf(amqp_connection_object, zo)); } -static inline amqp_channel_object *php_amqp_channel_object_fetch(zend_object *obj) { - return (amqp_channel_object *)((char *)obj - XtOffsetOf(amqp_channel_object, zo)); +static inline amqp_channel_object *php_amqp_channel_object_fetch(zend_object *obj) +{ + return (amqp_channel_object *) ((char *) obj - XtOffsetOf(amqp_channel_object, zo)); } #define PHP_AMQP_GET_CONNECTION(obj) php_amqp_connection_object_fetch(Z_OBJ_P(obj)) @@ -262,79 +271,98 @@ static inline amqp_channel_object *php_amqp_channel_object_fetch(zend_object *ob #define PHP_AMQP_FETCH_CONNECTION(obj) php_amqp_connection_object_fetch(obj) #define PHP_AMQP_FETCH_CHANNEL(obj) php_amqp_channel_object_fetch(obj) -#define PHP_AMQP_GET_CHANNEL_RESOURCE(obj) (IS_OBJECT == Z_TYPE_P(obj) ? (PHP_AMQP_GET_CHANNEL(obj))->channel_resource : NULL) - -#define PHP_AMQP_VERIFY_CONNECTION_ERROR(error, reason) \ - char verify_connection_error_tmp[255]; \ - snprintf(verify_connection_error_tmp, 255, "%s %s", error, reason); \ - zend_throw_exception(amqp_connection_exception_class_entry, verify_connection_error_tmp, 0 TSRMLS_CC); \ - return; \ - -#define PHP_AMQP_VERIFY_CONNECTION(connection, error) \ - if (!connection) { \ - PHP_AMQP_VERIFY_CONNECTION_ERROR(error, "Stale reference to the connection object.") \ - } \ - if (!(connection)->connection_resource || !(connection)->connection_resource->is_connected) { \ - PHP_AMQP_VERIFY_CONNECTION_ERROR(error, "No connection available.") \ - } \ - -#define PHP_AMQP_VERIFY_CHANNEL_ERROR(error, reason) \ - char verify_channel_error_tmp[255]; \ - snprintf(verify_channel_error_tmp, 255, "%s %s", error, reason); \ - zend_throw_exception(amqp_channel_exception_class_entry, verify_channel_error_tmp, 0 TSRMLS_CC); \ - return; \ - -#define PHP_AMQP_VERIFY_CHANNEL_RESOURCE(resource, error) \ - if (!resource) { \ - PHP_AMQP_VERIFY_CHANNEL_ERROR(error, "Stale reference to the channel object.") \ - } \ - if (!(resource)->is_connected) { \ - PHP_AMQP_VERIFY_CHANNEL_ERROR(error, "No channel available.") \ - } \ - if (!(resource)->connection_resource) { \ - PHP_AMQP_VERIFY_CONNECTION_ERROR(error, "Stale reference to the connection object.") \ - } \ - if (!(resource)->connection_resource->is_connected) { \ - PHP_AMQP_VERIFY_CONNECTION_ERROR(error, "No connection available.") \ - } \ - -#define PHP_AMQP_VERIFY_CHANNEL_CONNECTION_RESOURCE(resource, error) \ - if (!resource) { \ - PHP_AMQP_VERIFY_CHANNEL_ERROR(error, "Stale reference to the channel object.") \ - } \ - if (!(resource)->connection_resource) { \ - PHP_AMQP_VERIFY_CONNECTION_ERROR(error, "Stale reference to the connection object.") \ - } \ - if (!(resource)->connection_resource->is_connected) { \ - PHP_AMQP_VERIFY_CONNECTION_ERROR(error, "No connection available.") \ - } \ - -#define PHP_AMQP_MAYBE_ERROR(res, channel_resource) (\ - (AMQP_RESPONSE_NORMAL != (res).reply_type) \ - && \ - PHP_AMQP_RESOURCE_RESPONSE_OK != php_amqp_error(res, &PHP_AMQP_G(error_message), (channel_resource)->connection_resource, (channel_resource) TSRMLS_CC) \ - ) - -#define PHP_AMQP_MAYBE_ERROR_RECOVERABLE(res, channel_resource) (\ - (AMQP_RESPONSE_NORMAL != (res).reply_type) \ - && \ - PHP_AMQP_RESOURCE_RESPONSE_OK != php_amqp_error_advanced(res, &PHP_AMQP_G(error_message), (channel_resource)->connection_resource, (channel_resource), 0 TSRMLS_CC) \ - ) - -#define PHP_AMQP_IS_ERROR_RECOVERABLE(res, channel_resource, channel_object) ( \ - AMQP_RESPONSE_LIBRARY_EXCEPTION == (res).reply_type && AMQP_STATUS_UNEXPECTED_STATE == (res).library_error \ - && (0 <= php_amqp_connection_resource_error_advanced(res, &PHP_AMQP_G(error_message), (channel_resource)->connection_resource, (amqp_channel_t)(channel_resource ? (channel_resource)->channel_id : 0), (channel_object) TSRMLS_CC)) \ -) +#define PHP_AMQP_GET_CHANNEL_RESOURCE(obj) \ + (IS_OBJECT == Z_TYPE_P(obj) ? (PHP_AMQP_GET_CHANNEL(obj))->channel_resource : NULL) + +#define PHP_AMQP_VERIFY_CONNECTION_ERROR(error, reason) \ + char verify_connection_error_tmp[255]; \ + snprintf(verify_connection_error_tmp, 255, "%s %s", error, reason); \ + zend_throw_exception(amqp_connection_exception_class_entry, verify_connection_error_tmp, 0 TSRMLS_CC); \ + return; + +#define PHP_AMQP_VERIFY_CONNECTION(connection, error) \ + if (!connection) { \ + PHP_AMQP_VERIFY_CONNECTION_ERROR(error, "Stale reference to the connection object.") \ + } \ + if (!(connection)->connection_resource || !(connection)->connection_resource->is_connected) { \ + PHP_AMQP_VERIFY_CONNECTION_ERROR(error, "No connection available.") \ + } + +#define PHP_AMQP_VERIFY_CHANNEL_ERROR(error, reason) \ + char verify_channel_error_tmp[255]; \ + snprintf(verify_channel_error_tmp, 255, "%s %s", error, reason); \ + zend_throw_exception(amqp_channel_exception_class_entry, verify_channel_error_tmp, 0 TSRMLS_CC); \ + return; + +#define PHP_AMQP_VERIFY_CHANNEL_RESOURCE(resource, error) \ + if (!resource) { \ + PHP_AMQP_VERIFY_CHANNEL_ERROR(error, "Stale reference to the channel object.") \ + } \ + if (!(resource)->is_connected) { \ + PHP_AMQP_VERIFY_CHANNEL_ERROR(error, "No channel available.") \ + } \ + if (!(resource)->connection_resource) { \ + PHP_AMQP_VERIFY_CONNECTION_ERROR(error, "Stale reference to the connection object.") \ + } \ + if (!(resource)->connection_resource->is_connected) { \ + PHP_AMQP_VERIFY_CONNECTION_ERROR(error, "No connection available.") \ + } + +#define PHP_AMQP_VERIFY_CHANNEL_CONNECTION_RESOURCE(resource, error) \ + if (!resource) { \ + PHP_AMQP_VERIFY_CHANNEL_ERROR(error, "Stale reference to the channel object.") \ + } \ + if (!(resource)->connection_resource) { \ + PHP_AMQP_VERIFY_CONNECTION_ERROR(error, "Stale reference to the connection object.") \ + } \ + if (!(resource)->connection_resource->is_connected) { \ + PHP_AMQP_VERIFY_CONNECTION_ERROR(error, "No connection available.") \ + } + +#define PHP_AMQP_MAYBE_ERROR(res, channel_resource) \ + ((AMQP_RESPONSE_NORMAL != (res).reply_type) && \ + PHP_AMQP_RESOURCE_RESPONSE_OK != php_amqp_error( \ + res, \ + &PHP_AMQP_G(error_message), \ + (channel_resource)->connection_resource, \ + (channel_resource) TSRMLS_CC \ + )) + +#define PHP_AMQP_MAYBE_ERROR_RECOVERABLE(res, channel_resource) \ + ((AMQP_RESPONSE_NORMAL != (res).reply_type) && \ + PHP_AMQP_RESOURCE_RESPONSE_OK != php_amqp_error_advanced( \ + res, \ + &PHP_AMQP_G(error_message), \ + (channel_resource)->connection_resource, \ + (channel_resource), \ + 0 TSRMLS_CC \ + )) + +#define PHP_AMQP_IS_ERROR_RECOVERABLE(res, channel_resource, channel_object) \ + (AMQP_RESPONSE_LIBRARY_EXCEPTION == (res).reply_type && AMQP_STATUS_UNEXPECTED_STATE == (res).library_error && \ + (0 <= php_amqp_connection_resource_error_advanced( \ + res, \ + &PHP_AMQP_G(error_message), \ + (channel_resource)->connection_resource, \ + (amqp_channel_t) (channel_resource ? (channel_resource)->channel_id : 0), \ + (channel_object) TSRMLS_CC \ + ))) #if ZEND_MODULE_API_NO >= 20100000 - #define AMQP_OBJECT_PROPERTIES_INIT(obj, ce) object_properties_init(&(obj), ce); + #define AMQP_OBJECT_PROPERTIES_INIT(obj, ce) object_properties_init(&(obj), ce); #else - #define AMQP_OBJECT_PROPERTIES_INIT(obj, ce) \ - do { \ - zval *tmp; \ - zend_hash_copy((obj).properties, &(ce)->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); \ - } while (0); + #define AMQP_OBJECT_PROPERTIES_INIT(obj, ce) \ + do { \ + zval *tmp; \ + zend_hash_copy( \ + (obj).properties, \ + &(ce)->default_properties, \ + (copy_ctor_func_t) zval_add_ref, \ + (void *) &tmp, \ + sizeof(zval *) \ + ); \ + } while (0); #endif @@ -342,49 +370,68 @@ static inline amqp_channel_object *php_amqp_channel_object_fetch(zend_object *ob #ifdef PHP_WIN32 -# define AMQP_OS_SOCKET_TIMEOUT_ERRNO AMQP_ERROR_CATEGORY_MASK | WSAETIMEDOUT + #define AMQP_OS_SOCKET_TIMEOUT_ERRNO AMQP_ERROR_CATEGORY_MASK | WSAETIMEDOUT #else -# define AMQP_OS_SOCKET_TIMEOUT_ERRNO AMQP_ERROR_CATEGORY_MASK | EAGAIN + #define AMQP_OS_SOCKET_TIMEOUT_ERRNO AMQP_ERROR_CATEGORY_MASK | EAGAIN #endif ZEND_BEGIN_MODULE_GLOBALS(amqp) - char *error_message; - zend_long error_code; +char *error_message; +zend_long error_code; ZEND_END_MODULE_GLOBALS(amqp) ZEND_EXTERN_MODULE_GLOBALS(amqp) #ifdef ZEND_MODULE_GLOBALS_ACCESSOR - #define PHP_AMQP_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(amqp, v) + #define PHP_AMQP_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(amqp, v) - #if defined(ZTS) && defined(COMPILE_DL_WEAK) - ZEND_TSRMLS_CACHE_EXTERN(); - #endif + #if defined(ZTS) && defined(COMPILE_DL_WEAK) +ZEND_TSRMLS_CACHE_EXTERN(); + #endif #else - #ifdef ZTS - #define PHP_AMQP_G(v) TSRMG(amqp_globals_id, zend_amqp_globals *, v) - #else - #define PHP_AMQP_G(v) (amqp_globals.v) - #endif + #ifdef ZTS + #define PHP_AMQP_G(v) TSRMG(amqp_globals_id, zend_amqp_globals *, v) + #else + #define PHP_AMQP_G(v) (amqp_globals.v) + #endif #endif #ifndef PHP_AMQP_VERSION -#define PHP_AMQP_VERSION "1.12.0dev" + #define PHP_AMQP_VERSION "1.12.0dev" #endif #ifndef PHP_AMQP_REVISION -#define PHP_AMQP_REVISION "release" + #define PHP_AMQP_REVISION "release" #endif -int php_amqp_error(amqp_rpc_reply_t reply, char **message, amqp_connection_resource *connection_resource, amqp_channel_resource *channel_resource TSRMLS_DC); -int php_amqp_error_advanced(amqp_rpc_reply_t reply, char **message, amqp_connection_resource *connection_resource, amqp_channel_resource *channel_resource, int fail_on_errors TSRMLS_DC); +int php_amqp_error( + amqp_rpc_reply_t reply, + char **message, + amqp_connection_resource *connection_resource, + amqp_channel_resource *channel_resource TSRMLS_DC +); +int php_amqp_error_advanced( + amqp_rpc_reply_t reply, + char **message, + amqp_connection_resource *connection_resource, + amqp_channel_resource *channel_resource, + int fail_on_errors TSRMLS_DC +); /** * @deprecated */ -void php_amqp_zend_throw_exception(amqp_rpc_reply_t reply, zend_class_entry *exception_ce, const char *message, zend_long code TSRMLS_DC); +void php_amqp_zend_throw_exception( + amqp_rpc_reply_t reply, + zend_class_entry *exception_ce, + const char *message, + zend_long code TSRMLS_DC +); void php_amqp_zend_throw_exception_short(amqp_rpc_reply_t reply, zend_class_entry *exception_ce TSRMLS_DC); -void php_amqp_maybe_release_buffers_on_channel(amqp_connection_resource *connection_resource, amqp_channel_resource *channel_resource); +void php_amqp_maybe_release_buffers_on_channel( + amqp_connection_resource *connection_resource, + amqp_channel_resource *channel_resource +); zend_bool php_amqp_is_valid_identifier(zend_string *val); zend_bool php_amqp_is_valid_credential(zend_string *val); @@ -396,14 +443,4 @@ zend_bool php_amqp_is_valid_heartbeat(zend_long val); zend_bool php_amqp_is_valid_prefetch_count(zend_long val); zend_bool php_amqp_is_valid_prefetch_size(zend_long val); -#endif /* PHP_AMQP_H */ - - -/* - * 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 - */ +#endif /* PHP_AMQP_H */ diff --git a/tools/dev-build.sh b/tools/dev-build.sh new file mode 100755 index 00000000..8723080d --- /dev/null +++ b/tools/dev-build.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env sh +set -e +phpize +CFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror" ./configure +make clean all \ No newline at end of file diff --git a/tools/dev-format.sh b/tools/dev-format.sh new file mode 100755 index 00000000..bb3e97a9 --- /dev/null +++ b/tools/dev-format.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh +set -e +clang-format-17 -i *.c *.h \ No newline at end of file From abd9fd77094f45035425904a4b8725f23fef1d0c Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Sat, 29 Jul 2023 10:21:51 +0200 Subject: [PATCH 016/147] The big fat API renovation (#437) --- .clang-format | 4 +- .github/workflows/test.yaml | 137 +-- .gitignore | 5 + README.md | 2 +- amqp.c | 48 +- amqp_basic_properties.c | 357 +++++--- amqp_basic_properties.h | 8 +- amqp_channel.c | 434 ++++----- amqp_channel.h | 2 +- amqp_connection.c | 831 ++++++++---------- amqp_connection.h | 2 +- amqp_connection_resource.c | 144 +-- amqp_connection_resource.h | 17 +- amqp_decimal.c | 49 +- amqp_envelope.c | 93 +- amqp_envelope.h | 2 +- amqp_envelope_exception.c | 79 ++ amqp_envelope_exception.h | 27 + amqp_exchange.c | 285 +++--- amqp_methods_handling.c | 34 +- amqp_methods_handling.h | 14 +- amqp_queue.c | 439 ++++----- amqp_timestamp.c | 52 +- amqp_type.c | 46 +- amqp_type.h | 18 +- composer.json | 5 +- config.m4 | 4 +- config.w32 | 2 +- package.xml | 6 +- php_amqp.h | 114 ++- stubs/AMQP.php | 52 +- stubs/AMQPBasicProperties.php | 117 +-- stubs/AMQPChannel.php | 83 +- stubs/AMQPConnection.php | 255 +++--- stubs/AMQPDecimal.php | 9 +- stubs/AMQPEnvelope.php | 27 +- stubs/AMQPEnvelopeException.php | 8 +- stubs/AMQPExchange.php | 135 +-- stubs/AMQPQueue.php | 164 ++-- stubs/AMQPTimestamp.php | 20 +- tests/004-queue-consume-orphaned.phpt | 48 +- tests/amqpbasicproperties.phpt | 36 +- tests/amqpchannel_basicRecover.phpt | 2 +- tests/amqpchannel_confirmSelect.phpt | 2 +- tests/amqpchannel_getChannelId.phpt | 2 +- tests/amqpchannel_get_connection.phpt | 2 +- tests/amqpchannel_slots_usage.phpt | 2 +- tests/amqpchannel_validation.phpt | 16 +- tests/amqpchannel_var_dump.phpt | 66 +- tests/amqpconnection_connection_getters.phpt | 2 +- .../amqpconnection_construct_with_limits.phpt | 24 +- ...mqpconnection_heartbeat_with_consumer.phpt | 24 +- tests/amqpconnection_nullable_setters.phpt | 51 ++ tests/amqpconnection_setPort_int.phpt | 4 +- tests/amqpconnection_setPort_string.phpt | 4 +- ...onnection_setReadTimeout_out_of_range.phpt | 2 +- ...connection_setRpcTimeout_out_of_range.phpt | 2 +- ...nnection_setWriteTimeout_out_of_range.phpt | 2 +- tests/amqpconnection_validation.phpt | 12 +- tests/amqpconnection_var_dump.phpt | 74 +- tests/amqpdecimal.phpt | 2 +- tests/amqpenvelope_construct.phpt | 54 +- tests/amqpenvelope_get_accessors.phpt | 62 +- tests/amqpenvelope_var_dump.phpt | 94 +- tests/amqpexchange_attributes.phpt | 2 +- tests/amqpexchange_bind.phpt | 4 +- tests/amqpexchange_bind_with_arguments.phpt | 4 +- tests/amqpexchange_bind_without_key.phpt | 6 +- ...hange_bind_without_key_with_arguments.phpt | 4 +- tests/amqpexchange_declare_basic.phpt | 10 +- tests/amqpexchange_declare_existent.phpt | 4 +- tests/amqpexchange_get_connection.phpt | 2 +- tests/amqpexchange_name.phpt | 31 + tests/amqpexchange_publish_basic.phpt | 4 +- tests/amqpexchange_publish_confirms.phpt | 20 +- ...amqpexchange_publish_confirms_consume.phpt | 12 +- ...mqpexchange_publish_empty_routing_key.phpt | 4 +- tests/amqpexchange_publish_mandatory.phpt | 46 +- ...mqpexchange_publish_mandatory_consume.phpt | 46 +- ..._mandatory_multiple_channels_pitfall.phpt} | 13 +- ...amqpexchange_publish_null_routing_key.phpt | 4 +- .../amqpexchange_publish_with_properties.phpt | 6 +- ...ish_with_properties_ignore_num_header.phpt | 8 +- ...ties_ignore_unsupported_header_values.phpt | 4 +- ...blish_with_properties_user_id_failure.phpt | 4 +- ...xchange_publish_with_timestamp_header.phpt | 4 +- tests/amqpexchange_publish_xdeath.phpt | 2 +- tests/amqpexchange_setArgument.phpt | 282 +----- tests/amqpexchange_set_flags.phpt | 96 +- tests/amqpexchange_type.phpt | 34 + tests/amqpexchange_unbind.phpt | 6 +- tests/amqpexchange_unbind_with_arguments.phpt | 6 +- tests/amqpexchange_unbind_without_key.phpt | 6 +- ...nge_unbind_without_key_with_arguments.phpt | 12 +- tests/amqpexchange_var_dump.phpt | 190 +--- tests/amqpqueue-cancel-no-consumers.phpt | 3 +- tests/amqpqueue_attributes.phpt | 8 +- tests/amqpqueue_bind_basic.phpt | 2 +- ...mqpqueue_bind_basic_empty_routing_key.phpt | 14 +- ...mqpqueue_bind_basic_headers_arguments.phpt | 14 +- tests/amqpqueue_bind_null_routing_key.phpt | 16 +- tests/amqpqueue_consume_basic.phpt | 32 +- tests/amqpqueue_declare_basic.phpt | 14 +- tests/amqpqueue_declare_with_arguments.phpt | 22 +- tests/amqpqueue_get_basic.phpt | 50 +- tests/amqpqueue_get_connection.phpt | 2 +- tests/amqpqueue_get_empty_body.phpt | 2 +- tests/amqpqueue_nested_headers.phpt | 2 +- tests/amqpqueue_setArgument.phpt | 288 +----- ...pqueue_unbind_basic_empty_routing_key.phpt | 4 +- ...pqueue_unbind_basic_headers_arguments.phpt | 4 +- tests/amqpqueue_var_dump.phpt | 100 +-- tests/amqptimestamp.phpt | 22 +- tests/amqptimestamp_php8.phpt | 60 -- tests/bug_19707.phpt | 16 +- tools/check-stubs.sh | 9 + tools/dev-format.sh | 4 +- tools/dump-reflection.php | 228 +++++ tools/validate-stubs.sh | 17 + 119 files changed, 2928 insertions(+), 3600 deletions(-) create mode 100644 amqp_envelope_exception.c create mode 100644 amqp_envelope_exception.h create mode 100644 tests/amqpconnection_nullable_setters.phpt create mode 100644 tests/amqpexchange_name.phpt rename tests/{amqpexchange_publish_mandatory_multiple_channels_pitfal.phpt => amqpexchange_publish_mandatory_multiple_channels_pitfall.phpt} (81%) create mode 100644 tests/amqpexchange_type.phpt delete mode 100644 tests/amqptimestamp_php8.phpt create mode 100755 tools/check-stubs.sh create mode 100644 tools/dump-reflection.php create mode 100755 tools/validate-stubs.sh diff --git a/.clang-format b/.clang-format index 33b9745a..a79780cd 100644 --- a/.clang-format +++ b/.clang-format @@ -20,7 +20,7 @@ AllowShortLoopsOnASingleLine: true AlwaysBreakAfterReturnType: None AlwaysBreakTemplateDeclarations: Yes BreakBeforeBraces: Custom -MacroBlockBegin: "(ZEND_BEGIN_ARG_INFO(_EX)?|PHP_INI_BEGIN)" +MacroBlockBegin: "(ZEND_BEGIN_ARG_(INFO|WITH_RETURN_(TYPE|OBJ)_INFO)(_EX)?|PHP_INI_BEGIN)" MacroBlockEnd: "(ZEND_END_ARG_INFO|PHP_INI_END)" Macros: - "PHP_ME(a, b, c, d)={a, b, c, d}," @@ -82,4 +82,4 @@ SortIncludes: Never IndentWrappedFunctionNames: true InsertNewlineAtEOF: true PenaltyReturnTypeOnItsOwnLine: 9999 -PenaltyExcessCharacter: 100 \ No newline at end of file +PenaltyExcessCharacter: 999 \ No newline at end of file diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e2a95abd..5cffeefb 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -3,15 +3,15 @@ name: Test on: push: pull_request: - types: [opened, synchronize, edited, reopened] + types: [opened, synchronize, reopened] env: - ACTIONS_ALLOW_UNSECURE_COMMANDS: true TEST_TIMEOUT: 120 + CFLAGS: -D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror jobs: checkstyle: - name: Check coding style + name: Check C formatting runs-on: ubuntu-22.04 steps: - name: install clang-format @@ -28,9 +28,45 @@ jobs: - name: Check style run: clang-format-17 --dry-run --Werror *.c *.h + stubs: + name: Check stubs php-${{ matrix.php-version }} + runs-on: ubuntu-22.04 + + strategy: + fail-fast: false + matrix: + php-version: ["8.2", "8.1", "8.0", "7.4"] + + steps: + - name: Checkout + uses: actions/checkout@v3.5.3 + + - name: Install packages + run: sudo apt-get install -y cmake valgrind + + - name: Setup PHP + uses: shivammathur/setup-php@2.25.4 + with: + php-version: ${{ matrix.php-version }} + extensions: json + coverage: none + + - name: Check stubs + run: ./tools/check-stubs.sh + + - name: Build librabbitmq + run: sudo ./provision/install_rabbitmq-c.sh master + + - name: Build PHP extension + run: phpize && ./configure && make + + - name: Validate stubs + run: ./tools/validate-stubs.sh + test: - name: php-${{ matrix.php-version }} librabbitmq-${{ matrix.librabbitmq-version }} ${{ matrix.test-php-args == '-m' && 'memory leaks' || '' }} - runs-on: ${{ matrix.os }} + name: Test php-${{ matrix.php-version }}${{ matrix.php-thread-safe && '-zts' || '' }} librabbitmq-${{ matrix.librabbitmq-version }} ${{ matrix.test-php-args == '-m' && 'memory leaks' || '' }} + # librabbitmq < 0.11 needs older OpenSSL version + runs-on: ${{ matrix.librabbitmq-version == 'v0.10.0' && 'ubuntu-20.04' || 'ubuntu-22.04' }} env: TEST_PHP_ARGS: ${{ matrix.test-php-args }} @@ -38,95 +74,19 @@ jobs: strategy: fail-fast: false matrix: + php-version: ['8.2', '8.1', '8.0', '7.4'] + php-thread-safe: [true, false] + librabbitmq-version: ['master', 'v0.13.0', 'v0.11.0', 'v0.10.0'] include: - php-version: '8.2' - librabbitmq-version: 'master' - experimental: false - os: ubuntu-22.04 - - php-version: '8.2' + php-thread-safe: false librabbitmq-version: 'master' test-php-args: '-m' - experimental: false - os: ubuntu-22.04 - - php-version: '8.2' - librabbitmq-version: 'v0.13.0' - experimental: false - os: ubuntu-22.04 - - php-version: '8.2' - librabbitmq-version: 'v0.11.0' - experimental: false - os: ubuntu-22.04 - - php-version: '8.2' - librabbitmq-version: 'v0.10.0' - experimental: false - os: ubuntu-20.04 - php-version: '8.1' - librabbitmq-version: 'master' - experimental: false - os: ubuntu-22.04 - - php-version: '8.1' - librabbitmq-version: 'master' - test-php-args: '-m' - experimental: false - os: ubuntu-22.04 - - php-version: '8.1' - librabbitmq-version: 'v0.13.0' - experimental: false - os: ubuntu-22.04 - - php-version: '8.1' - librabbitmq-version: 'v0.11.0' - experimental: false - os: ubuntu-22.04 - - php-version: '8.1' - librabbitmq-version: 'v0.10.0' - experimental: false - os: ubuntu-20.04 - - - php-version: '8.0' - librabbitmq-version: 'master' - experimental: false - os: ubuntu-22.04 - - php-version: '8.0' + php-thread-safe: true librabbitmq-version: 'master' test-php-args: '-m' - experimental: true - os: ubuntu-22.04 - - php-version: '8.0' - librabbitmq-version: 'v0.13.0' - experimental: false - os: ubuntu-22.04 - - php-version: '8.0' - librabbitmq-version: 'v0.11.0' - experimental: false - os: ubuntu-22.04 - - php-version: '8.0' - librabbitmq-version: 'v0.10.0' - experimental: false - os: ubuntu-20.04 - - - php-version: '7.4' - librabbitmq-version: 'master' - experimental: false - os: ubuntu-22.04 - - php-version: '7.4' - librabbitmq-version: 'v0.13.0' - experimental: false - os: ubuntu-22.04 - - php-version: '7.4' - librabbitmq-version: 'v0.13.0' - test-php-args: '-m' - experimental: true - os: ubuntu-22.04 - - php-version: '7.4' - librabbitmq-version: 'v0.11.0' - experimental: false - os: ubuntu-22.04 - - php-version: '7.4' - librabbitmq-version: 'v0.10.0' - experimental: false - os: ubuntu-20.04 - services: rabbitmq: image: rabbitmq:3 @@ -148,6 +108,8 @@ jobs: with: php-version: ${{ matrix.php-version }} coverage: none + env: + phpts: ${{ matrix.php-thread-safe && 'ts' || 'nts' }} - name: Build librabbitmq run: sudo ./provision/install_rabbitmq-c.sh ${{ matrix.librabbitmq-version }} @@ -156,8 +118,6 @@ jobs: run: pkg-config librabbitmq --debug - name: Build PHP extension - env: - CFLAGS: -D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror run: phpize && ./configure && make - name: Test PHP extension @@ -168,4 +128,3 @@ jobs: - name: Dump report run: sh test-report.sh - continue-on-error: ${{ matrix.experimental }} diff --git a/.gitignore b/.gitignore index e04d1daa..0544517a 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,8 @@ CMakeLists.txt .idea/ /vendor/ /composer.lock + +/config.h.in~ +/configure~ +/impl.json +/stubs.json diff --git a/README.md b/README.md index d39315a6..deee9f4b 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Object-oriented PHP bindings for the AMQP C library (https://github.com/alanxz/r - PHP >= 7.4 with either ZTS or non-ZTS version. - [RabbitMQ C library](https://github.com/alanxz/rabbitmq-c), commonly known as librabbitmq - (since php-amqp >= 1.12.0 librabbitmq >= 0.10.0, + (since php-amqp >= 2.0.0 librabbitmq >= 0.10.0, see [release notes](https://pecl.php.net/package-changelog.php?package=amqp)). - to run tests [RabbitMQ server](https://www.rabbitmq.com/) >= 3.4.0 required. diff --git a/amqp.c b/amqp.c index 36389622..380f6bd6 100644 --- a/amqp.c +++ b/amqp.c @@ -56,6 +56,7 @@ #include "amqp_connection_resource.h" #include "amqp_channel.h" #include "amqp_envelope.h" +#include "amqp_envelope_exception.h" #include "amqp_exchange.h" #include "amqp_queue.h" #include "amqp_timestamp.h" @@ -71,7 +72,7 @@ zend_class_entry *amqp_exception_class_entry, *amqp_connection_exception_class_entry, *amqp_channel_exception_class_entry, *amqp_queue_exception_class_entry, *amqp_exchange_exception_class_entry, - *amqp_envelope_exception_class_entry, *amqp_value_exception_class_entry; + *amqp_value_exception_class_entry; /* {{{ amqp_functions[] * @@ -245,18 +246,9 @@ static PHP_MINIT_FUNCTION(amqp) /* {{{ */ module_number ); - PHP_MINIT(amqp_connection)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(amqp_channel)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(amqp_queue)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(amqp_exchange)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(amqp_basic_properties)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(amqp_envelope)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(amqp_timestamp)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(amqp_decimal)(INIT_FUNC_ARGS_PASSTHRU); - /* Class Exceptions */ INIT_CLASS_ENTRY(ce, "AMQPException", NULL); - amqp_exception_class_entry = zend_register_internal_class_ex(&ce, zend_exception_get_default(TSRMLS_C)); + amqp_exception_class_entry = zend_register_internal_class_ex(&ce, zend_exception_get_default()); INIT_CLASS_ENTRY(ce, "AMQPConnectionException", NULL); amqp_connection_exception_class_entry = zend_register_internal_class_ex(&ce, amqp_exception_class_entry); @@ -267,16 +259,22 @@ static PHP_MINIT_FUNCTION(amqp) /* {{{ */ INIT_CLASS_ENTRY(ce, "AMQPQueueException", NULL); amqp_queue_exception_class_entry = zend_register_internal_class_ex(&ce, amqp_exception_class_entry); - INIT_CLASS_ENTRY(ce, "AMQPEnvelopeException", NULL); - amqp_envelope_exception_class_entry = zend_register_internal_class_ex(&ce, amqp_exception_class_entry); - zend_declare_property_null(amqp_envelope_exception_class_entry, ZEND_STRL("envelope"), ZEND_ACC_PUBLIC TSRMLS_CC); - INIT_CLASS_ENTRY(ce, "AMQPExchangeException", NULL); amqp_exchange_exception_class_entry = zend_register_internal_class_ex(&ce, amqp_exception_class_entry); INIT_CLASS_ENTRY(ce, "AMQPValueException", NULL); amqp_value_exception_class_entry = zend_register_internal_class_ex(&ce, amqp_exception_class_entry); + PHP_MINIT(amqp_connection)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(amqp_channel)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(amqp_queue)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(amqp_exchange)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(amqp_basic_properties)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(amqp_envelope)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(amqp_envelope_exception)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(amqp_timestamp)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(amqp_decimal)(INIT_FUNC_ARGS_PASSTHRU); + REGISTER_INI_ENTRIES(); REGISTER_LONG_CONSTANT("AMQP_NOPARAM", AMQP_NOPARAM, CONST_CS | CONST_PERSISTENT); @@ -374,10 +372,10 @@ int php_amqp_error( amqp_rpc_reply_t reply, char **message, amqp_connection_resource *connection_resource, - amqp_channel_resource *channel_resource TSRMLS_DC + amqp_channel_resource *channel_resource ) { - return php_amqp_error_advanced(reply, message, connection_resource, channel_resource, 1 TSRMLS_CC); + return php_amqp_error_advanced(reply, message, connection_resource, channel_resource, 1); } int php_amqp_error_advanced( @@ -385,7 +383,7 @@ int php_amqp_error_advanced( char **message, amqp_connection_resource *connection_resource, amqp_channel_resource *channel_resource, - int fail_on_errors TSRMLS_DC + int fail_on_errors ) { assert(connection_resource != NULL); @@ -399,7 +397,7 @@ int php_amqp_error_advanced( reply, message, connection_resource, - (amqp_channel_t) (channel_resource ? channel_resource->channel_id : 0) TSRMLS_CC + (amqp_channel_t) (channel_resource ? channel_resource->channel_id : 0) ); switch (res) { @@ -416,7 +414,7 @@ int php_amqp_error_advanced( connection_resource->is_connected = '\0'; /* Close connection with all its channels */ - php_amqp_disconnect_force(connection_resource TSRMLS_CC); + php_amqp_disconnect_force(connection_resource); break; case PHP_AMQP_RESOURCE_RESPONSE_ERROR_CHANNEL_CLOSED: @@ -426,7 +424,7 @@ int php_amqp_error_advanced( channel_resource->is_connected = '\0'; /* Close channel */ - php_amqp_close_channel(channel_resource, 1 TSRMLS_CC); + php_amqp_close_channel(channel_resource, 1); } /* No more error handling necessary, returning. */ break; @@ -438,16 +436,16 @@ int php_amqp_error_advanced( return res; } -void php_amqp_zend_throw_exception_short(amqp_rpc_reply_t reply, zend_class_entry *exception_ce TSRMLS_DC) +void php_amqp_zend_throw_exception_short(amqp_rpc_reply_t reply, zend_class_entry *exception_ce) { - php_amqp_zend_throw_exception(reply, exception_ce, PHP_AMQP_G(error_message), PHP_AMQP_G(error_code) TSRMLS_CC); + php_amqp_zend_throw_exception(reply, exception_ce, PHP_AMQP_G(error_message), PHP_AMQP_G(error_code)); } void php_amqp_zend_throw_exception( amqp_rpc_reply_t reply, zend_class_entry *exception_ce, const char *message, - zend_long code TSRMLS_DC + zend_long code ) { switch (reply.reply_type) { @@ -477,7 +475,7 @@ void php_amqp_zend_throw_exception( break; } - zend_throw_exception(exception_ce, message, code TSRMLS_CC); + zend_throw_exception(exception_ce, message, code); } diff --git a/amqp_basic_properties.c b/amqp_basic_properties.c index 37ec67b6..40aca91b 100644 --- a/amqp_basic_properties.c +++ b/amqp_basic_properties.c @@ -66,21 +66,21 @@ zend_class_entry *amqp_basic_properties_class_entry; #define this_ce amqp_basic_properties_class_entry -void php_amqp_basic_properties_convert_to_zval(amqp_basic_properties_t *props, zval *obj TSRMLS_DC) +void php_amqp_basic_properties_convert_to_zval(amqp_basic_properties_t *props, zval *obj) { object_init_ex(obj, this_ce); - php_amqp_basic_properties_extract(props, obj TSRMLS_CC); + php_amqp_basic_properties_extract(props, obj); } -void php_amqp_basic_properties_set_empty_headers(zval *obj TSRMLS_DC) +void php_amqp_basic_properties_set_empty_headers(zval *obj) { zval headers; ZVAL_UNDEF(&headers); array_init(&headers); - zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("headers"), &headers TSRMLS_CC); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("headers"), &headers); zval_ptr_dtor(&headers); } @@ -89,9 +89,9 @@ void php_amqp_basic_properties_set_empty_headers(zval *obj TSRMLS_DC) /* {{{ proto AMQPBasicProperties::__construct() */ static PHP_METHOD(AMQPBasicProperties, __construct) { - char *content_type = NULL; size_t content_type_len = 0; + char *content_encoding = NULL; size_t content_encoding_len = 0; @@ -102,10 +102,13 @@ static PHP_METHOD(AMQPBasicProperties, __construct) char *correlation_id = NULL; size_t correlation_id_len = 0; + char *reply_to = NULL; size_t reply_to_len = 0; + char *expiration = NULL; size_t expiration_len = 0; + char *message_id = NULL; size_t message_id_len = 0; @@ -113,16 +116,18 @@ static PHP_METHOD(AMQPBasicProperties, __construct) char *type = NULL; size_t type_len = 0; + char *user_id = NULL; size_t user_id_len = 0; + char *app_id = NULL; size_t app_id_len = 0; + char *cluster_id = NULL; size_t cluster_id_len = 0; - if (zend_parse_parameters( - ZEND_NUM_ARGS() TSRMLS_CC, + ZEND_NUM_ARGS(), "|ssallsssslssss", /* s */ &content_type, &content_type_len, @@ -154,84 +159,67 @@ static PHP_METHOD(AMQPBasicProperties, __construct) zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("content_type"), + ZEND_STRL("contentType"), content_type, - content_type_len TSRMLS_CC + content_type_len ); zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("content_encoding"), + ZEND_STRL("contentEncoding"), content_encoding, - content_encoding_len TSRMLS_CC + content_encoding_len ); if (headers != NULL) { - zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("headers"), headers TSRMLS_CC); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("headers"), headers); } else { - php_amqp_basic_properties_set_empty_headers(getThis() TSRMLS_CC); + php_amqp_basic_properties_set_empty_headers(getThis()); } - zend_update_property_long( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("delivery_mode"), - delivery_mode TSRMLS_CC - ); - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("priority"), priority TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("deliveryMode"), delivery_mode); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("priority"), priority); zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("correlation_id"), + ZEND_STRL("correlationId"), correlation_id, - correlation_id_len TSRMLS_CC + correlation_id_len ); zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("reply_to"), + ZEND_STRL("replyTo"), reply_to, - reply_to_len TSRMLS_CC + reply_to_len ); zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("expiration"), expiration, - expiration_len TSRMLS_CC + expiration_len ); zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("message_id"), + ZEND_STRL("messageId"), message_id, - message_id_len TSRMLS_CC + message_id_len ); - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("timestamp"), timestamp TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("timestamp"), timestamp); - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("type"), type, type_len TSRMLS_CC); - zend_update_property_stringl( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("user_id"), - user_id, - user_id_len TSRMLS_CC - ); - zend_update_property_stringl( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("app_id"), - app_id, - app_id_len TSRMLS_CC - ); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("type"), type, type_len); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("userId"), user_id, user_id_len); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("appId"), app_id, app_id_len); zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("cluster_id"), + ZEND_STRL("clusterId"), cluster_id, - cluster_id_len TSRMLS_CC + cluster_id_len ); } /* }}} */ @@ -241,7 +229,7 @@ static PHP_METHOD(AMQPBasicProperties, getContentType) { zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("content_type"); + PHP_AMQP_RETURN_THIS_PROP("contentType"); } /* }}} */ @@ -250,7 +238,7 @@ static PHP_METHOD(AMQPBasicProperties, getContentEncoding) { zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("content_encoding"); + PHP_AMQP_RETURN_THIS_PROP("contentEncoding"); } /* }}} */ @@ -268,7 +256,7 @@ static PHP_METHOD(AMQPBasicProperties, getDeliveryMode) { zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("delivery_mode"); + PHP_AMQP_RETURN_THIS_PROP("deliveryMode"); } /* }}} */ @@ -286,7 +274,7 @@ static PHP_METHOD(AMQPBasicProperties, getCorrelationId) { zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("correlation_id"); + PHP_AMQP_RETURN_THIS_PROP("correlationId"); } /* }}} */ @@ -295,7 +283,7 @@ static PHP_METHOD(AMQPBasicProperties, getReplyTo) { zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("reply_to"); + PHP_AMQP_RETURN_THIS_PROP("replyTo"); } /* }}} */ @@ -314,7 +302,7 @@ static PHP_METHOD(AMQPBasicProperties, getMessageId) { zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("message_id"); + PHP_AMQP_RETURN_THIS_PROP("messageId"); } /* }}} */ @@ -341,7 +329,7 @@ static PHP_METHOD(AMQPBasicProperties, getUserId) { zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("user_id"); + PHP_AMQP_RETURN_THIS_PROP("userId"); } /* }}} */ @@ -350,7 +338,7 @@ static PHP_METHOD(AMQPBasicProperties, getAppId) { zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("app_id"); + PHP_AMQP_RETURN_THIS_PROP("appId"); } /* }}} */ @@ -359,53 +347,139 @@ static PHP_METHOD(AMQPBasicProperties, getClusterId) { zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("cluster_id"); + PHP_AMQP_RETURN_THIS_PROP("clusterId"); } /* }}} */ ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class__construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, contentType, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, contentEncoding, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, headers, IS_ARRAY, 0, "[]") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, deliveryMode, IS_LONG, 0, "AMQP_DELIVERY_MODE_TRANSIENT") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, priority, IS_LONG, 0, "0") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, correlationId, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, replyTo, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, expiration, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, messageId, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timestamp, IS_LONG, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, type, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, userId, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, appId, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, clusterId, IS_STRING, 1, "null") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getContentType, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX( + arginfo_amqp_basic_properties_class_getContentType, + ZEND_SEND_BY_VAL, + 0, + IS_STRING, + 1 +) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getContentEncoding, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX( + arginfo_amqp_basic_properties_class_getContentEncoding, + ZEND_SEND_BY_VAL, + 0, + IS_STRING, + 1 +) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getHeaders, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX( + arginfo_amqp_basic_properties_class_getHeaders, + ZEND_SEND_BY_VAL, + 0, + IS_ARRAY, + 0 +) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getDeliveryMode, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX( + arginfo_amqp_basic_properties_class_getDeliveryMode, + ZEND_SEND_BY_VAL, + 0, + IS_LONG, + 0 +) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getPriority, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX( + arginfo_amqp_basic_properties_class_getPriority, + ZEND_SEND_BY_VAL, + 0, + IS_LONG, + 0 +) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getCorrelationId, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX( + arginfo_amqp_basic_properties_class_getCorrelationId, + ZEND_SEND_BY_VAL, + 0, + IS_STRING, + 1 +) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getReplyTo, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX( + arginfo_amqp_basic_properties_class_getReplyTo, + ZEND_SEND_BY_VAL, + 0, + IS_STRING, + 1 +) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getExpiration, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX( + arginfo_amqp_basic_properties_class_getExpiration, + ZEND_SEND_BY_VAL, + 0, + IS_STRING, + 1 +) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getMessageId, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX( + arginfo_amqp_basic_properties_class_getMessageId, + ZEND_SEND_BY_VAL, + 0, + IS_STRING, + 1 +) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getTimestamp, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX( + arginfo_amqp_basic_properties_class_getTimestamp, + ZEND_SEND_BY_VAL, + 0, + IS_LONG, + 1 +) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getType, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_basic_properties_class_getType, ZEND_SEND_BY_VAL, 0, IS_STRING, 1) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getUserId, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX( + arginfo_amqp_basic_properties_class_getUserId, + ZEND_SEND_BY_VAL, + 0, + IS_STRING, + 1 +) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getAppId, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_basic_properties_class_getAppId, ZEND_SEND_BY_VAL, 0, IS_STRING, 1) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_basic_properties_class_getClusterId, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX( + arginfo_amqp_basic_properties_class_getClusterId, + ZEND_SEND_BY_VAL, + 0, + IS_STRING, + 1 +) ZEND_END_ARG_INFO() @@ -435,44 +509,60 @@ zend_function_entry amqp_basic_properties_class_functions[] = { {NULL, NULL, NULL} }; +#define PHP_AMQP_ZVAL_AMQP_DELIVERY_NONPERSISTENT(v) ZVAL_LONG(v, AMQP_DELIVERY_NONPERSISTENT) PHP_MINIT_FUNCTION(amqp_basic_properties) { zend_class_entry ce; INIT_CLASS_ENTRY(ce, "AMQPBasicProperties", amqp_basic_properties_class_functions); - this_ce = zend_register_internal_class(&ce TSRMLS_CC); + this_ce = zend_register_internal_class(&ce); - zend_declare_property_stringl(this_ce, ZEND_STRL("content_type"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_stringl(this_ce, ZEND_STRL("content_encoding"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "contentType", ZEND_ACC_PRIVATE, IS_STRING, 1); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "contentEncoding", ZEND_ACC_PRIVATE, IS_STRING, 1); - zend_declare_property_null(this_ce, ZEND_STRL("headers"), ZEND_ACC_PRIVATE TSRMLS_CC); +#if PHP_VERSION_ID >= 80000 + PHP_AMQP_DECLARE_TYPED_PROPERTY_WITH_DEFAULT(this_ce, "headers", ZEND_ACC_PRIVATE, IS_ARRAY, 0, ZVAL_EMPTY_ARRAY); +#else + PHP_AMQP_DECLARE_TYPED_PROPERTY_WITH_DEFAULT(this_ce, "headers", ZEND_ACC_PRIVATE, IS_ARRAY, 0, ZVAL_NULL); +#endif - zend_declare_property_long( + PHP_AMQP_DECLARE_TYPED_PROPERTY_WITH_DEFAULT( this_ce, - ZEND_STRL("delivery_mode"), - AMQP_DELIVERY_NONPERSISTENT, - ZEND_ACC_PRIVATE TSRMLS_CC + "deliveryMode", + ZEND_ACC_PRIVATE, + IS_LONG, + 0, + PHP_AMQP_ZVAL_AMQP_DELIVERY_NONPERSISTENT + ); + zval default_priority; + ZVAL_LONG(&default_priority, 0); + PHP_AMQP_DECLARE_TYPED_PROPERTY_ZVAL( + this_ce, + "priority", + ZEND_ACC_PRIVATE, + PHP_AMQP_DECLARE_PROPERTY_TYPE(IS_LONG, 0), + default_priority ); - zend_declare_property_long(this_ce, ZEND_STRL("priority"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_stringl(this_ce, ZEND_STRL("correlation_id"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_stringl(this_ce, ZEND_STRL("reply_to"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_stringl(this_ce, ZEND_STRL("expiration"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_stringl(this_ce, ZEND_STRL("message_id"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "correlationId", ZEND_ACC_PRIVATE, IS_STRING, 1); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "replyTo", ZEND_ACC_PRIVATE, IS_STRING, 1); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "expiration", ZEND_ACC_PRIVATE, IS_STRING, 1); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "messageId", ZEND_ACC_PRIVATE, IS_STRING, 1); - zend_declare_property_long(this_ce, ZEND_STRL("timestamp"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "timestamp", ZEND_ACC_PRIVATE, IS_LONG, 1); - zend_declare_property_stringl(this_ce, ZEND_STRL("type"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_stringl(this_ce, ZEND_STRL("user_id"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_stringl(this_ce, ZEND_STRL("app_id"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_stringl(this_ce, ZEND_STRL("cluster_id"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "type", ZEND_ACC_PRIVATE, IS_STRING, 1); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "userId", ZEND_ACC_PRIVATE, IS_STRING, 1); + + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "appId", ZEND_ACC_PRIVATE, IS_STRING, 1); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "clusterId", ZEND_ACC_PRIVATE, IS_STRING, 1); return SUCCESS; } -void parse_amqp_table(amqp_table_t *table, zval *result TSRMLS_DC) +void parse_amqp_table(amqp_table_t *table, zval *result) { int i; zend_bool has_value = 0; @@ -545,7 +635,7 @@ void parse_amqp_table(amqp_table_t *table, zval *result TSRMLS_DC) ZVAL_UNDEF(&subtable); array_init(&subtable); - parse_amqp_table(&(entry->value.value.array.entries[j].value.table), &subtable TSRMLS_CC); + parse_amqp_table(&(entry->value.value.array.entries[j].value.table), &subtable); add_next_index_zval(&value, &subtable); } break; default: @@ -555,16 +645,14 @@ void parse_amqp_table(amqp_table_t *table, zval *result TSRMLS_DC) } break; case AMQP_FIELD_KIND_TABLE: array_init(&value); - parse_amqp_table(&(entry->value.value.table), &value TSRMLS_CC); + parse_amqp_table(&(entry->value.value.table), &value); break; case AMQP_FIELD_KIND_TIMESTAMP: { - char timestamp_str[20]; zval timestamp; ZVAL_UNDEF(×tamp); - int length = snprintf(timestamp_str, sizeof(timestamp_str), ZEND_ULONG_FMT, entry->value.value.u64); - ZVAL_STRINGL(×tamp, (char *) timestamp_str, length); + ZVAL_DOUBLE(×tamp, entry->value.value.u64); object_init_ex(&value, amqp_timestamp_class_entry); zend_call_method_with_1_params( @@ -575,8 +663,6 @@ void parse_amqp_table(amqp_table_t *table, zval *result TSRMLS_DC) NULL, ×tamp ); - - zval_ptr_dtor(×tamp); break; } @@ -627,7 +713,7 @@ void parse_amqp_table(amqp_table_t *table, zval *result TSRMLS_DC) return; } -void php_amqp_basic_properties_extract(amqp_basic_properties_t *p, zval *obj TSRMLS_DC) +void php_amqp_basic_properties_extract(amqp_basic_properties_t *p, zval *obj) { zval headers; @@ -638,93 +724,82 @@ void php_amqp_basic_properties_extract(amqp_basic_properties_t *p, zval *obj TSR zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), - ZEND_STRL("content_type"), + ZEND_STRL("contentType"), (const char *) p->content_type.bytes, - (size_t) p->content_type.len TSRMLS_CC + (size_t) p->content_type.len ); } else { /* BC */ - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("content_type"), "", 0 TSRMLS_CC); + zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("contentType")); } if (p->_flags & AMQP_BASIC_CONTENT_ENCODING_FLAG) { zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), - ZEND_STRL("content_encoding"), + ZEND_STRL("contentEncoding"), (const char *) p->content_encoding.bytes, - (size_t) p->content_encoding.len TSRMLS_CC + (size_t) p->content_encoding.len ); } else { /* BC */ - zend_update_property_stringl( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(obj), - ZEND_STRL("content_encoding"), - "", - 0 TSRMLS_CC - ); + zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("contentEncoding")); } if (p->_flags & AMQP_BASIC_HEADERS_FLAG) { - parse_amqp_table(&(p->headers), &headers TSRMLS_CC); + parse_amqp_table(&(p->headers), &headers); } - zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("headers"), &headers TSRMLS_CC); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("headers"), &headers); if (p->_flags & AMQP_BASIC_DELIVERY_MODE_FLAG) { zend_update_property_long( this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), - ZEND_STRL("delivery_mode"), - (zend_long) p->delivery_mode TSRMLS_CC + ZEND_STRL("deliveryMode"), + (zend_long) p->delivery_mode ); } else { /* BC */ zend_update_property_long( this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), - ZEND_STRL("delivery_mode"), - AMQP_DELIVERY_NONPERSISTENT TSRMLS_CC + ZEND_STRL("deliveryMode"), + AMQP_DELIVERY_NONPERSISTENT ); } if (p->_flags & AMQP_BASIC_PRIORITY_FLAG) { - zend_update_property_long( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(obj), - ZEND_STRL("priority"), - (zend_long) p->priority TSRMLS_CC - ); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("priority"), (zend_long) p->priority); } else { /* BC */ - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("priority"), 0 TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("priority"), 0); } if (p->_flags & AMQP_BASIC_CORRELATION_ID_FLAG) { zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), - ZEND_STRL("correlation_id"), + ZEND_STRL("correlationId"), (const char *) p->correlation_id.bytes, - (size_t) p->correlation_id.len TSRMLS_CC + (size_t) p->correlation_id.len ); } else { /* BC */ - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("correlation_id"), "", 0 TSRMLS_CC); + zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("correlationId")); } if (p->_flags & AMQP_BASIC_REPLY_TO_FLAG) { zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), - ZEND_STRL("reply_to"), + ZEND_STRL("replyTo"), (const char *) p->reply_to.bytes, - (size_t) p->reply_to.len TSRMLS_CC + (size_t) p->reply_to.len ); } else { /* BC */ - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("reply_to"), "", 0 TSRMLS_CC); + zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("replyTo")); } if (p->_flags & AMQP_BASIC_EXPIRATION_FLAG) { @@ -733,24 +808,24 @@ void php_amqp_basic_properties_extract(amqp_basic_properties_t *p, zval *obj TSR PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("expiration"), (const char *) p->expiration.bytes, - (size_t) p->expiration.len TSRMLS_CC + (size_t) p->expiration.len ); } else { /* BC */ - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("expiration"), "", 0 TSRMLS_CC); + zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("expiration")); } if (p->_flags & AMQP_BASIC_MESSAGE_ID_FLAG) { zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), - ZEND_STRL("message_id"), + ZEND_STRL("messageId"), (const char *) p->message_id.bytes, - (size_t) p->message_id.len TSRMLS_CC + (size_t) p->message_id.len ); } else { /* BC */ - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("message_id"), "", 0 TSRMLS_CC); + zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("messageId")); } if (p->_flags & AMQP_BASIC_TIMESTAMP_FLAG) { @@ -758,11 +833,11 @@ void php_amqp_basic_properties_extract(amqp_basic_properties_t *p, zval *obj TSR this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("timestamp"), - (zend_long) p->timestamp TSRMLS_CC + (zend_long) p->timestamp ); } else { /* BC */ - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("timestamp"), 0 TSRMLS_CC); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("timestamp"), 0); } if (p->_flags & AMQP_BASIC_TYPE_FLAG) { @@ -771,37 +846,37 @@ void php_amqp_basic_properties_extract(amqp_basic_properties_t *p, zval *obj TSR PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("type"), (const char *) p->type.bytes, - (size_t) p->type.len TSRMLS_CC + (size_t) p->type.len ); } else { /* BC */ - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("type"), "", 0 TSRMLS_CC); + zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("type")); } if (p->_flags & AMQP_BASIC_USER_ID_FLAG) { zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), - ZEND_STRL("user_id"), + ZEND_STRL("userId"), (const char *) p->user_id.bytes, - (size_t) p->user_id.len TSRMLS_CC + (size_t) p->user_id.len ); } else { /* BC */ - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("user_id"), "", 0 TSRMLS_CC); + zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("userId")); } if (p->_flags & AMQP_BASIC_APP_ID_FLAG) { zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), - ZEND_STRL("app_id"), + ZEND_STRL("appId"), (const char *) p->app_id.bytes, - (size_t) p->app_id.len TSRMLS_CC + (size_t) p->app_id.len ); } else { /* BC */ - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("app_id"), "", 0 TSRMLS_CC); + zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("appId")); } zval_ptr_dtor(&headers); diff --git a/amqp_basic_properties.h b/amqp_basic_properties.h index a322ac67..bd27e92f 100644 --- a/amqp_basic_properties.h +++ b/amqp_basic_properties.h @@ -26,12 +26,12 @@ extern zend_class_entry *amqp_basic_properties_class_entry; -void parse_amqp_table(amqp_table_t *table, zval *result TSRMLS_DC); -void php_amqp_basic_properties_extract(amqp_basic_properties_t *p, zval *obj TSRMLS_DC); +void parse_amqp_table(amqp_table_t *table, zval *result); +void php_amqp_basic_properties_extract(amqp_basic_properties_t *p, zval *obj); -void php_amqp_basic_properties_convert_to_zval(amqp_basic_properties_t *props, zval *obj TSRMLS_DC); -void php_amqp_basic_properties_set_empty_headers(zval *obj TSRMLS_DC); +void php_amqp_basic_properties_convert_to_zval(amqp_basic_properties_t *props, zval *obj); +void php_amqp_basic_properties_set_empty_headers(zval *obj); PHP_MINIT_FUNCTION(amqp_basic_properties); diff --git a/amqp_channel.c b/amqp_channel.c index cd91dbb0..cd492792 100644 --- a/amqp_channel.c +++ b/amqp_channel.c @@ -66,7 +66,7 @@ zend_class_entry *amqp_channel_class_entry; zend_object_handlers amqp_channel_object_handlers; -void php_amqp_close_channel(amqp_channel_resource *channel_resource, zend_bool check_errors TSRMLS_DC) +void php_amqp_close_channel(amqp_channel_resource *channel_resource, zend_bool check_errors) { assert(channel_resource != NULL); @@ -96,7 +96,7 @@ void php_amqp_close_channel(amqp_channel_resource *channel_resource, zend_bool c amqp_rpc_reply_t res = amqp_get_rpc_reply(connection_resource->connection_state); if (check_errors && PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); return; } @@ -184,7 +184,7 @@ static HashTable *amqp_channel_gc(zend_object *object, zval **table, int *n) /* *table = channel->gc_data; *n = cnt; - return zend_std_get_properties(object TSRMLS_CC); + return zend_std_get_properties(object); } /* }}} */ static void php_amqp_clean_callbacks(amqp_channel_callbacks *callbacks) @@ -195,12 +195,12 @@ static void php_amqp_clean_callbacks(amqp_channel_callbacks *callbacks) } -void amqp_channel_free(zend_object *object TSRMLS_DC) +void amqp_channel_free(zend_object *object) { amqp_channel_object *channel = PHP_AMQP_FETCH_CHANNEL(object); if (channel->channel_resource != NULL) { - php_amqp_close_channel(channel->channel_resource, 0 TSRMLS_CC); + php_amqp_close_channel(channel->channel_resource, 0); efree(channel->channel_resource); channel->channel_resource = NULL; @@ -212,16 +212,16 @@ void amqp_channel_free(zend_object *object TSRMLS_DC) php_amqp_clean_callbacks(&channel->callbacks); - zend_object_std_dtor(&channel->zo TSRMLS_CC); + zend_object_std_dtor(&channel->zo); } -zend_object *amqp_channel_ctor(zend_class_entry *ce TSRMLS_DC) +zend_object *amqp_channel_ctor(zend_class_entry *ce) { amqp_channel_object *channel = (amqp_channel_object *) ecalloc(1, sizeof(amqp_channel_object) + zend_object_properties_size(ce)); - zend_object_std_init(&channel->zo, ce TSRMLS_CC); + zend_object_std_init(&channel->zo, ce); AMQP_OBJECT_PROPERTIES_INIT(channel->zo, ce); #if PHP_MAJOR_VERSION >= 7 @@ -232,7 +232,7 @@ zend_object *amqp_channel_ctor(zend_class_entry *ce TSRMLS_DC) zend_object *new_value; new_value.handle = - zend_objects_store_put(channel, NULL, (zend_objects_free_object_storage_t) amqp_channel_free, NULL TSRMLS_CC); + zend_objects_store_put(channel, NULL, (zend_objects_free_object_storage_t) amqp_channel_free, NULL); new_value.handlers = zend_get_std_object_handlers(); @@ -254,13 +254,8 @@ static PHP_METHOD(amqp_channel_class, __construct) amqp_connection_object *connection; /* Parse out the method parameters */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &connection_object, amqp_connection_class_entry) == - FAILURE) { - zend_throw_exception( - amqp_channel_exception_class_entry, - "Parameter must be an instance of AMQPConnection.", - 0 TSRMLS_CC - ); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &connection_object, amqp_connection_class_entry) == FAILURE) { + zend_throw_exception(amqp_channel_exception_class_entry, "Parameter must be an instance of AMQPConnection.", 0); RETURN_NULL(); } @@ -269,7 +264,7 @@ static PHP_METHOD(amqp_channel_class, __construct) ZVAL_UNDEF(&consumers); array_init(&consumers); - zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("consumers"), &consumers TSRMLS_CC); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("consumers"), &consumers); zval_ptr_dtor(&consumers); @@ -279,32 +274,32 @@ static PHP_METHOD(amqp_channel_class, __construct) zend_update_property_long( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("prefetch_count"), - INI_INT("amqp.prefetch_count") TSRMLS_CC + ZEND_STRL("prefetchCount"), + INI_INT("amqp.prefetch_count") ); /* Set the prefetch size */ zend_update_property_long( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("prefetch_size"), - INI_INT("amqp.prefetch_size") TSRMLS_CC + ZEND_STRL("prefetchSize"), + INI_INT("amqp.prefetch_size") ); /* Set the global prefetch count */ zend_update_property_long( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("global_prefetch_count"), - INI_INT("amqp.global_prefetch_count") TSRMLS_CC + ZEND_STRL("globalPrefetchCount"), + INI_INT("amqp.global_prefetch_count") ); /* Set the global prefetch size */ zend_update_property_long( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("global_prefetch_size"), - INI_INT("amqp.global_prefetch_size") TSRMLS_CC + ZEND_STRL("globalPrefetchSize"), + INI_INT("amqp.global_prefetch_size") ); /* Pull out and verify the connection */ @@ -315,7 +310,7 @@ static PHP_METHOD(amqp_channel_class, __construct) zend_throw_exception( amqp_channel_exception_class_entry, "Could not create channel. No connection resource.", - 0 TSRMLS_CC + 0 ); return; } @@ -324,17 +319,12 @@ static PHP_METHOD(amqp_channel_class, __construct) zend_throw_exception( amqp_channel_exception_class_entry, "Could not create channel. Connection resource is not connected.", - 0 TSRMLS_CC + 0 ); return; } - zend_update_property( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("connection"), - connection_object TSRMLS_CC - ); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connection"), connection_object); channel_resource = (amqp_channel_resource *) ecalloc(1, sizeof(amqp_channel_resource)); channel->channel_resource = channel_resource; @@ -349,7 +339,7 @@ static PHP_METHOD(amqp_channel_class, __construct) zend_throw_exception( amqp_channel_exception_class_entry, "Could not create channel. Connection has no open channel slots remaining.", - 0 TSRMLS_CC + 0 ); return; } @@ -362,7 +352,7 @@ static PHP_METHOD(amqp_channel_class, __construct) zend_throw_exception( amqp_channel_exception_class_entry, "Could not create channel. Failed to add channel to connection slot.", - 0 TSRMLS_CC + 0 ); } @@ -374,18 +364,13 @@ static PHP_METHOD(amqp_channel_class, __construct) if (!r) { amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - php_amqp_error( - res, - &PHP_AMQP_G(error_message), - channel_resource->connection_resource, - channel_resource TSRMLS_CC - ); + php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource); php_amqp_zend_throw_exception( res, amqp_channel_exception_class_entry, PHP_AMQP_G(error_message), - PHP_AMQP_G(error_code) TSRMLS_CC + PHP_AMQP_G(error_code) ); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); @@ -411,8 +396,8 @@ static PHP_METHOD(amqp_channel_class, __construct) amqp_basic_qos( channel_resource->connection_resource->connection_state, channel_resource->channel_id, - 0, /* prefetch window size */ - (uint16_t) PHP_AMQP_READ_THIS_PROP_LONG("prefetch_count"), /* prefetch message count */ + 0, /* prefetch window size */ + (uint16_t) PHP_AMQP_READ_THIS_PROP_LONG("prefetchCount"), /* prefetch message count */ /* NOTE that RabbitMQ has reinterpreted global flag field. See https://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.qos.global for details */ 0 /* global flag */ ); @@ -420,15 +405,15 @@ static PHP_METHOD(amqp_channel_class, __construct) amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - uint32_t global_prefetch_size = (uint32_t) PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_size"); - uint16_t global_prefetch_count = (uint16_t) PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_count"); + uint32_t global_prefetch_size = (uint32_t) PHP_AMQP_READ_THIS_PROP_LONG("globalPrefetchSize"); + uint16_t global_prefetch_count = (uint16_t) PHP_AMQP_READ_THIS_PROP_LONG("globalPrefetchCount"); /* Set the global prefetch settings (ignoring if 0 for backwards compatibility) */ if (global_prefetch_size != 0 || global_prefetch_count != 0) { @@ -443,7 +428,7 @@ static PHP_METHOD(amqp_channel_class, __construct) res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } @@ -479,7 +464,7 @@ static PHP_METHOD(amqp_channel_class, close) channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); if (channel_resource && channel_resource->is_connected) { - php_amqp_close_channel(channel_resource, 1 TSRMLS_CC); + php_amqp_close_channel(channel_resource, 1); } } /* }}} */ @@ -511,15 +496,15 @@ static PHP_METHOD(amqp_channel_class, setPrefetchCount) amqp_channel_resource *channel_resource; zend_long prefetch_count; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &prefetch_count) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &prefetch_count) == FAILURE) { return; } if (!php_amqp_is_valid_prefetch_count(prefetch_count)) { zend_throw_exception_ex( amqp_connection_exception_class_entry, - 0 TSRMLS_CC, - "Parameter 'prefetch_count' must be between 0 and %u.", + 0, + "Parameter 'prefetchCount' must be between 0 and %u.", PHP_AMQP_MAX_PREFETCH_COUNT ); return; @@ -542,15 +527,15 @@ static PHP_METHOD(amqp_channel_class, setPrefetchCount) amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - uint32_t global_prefetch_size = (uint32_t) PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_size"); - uint16_t global_prefetch_count = (uint16_t) PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_count"); + uint32_t global_prefetch_size = (uint32_t) PHP_AMQP_READ_THIS_PROP_LONG("globalPrefetchSize"); + uint16_t global_prefetch_count = (uint16_t) PHP_AMQP_READ_THIS_PROP_LONG("globalPrefetchCount"); /* Re-apply current global prefetch settings if set (writing consumer prefetch settings will clear global prefetch settings) */ if (global_prefetch_size != 0 || global_prefetch_count != 0) { @@ -565,7 +550,7 @@ static PHP_METHOD(amqp_channel_class, setPrefetchCount) res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } @@ -575,15 +560,8 @@ static PHP_METHOD(amqp_channel_class, setPrefetchCount) } /* Set the prefetch count - the implication is to disable the size */ - zend_update_property_long( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("prefetch_count"), - prefetch_count TSRMLS_CC - ); - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("prefetch_size"), 0 TSRMLS_CC); - - RETURN_TRUE; + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("prefetchCount"), prefetch_count); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("prefetchSize"), 0); } /* }}} */ @@ -593,7 +571,7 @@ static PHP_METHOD(amqp_channel_class, getPrefetchCount) { zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("prefetch_count") + PHP_AMQP_RETURN_THIS_PROP("prefetchCount") } /* }}} */ @@ -606,15 +584,15 @@ static PHP_METHOD(amqp_channel_class, setPrefetchSize) amqp_channel_resource *channel_resource; zend_long prefetch_size; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &prefetch_size) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &prefetch_size) == FAILURE) { return; } if (!php_amqp_is_valid_prefetch_size(prefetch_size)) { zend_throw_exception_ex( amqp_connection_exception_class_entry, - 0 TSRMLS_CC, - "Parameter 'prefetch_size' must be between 0 and %u.", + 0, + "Parameter 'prefetchSize' must be between 0 and %u.", PHP_AMQP_MAX_PREFETCH_SIZE ); return; @@ -636,15 +614,15 @@ static PHP_METHOD(amqp_channel_class, setPrefetchSize) amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - uint32_t global_prefetch_size = (uint32_t) PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_size"); - uint16_t global_prefetch_count = (uint16_t) PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_count"); + uint32_t global_prefetch_size = (uint32_t) PHP_AMQP_READ_THIS_PROP_LONG("globalPrefetchSize"); + uint16_t global_prefetch_count = (uint16_t) PHP_AMQP_READ_THIS_PROP_LONG("globalPrefetchCount"); /* Re-apply current global prefetch settings if set (writing consumer prefetch settings will clear global prefetch settings) */ if (global_prefetch_size != 0 || global_prefetch_count != 0) { @@ -659,7 +637,7 @@ static PHP_METHOD(amqp_channel_class, setPrefetchSize) res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } @@ -669,15 +647,8 @@ static PHP_METHOD(amqp_channel_class, setPrefetchSize) } /* Set the prefetch size - the implication is to disable the count */ - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("prefetch_count"), 0 TSRMLS_CC); - zend_update_property_long( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("prefetch_size"), - prefetch_size TSRMLS_CC - ); - - RETURN_TRUE; + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("prefetchCount"), 0); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("prefetchSize"), prefetch_size); } /* }}} */ @@ -687,7 +658,7 @@ static PHP_METHOD(amqp_channel_class, getPrefetchSize) { zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("prefetch_size") + PHP_AMQP_RETURN_THIS_PROP("prefetchSize") } /* }}} */ @@ -698,15 +669,15 @@ static PHP_METHOD(amqp_channel_class, setGlobalPrefetchCount) amqp_channel_resource *channel_resource; zend_long global_prefetch_count; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &global_prefetch_count) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &global_prefetch_count) == FAILURE) { return; } if (!php_amqp_is_valid_prefetch_count(global_prefetch_count)) { zend_throw_exception_ex( amqp_connection_exception_class_entry, - 0 TSRMLS_CC, - "Parameter 'global_prefetch_count' must be between 0 and %u.", + 0, + "Parameter 'globalPrefetchCount' must be between 0 and %u.", PHP_AMQP_MAX_PREFETCH_COUNT ); return; @@ -729,7 +700,7 @@ static PHP_METHOD(amqp_channel_class, setGlobalPrefetchCount) amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } @@ -741,12 +712,10 @@ static PHP_METHOD(amqp_channel_class, setGlobalPrefetchCount) zend_update_property_long( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("global_prefetch_count"), - global_prefetch_count TSRMLS_CC + ZEND_STRL("globalPrefetchCount"), + global_prefetch_count ); - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("global_prefetch_size"), 0 TSRMLS_CC); - - RETURN_TRUE; + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("globalPrefetchSize"), 0); } /* }}} */ @@ -756,7 +725,7 @@ static PHP_METHOD(amqp_channel_class, getGlobalPrefetchCount) { zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("global_prefetch_count") + PHP_AMQP_RETURN_THIS_PROP("globalPrefetchCount") } /* }}} */ @@ -767,15 +736,15 @@ static PHP_METHOD(amqp_channel_class, setGlobalPrefetchSize) amqp_channel_resource *channel_resource; zend_long global_prefetch_size; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &global_prefetch_size) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &global_prefetch_size) == FAILURE) { return; } if (!php_amqp_is_valid_prefetch_size(global_prefetch_size)) { zend_throw_exception_ex( amqp_connection_exception_class_entry, - 0 TSRMLS_CC, - "Parameter 'global_prefetch_size' must be between 0 and %u.", + 0, + "Parameter 'globalPrefetchSize' must be between 0 and %u.", PHP_AMQP_MAX_PREFETCH_SIZE ); return; @@ -798,7 +767,7 @@ static PHP_METHOD(amqp_channel_class, setGlobalPrefetchSize) amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } @@ -807,20 +776,13 @@ static PHP_METHOD(amqp_channel_class, setGlobalPrefetchSize) } /* Set the global prefetch size - the implication is to disable the count */ + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("globalPrefetchCount"), 0); zend_update_property_long( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("global_prefetch_count"), - 0 TSRMLS_CC - ); - zend_update_property_long( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("global_prefetch_size"), - global_prefetch_size TSRMLS_CC + ZEND_STRL("globalPrefetchSize"), + global_prefetch_size ); - - RETURN_TRUE; } /* }}} */ @@ -830,7 +792,7 @@ static PHP_METHOD(amqp_channel_class, getGlobalPrefetchSize) { zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("global_prefetch_size") + PHP_AMQP_RETURN_THIS_PROP("globalPrefetchSize") } /* }}} */ @@ -845,7 +807,7 @@ static PHP_METHOD(amqp_channel_class, qos) zend_long prefetch_count; zend_bool global = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll|b", &prefetch_size, &prefetch_count, &global) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|b", &prefetch_size, &prefetch_count, &global) == FAILURE) { return; } @@ -857,27 +819,22 @@ static PHP_METHOD(amqp_channel_class, qos) zend_update_property_long( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("global_prefetch_size"), - prefetch_size TSRMLS_CC + ZEND_STRL("globalPrefetchSize"), + prefetch_size ); zend_update_property_long( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("global_prefetch_count"), - prefetch_count TSRMLS_CC + ZEND_STRL("globalPrefetchCount"), + prefetch_count ); } else { + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("prefetchSize"), prefetch_size); zend_update_property_long( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("prefetch_size"), - prefetch_size TSRMLS_CC - ); - zend_update_property_long( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("prefetch_count"), - prefetch_count TSRMLS_CC + ZEND_STRL("prefetchCount"), + prefetch_count ); } @@ -886,8 +843,8 @@ static PHP_METHOD(amqp_channel_class, qos) amqp_basic_qos( channel_resource->connection_resource->connection_state, channel_resource->channel_id, - (uint32_t) PHP_AMQP_READ_THIS_PROP_LONG("prefetch_size"), - (uint16_t) PHP_AMQP_READ_THIS_PROP_LONG("prefetch_count"), + (uint32_t) PHP_AMQP_READ_THIS_PROP_LONG("prefetchSize"), + (uint16_t) PHP_AMQP_READ_THIS_PROP_LONG("prefetchCount"), /* NOTE that RabbitMQ has reinterpreted global flag field. See https://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.qos.global for details */ 0 /* Global flag - whether this change should affect every channel_resource */ ); @@ -895,15 +852,15 @@ static PHP_METHOD(amqp_channel_class, qos) amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - uint32_t global_prefetch_size = (uint32_t) PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_size"); - uint16_t global_prefetch_count = (uint16_t) PHP_AMQP_READ_THIS_PROP_LONG("global_prefetch_count"); + uint32_t global_prefetch_size = (uint32_t) PHP_AMQP_READ_THIS_PROP_LONG("globalPrefetchSize"); + uint16_t global_prefetch_count = (uint16_t) PHP_AMQP_READ_THIS_PROP_LONG("globalPrefetchCount"); /* Re-apply current global prefetch settings if set (writing consumer prefetch settings will clear global prefetch settings) */ if (global_prefetch_size != 0 || global_prefetch_count != 0) { @@ -918,7 +875,7 @@ static PHP_METHOD(amqp_channel_class, qos) res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } @@ -926,8 +883,6 @@ static PHP_METHOD(amqp_channel_class, qos) php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); } } - - RETURN_TRUE; } /* }}} */ @@ -940,7 +895,7 @@ static PHP_METHOD(amqp_channel_class, startTransaction) amqp_rpc_reply_t res; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) { return; } @@ -952,14 +907,12 @@ static PHP_METHOD(amqp_channel_class, startTransaction) res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - - RETURN_TRUE; } /* }}} */ @@ -972,7 +925,7 @@ static PHP_METHOD(amqp_channel_class, commitTransaction) amqp_rpc_reply_t res; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) { return; } @@ -984,14 +937,12 @@ static PHP_METHOD(amqp_channel_class, commitTransaction) res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - - RETURN_TRUE; } /* }}} */ @@ -1003,7 +954,7 @@ static PHP_METHOD(amqp_channel_class, rollbackTransaction) amqp_rpc_reply_t res; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) { return; } @@ -1016,14 +967,12 @@ static PHP_METHOD(amqp_channel_class, rollbackTransaction) res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - - RETURN_TRUE; } /* }}} */ @@ -1047,7 +996,7 @@ static PHP_METHOD(amqp_channel_class, basicRecover) zend_bool requeue = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &requeue) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &requeue) == FAILURE) { return; } @@ -1063,14 +1012,12 @@ static PHP_METHOD(amqp_channel_class, basicRecover) res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - - RETURN_TRUE; } /* }}} */ @@ -1081,7 +1028,7 @@ PHP_METHOD(amqp_channel_class, confirmSelect) amqp_channel_resource *channel_resource; amqp_rpc_reply_t res; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) { return; } @@ -1093,14 +1040,12 @@ PHP_METHOD(amqp_channel_class, confirmSelect) res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry TSRMLS_CC); + php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - - RETURN_TRUE; } /* }}} */ @@ -1111,7 +1056,7 @@ PHP_METHOD(amqp_channel_class, setReturnCallback) zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fcc = empty_fcall_info_cache; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f!", &fci, &fcc) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "f!", &fci, &fcc) == FAILURE) { return; } @@ -1142,16 +1087,12 @@ PHP_METHOD(amqp_channel_class, waitForBasicReturn) struct timeval tv = {0}; struct timeval *tv_ptr = &tv; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|d", &timeout) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|d", &timeout) == FAILURE) { return; } if (timeout < 0) { - zend_throw_exception( - amqp_channel_exception_class_entry, - "Timeout must be greater than or equal to zero.", - 0 TSRMLS_CC - ); + zend_throw_exception(amqp_channel_exception_class_entry, "Timeout must be greater than or equal to zero.", 0); return; } @@ -1181,7 +1122,7 @@ PHP_METHOD(amqp_channel_class, waitForBasicReturn) ); if (AMQP_STATUS_TIMEOUT == status) { - zend_throw_exception(amqp_queue_exception_class_entry, "Wait timeout exceed", 0 TSRMLS_CC); + zend_throw_exception(amqp_queue_exception_class_entry, "Wait timeout exceed", 0); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; @@ -1199,18 +1140,13 @@ PHP_METHOD(amqp_channel_class, waitForBasicReturn) res.library_error = status; } - php_amqp_error( - res, - &PHP_AMQP_G(error_message), - channel_resource->connection_resource, - channel_resource TSRMLS_CC - ); + php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource); php_amqp_zend_throw_exception( res, amqp_queue_exception_class_entry, PHP_AMQP_G(error_message), - PHP_AMQP_G(error_code) TSRMLS_CC + PHP_AMQP_G(error_code) ); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; @@ -1221,7 +1157,7 @@ PHP_METHOD(amqp_channel_class, waitForBasicReturn) channel_resource->connection_resource, channel_resource->channel_id, channel, - &method TSRMLS_CC + &method ); if (PHP_AMQP_RESOURCE_RESPONSE_BREAK == status) { @@ -1235,18 +1171,13 @@ PHP_METHOD(amqp_channel_class, waitForBasicReturn) res.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; res.library_error = status; - php_amqp_error( - res, - &PHP_AMQP_G(error_message), - channel_resource->connection_resource, - channel_resource TSRMLS_CC - ); + php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource); php_amqp_zend_throw_exception( res, amqp_channel_exception_class_entry, PHP_AMQP_G(error_message), - PHP_AMQP_G(error_code) TSRMLS_CC + PHP_AMQP_G(error_code) ); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; @@ -1265,8 +1196,7 @@ PHP_METHOD(amqp_channel_class, setConfirmCallback) zend_fcall_info nack_fci = empty_fcall_info; zend_fcall_info_cache nack_fcc = empty_fcall_info_cache; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f!|f!", &ack_fci, &ack_fcc, &nack_fci, &nack_fcc) == - FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "f!|f!", &ack_fci, &ack_fcc, &nack_fci, &nack_fcc) == FAILURE) { return; } @@ -1306,16 +1236,12 @@ PHP_METHOD(amqp_channel_class, waitForConfirm) struct timeval tv = {0}; struct timeval *tv_ptr = &tv; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|d", &timeout) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|d", &timeout) == FAILURE) { return; } if (timeout < 0) { - zend_throw_exception( - amqp_channel_exception_class_entry, - "Timeout must be greater than or equal to zero.", - 0 TSRMLS_CC - ); + zend_throw_exception(amqp_channel_exception_class_entry, "Timeout must be greater than or equal to zero.", 0); return; } @@ -1349,7 +1275,7 @@ PHP_METHOD(amqp_channel_class, waitForConfirm) ); if (AMQP_STATUS_TIMEOUT == status) { - zend_throw_exception(amqp_queue_exception_class_entry, "Wait timeout exceed", 0 TSRMLS_CC); + zend_throw_exception(amqp_queue_exception_class_entry, "Wait timeout exceed", 0); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; @@ -1367,18 +1293,13 @@ PHP_METHOD(amqp_channel_class, waitForConfirm) res.library_error = status; } - php_amqp_error( - res, - &PHP_AMQP_G(error_message), - channel_resource->connection_resource, - channel_resource TSRMLS_CC - ); + php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource); php_amqp_zend_throw_exception( res, amqp_channel_exception_class_entry, PHP_AMQP_G(error_message), - PHP_AMQP_G(error_code) TSRMLS_CC + PHP_AMQP_G(error_code) ); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; @@ -1391,7 +1312,7 @@ PHP_METHOD(amqp_channel_class, waitForConfirm) channel_resource->connection_resource, channel_resource->channel_id, channel, - &method TSRMLS_CC + &method ); break; case AMQP_BASIC_NACK_METHOD: @@ -1400,7 +1321,7 @@ PHP_METHOD(amqp_channel_class, waitForConfirm) channel_resource->connection_resource, channel_resource->channel_id, channel, - &method TSRMLS_CC + &method ); break; case AMQP_BASIC_RETURN_METHOD: @@ -1409,7 +1330,7 @@ PHP_METHOD(amqp_channel_class, waitForConfirm) channel_resource->connection_resource, channel_resource->channel_id, channel, - &method TSRMLS_CC + &method ); break; default: @@ -1427,18 +1348,13 @@ PHP_METHOD(amqp_channel_class, waitForConfirm) res.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; res.library_error = status; - php_amqp_error( - res, - &PHP_AMQP_G(error_message), - channel_resource->connection_resource, - channel_resource TSRMLS_CC - ); + php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource); php_amqp_zend_throw_exception( res, amqp_queue_exception_class_entry, PHP_AMQP_G(error_message), - PHP_AMQP_G(error_code) TSRMLS_CC + PHP_AMQP_G(error_code) ); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; @@ -1458,93 +1374,115 @@ static PHP_METHOD(amqp_channel_class, getConsumers) ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class__construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_OBJ_INFO(0, amqp_connection, AMQPConnection, 0) + ZEND_ARG_OBJ_INFO(0, connection, AMQPConnection, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_isConnected, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_channel_class_isConnected, ZEND_SEND_BY_VAL, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_close, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_channel_class_close, ZEND_SEND_BY_VAL, 0, IS_VOID, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_getChannelId, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_channel_class_getChannelId, ZEND_SEND_BY_VAL, 0, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_setPrefetchSize, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, size) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_channel_class_setPrefetchSize, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, size, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_getPrefetchSize, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_channel_class_getPrefetchSize, ZEND_SEND_BY_VAL, 0, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_setPrefetchCount, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, count) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_channel_class_setPrefetchCount, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, count, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_getPrefetchCount, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_channel_class_getPrefetchCount, ZEND_SEND_BY_VAL, 0, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_setGlobalPrefetchSize, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, size) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX( + arginfo_amqp_channel_class_setGlobalPrefetchSize, + ZEND_SEND_BY_VAL, + 1, + IS_VOID, + 0 +) + ZEND_ARG_TYPE_INFO(0, size, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_getGlobalPrefetchSize, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX( + arginfo_amqp_channel_class_getGlobalPrefetchSize, + ZEND_SEND_BY_VAL, + 0, + IS_LONG, + 0 +) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_setGlobalPrefetchCount, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, count) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX( + arginfo_amqp_channel_class_setGlobalPrefetchCount, + ZEND_SEND_BY_VAL, + 1, + IS_VOID, + 0 +) + ZEND_ARG_TYPE_INFO(0, count, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_getGlobalPrefetchCount, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX( + arginfo_amqp_channel_class_getGlobalPrefetchCount, + ZEND_SEND_BY_VAL, + 0, + IS_LONG, + 0 +) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_qos, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 2) - ZEND_ARG_INFO(0, size) - ZEND_ARG_INFO(0, count) - ZEND_ARG_INFO(0, global) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_channel_class_qos, ZEND_SEND_BY_VAL, 2, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, size, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, count, IS_LONG, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, global, _IS_BOOL, 0, "false") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_startTransaction, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_channel_class_startTransaction, ZEND_SEND_BY_VAL, 0, IS_VOID, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_commitTransaction, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_channel_class_commitTransaction, ZEND_SEND_BY_VAL, 0, IS_VOID, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_rollbackTransaction, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_channel_class_rollbackTransaction, ZEND_SEND_BY_VAL, 0, IS_VOID, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_getConnection, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(arginfo_amqp_channel_class_getConnection, AMQPConnection, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_basicRecover, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) - ZEND_ARG_INFO(0, requeue) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_channel_class_basicRecover, ZEND_SEND_BY_VAL, 0, IS_VOID, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, requeue, _IS_BOOL, 0, "true") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_confirmSelect, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_channel_class_confirmSelect, ZEND_SEND_BY_VAL, 0, IS_VOID, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_setConfirmCallback, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, ack_callback) - ZEND_ARG_INFO(0, nack_callback) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_channel_class_setConfirmCallback, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_CALLABLE_INFO(0, ackCallback, 1) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, nackCallback, IS_CALLABLE, 1, "null") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_waitForConfirm, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) - ZEND_ARG_INFO(0, timeout) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_channel_class_waitForConfirm, ZEND_SEND_BY_VAL, 0, IS_VOID, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timeout, IS_DOUBLE, 0, "0.0") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_setReturnCallback, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, return_callback) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_channel_class_setReturnCallback, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_CALLABLE_INFO(0, returnCallback, 1) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_waitForBasicReturn, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) - ZEND_ARG_INFO(0, timeout) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_channel_class_waitForBasicReturn, ZEND_SEND_BY_VAL, 0, IS_VOID, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timeout, IS_DOUBLE, 0, "0.0") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_channel_class_getConsumers, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_channel_class_getConsumers, ZEND_SEND_BY_VAL, 0, IS_ARRAY, 0) ZEND_END_ARG_INFO() -//setConfirmsCallback - zend_function_entry amqp_channel_class_functions[] = { PHP_ME(amqp_channel_class, __construct, arginfo_amqp_channel_class__construct, ZEND_ACC_PUBLIC) @@ -1589,16 +1527,18 @@ PHP_MINIT_FUNCTION(amqp_channel) INIT_CLASS_ENTRY(ce, "AMQPChannel", amqp_channel_class_functions); ce.create_object = amqp_channel_ctor; - amqp_channel_class_entry = zend_register_internal_class(&ce TSRMLS_CC); - - zend_declare_property_null(this_ce, ZEND_STRL("connection"), ZEND_ACC_PRIVATE TSRMLS_CC); - - zend_declare_property_null(this_ce, ZEND_STRL("prefetch_count"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_long(this_ce, ZEND_STRL("prefetch_size"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("global_prefetch_count"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("global_prefetch_size"), ZEND_ACC_PRIVATE TSRMLS_CC); - - zend_declare_property_null(this_ce, ZEND_STRL("consumers"), ZEND_ACC_PRIVATE TSRMLS_CC); + amqp_channel_class_entry = zend_register_internal_class(&ce); + + PHP_AMQP_DECLARE_TYPED_PROPERTY_OBJ(this_ce, "connection", ZEND_ACC_PRIVATE, AMQPConnection, 0); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "prefetchCount", ZEND_ACC_PRIVATE, IS_LONG, 1); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "prefetchSize", ZEND_ACC_PRIVATE, IS_LONG, 1); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "globalPrefetchCount", ZEND_ACC_PRIVATE, IS_LONG, 1); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "globalPrefetchSize", ZEND_ACC_PRIVATE, IS_LONG, 1); +#if PHP_VERSION_ID >= 80000 + PHP_AMQP_DECLARE_TYPED_PROPERTY_WITH_DEFAULT(this_ce, "consumers", ZEND_ACC_PRIVATE, IS_ARRAY, 0, ZVAL_EMPTY_ARRAY); +#else + PHP_AMQP_DECLARE_TYPED_PROPERTY_WITH_DEFAULT(this_ce, "consumers", ZEND_ACC_PRIVATE, IS_ARRAY, 0, ZVAL_NULL); +#endif #if PHP_MAJOR_VERSION >= 7 memcpy(&amqp_channel_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); diff --git a/amqp_channel.h b/amqp_channel.h index 6e036cc5..b66f0865 100644 --- a/amqp_channel.h +++ b/amqp_channel.h @@ -22,6 +22,6 @@ */ extern zend_class_entry *amqp_channel_class_entry; -void php_amqp_close_channel(amqp_channel_resource *channel_resource, zend_bool check_errors TSRMLS_DC); +void php_amqp_close_channel(amqp_channel_resource *channel_resource, zend_bool check_errors); PHP_MINIT_FUNCTION(amqp_channel); diff --git a/amqp_connection.c b/amqp_connection.c index a91dcdf2..54c48132 100644 --- a/amqp_connection.c +++ b/amqp_connection.c @@ -73,23 +73,18 @@ zend_object_handlers amqp_connection_object_handlers; #define PHP_AMQP_EXTRACT_CONNECTION_STR(name) \ zdata = NULL; \ - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), (name), sizeof(name))) != NULL) { \ + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL(name))) != NULL) { \ SEPARATE_ZVAL(zdata); \ convert_to_string(zdata); \ } \ if (zdata && Z_STRLEN_P(zdata) > 0) { \ + zend_update_property_string(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(name), Z_STRVAL_P(zdata)); \ + } else if (strlen(INI_STR("amqp." name)) > 0) { \ zend_update_property_string( \ this_ce, \ PHP_AMQP_COMPAT_OBJ_P(getThis()), \ ZEND_STRL(name), \ - Z_STRVAL_P(zdata) TSRMLS_CC \ - ); \ - } else { \ - zend_update_property_string( \ - this_ce, \ - PHP_AMQP_COMPAT_OBJ_P(getThis()), \ - ZEND_STRL(name), \ - INI_STR("amqp." name) TSRMLS_CC \ + INI_STR("amqp." name) \ ); \ } @@ -100,22 +95,12 @@ zend_object_handlers amqp_connection_object_handlers; convert_to_long(zdata); \ } \ if (zdata) { \ - zend_update_property_bool( \ - this_ce, \ - PHP_AMQP_COMPAT_OBJ_P(getThis()), \ - ZEND_STRL(name), \ - Z_LVAL_P(zdata) TSRMLS_CC \ - ); \ + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(name), Z_LVAL_P(zdata)); \ } else { \ - zend_update_property_bool( \ - this_ce, \ - PHP_AMQP_COMPAT_OBJ_P(getThis()), \ - ZEND_STRL(name), \ - INI_INT("amqp." name) TSRMLS_CC \ - ); \ + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(name), INI_INT("amqp." name)); \ } -static int php_amqp_connection_resource_deleter(zval *el, amqp_connection_resource *connection_resource TSRMLS_DC) +static int php_amqp_connection_resource_deleter(zval *el, amqp_connection_resource *connection_resource) { if (Z_RES_P(el)->ptr == connection_resource) { return ZEND_HASH_APPLY_REMOVE | ZEND_HASH_APPLY_STOP; @@ -147,7 +132,7 @@ static size_t php_amqp_get_connection_hash(amqp_connection_params *params, char ); } -static void php_amqp_cleanup_connection_resource(amqp_connection_resource *connection_resource TSRMLS_DC) +static void php_amqp_cleanup_connection_resource(amqp_connection_resource *connection_resource) { if (!connection_resource) { return; @@ -163,7 +148,7 @@ static void php_amqp_cleanup_connection_resource(amqp_connection_resource *conne zend_hash_apply_with_argument( &EG(persistent_list), (apply_func_arg_t) php_amqp_connection_resource_deleter, - (void *) connection_resource TSRMLS_CC + (void *) connection_resource ); } @@ -179,18 +164,18 @@ static void php_amqp_cleanup_connection_resource(amqp_connection_resource *conne } } -static void php_amqp_disconnect(amqp_connection_resource *resource TSRMLS_DC) +static void php_amqp_disconnect(amqp_connection_resource *resource) { - php_amqp_prepare_for_disconnect(resource TSRMLS_CC); - php_amqp_cleanup_connection_resource(resource TSRMLS_CC); + php_amqp_prepare_for_disconnect(resource); + php_amqp_cleanup_connection_resource(resource); } -void php_amqp_disconnect_force(amqp_connection_resource *resource TSRMLS_DC) +void php_amqp_disconnect_force(amqp_connection_resource *resource) { - php_amqp_prepare_for_disconnect(resource TSRMLS_CC); + php_amqp_prepare_for_disconnect(resource); resource->is_dirty = '\1'; - php_amqp_cleanup_connection_resource(resource TSRMLS_CC); + php_amqp_cleanup_connection_resource(resource); } /** @@ -207,7 +192,7 @@ int php_amqp_connect(amqp_connection_object *connection, zend_bool persistent, I if (connection->connection_resource) { /* Clean up old memory allocations which are now invalid (new connection) */ - php_amqp_cleanup_connection_resource(connection->connection_resource TSRMLS_CC); + php_amqp_cleanup_connection_resource(connection->connection_resource); } assert(connection->connection_resource == NULL); @@ -219,20 +204,20 @@ int php_amqp_connect(amqp_connection_object *connection, zend_bool persistent, I connection_params.vhost = PHP_AMQP_READ_THIS_PROP_STR("vhost"); connection_params.login = PHP_AMQP_READ_THIS_PROP_STR("login"); connection_params.password = PHP_AMQP_READ_THIS_PROP_STR("password"); - connection_params.frame_max = (int) PHP_AMQP_READ_THIS_PROP_LONG("frame_max"); - connection_params.channel_max = (int) PHP_AMQP_READ_THIS_PROP_LONG("channel_max"); + connection_params.frame_max = (int) PHP_AMQP_READ_THIS_PROP_LONG("frameMax"); + connection_params.channel_max = (int) PHP_AMQP_READ_THIS_PROP_LONG("channelMax"); connection_params.heartbeat = (int) PHP_AMQP_READ_THIS_PROP_LONG("heartbeat"); - connection_params.read_timeout = PHP_AMQP_READ_THIS_PROP_DOUBLE("read_timeout"); - connection_params.write_timeout = PHP_AMQP_READ_THIS_PROP_DOUBLE("write_timeout"); - connection_params.connect_timeout = PHP_AMQP_READ_THIS_PROP_DOUBLE("connect_timeout"); - connection_params.rpc_timeout = PHP_AMQP_READ_THIS_PROP_DOUBLE("rpc_timeout"); + connection_params.read_timeout = PHP_AMQP_READ_THIS_PROP_DOUBLE("readTimeout"); + connection_params.write_timeout = PHP_AMQP_READ_THIS_PROP_DOUBLE("writeTimeout"); + connection_params.connect_timeout = PHP_AMQP_READ_THIS_PROP_DOUBLE("connectTimeout"); + connection_params.rpc_timeout = PHP_AMQP_READ_THIS_PROP_DOUBLE("rpcTimeout"); connection_params.cacert = PHP_AMQP_READ_THIS_PROP_STRLEN("cacert") ? PHP_AMQP_READ_THIS_PROP_STR("cacert") : NULL; connection_params.cert = PHP_AMQP_READ_THIS_PROP_STRLEN("cert") ? PHP_AMQP_READ_THIS_PROP_STR("cert") : NULL; connection_params.key = PHP_AMQP_READ_THIS_PROP_STRLEN("key") ? PHP_AMQP_READ_THIS_PROP_STR("key") : NULL; connection_params.verify = (int) PHP_AMQP_READ_THIS_PROP_BOOL("verify"); - connection_params.sasl_method = (int) PHP_AMQP_READ_THIS_PROP_LONG("sasl_method"); + connection_params.sasl_method = (int) PHP_AMQP_READ_THIS_PROP_LONG("saslMethod"); connection_params.connection_name = - PHP_AMQP_READ_THIS_PROP_STRLEN("connection_name") ? PHP_AMQP_READ_THIS_PROP_STR("connection_name") : NULL; + PHP_AMQP_READ_THIS_PROP_STRLEN("connectionName") ? PHP_AMQP_READ_THIS_PROP_STR("connectionName") : NULL; if (persistent) { zend_resource *le = NULL; @@ -245,6 +230,11 @@ int php_amqp_connect(amqp_connection_object *connection, zend_bool persistent, I if (le->type != le_amqp_connection_resource_persistent) { /* hash conflict, given name associate with non-amqp persistent connection resource */ + zend_throw_exception( + amqp_connection_exception_class_entry, + "Connection hash conflict detected. Persistent connection found that does not belong to AMQP.", + 0 + ); return 0; } @@ -259,7 +249,7 @@ int php_amqp_connect(amqp_connection_object *connection, zend_bool persistent, I zend_throw_exception( amqp_connection_exception_class_entry, "There are already established persistent connection to the same resource.", - 0 TSRMLS_CC + 0 ); return 0; } @@ -273,18 +263,18 @@ int php_amqp_connect(amqp_connection_object *connection, zend_bool persistent, I /* Set desired timeouts */ if (php_amqp_set_resource_read_timeout( connection->connection_resource, - PHP_AMQP_READ_THIS_PROP_DOUBLE("read_timeout") TSRMLS_CC + PHP_AMQP_READ_THIS_PROP_DOUBLE("readTimeout") ) == 0 || php_amqp_set_resource_write_timeout( connection->connection_resource, - PHP_AMQP_READ_THIS_PROP_DOUBLE("write_timeout") TSRMLS_CC + PHP_AMQP_READ_THIS_PROP_DOUBLE("writeTimeout") ) == 0 || php_amqp_set_resource_rpc_timeout( connection->connection_resource, - PHP_AMQP_READ_THIS_PROP_DOUBLE("rpc_timeout") TSRMLS_CC + PHP_AMQP_READ_THIS_PROP_DOUBLE("rpcTimeout") ) == 0) { - php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC); + php_amqp_disconnect_force(connection->connection_resource); return 0; } @@ -298,7 +288,7 @@ int php_amqp_connect(amqp_connection_object *connection, zend_bool persistent, I efree(key); } - connection->connection_resource = connection_resource_constructor(&connection_params, persistent TSRMLS_CC); + connection->connection_resource = connection_resource_constructor(&connection_params, persistent); if (connection->connection_resource == NULL) { return 0; @@ -322,11 +312,18 @@ int php_amqp_connect(amqp_connection_object *connection, zend_bool persistent, I /* Store a reference in the persistence list */ new_le.ptr = connection->connection_resource; - new_le.type = persistent ? le_amqp_connection_resource_persistent : le_amqp_connection_resource; + new_le.type = le_amqp_connection_resource_persistent; if (!zend_hash_str_update_mem(&EG(persistent_list), key, key_len, &new_le, sizeof(zend_resource))) { efree(key); - php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC); + php_amqp_disconnect_force(connection->connection_resource); + + zend_throw_exception( + amqp_connection_exception_class_entry, + "Could not store persistent connection in pool.", + 0 + ); + return 0; } efree(key); @@ -335,23 +332,23 @@ int php_amqp_connect(amqp_connection_object *connection, zend_bool persistent, I return 1; } -void amqp_connection_free(zend_object *object TSRMLS_DC) +void amqp_connection_free(zend_object *object) { amqp_connection_object *connection = PHP_AMQP_FETCH_CONNECTION(object); if (connection->connection_resource) { - php_amqp_disconnect(connection->connection_resource TSRMLS_CC); + php_amqp_disconnect(connection->connection_resource); } - zend_object_std_dtor(&connection->zo TSRMLS_CC); + zend_object_std_dtor(&connection->zo); } -zend_object *amqp_connection_ctor(zend_class_entry *ce TSRMLS_DC) +zend_object *amqp_connection_ctor(zend_class_entry *ce) { amqp_connection_object *connection = (amqp_connection_object *) ecalloc(1, sizeof(amqp_connection_object) + zend_object_properties_size(ce)); - zend_object_std_init(&connection->zo, ce TSRMLS_CC); + zend_object_std_init(&connection->zo, ce); AMQP_OBJECT_PROPERTIES_INIT(connection->zo, ce); connection->zo.handlers = &amqp_connection_object_handlers; @@ -370,13 +367,13 @@ static PHP_METHOD(amqp_connection_class, __construct) zval *zdata = NULL; /* Parse out the method parameters */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a/", &ini_arr) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|a/", &ini_arr) == FAILURE) { return; } /* Pull the login out of the $params array */ zdata = NULL; - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "login", sizeof("login") - 1)) != NULL) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("login"))) != NULL) { SEPARATE_ZVAL(zdata); convert_to_string(zdata); } @@ -385,26 +382,26 @@ static PHP_METHOD(amqp_connection_class, __construct) if (!php_amqp_is_valid_credential(Z_STR_P(zdata))) { zend_throw_exception_ex( amqp_connection_exception_class_entry, - 0 TSRMLS_CC, + 0, "Parameter 'login' exceeds %d character limit.", PHP_AMQP_MAX_CREDENTIALS_LENGTH ); return; } - zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("login"), zdata TSRMLS_CC); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("login"), zdata); } else { zend_update_property_string( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("login"), - INI_STR("amqp.login") TSRMLS_CC + INI_STR("amqp.login") ); } /* Pull the password out of the $params array */ zdata = NULL; - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "password", sizeof("password") - 1)) != NULL) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("password"))) != NULL) { SEPARATE_ZVAL(zdata); convert_to_string(zdata); } @@ -413,7 +410,7 @@ static PHP_METHOD(amqp_connection_class, __construct) if (!php_amqp_is_valid_credential(Z_STR_P(zdata))) { zend_throw_exception_ex( amqp_connection_exception_class_entry, - 0 TSRMLS_CC, + 0, "Parameter 'password' exceeds %d character limit.", PHP_AMQP_MAX_CREDENTIALS_LENGTH ); @@ -425,20 +422,20 @@ static PHP_METHOD(amqp_connection_class, __construct) PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("password"), Z_STRVAL_P(zdata), - Z_STRLEN_P(zdata) TSRMLS_CC + Z_STRLEN_P(zdata) ); } else { zend_update_property_string( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("password"), - INI_STR("amqp.password") TSRMLS_CC + INI_STR("amqp.password") ); } /* Pull the host out of the $params array */ zdata = NULL; - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "host", sizeof("host") - 1)) != NULL) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("host"))) != NULL) { SEPARATE_ZVAL(zdata); convert_to_string(zdata); } @@ -447,7 +444,7 @@ static PHP_METHOD(amqp_connection_class, __construct) if (!php_amqp_is_valid_identifier(Z_STR_P(zdata))) { zend_throw_exception_ex( amqp_connection_exception_class_entry, - 0 TSRMLS_CC, + 0, "Parameter 'host' exceeds %d character limit.", PHP_AMQP_MAX_IDENTIFIER_LENGTH ); @@ -459,20 +456,15 @@ static PHP_METHOD(amqp_connection_class, __construct) PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("host"), Z_STRVAL_P(zdata), - Z_STRLEN_P(zdata) TSRMLS_CC + Z_STRLEN_P(zdata) ); } else { - zend_update_property_string( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("host"), - INI_STR("amqp.host") TSRMLS_CC - ); + zend_update_property_string(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("host"), INI_STR("amqp.host")); } /* Pull the vhost out of the $params array */ zdata = NULL; - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "vhost", sizeof("vhost") - 1)) != NULL) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("vhost"))) != NULL) { SEPARATE_ZVAL(zdata); convert_to_string(zdata); } @@ -481,7 +473,7 @@ static PHP_METHOD(amqp_connection_class, __construct) if (!php_amqp_is_valid_identifier(Z_STR_P(zdata))) { zend_throw_exception_ex( amqp_connection_exception_class_entry, - 0 TSRMLS_CC, + 0, "Parameter 'vhost' exceeds %d character limit.", PHP_AMQP_MAX_IDENTIFIER_LENGTH ); @@ -493,32 +485,27 @@ static PHP_METHOD(amqp_connection_class, __construct) PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("vhost"), Z_STRVAL_P(zdata), - Z_STRLEN_P(zdata) TSRMLS_CC + Z_STRLEN_P(zdata) ); } else { zend_update_property_string( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("vhost"), - INI_STR("amqp.vhost") TSRMLS_CC + INI_STR("amqp.vhost") ); } - zend_update_property_long( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("port"), - INI_INT("amqp.port") TSRMLS_CC - ); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("port"), INI_INT("amqp.port")); - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "port", sizeof("port") - 1)) != NULL) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("port"))) != NULL) { SEPARATE_ZVAL(zdata); convert_to_long(zdata); if (!php_amqp_is_valid_port(Z_LVAL_P(zdata))) { zend_throw_exception_ex( amqp_connection_exception_class_entry, - 0 TSRMLS_CC, + 0, "Parameter 'port' must be a valid port number between %d and %d.", PHP_AMQP_MIN_PORT, PHP_AMQP_MAX_PORT @@ -526,22 +513,17 @@ static PHP_METHOD(amqp_connection_class, __construct) return; } - zend_update_property_long( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("port"), - Z_LVAL_P(zdata) TSRMLS_CC - ); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("port"), Z_LVAL_P(zdata)); } zend_update_property_double( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("read_timeout"), - INI_FLT("amqp.read_timeout") TSRMLS_CC + ZEND_STRL("readTimeout"), + INI_FLT("amqp.read_timeout") ); - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "read_timeout", sizeof("read_timeout") - 1)) != NULL) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("read_timeout"))) != NULL) { SEPARATE_ZVAL(zdata); convert_to_double(zdata); @@ -549,7 +531,7 @@ static PHP_METHOD(amqp_connection_class, __construct) zend_throw_exception( amqp_connection_exception_class_entry, "Parameter 'read_timeout' must be greater than or equal to zero.", - 0 TSRMLS_CC + 0 ); return; } @@ -557,18 +539,18 @@ static PHP_METHOD(amqp_connection_class, __construct) zend_update_property_double( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("read_timeout"), - Z_DVAL_P(zdata) TSRMLS_CC + ZEND_STRL("readTimeout"), + Z_DVAL_P(zdata) ); - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "timeout", sizeof("timeout") - 1)) != NULL) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("timeout"))) != NULL) { /* 'read_timeout' takes precedence on 'timeout' but users have to know this */ - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Parameter 'timeout' is deprecated, 'read_timeout' used instead"); + php_error_docref(NULL, E_NOTICE, "Parameter 'timeout' is deprecated, 'read_timeout' used instead"); } - } else if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "timeout", sizeof("timeout") - 1)) != NULL) { + } else if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("timeout"))) != NULL) { - php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "Parameter 'timeout' is deprecated; use 'read_timeout' instead"); + php_error_docref(NULL, E_DEPRECATED, "Parameter 'timeout' is deprecated; use 'read_timeout' instead"); SEPARATE_ZVAL(zdata); convert_to_double(zdata); @@ -577,7 +559,7 @@ static PHP_METHOD(amqp_connection_class, __construct) zend_throw_exception( amqp_connection_exception_class_entry, "Parameter 'timeout' must be greater than or equal to zero.", - 0 TSRMLS_CC + 0 ); return; } @@ -585,15 +567,15 @@ static PHP_METHOD(amqp_connection_class, __construct) zend_update_property_double( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("read_timeout"), - Z_DVAL_P(zdata) TSRMLS_CC + ZEND_STRL("readTimeout"), + Z_DVAL_P(zdata) ); } else { assert(DEFAULT_TIMEOUT != NULL); if (strcmp(DEFAULT_TIMEOUT, INI_STR("amqp.timeout")) != 0) { php_error_docref( - NULL TSRMLS_CC, + NULL, E_DEPRECATED, "INI setting 'amqp.timeout' is deprecated; use 'amqp.read_timeout' instead" ); @@ -602,28 +584,28 @@ static PHP_METHOD(amqp_connection_class, __construct) zend_update_property_double( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("read_timeout"), - INI_FLT("amqp.timeout") TSRMLS_CC + ZEND_STRL("readTimeout"), + INI_FLT("amqp.timeout") ); } else { php_error_docref( - NULL TSRMLS_CC, + NULL, E_NOTICE, "INI setting 'amqp.read_timeout' will be used instead of 'amqp.timeout'" ); zend_update_property_double( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("read_timeout"), - INI_FLT("amqp.read_timeout") TSRMLS_CC + ZEND_STRL("readTimeout"), + INI_FLT("amqp.read_timeout") ); } } else { zend_update_property_double( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("read_timeout"), - INI_FLT("amqp.read_timeout") TSRMLS_CC + ZEND_STRL("readTimeout"), + INI_FLT("amqp.read_timeout") ); } } @@ -631,12 +613,11 @@ static PHP_METHOD(amqp_connection_class, __construct) zend_update_property_double( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("write_timeout"), - INI_FLT("amqp.write_timeout") TSRMLS_CC + ZEND_STRL("writeTimeout"), + INI_FLT("amqp.write_timeout") ); - if (ini_arr && - (zdata = zend_hash_str_find(HASH_OF(ini_arr), "write_timeout", sizeof("write_timeout") - 1)) != NULL) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("write_timeout"))) != NULL) { SEPARATE_ZVAL(zdata); convert_to_double(zdata); @@ -644,7 +625,7 @@ static PHP_METHOD(amqp_connection_class, __construct) zend_throw_exception( amqp_connection_exception_class_entry, "Parameter 'write_timeout' must be greater than or equal to zero.", - 0 TSRMLS_CC + 0 ); return; } @@ -652,19 +633,19 @@ static PHP_METHOD(amqp_connection_class, __construct) zend_update_property_double( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("write_timeout"), - Z_DVAL_P(zdata) TSRMLS_CC + ZEND_STRL("writeTimeout"), + Z_DVAL_P(zdata) ); } zend_update_property_double( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("rpc_timeout"), - INI_FLT("amqp.rpc_timeout") TSRMLS_CC + ZEND_STRL("rpcTimeout"), + INI_FLT("amqp.rpc_timeout") ); - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "rpc_timeout", sizeof("rpc_timeout") - 1)) != NULL) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("rpc_timeout"))) != NULL) { SEPARATE_ZVAL(zdata); convert_to_double(zdata); @@ -672,7 +653,7 @@ static PHP_METHOD(amqp_connection_class, __construct) zend_throw_exception( amqp_connection_exception_class_entry, "Parameter 'rpc_timeout' must be greater than or equal to zero.", - 0 TSRMLS_CC + 0 ); return; } @@ -680,20 +661,19 @@ static PHP_METHOD(amqp_connection_class, __construct) zend_update_property_double( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("rpc_timeout"), - Z_DVAL_P(zdata) TSRMLS_CC + ZEND_STRL("rpcTimeout"), + Z_DVAL_P(zdata) ); } zend_update_property_double( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("connect_timeout"), - INI_FLT("amqp.connect_timeout") TSRMLS_CC + ZEND_STRL("connectTimeout"), + INI_FLT("amqp.connect_timeout") ); - if (ini_arr && - (zdata = zend_hash_str_find(HASH_OF(ini_arr), "connect_timeout", sizeof("connect_timeout") - 1)) != NULL) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("connect_timeout"))) != NULL) { SEPARATE_ZVAL(zdata); convert_to_double(zdata); @@ -701,7 +681,7 @@ static PHP_METHOD(amqp_connection_class, __construct) zend_throw_exception( amqp_connection_exception_class_entry, "Parameter 'connect_timeout' must be greater than or equal to zero.", - 0 TSRMLS_CC + 0 ); return; } @@ -709,28 +689,24 @@ static PHP_METHOD(amqp_connection_class, __construct) zend_update_property_double( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("connect_timeout"), - Z_DVAL_P(zdata) TSRMLS_CC + ZEND_STRL("connectTimeout"), + Z_DVAL_P(zdata) ); } zend_update_property_long( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("channel_max"), - INI_INT("amqp.channel_max") TSRMLS_CC + ZEND_STRL("channelMax"), + INI_INT("amqp.channel_max") ); - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "channel_max", sizeof("channel_max") - 1)) != NULL) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("channel_max"))) != NULL) { SEPARATE_ZVAL(zdata); convert_to_long(zdata); if (!php_amqp_is_valid_channel_max(Z_LVAL_P(zdata))) { - zend_throw_exception( - amqp_connection_exception_class_entry, - "Parameter 'channel_max' is out of range.", - 0 TSRMLS_CC - ); + zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'channel_max' is out of range.", 0); return; } @@ -738,15 +714,15 @@ static PHP_METHOD(amqp_connection_class, __construct) zend_update_property_long( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("channel_max"), - PHP_AMQP_DEFAULT_CHANNEL_MAX TSRMLS_CC + ZEND_STRL("channelMax"), + PHP_AMQP_DEFAULT_CHANNEL_MAX ); } else { zend_update_property_long( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("channel_max"), - Z_LVAL_P(zdata) TSRMLS_CC + ZEND_STRL("channelMax"), + Z_LVAL_P(zdata) ); } } @@ -754,19 +730,15 @@ static PHP_METHOD(amqp_connection_class, __construct) zend_update_property_long( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("frame_max"), - INI_INT("amqp.frame_max") TSRMLS_CC + ZEND_STRL("frameMax"), + INI_INT("amqp.frame_max") ); - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "frame_max", sizeof("frame_max") - 1)) != NULL) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("frame_max"))) != NULL) { SEPARATE_ZVAL(zdata); convert_to_long(zdata); if (!php_amqp_is_valid_frame_size_max(Z_LVAL_P(zdata))) { - zend_throw_exception( - amqp_connection_exception_class_entry, - "Parameter 'frame_max' is out of range.", - 0 TSRMLS_CC - ); + zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'frame_max' is out of range.", 0); return; } @@ -774,15 +746,15 @@ static PHP_METHOD(amqp_connection_class, __construct) zend_update_property_long( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("frame_max"), - PHP_AMQP_DEFAULT_FRAME_MAX TSRMLS_CC + ZEND_STRL("frameMax"), + PHP_AMQP_DEFAULT_FRAME_MAX ); } else { zend_update_property_long( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("frame_max"), - Z_LVAL_P(zdata) TSRMLS_CC + ZEND_STRL("frameMax"), + Z_LVAL_P(zdata) ); } } @@ -791,45 +763,31 @@ static PHP_METHOD(amqp_connection_class, __construct) this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("heartbeat"), - INI_INT("amqp.heartbeat") TSRMLS_CC + INI_INT("amqp.heartbeat") ); - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "heartbeat", sizeof("heartbeat") - 1)) != NULL) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("heartbeat"))) != NULL) { SEPARATE_ZVAL(zdata); convert_to_long(zdata); if (!php_amqp_is_valid_heartbeat(Z_LVAL_P(zdata))) { - zend_throw_exception( - amqp_connection_exception_class_entry, - "Parameter 'heartbeat' is out of range.", - 0 TSRMLS_CC - ); + zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'heartbeat' is out of range.", 0); return; } - zend_update_property_long( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("heartbeat"), - Z_LVAL_P(zdata) TSRMLS_CC - ); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("heartbeat"), Z_LVAL_P(zdata)); } zend_update_property_long( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("sasl_method"), - INI_INT("amqp.sasl_method") TSRMLS_CC + ZEND_STRL("saslMethod"), + INI_INT("amqp.sasl_method") ); - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), "sasl_method", sizeof("sasl_method") - 1)) != NULL) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("sasl_method"))) != NULL) { SEPARATE_ZVAL(zdata); convert_to_long(zdata); - zend_update_property_long( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("sasl_method"), - Z_LVAL_P(zdata) TSRMLS_CC - ); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("saslMethod"), Z_LVAL_P(zdata)); } @@ -841,8 +799,7 @@ static PHP_METHOD(amqp_connection_class, __construct) /* Pull the connection_name out of the $params array */ zdata = NULL; - if (ini_arr && - (zdata = zend_hash_str_find(HASH_OF(ini_arr), "connection_name", sizeof("connection_name") - 1)) != NULL) { + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("connection_name"))) != NULL) { SEPARATE_ZVAL(zdata); convert_to_string(zdata); } @@ -850,8 +807,8 @@ static PHP_METHOD(amqp_connection_class, __construct) zend_update_property_string( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("connection_name"), - Z_STRVAL_P(zdata) TSRMLS_CC + ZEND_STRL("connectionName"), + Z_STRVAL_P(zdata) ); } } @@ -869,13 +826,7 @@ static PHP_METHOD(amqp_connection_class, isConnected) /* Get the connection object out of the store */ connection = PHP_AMQP_GET_CONNECTION(getThis()); - /* If the channel_connect is 1, we have a connection */ - if (connection->connection_resource != NULL && connection->connection_resource->is_connected) { - RETURN_TRUE; - } - - /* We have no connection */ - RETURN_FALSE; + RETURN_BOOL(connection->connection_resource != NULL && connection->connection_resource->is_connected); } /* }}} */ @@ -894,7 +845,7 @@ static PHP_METHOD(amqp_connection_class, connect) if (connection->connection_resource && connection->connection_resource->is_connected) { if (connection->connection_resource->is_persistent) { php_error_docref( - NULL TSRMLS_CC, + NULL, E_WARNING, "Attempt to start transient connection while persistent transient one already established. Continue." ); @@ -904,7 +855,7 @@ static PHP_METHOD(amqp_connection_class, connect) } /* Actually connect this resource to the broker */ - RETURN_BOOL(php_amqp_connect(connection, 0, INTERNAL_FUNCTION_PARAM_PASSTHRU)); + php_amqp_connect(connection, 0, INTERNAL_FUNCTION_PARAM_PASSTHRU); } /* }}} */ @@ -925,7 +876,7 @@ static PHP_METHOD(amqp_connection_class, pconnect) assert(connection->connection_resource != NULL); if (!connection->connection_resource->is_persistent) { php_error_docref( - NULL TSRMLS_CC, + NULL, E_WARNING, "Attempt to start persistent connection while transient one already established. Continue." ); @@ -935,10 +886,12 @@ static PHP_METHOD(amqp_connection_class, pconnect) } /* Actually connect this resource to the broker or use stored connection */ - RETURN_BOOL(php_amqp_connect(connection, 1, INTERNAL_FUNCTION_PARAM_PASSTHRU)); + php_amqp_connect(connection, 1, INTERNAL_FUNCTION_PARAM_PASSTHRU); } /* }}} */ +#define PERSISTENT_TRANSIENT_EXCEPTION_MESSAGE \ + "Attempted to %s a %s connection while a %s connection is established. Call '%s' instead" /* {{{ proto amqp:pdisconnect() destroy amqp persistent connection */ @@ -952,24 +905,25 @@ static PHP_METHOD(amqp_connection_class, pdisconnect) connection = PHP_AMQP_GET_CONNECTION(getThis()); if (!connection->connection_resource || !connection->connection_resource->is_connected) { - RETURN_TRUE; + return; } assert(connection->connection_resource != NULL); if (!connection->connection_resource->is_persistent) { - php_error_docref( - NULL TSRMLS_CC, - E_WARNING, - "Attempt to close persistent connection while transient one already established. Abort." + zend_throw_exception_ex( + amqp_connection_exception_class_entry, + 0, + PERSISTENT_TRANSIENT_EXCEPTION_MESSAGE, + "close", + "persistent", + "transient", + "disconnect" ); - - RETURN_FALSE; + return; } - php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC); - - RETURN_TRUE; + php_amqp_disconnect_force(connection->connection_resource); } /* }}} */ @@ -986,24 +940,25 @@ static PHP_METHOD(amqp_connection_class, disconnect) connection = PHP_AMQP_GET_CONNECTION(getThis()); if (!connection->connection_resource || !connection->connection_resource->is_connected) { - RETURN_TRUE; + return; } if (connection->connection_resource->is_persistent) { - php_error_docref( - NULL TSRMLS_CC, - E_WARNING, - "Attempt to close transient connection while persistent one already established. Abort." + zend_throw_exception_ex( + amqp_connection_exception_class_entry, + 0, + PERSISTENT_TRANSIENT_EXCEPTION_MESSAGE, + "close", + "transient", + "persistent", + "pdisconnect" ); - - RETURN_FALSE; + return; } assert(connection->connection_resource != NULL); - php_amqp_disconnect(connection->connection_resource TSRMLS_CC); - - RETURN_TRUE; + php_amqp_disconnect(connection->connection_resource); } /* }}} */ @@ -1024,19 +979,22 @@ static PHP_METHOD(amqp_connection_class, reconnect) assert(connection->connection_resource != NULL); if (connection->connection_resource->is_persistent) { - php_error_docref( - NULL TSRMLS_CC, - E_WARNING, - "Attempt to reconnect persistent connection while transient one already established. Abort." + zend_throw_exception_ex( + amqp_connection_exception_class_entry, + 0, + PERSISTENT_TRANSIENT_EXCEPTION_MESSAGE, + "reconnect", + "transient", + "persistent", + "preconnect" ); - - RETURN_FALSE; + return; } - php_amqp_disconnect(connection->connection_resource TSRMLS_CC); + php_amqp_disconnect(connection->connection_resource); } - RETURN_BOOL(php_amqp_connect(connection, 0, INTERNAL_FUNCTION_PARAM_PASSTHRU)); + php_amqp_connect(connection, 0, INTERNAL_FUNCTION_PARAM_PASSTHRU); } /* }}} */ @@ -1057,19 +1015,22 @@ static PHP_METHOD(amqp_connection_class, preconnect) assert(connection->connection_resource != NULL); if (!connection->connection_resource->is_persistent) { - php_error_docref( - NULL TSRMLS_CC, - E_WARNING, - "Attempt to reconnect transient connection while persistent one already established. Abort." + zend_throw_exception_ex( + amqp_connection_exception_class_entry, + 0, + PERSISTENT_TRANSIENT_EXCEPTION_MESSAGE, + "reconnect", + "persistent", + "transient", + "reconnect" ); - - RETURN_FALSE; + return; } - php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC); + php_amqp_disconnect_force(connection->connection_resource); } - RETURN_BOOL(php_amqp_connect(connection, 1, INTERNAL_FUNCTION_PARAM_PASSTHRU)); + php_amqp_connect(connection, 1, INTERNAL_FUNCTION_PARAM_PASSTHRU); } /* }}} */ @@ -1093,7 +1054,7 @@ static PHP_METHOD(amqp_connection_class, setLogin) size_t login_len = 0; /* Get the login from the method params */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &login, &login_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &login, &login_len) == FAILURE) { return; } @@ -1101,22 +1062,14 @@ static PHP_METHOD(amqp_connection_class, setLogin) if (login_len > PHP_AMQP_MAX_CREDENTIALS_LENGTH) { zend_throw_exception_ex( amqp_connection_exception_class_entry, - 0 TSRMLS_CC, + 0, "Parameter 'login' exceeds %d character limit.", PHP_AMQP_MAX_CREDENTIALS_LENGTH ); return; } - zend_update_property_stringl( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("login"), - login, - login_len TSRMLS_CC - ); - - RETURN_TRUE; + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("login"), login, login_len); } /* }}} */ @@ -1139,7 +1092,7 @@ static PHP_METHOD(amqp_connection_class, setPassword) size_t password_len = 0; /* Get the password from the method params */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &password, &password_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &password, &password_len) == FAILURE) { return; } @@ -1147,7 +1100,7 @@ static PHP_METHOD(amqp_connection_class, setPassword) if (password_len > PHP_AMQP_MAX_CREDENTIALS_LENGTH) { zend_throw_exception_ex( amqp_connection_exception_class_entry, - 0 TSRMLS_CC, + 0, "Parameter 'password' exceeds %d character limit.", PHP_AMQP_MAX_CREDENTIALS_LENGTH ); @@ -1159,10 +1112,8 @@ static PHP_METHOD(amqp_connection_class, setPassword) PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("password"), password, - password_len TSRMLS_CC + password_len ); - - RETURN_TRUE; } /* }}} */ @@ -1186,7 +1137,7 @@ static PHP_METHOD(amqp_connection_class, setHost) size_t host_len = 0; /* Get the host from the method params */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &host, &host_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &host, &host_len) == FAILURE) { return; } @@ -1194,16 +1145,14 @@ static PHP_METHOD(amqp_connection_class, setHost) if (host_len > PHP_AMQP_MAX_IDENTIFIER_LENGTH) { zend_throw_exception_ex( amqp_connection_exception_class_entry, - 0 TSRMLS_CC, + 0, "Parameter 'host' exceeds %d character limit.", PHP_AMQP_MAX_IDENTIFIER_LENGTH ); return; } - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("host"), host, host_len TSRMLS_CC); - - RETURN_TRUE; + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("host"), host, host_len); } /* }}} */ @@ -1227,7 +1176,7 @@ static PHP_METHOD(amqp_connection_class, setPort) int port; /* Get the port from the method params */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &zvalPort) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "z/", &zvalPort) == FAILURE) { return; } @@ -1252,14 +1201,12 @@ static PHP_METHOD(amqp_connection_class, setPort) zend_throw_exception( amqp_connection_exception_class_entry, "Invalid port given. Value must be between 1 and 65535.", - 0 TSRMLS_CC + 0 ); return; } - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("port"), port TSRMLS_CC); - - RETURN_TRUE; + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("port"), port); } /* }}} */ @@ -1281,7 +1228,7 @@ static PHP_METHOD(amqp_connection_class, setVhost) char *vhost = NULL; size_t vhost_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &vhost, &vhost_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &vhost, &vhost_len) == FAILURE) { return; } @@ -1289,22 +1236,14 @@ static PHP_METHOD(amqp_connection_class, setVhost) if (vhost_len > PHP_AMQP_MAX_IDENTIFIER_LENGTH) { zend_throw_exception_ex( amqp_connection_exception_class_entry, - 0 TSRMLS_CC, + 0, "Parameter 'vhost' exceeds %d characters limit.", PHP_AMQP_MAX_IDENTIFIER_LENGTH ); return; } - zend_update_property_stringl( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("vhost"), - vhost, - vhost_len TSRMLS_CC - ); - - RETURN_TRUE; + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("vhost"), vhost, vhost_len); } /* }}} */ @@ -1314,14 +1253,14 @@ get the timeout */ static PHP_METHOD(amqp_connection_class, getTimeout) { php_error_docref( - NULL TSRMLS_CC, + NULL, E_DEPRECATED, "AMQPConnection::getTimeout() method is deprecated; use AMQPConnection::getReadTimeout() instead" ); zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("read_timeout"); + PHP_AMQP_RETURN_THIS_PROP("readTimeout"); } /* }}} */ @@ -1334,14 +1273,14 @@ static PHP_METHOD(amqp_connection_class, setTimeout) double read_timeout; php_error_docref( - NULL TSRMLS_CC, + NULL, E_DEPRECATED, "AMQPConnection::setTimeout($timeout) method is deprecated; use AMQPConnection::setReadTimeout($timeout) " "instead" ); /* Get the timeout from the method params */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &read_timeout) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "d", &read_timeout) == FAILURE) { return; } @@ -1350,7 +1289,7 @@ static PHP_METHOD(amqp_connection_class, setTimeout) zend_throw_exception( amqp_connection_exception_class_entry, "Parameter 'timeout' must be greater than or equal to zero.", - 0 TSRMLS_CC + 0 ); return; } @@ -1358,23 +1297,16 @@ static PHP_METHOD(amqp_connection_class, setTimeout) /* Get the connection object out of the store */ connection = PHP_AMQP_GET_CONNECTION(getThis()); - zend_update_property_double( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("read_timeout"), - read_timeout TSRMLS_CC - ); + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("readTimeout"), read_timeout); if (connection->connection_resource && connection->connection_resource->is_connected) { - if (php_amqp_set_resource_read_timeout(connection->connection_resource, read_timeout TSRMLS_CC) == 0) { + if (php_amqp_set_resource_read_timeout(connection->connection_resource, read_timeout) == 0) { - php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC); + php_amqp_disconnect_force(connection->connection_resource); - RETURN_FALSE; + zend_throw_exception(amqp_connection_exception_class_entry, "Could not set read timeout", 0); } } - - RETURN_TRUE; } /* }}} */ @@ -1384,7 +1316,7 @@ static PHP_METHOD(amqp_connection_class, getReadTimeout) { zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("read_timeout"); + PHP_AMQP_RETURN_THIS_PROP("readTimeout"); } /* }}} */ @@ -1396,7 +1328,7 @@ static PHP_METHOD(amqp_connection_class, setReadTimeout) double read_timeout; /* Get the timeout from the method params */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &read_timeout) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "d", &read_timeout) == FAILURE) { return; } @@ -1404,8 +1336,8 @@ static PHP_METHOD(amqp_connection_class, setReadTimeout) if (!php_amqp_is_valid_timeout(read_timeout)) { zend_throw_exception( amqp_connection_exception_class_entry, - "Parameter 'read_timeout' must be greater than or equal to zero.", - 0 TSRMLS_CC + "Parameter 'readTimeout' must be greater than or equal to zero.", + 0 ); return; } @@ -1413,23 +1345,16 @@ static PHP_METHOD(amqp_connection_class, setReadTimeout) /* Get the connection object out of the store */ connection = PHP_AMQP_GET_CONNECTION(getThis()); - zend_update_property_double( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("read_timeout"), - read_timeout TSRMLS_CC - ); + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("readTimeout"), read_timeout); if (connection->connection_resource && connection->connection_resource->is_connected) { - if (php_amqp_set_resource_read_timeout(connection->connection_resource, read_timeout TSRMLS_CC) == 0) { + if (php_amqp_set_resource_read_timeout(connection->connection_resource, read_timeout) == 0) { - php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC); + php_amqp_disconnect_force(connection->connection_resource); - RETURN_FALSE; + zend_throw_exception(amqp_connection_exception_class_entry, "Could not set read timeout", 0); } } - - RETURN_TRUE; } /* }}} */ @@ -1439,7 +1364,7 @@ static PHP_METHOD(amqp_connection_class, getWriteTimeout) { zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("write_timeout"); + PHP_AMQP_RETURN_THIS_PROP("writeTimeout"); } /* }}} */ @@ -1451,7 +1376,7 @@ static PHP_METHOD(amqp_connection_class, setWriteTimeout) double write_timeout; /* Get the timeout from the method params */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &write_timeout) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "d", &write_timeout) == FAILURE) { return; } @@ -1459,8 +1384,8 @@ static PHP_METHOD(amqp_connection_class, setWriteTimeout) if (!php_amqp_is_valid_timeout(write_timeout)) { zend_throw_exception( amqp_connection_exception_class_entry, - "Parameter 'write_timeout' must be greater than or equal to zero.", - 0 TSRMLS_CC + "Parameter 'writeTimeout' must be greater than or equal to zero.", + 0 ); return; } @@ -1468,23 +1393,16 @@ static PHP_METHOD(amqp_connection_class, setWriteTimeout) /* Get the connection object out of the store */ connection = PHP_AMQP_GET_CONNECTION(getThis()); - zend_update_property_double( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("write_timeout"), - write_timeout TSRMLS_CC - ); + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("writeTimeout"), write_timeout); if (connection->connection_resource && connection->connection_resource->is_connected) { - if (php_amqp_set_resource_write_timeout(connection->connection_resource, write_timeout TSRMLS_CC) == 0) { + if (php_amqp_set_resource_write_timeout(connection->connection_resource, write_timeout) == 0) { - php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC); + php_amqp_disconnect_force(connection->connection_resource); - RETURN_FALSE; + zend_throw_exception(amqp_connection_exception_class_entry, "Could not set write timeout", 0); } } - - RETURN_TRUE; } /* }}} */ @@ -1494,7 +1412,7 @@ static PHP_METHOD(amqp_connection_class, getConnectTimeout) { zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("connect_timeout"); + PHP_AMQP_RETURN_THIS_PROP("connectTimeout"); } /* }}} */ @@ -1504,7 +1422,7 @@ static PHP_METHOD(amqp_connection_class, getRpcTimeout) { zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("rpc_timeout"); + PHP_AMQP_RETURN_THIS_PROP("rpcTimeout"); } /* }}} */ @@ -1516,7 +1434,7 @@ static PHP_METHOD(amqp_connection_class, setRpcTimeout) double rpc_timeout; /* Get the timeout from the method params */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &rpc_timeout) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "d", &rpc_timeout) == FAILURE) { return; } @@ -1524,8 +1442,8 @@ static PHP_METHOD(amqp_connection_class, setRpcTimeout) if (!php_amqp_is_valid_timeout(rpc_timeout)) { zend_throw_exception( amqp_connection_exception_class_entry, - "Parameter 'rpc_timeout' must be greater than or equal to zero.", - 0 TSRMLS_CC + "Parameter 'rpcTimeout' must be greater than or equal to zero.", + 0 ); return; } @@ -1533,23 +1451,16 @@ static PHP_METHOD(amqp_connection_class, setRpcTimeout) /* Get the connection object out of the store */ connection = PHP_AMQP_GET_CONNECTION(getThis()); - zend_update_property_double( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("rpc_timeout"), - rpc_timeout TSRMLS_CC - ); + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("rpcTimeout"), rpc_timeout); if (connection->connection_resource && connection->connection_resource->is_connected) { - if (php_amqp_set_resource_rpc_timeout(connection->connection_resource, rpc_timeout TSRMLS_CC) == 0) { + if (php_amqp_set_resource_rpc_timeout(connection->connection_resource, rpc_timeout) == 0) { - php_amqp_disconnect_force(connection->connection_resource TSRMLS_CC); + php_amqp_disconnect_force(connection->connection_resource); - RETURN_FALSE; + zend_throw_exception(amqp_connection_exception_class_entry, "Could not set connect timeout", 0); } } - - RETURN_TRUE; } /* }}} */ @@ -1566,7 +1477,7 @@ static PHP_METHOD(amqp_connection_class, getUsedChannels) connection = PHP_AMQP_GET_CONNECTION(getThis()); if (!connection->connection_resource || !connection->connection_resource->is_connected) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Connection is not connected."); + php_error_docref(NULL, E_WARNING, "Connection is not connected."); RETURN_LONG(0); } @@ -1591,7 +1502,7 @@ PHP_METHOD(amqp_connection_class, getMaxChannels) RETURN_LONG(connection->connection_resource->max_slots); } - PHP_AMQP_RETURN_THIS_PROP("channel_max"); + PHP_AMQP_RETURN_THIS_PROP("channelMax"); } /* }}} */ @@ -1611,7 +1522,7 @@ static PHP_METHOD(amqp_connection_class, getMaxFrameSize) RETURN_LONG(amqp_get_frame_max(connection->connection_resource->connection_state)); } - PHP_AMQP_RETURN_THIS_PROP("frame_max"); + PHP_AMQP_RETURN_THIS_PROP("frameMax"); } /* }}} */ @@ -1665,13 +1576,15 @@ static PHP_METHOD(amqp_connection_class, setCACert) char *str = NULL; size_t str_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &str, &str_len) == FAILURE) { return; } - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("cacert"), str, str_len TSRMLS_CC); - - RETURN_TRUE; + if (str == NULL) { + zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("cacert")); + } else { + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("cacert"), str, str_len); + } } /* }}} */ @@ -1690,13 +1603,15 @@ static PHP_METHOD(amqp_connection_class, setCert) char *str = NULL; size_t str_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &str, &str_len) == FAILURE) { return; } - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("cert"), str, str_len TSRMLS_CC); - - RETURN_TRUE; + if (str == NULL) { + zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("cert")); + } else { + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("cert"), str, str_len); + } } /* }}} */ @@ -1715,13 +1630,15 @@ static PHP_METHOD(amqp_connection_class, setKey) char *str = NULL; size_t str_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &str, &str_len) == FAILURE) { return; } - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("key"), str, str_len TSRMLS_CC); - - RETURN_TRUE; + if (str == NULL) { + zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("key")); + } else { + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("key"), str, str_len); + } } /* }}} */ @@ -1740,13 +1657,11 @@ static PHP_METHOD(amqp_connection_class, setVerify) { zend_bool verify = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &verify) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &verify) == FAILURE) { return; } - zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("verify"), verify TSRMLS_CC); - - RETURN_TRUE; + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("verify"), verify); } /* }}} */ @@ -1756,7 +1671,7 @@ static PHP_METHOD(amqp_connection_class, getSaslMethod) { zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("sasl_method"); + PHP_AMQP_RETURN_THIS_PROP("saslMethod"); } /* }}} */ @@ -1767,7 +1682,7 @@ static PHP_METHOD(amqp_connection_class, setSaslMethod) long method; /* Get the port from the method params */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &method) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &method) == FAILURE) { return; } @@ -1776,14 +1691,12 @@ static PHP_METHOD(amqp_connection_class, setSaslMethod) zend_throw_exception( amqp_connection_exception_class_entry, "Invalid SASL method given. Method must be AMQP_SASL_METHOD_PLAIN or AMQP_SASL_METHOD_EXTERNAL.", - 0 TSRMLS_CC + 0 ); return; } - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("sasl_method"), method TSRMLS_CC); - - RETURN_TRUE; + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("saslMethod"), method); } /* }}} */ @@ -1792,7 +1705,7 @@ static PHP_METHOD(amqp_connection_class, getConnectionName) { zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("connection_name"); + PHP_AMQP_RETURN_THIS_PROP("connectionName"); } /* }}} */ @@ -1802,173 +1715,200 @@ static PHP_METHOD(amqp_connection_class, setConnectionName) char *str = NULL; size_t str_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &str, &str_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &str, &str_len) == FAILURE) { return; } if (str == NULL) { - zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connection_name") TSRMLS_CC); + zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connectionName")); } else { zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("connection_name"), + ZEND_STRL("connectionName"), str, - str_len TSRMLS_CC + str_len ); } - - - RETURN_TRUE; } /* }}} */ /* amqp_connection_class ARG_INFO definition */ ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class__construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) - ZEND_ARG_ARRAY_INFO(0, credentials, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, credentials, IS_ARRAY, 0, "[]") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_isConnected, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_isConnected, ZEND_SEND_BY_VAL, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_connect, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_connect, ZEND_SEND_BY_VAL, 0, IS_VOID, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_pconnect, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_pconnect, ZEND_SEND_BY_VAL, 0, IS_VOID, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_pdisconnect, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_pdisconnect, ZEND_SEND_BY_VAL, 0, IS_VOID, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_disconnect, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_disconnect, ZEND_SEND_BY_VAL, 0, IS_VOID, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_reconnect, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_reconnect, ZEND_SEND_BY_VAL, 0, IS_VOID, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_preconnect, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_preconnect, ZEND_SEND_BY_VAL, 0, IS_VOID, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getLogin, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_getLogin, ZEND_SEND_BY_VAL, 0, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setLogin, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, login) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_setLogin, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, login, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getPassword, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_getPassword, ZEND_SEND_BY_VAL, 0, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setPassword, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, password) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_setPassword, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, password, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getHost, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_getHost, ZEND_SEND_BY_VAL, 0, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setHost, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, host) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_setHost, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, host, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getPort, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_getPort, ZEND_SEND_BY_VAL, 0, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setPort, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, port) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_setPort, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, port, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getVhost, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_getVhost, ZEND_SEND_BY_VAL, 0, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setVhost, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, vhost) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_setVhost, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, vhost, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_getTimeout, ZEND_SEND_BY_VAL, 0, IS_DOUBLE, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, timeout) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_setTimeout, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, timeout, IS_DOUBLE, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getReadTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_getReadTimeout, ZEND_SEND_BY_VAL, 0, IS_DOUBLE, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setReadTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, timeout) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_setReadTimeout, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, timeout, IS_DOUBLE, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getWriteTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX( + arginfo_amqp_connection_class_getWriteTimeout, + ZEND_SEND_BY_VAL, + 0, + IS_DOUBLE, + 0 +) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setWriteTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, timeout) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_setWriteTimeout, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, timeout, IS_DOUBLE, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getConnectTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX( + arginfo_amqp_connection_class_getConnectTimeout, + ZEND_SEND_BY_VAL, + 0, + IS_DOUBLE, + 0 +) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getRpcTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_getRpcTimeout, ZEND_SEND_BY_VAL, 0, IS_DOUBLE, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setRpcTimeout, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, timeout) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_setRpcTimeout, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, timeout, IS_DOUBLE, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getUsedChannels, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_getUsedChannels, ZEND_SEND_BY_VAL, 0, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getMaxChannels, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_getMaxChannels, ZEND_SEND_BY_VAL, 0, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getMaxFrameSize, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_getMaxFrameSize, ZEND_SEND_BY_VAL, 0, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getHeartbeatInterval, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX( + arginfo_amqp_connection_class_getHeartbeatInterval, + ZEND_SEND_BY_VAL, + 0, + IS_LONG, + 0 +) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_isPersistent, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_isPersistent, ZEND_SEND_BY_VAL, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getCACert, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_getCACert, ZEND_SEND_BY_VAL, 0, IS_STRING, 1) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setCACert, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, cacert) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_setCACert, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, cacert, IS_STRING, 1) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getCert, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_getCert, ZEND_SEND_BY_VAL, 0, IS_STRING, 1) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setCert, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, cert) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_setCert, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, cert, IS_STRING, 1) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getKey, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_getKey, ZEND_SEND_BY_VAL, 0, IS_STRING, 1) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setKey, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, key) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_setKey, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 1) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getVerify, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_getVerify, ZEND_SEND_BY_VAL, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setVerify, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, verify) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_setVerify, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, verify, _IS_BOOL, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getSaslMethod, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_getSaslMethod, ZEND_SEND_BY_VAL, 0, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setSaslMethod, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, sasl_method) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_connection_class_setSaslMethod, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, saslMethod, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_getConnectionName, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX( + arginfo_amqp_connection_class_getConnectionName, + ZEND_SEND_BY_VAL, + 0, + IS_STRING, + 1 +) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_connection_class_setConnectionName, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, connection_name) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX( + arginfo_amqp_connection_class_setConnectionName, + ZEND_SEND_BY_VAL, + 1, + IS_VOID, + 0 +) + ZEND_ARG_TYPE_INFO(0, connectionName, IS_STRING, 1) ZEND_END_ARG_INFO() @@ -2039,38 +1979,45 @@ zend_function_entry amqp_connection_class_functions[] = { {NULL, NULL, NULL} }; - PHP_MINIT_FUNCTION(amqp_connection) { zend_class_entry ce; INIT_CLASS_ENTRY(ce, "AMQPConnection", amqp_connection_class_functions); ce.create_object = amqp_connection_ctor; - this_ce = zend_register_internal_class(&ce TSRMLS_CC); - - zend_declare_property_null(this_ce, ZEND_STRL("login"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("password"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("host"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("vhost"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("port"), ZEND_ACC_PRIVATE TSRMLS_CC); - - zend_declare_property_null(this_ce, ZEND_STRL("read_timeout"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("write_timeout"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("connect_timeout"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("rpc_timeout"), ZEND_ACC_PRIVATE TSRMLS_CC); - - zend_declare_property_null(this_ce, ZEND_STRL("channel_max"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("frame_max"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("heartbeat"), ZEND_ACC_PRIVATE TSRMLS_CC); - - zend_declare_property_null(this_ce, ZEND_STRL("cacert"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("key"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("cert"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("verify"), ZEND_ACC_PRIVATE TSRMLS_CC); - - zend_declare_property_null(this_ce, ZEND_STRL("sasl_method"), ZEND_ACC_PRIVATE TSRMLS_CC); + this_ce = zend_register_internal_class(&ce); + + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "login", ZEND_ACC_PRIVATE, IS_STRING, 0); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "password", ZEND_ACC_PRIVATE, IS_STRING, 0); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "host", ZEND_ACC_PRIVATE, IS_STRING, 0); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "vhost", ZEND_ACC_PRIVATE, IS_STRING, 0); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "port", ZEND_ACC_PRIVATE, IS_LONG, 0); + + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "readTimeout", ZEND_ACC_PRIVATE, IS_DOUBLE, 0); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "writeTimeout", ZEND_ACC_PRIVATE, IS_DOUBLE, 0); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "connectTimeout", ZEND_ACC_PRIVATE, IS_DOUBLE, 0); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "rpcTimeout", ZEND_ACC_PRIVATE, IS_DOUBLE, 0); + + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "frameMax", ZEND_ACC_PRIVATE, IS_LONG, 0); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "channelMax", ZEND_ACC_PRIVATE, IS_LONG, 0); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "heartbeat", ZEND_ACC_PRIVATE, IS_LONG, 0); + + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "cacert", ZEND_ACC_PRIVATE, IS_STRING, 1); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "key", ZEND_ACC_PRIVATE, IS_STRING, 1); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "cert", ZEND_ACC_PRIVATE, IS_STRING, 1); + PHP_AMQP_DECLARE_TYPED_PROPERTY_WITH_DEFAULT(this_ce, "verify", ZEND_ACC_PRIVATE, _IS_BOOL, 0, ZVAL_TRUE); + + zval default_sasl_method; + ZVAL_LONG(&default_sasl_method, DEFAULT_SASL_METHOD); + PHP_AMQP_DECLARE_TYPED_PROPERTY_ZVAL( + this_ce, + "saslMethod", + ZEND_ACC_PRIVATE, + PHP_AMQP_DECLARE_PROPERTY_TYPE(IS_LONG, 0), + default_sasl_method + ); - zend_declare_property_null(this_ce, ZEND_STRL("connection_name"), ZEND_ACC_PRIVATE TSRMLS_CC); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "connectionName", ZEND_ACC_PRIVATE, IS_STRING, 1); memcpy(&amqp_connection_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); diff --git a/amqp_connection.h b/amqp_connection.h index 82dbd16c..a2d0df4c 100644 --- a/amqp_connection.h +++ b/amqp_connection.h @@ -25,7 +25,7 @@ extern zend_class_entry *amqp_connection_class_entry; int php_amqp_connect(amqp_connection_object *amqp_connection, zend_bool persistent, INTERNAL_FUNCTION_PARAMETERS); -void php_amqp_disconnect_force(amqp_connection_resource *resource TSRMLS_DC); +void php_amqp_disconnect_force(amqp_connection_resource *resource); PHP_MINIT_FUNCTION(amqp_connection); diff --git a/amqp_connection_resource.c b/amqp_connection_resource.c index 85fe72d0..37cc45dc 100644 --- a/amqp_connection_resource.c +++ b/amqp_connection_resource.c @@ -74,17 +74,17 @@ int le_amqp_connection_resource; int le_amqp_connection_resource_persistent; -static void connection_resource_destructor(amqp_connection_resource *resource, int persistent TSRMLS_DC); +static void connection_resource_destructor(amqp_connection_resource *resource, int persistent); static void php_amqp_close_connection_from_server( amqp_rpc_reply_t reply, char **message, - amqp_connection_resource *resource TSRMLS_DC + amqp_connection_resource *resource ); static void php_amqp_close_channel_from_server( amqp_rpc_reply_t reply, char **message, amqp_connection_resource *resource, - amqp_channel_t channel_id TSRMLS_DC + amqp_channel_t channel_id ); @@ -93,7 +93,7 @@ int php_amqp_connection_resource_error( amqp_rpc_reply_t reply, char **message, amqp_connection_resource *resource, - amqp_channel_t channel_id TSRMLS_DC + amqp_channel_t channel_id ) { assert(resource != NULL); @@ -113,11 +113,11 @@ int php_amqp_connection_resource_error( case AMQP_RESPONSE_SERVER_EXCEPTION: switch (reply.reply.id) { case AMQP_CONNECTION_CLOSE_METHOD: { - php_amqp_close_connection_from_server(reply, message, resource TSRMLS_CC); + php_amqp_close_connection_from_server(reply, message, resource); return PHP_AMQP_RESOURCE_RESPONSE_ERROR_CONNECTION_CLOSED; } case AMQP_CHANNEL_CLOSE_METHOD: { - php_amqp_close_channel_from_server(reply, message, resource, channel_id TSRMLS_CC); + php_amqp_close_channel_from_server(reply, message, resource, channel_id); return PHP_AMQP_RESOURCE_RESPONSE_ERROR_CHANNEL_CLOSED; } } @@ -133,7 +133,7 @@ int php_amqp_connection_resource_error( static void php_amqp_close_connection_from_server( amqp_rpc_reply_t reply, char **message, - amqp_connection_resource *resource TSRMLS_DC + amqp_connection_resource *resource ) { amqp_connection_close_t *m = (amqp_connection_close_t *) reply.reply.decoded; @@ -177,11 +177,7 @@ static void php_amqp_close_connection_from_server( ); if (result != AMQP_STATUS_OK) { - zend_throw_exception( - amqp_channel_exception_class_entry, - "An error occurred while closing the connection.", - 0 TSRMLS_CC - ); + zend_throw_exception(amqp_channel_exception_class_entry, "An error occurred while closing the connection.", 0); } /* Prevent finishing AMQP connection in connection resource destructor */ @@ -192,7 +188,7 @@ static void php_amqp_close_channel_from_server( amqp_rpc_reply_t reply, char **message, amqp_connection_resource *resource, - amqp_channel_t channel_id TSRMLS_DC + amqp_channel_t channel_id ) { assert(channel_id > 0 && channel_id <= resource->max_slots); @@ -235,11 +231,7 @@ static void php_amqp_close_channel_from_server( result = amqp_send_method(resource->connection_state, channel_id, AMQP_CHANNEL_CLOSE_OK_METHOD, &decoded); if (result != AMQP_STATUS_OK) { - zend_throw_exception( - amqp_channel_exception_class_entry, - "An error occurred while closing channel.", - 0 TSRMLS_CC - ); + zend_throw_exception(amqp_channel_exception_class_entry, "An error occurred while closing channel.", 0); } } } @@ -250,7 +242,7 @@ int php_amqp_connection_resource_error_advanced( char **message, amqp_connection_resource *resource, amqp_channel_t channel_id, - amqp_channel_object *channel TSRMLS_DC + amqp_channel_object *channel ) { assert(resource != NULL); @@ -277,11 +269,11 @@ int php_amqp_connection_resource_error_advanced( if (AMQP_FRAME_METHOD == frame.frame_type) { switch (frame.payload.method.id) { case AMQP_CONNECTION_CLOSE_METHOD: { - php_amqp_close_connection_from_server(reply, message, resource TSRMLS_CC); + php_amqp_close_connection_from_server(reply, message, resource); return PHP_AMQP_RESOURCE_RESPONSE_ERROR_CONNECTION_CLOSED; } case AMQP_CHANNEL_CLOSE_METHOD: { - php_amqp_close_channel_from_server(reply, message, resource, channel_id TSRMLS_CC); + php_amqp_close_channel_from_server(reply, message, resource, channel_id); return PHP_AMQP_RESOURCE_RESPONSE_ERROR_CHANNEL_CLOSED; } @@ -290,37 +282,19 @@ int php_amqp_connection_resource_error_advanced( * here is a message being confirmed */ - return php_amqp_handle_basic_ack( - message, - resource, - channel_id, - channel, - &frame.payload.method TSRMLS_CC - ); + return php_amqp_handle_basic_ack(message, resource, channel_id, channel, &frame.payload.method); case AMQP_BASIC_NACK_METHOD: /* if we've turned publisher confirms on, and we've published a message * here is a message being confirmed */ - return php_amqp_handle_basic_nack( - message, - resource, - channel_id, - channel, - &frame.payload.method TSRMLS_CC - ); + return php_amqp_handle_basic_nack(message, resource, channel_id, channel, &frame.payload.method); case AMQP_BASIC_RETURN_METHOD: /* if a published message couldn't be routed and the mandatory flag was set * this is what would be returned. The message then needs to be read. */ - return php_amqp_handle_basic_return( - message, - resource, - channel_id, - channel, - &frame.payload.method TSRMLS_CC - ); + return php_amqp_handle_basic_return(message, resource, channel_id, channel, &frame.payload.method); default: if (*message != NULL) { efree(*message); @@ -345,7 +319,7 @@ int php_amqp_connection_resource_error_advanced( } /* Socket-related functions */ -int php_amqp_set_resource_read_timeout(amqp_connection_resource *resource, double timeout TSRMLS_DC) +int php_amqp_set_resource_read_timeout(amqp_connection_resource *resource, double timeout) { assert(timeout >= 0.0); @@ -375,18 +349,14 @@ int php_amqp_set_resource_read_timeout(amqp_connection_resource *resource, doubl (char *) &read_timeout, sizeof(read_timeout) )) { - zend_throw_exception( - amqp_connection_exception_class_entry, - "Socket error: cannot setsockopt SO_RCVTIMEO", - 0 TSRMLS_CC - ); + zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: cannot setsockopt SO_RCVTIMEO", 0); return 0; } return 1; } -int php_amqp_set_resource_rpc_timeout(amqp_connection_resource *resource, double timeout TSRMLS_DC) +int php_amqp_set_resource_rpc_timeout(amqp_connection_resource *resource, double timeout) { assert(timeout >= 0.0); @@ -400,11 +370,7 @@ int php_amqp_set_resource_rpc_timeout(amqp_connection_resource *resource, double rpc_timeout.tv_usec = (int) ((timeout - floor(timeout)) * 1.e+6); if (AMQP_STATUS_OK != amqp_set_rpc_timeout(resource->connection_state, &rpc_timeout)) { - zend_throw_exception( - amqp_connection_exception_class_entry, - "Library error: cannot set rpc_timeout", - 0 TSRMLS_CC - ); + zend_throw_exception(amqp_connection_exception_class_entry, "Library error: cannot set rpc_timeout", 0); return 0; } #endif @@ -412,7 +378,7 @@ int php_amqp_set_resource_rpc_timeout(amqp_connection_resource *resource, double return 1; } -int php_amqp_set_resource_write_timeout(amqp_connection_resource *resource, double timeout TSRMLS_DC) +int php_amqp_set_resource_write_timeout(amqp_connection_resource *resource, double timeout) { assert(timeout >= 0.0); @@ -437,11 +403,7 @@ int php_amqp_set_resource_write_timeout(amqp_connection_resource *resource, doub (char *) &write_timeout, sizeof(write_timeout) )) { - zend_throw_exception( - amqp_connection_exception_class_entry, - "Socket error: cannot setsockopt SO_SNDTIMEO", - 0 TSRMLS_CC - ); + zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: cannot setsockopt SO_SNDTIMEO", 0); return 0; } @@ -512,7 +474,7 @@ int php_amqp_connection_resource_unregister_channel(amqp_connection_resource *re /* Creating and destroying resource */ -amqp_connection_resource *connection_resource_constructor(amqp_connection_params *params, zend_bool persistent TSRMLS_DC) +amqp_connection_resource *connection_resource_constructor(amqp_connection_params *params, zend_bool persistent) { struct timeval tv = {0}; struct timeval *tv_ptr = &tv; @@ -540,7 +502,7 @@ amqp_connection_resource *connection_resource_constructor(amqp_connection_params zend_throw_exception( amqp_connection_exception_class_entry, "Socket error: could not create SSL socket.", - 0 TSRMLS_CC + 0 ); return NULL; @@ -549,22 +511,14 @@ amqp_connection_resource *connection_resource_constructor(amqp_connection_params resource->socket = amqp_tcp_socket_new(resource->connection_state); if (!resource->socket) { - zend_throw_exception( - amqp_connection_exception_class_entry, - "Socket error: could not create socket.", - 0 TSRMLS_CC - ); + zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: could not create socket.", 0); return NULL; } } if (params->cacert && amqp_ssl_socket_set_cacert(resource->socket, params->cacert)) { - zend_throw_exception( - amqp_connection_exception_class_entry, - "Socket error: could not set CA certificate.", - 0 TSRMLS_CC - ); + zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: could not set CA certificate.", 0); return NULL; } @@ -579,11 +533,7 @@ amqp_connection_resource *connection_resource_constructor(amqp_connection_params } if (params->cert && params->key && amqp_ssl_socket_set_key(resource->socket, params->cert, params->key)) { - zend_throw_exception( - amqp_connection_exception_class_entry, - "Socket error: could not setting client cert.", - 0 TSRMLS_CC - ); + zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: could not setting client cert.", 0); return NULL; } @@ -598,33 +548,29 @@ amqp_connection_resource *connection_resource_constructor(amqp_connection_params /* Try to connect and verify that no error occurred */ if (amqp_socket_open_noblock(resource->socket, params->host, params->port, tv_ptr)) { - zend_throw_exception( - amqp_connection_exception_class_entry, - "Socket error: could not connect to host.", - 0 TSRMLS_CC - ); + zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: could not connect to host.", 0); - connection_resource_destructor(resource, persistent TSRMLS_CC); + connection_resource_destructor(resource, persistent); return NULL; } - if (!php_amqp_set_resource_read_timeout(resource, params->read_timeout TSRMLS_CC)) { - connection_resource_destructor(resource, persistent TSRMLS_CC); + if (!php_amqp_set_resource_read_timeout(resource, params->read_timeout)) { + connection_resource_destructor(resource, persistent); return NULL; } - if (!php_amqp_set_resource_write_timeout(resource, params->write_timeout TSRMLS_CC)) { - connection_resource_destructor(resource, persistent TSRMLS_CC); + if (!php_amqp_set_resource_write_timeout(resource, params->write_timeout)) { + connection_resource_destructor(resource, persistent); return NULL; } - if (!php_amqp_set_resource_rpc_timeout(resource, params->rpc_timeout TSRMLS_CC)) { - connection_resource_destructor(resource, persistent TSRMLS_CC); + if (!php_amqp_set_resource_rpc_timeout(resource, params->rpc_timeout)) { + connection_resource_destructor(resource, persistent); return NULL; } - std_datetime = php_std_date(time(NULL) TSRMLS_CC); + std_datetime = php_std_date(time(NULL)); client_properties_entries[0].key = amqp_cstring_bytes("type"); client_properties_entries[0].value.kind = AMQP_FIELD_KIND_UTF8; @@ -684,10 +630,10 @@ amqp_connection_resource *connection_resource_constructor(amqp_connection_params if (AMQP_RESPONSE_NORMAL != res.reply_type) { char *message = NULL, *long_message = NULL; - php_amqp_connection_resource_error(res, &message, resource, 0 TSRMLS_CC); + php_amqp_connection_resource_error(res, &message, resource, 0); spprintf(&long_message, 0, "%s - Potential login failure.", message); - zend_throw_exception(amqp_connection_exception_class_entry, long_message, PHP_AMQP_G(error_code) TSRMLS_CC); + zend_throw_exception(amqp_connection_exception_class_entry, long_message, PHP_AMQP_G(error_code)); efree(message); efree(long_message); @@ -702,7 +648,7 @@ amqp_connection_resource *connection_resource_constructor(amqp_connection_params * (presumably a thread) for a period of several seconds and then to close the network connection. This * includes syntax errors, over-sized data, and failed attempts to authenticate. */ - connection_resource_destructor(resource, persistent TSRMLS_CC); + connection_resource_destructor(resource, persistent); return NULL; } @@ -722,17 +668,17 @@ ZEND_RSRC_DTOR_FUNC(amqp_connection_resource_dtor_persistent) { amqp_connection_resource *resource = (amqp_connection_resource *) res->ptr; - connection_resource_destructor(resource, 1 TSRMLS_CC); + connection_resource_destructor(resource, 1); } ZEND_RSRC_DTOR_FUNC(amqp_connection_resource_dtor) { amqp_connection_resource *resource = (amqp_connection_resource *) res->ptr; - connection_resource_destructor(resource, 0 TSRMLS_CC); + connection_resource_destructor(resource, 0); } -static void connection_resource_destructor(amqp_connection_resource *resource, int persistent TSRMLS_DC) +static void connection_resource_destructor(amqp_connection_resource *resource, int persistent) { assert(resource != NULL); @@ -753,7 +699,7 @@ static void connection_resource_destructor(amqp_connection_resource *resource, i } if (resource->slots) { - php_amqp_prepare_for_disconnect(resource TSRMLS_CC); + php_amqp_prepare_for_disconnect(resource); pefree(resource->slots, persistent); resource->slots = NULL; @@ -774,7 +720,7 @@ static void connection_resource_destructor(amqp_connection_resource *resource, i pefree(resource, persistent); } -void php_amqp_prepare_for_disconnect(amqp_connection_resource *resource TSRMLS_DC) +void php_amqp_prepare_for_disconnect(amqp_connection_resource *resource) { if (resource == NULL) { return; @@ -791,7 +737,7 @@ void php_amqp_prepare_for_disconnect(amqp_connection_resource *resource TSRMLS_D for (slot = 0; slot < resource->max_slots; slot++) { if (resource->slots[slot] != 0) { - php_amqp_close_channel(resource->slots[slot], 0 TSRMLS_CC); + php_amqp_close_channel(resource->slots[slot], 0); } } } diff --git a/amqp_connection_resource.h b/amqp_connection_resource.h index 754ba542..7d3c22fe 100644 --- a/amqp_connection_resource.h +++ b/amqp_connection_resource.h @@ -39,7 +39,7 @@ extern int le_amqp_connection_resource_persistent; #include #endif -void php_amqp_prepare_for_disconnect(amqp_connection_resource *resource TSRMLS_DC); +void php_amqp_prepare_for_disconnect(amqp_connection_resource *resource); typedef struct _amqp_connection_params { char *login; @@ -67,22 +67,22 @@ int php_amqp_connection_resource_error( amqp_rpc_reply_t reply, char **message, amqp_connection_resource *resource, - amqp_channel_t channel_id TSRMLS_DC + amqp_channel_t channel_id ); int php_amqp_connection_resource_error_advanced( amqp_rpc_reply_t reply, char **message, amqp_connection_resource *resource, amqp_channel_t channel_id, - amqp_channel_object *channel TSRMLS_DC + amqp_channel_object *channel ); /* Socket-related functions */ -int php_amqp_set_resource_read_timeout(amqp_connection_resource *resource, double read_timeout TSRMLS_DC); -int php_amqp_set_resource_write_timeout(amqp_connection_resource *resource, double write_timeout TSRMLS_DC); +int php_amqp_set_resource_read_timeout(amqp_connection_resource *resource, double read_timeout); +int php_amqp_set_resource_write_timeout(amqp_connection_resource *resource, double write_timeout); /*Not socket-related rpc timeout function */ -int php_amqp_set_resource_rpc_timeout(amqp_connection_resource *resource, double rpc_timeout TSRMLS_DC); +int php_amqp_set_resource_rpc_timeout(amqp_connection_resource *resource, double rpc_timeout); /* Channel-related functions */ amqp_channel_t php_amqp_connection_resource_get_available_channel_id(amqp_connection_resource *resource); @@ -94,10 +94,7 @@ int php_amqp_connection_resource_register_channel( ); /* Creating and destroying resource */ -amqp_connection_resource *connection_resource_constructor( - amqp_connection_params *params, - zend_bool persistent TSRMLS_DC -); +amqp_connection_resource *connection_resource_constructor(amqp_connection_params *params, zend_bool persistent); ZEND_RSRC_DTOR_FUNC(amqp_connection_resource_dtor_persistent); ZEND_RSRC_DTOR_FUNC(amqp_connection_resource_dtor); diff --git a/amqp_decimal.c b/amqp_decimal.c index b3750247..9c368e2e 100644 --- a/amqp_decimal.c +++ b/amqp_decimal.c @@ -43,54 +43,41 @@ static PHP_METHOD(amqp_decimal_class, __construct) { zend_long exponent, significand; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &exponent, &significand) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &exponent, &significand) == FAILURE) { return; } if (exponent < AMQP_DECIMAL_EXPONENT_MIN) { - zend_throw_exception_ex( - amqp_value_exception_class_entry, - 0 TSRMLS_CC, - "Decimal exponent value must be unsigned." - ); + zend_throw_exception_ex(amqp_value_exception_class_entry, 0, "Decimal exponent value must be unsigned."); return; } if (exponent > AMQP_DECIMAL_EXPONENT_MAX) { zend_throw_exception_ex( amqp_value_exception_class_entry, - 0 TSRMLS_CC, + 0, "Decimal exponent value must be less than %u.", (unsigned) AMQP_DECIMAL_EXPONENT_MAX ); return; } if (significand < AMQP_DECIMAL_SIGNIFICAND_MIN) { - zend_throw_exception_ex( - amqp_value_exception_class_entry, - 0 TSRMLS_CC, - "Decimal significand value must be unsigned." - ); + zend_throw_exception_ex(amqp_value_exception_class_entry, 0, "Decimal significand value must be unsigned."); return; } if (significand > AMQP_DECIMAL_SIGNIFICAND_MAX) { zend_throw_exception_ex( amqp_value_exception_class_entry, - 0 TSRMLS_CC, + 0, "Decimal significand value must be less than %u.", (unsigned) AMQP_DECIMAL_SIGNIFICAND_MAX ); return; } - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("exponent"), exponent TSRMLS_CC); - zend_update_property_long( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("significand"), - significand TSRMLS_CC - ); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("exponent"), exponent); + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("significand"), significand); } /* }}} */ @@ -118,14 +105,14 @@ static PHP_METHOD(amqp_decimal_class, getSignificand) ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_decimal_class_construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 2) - ZEND_ARG_INFO(0, exponent) - ZEND_ARG_INFO(0, significand) + ZEND_ARG_TYPE_INFO(0, exponent, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, significand, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_decimal_class_getExponent, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_decimal_class_getExponent, ZEND_SEND_BY_VAL, 0, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_decimal_class_getSignificand, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_decimal_class_getSignificand, ZEND_SEND_BY_VAL, 0, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -143,16 +130,16 @@ PHP_MINIT_FUNCTION(amqp_decimal) zend_class_entry ce; INIT_CLASS_ENTRY(ce, "AMQPDecimal", amqp_decimal_class_functions); - this_ce = zend_register_internal_class(&ce TSRMLS_CC); + this_ce = zend_register_internal_class(&ce); this_ce->ce_flags = this_ce->ce_flags | ZEND_ACC_FINAL; - zend_declare_class_constant_long(this_ce, ZEND_STRL("EXPONENT_MIN"), AMQP_DECIMAL_EXPONENT_MIN TSRMLS_CC); - zend_declare_class_constant_long(this_ce, ZEND_STRL("EXPONENT_MAX"), AMQP_DECIMAL_EXPONENT_MAX TSRMLS_CC); - zend_declare_class_constant_long(this_ce, ZEND_STRL("SIGNIFICAND_MIN"), AMQP_DECIMAL_SIGNIFICAND_MIN TSRMLS_CC); - zend_declare_class_constant_long(this_ce, ZEND_STRL("SIGNIFICAND_MAX"), AMQP_DECIMAL_SIGNIFICAND_MAX TSRMLS_CC); + zend_declare_class_constant_long(this_ce, ZEND_STRL("EXPONENT_MIN"), AMQP_DECIMAL_EXPONENT_MIN); + zend_declare_class_constant_long(this_ce, ZEND_STRL("EXPONENT_MAX"), AMQP_DECIMAL_EXPONENT_MAX); + zend_declare_class_constant_long(this_ce, ZEND_STRL("SIGNIFICAND_MIN"), AMQP_DECIMAL_SIGNIFICAND_MIN); + zend_declare_class_constant_long(this_ce, ZEND_STRL("SIGNIFICAND_MAX"), AMQP_DECIMAL_SIGNIFICAND_MAX); - zend_declare_property_long(this_ce, ZEND_STRL("exponent"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_long(this_ce, ZEND_STRL("significand"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "exponent", ZEND_ACC_PRIVATE, IS_LONG, 0); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "significand", ZEND_ACC_PRIVATE, IS_LONG, 0); return SUCCESS; } diff --git a/amqp_envelope.c b/amqp_envelope.c index c5ba803c..def39b5c 100644 --- a/amqp_envelope.c +++ b/amqp_envelope.c @@ -65,7 +65,7 @@ zend_class_entry *amqp_envelope_class_entry; #define this_ce amqp_envelope_class_entry -void convert_amqp_envelope_to_zval(amqp_envelope_t *amqp_envelope, zval *envelope TSRMLS_DC) +void convert_amqp_envelope_to_zval(amqp_envelope_t *amqp_envelope, zval *envelope) { /* Build the envelope */ object_init_ex(envelope, this_ce); @@ -79,44 +79,44 @@ void convert_amqp_envelope_to_zval(amqp_envelope_t *amqp_envelope, zval *envelop PHP_AMQP_COMPAT_OBJ_P(envelope), ZEND_STRL("body"), (const char *) message->body.bytes, - (size_t) message->body.len TSRMLS_CC + (size_t) message->body.len ); zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(envelope), - ZEND_STRL("consumer_tag"), + ZEND_STRL("consumerTag"), (const char *) amqp_envelope->consumer_tag.bytes, - (size_t) amqp_envelope->consumer_tag.len TSRMLS_CC + (size_t) amqp_envelope->consumer_tag.len ); zend_update_property_long( this_ce, PHP_AMQP_COMPAT_OBJ_P(envelope), - ZEND_STRL("delivery_tag"), - (zend_long) amqp_envelope->delivery_tag TSRMLS_CC + ZEND_STRL("deliveryTag"), + (zend_long) amqp_envelope->delivery_tag ); zend_update_property_bool( this_ce, PHP_AMQP_COMPAT_OBJ_P(envelope), - ZEND_STRL("is_redelivery"), - (zend_long) amqp_envelope->redelivered TSRMLS_CC + ZEND_STRL("isRedelivery"), + (zend_long) amqp_envelope->redelivered ); zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(envelope), - ZEND_STRL("exchange_name"), + ZEND_STRL("exchangeName"), (const char *) amqp_envelope->exchange.bytes, - (size_t) amqp_envelope->exchange.len TSRMLS_CC + (size_t) amqp_envelope->exchange.len ); zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(envelope), - ZEND_STRL("routing_key"), + ZEND_STRL("routingKey"), (const char *) amqp_envelope->routing_key.bytes, - (size_t) amqp_envelope->routing_key.len TSRMLS_CC + (size_t) amqp_envelope->routing_key.len ); - php_amqp_basic_properties_extract(p, envelope TSRMLS_CC); + php_amqp_basic_properties_extract(p, envelope); } /* {{{ proto AMQPEnvelope::__construct() */ @@ -125,7 +125,7 @@ static PHP_METHOD(amqp_envelope_class, __construct) PHP_AMQP_NOPARAMS(); /* BC */ - php_amqp_basic_properties_set_empty_headers(getThis() TSRMLS_CC); + php_amqp_basic_properties_set_empty_headers(getThis()); } /* }}} */ @@ -140,7 +140,6 @@ static PHP_METHOD(amqp_envelope_class, getBody) zval *zv = PHP_AMQP_READ_THIS_PROP("body"); if (Z_STRLEN_P(zv) == 0) { - /* BC */ RETURN_STRING(""); } @@ -153,7 +152,7 @@ static PHP_METHOD(amqp_envelope_class, getRoutingKey) { zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("routing_key"); + PHP_AMQP_RETURN_THIS_PROP("routingKey"); } /* }}} */ @@ -162,7 +161,7 @@ static PHP_METHOD(amqp_envelope_class, getDeliveryTag) { zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("delivery_tag"); + PHP_AMQP_RETURN_THIS_PROP("deliveryTag"); } /* }}} */ @@ -171,7 +170,7 @@ static PHP_METHOD(amqp_envelope_class, getConsumerTag) { zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("consumer_tag"); + PHP_AMQP_RETURN_THIS_PROP("consumerTag"); } /* }}} */ @@ -180,7 +179,7 @@ static PHP_METHOD(amqp_envelope_class, getExchangeName) { zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("exchange_name"); + PHP_AMQP_RETURN_THIS_PROP("exchangeName"); } /* }}} */ @@ -189,7 +188,7 @@ static PHP_METHOD(amqp_envelope_class, isRedelivery) { zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("is_redelivery"); + PHP_AMQP_RETURN_THIS_PROP("isRedelivery"); } /* }}} */ @@ -203,7 +202,7 @@ static PHP_METHOD(amqp_envelope_class, getHeader) size_t key_len; zval *tmp = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &key, &key_len) == FAILURE) { return; } @@ -227,18 +226,14 @@ static PHP_METHOD(amqp_envelope_class, hasHeader) char *key; size_t key_len; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &key, &key_len) == FAILURE) { return; } zval *zv = PHP_AMQP_READ_THIS_PROP_CE("headers", amqp_basic_properties_class_entry); /* Look for the hash key */ - if (zend_hash_str_find(HASH_OF(zv), key, key_len) == NULL) { - RETURN_FALSE; - } - - RETURN_TRUE; + RETURN_BOOL(zend_hash_str_find(HASH_OF(zv), key, key_len) != NULL); } /* }}} */ @@ -247,30 +242,30 @@ static PHP_METHOD(amqp_envelope_class, hasHeader) ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class__construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_getBody, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_envelope_class_getBody, ZEND_SEND_BY_VAL, 0, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_getRoutingKey, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_envelope_class_getRoutingKey, ZEND_SEND_BY_VAL, 0, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_getConsumerTag, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_envelope_class_getConsumerTag, ZEND_SEND_BY_VAL, 0, IS_STRING, 1) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_getDeliveryTag, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_envelope_class_getDeliveryTag, ZEND_SEND_BY_VAL, 0, IS_LONG, 1) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_getExchangeName, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_envelope_class_getExchangeName, ZEND_SEND_BY_VAL, 0, IS_STRING, 1) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_isRedelivery, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_envelope_class_isRedelivery, ZEND_SEND_BY_VAL, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_getHeader, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, name) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_envelope_class_getHeader, ZEND_SEND_BY_VAL, 1, IS_STRING, 1) + ZEND_ARG_TYPE_INFO(0, headerName, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_hasHeader, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, name) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_envelope_class_hasHeader, ZEND_SEND_BY_VAL, 1, _IS_BOOL, 0) + ZEND_ARG_TYPE_INFO(0, headerName, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -297,15 +292,21 @@ PHP_MINIT_FUNCTION(amqp_envelope) zend_class_entry ce; INIT_CLASS_ENTRY(ce, "AMQPEnvelope", amqp_envelope_class_functions); - this_ce = zend_register_internal_class_ex(&ce, amqp_basic_properties_class_entry TSRMLS_CC); - - zend_declare_property_stringl(this_ce, ZEND_STRL("body"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); - - zend_declare_property_null(this_ce, ZEND_STRL("consumer_tag"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("delivery_tag"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("is_redelivery"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("exchange_name"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_stringl(this_ce, ZEND_STRL("routing_key"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); + this_ce = zend_register_internal_class_ex(&ce, amqp_basic_properties_class_entry); + + PHP_AMQP_DECLARE_TYPED_PROPERTY_WITH_DEFAULT(this_ce, "body", ZEND_ACC_PRIVATE, IS_STRING, 0, ZVAL_EMPTY_STRING); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "consumerTag", ZEND_ACC_PRIVATE, IS_STRING, 1); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "deliveryTag", ZEND_ACC_PRIVATE, IS_LONG, 1); + PHP_AMQP_DECLARE_TYPED_PROPERTY_WITH_DEFAULT(this_ce, "isRedelivery", ZEND_ACC_PRIVATE, _IS_BOOL, 0, ZVAL_FALSE); + PHP_AMQP_DECLARE_TYPED_PROPERTY_WITH_DEFAULT(this_ce, "exchangeName", ZEND_ACC_PRIVATE, IS_STRING, 1, ZVAL_NULL); + PHP_AMQP_DECLARE_TYPED_PROPERTY_WITH_DEFAULT( + this_ce, + "routingKey", + ZEND_ACC_PRIVATE, + IS_STRING, + 0, + ZVAL_EMPTY_STRING + ); return SUCCESS; } diff --git a/amqp_envelope.h b/amqp_envelope.h index c8adb94c..277e059a 100644 --- a/amqp_envelope.h +++ b/amqp_envelope.h @@ -25,6 +25,6 @@ extern zend_class_entry *amqp_envelope_class_entry; -void convert_amqp_envelope_to_zval(amqp_envelope_t *amqp_envelope, zval *envelope TSRMLS_DC); +void convert_amqp_envelope_to_zval(amqp_envelope_t *amqp_envelope, zval *envelope); PHP_MINIT_FUNCTION(amqp_envelope); diff --git a/amqp_envelope_exception.c b/amqp_envelope_exception.c new file mode 100644 index 00000000..450ffbf1 --- /dev/null +++ b/amqp_envelope_exception.c @@ -0,0 +1,79 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2007 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Alexandre Kalendarev akalend@mail.ru Copyright (c) 2009-2010 | + | Lead: | + | - Pieter de Zwart | + | Maintainers: | + | - Brad Rodriguez | + | - Jonathan Tansavatdi | + +----------------------------------------------------------------------+ +*/ +#ifdef HAVE_CONFIG_H + #include "config.h" +#endif + +#include "php.h" +#include "php_ini.h" +#include "zend_exceptions.h" +#include "php_amqp.h" + +zend_class_entry *amqp_envelope_exception_class_entry; +#define this_ce amqp_envelope_exception_class_entry + +/* {{{ proto float AMQPEnvelopeException::getEnvelope() +Get AMQPEnvelope object */ +static PHP_METHOD(amqp_envelope_exception_class, getEnvelope) +{ + zval rv; + PHP_AMQP_NOPARAMS(); + + PHP_AMQP_RETURN_THIS_PROP("envelope"); +} +/* }}} */ + + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX( + arginfo_amqp_envelope_exception_class_getEnvelope, + ZEND_SEND_BY_VAL, + 0, + AMQPEnvelope, + 0 +) +ZEND_END_ARG_INFO() + +zend_function_entry amqp_envelope_exception_class_functions[] = { + PHP_ME(amqp_envelope_exception_class, getEnvelope, arginfo_amqp_envelope_exception_class_getEnvelope, ZEND_ACC_PUBLIC) + + {NULL, NULL, NULL} +}; + + +PHP_MINIT_FUNCTION(amqp_envelope_exception) +{ + zend_class_entry ce; + + INIT_CLASS_ENTRY(ce, "AMQPEnvelopeException", amqp_envelope_exception_class_functions); + amqp_envelope_exception_class_entry = zend_register_internal_class_ex(&ce, amqp_exception_class_entry); + + PHP_AMQP_DECLARE_TYPED_PROPERTY_OBJ( + amqp_envelope_exception_class_entry, + "envelope", + ZEND_ACC_PRIVATE, + AMQPEnvelope, + 0 + ); + + return SUCCESS; +} diff --git a/amqp_envelope_exception.h b/amqp_envelope_exception.h new file mode 100644 index 00000000..49509579 --- /dev/null +++ b/amqp_envelope_exception.h @@ -0,0 +1,27 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2007 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Alexandre Kalendarev akalend@mail.ru Copyright (c) 2009-2010 | + | Lead: | + | - Pieter de Zwart | + | Maintainers: | + | - Brad Rodriguez | + | - Jonathan Tansavatdi | + +----------------------------------------------------------------------+ +*/ +#include "php.h" + +extern zend_class_entry *amqp_envelope_exception_class_entry; + +PHP_MINIT_FUNCTION(amqp_envelope_exception); diff --git a/amqp_exchange.c b/amqp_exchange.c index 1654c43c..07327b09 100644 --- a/amqp_exchange.c +++ b/amqp_exchange.c @@ -74,24 +74,24 @@ static PHP_METHOD(amqp_exchange_class, __construct) zval *channelObj; amqp_channel_resource *channel_resource; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &channelObj, amqp_channel_class_entry) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &channelObj, amqp_channel_class_entry) == FAILURE) { return; } ZVAL_UNDEF(&arguments); array_init(&arguments); - zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("arguments"), &arguments TSRMLS_CC); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("arguments"), &arguments); zval_ptr_dtor(&arguments); channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(channelObj); PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not create exchange."); - zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("channel"), channelObj TSRMLS_CC); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("channel"), channelObj); zend_update_property( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connection"), - PHP_AMQP_READ_OBJ_PROP(amqp_channel_class_entry, channelObj, "connection") TSRMLS_CC + PHP_AMQP_READ_OBJ_PROP(amqp_channel_class_entry, channelObj, "connection") ); } /* }}} */ @@ -108,8 +108,7 @@ static PHP_METHOD(amqp_exchange_class, getName) if (PHP_AMQP_READ_THIS_PROP_STRLEN("name") > 0) { PHP_AMQP_RETURN_THIS_PROP("name"); } else { - /* BC */ - RETURN_FALSE; + RETURN_NULL(); } } /* }}} */ @@ -122,7 +121,7 @@ static PHP_METHOD(amqp_exchange_class, setName) char *name = NULL; size_t name_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &name, &name_len) == FAILURE) { return; } @@ -131,13 +130,13 @@ static PHP_METHOD(amqp_exchange_class, setName) zend_throw_exception( amqp_exchange_exception_class_entry, "Invalid exchange name given, must be less than 255 characters long.", - 0 TSRMLS_CC + 0 ); return; } /* Set the exchange name */ - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("name"), name, name_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("name"), name, name_len); } /* }}} */ @@ -160,7 +159,7 @@ static PHP_METHOD(amqp_exchange_class, getFlags) flags |= AMQP_DURABLE; } - if (PHP_AMQP_READ_THIS_PROP_BOOL("auto_delete")) { + if (PHP_AMQP_READ_THIS_PROP_BOOL("autoDelete")) { flags |= AMQP_AUTODELETE; } @@ -180,37 +179,17 @@ static PHP_METHOD(amqp_exchange_class, setFlags) zend_long flags = AMQP_NOPARAM; zend_bool flags_is_null = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l!", &flags, &flags_is_null) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l!", &flags, &flags_is_null) == FAILURE) { return; } /* Set the flags based on the bitmask we were given */ flags = flags ? flags & PHP_AMQP_EXCHANGE_FLAGS : flags; - zend_update_property_bool( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("passive"), - IS_PASSIVE(flags) TSRMLS_CC - ); - zend_update_property_bool( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("durable"), - IS_DURABLE(flags) TSRMLS_CC - ); - zend_update_property_bool( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("auto_delete"), - IS_AUTODELETE(flags) TSRMLS_CC - ); - zend_update_property_bool( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("internal"), - IS_INTERNAL(flags) TSRMLS_CC - ); + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("passive"), IS_PASSIVE(flags)); + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("durable"), IS_DURABLE(flags)); + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("autoDelete"), IS_AUTODELETE(flags)); + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("internal"), IS_INTERNAL(flags)); } /* }}} */ @@ -226,8 +205,7 @@ static PHP_METHOD(amqp_exchange_class, getType) if (PHP_AMQP_READ_THIS_PROP_STRLEN("type") > 0) { PHP_AMQP_RETURN_THIS_PROP("type"); } else { - /* BC */ - RETURN_FALSE; + RETURN_NULL(); } } /* }}} */ @@ -240,11 +218,11 @@ static PHP_METHOD(amqp_exchange_class, setType) char *type = NULL; size_t type_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &type, &type_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &type, &type_len) == FAILURE) { return; } - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("type"), type, type_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("type"), type, type_len); } /* }}} */ @@ -260,7 +238,7 @@ static PHP_METHOD(amqp_exchange_class, getArgument) char *key; size_t key_len; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &key, &key_len) == FAILURE) { return; } @@ -276,19 +254,14 @@ static PHP_METHOD(amqp_exchange_class, getArgument) static PHP_METHOD(amqp_exchange_class, hasArgument) { zval rv; - zval *tmp = NULL; char *key; size_t key_len; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &key, &key_len) == FAILURE) { return; } - if ((tmp = zend_hash_str_find(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len)) == NULL) { - RETURN_FALSE; - } - - RETURN_TRUE; + RETURN_BOOL(zend_hash_str_find(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len) != NULL); } /* }}} */ @@ -309,13 +282,11 @@ static PHP_METHOD(amqp_exchange_class, setArguments) { zval *zvalArguments; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &zvalArguments) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a/", &zvalArguments) == FAILURE) { return; } - zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("arguments"), zvalArguments TSRMLS_CC); - - RETURN_TRUE; + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("arguments"), zvalArguments); } /* }}} */ @@ -329,7 +300,7 @@ static PHP_METHOD(amqp_exchange_class, setArgument) size_t key_len = 0; zval *value = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &key, &key_len, &value) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz", &key, &key_len, &value) == FAILURE) { return; } @@ -349,12 +320,10 @@ static PHP_METHOD(amqp_exchange_class, setArgument) zend_throw_exception( amqp_exchange_exception_class_entry, "The value parameter must be of type NULL, int, double or string.", - 0 TSRMLS_CC + 0 ); return; } - - RETURN_TRUE; } /* }}} */ @@ -381,7 +350,7 @@ static PHP_METHOD(amqp_exchange_class, declareExchange) zend_throw_exception( amqp_exchange_exception_class_entry, "Could not declare exchange. Exchanges must have a name.", - 0 TSRMLS_CC + 0 ); return; } @@ -391,12 +360,12 @@ static PHP_METHOD(amqp_exchange_class, declareExchange) zend_throw_exception( amqp_exchange_exception_class_entry, "Could not declare exchange. Exchanges must have a type.", - 0 TSRMLS_CC + 0 ); return; } - arguments = php_amqp_type_convert_zval_to_amqp_table(PHP_AMQP_READ_THIS_PROP("arguments") TSRMLS_CC); + arguments = php_amqp_type_convert_zval_to_amqp_table(PHP_AMQP_READ_THIS_PROP("arguments")); amqp_exchange_declare( channel_resource->connection_resource->connection_state, @@ -405,7 +374,7 @@ static PHP_METHOD(amqp_exchange_class, declareExchange) amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("type")), PHP_AMQP_READ_THIS_PROP_BOOL("passive"), PHP_AMQP_READ_THIS_PROP_BOOL("durable"), - PHP_AMQP_READ_THIS_PROP_BOOL("auto_delete"), + PHP_AMQP_READ_THIS_PROP_BOOL("autoDelete"), PHP_AMQP_READ_THIS_PROP_BOOL("internal"), *arguments ); @@ -416,11 +385,9 @@ static PHP_METHOD(amqp_exchange_class, declareExchange) php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_exchange_exception_class_entry TSRMLS_CC); + php_amqp_zend_throw_exception_short(res, amqp_exchange_exception_class_entry); return; } - - RETURN_TRUE; } /* }}} */ @@ -438,7 +405,7 @@ static PHP_METHOD(amqp_exchange_class, delete) size_t name_len = 0; zend_long flags = AMQP_NOPARAM; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sl", &name, &name_len, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|sl", &name, &name_len, &flags) == FAILURE) { return; } @@ -448,21 +415,23 @@ static PHP_METHOD(amqp_exchange_class, delete) amqp_exchange_delete( channel_resource->connection_resource->connection_state, channel_resource->channel_id, - amqp_cstring_bytes(name_len ? name : PHP_AMQP_READ_THIS_PROP_STR("name")), + amqp_cstring_bytes( + name_len ? name + : PHP_AMQP_READ_THIS_PROP_STRLEN("name") ? PHP_AMQP_READ_THIS_PROP_STR("name") + : "" + ), (AMQP_IFUNUSED & flags) ? 1 : 0 ); amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_exchange_exception_class_entry TSRMLS_CC); + php_amqp_zend_throw_exception_short(res, amqp_exchange_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - - RETURN_TRUE; } /* }}} */ @@ -492,16 +461,8 @@ static PHP_METHOD(amqp_exchange_class, publish) amqp_basic_properties_t props; - if (zend_parse_parameters( - ZEND_NUM_ARGS() TSRMLS_CC, - "s|s!la/", - &msg, - &msg_len, - &key_name, - &key_len, - &flags, - &ini_arr - ) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s!la/", &msg, &msg_len, &key_name, &key_len, &flags, &ini_arr) == + FAILURE) { return; } @@ -512,8 +473,7 @@ static PHP_METHOD(amqp_exchange_class, publish) props.headers.entries = 0; { - if (ini_arr && - (tmp = zend_hash_str_find(HASH_OF(ini_arr), "content_type", sizeof("content_type") - 1)) != NULL) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("content_type"))) != NULL) { SEPARATE_ZVAL(tmp); convert_to_string(tmp); @@ -523,8 +483,7 @@ static PHP_METHOD(amqp_exchange_class, publish) } } - if (ini_arr && - (tmp = zend_hash_str_find(HASH_OF(ini_arr), "content_encoding", sizeof("content_encoding") - 1)) != NULL) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("content_encoding"))) != NULL) { SEPARATE_ZVAL(tmp); convert_to_string(tmp); @@ -534,7 +493,7 @@ static PHP_METHOD(amqp_exchange_class, publish) } } - if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "message_id", sizeof("message_id") - 1)) != NULL) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("message_id"))) != NULL) { SEPARATE_ZVAL(tmp); convert_to_string(tmp); @@ -544,7 +503,7 @@ static PHP_METHOD(amqp_exchange_class, publish) } } - if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "user_id", sizeof("user_id") - 1)) != NULL) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("user_id"))) != NULL) { SEPARATE_ZVAL(tmp); convert_to_string(tmp); @@ -554,7 +513,7 @@ static PHP_METHOD(amqp_exchange_class, publish) } } - if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "app_id", sizeof("app_id") - 1)) != NULL) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("app_id"))) != NULL) { SEPARATE_ZVAL(tmp); convert_to_string(tmp); @@ -564,8 +523,7 @@ static PHP_METHOD(amqp_exchange_class, publish) } } - if (ini_arr && - (tmp = zend_hash_str_find(HASH_OF(ini_arr), "delivery_mode", sizeof("delivery_mode") - 1)) != NULL) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("delivery_mode"))) != NULL) { SEPARATE_ZVAL(tmp); convert_to_long(tmp); @@ -573,7 +531,7 @@ static PHP_METHOD(amqp_exchange_class, publish) props._flags |= AMQP_BASIC_DELIVERY_MODE_FLAG; } - if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "priority", sizeof("priority") - 1)) != NULL) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("priority"))) != NULL) { SEPARATE_ZVAL(tmp); convert_to_long(tmp); @@ -581,7 +539,7 @@ static PHP_METHOD(amqp_exchange_class, publish) props._flags |= AMQP_BASIC_PRIORITY_FLAG; } - if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "timestamp", sizeof("timestamp") - 1)) != NULL) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("timestamp"))) != NULL) { SEPARATE_ZVAL(tmp); convert_to_long(tmp); @@ -589,7 +547,7 @@ static PHP_METHOD(amqp_exchange_class, publish) props._flags |= AMQP_BASIC_TIMESTAMP_FLAG; } - if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "expiration", sizeof("expiration") - 1)) != NULL) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("expiration"))) != NULL) { SEPARATE_ZVAL(tmp); convert_to_string(tmp); @@ -599,7 +557,7 @@ static PHP_METHOD(amqp_exchange_class, publish) } } - if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "type", sizeof("type") - 1)) != NULL) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("type"))) != NULL) { SEPARATE_ZVAL(tmp); convert_to_string(tmp); @@ -609,7 +567,7 @@ static PHP_METHOD(amqp_exchange_class, publish) } } - if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "reply_to", sizeof("reply_to") - 1)) != NULL) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("reply_to"))) != NULL) { SEPARATE_ZVAL(tmp); convert_to_string(tmp); @@ -618,8 +576,7 @@ static PHP_METHOD(amqp_exchange_class, publish) props._flags |= AMQP_BASIC_REPLY_TO_FLAG; } } - if (ini_arr && - (tmp = zend_hash_str_find(HASH_OF(ini_arr), "correlation_id", sizeof("correlation_id") - 1)) != NULL) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("correlation_id"))) != NULL) { SEPARATE_ZVAL(tmp); convert_to_string(tmp); @@ -632,11 +589,11 @@ static PHP_METHOD(amqp_exchange_class, publish) amqp_table_t *headers = NULL; - if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), "headers", sizeof("headers") - 1)) != NULL) { + if (ini_arr && (tmp = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL("headers"))) != NULL) { SEPARATE_ZVAL(tmp); convert_to_array(tmp); - headers = php_amqp_type_convert_zval_to_amqp_table(tmp TSRMLS_CC); + headers = php_amqp_type_convert_zval_to_amqp_table(tmp); props._flags |= AMQP_BASIC_HEADERS_FLAG; props.headers = *headers; @@ -681,24 +638,17 @@ static PHP_METHOD(amqp_exchange_class, publish) res.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; res.library_error = status; - php_amqp_error( - res, - &PHP_AMQP_G(error_message), - channel_resource->connection_resource, - channel_resource TSRMLS_CC - ); + php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource); php_amqp_zend_throw_exception( res, amqp_exchange_exception_class_entry, PHP_AMQP_G(error_message), - PHP_AMQP_G(error_code) TSRMLS_CC + PHP_AMQP_G(error_code) ); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } - - RETURN_TRUE; } /* }}} */ @@ -722,7 +672,7 @@ static PHP_METHOD(amqp_exchange_class, bind) amqp_table_t *arguments = NULL; if (zend_parse_parameters( - ZEND_NUM_ARGS() TSRMLS_CC, + ZEND_NUM_ARGS(), "s|s!a", &src_name, &src_name_len, @@ -737,13 +687,13 @@ static PHP_METHOD(amqp_exchange_class, bind) PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not bind to exchange."); if (zvalArguments) { - arguments = php_amqp_type_convert_zval_to_amqp_table(zvalArguments TSRMLS_CC); + arguments = php_amqp_type_convert_zval_to_amqp_table(zvalArguments); } amqp_exchange_bind( channel_resource->connection_resource->connection_state, channel_resource->channel_id, - amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), + amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STRLEN("name") ? PHP_AMQP_READ_THIS_PROP_STR("name") : ""), (src_name_len > 0 ? amqp_cstring_bytes(src_name) : amqp_empty_bytes), (keyname != NULL && keyname_len > 0 ? amqp_cstring_bytes(keyname) : amqp_empty_bytes), (arguments ? *arguments : amqp_empty_table) @@ -756,14 +706,12 @@ static PHP_METHOD(amqp_exchange_class, bind) amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_exchange_exception_class_entry TSRMLS_CC); + php_amqp_zend_throw_exception_short(res, amqp_exchange_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - - RETURN_TRUE; } /* }}} */ @@ -786,7 +734,7 @@ static PHP_METHOD(amqp_exchange_class, unbind) amqp_table_t *arguments = NULL; if (zend_parse_parameters( - ZEND_NUM_ARGS() TSRMLS_CC, + ZEND_NUM_ARGS(), "s|s!a", &src_name, &src_name_len, @@ -801,13 +749,13 @@ static PHP_METHOD(amqp_exchange_class, unbind) PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not unbind from exchange."); if (zvalArguments) { - arguments = php_amqp_type_convert_zval_to_amqp_table(zvalArguments TSRMLS_CC); + arguments = php_amqp_type_convert_zval_to_amqp_table(zvalArguments); } amqp_exchange_unbind( channel_resource->connection_resource->connection_state, channel_resource->channel_id, - amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), + amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STRLEN("name") ? PHP_AMQP_READ_THIS_PROP_STR("name") : ""), (src_name_len > 0 ? amqp_cstring_bytes(src_name) : amqp_empty_bytes), (keyname != NULL && keyname_len > 0 ? amqp_cstring_bytes(keyname) : amqp_empty_bytes), (arguments ? *arguments : amqp_empty_table) @@ -820,14 +768,12 @@ static PHP_METHOD(amqp_exchange_class, unbind) amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_exchange_exception_class_entry TSRMLS_CC); + php_amqp_zend_throw_exception_short(res, amqp_exchange_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - - RETURN_TRUE; } /* }}} */ @@ -853,81 +799,81 @@ static PHP_METHOD(amqp_exchange_class, getConnection) /* amqp_exchange ARG_INFO definition */ ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class__construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_OBJ_INFO(0, amqp_channel, AMQPChannel, 0) + ZEND_ARG_OBJ_INFO(0, channel, AMQPChannel, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_getName, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_exchange_class_getName, ZEND_SEND_BY_VAL, 0, IS_STRING, 1) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_setName, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, exchange_name) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_exchange_class_setName, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, exchangeName, IS_STRING, 1) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_getFlags, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_exchange_class_getFlags, ZEND_SEND_BY_VAL, 0, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_setFlags, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, flags) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_exchange_class_setFlags, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 1) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_getType, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_exchange_class_getType, ZEND_SEND_BY_VAL, 0, IS_STRING, 1) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_setType, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, exchange_type) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_exchange_class_setType, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, exchangeType, IS_STRING, 1) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_getArgument, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, argument) + ZEND_ARG_TYPE_INFO(0, argumentName, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_hasArgument, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, argument) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_exchange_class_hasArgument, ZEND_SEND_BY_VAL, 1, _IS_BOOL, 0) + ZEND_ARG_TYPE_INFO(0, argumentName, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_getArguments, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_exchange_class_getArguments, ZEND_SEND_BY_VAL, 0, IS_ARRAY, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_setArgument, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 2) - ZEND_ARG_INFO(0, key) - ZEND_ARG_INFO(0, value) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_exchange_class_setArgument, ZEND_SEND_BY_VAL, 2, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, argumentName, IS_STRING, 0) + ZEND_ARG_INFO(0, argumentValue) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_setArguments, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_exchange_class_setArguments, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) ZEND_ARG_ARRAY_INFO(0, arguments, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_declareExchange, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_exchange_class_declareExchange, ZEND_SEND_BY_VAL, 0, IS_VOID, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_bind, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 2) - ZEND_ARG_INFO(0, exchange_name) - ZEND_ARG_INFO(0, routing_key) - ZEND_ARG_INFO(0, flags) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_exchange_class_bind, ZEND_RETURN_VALUE, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, exchangeName, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, routingKey, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, arguments, IS_ARRAY, 0, "[]") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_unbind, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 2) - ZEND_ARG_INFO(0, exchange_name) - ZEND_ARG_INFO(0, routing_key) - ZEND_ARG_INFO(0, flags) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_exchange_class_unbind, ZEND_RETURN_VALUE, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, exchangeName, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, routingKey, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, arguments, IS_ARRAY, 0, "[]") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_delete, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) - ZEND_ARG_INFO(0, exchange_name) - ZEND_ARG_INFO(0, flags) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_exchange_class_delete, ZEND_RETURN_VALUE, 0, IS_VOID, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, exchangeName, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "AMQP_NOPARAM") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_publish, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, message) - ZEND_ARG_INFO(0, routing_key) - ZEND_ARG_INFO(0, flags) - ZEND_ARG_ARRAY_INFO(0, headers, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_exchange_class_publish, ZEND_RETURN_VALUE, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, routingKey, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "AMQP_NOPARAM") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, headers, IS_ARRAY, 0, "[]") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_getChannel, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(arginfo_amqp_exchange_class_getChannel, AMQPChannel, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_exchange_class_getConnection, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(arginfo_amqp_exchange_class_getConnection, AMQPConnection, 0) ZEND_END_ARG_INFO() zend_function_entry amqp_exchange_class_functions[] = { @@ -948,7 +894,9 @@ zend_function_entry amqp_exchange_class_functions[] = { PHP_ME(amqp_exchange_class, setArguments, arginfo_amqp_exchange_class_setArguments, ZEND_ACC_PUBLIC) PHP_ME(amqp_exchange_class, hasArgument, arginfo_amqp_exchange_class_hasArgument, ZEND_ACC_PUBLIC) - PHP_ME(amqp_exchange_class, declareExchange,arginfo_amqp_exchange_class_declareExchange,ZEND_ACC_PUBLIC) + PHP_ME(amqp_exchange_class, declareExchange, arginfo_amqp_exchange_class_declareExchange, ZEND_ACC_PUBLIC) + PHP_MALIAS(amqp_exchange_class, declare, declareExchange, arginfo_amqp_exchange_class_declareExchange, ZEND_ACC_PUBLIC) + PHP_ME(amqp_exchange_class, bind, arginfo_amqp_exchange_class_bind, ZEND_ACC_PUBLIC) PHP_ME(amqp_exchange_class, unbind, arginfo_amqp_exchange_class_unbind, ZEND_ACC_PUBLIC) PHP_ME(amqp_exchange_class, delete, arginfo_amqp_exchange_class_delete, ZEND_ACC_PUBLIC) @@ -957,8 +905,6 @@ zend_function_entry amqp_exchange_class_functions[] = { PHP_ME(amqp_exchange_class, getChannel, arginfo_amqp_exchange_class_getChannel, ZEND_ACC_PUBLIC) PHP_ME(amqp_exchange_class, getConnection, arginfo_amqp_exchange_class_getConnection, ZEND_ACC_PUBLIC) - PHP_MALIAS(amqp_exchange_class, declare, declareExchange, arginfo_amqp_exchange_class_declareExchange, ZEND_ACC_PUBLIC | ZEND_ACC_DEPRECATED) - {NULL, NULL, NULL} }; @@ -967,18 +913,21 @@ PHP_MINIT_FUNCTION(amqp_exchange) zend_class_entry ce; INIT_CLASS_ENTRY(ce, "AMQPExchange", amqp_exchange_class_functions); - this_ce = zend_register_internal_class(&ce TSRMLS_CC); - - zend_declare_property_null(this_ce, ZEND_STRL("connection"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("channel"), ZEND_ACC_PRIVATE TSRMLS_CC); - - zend_declare_property_stringl(this_ce, ZEND_STRL("name"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("type"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_bool(this_ce, ZEND_STRL("passive"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_bool(this_ce, ZEND_STRL("durable"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_bool(this_ce, ZEND_STRL("auto_delete"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_bool(this_ce, ZEND_STRL("internal"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("arguments"), ZEND_ACC_PRIVATE TSRMLS_CC); + this_ce = zend_register_internal_class(&ce); + + PHP_AMQP_DECLARE_TYPED_PROPERTY_OBJ(this_ce, "connection", ZEND_ACC_PRIVATE, AMQPConnection, 0); + PHP_AMQP_DECLARE_TYPED_PROPERTY_OBJ(this_ce, "channel", ZEND_ACC_PRIVATE, AMQPChannel, 0); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "name", ZEND_ACC_PRIVATE, IS_STRING, 1); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "type", ZEND_ACC_PRIVATE, IS_STRING, 1); + PHP_AMQP_DECLARE_TYPED_PROPERTY_WITH_DEFAULT(this_ce, "passive", ZEND_ACC_PRIVATE, _IS_BOOL, 0, ZVAL_FALSE); + PHP_AMQP_DECLARE_TYPED_PROPERTY_WITH_DEFAULT(this_ce, "durable", ZEND_ACC_PRIVATE, _IS_BOOL, 0, ZVAL_FALSE); + PHP_AMQP_DECLARE_TYPED_PROPERTY_WITH_DEFAULT(this_ce, "autoDelete", ZEND_ACC_PRIVATE, _IS_BOOL, 0, ZVAL_FALSE); + PHP_AMQP_DECLARE_TYPED_PROPERTY_WITH_DEFAULT(this_ce, "internal", ZEND_ACC_PRIVATE, _IS_BOOL, 0, ZVAL_FALSE); +#if PHP_VERSION_ID >= 80000 + PHP_AMQP_DECLARE_TYPED_PROPERTY_WITH_DEFAULT(this_ce, "arguments", ZEND_ACC_PRIVATE, IS_ARRAY, 0, ZVAL_EMPTY_ARRAY); +#else + PHP_AMQP_DECLARE_TYPED_PROPERTY_WITH_DEFAULT(this_ce, "arguments", ZEND_ACC_PRIVATE, IS_ARRAY, 0, ZVAL_NULL); +#endif return SUCCESS; } diff --git a/amqp_methods_handling.c b/amqp_methods_handling.c index 9a6c39f0..306cdbde 100644 --- a/amqp_methods_handling.c +++ b/amqp_methods_handling.c @@ -92,7 +92,7 @@ int php_amqp_handle_basic_return( amqp_connection_resource *resource, amqp_channel_t channel_id, amqp_channel_object *channel, - amqp_method_t *method TSRMLS_DC + amqp_method_t *method ) { amqp_rpc_reply_t ret; @@ -106,11 +106,11 @@ int php_amqp_handle_basic_return( ret = amqp_read_message(resource->connection_state, channel_id, &msg, 0); if (AMQP_RESPONSE_NORMAL != ret.reply_type) { - return php_amqp_connection_resource_error(ret, message, resource, channel_id TSRMLS_CC); + return php_amqp_connection_resource_error(ret, message, resource, channel_id); } if (channel->callbacks.basic_return.fci.size > 0) { - status = php_amqp_call_basic_return_callback(m, &msg, &channel->callbacks.basic_return TSRMLS_CC); + status = php_amqp_call_basic_return_callback(m, &msg, &channel->callbacks.basic_return); } else { zend_error( E_NOTICE, @@ -124,7 +124,7 @@ int php_amqp_handle_basic_return( return status; } -int php_amqp_call_basic_return_callback(amqp_basic_return_t *m, amqp_message_t *msg, amqp_callback_bucket *cb TSRMLS_DC) +int php_amqp_call_basic_return_callback(amqp_basic_return_t *m, amqp_message_t *msg, amqp_callback_bucket *cb) { zval params; zval basic_properties; @@ -143,13 +143,13 @@ int php_amqp_call_basic_return_callback(amqp_basic_return_t *m, amqp_message_t * add_next_index_stringl(¶ms, m->exchange.bytes, m->exchange.len); add_next_index_stringl(¶ms, m->routing_key.bytes, m->routing_key.len); - php_amqp_basic_properties_convert_to_zval(&msg->properties, &basic_properties TSRMLS_CC); + php_amqp_basic_properties_convert_to_zval(&msg->properties, &basic_properties); add_next_index_zval(¶ms, &basic_properties); Z_ADDREF_P(&basic_properties); add_next_index_stringl(¶ms, msg->body.bytes, msg->body.len); - status = php_amqp_call_callback_with_params(params, cb TSRMLS_CC); + status = php_amqp_call_callback_with_params(params, cb); zval_ptr_dtor(&basic_properties); @@ -161,7 +161,7 @@ int php_amqp_handle_basic_ack( amqp_connection_resource *resource, amqp_channel_t channel_id, amqp_channel_object *channel, - amqp_method_t *method TSRMLS_DC + amqp_method_t *method ) { int status = PHP_AMQP_RESOURCE_RESPONSE_OK; @@ -171,7 +171,7 @@ int php_amqp_handle_basic_ack( amqp_basic_ack_t *m = (amqp_basic_ack_t *) method->decoded; if (channel->callbacks.basic_ack.fci.size > 0) { - status = php_amqp_call_basic_ack_callback(m, &channel->callbacks.basic_ack TSRMLS_CC); + status = php_amqp_call_basic_ack_callback(m, &channel->callbacks.basic_ack); } else { zend_error( E_NOTICE, @@ -183,7 +183,7 @@ int php_amqp_handle_basic_ack( return status; } -int php_amqp_call_basic_ack_callback(amqp_basic_ack_t *m, amqp_callback_bucket *cb TSRMLS_DC) +int php_amqp_call_basic_ack_callback(amqp_basic_ack_t *m, amqp_callback_bucket *cb) { zval params; @@ -194,7 +194,7 @@ int php_amqp_call_basic_ack_callback(amqp_basic_ack_t *m, amqp_callback_bucket * add_next_index_long(¶ms, (zend_long) m->delivery_tag); add_next_index_bool(¶ms, m->multiple); - return php_amqp_call_callback_with_params(params, cb TSRMLS_CC); + return php_amqp_call_callback_with_params(params, cb); } int php_amqp_handle_basic_nack( @@ -202,7 +202,7 @@ int php_amqp_handle_basic_nack( amqp_connection_resource *resource, amqp_channel_t channel_id, amqp_channel_object *channel, - amqp_method_t *method TSRMLS_DC + amqp_method_t *method ) { int status = PHP_AMQP_RESOURCE_RESPONSE_OK; @@ -212,7 +212,7 @@ int php_amqp_handle_basic_nack( amqp_basic_nack_t *m = (amqp_basic_nack_t *) method->decoded; if (channel->callbacks.basic_nack.fci.size > 0) { - status = php_amqp_call_basic_nack_callback(m, &channel->callbacks.basic_nack TSRMLS_CC); + status = php_amqp_call_basic_nack_callback(m, &channel->callbacks.basic_nack); } else { zend_error( E_NOTICE, @@ -224,7 +224,7 @@ int php_amqp_handle_basic_nack( return status; } -int php_amqp_call_basic_nack_callback(amqp_basic_nack_t *m, amqp_callback_bucket *cb TSRMLS_DC) +int php_amqp_call_basic_nack_callback(amqp_basic_nack_t *m, amqp_callback_bucket *cb) { zval params; @@ -236,10 +236,10 @@ int php_amqp_call_basic_nack_callback(amqp_basic_nack_t *m, amqp_callback_bucket add_next_index_bool(¶ms, m->multiple); add_next_index_bool(¶ms, m->requeue); - return php_amqp_call_callback_with_params(params, cb TSRMLS_CC); + return php_amqp_call_callback_with_params(params, cb); } -int php_amqp_call_callback_with_params(zval params, amqp_callback_bucket *cb TSRMLS_DC) +int php_amqp_call_callback_with_params(zval params, amqp_callback_bucket *cb) { zval retval; zval *retval_ptr = &retval; @@ -249,12 +249,12 @@ int php_amqp_call_callback_with_params(zval params, amqp_callback_bucket *cb TSR ZVAL_NULL(&retval); /* Convert everything to be callable */ - zend_fcall_info_args(&cb->fci, ¶ms TSRMLS_CC); + zend_fcall_info_args(&cb->fci, ¶ms); /* Initialize the return value pointer */ cb->fci.retval = retval_ptr; - zend_call_function(&cb->fci, &cb->fcc TSRMLS_CC); + zend_call_function(&cb->fci, &cb->fcc); /* Check if user land function wants to bail */ if (EG(exception) || Z_TYPE_P(retval_ptr) == IS_FALSE) { diff --git a/amqp_methods_handling.h b/amqp_methods_handling.h index dc8ef58a..fe69ea07 100644 --- a/amqp_methods_handling.h +++ b/amqp_methods_handling.h @@ -47,33 +47,33 @@ int amqp_simple_wait_method_noblock( struct timeval *timeout ); -int php_amqp_call_callback_with_params(zval params, amqp_callback_bucket *cb TSRMLS_DC); +int php_amqp_call_callback_with_params(zval params, amqp_callback_bucket *cb); -int php_amqp_call_basic_return_callback(amqp_basic_return_t *m, amqp_message_t *msg, amqp_callback_bucket *cb TSRMLS_DC); +int php_amqp_call_basic_return_callback(amqp_basic_return_t *m, amqp_message_t *msg, amqp_callback_bucket *cb); int php_amqp_handle_basic_return( char **message, amqp_connection_resource *resource, amqp_channel_t channel_id, amqp_channel_object *channel, - amqp_method_t *method TSRMLS_DC + amqp_method_t *method ); -int php_amqp_call_basic_ack_callback(amqp_basic_ack_t *m, amqp_callback_bucket *cb TSRMLS_DC); +int php_amqp_call_basic_ack_callback(amqp_basic_ack_t *m, amqp_callback_bucket *cb); int php_amqp_handle_basic_ack( char **message, amqp_connection_resource *resource, amqp_channel_t channel_id, amqp_channel_object *channel, - amqp_method_t *method TSRMLS_DC + amqp_method_t *method ); -int php_amqp_call_basic_nack_callback(amqp_basic_nack_t *m, amqp_callback_bucket *cb TSRMLS_DC); +int php_amqp_call_basic_nack_callback(amqp_basic_nack_t *m, amqp_callback_bucket *cb); int php_amqp_handle_basic_nack( char **message, amqp_connection_resource *resource, amqp_channel_t channel_id, amqp_channel_object *channel, - amqp_method_t *method TSRMLS_DC + amqp_method_t *method ); #endif diff --git a/amqp_queue.c b/amqp_queue.c index f895474f..367fbbe8 100644 --- a/amqp_queue.c +++ b/amqp_queue.c @@ -56,6 +56,7 @@ #include "php_amqp.h" #include "amqp_envelope.h" +#include "amqp_envelope_exception.h" #include "amqp_connection.h" #include "amqp_channel.h" #include "amqp_connection.h" @@ -80,24 +81,24 @@ static PHP_METHOD(amqp_queue_class, __construct) zval *channelObj; amqp_channel_resource *channel_resource; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &channelObj, amqp_channel_class_entry) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &channelObj, amqp_channel_class_entry) == FAILURE) { return; } ZVAL_UNDEF(&arguments); array_init(&arguments); - zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("arguments"), &arguments TSRMLS_CC); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("arguments"), &arguments); zval_ptr_dtor(&arguments); channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(channelObj); PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not create queue."); - zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("channel"), channelObj TSRMLS_CC); + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("channel"), channelObj); zend_update_property( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connection"), - PHP_AMQP_READ_OBJ_PROP(amqp_channel_class_entry, channelObj, "connection") TSRMLS_CC + PHP_AMQP_READ_OBJ_PROP(amqp_channel_class_entry, channelObj, "connection") ); } /* }}} */ @@ -114,8 +115,7 @@ static PHP_METHOD(amqp_queue_class, getName) if (PHP_AMQP_READ_THIS_PROP_STRLEN("name") > 0) { PHP_AMQP_RETURN_THIS_PROP("name"); } else { - /* BC */ - RETURN_FALSE; + RETURN_NULL(); } } /* }}} */ @@ -128,7 +128,7 @@ static PHP_METHOD(amqp_queue_class, setName) char *name = NULL; size_t name_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) { return; } @@ -137,16 +137,13 @@ static PHP_METHOD(amqp_queue_class, setName) zend_throw_exception( amqp_queue_exception_class_entry, "Invalid queue name given, must be between 1 and 255 characters long.", - 0 TSRMLS_CC + 0 ); return; } /* Set the queue name */ - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("name"), name, name_len TSRMLS_CC); - - /* BC */ - RETURN_TRUE; + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("name"), name, name_len); } /* }}} */ @@ -173,7 +170,7 @@ static PHP_METHOD(amqp_queue_class, getFlags) flags |= AMQP_EXCLUSIVE; } - if (PHP_AMQP_READ_THIS_PROP_BOOL("auto_delete")) { + if (PHP_AMQP_READ_THIS_PROP_BOOL("autoDelete")) { flags |= AMQP_AUTODELETE; } @@ -189,40 +186,17 @@ static PHP_METHOD(amqp_queue_class, setFlags) zend_long flags; zend_bool flags_is_null = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l!", &flags, &flags_is_null) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l!", &flags, &flags_is_null) == FAILURE) { return; } /* Set the flags based on the bitmask we were given */ flags = flags ? flags & PHP_AMQP_QUEUE_FLAGS : flags; - zend_update_property_bool( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("passive"), - IS_PASSIVE(flags) TSRMLS_CC - ); - zend_update_property_bool( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("durable"), - IS_DURABLE(flags) TSRMLS_CC - ); - zend_update_property_bool( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("exclusive"), - IS_EXCLUSIVE(flags) TSRMLS_CC - ); - zend_update_property_bool( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("auto_delete"), - IS_AUTODELETE(flags) TSRMLS_CC - ); - - /* BC */ - RETURN_TRUE; + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("passive"), IS_PASSIVE(flags)); + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("durable"), IS_DURABLE(flags)); + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("exclusive"), IS_EXCLUSIVE(flags)); + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("autoDelete"), IS_AUTODELETE(flags)); } /* }}} */ @@ -236,12 +210,12 @@ static PHP_METHOD(amqp_queue_class, getArgument) char *key; size_t key_len; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &key, &key_len) == FAILURE) { return; } if ((tmp = zend_hash_str_find(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len)) == NULL) { - RETURN_FALSE; + RETURN_NULL(); } RETURN_ZVAL(tmp, 1, 0); @@ -253,20 +227,14 @@ static PHP_METHOD(amqp_queue_class, hasArgument) { zval rv; - zval *tmp = NULL; - char *key; size_t key_len; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &key, &key_len) == FAILURE) { return; } - if ((tmp = zend_hash_str_find(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len)) == NULL) { - RETURN_FALSE; - } - - RETURN_TRUE; + RETURN_BOOL(zend_hash_str_find(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len) != NULL); } /* }}} */ @@ -287,13 +255,11 @@ static PHP_METHOD(amqp_queue_class, setArguments) { zval *zvalArguments; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &zvalArguments) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a/", &zvalArguments) == FAILURE) { return; } - zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("arguments"), zvalArguments TSRMLS_CC); - - RETURN_TRUE; + zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("arguments"), zvalArguments); } /* }}} */ @@ -308,7 +274,7 @@ static PHP_METHOD(amqp_queue_class, setArgument) size_t key_len = 0; zval *value = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &key, &key_len, &value) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz", &key, &key_len, &value) == FAILURE) { return; } @@ -328,12 +294,10 @@ static PHP_METHOD(amqp_queue_class, setArgument) zend_throw_exception( amqp_exchange_exception_class_entry, "The value parameter must be of type NULL, int, double or string.", - 0 TSRMLS_CC + 0 ); return; } - - RETURN_TRUE; } /* }}} */ @@ -358,16 +322,16 @@ static PHP_METHOD(amqp_queue_class, declareQueue) channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not declare queue."); - arguments = php_amqp_type_convert_zval_to_amqp_table(PHP_AMQP_READ_THIS_PROP("arguments") TSRMLS_CC); + arguments = php_amqp_type_convert_zval_to_amqp_table(PHP_AMQP_READ_THIS_PROP("arguments")); amqp_queue_declare_ok_t *r = amqp_queue_declare( channel_resource->connection_resource->connection_state, channel_resource->channel_id, - amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), + amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STRLEN("name") ? PHP_AMQP_READ_THIS_PROP_STR("name") : ""), PHP_AMQP_READ_THIS_PROP_BOOL("passive"), PHP_AMQP_READ_THIS_PROP_BOOL("durable"), PHP_AMQP_READ_THIS_PROP_BOOL("exclusive"), - PHP_AMQP_READ_THIS_PROP_BOOL("auto_delete"), + PHP_AMQP_READ_THIS_PROP_BOOL("autoDelete"), *arguments ); @@ -376,18 +340,13 @@ static PHP_METHOD(amqp_queue_class, declareQueue) if (!r) { amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - php_amqp_error( - res, - &PHP_AMQP_G(error_message), - channel_resource->connection_resource, - channel_resource TSRMLS_CC - ); + php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource); php_amqp_zend_throw_exception( res, amqp_queue_exception_class_entry, PHP_AMQP_G(error_message), - PHP_AMQP_G(error_code) TSRMLS_CC + PHP_AMQP_G(error_code) ); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; @@ -397,7 +356,7 @@ static PHP_METHOD(amqp_queue_class, declareQueue) /* Set the queue name, in case it is an autogenerated queue name */ name = php_amqp_type_amqp_bytes_to_char(r->queue); - zend_update_property_string(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("name"), name TSRMLS_CC); + zend_update_property_string(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("name"), name); efree(name); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); @@ -426,7 +385,7 @@ static PHP_METHOD(amqp_queue_class, bind) amqp_table_t *arguments = NULL; if (zend_parse_parameters( - ZEND_NUM_ARGS() TSRMLS_CC, + ZEND_NUM_ARGS(), "s|s!a", &exchange_name, &exchange_name_len, @@ -441,13 +400,13 @@ static PHP_METHOD(amqp_queue_class, bind) PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not bind queue."); if (zvalArguments) { - arguments = php_amqp_type_convert_zval_to_amqp_table(zvalArguments TSRMLS_CC); + arguments = php_amqp_type_convert_zval_to_amqp_table(zvalArguments); } amqp_queue_bind( channel_resource->connection_resource->connection_state, channel_resource->channel_id, - amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), + amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STRLEN("name") ? PHP_AMQP_READ_THIS_PROP_STR("name") : ""), (exchange_name_len > 0 ? amqp_cstring_bytes(exchange_name) : amqp_empty_bytes), (keyname_len > 0 ? amqp_cstring_bytes(keyname) : amqp_empty_bytes), (arguments ? *arguments : amqp_empty_table) @@ -460,14 +419,12 @@ static PHP_METHOD(amqp_queue_class, bind) amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry TSRMLS_CC); + php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - - RETURN_TRUE; } /* }}} */ @@ -487,7 +444,7 @@ static PHP_METHOD(amqp_queue_class, get) zend_long flags = INI_INT("amqp.auto_ack") ? AMQP_AUTOACK : AMQP_NOPARAM; /* Parse out the method parameters */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &flags) == FAILURE) { return; } @@ -497,19 +454,19 @@ static PHP_METHOD(amqp_queue_class, get) amqp_rpc_reply_t res = amqp_basic_get( channel_resource->connection_resource->connection_state, channel_resource->channel_id, - amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), + amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STRLEN("name") ? PHP_AMQP_READ_THIS_PROP_STR("name") : ""), (AMQP_AUTOACK & flags) ? 1 : 0 ); if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry TSRMLS_CC); + php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } if (AMQP_BASIC_GET_EMPTY_METHOD == res.reply.id) { php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - RETURN_FALSE; + RETURN_NULL(); } assert(AMQP_BASIC_GET_OK_METHOD == res.reply.id); @@ -536,7 +493,7 @@ static PHP_METHOD(amqp_queue_class, get) ); if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry TSRMLS_CC); + php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); amqp_destroy_envelope(&envelope); return; @@ -544,7 +501,7 @@ static PHP_METHOD(amqp_queue_class, get) ZVAL_UNDEF(&message); - convert_amqp_envelope_to_zval(&envelope, &message TSRMLS_CC); + convert_amqp_envelope_to_zval(&envelope, &message); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); amqp_destroy_envelope(&envelope); @@ -578,32 +535,20 @@ static PHP_METHOD(amqp_queue_class, consume) size_t consumer_tag_len = 0; zend_long flags = INI_INT("amqp.auto_ack") ? AMQP_AUTOACK : AMQP_NOPARAM; - if (zend_parse_parameters( - ZEND_NUM_ARGS() TSRMLS_CC, - "|f!ls", - &fci, - &fci_cache, - &flags, - &consumer_tag, - &consumer_tag_len - ) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|f!ls", &fci, &fci_cache, &flags, &consumer_tag, &consumer_tag_len) == + FAILURE) { return; } zval *channel_zv = PHP_AMQP_READ_THIS_PROP("channel"); - zval *consumers = zend_read_property( - amqp_channel_class_entry, - PHP_AMQP_COMPAT_OBJ_P(channel_zv), - ZEND_STRL("consumers"), - 0, - &rv TSRMLS_CC - ); + zval *consumers = + zend_read_property(amqp_channel_class_entry, PHP_AMQP_COMPAT_OBJ_P(channel_zv), ZEND_STRL("consumers"), 0, &rv); if (IS_ARRAY != Z_TYPE_P(consumers)) { zend_throw_exception( amqp_queue_exception_class_entry, "Invalid channel consumers, forgot to call channel constructor?", - 0 TSRMLS_CC + 0 ); return; } @@ -615,12 +560,12 @@ static PHP_METHOD(amqp_queue_class, consume) if (!(AMQP_JUST_CONSUME & flags)) { /* Setup the consume */ - arguments = php_amqp_type_convert_zval_to_amqp_table(PHP_AMQP_READ_THIS_PROP("arguments") TSRMLS_CC); + arguments = php_amqp_type_convert_zval_to_amqp_table(PHP_AMQP_READ_THIS_PROP("arguments")); amqp_basic_consume_ok_t *r = amqp_basic_consume( channel_resource->connection_resource->connection_state, channel_resource->channel_id, - amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), + amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STRLEN("name") ? PHP_AMQP_READ_THIS_PROP_STR("name") : ""), (consumer_tag_len > 0 ? amqp_cstring_bytes(consumer_tag) : amqp_empty_bytes), /* Consumer tag */ (AMQP_NOLOCAL & flags) ? 1 : 0, /* No local */ (AMQP_AUTOACK & flags) ? 1 : 0, /* no_ack, aka AUTOACK */ @@ -633,18 +578,9 @@ static PHP_METHOD(amqp_queue_class, consume) if (!r) { amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - php_amqp_error( - res, - &PHP_AMQP_G(error_message), - channel_resource->connection_resource, - channel_resource TSRMLS_CC - ); + php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource); - zend_throw_exception( - amqp_queue_exception_class_entry, - PHP_AMQP_G(error_message), - PHP_AMQP_G(error_code) TSRMLS_CC - ); + zend_throw_exception(amqp_queue_exception_class_entry, PHP_AMQP_G(error_message), PHP_AMQP_G(error_code)); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } @@ -654,7 +590,7 @@ static PHP_METHOD(amqp_queue_class, consume) if (zend_hash_str_find(Z_ARRVAL_P(consumers), key, r->consumer_tag.len) != NULL) { // This should never happen as AMQP server guarantees that consumer tag is unique within channel - zend_throw_exception(amqp_exception_class_entry, "Duplicate consumer tag", 0 TSRMLS_CC); + zend_throw_exception(amqp_exception_class_entry, "Duplicate consumer tag", 0); efree(key); return; } @@ -671,9 +607,9 @@ static PHP_METHOD(amqp_queue_class, consume) zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("consumer_tag"), + ZEND_STRL("consumerTag"), (const char *) r->consumer_tag.bytes, - (size_t) r->consumer_tag.len TSRMLS_CC + (size_t) r->consumer_tag.len ); } @@ -688,7 +624,7 @@ static PHP_METHOD(amqp_queue_class, consume) double read_timeout = PHP_AMQP_READ_OBJ_PROP_DOUBLE( amqp_connection_class_entry, PHP_AMQP_READ_THIS_PROP("connection"), - "read_timeout" + "readTimeout" ); if (read_timeout > 0) { @@ -710,7 +646,7 @@ static PHP_METHOD(amqp_queue_class, consume) amqp_consume_message(channel_resource->connection_resource->connection_state, &envelope, tv_ptr, 0); if (AMQP_RESPONSE_LIBRARY_EXCEPTION == res.reply_type && AMQP_STATUS_TIMEOUT == res.library_error) { - zend_throw_exception(amqp_queue_exception_class_entry, "Consumer timeout exceed", 0 TSRMLS_CC); + zend_throw_exception(amqp_queue_exception_class_entry, "Consumer timeout exceed", 0); amqp_destroy_envelope(&envelope); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); @@ -729,10 +665,10 @@ static PHP_METHOD(amqp_queue_class, consume) channel_resource->connection_resource->is_connected = '\0'; /* Close connection with all its channels */ - php_amqp_disconnect_force(channel_resource->connection_resource TSRMLS_CC); + php_amqp_disconnect_force(channel_resource->connection_resource); } - php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry TSRMLS_CC); + php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry); amqp_destroy_envelope(&envelope); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); @@ -741,7 +677,7 @@ static PHP_METHOD(amqp_queue_class, consume) } ZVAL_UNDEF(&message); - convert_amqp_envelope_to_zval(&envelope, &message TSRMLS_CC); + convert_amqp_envelope_to_zval(&envelope, &message); current_channel_resource = channel_resource->connection_resource->slots[envelope.channel - 1]; @@ -751,7 +687,7 @@ static PHP_METHOD(amqp_queue_class, consume) res, amqp_queue_exception_class_entry, "Orphaned channel. Please, report a bug.", - 0 TSRMLS_CC + 0 ); amqp_destroy_envelope(&envelope); break; @@ -765,14 +701,14 @@ static PHP_METHOD(amqp_queue_class, consume) PHP_AMQP_COMPAT_OBJ_P(¤t_channel_zv), ZEND_STRL("consumers"), 0, - &rv TSRMLS_CC + &rv ); if (IS_ARRAY != Z_TYPE_P(consumers)) { zend_throw_exception( amqp_queue_exception_class_entry, "Invalid channel consumers, forgot to call channel constructor?", - 0 TSRMLS_CC + 0 ); amqp_destroy_envelope(&envelope); break; @@ -786,19 +722,19 @@ static PHP_METHOD(amqp_queue_class, consume) ZVAL_UNDEF(&exception); object_init_ex(&exception, amqp_envelope_exception_class_entry); zend_update_property_string( - zend_exception_get_default(TSRMLS_C), + zend_exception_get_default(), PHP_AMQP_COMPAT_OBJ_P(&exception), ZEND_STRL("message"), - "Orphaned envelope" TSRMLS_CC + "Orphaned envelope" ); zend_update_property( amqp_envelope_exception_class_entry, PHP_AMQP_COMPAT_OBJ_P(&exception), ZEND_STRL("envelope"), - &message TSRMLS_CC + &message ); - zend_throw_exception_object(&exception TSRMLS_CC); + zend_throw_exception_object(&exception); zval_ptr_dtor(&message); @@ -828,13 +764,13 @@ static PHP_METHOD(amqp_queue_class, consume) /* Convert everything to be callable */ - zend_fcall_info_args(&fci, ¶ms TSRMLS_CC); + zend_fcall_info_args(&fci, ¶ms); /* Initialize the return value pointer */ fci.retval = &retval; /* Call the function, and track the return value */ - if (zend_call_function(&fci, &fci_cache TSRMLS_CC) == SUCCESS && fci.retval) { + if (zend_call_function(&fci, &fci_cache) == SUCCESS && fci.retval) { RETVAL_ZVAL(&retval, 1, 1); } @@ -867,7 +803,7 @@ static PHP_METHOD(amqp_queue_class, ack) zend_long deliveryTag = 0; zend_long flags = AMQP_NOPARAM; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &deliveryTag, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l", &deliveryTag, &flags) == FAILURE) { return; } @@ -888,24 +824,17 @@ static PHP_METHOD(amqp_queue_class, ack) res.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; res.library_error = status; - php_amqp_error( - res, - &PHP_AMQP_G(error_message), - channel_resource->connection_resource, - channel_resource TSRMLS_CC - ); + php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource); php_amqp_zend_throw_exception( res, amqp_queue_exception_class_entry, PHP_AMQP_G(error_message), - PHP_AMQP_G(error_code) TSRMLS_CC + PHP_AMQP_G(error_code) ); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } - - RETURN_TRUE; } /* }}} */ @@ -922,7 +851,7 @@ static PHP_METHOD(amqp_queue_class, nack) zend_long deliveryTag = 0; zend_long flags = AMQP_NOPARAM; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &deliveryTag, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l", &deliveryTag, &flags) == FAILURE) { return; } @@ -944,24 +873,17 @@ static PHP_METHOD(amqp_queue_class, nack) res.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; res.library_error = status; - php_amqp_error( - res, - &PHP_AMQP_G(error_message), - channel_resource->connection_resource, - channel_resource TSRMLS_CC - ); + php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource); php_amqp_zend_throw_exception( res, amqp_queue_exception_class_entry, PHP_AMQP_G(error_message), - PHP_AMQP_G(error_code) TSRMLS_CC + PHP_AMQP_G(error_code) ); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } - - RETURN_TRUE; } /* }}} */ @@ -978,7 +900,7 @@ static PHP_METHOD(amqp_queue_class, reject) zend_long deliveryTag = 0; zend_long flags = AMQP_NOPARAM; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &deliveryTag, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l", &deliveryTag, &flags) == FAILURE) { return; } @@ -999,24 +921,17 @@ static PHP_METHOD(amqp_queue_class, reject) res.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; res.library_error = status; - php_amqp_error( - res, - &PHP_AMQP_G(error_message), - channel_resource->connection_resource, - channel_resource TSRMLS_CC - ); + php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource); php_amqp_zend_throw_exception( res, amqp_queue_exception_class_entry, PHP_AMQP_G(error_message), - PHP_AMQP_G(error_code) TSRMLS_CC + PHP_AMQP_G(error_code) ); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } - - RETURN_TRUE; } /* }}} */ @@ -1040,42 +955,32 @@ static PHP_METHOD(amqp_queue_class, purge) amqp_queue_purge_ok_t *r = amqp_queue_purge( channel_resource->connection_resource->connection_state, channel_resource->channel_id, - amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")) + amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STRLEN("name") ? PHP_AMQP_READ_THIS_PROP_STR("name") : "") ); if (!r) { amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - php_amqp_error( - res, - &PHP_AMQP_G(error_message), - channel_resource->connection_resource, - channel_resource TSRMLS_CC - ); + php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource); php_amqp_zend_throw_exception( res, amqp_queue_exception_class_entry, PHP_AMQP_G(error_message), - PHP_AMQP_G(error_code) TSRMLS_CC + PHP_AMQP_G(error_code) ); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } - /* long message_count = r->message_count; */ - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - /* RETURN_LONG(message_count) */; - - /* BC */ - RETURN_TRUE; + RETURN_LONG(r->message_count); } /* }}} */ -/* {{{ proto int AMQPQueue::cancel([string consumer_tag]); +/* {{{ proto int AMQPQueue::cancel([string consumerTag]); cancel queue to consumer */ static PHP_METHOD(amqp_queue_class, cancel) @@ -1087,26 +992,21 @@ static PHP_METHOD(amqp_queue_class, cancel) char *consumer_tag = NULL; size_t consumer_tag_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &consumer_tag, &consumer_tag_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &consumer_tag, &consumer_tag_len) == FAILURE) { return; } zval *channel_zv = PHP_AMQP_READ_THIS_PROP("channel"); - zval *consumers = zend_read_property( - amqp_channel_class_entry, - PHP_AMQP_COMPAT_OBJ_P(channel_zv), - ZEND_STRL("consumers"), - 0, - &rv TSRMLS_CC - ); + zval *consumers = + zend_read_property(amqp_channel_class_entry, PHP_AMQP_COMPAT_OBJ_P(channel_zv), ZEND_STRL("consumers"), 0, &rv); zend_bool previous_consumer_tag_exists = - (zend_bool) (IS_STRING == Z_TYPE_P(PHP_AMQP_READ_THIS_PROP("consumer_tag"))); + (zend_bool) (IS_STRING == Z_TYPE_P(PHP_AMQP_READ_THIS_PROP("consumerTag"))); if (IS_ARRAY != Z_TYPE_P(consumers)) { zend_throw_exception( amqp_queue_exception_class_entry, "Invalid channel consumers, forgot to call channel constructor?", - 0 TSRMLS_CC + 0 ); return; } @@ -1114,7 +1014,7 @@ static PHP_METHOD(amqp_queue_class, cancel) channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(channel_zv); PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not cancel queue."); - if (!consumer_tag_len && (!previous_consumer_tag_exists || !PHP_AMQP_READ_THIS_PROP_STRLEN("consumer_tag"))) { + if (!consumer_tag_len && (!previous_consumer_tag_exists || !PHP_AMQP_READ_THIS_PROP_STRLEN("consumerTag"))) { return; } @@ -1122,39 +1022,32 @@ static PHP_METHOD(amqp_queue_class, cancel) channel_resource->connection_resource->connection_state, channel_resource->channel_id, consumer_tag_len > 0 ? amqp_cstring_bytes(consumer_tag) - : amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("consumer_tag")) + : amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("consumerTag")) ); if (!r) { amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - php_amqp_error( - res, - &PHP_AMQP_G(error_message), - channel_resource->connection_resource, - channel_resource TSRMLS_CC - ); + php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource); php_amqp_zend_throw_exception( res, amqp_queue_exception_class_entry, PHP_AMQP_G(error_message), - PHP_AMQP_G(error_code) TSRMLS_CC + PHP_AMQP_G(error_code) ); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } if (!consumer_tag_len || - (previous_consumer_tag_exists && strcmp(consumer_tag, PHP_AMQP_READ_THIS_PROP_STR("consumer_tag")) == 0)) { - zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("consumer_tag") TSRMLS_CC); + (previous_consumer_tag_exists && strcmp(consumer_tag, PHP_AMQP_READ_THIS_PROP_STR("consumerTag")) == 0)) { + zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("consumerTag")); } zend_hash_str_del_ind(Z_ARRVAL_P(consumers), r->consumer_tag.bytes, r->consumer_tag.len); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - - RETURN_TRUE; } /* }}} */ @@ -1177,7 +1070,7 @@ static PHP_METHOD(amqp_queue_class, unbind) amqp_table_t *arguments = NULL; if (zend_parse_parameters( - ZEND_NUM_ARGS() TSRMLS_CC, + ZEND_NUM_ARGS(), "s|sa", &exchange_name, &exchange_name_len, @@ -1192,13 +1085,13 @@ static PHP_METHOD(amqp_queue_class, unbind) PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not unbind queue."); if (zvalArguments) { - arguments = php_amqp_type_convert_zval_to_amqp_table(zvalArguments TSRMLS_CC); + arguments = php_amqp_type_convert_zval_to_amqp_table(zvalArguments); } amqp_queue_unbind( channel_resource->connection_resource->connection_state, channel_resource->channel_id, - amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), + amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STRLEN("name") ? PHP_AMQP_READ_THIS_PROP_STR("name") : ""), (exchange_name_len > 0 ? amqp_cstring_bytes(exchange_name) : amqp_empty_bytes), (keyname_len > 0 ? amqp_cstring_bytes(keyname) : amqp_empty_bytes), (arguments ? *arguments : amqp_empty_table) @@ -1211,14 +1104,12 @@ static PHP_METHOD(amqp_queue_class, unbind) amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry TSRMLS_CC); + php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - - RETURN_TRUE; } /* }}} */ @@ -1236,7 +1127,7 @@ static PHP_METHOD(amqp_queue_class, delete) zend_long message_count; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &flags) == FAILURE) { return; } @@ -1246,7 +1137,7 @@ static PHP_METHOD(amqp_queue_class, delete) amqp_queue_delete_ok_t *r = amqp_queue_delete( channel_resource->connection_resource->connection_state, channel_resource->channel_id, - amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STR("name")), + amqp_cstring_bytes(PHP_AMQP_READ_THIS_PROP_STRLEN("name") ? PHP_AMQP_READ_THIS_PROP_STR("name") : ""), (AMQP_IFUNUSED & flags) ? 1 : 0, (AMQP_IFEMPTY & flags) ? 1 : 0 ); @@ -1254,18 +1145,13 @@ static PHP_METHOD(amqp_queue_class, delete) if (!r) { amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - php_amqp_error( - res, - &PHP_AMQP_G(error_message), - channel_resource->connection_resource, - channel_resource TSRMLS_CC - ); + php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource); php_amqp_zend_throw_exception( res, amqp_queue_exception_class_entry, PHP_AMQP_G(error_message), - PHP_AMQP_G(error_code) TSRMLS_CC + PHP_AMQP_G(error_code) ); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; @@ -1305,107 +1191,107 @@ static PHP_METHOD(amqp_queue_class, getConsumerTag) { zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("consumer_tag"); + PHP_AMQP_RETURN_THIS_PROP("consumerTag"); } /* }}} */ /* amqp_queue_class ARG_INFO definition */ ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class__construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_OBJ_INFO(0, amqp_channel, AMQPChannel, 0) + ZEND_ARG_OBJ_INFO(0, channel, AMQPChannel, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_getName, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_getName, ZEND_SEND_BY_VAL, 0, IS_STRING, 1) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_setName, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, queue_name) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_setName, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_getFlags, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_getFlags, ZEND_SEND_BY_VAL, 0, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_setFlags, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, flags) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_setFlags, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_getArgument, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, argument) + ZEND_ARG_TYPE_INFO(0, argumentName, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_getArguments, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_getArguments, ZEND_SEND_BY_VAL, 0, IS_ARRAY, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_setArgument, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 2) - ZEND_ARG_INFO(0, key) - ZEND_ARG_INFO(0, value) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_setArgument, ZEND_SEND_BY_VAL, 2, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, argumentName, IS_STRING, 0) + ZEND_ARG_INFO(0, argumentValue) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_hasArgument, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, key) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_hasArgument, ZEND_SEND_BY_VAL, 1, _IS_BOOL, 0) + ZEND_ARG_TYPE_INFO(0, argumentName, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_setArguments, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_setArguments, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) ZEND_ARG_ARRAY_INFO(0, arguments, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_declareQueue, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_declareQueue, ZEND_SEND_BY_VAL, 0, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_bind, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, exchange_name) - ZEND_ARG_INFO(0, routing_key) - ZEND_ARG_INFO(0, arguments) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_bind, ZEND_RETURN_VALUE, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, exchangeName, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, routingKey, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, arguments, IS_ARRAY, 0, "[]") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_get, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) - ZEND_ARG_INFO(0, flags) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_amqp_queue_class_get, ZEND_SEND_BY_VAL, 0, AMQPEnvelope, 1) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "AMQP_NOPARAM") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_consume, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, callback) - ZEND_ARG_INFO(0, flags) - ZEND_ARG_INFO(0, consumer_tag) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_consume, ZEND_SEND_BY_VAL, 0, IS_VOID, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, callback, IS_CALLABLE, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "AMQP_NOPARAM") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, consumerTag, IS_STRING, 1, "null") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_ack, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, delivery_tag) - ZEND_ARG_INFO(0, flags) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_ack, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, deliveryTag, IS_LONG, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "AMQP_NOPARAM") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_nack, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, delivery_tag) - ZEND_ARG_INFO(0, flags) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_nack, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, deliveryTag, IS_LONG, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "AMQP_NOPARAM") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_reject, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, delivery_tag) - ZEND_ARG_INFO(0, flags) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_reject, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, deliveryTag, IS_LONG, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "AMQP_NOPARAM") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_purge, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_purge, ZEND_SEND_BY_VAL, 0, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_cancel, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) - ZEND_ARG_INFO(0, consumer_tag) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_cancel, ZEND_SEND_BY_VAL, 0, IS_VOID, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, consumerTag, IS_STRING, 0, "\"\"") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_unbind, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) - ZEND_ARG_INFO(0, exchange_name) - ZEND_ARG_INFO(0, routing_key) - ZEND_ARG_INFO(0, arguments) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_unbind, ZEND_RETURN_VALUE, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, exchangeName, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, routingKey, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, arguments, IS_ARRAY, 0, "[]") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_delete, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) - ZEND_ARG_INFO(0, flags) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_delete, ZEND_SEND_BY_VAL, 0, IS_LONG, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "AMQP_NOPARAM") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_getChannel, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(arginfo_amqp_queue_class_getChannel, AMQPChannel, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_getConnection, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(arginfo_amqp_queue_class_getConnection, AMQPConnection, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_getConsumerTag, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_getConsumerTag, ZEND_SEND_BY_VAL, 0, IS_STRING, 1) ZEND_END_ARG_INFO() zend_function_entry amqp_queue_class_functions[] = { @@ -1424,6 +1310,7 @@ zend_function_entry amqp_queue_class_functions[] = { PHP_ME(amqp_queue_class, hasArgument, arginfo_amqp_queue_class_hasArgument, ZEND_ACC_PUBLIC) PHP_ME(amqp_queue_class, declareQueue, arginfo_amqp_queue_class_declareQueue, ZEND_ACC_PUBLIC) + PHP_MALIAS(amqp_queue_class, declare, declareQueue, arginfo_amqp_queue_class_declareQueue, ZEND_ACC_PUBLIC) PHP_ME(amqp_queue_class, bind, arginfo_amqp_queue_class_bind, ZEND_ACC_PUBLIC) PHP_ME(amqp_queue_class, get, arginfo_amqp_queue_class_get, ZEND_ACC_PUBLIC) @@ -1441,8 +1328,6 @@ zend_function_entry amqp_queue_class_functions[] = { PHP_ME(amqp_queue_class, getConnection, arginfo_amqp_queue_class_getConnection, ZEND_ACC_PUBLIC) PHP_ME(amqp_queue_class, getConsumerTag, arginfo_amqp_queue_class_getConsumerTag, ZEND_ACC_PUBLIC) - PHP_MALIAS(amqp_queue_class, declare, declareQueue, arginfo_amqp_queue_class_declareQueue, ZEND_ACC_PUBLIC | ZEND_ACC_DEPRECATED) - {NULL, NULL, NULL} }; @@ -1451,22 +1336,22 @@ PHP_MINIT_FUNCTION(amqp_queue) zend_class_entry ce; INIT_CLASS_ENTRY(ce, "AMQPQueue", amqp_queue_class_functions); - this_ce = zend_register_internal_class(&ce TSRMLS_CC); - - zend_declare_property_null(this_ce, ZEND_STRL("connection"), ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("channel"), ZEND_ACC_PRIVATE TSRMLS_CC); - - zend_declare_property_stringl(this_ce, ZEND_STRL("name"), "", 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_null(this_ce, ZEND_STRL("consumer_tag"), ZEND_ACC_PRIVATE TSRMLS_CC); - - zend_declare_property_bool(this_ce, ZEND_STRL("passive"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_bool(this_ce, ZEND_STRL("durable"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_bool(this_ce, ZEND_STRL("exclusive"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); + this_ce = zend_register_internal_class(&ce); + + PHP_AMQP_DECLARE_TYPED_PROPERTY_OBJ(this_ce, "connection", ZEND_ACC_PRIVATE, AMQPConnection, 0); + PHP_AMQP_DECLARE_TYPED_PROPERTY_OBJ(this_ce, "channel", ZEND_ACC_PRIVATE, AMQPChannel, 0); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "name", ZEND_ACC_PRIVATE, IS_STRING, 1); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "consumerTag", ZEND_ACC_PRIVATE, IS_STRING, 1); + PHP_AMQP_DECLARE_TYPED_PROPERTY_WITH_DEFAULT(this_ce, "passive", ZEND_ACC_PRIVATE, _IS_BOOL, 0, ZVAL_FALSE); + PHP_AMQP_DECLARE_TYPED_PROPERTY_WITH_DEFAULT(this_ce, "durable", ZEND_ACC_PRIVATE, _IS_BOOL, 0, ZVAL_FALSE); + PHP_AMQP_DECLARE_TYPED_PROPERTY_WITH_DEFAULT(this_ce, "exclusive", ZEND_ACC_PRIVATE, _IS_BOOL, 0, ZVAL_FALSE); /* By default, the auto_delete flag should be set */ - zend_declare_property_bool(this_ce, ZEND_STRL("auto_delete"), 1, ZEND_ACC_PRIVATE TSRMLS_CC); - - - zend_declare_property_null(this_ce, ZEND_STRL("arguments"), ZEND_ACC_PRIVATE TSRMLS_CC); + PHP_AMQP_DECLARE_TYPED_PROPERTY_WITH_DEFAULT(this_ce, "autoDelete", ZEND_ACC_PRIVATE, _IS_BOOL, 0, ZVAL_TRUE); +#if PHP_VERSION_ID >= 80000 + PHP_AMQP_DECLARE_TYPED_PROPERTY_WITH_DEFAULT(this_ce, "arguments", ZEND_ACC_PRIVATE, IS_ARRAY, 0, ZVAL_EMPTY_ARRAY); +#else + PHP_AMQP_DECLARE_TYPED_PROPERTY_WITH_DEFAULT(this_ce, "arguments", ZEND_ACC_PRIVATE, IS_ARRAY, 0, ZVAL_NULL); +#endif return SUCCESS; } diff --git a/amqp_timestamp.c b/amqp_timestamp.c index c147193b..de15834d 100644 --- a/amqp_timestamp.c +++ b/amqp_timestamp.c @@ -33,23 +33,23 @@ zend_class_entry *amqp_timestamp_class_entry; #define this_ce amqp_timestamp_class_entry -static const double AMQP_TIMESTAMP_MAX = 0xFFFFFFFFFFFFFFFF; +static const double AMQP_TIMESTAMP_MAX = 0xFFFFFFFFFFFFFFFFp0; static const double AMQP_TIMESTAMP_MIN = 0; -/* {{{ proto AMQPTimestamp::__construct(string $timestamp) +/* {{{ proto AMQPTimestamp::__construct(float $timestamp) */ static PHP_METHOD(amqp_timestamp_class, __construct) { double timestamp; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", ×tamp) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "d", ×tamp) == FAILURE) { return; } if (timestamp < AMQP_TIMESTAMP_MIN) { zend_throw_exception_ex( amqp_value_exception_class_entry, - 0 TSRMLS_CC, + 0, "The timestamp parameter must be greater than %0.f.", AMQP_TIMESTAMP_MIN ); @@ -59,22 +59,19 @@ static PHP_METHOD(amqp_timestamp_class, __construct) if (timestamp > AMQP_TIMESTAMP_MAX) { zend_throw_exception_ex( amqp_value_exception_class_entry, - 0 TSRMLS_CC, + 0, "The timestamp parameter must be less than %0.f.", AMQP_TIMESTAMP_MAX ); return; } - zend_string *str; - str = _php_math_number_format_ex(timestamp, 0, "", 0, "", 0); - zend_update_property_str(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("timestamp"), str); - zend_string_delref(str); + zend_update_property_double(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("timestamp"), floor(timestamp)); } /* }}} */ -/* {{{ proto string AMQPTimestamp::getTimestamp() +/* {{{ proto float AMQPTimestamp::getTimestamp() Get timestamp */ static PHP_METHOD(amqp_timestamp_class, getTimestamp) { @@ -93,28 +90,20 @@ static PHP_METHOD(amqp_timestamp_class, __toString) zval rv; PHP_AMQP_NOPARAMS(); - PHP_AMQP_RETURN_THIS_PROP("timestamp"); + zval *timestamp = zend_read_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("timestamp"), 0, &rv); + + RETURN_NEW_STR(_php_math_number_format_ex(Z_DVAL_P(timestamp), 0, "", 0, "", 0)); } /* }}} */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_timestamp_class_construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) - ZEND_ARG_INFO(0, timestamp) +ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_timestamp_class_construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) + ZEND_ARG_TYPE_INFO(0, timestamp, IS_DOUBLE, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_timestamp_class_getTimestamp, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_timestamp_class_getTimestamp, ZEND_SEND_BY_VAL, 0, IS_DOUBLE, 0) ZEND_END_ARG_INFO() -#if PHP_MAJOR_VERSION < 8 -ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_timestamp_class_toString, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) -#else -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX( - arginfo_amqp_timestamp_class_toString, - ZEND_SEND_BY_VAL, - ZEND_RETURN_VALUE, - IS_STRING, - 0 -) -#endif +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_timestamp_class_toString, ZEND_SEND_BY_VAL, 0, IS_STRING, 0) ZEND_END_ARG_INFO() zend_function_entry amqp_timestamp_class_functions[] = { @@ -129,20 +118,15 @@ zend_function_entry amqp_timestamp_class_functions[] = { PHP_MINIT_FUNCTION(amqp_timestamp) { zend_class_entry ce; - char min[21], max[21]; - int min_len, max_len; INIT_CLASS_ENTRY(ce, "AMQPTimestamp", amqp_timestamp_class_functions); - this_ce = zend_register_internal_class(&ce TSRMLS_CC); + this_ce = zend_register_internal_class(&ce); this_ce->ce_flags = this_ce->ce_flags | ZEND_ACC_FINAL; - zend_declare_property_null(this_ce, ZEND_STRL("timestamp"), ZEND_ACC_PRIVATE TSRMLS_CC); - - max_len = snprintf(max, sizeof(max), "%.0f", AMQP_TIMESTAMP_MAX); - zend_declare_class_constant_stringl(this_ce, ZEND_STRL("MAX"), max, max_len TSRMLS_CC); + PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "timestamp", ZEND_ACC_PRIVATE, IS_DOUBLE, 0); - min_len = snprintf(min, sizeof(min), "%.0f", AMQP_TIMESTAMP_MIN); - zend_declare_class_constant_stringl(this_ce, ZEND_STRL("MIN"), min, min_len TSRMLS_CC); + zend_declare_class_constant_double(this_ce, ZEND_STRL("MAX"), AMQP_TIMESTAMP_MAX); + zend_declare_class_constant_double(this_ce, ZEND_STRL("MIN"), AMQP_TIMESTAMP_MIN); return SUCCESS; } diff --git a/amqp_type.c b/amqp_type.c index 68476f7a..81cda00e 100644 --- a/amqp_type.c +++ b/amqp_type.c @@ -78,11 +78,7 @@ char *php_amqp_type_amqp_bytes_to_char(amqp_bytes_t bytes) return res; } -void php_amqp_type_internal_convert_zval_array( - zval *php_array, - amqp_field_value_t **field, - zend_bool allow_int_keys TSRMLS_DC -) +void php_amqp_type_internal_convert_zval_array(zval *php_array, amqp_field_value_t **field, zend_bool allow_int_keys) { HashTable *ht; zend_string *key; @@ -100,17 +96,17 @@ void php_amqp_type_internal_convert_zval_array( if (is_amqp_array) { (*field)->kind = AMQP_FIELD_KIND_ARRAY; - php_amqp_type_internal_convert_zval_to_amqp_array(php_array, &(*field)->value.array TSRMLS_CC); + php_amqp_type_internal_convert_zval_to_amqp_array(php_array, &(*field)->value.array); } else { (*field)->kind = AMQP_FIELD_KIND_TABLE; - php_amqp_type_internal_convert_zval_to_amqp_table(php_array, &(*field)->value.table, allow_int_keys TSRMLS_CC); + php_amqp_type_internal_convert_zval_to_amqp_table(php_array, &(*field)->value.table, allow_int_keys); } } void php_amqp_type_internal_convert_zval_to_amqp_table( zval *php_array, amqp_table_t *amqp_table, - zend_bool allow_int_keys TSRMLS_DC + zend_bool allow_int_keys ) { HashTable *ht; @@ -140,7 +136,7 @@ void php_amqp_type_internal_convert_zval_to_amqp_table( key = str; } else { /* Skip things that are not strings */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Ignoring non-string header field '%lu'", index); + php_error_docref(NULL, E_WARNING, "Ignoring non-string header field '%lu'", index); continue; } @@ -153,7 +149,7 @@ void php_amqp_type_internal_convert_zval_to_amqp_table( table_entry = &amqp_table->entries[amqp_table->num_entries++]; field = &table_entry->value; - if (!php_amqp_type_internal_convert_php_to_amqp_field_value(value, &field, key TSRMLS_CC)) { + if (!php_amqp_type_internal_convert_php_to_amqp_field_value(value, &field, key)) { /* Reset entries counter back */ amqp_table->num_entries--; @@ -165,7 +161,7 @@ void php_amqp_type_internal_convert_zval_to_amqp_table( ZEND_HASH_FOREACH_END(); } -void php_amqp_type_internal_convert_zval_to_amqp_array(zval *zval_arguments, amqp_array_t *arguments TSRMLS_DC) +void php_amqp_type_internal_convert_zval_to_amqp_array(zval *zval_arguments, amqp_array_t *arguments) { HashTable *ht; @@ -183,7 +179,7 @@ void php_amqp_type_internal_convert_zval_to_amqp_array(zval *zval_arguments, amq ZEND_HASH_FOREACH_STR_KEY_VAL(ht, zkey, value) amqp_field_value_t *field = &arguments->entries[arguments->num_entries++]; - if (!php_amqp_type_internal_convert_php_to_amqp_field_value(value, &field, ZSTR_VAL(zkey) TSRMLS_CC)) { + if (!php_amqp_type_internal_convert_php_to_amqp_field_value(value, &field, ZSTR_VAL(zkey))) { /* Reset entries counter back */ arguments->num_entries--; @@ -192,11 +188,7 @@ void php_amqp_type_internal_convert_zval_to_amqp_array(zval *zval_arguments, amq ZEND_HASH_FOREACH_END (); } -zend_bool php_amqp_type_internal_convert_php_to_amqp_field_value( - zval *value, - amqp_field_value_t **fieldPtr, - char *key TSRMLS_DC -) +zend_bool php_amqp_type_internal_convert_php_to_amqp_field_value(zval *value, amqp_field_value_t **fieldPtr, char *key) { zend_bool result; char type[16]; @@ -234,13 +226,13 @@ zend_bool php_amqp_type_internal_convert_php_to_amqp_field_value( break; case IS_ARRAY: - php_amqp_type_internal_convert_zval_array(value, &field, 1 TSRMLS_CC); + php_amqp_type_internal_convert_zval_array(value, &field, 1); break; case IS_NULL: field->kind = AMQP_FIELD_KIND_VOID; break; case IS_OBJECT: - if (instanceof_function(Z_OBJCE_P(value), amqp_timestamp_class_entry TSRMLS_CC)) { + if (instanceof_function(Z_OBJCE_P(value), amqp_timestamp_class_entry)) { zval result_zv; zend_call_method_with_0_params( @@ -252,12 +244,12 @@ zend_bool php_amqp_type_internal_convert_php_to_amqp_field_value( ); field->kind = AMQP_FIELD_KIND_TIMESTAMP; - field->value.u64 = strtoimax(Z_STRVAL(result_zv), NULL, 10); + field->value.u64 = Z_DVAL(result_zv); zval_ptr_dtor(&result_zv); break; - } else if (instanceof_function(Z_OBJCE_P(value), amqp_decimal_class_entry TSRMLS_CC)) { + } else if (instanceof_function(Z_OBJCE_P(value), amqp_decimal_class_entry)) { field->kind = AMQP_FIELD_KIND_DECIMAL; zval result_zv; @@ -296,13 +288,7 @@ zend_bool php_amqp_type_internal_convert_php_to_amqp_field_value( break; } - php_error_docref( - NULL TSRMLS_CC, - E_WARNING, - "Ignoring field '%s' due to unsupported value type (%s)", - key, - type - ); + php_error_docref(NULL, E_WARNING, "Ignoring field '%s' due to unsupported value type (%s)", key, type); result = 0; break; } @@ -310,13 +296,13 @@ zend_bool php_amqp_type_internal_convert_php_to_amqp_field_value( return result; } -amqp_table_t *php_amqp_type_convert_zval_to_amqp_table(zval *php_array TSRMLS_DC) +amqp_table_t *php_amqp_type_convert_zval_to_amqp_table(zval *php_array) { amqp_table_t *amqp_table; /* In setArguments, we are overwriting all the existing values */ amqp_table = (amqp_table_t *) emalloc(sizeof(amqp_table_t)); - php_amqp_type_internal_convert_zval_to_amqp_table(php_array, amqp_table, 0 TSRMLS_CC); + php_amqp_type_internal_convert_zval_to_amqp_table(php_array, amqp_table, 0); return amqp_table; } diff --git a/amqp_type.h b/amqp_type.h index e0f4fe09..16505bc1 100644 --- a/amqp_type.h +++ b/amqp_type.h @@ -38,23 +38,15 @@ PHP_MINIT_FUNCTION(amqp_type); char *php_amqp_type_amqp_bytes_to_char(amqp_bytes_t bytes); amqp_bytes_t php_amqp_type_char_to_amqp_long(char const *cstr, size_t len); -amqp_table_t *php_amqp_type_convert_zval_to_amqp_table(zval *php_array TSRMLS_DC); +amqp_table_t *php_amqp_type_convert_zval_to_amqp_table(zval *php_array); void php_amqp_type_free_amqp_table(amqp_table_t *object); /** Internal functions */ -zend_bool php_amqp_type_internal_convert_php_to_amqp_field_value( - zval *value, - amqp_field_value_t **fieldPtr, - char *key TSRMLS_DC -); -void php_amqp_type_internal_convert_zval_array( - zval *php_array, - amqp_field_value_t **field, - zend_bool allow_int_keys TSRMLS_DC -); +zend_bool php_amqp_type_internal_convert_php_to_amqp_field_value(zval *value, amqp_field_value_t **fieldPtr, char *key); +void php_amqp_type_internal_convert_zval_array(zval *php_array, amqp_field_value_t **field, zend_bool allow_int_keys); void php_amqp_type_internal_convert_zval_to_amqp_table( zval *php_array, amqp_table_t *amqp_table, - zend_bool allow_int_keys TSRMLS_DC + zend_bool allow_int_keys ); -void php_amqp_type_internal_convert_zval_to_amqp_array(zval *php_array, amqp_array_t *amqp_array TSRMLS_DC); +void php_amqp_type_internal_convert_zval_to_amqp_array(zval *php_array, amqp_array_t *amqp_array); diff --git a/composer.json b/composer.json index 545ec1d1..86c911e3 100644 --- a/composer.json +++ b/composer.json @@ -18,8 +18,11 @@ } ], "require": { - "php": ">=7.1", + "php": ">=7.4", "ext-dom": "*", "ext-simplexml": "*" + }, + "require-dev": { + "ext-json": "*" } } diff --git a/config.m4 b/config.m4 index cdbba9cf..873d13d1 100644 --- a/config.m4 +++ b/config.m4 @@ -7,7 +7,7 @@ PHP_ARG_WITH(librabbitmq-dir, for amqp, [ --with-librabbitmq-dir[=DIR] Set the path to librabbitmq install prefix.], yes) dnl Set test wrapper binary to ignore any local ini settings -PHP_EXECUTABLE="$PWD/php-test-bin" +PHP_EXECUTABLE="\$(top_srcdir)/php-test-bin" if test "$PHP_AMQP" != "no"; then AC_MSG_CHECKING([for supported PHP versions]) @@ -158,7 +158,7 @@ if test "$PHP_AMQP" != "no"; then PHP_SUBST(AMQP_SHARED_LIBADD) - AMQP_SOURCES="amqp.c amqp_type.c amqp_exchange.c amqp_queue.c amqp_connection.c amqp_connection_resource.c amqp_channel.c amqp_envelope.c amqp_basic_properties.c amqp_methods_handling.c amqp_timestamp.c amqp_decimal.c" + AMQP_SOURCES="amqp.c amqp_envelope_exception.c amqp_type.c amqp_exchange.c amqp_queue.c amqp_connection.c amqp_connection_resource.c amqp_channel.c amqp_envelope.c amqp_basic_properties.c amqp_methods_handling.c amqp_timestamp.c amqp_decimal.c" PHP_NEW_EXTENSION(amqp, $AMQP_SOURCES, $ext_shared) fi diff --git a/config.w32 b/config.w32 index b9d32299..6d1111d5 100644 --- a/config.w32 +++ b/config.w32 @@ -4,7 +4,7 @@ if (PHP_AMQP != "no") { if (CHECK_HEADER_ADD_INCLUDE("amqp.h", "CFLAGS_AMQP", PHP_PHP_BUILD + "\\include;" + PHP_PHP_BUILD + "\\include\\librabbitmq;" + PHP_AMQP) && CHECK_LIB("rabbitmq.4.lib", "amqp", PHP_PHP_BUILD + "\\lib;" + PHP_AMQP)) { // ADD_FLAG("CFLAGS_AMQP", "/D HAVE_AMQP_GETSOCKOPT"); - EXTENSION('amqp', 'amqp.c amqp_type.c amqp_exchange.c amqp_queue.c amqp_connection.c amqp_connection_resource.c amqp_channel.c amqp_envelope.c amqp_basic_properties.c amqp_methods_handling.c amqp_timestamp.c amqp_decimal.c'); + EXTENSION('amqp', 'amqp.c amqp_envelope_exception.c amqp_type.c amqp_exchange.c amqp_queue.c amqp_connection.c amqp_connection_resource.c amqp_channel.c amqp_envelope.c amqp_basic_properties.c amqp_methods_handling.c amqp_timestamp.c amqp_decimal.c'); AC_DEFINE('HAVE_AMQP', 1); } else { WARNING("amqp not enabled; libraries and headers not found"); diff --git a/package.xml b/package.xml index a8c42e60..ce726446 100644 --- a/package.xml +++ b/package.xml @@ -25,8 +25,8 @@ 2021-12-01 - 1.12.0dev - 1.12.0dev + 2.0.0dev + 2.0.0dev devel @@ -59,6 +59,8 @@ https://github.com/php-amqp/php-amqp/compare/v1.11.0...latest + + diff --git a/php_amqp.h b/php_amqp.h index 7f32cb45..f2965a64 100644 --- a/php_amqp.h +++ b/php_amqp.h @@ -30,7 +30,7 @@ /* True global resources - no need for thread safety here */ extern zend_class_entry *amqp_exception_class_entry, *amqp_connection_exception_class_entry, *amqp_channel_exception_class_entry, *amqp_exchange_exception_class_entry, *amqp_queue_exception_class_entry, - *amqp_envelope_exception_class_entry, *amqp_value_exception_class_entry; + *amqp_value_exception_class_entry; typedef struct _amqp_connection_resource amqp_connection_resource; @@ -40,11 +40,6 @@ typedef struct _amqp_channel_resource amqp_channel_resource; typedef struct _amqp_channel_callbacks amqp_channel_callbacks; typedef struct _amqp_callback_bucket amqp_callback_bucket; -#if PHP_VERSION_ID < 50600 - // should never get her, but just in case - #error PHP >= 5.6 required -#endif - #if HAVE_LIBRABBITMQ_NEW_LAYOUT #include #else @@ -64,23 +59,72 @@ extern zend_module_entry amqp_module_entry; #include "TSRM.h" #endif -/* Small change to let it build after a major internal change for php8.0 - * More info: - * https://github.com/php/php-src/blob/php-8.0.0alpha3/UPGRADING.INTERNALS#L47 - */ -#if PHP_MAJOR_VERSION >= 8 - #define TSRMLS_DC - #define TSRMLS_D - #define TSRMLS_CC - #define TSRMLS_C + +#if PHP_VERSION_ID >= 80000 #define PHP_AMQP_COMPAT_OBJ_P(zv) Z_OBJ_P(zv) + #define PHP_AMQP_DECLARE_PROPERTY_TYPE(type, nullable) (zend_type) ZEND_TYPE_INIT_CODE(type, nullable, 0) + #define PHP_AMQP_DECLARE_PROPERTY_OBJ_TYPE(class_name, nullable) \ + (zend_type) ZEND_TYPE_INIT_CLASS(class_name, nullable, 0) #else #define PHP_AMQP_COMPAT_OBJ_P(zv) (zv) + #define ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(pass_by_ref, name, type_hint, allow_null, default_value) \ + ZEND_ARG_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) + #define PHP_AMQP_DECLARE_PROPERTY_TYPE(type, nullable) ZEND_TYPE_ENCODE(type, nullable) + #define PHP_AMQP_DECLARE_PROPERTY_OBJ_TYPE(class_name, nullable) ZEND_TYPE_ENCODE_CLASS(class_name, nullable) #endif #if PHP_VERSION_ID < 80200 #define zend_ini_parse_quantity_warn(v, name) (zend_atol(ZSTR_VAL(v), ZSTR_LEN(v))) #endif +#define PHP_AMQP_NULLABLE_DEFAULT_INIT(val, nullable) \ + zval val; \ + if (nullable) { \ + ZVAL_NULL(&val); \ + } else { \ + ZVAL_UNDEF(&val); \ + } +#define PHP_AMQP_DECLARE_TYPED_PROPERTY_ZVAL(class_entry, name, flags, type_info, val) \ + { \ + zend_string *__name = zend_string_init(ZEND_STRL(name), 1); \ + zend_declare_typed_property(class_entry, __name, &(val), flags, NULL, type_info); \ + zend_string_release(__name); \ + } +#define PHP_AMQP_DECLARE_TYPED_PROPERTY(class_entry, name, flags, type, nullable) \ + { \ + PHP_AMQP_NULLABLE_DEFAULT_INIT(__val, nullable); \ + PHP_AMQP_DECLARE_TYPED_PROPERTY_ZVAL( \ + class_entry, \ + name, \ + flags, \ + PHP_AMQP_DECLARE_PROPERTY_TYPE(type, nullable), \ + __val \ + ) \ + } +#define PHP_AMQP_DECLARE_TYPED_PROPERTY_WITH_DEFAULT(class_entry, name, flags, type, nullable, init) \ + { \ + zval __val; \ + init(&__val); \ + PHP_AMQP_DECLARE_TYPED_PROPERTY_ZVAL( \ + class_entry, \ + name, \ + flags, \ + PHP_AMQP_DECLARE_PROPERTY_TYPE(type, nullable), \ + __val \ + ) \ + } +#define PHP_AMQP_DECLARE_TYPED_PROPERTY_OBJ(class_entry, name, flags, class_name, nullable) \ + { \ + PHP_AMQP_NULLABLE_DEFAULT_INIT(__val, nullable); \ + zend_string *__class_name = zend_string_init(ZEND_STRL(#class_name), 1); \ + PHP_AMQP_DECLARE_TYPED_PROPERTY_ZVAL( \ + class_entry, \ + name, \ + flags, \ + PHP_AMQP_DECLARE_PROPERTY_OBJ_TYPE(__class_name, nullable), \ + __val \ + ) \ + } + #include "amqp_connection_resource.h" #define AMQP_NOPARAM 0 @@ -176,7 +220,7 @@ struct _amqp_connection_object { #define DEFAULT_PREFETCH_SIZE "0" #define DEFAULT_GLOBAL_PREFETCH_COUNT "0" #define DEFAULT_GLOBAL_PREFETCH_SIZE "0" -#define DEFAULT_SASL_METHOD "0" +#define DEFAULT_SASL_METHOD AMQP_SASL_METHOD_PLAIN /* Usually, default is 0 which means 65535, but underlying rabbitmq-c library pool allocates minimal pool for each channel, * so it takes a lot of memory to keep all that channels. Even after channel closing that buffer still keep memory allocation. @@ -224,10 +268,6 @@ struct _amqp_connection_object { #define IS_EXCLUSIVE(bitmask) (AMQP_EXCLUSIVE & (bitmask)) ? 1 : 0 #define IS_AUTODELETE(bitmask) (AMQP_AUTODELETE & (bitmask)) ? 1 : 0 #define IS_INTERNAL(bitmask) (AMQP_INTERNAL & (bitmask)) ? 1 : 0 -#define IS_NOWAIT(bitmask) \ - (AMQP_NOWAIT & (bitmask)) \ - ? 1 \ - : 0 /* NOTE: always 0 in rabbitmq-c internals, so don't use it unless you are clearly understand aftermath*/ #define PHP_AMQP_NOPARAMS() \ if (zend_parse_parameters_none() == FAILURE) { \ @@ -235,17 +275,17 @@ struct _amqp_connection_object { } #define PHP_AMQP_RETURN_THIS_PROP(prop_name) \ - zval *_zv = zend_read_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(prop_name), 0, &rv TSRMLS_CC); \ + zval *_zv = zend_read_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(prop_name), 0, &rv); \ RETURN_ZVAL(_zv, 1, 0); #define PHP_AMQP_READ_OBJ_PROP(cls, obj, name) \ - zend_read_property((cls), PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL(name), 0, &rv TSRMLS_CC) + zend_read_property((cls), PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL(name), 0, &rv) #define PHP_AMQP_READ_OBJ_PROP_DOUBLE(cls, obj, name) Z_DVAL_P(PHP_AMQP_READ_OBJ_PROP((cls), (obj), (name))) #define PHP_AMQP_READ_THIS_PROP_CE(name, ce) \ - zend_read_property((ce), PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(name), 0, &rv TSRMLS_CC) + zend_read_property((ce), PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(name), 0, &rv) #define PHP_AMQP_READ_THIS_PROP(name) \ - zend_read_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(name), 0, &rv TSRMLS_CC) + zend_read_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL(name), 0, &rv) #define PHP_AMQP_READ_THIS_PROP_BOOL(name) Z_TYPE_P(PHP_AMQP_READ_THIS_PROP(name)) == IS_TRUE #define PHP_AMQP_READ_THIS_PROP_STR(name) Z_STRVAL_P(PHP_AMQP_READ_THIS_PROP(name)) #define PHP_AMQP_READ_THIS_PROP_STRLEN(name) \ @@ -277,7 +317,7 @@ static inline amqp_channel_object *php_amqp_channel_object_fetch(zend_object *ob #define PHP_AMQP_VERIFY_CONNECTION_ERROR(error, reason) \ char verify_connection_error_tmp[255]; \ snprintf(verify_connection_error_tmp, 255, "%s %s", error, reason); \ - zend_throw_exception(amqp_connection_exception_class_entry, verify_connection_error_tmp, 0 TSRMLS_CC); \ + zend_throw_exception(amqp_connection_exception_class_entry, verify_connection_error_tmp, 0); \ return; #define PHP_AMQP_VERIFY_CONNECTION(connection, error) \ @@ -291,7 +331,7 @@ static inline amqp_channel_object *php_amqp_channel_object_fetch(zend_object *ob #define PHP_AMQP_VERIFY_CHANNEL_ERROR(error, reason) \ char verify_channel_error_tmp[255]; \ snprintf(verify_channel_error_tmp, 255, "%s %s", error, reason); \ - zend_throw_exception(amqp_channel_exception_class_entry, verify_channel_error_tmp, 0 TSRMLS_CC); \ + zend_throw_exception(amqp_channel_exception_class_entry, verify_channel_error_tmp, 0); \ return; #define PHP_AMQP_VERIFY_CHANNEL_RESOURCE(resource, error) \ @@ -321,12 +361,8 @@ static inline amqp_channel_object *php_amqp_channel_object_fetch(zend_object *ob #define PHP_AMQP_MAYBE_ERROR(res, channel_resource) \ ((AMQP_RESPONSE_NORMAL != (res).reply_type) && \ - PHP_AMQP_RESOURCE_RESPONSE_OK != php_amqp_error( \ - res, \ - &PHP_AMQP_G(error_message), \ - (channel_resource)->connection_resource, \ - (channel_resource) TSRMLS_CC \ - )) + PHP_AMQP_RESOURCE_RESPONSE_OK != \ + php_amqp_error(res, &PHP_AMQP_G(error_message), (channel_resource)->connection_resource, (channel_resource))) #define PHP_AMQP_MAYBE_ERROR_RECOVERABLE(res, channel_resource) \ ((AMQP_RESPONSE_NORMAL != (res).reply_type) && \ @@ -335,7 +371,7 @@ static inline amqp_channel_object *php_amqp_channel_object_fetch(zend_object *ob &PHP_AMQP_G(error_message), \ (channel_resource)->connection_resource, \ (channel_resource), \ - 0 TSRMLS_CC \ + 0 \ )) #define PHP_AMQP_IS_ERROR_RECOVERABLE(res, channel_resource, channel_object) \ @@ -345,7 +381,7 @@ static inline amqp_channel_object *php_amqp_channel_object_fetch(zend_object *ob &PHP_AMQP_G(error_message), \ (channel_resource)->connection_resource, \ (amqp_channel_t) (channel_resource ? (channel_resource)->channel_id : 0), \ - (channel_object) TSRMLS_CC \ + (channel_object) \ ))) @@ -397,7 +433,7 @@ ZEND_TSRMLS_CACHE_EXTERN(); #endif #ifndef PHP_AMQP_VERSION - #define PHP_AMQP_VERSION "1.12.0dev" + #define PHP_AMQP_VERSION "2.0.0dev" #endif #ifndef PHP_AMQP_REVISION @@ -408,14 +444,14 @@ int php_amqp_error( amqp_rpc_reply_t reply, char **message, amqp_connection_resource *connection_resource, - amqp_channel_resource *channel_resource TSRMLS_DC + amqp_channel_resource *channel_resource ); int php_amqp_error_advanced( amqp_rpc_reply_t reply, char **message, amqp_connection_resource *connection_resource, amqp_channel_resource *channel_resource, - int fail_on_errors TSRMLS_DC + int fail_on_errors ); /** @@ -425,9 +461,9 @@ void php_amqp_zend_throw_exception( amqp_rpc_reply_t reply, zend_class_entry *exception_ce, const char *message, - zend_long code TSRMLS_DC + zend_long code ); -void php_amqp_zend_throw_exception_short(amqp_rpc_reply_t reply, zend_class_entry *exception_ce TSRMLS_DC); +void php_amqp_zend_throw_exception_short(amqp_rpc_reply_t reply, zend_class_entry *exception_ce); void php_amqp_maybe_release_buffers_on_channel( amqp_connection_resource *connection_resource, amqp_channel_resource *channel_resource diff --git a/stubs/AMQP.php b/stubs/AMQP.php index 33f26d97..f7552c14 100644 --- a/stubs/AMQP.php +++ b/stubs/AMQP.php @@ -4,29 +4,29 @@ * Passing in this constant as a flag will forcefully disable all other flags. * Use this if you want to temporarily disable the amqp.auto_ack ini setting. */ -define('AMQP_NOPARAM', 0); +const AMQP_NOPARAM = 0; /** * Passing in this constant as a flag to proper methods will forcefully ignore all other flags. * Do not send basic.consume request during AMQPQueue::consume(). Use this if you want to run callback on top of previously * declared consumers. */ -define('AMQP_JUST_CONSUME', 1); +const AMQP_JUST_CONSUME = 1; /** * Durable exchanges and queues will survive a broker restart, complete with all of their data. */ -define('AMQP_DURABLE', 2); +const AMQP_DURABLE = 2; /** * Passive exchanges and queues will not be redeclared, but the broker will throw an error if the exchange or queue does not exist. */ -define('AMQP_PASSIVE', 4); +const AMQP_PASSIVE = 4; /** * Valid for queues only, this flag indicates that only one client can be listening to and consuming from this queue. */ -define('AMQP_EXCLUSIVE', 8); +const AMQP_EXCLUSIVE = 8; /** * For exchanges, the auto delete flag indicates that the exchange will be deleted as soon as no more queues are bound @@ -35,44 +35,44 @@ * subscription has ever been active, the queue will never be deleted. Note: Exclusive queues will always be * automatically deleted with the client disconnects. */ -define('AMQP_AUTODELETE', 16); +const AMQP_AUTODELETE = 16; /** * Clients are not allowed to make specific queue bindings to exchanges defined with this flag. */ -define('AMQP_INTERNAL', 32); +const AMQP_INTERNAL = 32; /** * When passed to the consume method for a clustered environment, do not consume from the local node. */ -define('AMQP_NOLOCAL', 64); +const AMQP_NOLOCAL = 64; /** * When passed to the {@link AMQPQueue::get()} and {@link AMQPQueue::consume()} methods as a flag, * the messages will be immediately marked as acknowledged by the server upon delivery. */ -define('AMQP_AUTOACK', 128); +const AMQP_AUTOACK = 128; /** * Passed on queue creation, this flag indicates that the queue should be deleted if it becomes empty. */ -define('AMQP_IFEMPTY', 256); +const AMQP_IFEMPTY = 256; /** * Passed on queue or exchange creation, this flag indicates that the queue or exchange should be * deleted when no clients are connected to the given queue or exchange. */ -define('AMQP_IFUNUSED', 512); +const AMQP_IFUNUSED = 512; /** * When publishing a message, the message must be routed to a valid queue. If it is not, an error will be returned. */ -define('AMQP_MANDATORY', 1024); +const AMQP_MANDATORY = 1024; /** * When publishing a message, mark this message for immediate processing by the broker. (High priority message.) */ -define('AMQP_IMMEDIATE', 2048); +const AMQP_IMMEDIATE = 2048; /** * If set during a call to {@link AMQPQueue::ack()}, the delivery tag is treated as "up to and including", so that multiple @@ -80,64 +80,64 @@ * If the AMQP_MULTIPLE flag is set, and the delivery tag is zero, this indicates acknowledgement of all outstanding * messages. */ -define('AMQP_MULTIPLE', 4096); +const AMQP_MULTIPLE = 4096; /** * If set during a call to {@link AMQPExchange::bind()}, the server will not respond to the method.The client should not wait * for a reply method. If the server could not complete the method it will raise a channel or connection exception. */ -define('AMQP_NOWAIT', 8192); +const AMQP_NOWAIT = 8192; /** * If set during a call to {@link AMQPQueue::nack()}, the message will be placed back to the queue. */ -define('AMQP_REQUEUE', 16384); +const AMQP_REQUEUE = 16384; /** * A direct exchange type. */ -define('AMQP_EX_TYPE_DIRECT', 'direct'); +const AMQP_EX_TYPE_DIRECT = 'direct'; /** * A fanout exchange type. */ -define('AMQP_EX_TYPE_FANOUT', 'fanout'); +const AMQP_EX_TYPE_FANOUT = 'fanout'; /** * A topic exchange type. */ -define('AMQP_EX_TYPE_TOPIC', 'topic'); +const AMQP_EX_TYPE_TOPIC = 'topic'; /** * A header exchange type. */ -define('AMQP_EX_TYPE_HEADERS', 'headers'); +const AMQP_EX_TYPE_HEADERS = 'headers'; /** * */ -define('AMQP_OS_SOCKET_TIMEOUT_ERRNO', 536870947); +const AMQP_OS_SOCKET_TIMEOUT_ERRNO = 536870947; /** * */ -define('PHP_AMQP_MAX_CHANNELS', 256); +const PHP_AMQP_MAX_CHANNELS = 256; /** * */ -define('AMQP_SASL_METHOD_PLAIN', 0); +const AMQP_SASL_METHOD_PLAIN = 0; /** * */ -define('AMQP_SASL_METHOD_EXTERNAL', 1); +const AMQP_SASL_METHOD_EXTERNAL = 1; /** * Default delivery mode, keeps the message in memory when the message is placed in a queue. */ -define('AMQP_DELIVERY_MODE_TRANSIENT', 1); +const AMQP_DELIVERY_MODE_TRANSIENT = 1; /** * Writes the message to the disk when the message is placed in a durable queue. */ -define('AMQP_DELIVERY_MODE_PERSISTENT', 2); +const AMQP_DELIVERY_MODE_PERSISTENT = 2; diff --git a/stubs/AMQPBasicProperties.php b/stubs/AMQPBasicProperties.php index 6b14af49..259b5da7 100644 --- a/stubs/AMQPBasicProperties.php +++ b/stubs/AMQPBasicProperties.php @@ -5,55 +5,70 @@ */ class AMQPBasicProperties { + private ?string $contentType = null; + private ?string $contentEncoding = null; + private array $headers = []; + private int $deliveryMode = AMQP_DELIVERY_MODE_TRANSIENT; + private int $priority = 0; + private ?string $correlationId = null; + private ?string $replyTo = null; + private ?string $expiration = null; + private ?string $messageId = null; + private ?int $timestamp = null; + private ?string $type = null; + private ?string $userId = null; + private ?string $appId = null; + private ?string $clusterId = null; + /** - * @param string $content_type - * @param string $content_encoding + * @param ?string $contentType + * @param ?string $contentEncoding * @param array $headers - * @param int $delivery_mode + * @param int $deliveryMode * @param int $priority - * @param string $correlation_id - * @param string $reply_to - * @param string $expiration - * @param string $message_id - * @param int $timestamp - * @param string $type - * @param string $user_id - * @param string $app_id - * @param string $cluster_id + * @param ?string $correlationId + * @param ?string $replyTo + * @param ?string $expiration + * @param ?string $messageId + * @param ?int $timestamp + * @param ?string $type + * @param ?string $userId + * @param ?string $appId + * @param ?string $clusterId */ public function __construct( - $content_type = "", - $content_encoding = "", + ?string $contentType = null, + ?string $contentEncoding = null, array $headers = [], - $delivery_mode = AMQP_DELIVERY_MODE_TRANSIENT, - $priority = 0, - $correlation_id = "", - $reply_to = "", - $expiration = "", - $message_id = "", - $timestamp = 0, - $type = "", - $user_id = "", - $app_id = "", - $cluster_id = "" + int $deliveryMode = AMQP_DELIVERY_MODE_TRANSIENT, + int $priority = 0, + ?string $correlationId = null, + ?string $replyTo = null, + ?string $expiration = null, + ?string $messageId = null, + ?int $timestamp = null, + ?string $type = null, + ?string $userId = null, + ?string $appId = null, + ?string $clusterId = null ) { } /** * Get the message content type. * - * @return string The content type of the message. + * @return string|null The content type of the message. */ - public function getContentType() + public function getContentType(): ?string { } /** * Get the content encoding of the message. * - * @return string The content encoding of the message. + * @return string|null The content encoding of the message. */ - public function getContentEncoding() + public function getContentEncoding(): ?string { } @@ -62,16 +77,16 @@ public function getContentEncoding() * * @return array An array of key value pairs associated with the message. */ - public function getHeaders() + public function getHeaders(): array { } /** * Get the delivery mode of the message. * - * @return integer The delivery mode of the message. + * @return int The delivery mode of the message. */ - public function getDeliveryMode() + public function getDeliveryMode(): int { } @@ -80,88 +95,88 @@ public function getDeliveryMode() * * @return int The message priority. */ - public function getPriority() + public function getPriority(): int { } /** * Get the message correlation id. * - * @return string The correlation id of the message. + * @return string|null The correlation id of the message. */ - public function getCorrelationId() + public function getCorrelationId(): ?string { } /** * Get the reply-to address of the message. * - * @return string The contents of the reply to field. + * @return string|null The contents of the reply to field. */ - public function getReplyTo() + public function getReplyTo(): ?string { } /** * Get the expiration of the message. * - * @return string The message expiration. + * @return string|null The message expiration. */ - public function getExpiration() + public function getExpiration(): ?string { } /** * Get the message id of the message. * - * @return string The message id + * @return string|null The message id */ - public function getMessageId() + public function getMessageId(): ?string { } /** * Get the timestamp of the message. * - * @return string The message timestamp. + * @return int|null The message timestamp. */ - public function getTimestamp() + public function getTimestamp(): ?int { } /** * Get the message type. * - * @return string The message type. + * @return string|null The message type. */ - public function getType() + public function getType(): ?string { } /** * Get the message user id. * - * @return string The message user id. + * @return string|null The message user id. */ - public function getUserId() + public function getUserId(): ?string { } /** * Get the application id of the message. * - * @return string The application id of the message. + * @return string|null The application id of the message. */ - public function getAppId() + public function getAppId(): ?string { } /** * Get the cluster id of the message. * - * @return string The cluster id of the message. + * @return string|null The cluster id of the message. */ - public function getClusterId() + public function getClusterId(): ?string { } } diff --git a/stubs/AMQPChannel.php b/stubs/AMQPChannel.php index c9d979c8..0413337a 100644 --- a/stubs/AMQPChannel.php +++ b/stubs/AMQPChannel.php @@ -5,6 +5,13 @@ */ class AMQPChannel { + private AMQPConnection $connection; + private ?int $prefetchCount = null; + private ?int $prefetchSize; + private ?int $globalPrefetchCount; + private ?int $globalPrefetchSize; + private array $consumers = []; + /** * Commit a pending transaction. * @@ -12,23 +19,23 @@ class AMQPChannel * calling this method. * @throws AMQPConnectionException If the connection to the broker was lost. * - * @return bool TRUE on success or FALSE on failure. + * @return void */ - public function commitTransaction() + public function commitTransaction(): void { } /** * Create an instance of an AMQPChannel object. * - * @param AMQPConnection $amqp_connection An instance of AMQPConnection + * @param AMQPConnection $connection An instance of AMQPConnection * with an active connection to a * broker. * * @throws AMQPConnectionException If the connection to the broker * was lost. */ - public function __construct(AMQPConnection $amqp_connection) + public function __construct(AMQPConnection $connection) { } @@ -37,7 +44,7 @@ public function __construct(AMQPConnection $amqp_connection) * * @return bool Indicates whether the channel is connected. */ - public function isConnected() + public function isConnected(): bool { } @@ -46,7 +53,7 @@ public function isConnected() * * @return void */ - public function close() + public function close(): void { } @@ -55,7 +62,7 @@ public function close() * * @return integer */ - public function getChannelId() + public function getChannelId(): int { } @@ -80,9 +87,9 @@ public function getChannelId() * * @throws AMQPConnectionException If the connection to the broker was lost. * - * @return bool TRUE on success or FALSE on failure. + * @return void */ - public function qos($size, $count, $global) + public function qos(int $size, int $count, bool $global = false): void { } @@ -96,9 +103,9 @@ public function qos($size, $count, $global) * calling this method. * @throws AMQPConnectionException If the connection to the broker was lost. * - * @return bool TRUE on success or FALSE on failure. + * @return void */ - public function rollbackTransaction() + public function rollbackTransaction(): void { } @@ -112,9 +119,9 @@ public function rollbackTransaction() * * @throws AMQPConnectionException If the connection to the broker was lost. * - * @return boolean TRUE on success or FALSE on failure. + * @return void */ - public function setPrefetchCount($count) + public function setPrefetchCount(int $count): void { } @@ -123,7 +130,7 @@ public function setPrefetchCount($count) * * @return integer */ - public function getPrefetchCount() + public function getPrefetchCount(): int { } @@ -141,9 +148,9 @@ public function getPrefetchCount() * * @throws AMQPConnectionException If the connection to the broker was lost. * - * @return bool TRUE on success or FALSE on failure. + * @return void */ - public function setPrefetchSize($size) + public function setPrefetchSize(int $size): void { } @@ -152,7 +159,7 @@ public function setPrefetchSize($size) * * @return integer */ - public function getPrefetchSize() + public function getPrefetchSize(): int { } @@ -166,9 +173,9 @@ public function getPrefetchSize() * * @throws AMQPConnectionException If the connection to the broker was lost. * - * @return boolean TRUE on success or FALSE on failure. + * @return void */ - public function setGlobalPrefetchCount($count) + public function setGlobalPrefetchCount(int $count): void { } @@ -177,7 +184,7 @@ public function setGlobalPrefetchCount($count) * * @return integer */ - public function getGlobalPrefetchCount() + public function getGlobalPrefetchCount(): int { } @@ -195,9 +202,9 @@ public function getGlobalPrefetchCount() * * @throws AMQPConnectionException If the connection to the broker was lost. * - * @return bool TRUE on success or FALSE on failure. + * @return void */ - public function setGlobalPrefetchSize($size) + public function setGlobalPrefetchSize(int $size): void { } @@ -206,7 +213,7 @@ public function setGlobalPrefetchSize($size) * * @return integer */ - public function getGlobalPrefetchSize() + public function getGlobalPrefetchSize(): int { } @@ -218,9 +225,9 @@ public function getGlobalPrefetchSize() * * @throws AMQPConnectionException If the connection to the broker was lost. * - * @return bool TRUE on success or FALSE on failure. + * @return void */ - public function startTransaction() + public function startTransaction(): void { } @@ -229,7 +236,7 @@ public function startTransaction() * * @return AMQPConnection */ - public function getConnection() + public function getConnection(): AMQPConnection { } @@ -237,18 +244,18 @@ public function getConnection() * Redeliver unacknowledged messages. * * @param bool $requeue - * @return bool + * @return void */ - public function basicRecover($requeue = true) + public function basicRecover(bool $requeue = true): void { } /** * Set the channel to use publisher acknowledgements. This can only used on a non-transactional channel. * - * @return bool + * @return void */ - public function confirmSelect() + public function confirmSelect(): void { } @@ -266,11 +273,11 @@ public function confirmSelect() * Note, basic.nack server method will only be delivered if an internal error occurs in the Erlang process * responsible for a queue (see https://www.rabbitmq.com/confirms.html for details). * - * @param callable|null $ack_callback - * @param callable|null $nack_callback + * @param callable|null $ackCallback + * @param callable|null $nackCallback * @return void */ - public function setConfirmCallback(callable $ack_callback=null, callable $nack_callback=null) + public function setConfirmCallback(?callable $ackCallback, callable $nackCallback = null): void { } @@ -285,7 +292,7 @@ public function setConfirmCallback(callable $ack_callback=null, callable $nack_c * * @return void */ - public function waitForConfirm($timeout = 0.0) + public function waitForConfirm(float $timeout = 0.0): void { } @@ -303,10 +310,10 @@ public function waitForConfirm($timeout = 0.0) * * and should return boolean false when wait loop should be canceled. * - * @param callable|null $return_callback + * @param callable|null $returnCallback * @return void */ - public function setReturnCallback(callable $return_callback=null) + public function setReturnCallback(?callable $returnCallback): void { } @@ -319,7 +326,7 @@ public function setReturnCallback(callable $return_callback=null) * * @return void */ - public function waitForBasicReturn($timeout = 0.0) + public function waitForBasicReturn(float $timeout = 0.0): void { } @@ -328,7 +335,7 @@ public function waitForBasicReturn($timeout = 0.0) * * @return AMQPQueue[] */ - public function getConsumers() + public function getConsumers(): array { } } diff --git a/stubs/AMQPConnection.php b/stubs/AMQPConnection.php index 01e9a00a..e6fbfbba 100644 --- a/stubs/AMQPConnection.php +++ b/stubs/AMQPConnection.php @@ -5,17 +5,24 @@ */ class AMQPConnection { - /** - * Establish a transient connection with the AMQP broker. - * - * This method will initiate a connection with the AMQP broker. - * - * @throws AMQPConnectionException - * @return boolean TRUE on success or throw an exception on failure. - */ - public function connect() - { - } + private string $login; + private string $password; + private string $host; + private string $vhost; + private int $port; + private float $readTimeout; + private float $writeTimeout; + private float $connectTimeout; + private float $rpcTimeout; + private int $channelMax; + private int $frameMax; + private int $heartbeat; + private ?string $cacert; + private ?string $key; + private ?string $cert; + private bool $verify = true; + private int $saslMethod = AMQP_SASL_METHOD_PLAIN; + private ?string $connectionName; /** * Create an instance of AMQPConnection. @@ -57,119 +64,144 @@ public function connect() * @param array $credentials Optional array of credential information for * connecting to the AMQP broker. */ - public function __construct(array $credentials = array()) + public function __construct(array $credentials = []) { } /** - * Closes the transient connection with the AMQP broker. + * Check whether the connection to the AMQP broker is still valid. * - * This method will close an open connection with the AMQP broker. + * It does so by checking the return status of the last connect-command. * - * @return boolean true if connection was successfully closed, false otherwise. + * @return boolean True if connected, false otherwise. */ - public function disconnect() + public function isConnected(): bool { } /** - * Get the configured host. + * Whether connection persistent. * - * @return string The configured hostname of the broker + * When no connection is established, it will always return false + * + * @return boolean */ - public function getHost() + public function isPersistent(): bool { } /** - * Get the configured login. + * Establish a transient connection with the AMQP broker. * - * @return string The configured login as a string. + * This method will initiate a connection with the AMQP broker. + * + * @throws AMQPConnectionException + * @return void */ - public function getLogin() + public function connect(): void { } /** - * Get the configured password. + * Closes the transient connection with the AMQP broker. * - * @return string The configured password as a string. + * This method will close an open connection with the AMQP broker. + * + * @throws AMQPConnectionException When attempting to disconnect a persistent connection + * @return void */ - public function getPassword() + public function disconnect(): void { } /** - * Get the configured port. + * Close any open transient connections and initiate a new one with the AMQP broker. * - * @return int The configured port as an integer. + * @throws AMQPConnectionException + * @return void */ - public function getPort() + public function reconnect(): void { } /** - * Get the configured vhost. + * Establish a persistent connection with the AMQP broker. * - * @return string The configured virtual host as a string. + * This method will initiate a connection with the AMQP broker + * or reuse an existing one if present. + * + * @throws AMQPConnectionException + * @return void */ - public function getVhost() + public function pconnect(): void { } /** - * Check whether the connection to the AMQP broker is still valid. + * Closes a persistent connection with the AMQP broker. * - * It does so by checking the return status of the last connect-command. + * This method will close an open persistent connection with the AMQP + * broker. * - * @return boolean True if connected, false otherwise. + * @throws AMQPConnectionException When attempting to disconnect a transient connection + * @return void */ - public function isConnected() + public function pdisconnect(): void { } /** - * Establish a persistent connection with the AMQP broker. - * - * This method will initiate a connection with the AMQP broker - * or reuse an existing one if present. + * Close any open persistent connections and initiate a new one with the AMQP broker. * * @throws AMQPConnectionException - * @return boolean TRUE on success or throws an exception on failure. + * @return void */ - public function pconnect() + public function preconnect(): void { } /** - * Closes a persistent connection with the AMQP broker. + * Get the configured host. * - * This method will close an open persistent connection with the AMQP - * broker. + * @return string The configured hostname of the broker + */ + public function getHost(): string + { + } + + /** + * Get the configured login. * - * @return boolean true if connection was found and closed, - * false if no persistent connection with this host, - * port, vhost and login could be found, + * @return string The configured login as a string. */ - public function pdisconnect() + public function getLogin(): string { } /** - * Close any open transient connections and initiate a new one with the AMQP broker. + * Get the configured password. * - * @return boolean TRUE on success or FALSE on failure. + * @return string The configured password as a string. */ - public function reconnect() + public function getPassword(): string { } /** - * Close any open persistent connections and initiate a new one with the AMQP broker. + * Get the configured port. * - * @return boolean TRUE on success or FALSE on failure. + * @return int The configured port as an integer. */ - public function preconnect() + public function getPort(): int + { + } + + /** + * Get the configured vhost. + * + * @return string The configured virtual host as a string. + */ + public function getVhost(): string { } @@ -181,9 +213,9 @@ public function preconnect() * * @throws AMQPConnectionException If host is longer then 1024 characters. * - * @return boolean TRUE on success or FALSE on failure. + * @return void */ - public function setHost($host) + public function setHost(string $host): void { } @@ -195,9 +227,9 @@ public function setHost($host) * * @throws AMQPConnectionException If login is longer then 32 characters. * - * @return boolean TRUE on success or FALSE on failure. + * @return void */ - public function setLogin($login) + public function setLogin(string $login): void { } @@ -209,9 +241,9 @@ public function setLogin($login) * * @throws AMQPConnectionException If password is longer then 32characters. * - * @return boolean TRUE on success or FALSE on failure. + * @return void */ - public function setPassword($password) + public function setPassword(string $password): void { } @@ -223,9 +255,9 @@ public function setPassword($password) * @throws AMQPConnectionException If port is longer not between * 1 and 65535. * - * @return boolean TRUE on success or FALSE on failure. + * @return void */ - public function setPort($port) + public function setPort(int $port): void { } @@ -237,9 +269,9 @@ public function setPort($port) * * @throws AMQPConnectionException If host is longer then 32 characters. * - * @return boolean true on success or false on failure. + * @return void */ - public function setVhost($vhost) + public function setVhost(string $vhost): void { } @@ -252,9 +284,9 @@ public function setVhost($vhost) * * @throws AMQPConnectionException If timeout is less than 0. * - * @return bool + * @return void */ - public function setTimeout($timeout) + public function setTimeout(float $timeout): void { } @@ -266,7 +298,7 @@ public function setTimeout($timeout) * * @return float */ - public function getTimeout() + public function getTimeout(): float { } @@ -277,9 +309,9 @@ public function getTimeout() * * @throws AMQPConnectionException If timeout is less than 0. * - * @return bool + * @return void */ - public function setReadTimeout($timeout) + public function setReadTimeout(float $timeout): void { } @@ -289,7 +321,7 @@ public function setReadTimeout($timeout) * * @return float */ - public function getReadTimeout() + public function getReadTimeout(): float { } @@ -300,9 +332,9 @@ public function getReadTimeout() * * @throws AMQPConnectionException If timeout is less than 0. * - * @return bool + * @return void */ - public function setWriteTimeout($timeout) + public function setWriteTimeout(float $timeout): void { } @@ -312,7 +344,7 @@ public function setWriteTimeout($timeout) * * @return float */ - public function getWriteTimeout() + public function getWriteTimeout(): float { } @@ -321,7 +353,7 @@ public function getWriteTimeout() * * @return float */ - public function getConnectTimeout() + public function getConnectTimeout(): float { } @@ -332,9 +364,9 @@ public function getConnectTimeout() * * @throws AMQPConnectionException If timeout is less than 0. * - * @return bool + * @return void */ - public function setRpcTimeout($timeout) + public function setRpcTimeout(float $timeout): void { } @@ -344,7 +376,7 @@ public function setRpcTimeout($timeout) * * @return float */ - public function getRpcTimeout() + public function getRpcTimeout(): float { } @@ -353,7 +385,7 @@ public function getRpcTimeout() * * @return int */ - public function getUsedChannels() + public function getUsedChannels(): int { } @@ -365,7 +397,7 @@ public function getUsedChannels() * * @return int */ - public function getMaxChannels() + public function getMaxChannels(): int { } @@ -377,7 +409,7 @@ public function getMaxChannels() * * @return int */ - public function getMaxFrameSize() + public function getMaxFrameSize(): int { } @@ -389,46 +421,35 @@ public function getMaxFrameSize() * * @return int */ - public function getHeartbeatInterval() - { - } - - /** - * Whether connection persistent. - * - * When connection is not connected, boolean false always returned - * - * @return bool - */ - public function isPersistent() + public function getHeartbeatInterval(): int { } /** * Get path to the CA cert file in PEM format * - * @return string + * @return string|null */ - public function getCACert() + public function getCACert(): ?string { } /** * Set path to the CA cert file in PEM format * - * @param string $cacert - * @return bool + * @param string|null $cacert + * @return void */ - public function setCACert($cacert) + public function setCACert(?string $cacert): void { } /** * Get path to the client certificate in PEM format * - * @return string + * @return string|null */ - public function getCert() + public function getCert(): ?string { } @@ -436,28 +457,28 @@ public function getCert() * Set path to the client certificate in PEM format * * @param string $cert - * @return bool + * @return void */ - public function setCert($cert) + public function setCert(?string $cert): void { } /** * Get path to the client key in PEM format * - * @return string + * @return string|null */ - public function getKey() + public function getKey(): ?string { } /** * Set path to the client key in PEM format * - * @param string $key - * @return bool + * @param string|null $key + * @return void */ - public function setKey($key) + public function setKey(?string $key): void { } @@ -466,7 +487,7 @@ public function setKey($key) * * @return bool */ - public function getVerify() + public function getVerify(): bool { } @@ -474,41 +495,41 @@ public function getVerify() * Enable or disable peer verification * * @param bool $verify - * @return bool + * @return void */ - public function setVerify($verify) + public function setVerify(bool $verify): void { } /** * set authentication method * - * @param int $method AMQP_SASL_METHOD_PLAIN | AMQP_SASL_METHOD_EXTERNAL - * @return bool + * @param int $saslMethod AMQP_SASL_METHOD_PLAIN | AMQP_SASL_METHOD_EXTERNAL + * @return void */ - public function setSaslMethod($method) + public function setSaslMethod(int $saslMethod): void { } /** * @return int */ - public function getSaslMethod() + public function getSaslMethod(): int { } /** - * @param string|null $connection_name - * @return bool + * @param string|null $connectionName + * @return void */ - public function setConnectionName($connection_name) + public function setConnectionName(?string $connectionName): void { } /** * @return string|null */ - public function getConnectionName() + public function getConnectionName(): ?string { } } diff --git a/stubs/AMQPDecimal.php b/stubs/AMQPDecimal.php index 0d563da8..e82ffdaa 100644 --- a/stubs/AMQPDecimal.php +++ b/stubs/AMQPDecimal.php @@ -25,23 +25,26 @@ final class AMQPDecimal */ const SIGNIFICAND_MAX = 4294967295; + private int $exponent; + private int $significand; + /** * @param int $exponent * @param int $significand * * @throws AMQPValueException */ - public function __construct($exponent, $significand) + public function __construct(int $exponent, int $significand) { } /** @return int */ - public function getExponent() + public function getExponent(): int { } /** @return int */ - public function getSignificand() + public function getSignificand(): int { } } diff --git a/stubs/AMQPEnvelope.php b/stubs/AMQPEnvelope.php index d4046b9f..2793fa94 100644 --- a/stubs/AMQPEnvelope.php +++ b/stubs/AMQPEnvelope.php @@ -5,6 +5,13 @@ */ class AMQPEnvelope extends AMQPBasicProperties { + private string $body = ''; + private ?string $consumerTag = null; + private ?int $deliveryTag = null; + private bool $isRedelivery = false; + private ?string $exchangeName = null; + private string $routingKey = ''; + public function __construct() { } @@ -14,7 +21,7 @@ public function __construct() * * @return string The contents of the message body. */ - public function getBody() + public function getBody(): string { } @@ -23,7 +30,7 @@ public function getBody() * * @return string The message routing key. */ - public function getRoutingKey() + public function getRoutingKey(): string { } @@ -32,7 +39,7 @@ public function getRoutingKey() * * @return string|null The consumer tag of the message. */ - public function getConsumerTag() + public function getConsumerTag(): ?string { } @@ -41,7 +48,7 @@ public function getConsumerTag() * * @return integer|null The delivery tag of the message. */ - public function getDeliveryTag() + public function getDeliveryTag(): ?int { } @@ -50,7 +57,7 @@ public function getDeliveryTag() * * @return string|null The exchange name on which the message was published. */ - public function getExchangeName() + public function getExchangeName(): ?string { } @@ -64,29 +71,29 @@ public function getExchangeName() * * @return bool TRUE if this is a redelivery, FALSE otherwise. */ - public function isRedelivery() + public function isRedelivery(): bool { } /** * Get a specific message header. * - * @param string $header_key Name of the header to get the value from. + * @param string $headerName Name of the header to get the value from. * * @return string|null The contents of the specified header or null if not set. */ - public function getHeader($header_key) + public function getHeader(string $headerName): ?string { } /** * Check whether specific message header exists. * - * @param string $header_key Name of the header to check. + * @param string $headerName Name of the header to check. * * @return boolean */ - public function hasHeader($header_key) + public function hasHeader(string $headerName): bool { } } diff --git a/stubs/AMQPEnvelopeException.php b/stubs/AMQPEnvelopeException.php index 4e39c962..91959bad 100644 --- a/stubs/AMQPEnvelopeException.php +++ b/stubs/AMQPEnvelopeException.php @@ -5,8 +5,8 @@ */ class AMQPEnvelopeException extends AMQPException { - /** - * @var AMQPEnvelope - */ - public $envelope; + private AMQPEnvelope $envelope; + public function getEnvelope(): AMQPEnvelope + { + } } diff --git a/stubs/AMQPExchange.php b/stubs/AMQPExchange.php index 6ae283db..b8741cf8 100644 --- a/stubs/AMQPExchange.php +++ b/stubs/AMQPExchange.php @@ -5,21 +5,31 @@ */ class AMQPExchange { + private AMQPConnection $connection; + private AMQPChannel $channel; + private ?string $name = null; + private ?string $type = null; + private bool $passive = false; + private bool $durable = false; + private bool $autoDelete = false; + private bool $internal = false; + private array $arguments = []; + /** * Bind to another exchange. * * Bind an exchange to another exchange using the specified routing key. * - * @param string $exchange_name Name of the exchange to bind. - * @param string $routing_key The routing key to use for binding. + * @param string $exchangeName Name of the exchange to bind. + * @param string|null $routingKey The routing key to use for binding. * @param array $arguments Additional binding arguments. * - * @throws AMQPExchangeException On failure. - * @throws AMQPChannelException If the channel is not open. + * @return void + *@throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. - * @return boolean true on success or false on failure. + * @throws AMQPExchangeException On failure. */ - public function bind($exchange_name, $routing_key = '', array $arguments = array()) + public function bind(string $exchangeName, ?string $routingKey = null, array $arguments = array()): void { } @@ -28,16 +38,16 @@ public function bind($exchange_name, $routing_key = '', array $arguments = array * * Remove a routing key binding on an another exchange from the given exchange. * - * @param string $exchange_name Name of the exchange to bind. - * @param string $routing_key The routing key to use for binding. + * @param string $exchangeName Name of the exchange to bind. + * @param string|null $routingKey The routing key to use for binding. * @param array $arguments Additional binding arguments. * - * @throws AMQPExchangeException On failure. - * @throws AMQPChannelException If the channel is not open. + * @return void + *@throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. - * @return boolean true on success or false on failure. + * @throws AMQPExchangeException On failure. */ - public function unbind($exchange_name, $routing_key = '', array $arguments = array()) + public function unbind(string $exchangeName, ?string $routingKey = null, array $arguments = array()): void { } @@ -47,7 +57,7 @@ public function unbind($exchange_name, $routing_key = '', array $arguments = arr * Returns a new instance of an AMQPExchange object, associated with the * given AMQPChannel object. * - * @param AMQPChannel $amqp_channel A valid AMQPChannel object, connected + * @param AMQPChannel $channel A valid AMQPChannel object, connected * to a broker. * * @throws AMQPExchangeException When amqp_channel is not connected to @@ -55,7 +65,7 @@ public function unbind($exchange_name, $routing_key = '', array $arguments = arr * @throws AMQPConnectionException If the connection to the broker was * lost. */ - public function __construct(AMQPChannel $amqp_channel) + public function __construct(AMQPChannel $channel) { } @@ -66,16 +76,30 @@ public function __construct(AMQPChannel $amqp_channel) * @throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. * - * @return boolean TRUE on success or FALSE on failure. + * @return void */ - public function declareExchange() + public function declareExchange(): void + { + } + + /** + * Declare a new exchange on the broker. + * + * @throws AMQPExchangeException On failure. + * @throws AMQPChannelException If the channel is not open. + * @throws AMQPConnectionException If the connection to the broker was lost. + * + * @return void + */ + public function declare(): void { } /** * Delete the exchange from the broker. * - * @param string $exchangeName Optional name of exchange to delete. + * @param string $exchangeName Optional name of exchange to delete. If not specified it uses the name of the + * exchange object * @param integer $flags Optionally AMQP_IFUNUSED can be specified * to indicate the exchange should not be * deleted until no clients are connected to @@ -85,41 +109,41 @@ public function declareExchange() * @throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. * - * @return boolean true on success or false on failure. + * @return void */ - public function delete($exchangeName = null, $flags = AMQP_NOPARAM) + public function delete(?string $exchangeName = null, int $flags = AMQP_NOPARAM): void { } /** * Get the argument associated with the given key. * - * @param string $key The key to look up. + * @param string $argumentName The key to look up. * * @return string|integer|boolean The string or integer value associated * with the given key, or FALSE if the key * is not set. */ - public function getArgument($key) + public function getArgument(string $argumentName) { } /** * Check whether argument associated with the given key exists. * - * @param string $key The key to look up. + * @param string $argumentName The key to look up. * - * @return bool + * @return boolean */ - public function hasArgument($key) + public function hasArgument(string $argumentName): bool { } /** * Get all arguments set on the given exchange. * - * @return array An array containing all of the set key/value pairs. + * @return array An array containing all the set key/value pairs. */ - public function getArguments() + public function getArguments(): array { } @@ -129,25 +153,25 @@ public function getArguments() * @return int An integer bitmask of all the flags currently set on this * exchange object. */ - public function getFlags() + public function getFlags(): int { } /** * Get the configured name. * - * @return string The configured name as a string. + * @return string|null The configured name as a string. */ - public function getName() + public function getName(): ?string { } /** * Get the configured type. * - * @return string The configured type as a string. + * @return string|null The configured type as a string. */ - public function getType() + public function getType(): ?string { } @@ -157,38 +181,37 @@ public function getType() * Publish a message to the exchange represented by the AMQPExchange object. * * @param string $message The message to publish. - * @param string $routing_key The optional routing key to which to + * @param string|null $routingKey The optional routing key to which to * publish to. * @param integer $flags One or more of AMQP_MANDATORY and * AMQP_IMMEDIATE. - * @param array $attributes One of content_type, content_encoding, + * @param array $headers One of content_type, content_encoding, * message_id, user_id, app_id, delivery_mode, * priority, timestamp, expiration, type * or reply_to, headers. - * - * @throws AMQPExchangeException On failure. * @throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. - * - * @return boolean TRUE on success or FALSE on failure. + * @throws AMQPExchangeException On failure. + * @return void */ public function publish( - $message, - $routing_key = null, - $flags = AMQP_NOPARAM, - array $attributes = array() - ) { + string $message, + ?string $routingKey = null, + int $flags = AMQP_NOPARAM, + array $headers = [] + ): void + { } /** * Set the value for the given key. * - * @param string $key Name of the argument to set. - * @param string|integer $value Value of the argument to set. + * @param string $argumentName Name of the argument to set. + * @param string|integer $argumentValue Value of the argument to set. * - * @return boolean TRUE on success or FALSE on failure. + * @return void */ - public function setArgument($key, $value) + public function setArgument(string $argumentName, $argumentValue): void { } @@ -197,34 +220,34 @@ public function setArgument($key, $value) * * @param array $arguments An array of key/value pairs of arguments. * - * @return boolean TRUE on success or FALSE on failure. + * @return void */ - public function setArguments(array $arguments) + public function setArguments(array $arguments): void { } /** * Set the flags on an exchange. * - * @param integer|null $flags A bitmask of flags. This call currently only + * @param integer $flags A bitmask of flags. This call currently only * considers the following flags: * AMQP_DURABLE, AMQP_PASSIVE * (and AMQP_DURABLE, if librabbitmq version >= 0.5.3) * * @return void */ - public function setFlags($flags) + public function setFlags(?int $flags): void { } /** * Set the name of the exchange. * - * @param string $exchange_name The name of the exchange to set as string. + * @param string|null $exchangeName The name of the exchange to set as string. * * @return void */ - public function setName($exchange_name) + public function setName(?string $exchangeName): void { } @@ -234,11 +257,11 @@ public function setName($exchange_name) * Set the type of the exchange. This can be any of AMQP_EX_TYPE_DIRECT, * AMQP_EX_TYPE_FANOUT, AMQP_EX_TYPE_HEADERS or AMQP_EX_TYPE_TOPIC. * - * @param string $exchange_type The type of exchange as a string. + * @param string|null $exchangeType The type of exchange as a string. * * @return void */ - public function setType($exchange_type) + public function setType(?string $exchangeType): void { } @@ -247,7 +270,7 @@ public function setType($exchange_type) * * @return AMQPChannel */ - public function getChannel() + public function getChannel(): AMQPChannel { } @@ -256,7 +279,7 @@ public function getChannel() * * @return AMQPConnection */ - public function getConnection() + public function getConnection(): AMQPConnection { } } diff --git a/stubs/AMQPQueue.php b/stubs/AMQPQueue.php index d7b4b20d..1b9aafab 100644 --- a/stubs/AMQPQueue.php +++ b/stubs/AMQPQueue.php @@ -5,16 +5,26 @@ */ class AMQPQueue { + private AMQPConnection $connection; + private AMQPChannel$channel; + private ?string $name = null; + private ?string $consumerTag = null; + private bool $passive = false; + private bool $durable = false; + private bool $exclusive = false; + private bool $autoDelete = true; + private array $arguments = []; + /** * Create an instance of an AMQPQueue object. * - * @param AMQPChannel $amqp_channel The amqp channel to use. + * @param AMQPChannel $channel The amqp channel to use. * * @throws AMQPQueueException When amqp_channel is not connected to a * broker. * @throws AMQPConnectionException If the connection to the broker was lost. */ - public function __construct(AMQPChannel $amqp_channel) + public function __construct(AMQPChannel $channel) { } @@ -25,40 +35,36 @@ public function __construct(AMQPChannel $amqp_channel) * without the AMQP_AUTOACK flag through AMQPQueue::get() or * AMQPQueue::consume() * - * @param integer $delivery_tag The message delivery tag of which to + * @param integer $deliveryTag The message delivery tag of which to * acknowledge receipt. * @param integer $flags The only valid flag that can be passed is * AMQP_MULTIPLE. - * - * @throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. - * - * @return boolean + * @throws AMQPChannelException If the channel is not open. + * @return void */ - public function ack($delivery_tag, $flags = AMQP_NOPARAM) + public function ack(int $deliveryTag, int $flags = AMQP_NOPARAM): void { } /** * Bind the given queue to a routing key on an exchange. * - * @param string $exchange_name Name of the exchange to bind to. - * @param string $routing_key Pattern or routing key to bind with. + * @param string $exchangeName Name of the exchange to bind to. + * @param string $routingKey Pattern or routing key to bind with. * @param array $arguments Additional binding arguments. - * - * @throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. - * - * @return boolean + * @throws AMQPChannelException If the channel is not open. + * @return void */ - public function bind($exchange_name, $routing_key = null, array $arguments = array()) + public function bind(string $exchangeName, ?string $routingKey = null, array $arguments = array()): void { } /** * Cancel a queue that is already bound to an exchange and routing key. * - * @param string $consumer_tag The consumer tag to cancel. If no tag is provided, + * @param string $consumerTag The consumer tag to cancel. If no tag is provided, * or it is empty string, the latest consumer * tag on this queue will be taken and after * the successful cancellation request it will set to null. @@ -69,13 +75,11 @@ public function bind($exchange_name, $routing_key = null, array $arguments = arr * or no consumer tag was passed and the latest tag was used * the internal consumer tag will be set to null, so that * `AMQPQueue::getConsumerTag()` will return null afterwards. - * - * @throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. - * - * @return bool; + * @throws AMQPChannelException If the channel is not open. + * @return void */ - public function cancel($consumer_tag = '') + public function cancel(string $consumerTag = ''): void { } @@ -120,9 +124,22 @@ public function cancel($consumer_tag = '') */ public function consume( callable $callback = null, - $flags = AMQP_NOPARAM, - $consumerTag = null - ) { + int $flags = AMQP_NOPARAM, + ?string $consumerTag = null + ): void { + } + + /** + * Declare a new queue on the broker. + * + * @throws AMQPChannelException If the channel is not open. + * @throws AMQPConnectionException If the connection to the broker was lost. + * @throws AMQPQueueException On failure. + * + * @return integer the message count. + */ + public function declareQueue(): int + { } /** @@ -134,7 +151,7 @@ public function consume( * * @return integer the message count. */ - public function declareQueue() + public function declare(): int { } @@ -153,7 +170,7 @@ public function declareQueue() * * @return integer The number of deleted messages. */ - public function delete($flags = AMQP_NOPARAM) + public function delete(int $flags = AMQP_NOPARAM): int { } @@ -178,31 +195,31 @@ public function delete($flags = AMQP_NOPARAM) * @throws AMQPConnectionException If the connection to the broker was lost. * @throws AMQPQueueException If queue is not exist. * - * @return AMQPEnvelope|boolean + * @return AMQPEnvelope|null */ - public function get($flags = AMQP_NOPARAM) + public function get(int $flags = AMQP_NOPARAM): ?AMQPEnvelope { } /** * Get the argument associated with the given key. * - * @param string $key The key to look up. + * @param string $argumentName The key to look up. * - * @return string|integer|boolean The string or integer value associated + * @return string|integer|null The string or integer value associated * with the given key, or false if the key * is not set. */ - public function getArgument($key) + public function getArgument(string $argumentName) { } /** * Get all set arguments as an array of key/value pairs. * - * @return array An array containing all of the set key/value pairs. + * @return array An array containing all the set key/value pairs. */ - public function getArguments() + public function getArguments(): array { } @@ -212,16 +229,16 @@ public function getArguments() * @return int An integer bitmask of all the flags currently set on this * exchange object. */ - public function getFlags() + public function getFlags(): int { } /** * Get the configured name. * - * @return string The configured name as a string. + * @return string|null The configured name as a string. */ - public function getName() + public function getName(): ?string { } @@ -238,17 +255,15 @@ public function getName() * behavior of calling this method while connected to any other broker is * undefined. * - * @param integer $delivery_tag Delivery tag of last message to reject. + * @param integer $deliveryTag Delivery tag of last message to reject. * @param integer $flags AMQP_REQUEUE to requeue the message(s), * AMQP_MULTIPLE to nack all previous * unacked messages as well. - * - * @throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. - * - * @return boolean + * @throws AMQPChannelException If the channel is not open. + * @return void */ - public function nack($delivery_tag, $flags = AMQP_NOPARAM) + public function nack(int $deliveryTag, int $flags = AMQP_NOPARAM): void { } @@ -261,39 +276,39 @@ public function nack($delivery_tag, $flags = AMQP_NOPARAM) * AMQPQueue::consume() and AMQPQueue::get() and using the AMQP_AUTOACK * flag are not eligible. * - * @param integer $delivery_tag Delivery tag of the message to reject. + * @param integer $deliveryTag Delivery tag of the message to reject. * @param integer $flags AMQP_REQUEUE to requeue the message(s). - * - * @throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. - * - * @return boolean + * @throws AMQPChannelException If the channel is not open. + * @return void */ - public function reject($delivery_tag, $flags = AMQP_NOPARAM) + public function reject(int $deliveryTag, int $flags = AMQP_NOPARAM): void { } /** * Purge the contents of a queue. * + * Returns the number of purged messages + * * @throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. * - * @return boolean + * @return int */ - public function purge() + public function purge(): int { } /** * Set a queue argument. * - * @param string $key The key to set. - * @param mixed $value The value to set. + * @param string $argumentName The key to set. + * @param mixed $argumentValue The value to set. * - * @return boolean + * @return void */ - public function setArgument($key, $value) + public function setArgument(string $argumentName, $argumentValue): void { } @@ -304,20 +319,20 @@ public function setArgument($key, $value) * * @param array $arguments An array of key/value pairs of arguments. * - * @return boolean + * @return void */ - public function setArguments(array $arguments) + public function setArguments(array $arguments): void { } /** * Check whether a queue has specific argument. * - * @param string $key The key to check. + * @param string $argumentName The key to check. * * @return boolean */ - public function hasArgument($key) + public function hasArgument(string $argumentName): bool { } @@ -328,38 +343,34 @@ public function hasArgument($key) * AMQP_DURABLE, AMQP_PASSIVE, * AMQP_EXCLUSIVE, AMQP_AUTODELETE. * - * @return boolean + * @return void */ - public function setFlags($flags) + public function setFlags(int $flags): void { } /** * Set the queue name. * - * @param string $queue_name The name of the queue. + * @param string $name The name of the queue. * - * @return boolean + * @return void */ - public function setName($queue_name) + public function setName(string $name): void { } /** * Remove a routing key binding on an exchange from the given queue. * - * @param string $exchange_name The name of the exchange on which the - * queue is bound. - * @param string $routing_key The binding routing key used by the - * queue. + * @param string $exchangeName The name of the exchange on which the queue is bound. + * @param string $routingKey The binding routing key used by the * @param array $arguments Additional binding arguments. - * - * @throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. - * - * @return boolean + * @throws AMQPChannelException If the channel is not open. + * @return void */ - public function unbind($exchange_name, $routing_key = null, array $arguments = array()) + public function unbind(string $exchangeName, ?string $routingKey = null, array $arguments = array()): void { } @@ -368,7 +379,7 @@ public function unbind($exchange_name, $routing_key = null, array $arguments = a * * @return AMQPChannel */ - public function getChannel() + public function getChannel(): AMQPChannel { } @@ -377,17 +388,16 @@ public function getChannel() * * @return AMQPConnection */ - public function getConnection() + public function getConnection(): AMQPConnection { } /** * Get latest consumer tag. If no consumer available or the latest on was canceled null will be returned. * - * @return string | null + * @return string|null */ - public function getConsumerTag() + public function getConsumerTag(): ?string { } - } diff --git a/stubs/AMQPTimestamp.php b/stubs/AMQPTimestamp.php index b7073c69..2ceb569e 100644 --- a/stubs/AMQPTimestamp.php +++ b/stubs/AMQPTimestamp.php @@ -6,31 +6,31 @@ final class AMQPTimestamp { /** - * @var string + * @var float */ - const MIN = "0"; + const MIN = 0.0; /** - * @var string + * @var float */ - const MAX = "18446744073709551616"; + const MAX = 18446744073709551616; + + private float $timestamp; /** - * @param string $timestamp + * @param float $timestamp * * @throws AMQPValueException */ - public function __construct($timestamp) + public function __construct(float $timestamp) { } - /** @return string */ - public function getTimestamp() + public function getTimestamp(): float { } - /** @return string */ - public function __toString() + public function __toString(): string { } } diff --git a/tests/004-queue-consume-orphaned.phpt b/tests/004-queue-consume-orphaned.phpt index a9d42865..eddc10cb 100644 --- a/tests/004-queue-consume-orphaned.phpt +++ b/tests/004-queue-consume-orphaned.phpt @@ -47,7 +47,7 @@ try { } catch (AMQPEnvelopeException $e) { echo get_class($e), ': ', $e->getMessage(), ':', PHP_EOL, PHP_EOL; - var_dump($e->envelope); + var_dump($e->getEnvelope()); } ?> @@ -55,45 +55,45 @@ try { AMQPEnvelopeException: Orphaned envelope: object(AMQPEnvelope)#6 (20) { - ["content_type":"AMQPBasicProperties":private]=> + ["contentType":"AMQPBasicProperties":private]=> string(10) "text/plain" - ["content_encoding":"AMQPBasicProperties":private]=> - string(0) "" + ["contentEncoding":"AMQPBasicProperties":private]=> + NULL ["headers":"AMQPBasicProperties":private]=> array(0) { } - ["delivery_mode":"AMQPBasicProperties":private]=> + ["deliveryMode":"AMQPBasicProperties":private]=> int(1) ["priority":"AMQPBasicProperties":private]=> int(0) - ["correlation_id":"AMQPBasicProperties":private]=> - string(0) "" - ["reply_to":"AMQPBasicProperties":private]=> - string(0) "" + ["correlationId":"AMQPBasicProperties":private]=> + NULL + ["replyTo":"AMQPBasicProperties":private]=> + NULL ["expiration":"AMQPBasicProperties":private]=> - string(0) "" - ["message_id":"AMQPBasicProperties":private]=> - string(0) "" + NULL + ["messageId":"AMQPBasicProperties":private]=> + NULL ["timestamp":"AMQPBasicProperties":private]=> int(0) ["type":"AMQPBasicProperties":private]=> - string(0) "" - ["user_id":"AMQPBasicProperties":private]=> - string(0) "" - ["app_id":"AMQPBasicProperties":private]=> - string(0) "" - ["cluster_id":"AMQPBasicProperties":private]=> - string(0) "" + NULL + ["userId":"AMQPBasicProperties":private]=> + NULL + ["appId":"AMQPBasicProperties":private]=> + NULL + ["clusterId":"AMQPBasicProperties":private]=> + NULL ["body":"AMQPEnvelope":private]=> string(13) "test orphaned" - ["consumer_tag":"AMQPEnvelope":private]=> + ["consumerTag":"AMQPEnvelope":private]=> string(31) "amq.ctag-%s" - ["delivery_tag":"AMQPEnvelope":private]=> + ["deliveryTag":"AMQPEnvelope":private]=> int(2) - ["is_redelivery":"AMQPEnvelope":private]=> + ["isRedelivery":"AMQPEnvelope":private]=> bool(false) - ["exchange_name":"AMQPEnvelope":private]=> + ["exchangeName":"AMQPEnvelope":private]=> string(%d) "ex1-%f" - ["routing_key":"AMQPEnvelope":private]=> + ["routingKey":"AMQPEnvelope":private]=> string(0) "" } diff --git a/tests/amqpbasicproperties.phpt b/tests/amqpbasicproperties.phpt index dc3153a6..b48a2dc1 100644 --- a/tests/amqpbasicproperties.phpt +++ b/tests/amqpbasicproperties.phpt @@ -35,34 +35,34 @@ dump_methods($props); ?> --EXPECT-- object(AMQPBasicProperties)#1 (14) { - ["content_type":"AMQPBasicProperties":private]=> + ["contentType":"AMQPBasicProperties":private]=> string(0) "" - ["content_encoding":"AMQPBasicProperties":private]=> + ["contentEncoding":"AMQPBasicProperties":private]=> string(0) "" ["headers":"AMQPBasicProperties":private]=> array(0) { } - ["delivery_mode":"AMQPBasicProperties":private]=> + ["deliveryMode":"AMQPBasicProperties":private]=> int(1) ["priority":"AMQPBasicProperties":private]=> int(0) - ["correlation_id":"AMQPBasicProperties":private]=> + ["correlationId":"AMQPBasicProperties":private]=> string(0) "" - ["reply_to":"AMQPBasicProperties":private]=> + ["replyTo":"AMQPBasicProperties":private]=> string(0) "" ["expiration":"AMQPBasicProperties":private]=> string(0) "" - ["message_id":"AMQPBasicProperties":private]=> + ["messageId":"AMQPBasicProperties":private]=> string(0) "" ["timestamp":"AMQPBasicProperties":private]=> int(0) ["type":"AMQPBasicProperties":private]=> string(0) "" - ["user_id":"AMQPBasicProperties":private]=> + ["userId":"AMQPBasicProperties":private]=> string(0) "" - ["app_id":"AMQPBasicProperties":private]=> + ["appId":"AMQPBasicProperties":private]=> string(0) "" - ["cluster_id":"AMQPBasicProperties":private]=> + ["clusterId":"AMQPBasicProperties":private]=> string(0) "" } AMQPBasicProperties @@ -97,36 +97,36 @@ AMQPBasicProperties string(0) "" object(AMQPBasicProperties)#2 (14) { - ["content_type":"AMQPBasicProperties":private]=> + ["contentType":"AMQPBasicProperties":private]=> string(12) "content_type" - ["content_encoding":"AMQPBasicProperties":private]=> + ["contentEncoding":"AMQPBasicProperties":private]=> string(16) "content_encoding" ["headers":"AMQPBasicProperties":private]=> array(1) { ["test"]=> string(7) "headers" } - ["delivery_mode":"AMQPBasicProperties":private]=> + ["deliveryMode":"AMQPBasicProperties":private]=> int(42) ["priority":"AMQPBasicProperties":private]=> int(24) - ["correlation_id":"AMQPBasicProperties":private]=> + ["correlationId":"AMQPBasicProperties":private]=> string(14) "correlation_id" - ["reply_to":"AMQPBasicProperties":private]=> + ["replyTo":"AMQPBasicProperties":private]=> string(8) "reply_to" ["expiration":"AMQPBasicProperties":private]=> string(10) "expiration" - ["message_id":"AMQPBasicProperties":private]=> + ["messageId":"AMQPBasicProperties":private]=> string(10) "message_id" ["timestamp":"AMQPBasicProperties":private]=> int(99999) ["type":"AMQPBasicProperties":private]=> string(4) "type" - ["user_id":"AMQPBasicProperties":private]=> + ["userId":"AMQPBasicProperties":private]=> string(7) "user_id" - ["app_id":"AMQPBasicProperties":private]=> + ["appId":"AMQPBasicProperties":private]=> string(6) "app_id" - ["cluster_id":"AMQPBasicProperties":private]=> + ["clusterId":"AMQPBasicProperties":private]=> string(10) "cluster_id" } AMQPBasicProperties diff --git a/tests/amqpchannel_basicRecover.phpt b/tests/amqpchannel_basicRecover.phpt index 6e7b6c4c..eb283caa 100644 --- a/tests/amqpchannel_basicRecover.phpt +++ b/tests/amqpchannel_basicRecover.phpt @@ -2,7 +2,7 @@ AMQPChannel::basicRecover --SKIPIF-- diff --git a/tests/amqpchannel_confirmSelect.phpt b/tests/amqpchannel_confirmSelect.phpt index afa3265e..dc62926e 100644 --- a/tests/amqpchannel_confirmSelect.phpt +++ b/tests/amqpchannel_confirmSelect.phpt @@ -2,7 +2,7 @@ AMQPChannel::confirmSelect() --SKIPIF-- diff --git a/tests/amqpchannel_getChannelId.phpt b/tests/amqpchannel_getChannelId.phpt index 0990b633..1c539155 100644 --- a/tests/amqpchannel_getChannelId.phpt +++ b/tests/amqpchannel_getChannelId.phpt @@ -2,7 +2,7 @@ AMQPChannel::getChannelId --SKIPIF-- diff --git a/tests/amqpchannel_get_connection.phpt b/tests/amqpchannel_get_connection.phpt index 29df770b..b0a711f3 100644 --- a/tests/amqpchannel_get_connection.phpt +++ b/tests/amqpchannel_get_connection.phpt @@ -2,7 +2,7 @@ AMQPChannel getConnection test --SKIPIF-- diff --git a/tests/amqpchannel_slots_usage.phpt b/tests/amqpchannel_slots_usage.phpt index 96d66917..771dc752 100644 --- a/tests/amqpchannel_slots_usage.phpt +++ b/tests/amqpchannel_slots_usage.phpt @@ -2,7 +2,7 @@ AMQPChannel slots usage --SKIPIF-- diff --git a/tests/amqpchannel_validation.phpt b/tests/amqpchannel_validation.phpt index cfbc7dac..51acd0df 100644 --- a/tests/amqpchannel_validation.phpt +++ b/tests/amqpchannel_validation.phpt @@ -57,12 +57,12 @@ try { ?> ==DONE== --EXPECTF-- -AMQPConnectionException: Parameter 'prefetch_size' must be between 0 and 4294967295. -AMQPConnectionException: Parameter 'prefetch_size' must be between 0 and 4294967295. -AMQPConnectionException: Parameter 'global_prefetch_size' must be between 0 and 4294967295. -AMQPConnectionException: Parameter 'global_prefetch_size' must be between 0 and 4294967295. -AMQPConnectionException: Parameter 'prefetch_count' must be between 0 and 65535. -AMQPConnectionException: Parameter 'prefetch_count' must be between 0 and 65535. -AMQPConnectionException: Parameter 'global_prefetch_count' must be between 0 and 65535. -AMQPConnectionException: Parameter 'global_prefetch_count' must be between 0 and 65535. +AMQPConnectionException: Parameter 'prefetchSize' must be between 0 and 4294967295. +AMQPConnectionException: Parameter 'prefetchSize' must be between 0 and 4294967295. +AMQPConnectionException: Parameter 'globalPrefetchSize' must be between 0 and 4294967295. +AMQPConnectionException: Parameter 'globalPrefetchSize' must be between 0 and 4294967295. +AMQPConnectionException: Parameter 'prefetchCount' must be between 0 and 65535. +AMQPConnectionException: Parameter 'prefetchCount' must be between 0 and 65535. +AMQPConnectionException: Parameter 'globalPrefetchCount' must be between 0 and 65535. +AMQPConnectionException: Parameter 'globalPrefetchCount' must be between 0 and 65535. ==DONE== \ No newline at end of file diff --git a/tests/amqpchannel_var_dump.phpt b/tests/amqpchannel_var_dump.phpt index e56cac33..4c3d2be1 100644 --- a/tests/amqpchannel_var_dump.phpt +++ b/tests/amqpchannel_var_dump.phpt @@ -2,7 +2,7 @@ AMQPChannel var_dump --SKIPIF-- @@ -31,40 +31,40 @@ object(AMQPChannel)#2 (6) { string(1) "/" ["port":"AMQPConnection":private]=> int(5672) - ["read_timeout":"AMQPConnection":private]=> + ["readTimeout":"AMQPConnection":private]=> float(0) - ["write_timeout":"AMQPConnection":private]=> + ["writeTimeout":"AMQPConnection":private]=> float(0) - ["connect_timeout":"AMQPConnection":private]=> + ["connectTimeout":"AMQPConnection":private]=> float(0) - ["rpc_timeout":"AMQPConnection":private]=> + ["rpcTimeout":"AMQPConnection":private]=> float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> + ["frameMax":"AMQPConnection":private]=> int(131072) + ["channelMax":"AMQPConnection":private]=> + int(256) ["heartbeat":"AMQPConnection":private]=> int(0) ["cacert":"AMQPConnection":private]=> - string(0) "" + NULL ["key":"AMQPConnection":private]=> - string(0) "" + NULL ["cert":"AMQPConnection":private]=> - string(0) "" + NULL ["verify":"AMQPConnection":private]=> bool(true) - ["sasl_method":"AMQPConnection":private]=> + ["saslMethod":"AMQPConnection":private]=> int(0) - ["connection_name":"AMQPConnection":private]=> + ["connectionName":"AMQPConnection":private]=> NULL } - ["prefetch_count":"AMQPChannel":private]=> + ["prefetchCount":"AMQPChannel":private]=> int(3) - ["prefetch_size":"AMQPChannel":private]=> + ["prefetchSize":"AMQPChannel":private]=> int(0) - ["global_prefetch_count":"AMQPChannel":private]=> + ["globalPrefetchCount":"AMQPChannel":private]=> int(0) - ["global_prefetch_size":"AMQPChannel":private]=> + ["globalPrefetchSize":"AMQPChannel":private]=> int(0) ["consumers":"AMQPChannel":private]=> array(0) { @@ -83,40 +83,40 @@ object(AMQPChannel)#2 (6) { string(1) "/" ["port":"AMQPConnection":private]=> int(5672) - ["read_timeout":"AMQPConnection":private]=> + ["readTimeout":"AMQPConnection":private]=> float(0) - ["write_timeout":"AMQPConnection":private]=> + ["writeTimeout":"AMQPConnection":private]=> float(0) - ["connect_timeout":"AMQPConnection":private]=> + ["connectTimeout":"AMQPConnection":private]=> float(0) - ["rpc_timeout":"AMQPConnection":private]=> + ["rpcTimeout":"AMQPConnection":private]=> float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> + ["frameMax":"AMQPConnection":private]=> int(131072) + ["channelMax":"AMQPConnection":private]=> + int(256) ["heartbeat":"AMQPConnection":private]=> int(0) ["cacert":"AMQPConnection":private]=> - string(0) "" + NULL ["key":"AMQPConnection":private]=> - string(0) "" + NULL ["cert":"AMQPConnection":private]=> - string(0) "" + NULL ["verify":"AMQPConnection":private]=> bool(true) - ["sasl_method":"AMQPConnection":private]=> + ["saslMethod":"AMQPConnection":private]=> int(0) - ["connection_name":"AMQPConnection":private]=> + ["connectionName":"AMQPConnection":private]=> NULL } - ["prefetch_count":"AMQPChannel":private]=> + ["prefetchCount":"AMQPChannel":private]=> int(3) - ["prefetch_size":"AMQPChannel":private]=> + ["prefetchSize":"AMQPChannel":private]=> int(0) - ["global_prefetch_count":"AMQPChannel":private]=> + ["globalPrefetchCount":"AMQPChannel":private]=> int(0) - ["global_prefetch_size":"AMQPChannel":private]=> + ["globalPrefetchSize":"AMQPChannel":private]=> int(0) ["consumers":"AMQPChannel":private]=> array(0) { diff --git a/tests/amqpconnection_connection_getters.phpt b/tests/amqpconnection_connection_getters.phpt index e92bc6f7..528af416 100644 --- a/tests/amqpconnection_connection_getters.phpt +++ b/tests/amqpconnection_connection_getters.phpt @@ -2,7 +2,7 @@ AMQPConnection - connection-specific getters --SKIPIF-- diff --git a/tests/amqpconnection_construct_with_limits.phpt b/tests/amqpconnection_construct_with_limits.phpt index c8c8b3f5..e712bd1e 100644 --- a/tests/amqpconnection_construct_with_limits.phpt +++ b/tests/amqpconnection_construct_with_limits.phpt @@ -26,30 +26,30 @@ object(AMQPConnection)#1 (18) { string(1) "/" ["port":"AMQPConnection":private]=> int(5672) - ["read_timeout":"AMQPConnection":private]=> + ["readTimeout":"AMQPConnection":private]=> float(0) - ["write_timeout":"AMQPConnection":private]=> + ["writeTimeout":"AMQPConnection":private]=> float(0) - ["connect_timeout":"AMQPConnection":private]=> + ["connectTimeout":"AMQPConnection":private]=> float(0) - ["rpc_timeout":"AMQPConnection":private]=> + ["rpcTimeout":"AMQPConnection":private]=> float(0) - ["channel_max":"AMQPConnection":private]=> - int(10) - ["frame_max":"AMQPConnection":private]=> + ["frameMax":"AMQPConnection":private]=> int(10240) + ["channelMax":"AMQPConnection":private]=> + int(10) ["heartbeat":"AMQPConnection":private]=> int(5) ["cacert":"AMQPConnection":private]=> - string(0) "" + NULL ["key":"AMQPConnection":private]=> - string(0) "" + NULL ["cert":"AMQPConnection":private]=> - string(0) "" + NULL ["verify":"AMQPConnection":private]=> bool(true) - ["sasl_method":"AMQPConnection":private]=> + ["saslMethod":"AMQPConnection":private]=> int(0) - ["connection_name":"AMQPConnection":private]=> + ["connectionName":"AMQPConnection":private]=> NULL } diff --git a/tests/amqpconnection_heartbeat_with_consumer.phpt b/tests/amqpconnection_heartbeat_with_consumer.phpt index df40041a..40945cc1 100644 --- a/tests/amqpconnection_heartbeat_with_consumer.phpt +++ b/tests/amqpconnection_heartbeat_with_consumer.phpt @@ -71,31 +71,31 @@ object(AMQPConnection)#1 (18) { string(1) "/" ["port":"AMQPConnection":private]=> int(5672) - ["read_timeout":"AMQPConnection":private]=> + ["readTimeout":"AMQPConnection":private]=> float(40) - ["write_timeout":"AMQPConnection":private]=> + ["writeTimeout":"AMQPConnection":private]=> float(0) - ["connect_timeout":"AMQPConnection":private]=> + ["connectTimeout":"AMQPConnection":private]=> float(0) - ["rpc_timeout":"AMQPConnection":private]=> + ["rpcTimeout":"AMQPConnection":private]=> float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> + ["frameMax":"AMQPConnection":private]=> int(131072) + ["channelMax":"AMQPConnection":private]=> + int(256) ["heartbeat":"AMQPConnection":private]=> int(2) ["cacert":"AMQPConnection":private]=> - string(0) "" + NULL ["key":"AMQPConnection":private]=> - string(0) "" + NULL ["cert":"AMQPConnection":private]=> - string(0) "" + NULL ["verify":"AMQPConnection":private]=> bool(true) - ["sasl_method":"AMQPConnection":private]=> + ["saslMethod":"AMQPConnection":private]=> int(0) - ["connection_name":"AMQPConnection":private]=> + ["connectionName":"AMQPConnection":private]=> NULL } Consumed: test message 1 (should be dead lettered) diff --git a/tests/amqpconnection_nullable_setters.phpt b/tests/amqpconnection_nullable_setters.phpt new file mode 100644 index 00000000..b7f8216a --- /dev/null +++ b/tests/amqpconnection_nullable_setters.phpt @@ -0,0 +1,51 @@ +--TEST-- +AMQPConnection - setters and nullability +--SKIPIF-- + +--FILE-- +setKey('key'); +var_dump($c->getKey()); +$c->setKey(null); +var_dump($c->getKey()); +$c->setKey(''); +var_dump($c->getKey()); + +$c->setCert('cert'); +var_dump($c->getCert()); +$c->setCert(null); +var_dump($c->getCert()); +$c->setCert(''); +var_dump($c->getCert()); + +$c->setCACert('cacert'); +var_dump($c->getCACert()); +$c->setCACert(null); +var_dump($c->getCACert()); +$c->setCACert(''); +var_dump($c->getCACert()); + +$c->setConnectionName('con'); +var_dump($c->getConnectionName()); +$c->setConnectionName(null); +var_dump($c->getConnectionName()); +$c->setConnectionName(''); +var_dump($c->getConnectionName()); +?> +==DONE== +--EXPECT-- +string(3) "key" +NULL +string(0) "" +string(4) "cert" +NULL +string(0) "" +string(6) "cacert" +NULL +string(0) "" +string(3) "con" +NULL +string(0) "" +==DONE== \ No newline at end of file diff --git a/tests/amqpconnection_setPort_int.phpt b/tests/amqpconnection_setPort_int.phpt index b7cc3f7a..d6745a3a 100644 --- a/tests/amqpconnection_setPort_int.phpt +++ b/tests/amqpconnection_setPort_int.phpt @@ -6,11 +6,11 @@ AMQPConnection constructor setPort($port), true), PHP_EOL; +var_dump($cnn->setPort($port)); echo $cnn->getPort(), PHP_EOL; echo gettype($port), PHP_EOL; ?> --EXPECT-- -true +NULL 12345 integer diff --git a/tests/amqpconnection_setPort_string.phpt b/tests/amqpconnection_setPort_string.phpt index 7aa5afe3..21ef8a39 100644 --- a/tests/amqpconnection_setPort_string.phpt +++ b/tests/amqpconnection_setPort_string.phpt @@ -6,11 +6,11 @@ AMQPConnection setPort with string setPort($port), PHP_EOL; +var_dump($cnn->setPort($port)); var_dump($cnn->getPort()); var_dump($port); ?> --EXPECT-- -1 +NULL int(12345) string(5) "12345" diff --git a/tests/amqpconnection_setReadTimeout_out_of_range.phpt b/tests/amqpconnection_setReadTimeout_out_of_range.phpt index 20e7ce59..68d9f362 100644 --- a/tests/amqpconnection_setReadTimeout_out_of_range.phpt +++ b/tests/amqpconnection_setReadTimeout_out_of_range.phpt @@ -15,4 +15,4 @@ try { ?> --EXPECT-- AMQPConnectionException -Parameter 'read_timeout' must be greater than or equal to zero. +Parameter 'readTimeout' must be greater than or equal to zero. diff --git a/tests/amqpconnection_setRpcTimeout_out_of_range.phpt b/tests/amqpconnection_setRpcTimeout_out_of_range.phpt index c11cec4a..ffe4cd92 100644 --- a/tests/amqpconnection_setRpcTimeout_out_of_range.phpt +++ b/tests/amqpconnection_setRpcTimeout_out_of_range.phpt @@ -15,4 +15,4 @@ try { ?> --EXPECT-- AMQPConnectionException -Parameter 'rpc_timeout' must be greater than or equal to zero. +Parameter 'rpcTimeout' must be greater than or equal to zero. diff --git a/tests/amqpconnection_setWriteTimeout_out_of_range.phpt b/tests/amqpconnection_setWriteTimeout_out_of_range.phpt index 4f6204ac..ec2ddb1e 100644 --- a/tests/amqpconnection_setWriteTimeout_out_of_range.phpt +++ b/tests/amqpconnection_setWriteTimeout_out_of_range.phpt @@ -15,4 +15,4 @@ try { ?> --EXPECT-- AMQPConnectionException -Parameter 'write_timeout' must be greater than or equal to zero. +Parameter 'writeTimeout' must be greater than or equal to zero. diff --git a/tests/amqpconnection_validation.phpt b/tests/amqpconnection_validation.phpt index afd43153..813cf7c6 100644 --- a/tests/amqpconnection_validation.phpt +++ b/tests/amqpconnection_validation.phpt @@ -19,8 +19,8 @@ $parameters = [ ['write_timeout', 'setWriteTimeout', 'getWriteTimeout', [-1], 30], ['connect_timeout', null, 'getConnectTimeout', [-1], 40], ['rpc_timeout', 'setRpcTimeout', 'getRpcTimeout', [-1], 50], - ['channel_max', null, 'getMaxChannels', [-1, 257], 128], ['frame_max', null, 'getMaxFrameSize', [-1, PHP_INT_MAX + 1], 128], + ['channel_max', null, 'getMaxChannels', [-1, 257], 128], ['heartbeat', null, 'getHeartbeatInterval', [-1, PHP_INT_MAX + 1], 250], ]; @@ -88,16 +88,16 @@ AMQPConnectionException: Parameter 'timeout' must be greater than or equal to ze Deprecated: AMQPConnection::setTimeout(): AMQPConnection::setTimeout($timeout) method is deprecated; use AMQPConnection::setReadTimeout($timeout) instead in %s on line %d AMQPConnectionException: Parameter 'timeout' must be greater than or equal to zero. AMQPConnectionException: Parameter 'read_timeout' must be greater than or equal to zero. -AMQPConnectionException: Parameter 'read_timeout' must be greater than or equal to zero. -AMQPConnectionException: Parameter 'write_timeout' must be greater than or equal to zero. +AMQPConnectionException: Parameter 'readTimeout' must be greater than or equal to zero. AMQPConnectionException: Parameter 'write_timeout' must be greater than or equal to zero. +AMQPConnectionException: Parameter 'writeTimeout' must be greater than or equal to zero. AMQPConnectionException: Parameter 'connect_timeout' must be greater than or equal to zero. AMQPConnectionException: Parameter 'rpc_timeout' must be greater than or equal to zero. -AMQPConnectionException: Parameter 'rpc_timeout' must be greater than or equal to zero. -AMQPConnectionException: Parameter 'channel_max' is out of range. -AMQPConnectionException: Parameter 'channel_max' is out of range. +AMQPConnectionException: Parameter 'rpcTimeout' must be greater than or equal to zero. AMQPConnectionException: Parameter 'frame_max' is out of range. AMQPConnectionException: Parameter 'frame_max' is out of range. +AMQPConnectionException: Parameter 'channel_max' is out of range. +AMQPConnectionException: Parameter 'channel_max' is out of range. AMQPConnectionException: Parameter 'heartbeat' is out of range. AMQPConnectionException: Parameter 'heartbeat' is out of range. ==DONE== \ No newline at end of file diff --git a/tests/amqpconnection_var_dump.phpt b/tests/amqpconnection_var_dump.phpt index 0871c110..3760e2fc 100644 --- a/tests/amqpconnection_var_dump.phpt +++ b/tests/amqpconnection_var_dump.phpt @@ -2,7 +2,7 @@ AMQPConnection var_dump --SKIPIF-- @@ -34,31 +34,31 @@ object(AMQPConnection)#1 (18) { string(1) "/" ["port":"AMQPConnection":private]=> int(5672) - ["read_timeout":"AMQPConnection":private]=> + ["readTimeout":"AMQPConnection":private]=> float(0) - ["write_timeout":"AMQPConnection":private]=> + ["writeTimeout":"AMQPConnection":private]=> float(0) - ["connect_timeout":"AMQPConnection":private]=> + ["connectTimeout":"AMQPConnection":private]=> float(0) - ["rpc_timeout":"AMQPConnection":private]=> + ["rpcTimeout":"AMQPConnection":private]=> float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> + ["frameMax":"AMQPConnection":private]=> int(131072) + ["channelMax":"AMQPConnection":private]=> + int(256) ["heartbeat":"AMQPConnection":private]=> int(0) ["cacert":"AMQPConnection":private]=> - string(0) "" + NULL ["key":"AMQPConnection":private]=> - string(0) "" + NULL ["cert":"AMQPConnection":private]=> - string(0) "" + NULL ["verify":"AMQPConnection":private]=> bool(true) - ["sasl_method":"AMQPConnection":private]=> + ["saslMethod":"AMQPConnection":private]=> int(0) - ["connection_name":"AMQPConnection":private]=> + ["connectionName":"AMQPConnection":private]=> NULL } bool(true) @@ -74,31 +74,31 @@ object(AMQPConnection)#1 (18) { string(1) "/" ["port":"AMQPConnection":private]=> int(5672) - ["read_timeout":"AMQPConnection":private]=> + ["readTimeout":"AMQPConnection":private]=> float(0) - ["write_timeout":"AMQPConnection":private]=> + ["writeTimeout":"AMQPConnection":private]=> float(0) - ["connect_timeout":"AMQPConnection":private]=> + ["connectTimeout":"AMQPConnection":private]=> float(0) - ["rpc_timeout":"AMQPConnection":private]=> + ["rpcTimeout":"AMQPConnection":private]=> float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> + ["frameMax":"AMQPConnection":private]=> int(131072) + ["channelMax":"AMQPConnection":private]=> + int(256) ["heartbeat":"AMQPConnection":private]=> int(0) ["cacert":"AMQPConnection":private]=> - string(0) "" + NULL ["key":"AMQPConnection":private]=> - string(0) "" + NULL ["cert":"AMQPConnection":private]=> - string(0) "" + NULL ["verify":"AMQPConnection":private]=> bool(true) - ["sasl_method":"AMQPConnection":private]=> + ["saslMethod":"AMQPConnection":private]=> int(0) - ["connection_name":"AMQPConnection":private]=> + ["connectionName":"AMQPConnection":private]=> NULL } bool(false) @@ -113,30 +113,30 @@ object(AMQPConnection)#1 (18) { string(1) "/" ["port":"AMQPConnection":private]=> int(5672) - ["read_timeout":"AMQPConnection":private]=> + ["readTimeout":"AMQPConnection":private]=> float(0) - ["write_timeout":"AMQPConnection":private]=> + ["writeTimeout":"AMQPConnection":private]=> float(0) - ["connect_timeout":"AMQPConnection":private]=> + ["connectTimeout":"AMQPConnection":private]=> float(0) - ["rpc_timeout":"AMQPConnection":private]=> + ["rpcTimeout":"AMQPConnection":private]=> float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> + ["frameMax":"AMQPConnection":private]=> int(131072) + ["channelMax":"AMQPConnection":private]=> + int(256) ["heartbeat":"AMQPConnection":private]=> int(0) ["cacert":"AMQPConnection":private]=> - string(0) "" + NULL ["key":"AMQPConnection":private]=> - string(0) "" + NULL ["cert":"AMQPConnection":private]=> - string(0) "" + NULL ["verify":"AMQPConnection":private]=> bool(true) - ["sasl_method":"AMQPConnection":private]=> + ["saslMethod":"AMQPConnection":private]=> int(0) - ["connection_name":"AMQPConnection":private]=> + ["connectionName":"AMQPConnection":private]=> NULL } diff --git a/tests/amqpdecimal.phpt b/tests/amqpdecimal.phpt index 4fd79d9a..35b1712a 100644 --- a/tests/amqpdecimal.phpt +++ b/tests/amqpdecimal.phpt @@ -2,7 +2,7 @@ AMQPDecimal --SKIPIF-- --EXPECT-- object(AMQPEnvelope)#1 (20) { - ["content_type":"AMQPBasicProperties":private]=> - string(0) "" - ["content_encoding":"AMQPBasicProperties":private]=> - string(0) "" + ["contentType":"AMQPBasicProperties":private]=> + NULL + ["contentEncoding":"AMQPBasicProperties":private]=> + NULL ["headers":"AMQPBasicProperties":private]=> array(0) { } - ["delivery_mode":"AMQPBasicProperties":private]=> + ["deliveryMode":"AMQPBasicProperties":private]=> int(1) ["priority":"AMQPBasicProperties":private]=> int(0) - ["correlation_id":"AMQPBasicProperties":private]=> - string(0) "" - ["reply_to":"AMQPBasicProperties":private]=> - string(0) "" + ["correlationId":"AMQPBasicProperties":private]=> + NULL + ["replyTo":"AMQPBasicProperties":private]=> + NULL ["expiration":"AMQPBasicProperties":private]=> - string(0) "" - ["message_id":"AMQPBasicProperties":private]=> - string(0) "" + NULL + ["messageId":"AMQPBasicProperties":private]=> + NULL ["timestamp":"AMQPBasicProperties":private]=> - int(0) + NULL ["type":"AMQPBasicProperties":private]=> - string(0) "" - ["user_id":"AMQPBasicProperties":private]=> - string(0) "" - ["app_id":"AMQPBasicProperties":private]=> - string(0) "" - ["cluster_id":"AMQPBasicProperties":private]=> - string(0) "" + NULL + ["userId":"AMQPBasicProperties":private]=> + NULL + ["appId":"AMQPBasicProperties":private]=> + NULL + ["clusterId":"AMQPBasicProperties":private]=> + NULL ["body":"AMQPEnvelope":private]=> string(0) "" - ["consumer_tag":"AMQPEnvelope":private]=> - NULL - ["delivery_tag":"AMQPEnvelope":private]=> + ["consumerTag":"AMQPEnvelope":private]=> NULL - ["is_redelivery":"AMQPEnvelope":private]=> + ["deliveryTag":"AMQPEnvelope":private]=> NULL - ["exchange_name":"AMQPEnvelope":private]=> + ["isRedelivery":"AMQPEnvelope":private]=> + bool(false) + ["exchangeName":"AMQPEnvelope":private]=> NULL - ["routing_key":"AMQPEnvelope":private]=> + ["routingKey":"AMQPEnvelope":private]=> string(0) "" } diff --git a/tests/amqpenvelope_get_accessors.phpt b/tests/amqpenvelope_get_accessors.phpt index af93cf82..33fd3f1a 100644 --- a/tests/amqpenvelope_get_accessors.phpt +++ b/tests/amqpenvelope_get_accessors.phpt @@ -37,48 +37,48 @@ var_dump($header); ?> --EXPECTF-- object(AMQPEnvelope)#5 (20) { - ["content_type":"AMQPBasicProperties":private]=> + ["contentType":"AMQPBasicProperties":private]=> string(10) "text/plain" - ["content_encoding":"AMQPBasicProperties":private]=> - string(0) "" + ["contentEncoding":"AMQPBasicProperties":private]=> + NULL ["headers":"AMQPBasicProperties":private]=> array(1) { ["foo"]=> string(3) "bar" } - ["delivery_mode":"AMQPBasicProperties":private]=> + ["deliveryMode":"AMQPBasicProperties":private]=> int(1) ["priority":"AMQPBasicProperties":private]=> int(0) - ["correlation_id":"AMQPBasicProperties":private]=> - string(0) "" - ["reply_to":"AMQPBasicProperties":private]=> - string(0) "" + ["correlationId":"AMQPBasicProperties":private]=> + NULL + ["replyTo":"AMQPBasicProperties":private]=> + NULL ["expiration":"AMQPBasicProperties":private]=> - string(0) "" - ["message_id":"AMQPBasicProperties":private]=> - string(0) "" + NULL + ["messageId":"AMQPBasicProperties":private]=> + NULL ["timestamp":"AMQPBasicProperties":private]=> int(0) ["type":"AMQPBasicProperties":private]=> - string(0) "" - ["user_id":"AMQPBasicProperties":private]=> - string(0) "" - ["app_id":"AMQPBasicProperties":private]=> - string(0) "" - ["cluster_id":"AMQPBasicProperties":private]=> - string(0) "" + NULL + ["userId":"AMQPBasicProperties":private]=> + NULL + ["appId":"AMQPBasicProperties":private]=> + NULL + ["clusterId":"AMQPBasicProperties":private]=> + NULL ["body":"AMQPEnvelope":private]=> string(7) "message" - ["consumer_tag":"AMQPEnvelope":private]=> + ["consumerTag":"AMQPEnvelope":private]=> string(0) "" - ["delivery_tag":"AMQPEnvelope":private]=> + ["deliveryTag":"AMQPEnvelope":private]=> int(1) - ["is_redelivery":"AMQPEnvelope":private]=> + ["isRedelivery":"AMQPEnvelope":private]=> bool(false) - ["exchange_name":"AMQPEnvelope":private]=> + ["exchangeName":"AMQPEnvelope":private]=> string(%d) "exchange-%f" - ["routing_key":"AMQPEnvelope":private]=> + ["routingKey":"AMQPEnvelope":private]=> string(9) "routing.1" } AMQPEnvelope @@ -99,25 +99,25 @@ AMQPEnvelope isRedelivery: bool(false) getContentEncoding: - string(0) "" + NULL getType: - string(0) "" + NULL getTimeStamp: int(0) getPriority: int(0) getExpiration: - string(0) "" + NULL getUserId: - string(0) "" + NULL getAppId: - string(0) "" + NULL getMessageId: - string(0) "" + NULL getReplyTo: - string(0) "" + NULL getCorrelationId: - string(0) "" + NULL getHeaders: array(1) { ["foo"]=> diff --git a/tests/amqpenvelope_var_dump.phpt b/tests/amqpenvelope_var_dump.phpt index ff1723ff..4944b891 100644 --- a/tests/amqpenvelope_var_dump.phpt +++ b/tests/amqpenvelope_var_dump.phpt @@ -2,7 +2,7 @@ AMQPEnvelope var_dump --SKIPIF-- consume("consumeThings"); ?> --EXPECTF-- object(AMQPEnvelope)#5 (20) { - ["content_type":"AMQPBasicProperties":private]=> + ["contentType":"AMQPBasicProperties":private]=> string(10) "text/plain" - ["content_encoding":"AMQPBasicProperties":private]=> - string(0) "" + ["contentEncoding":"AMQPBasicProperties":private]=> + NULL ["headers":"AMQPBasicProperties":private]=> array(0) { } - ["delivery_mode":"AMQPBasicProperties":private]=> + ["deliveryMode":"AMQPBasicProperties":private]=> int(1) ["priority":"AMQPBasicProperties":private]=> int(0) - ["correlation_id":"AMQPBasicProperties":private]=> - string(0) "" - ["reply_to":"AMQPBasicProperties":private]=> - string(0) "" + ["correlationId":"AMQPBasicProperties":private]=> + NULL + ["replyTo":"AMQPBasicProperties":private]=> + NULL ["expiration":"AMQPBasicProperties":private]=> - string(0) "" - ["message_id":"AMQPBasicProperties":private]=> - string(0) "" + NULL + ["messageId":"AMQPBasicProperties":private]=> + NULL ["timestamp":"AMQPBasicProperties":private]=> int(0) ["type":"AMQPBasicProperties":private]=> - string(0) "" - ["user_id":"AMQPBasicProperties":private]=> - string(0) "" - ["app_id":"AMQPBasicProperties":private]=> - string(0) "" - ["cluster_id":"AMQPBasicProperties":private]=> - string(0) "" + NULL + ["userId":"AMQPBasicProperties":private]=> + NULL + ["appId":"AMQPBasicProperties":private]=> + NULL + ["clusterId":"AMQPBasicProperties":private]=> + NULL ["body":"AMQPEnvelope":private]=> string(7) "message" - ["consumer_tag":"AMQPEnvelope":private]=> + ["consumerTag":"AMQPEnvelope":private]=> string(31) "amq.ctag-%s" - ["delivery_tag":"AMQPEnvelope":private]=> + ["deliveryTag":"AMQPEnvelope":private]=> int(1) - ["is_redelivery":"AMQPEnvelope":private]=> + ["isRedelivery":"AMQPEnvelope":private]=> bool(false) - ["exchange_name":"AMQPEnvelope":private]=> + ["exchangeName":"AMQPEnvelope":private]=> string(9) "exchange1" - ["routing_key":"AMQPEnvelope":private]=> + ["routingKey":"AMQPEnvelope":private]=> string(9) "routing.1" } object(AMQPEnvelope)#5 (20) { - ["content_type":"AMQPBasicProperties":private]=> + ["contentType":"AMQPBasicProperties":private]=> string(10) "text/plain" - ["content_encoding":"AMQPBasicProperties":private]=> - string(0) "" + ["contentEncoding":"AMQPBasicProperties":private]=> + NULL ["headers":"AMQPBasicProperties":private]=> array(1) { ["test"]=> string(6) "passed" } - ["delivery_mode":"AMQPBasicProperties":private]=> + ["deliveryMode":"AMQPBasicProperties":private]=> int(1) ["priority":"AMQPBasicProperties":private]=> int(0) - ["correlation_id":"AMQPBasicProperties":private]=> - string(0) "" - ["reply_to":"AMQPBasicProperties":private]=> - string(0) "" + ["correlationId":"AMQPBasicProperties":private]=> + NULL + ["replyTo":"AMQPBasicProperties":private]=> + NULL ["expiration":"AMQPBasicProperties":private]=> - string(0) "" - ["message_id":"AMQPBasicProperties":private]=> - string(0) "" + NULL + ["messageId":"AMQPBasicProperties":private]=> + NULL ["timestamp":"AMQPBasicProperties":private]=> int(0) ["type":"AMQPBasicProperties":private]=> - string(0) "" - ["user_id":"AMQPBasicProperties":private]=> - string(0) "" - ["app_id":"AMQPBasicProperties":private]=> - string(0) "" - ["cluster_id":"AMQPBasicProperties":private]=> - string(0) "" + NULL + ["userId":"AMQPBasicProperties":private]=> + NULL + ["appId":"AMQPBasicProperties":private]=> + NULL + ["clusterId":"AMQPBasicProperties":private]=> + NULL ["body":"AMQPEnvelope":private]=> string(7) "message" - ["consumer_tag":"AMQPEnvelope":private]=> + ["consumerTag":"AMQPEnvelope":private]=> string(31) "amq.ctag-%s" - ["delivery_tag":"AMQPEnvelope":private]=> + ["deliveryTag":"AMQPEnvelope":private]=> int(2) - ["is_redelivery":"AMQPEnvelope":private]=> + ["isRedelivery":"AMQPEnvelope":private]=> bool(false) - ["exchange_name":"AMQPEnvelope":private]=> + ["exchangeName":"AMQPEnvelope":private]=> string(9) "exchange1" - ["routing_key":"AMQPEnvelope":private]=> + ["routingKey":"AMQPEnvelope":private]=> string(9) "routing.1" } diff --git a/tests/amqpexchange_attributes.phpt b/tests/amqpexchange_attributes.phpt index b92765ea..b242b7c5 100644 --- a/tests/amqpexchange_attributes.phpt +++ b/tests/amqpexchange_attributes.phpt @@ -2,7 +2,7 @@ AMQPExchange attributes --SKIPIF-- diff --git a/tests/amqpexchange_bind.phpt b/tests/amqpexchange_bind.phpt index 39b7e77f..09b537cc 100644 --- a/tests/amqpexchange_bind.phpt +++ b/tests/amqpexchange_bind.phpt @@ -26,5 +26,5 @@ var_dump($ex->bind($ex2->getName(), 'test-key-1')); ?> --EXPECT-- -bool(true) -bool(true) \ No newline at end of file +NULL +NULL \ No newline at end of file diff --git a/tests/amqpexchange_bind_with_arguments.phpt b/tests/amqpexchange_bind_with_arguments.phpt index c3e13618..5c121238 100644 --- a/tests/amqpexchange_bind_with_arguments.phpt +++ b/tests/amqpexchange_bind_with_arguments.phpt @@ -28,5 +28,5 @@ var_dump($ex->bind($ex2->getName(), 'test', array('test' => 'passed', 'at' => $t ?> --EXPECT-- -bool(true) -bool(true) \ No newline at end of file +NULL +NULL \ No newline at end of file diff --git a/tests/amqpexchange_bind_without_key.phpt b/tests/amqpexchange_bind_without_key.phpt index d861e5e7..98521721 100644 --- a/tests/amqpexchange_bind_without_key.phpt +++ b/tests/amqpexchange_bind_without_key.phpt @@ -27,6 +27,6 @@ var_dump($ex->bind($ex2->getName(), '')); ?> --EXPECT-- -bool(true) -bool(true) -bool(true) \ No newline at end of file +NULL +NULL +NULL \ No newline at end of file diff --git a/tests/amqpexchange_bind_without_key_with_arguments.phpt b/tests/amqpexchange_bind_without_key_with_arguments.phpt index 6d6f57a8..103d237b 100644 --- a/tests/amqpexchange_bind_without_key_with_arguments.phpt +++ b/tests/amqpexchange_bind_without_key_with_arguments.phpt @@ -28,5 +28,5 @@ var_dump($ex->bind($ex2->getName(), '', array('test' => 'passed', 'at' => $time, ?> --EXPECT-- -bool(true) -bool(true) \ No newline at end of file +NULL +NULL \ No newline at end of file diff --git a/tests/amqpexchange_declare_basic.phpt b/tests/amqpexchange_declare_basic.phpt index a1bb4baa..99af7153 100644 --- a/tests/amqpexchange_declare_basic.phpt +++ b/tests/amqpexchange_declare_basic.phpt @@ -10,9 +10,11 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName("exchange-" . microtime(true)); -$ex->setType(AMQP_EX_TYPE_FANOUT); -echo $ex->declareExchange() ? "true" : "false"; +var_dump($ex->setName("exchange-" . microtime(true))); +var_dump($ex->setType(AMQP_EX_TYPE_FANOUT)); +var_dump($ex->declareExchange()); ?> --EXPECT-- -true +NULL +NULL +NULL diff --git a/tests/amqpexchange_declare_existent.phpt b/tests/amqpexchange_declare_existent.phpt index f2f04d17..d136d3ab 100644 --- a/tests/amqpexchange_declare_existent.phpt +++ b/tests/amqpexchange_declare_existent.phpt @@ -16,7 +16,7 @@ $exchangge_name = "exchange-" . microtime(true); $ex = new AMQPExchange($ch); $ex->setName($exchangge_name); $ex->setType(AMQP_EX_TYPE_FANOUT); -echo "Exchange declared: ", $ex->declareExchange() ? "true" : "false", PHP_EOL; +echo "Exchange declared: ", var_export($ex->declareExchange(), true), PHP_EOL; try { $ex = new AMQPExchange($ch); @@ -40,7 +40,7 @@ try { ?> --EXPECTF-- Channel id: 1 -Exchange declared: true +Exchange declared: NULL AMQPExchangeException(406): Server channel error: 406, message: PRECONDITION_FAILED - %s exchange 'exchange-%f' in vhost '/'%s Channel connected: false Connection connected: true diff --git a/tests/amqpexchange_get_connection.phpt b/tests/amqpexchange_get_connection.phpt index 7c944814..e5974093 100644 --- a/tests/amqpexchange_get_connection.phpt +++ b/tests/amqpexchange_get_connection.phpt @@ -2,7 +2,7 @@ AMQPExchange getConnection test --SKIPIF-- diff --git a/tests/amqpexchange_name.phpt b/tests/amqpexchange_name.phpt new file mode 100644 index 00000000..e8ed0383 --- /dev/null +++ b/tests/amqpexchange_name.phpt @@ -0,0 +1,31 @@ +--TEST-- +AMQPExchange getConnection test +--SKIPIF-- + +--FILE-- +connect(); +$ch = new AMQPChannel($cnn); + +$ex = new AMQPExchange($ch); +var_dump($ex->getName()); +$ex->setName('exchange'); +var_dump($ex->getName()); +$ex->setName(''); +var_dump($ex->getName()); +$ex->setName(null); +var_dump($ex->getName()); +?> +==DONE== +--EXPECT-- +NULL +string(8) "exchange" +NULL +NULL +==DONE== \ No newline at end of file diff --git a/tests/amqpexchange_publish_basic.phpt b/tests/amqpexchange_publish_basic.phpt index b1b8e559..4f99ca78 100644 --- a/tests/amqpexchange_publish_basic.phpt +++ b/tests/amqpexchange_publish_basic.phpt @@ -13,8 +13,8 @@ $ex = new AMQPExchange($ch); $ex->setName("exchange-" . microtime(true)); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); -echo $ex->publish('message', 'routing.key') ? 'true' : 'false'; +var_dump($ex->publish('message', 'routing.key')); $ex->delete(); ?> --EXPECT-- -true +NULL diff --git a/tests/amqpexchange_publish_confirms.phpt b/tests/amqpexchange_publish_confirms.phpt index 0d736704..7e0456f0 100644 --- a/tests/amqpexchange_publish_confirms.phpt +++ b/tests/amqpexchange_publish_confirms.phpt @@ -36,8 +36,8 @@ $ex1->setFlags(AMQP_AUTODELETE); $ex1->declareExchange(); -echo $ex1->publish('message 1', 'routing.key') ? 'true' : 'false', PHP_EOL; -echo $ex1->publish('message 1', 'routing.key', AMQP_MANDATORY) ? 'true' : 'false', PHP_EOL; +var_dump($ex1->publish('message 1', 'routing.key')); +var_dump($ex1->publish('message 1', 'routing.key', AMQP_MANDATORY)); try { $ch->waitForConfirm(); @@ -58,8 +58,8 @@ try { } -echo $ex1->publish('message 1', 'routing.key') ? 'true' : 'false', PHP_EOL; -echo $ex1->publish('message 1', 'routing.key', AMQP_MANDATORY) ? 'true' : 'false', PHP_EOL; +var_dump($ex1->publish('message 1', 'routing.key')); +var_dump($ex1->publish('message 1', 'routing.key', AMQP_MANDATORY)); // ack_callback(int $delivery_tag, bool $multiple) : bool; // nack_callback(int $delivery_tag, bool $multiple, bool $requeue) : bool; @@ -90,7 +90,7 @@ $ex1->delete(); $ex2 = new AMQPExchange($ch); $ex2->setName("exchange-nonexistent-" . microtime(true)); -echo $ex2->publish('message 2', 'routing.key') ? 'true' : 'false', PHP_EOL; +var_dump($ex2->publish('message 2', 'routing.key')); try { $ch->waitForConfirm(1); @@ -101,13 +101,13 @@ try { ?> --EXPECTF-- AMQPQueueException(0): Wait timeout exceed -true -true +NULL +NULL Unhandled basic.ack method from server received. Use AMQPChannel::setConfirmCallback() to process it. Unhandled basic.return method from server received. Use AMQPChannel::setReturnCallback() to process it. Unhandled basic.ack method from server received. Use AMQPChannel::setConfirmCallback() to process it. -true -true +NULL +NULL Message acked array(2) { [0]=> @@ -123,5 +123,5 @@ array(2) { [1]=> bool(false) } -true +NULL AMQPChannelException(404): Server channel error: 404, message: NOT_FOUND - no exchange 'exchange-nonexistent-%f' in vhost '/' diff --git a/tests/amqpexchange_publish_confirms_consume.phpt b/tests/amqpexchange_publish_confirms_consume.phpt index 354e8d31..e29ef7c1 100644 --- a/tests/amqpexchange_publish_confirms_consume.phpt +++ b/tests/amqpexchange_publish_confirms_consume.phpt @@ -26,7 +26,7 @@ $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->setFlags(AMQP_AUTODELETE); $ex->declareExchange(); -echo $ex->publish('message 1', 'routing.key', AMQP_MANDATORY) ? 'true' : 'false', PHP_EOL; +var_dump($ex->publish('message 1', 'routing.key', AMQP_MANDATORY)); // Create a new queue $q = new AMQPQueue($ch); @@ -47,7 +47,7 @@ try { echo get_class($e), "({$e->getCode()}): ", $e->getMessage(). PHP_EOL; } -echo $ex->publish('message 2', 'routing.key', AMQP_MANDATORY) ? 'true' : 'false', PHP_EOL; +var_dump($ex->publish('message 2', 'routing.key', AMQP_MANDATORY)); /* callback(int $reply_code, string $reply_text, string $exchange, string $routing_key, AMQPBasicProperties $properties, string $body); */ $ch->setReturnCallback(function ($reply_code, $reply_text, $exchange, $routing_key, AMQPBasicProperties $properties, $body) { @@ -79,13 +79,13 @@ try { $q->delete(); $ex->delete(); ?> ---EXPECTF-- -true -bool(false) +--EXPECT-- +NULL +NULL Unhandled basic.return method from server received. Use AMQPChannel::setReturnCallback() to process it. Unhandled basic.ack method from server received. Use AMQPChannel::setConfirmCallback() to process it. AMQPQueueException(0): Consumer timeout exceed -true +NULL Message returned: NO_ROUTE, message body:message 2 Message acked array(2) { diff --git a/tests/amqpexchange_publish_empty_routing_key.phpt b/tests/amqpexchange_publish_empty_routing_key.phpt index bab006f7..782d38f0 100644 --- a/tests/amqpexchange_publish_empty_routing_key.phpt +++ b/tests/amqpexchange_publish_empty_routing_key.phpt @@ -13,8 +13,8 @@ $ex = new AMQPExchange($ch); $ex->setName("exchange-" . microtime(true)); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); -echo $ex->publish('message') ? 'true' : 'false'; +var_dump($ex->publish('message')); $ex->delete(); ?> --EXPECT-- -true +NULL diff --git a/tests/amqpexchange_publish_mandatory.phpt b/tests/amqpexchange_publish_mandatory.phpt index 3ce304d5..c0ba2448 100644 --- a/tests/amqpexchange_publish_mandatory.phpt +++ b/tests/amqpexchange_publish_mandatory.phpt @@ -36,8 +36,8 @@ $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->setFlags(AMQP_AUTODELETE); $ex->declareExchange(); -echo $ex->publish('message 1', 'routing.key', AMQP_MANDATORY) ? 'true' : 'false', PHP_EOL; -echo $ex->publish('message 2', 'routing.key', AMQP_MANDATORY) ? 'true' : 'false', PHP_EOL; +var_dump($ex->publish('message 1', 'routing.key', AMQP_MANDATORY)); +var_dump($ex->publish('message 2', 'routing.key', AMQP_MANDATORY)); // Create a new queue $q = new AMQPQueue($ch); @@ -75,9 +75,9 @@ $ex->delete(); ?> --EXPECTF-- AMQPQueueException(0): Wait timeout exceed -true -true -bool(false) +NULL +NULL +NULL Unhandled basic.return method from server received. Use AMQPChannel::setReturnCallback() to process it. Message returned array(6) { @@ -91,35 +91,35 @@ array(6) { string(11) "routing.key" [4]=> object(AMQPBasicProperties)#7 (14) { - ["content_type":"AMQPBasicProperties":private]=> + ["contentType":"AMQPBasicProperties":private]=> string(10) "text/plain" - ["content_encoding":"AMQPBasicProperties":private]=> - string(0) "" + ["contentEncoding":"AMQPBasicProperties":private]=> + NULL ["headers":"AMQPBasicProperties":private]=> array(0) { } - ["delivery_mode":"AMQPBasicProperties":private]=> + ["deliveryMode":"AMQPBasicProperties":private]=> int(1) ["priority":"AMQPBasicProperties":private]=> int(0) - ["correlation_id":"AMQPBasicProperties":private]=> - string(0) "" - ["reply_to":"AMQPBasicProperties":private]=> - string(0) "" + ["correlationId":"AMQPBasicProperties":private]=> + NULL + ["replyTo":"AMQPBasicProperties":private]=> + NULL ["expiration":"AMQPBasicProperties":private]=> - string(0) "" - ["message_id":"AMQPBasicProperties":private]=> - string(0) "" + NULL + ["messageId":"AMQPBasicProperties":private]=> + NULL ["timestamp":"AMQPBasicProperties":private]=> int(0) ["type":"AMQPBasicProperties":private]=> - string(0) "" - ["user_id":"AMQPBasicProperties":private]=> - string(0) "" - ["app_id":"AMQPBasicProperties":private]=> - string(0) "" - ["cluster_id":"AMQPBasicProperties":private]=> - string(0) "" + NULL + ["userId":"AMQPBasicProperties":private]=> + NULL + ["appId":"AMQPBasicProperties":private]=> + NULL + ["clusterId":"AMQPBasicProperties":private]=> + NULL } [5]=> string(9) "message 2" diff --git a/tests/amqpexchange_publish_mandatory_consume.phpt b/tests/amqpexchange_publish_mandatory_consume.phpt index fde04f76..524bcf9f 100644 --- a/tests/amqpexchange_publish_mandatory_consume.phpt +++ b/tests/amqpexchange_publish_mandatory_consume.phpt @@ -26,7 +26,7 @@ $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->setFlags(AMQP_AUTODELETE); $ex->declareExchange(); -echo $ex->publish('message 1', 'routing.key', AMQP_MANDATORY) ? 'true' : 'false', PHP_EOL; +var_dump($ex->publish('message 1', 'routing.key', AMQP_MANDATORY)); // Create a new queue $q = new AMQPQueue($ch); @@ -47,7 +47,7 @@ try { echo get_class($e), "({$e->getCode()}): ", $e->getMessage(). PHP_EOL; } -echo $ex->publish('message 2', 'routing.key', AMQP_MANDATORY) ? 'true' : 'false', PHP_EOL; +var_dump($ex->publish('message 2', 'routing.key', AMQP_MANDATORY)); /* callback(int $reply_code, string $reply_text, string $exchange, string $routing_key, AMQPBasicProperties $properties, string $body); */ $ch->setReturnCallback(function ($reply_code, $reply_text, $exchange, $routing_key, AMQPBasicProperties $properties, $body) { @@ -72,11 +72,11 @@ $q->delete(); $ex->delete(); ?> --EXPECTF-- -true -bool(false) +NULL +NULL Unhandled basic.return method from server received. Use AMQPChannel::setReturnCallback() to process it. AMQPQueueException(0): Consumer timeout exceed -true +NULL Message returned array(6) { [0]=> @@ -89,35 +89,35 @@ array(6) { string(11) "routing.key" [4]=> object(AMQPBasicProperties)#9 (14) { - ["content_type":"AMQPBasicProperties":private]=> + ["contentType":"AMQPBasicProperties":private]=> string(10) "text/plain" - ["content_encoding":"AMQPBasicProperties":private]=> - string(0) "" + ["contentEncoding":"AMQPBasicProperties":private]=> + NULL ["headers":"AMQPBasicProperties":private]=> array(0) { } - ["delivery_mode":"AMQPBasicProperties":private]=> + ["deliveryMode":"AMQPBasicProperties":private]=> int(1) ["priority":"AMQPBasicProperties":private]=> int(0) - ["correlation_id":"AMQPBasicProperties":private]=> - string(0) "" - ["reply_to":"AMQPBasicProperties":private]=> - string(0) "" + ["correlationId":"AMQPBasicProperties":private]=> + NULL + ["replyTo":"AMQPBasicProperties":private]=> + NULL ["expiration":"AMQPBasicProperties":private]=> - string(0) "" - ["message_id":"AMQPBasicProperties":private]=> - string(0) "" + NULL + ["messageId":"AMQPBasicProperties":private]=> + NULL ["timestamp":"AMQPBasicProperties":private]=> int(0) ["type":"AMQPBasicProperties":private]=> - string(0) "" - ["user_id":"AMQPBasicProperties":private]=> - string(0) "" - ["app_id":"AMQPBasicProperties":private]=> - string(0) "" - ["cluster_id":"AMQPBasicProperties":private]=> - string(0) "" + NULL + ["userId":"AMQPBasicProperties":private]=> + NULL + ["appId":"AMQPBasicProperties":private]=> + NULL + ["clusterId":"AMQPBasicProperties":private]=> + NULL } [5]=> string(9) "message 2" diff --git a/tests/amqpexchange_publish_mandatory_multiple_channels_pitfal.phpt b/tests/amqpexchange_publish_mandatory_multiple_channels_pitfall.phpt similarity index 81% rename from tests/amqpexchange_publish_mandatory_multiple_channels_pitfal.phpt rename to tests/amqpexchange_publish_mandatory_multiple_channels_pitfall.phpt index 32741a16..0cc98bc6 100644 --- a/tests/amqpexchange_publish_mandatory_multiple_channels_pitfal.phpt +++ b/tests/amqpexchange_publish_mandatory_multiple_channels_pitfall.phpt @@ -46,11 +46,8 @@ $ex1->declareExchange(); $ex2 = new AMQPExchange($ch2); $ex2->setName($exchange_name); -echo $ex2->publish('message 1-2', 'routing.key', AMQP_MANDATORY) ? 'true' : 'false', PHP_EOL; -echo $ex2->publish('message 2-2', 'routing.key', AMQP_MANDATORY) ? 'true' : 'false', PHP_EOL; - -//echo $ex1->publish('message 1-1', 'routing.key', AMQP_MANDATORY) ? 'true' : 'false', PHP_EOL; -//echo $ex1->publish('message 2-1', 'routing.key', AMQP_MANDATORY) ? 'true' : 'false', PHP_EOL; +var_dump($ex2->publish('message 1-2', 'routing.key', AMQP_MANDATORY)); +var_dump($ex2->publish('message 2-2', 'routing.key', AMQP_MANDATORY)); // Create a new queue $q = new AMQPQueue($ch1); @@ -77,8 +74,8 @@ echo 'Connection active: ', ($cnn->isConnected() ? 'yes' : 'no'); --EXPECTF-- AMQPQueueException(0): Wait timeout exceed AMQPQueueException(0): Wait timeout exceed -true -true -bool(false) +NULL +NULL +NULL AMQPException(0): Library error: unexpected method received Connection active: no diff --git a/tests/amqpexchange_publish_null_routing_key.phpt b/tests/amqpexchange_publish_null_routing_key.phpt index 43cc1f03..8da9f2fc 100644 --- a/tests/amqpexchange_publish_null_routing_key.phpt +++ b/tests/amqpexchange_publish_null_routing_key.phpt @@ -13,8 +13,8 @@ $ex = new AMQPExchange($ch); $ex->setName("exchange-" . microtime(true)); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); -echo $ex->publish('message', null) ? 'true' : 'false'; +var_dump($ex->publish('message', null)); $ex->delete(); ?> --EXPECT-- -true +NULL diff --git a/tests/amqpexchange_publish_with_properties.phpt b/tests/amqpexchange_publish_with_properties.phpt index 19d1a963..7daf26d5 100644 --- a/tests/amqpexchange_publish_with_properties.phpt +++ b/tests/amqpexchange_publish_with_properties.phpt @@ -53,7 +53,7 @@ $attrs_control = array( //'headers' => 'not array', // should be array // NOTE: covered in tests/amqpexchange_publish_with_properties_ignore_num_header.phpt ); -echo $ex->publish('message', 'routing.key', AMQP_NOPARAM, $attrs) ? 'true' : 'false', PHP_EOL; +var_dump($ex->publish('message', 'routing.key', AMQP_NOPARAM, $attrs)); //var_dump($attrs, $attrs_control); @@ -70,7 +70,7 @@ $q->delete(); ?> --EXPECTF-- -true +NULL Message attributes are the same AMQPEnvelope getBody: @@ -100,7 +100,7 @@ AMQPEnvelope getExpiration: string(9) "100000000" getUserId: - string(0) "" + NULL getAppId: string(1) "5" getMessageId: diff --git a/tests/amqpexchange_publish_with_properties_ignore_num_header.phpt b/tests/amqpexchange_publish_with_properties_ignore_num_header.phpt index 2939eb89..c8343982 100644 --- a/tests/amqpexchange_publish_with_properties_ignore_num_header.phpt +++ b/tests/amqpexchange_publish_with_properties_ignore_num_header.phpt @@ -15,8 +15,8 @@ $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); -echo $ex->publish('message', 'routing.key', AMQP_NOPARAM, array('headers' => 'ignored')) ? 'true' : 'false', PHP_EOL; -echo $ex->publish('message', 'routing.key', AMQP_NOPARAM, array('headers' => array(2 => 'ignore_me'))) ? 'true' : 'false', PHP_EOL; +var_dump($ex->publish('message', 'routing.key', AMQP_NOPARAM, array('headers' => 'ignored'))); +var_dump($ex->publish('message', 'routing.key', AMQP_NOPARAM, array('headers' => array(2 => 'ignore_me')))); $ex->delete(); @@ -24,7 +24,7 @@ $ex->delete(); ?> --EXPECTF-- Warning: AMQPExchange::publish(): Ignoring non-string header field '0' in %s on line %d -true +NULL Warning: AMQPExchange::publish(): Ignoring non-string header field '2' in %s on line %d -true +NULL 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 792ddd87..3e1716df 100644 --- a/tests/amqpexchange_publish_with_properties_ignore_unsupported_header_values.phpt +++ b/tests/amqpexchange_publish_with_properties_ignore_unsupported_header_values.phpt @@ -22,7 +22,7 @@ $attrs = array( ), ); -echo $ex->publish('message', 'routing.key', AMQP_NOPARAM, $attrs) ? 'true' : 'false'; +var_dump($ex->publish('message', 'routing.key', AMQP_NOPARAM, $attrs)); $ex->delete(); @@ -32,4 +32,4 @@ $ex->delete(); Warning: AMQPExchange::publish(): Ignoring field 'object' due to unsupported value type (object) in %s on line %d Warning: AMQPExchange::publish(): Ignoring field 'resource' due to unsupported value type (resource) in %s on line %d -true +NULL diff --git a/tests/amqpexchange_publish_with_properties_user_id_failure.phpt b/tests/amqpexchange_publish_with_properties_user_id_failure.phpt index 0c304b7e..09458cfb 100644 --- a/tests/amqpexchange_publish_with_properties_user_id_failure.phpt +++ b/tests/amqpexchange_publish_with_properties_user_id_failure.phpt @@ -19,7 +19,7 @@ echo "Connection ", $cnn->isConnected() ? 'connected' : 'disconnected', PHP_EOL; try { // NOTE: basic.publish is asynchronous, so ... - echo $ex->publish('message', 'routing.key', AMQP_NOPARAM, array('user_id' => 'unknown-' . microtime(true))) ? 'true' : 'false', PHP_EOL; + var_dump($ex->publish('message', 'routing.key', AMQP_NOPARAM, array('user_id' => 'unknown-' . microtime(true)))); } catch (AMQPException $e) { echo get_class($e), "({$e->getCode()}): ", $e->getMessage(), PHP_EOL; } @@ -46,7 +46,7 @@ echo "Connection ", $cnn->isConnected() ? 'connected' : 'disconnected', PHP_EOL; --EXPECTF-- Channel connected Connection connected -true +NULL Channel connected Connection connected AMQPQueueException(406): Server channel error: 406, message: PRECONDITION_FAILED - user_id property set to 'unknown-%f' but authenticated user was 'guest' diff --git a/tests/amqpexchange_publish_with_timestamp_header.phpt b/tests/amqpexchange_publish_with_timestamp_header.phpt index cc435572..39dfafb4 100644 --- a/tests/amqpexchange_publish_with_timestamp_header.phpt +++ b/tests/amqpexchange_publish_with_timestamp_header.phpt @@ -38,14 +38,14 @@ array(1) { ["headerName"]=> object(AMQPTimestamp)#%d (1) { ["timestamp":"AMQPTimestamp":private]=> - string(10) "1488578462" + float(1488578462) } } array(1) { ["headerName"]=> object(AMQPTimestamp)#%d (1) { ["timestamp":"AMQPTimestamp":private]=> - string(10) "1488578462" + float(1488578462) } } same diff --git a/tests/amqpexchange_publish_xdeath.phpt b/tests/amqpexchange_publish_xdeath.phpt index 91e56048..437ff129 100644 --- a/tests/amqpexchange_publish_xdeath.phpt +++ b/tests/amqpexchange_publish_xdeath.phpt @@ -76,7 +76,7 @@ function assert_xdeath(AMQPEnvelope $envelope, $exchangeName, $queueName) { return 'unexpected-reason: ' . json_encode($header); } - if (!isset($header[0]['time']) || !$header[0]['time'] instanceof AMQPTimestamp) { + if (!isset($header[0]['time']) || !$header[0]['time'] instanceof AMQPTimestamp || $header[0]['time']->getTimestamp() < 1690465578) { return 'unexpected-time: ' . json_encode($header); } diff --git a/tests/amqpexchange_setArgument.phpt b/tests/amqpexchange_setArgument.phpt index 486e16b1..8a715bca 100644 --- a/tests/amqpexchange_setArgument.phpt +++ b/tests/amqpexchange_setArgument.phpt @@ -44,97 +44,9 @@ var_dump($ex); --EXPECTF-- object(AMQPExchange)#3 (9) { ["connection":"AMQPExchange":private]=> - object(AMQPConnection)#1 (18) { - ["login":"AMQPConnection":private]=> - string(5) "guest" - ["password":"AMQPConnection":private]=> - string(5) "guest" - ["host":"AMQPConnection":private]=> - string(9) "localhost" - ["vhost":"AMQPConnection":private]=> - string(1) "/" - ["port":"AMQPConnection":private]=> - int(5672) - ["read_timeout":"AMQPConnection":private]=> - float(0) - ["write_timeout":"AMQPConnection":private]=> - float(0) - ["connect_timeout":"AMQPConnection":private]=> - float(0) - ["rpc_timeout":"AMQPConnection":private]=> - float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> - int(131072) - ["heartbeat":"AMQPConnection":private]=> - int(0) - ["cacert":"AMQPConnection":private]=> - string(0) "" - ["key":"AMQPConnection":private]=> - string(0) "" - ["cert":"AMQPConnection":private]=> - string(0) "" - ["verify":"AMQPConnection":private]=> - bool(true) - ["sasl_method":"AMQPConnection":private]=> - int(0) - ["connection_name":"AMQPConnection":private]=> - NULL - } + %a ["channel":"AMQPExchange":private]=> - object(AMQPChannel)#2 (6) { - ["connection":"AMQPChannel":private]=> - object(AMQPConnection)#1 (18) { - ["login":"AMQPConnection":private]=> - string(5) "guest" - ["password":"AMQPConnection":private]=> - string(5) "guest" - ["host":"AMQPConnection":private]=> - string(9) "localhost" - ["vhost":"AMQPConnection":private]=> - string(1) "/" - ["port":"AMQPConnection":private]=> - int(5672) - ["read_timeout":"AMQPConnection":private]=> - float(0) - ["write_timeout":"AMQPConnection":private]=> - float(0) - ["connect_timeout":"AMQPConnection":private]=> - float(0) - ["rpc_timeout":"AMQPConnection":private]=> - float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> - int(131072) - ["heartbeat":"AMQPConnection":private]=> - int(0) - ["cacert":"AMQPConnection":private]=> - string(0) "" - ["key":"AMQPConnection":private]=> - string(0) "" - ["cert":"AMQPConnection":private]=> - string(0) "" - ["verify":"AMQPConnection":private]=> - bool(true) - ["sasl_method":"AMQPConnection":private]=> - int(0) - ["connection_name":"AMQPConnection":private]=> - NULL - } - ["prefetch_count":"AMQPChannel":private]=> - int(3) - ["prefetch_size":"AMQPChannel":private]=> - int(0) - ["global_prefetch_count":"AMQPChannel":private]=> - int(0) - ["global_prefetch_size":"AMQPChannel":private]=> - int(0) - ["consumers":"AMQPChannel":private]=> - array(0) { - } - } + %a ["name":"AMQPExchange":private]=> string(%d) "test.exchange.ae.%f" ["type":"AMQPExchange":private]=> @@ -143,7 +55,7 @@ object(AMQPExchange)#3 (9) { bool(false) ["durable":"AMQPExchange":private]=> bool(false) - ["auto_delete":"AMQPExchange":private]=> + ["autoDelete":"AMQPExchange":private]=> bool(true) ["internal":"AMQPExchange":private]=> bool(false) @@ -153,97 +65,9 @@ object(AMQPExchange)#3 (9) { } object(AMQPExchange)#4 (9) { ["connection":"AMQPExchange":private]=> - object(AMQPConnection)#1 (18) { - ["login":"AMQPConnection":private]=> - string(5) "guest" - ["password":"AMQPConnection":private]=> - string(5) "guest" - ["host":"AMQPConnection":private]=> - string(9) "localhost" - ["vhost":"AMQPConnection":private]=> - string(1) "/" - ["port":"AMQPConnection":private]=> - int(5672) - ["read_timeout":"AMQPConnection":private]=> - float(0) - ["write_timeout":"AMQPConnection":private]=> - float(0) - ["connect_timeout":"AMQPConnection":private]=> - float(0) - ["rpc_timeout":"AMQPConnection":private]=> - float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> - int(131072) - ["heartbeat":"AMQPConnection":private]=> - int(0) - ["cacert":"AMQPConnection":private]=> - string(0) "" - ["key":"AMQPConnection":private]=> - string(0) "" - ["cert":"AMQPConnection":private]=> - string(0) "" - ["verify":"AMQPConnection":private]=> - bool(true) - ["sasl_method":"AMQPConnection":private]=> - int(0) - ["connection_name":"AMQPConnection":private]=> - NULL - } + %a ["channel":"AMQPExchange":private]=> - object(AMQPChannel)#2 (6) { - ["connection":"AMQPChannel":private]=> - object(AMQPConnection)#1 (18) { - ["login":"AMQPConnection":private]=> - string(5) "guest" - ["password":"AMQPConnection":private]=> - string(5) "guest" - ["host":"AMQPConnection":private]=> - string(9) "localhost" - ["vhost":"AMQPConnection":private]=> - string(1) "/" - ["port":"AMQPConnection":private]=> - int(5672) - ["read_timeout":"AMQPConnection":private]=> - float(0) - ["write_timeout":"AMQPConnection":private]=> - float(0) - ["connect_timeout":"AMQPConnection":private]=> - float(0) - ["rpc_timeout":"AMQPConnection":private]=> - float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> - int(131072) - ["heartbeat":"AMQPConnection":private]=> - int(0) - ["cacert":"AMQPConnection":private]=> - string(0) "" - ["key":"AMQPConnection":private]=> - string(0) "" - ["cert":"AMQPConnection":private]=> - string(0) "" - ["verify":"AMQPConnection":private]=> - bool(true) - ["sasl_method":"AMQPConnection":private]=> - int(0) - ["connection_name":"AMQPConnection":private]=> - NULL - } - ["prefetch_count":"AMQPChannel":private]=> - int(3) - ["prefetch_size":"AMQPChannel":private]=> - int(0) - ["global_prefetch_count":"AMQPChannel":private]=> - int(0) - ["global_prefetch_size":"AMQPChannel":private]=> - int(0) - ["consumers":"AMQPChannel":private]=> - array(0) { - } - } + %a ["name":"AMQPExchange":private]=> string(%d) "test.exchange.%f" ["type":"AMQPExchange":private]=> @@ -252,7 +76,7 @@ object(AMQPExchange)#4 (9) { bool(false) ["durable":"AMQPExchange":private]=> bool(false) - ["auto_delete":"AMQPExchange":private]=> + ["autoDelete":"AMQPExchange":private]=> bool(true) ["internal":"AMQPExchange":private]=> bool(false) @@ -272,97 +96,9 @@ object(AMQPExchange)#4 (9) { } object(AMQPExchange)#4 (9) { ["connection":"AMQPExchange":private]=> - object(AMQPConnection)#1 (18) { - ["login":"AMQPConnection":private]=> - string(5) "guest" - ["password":"AMQPConnection":private]=> - string(5) "guest" - ["host":"AMQPConnection":private]=> - string(9) "localhost" - ["vhost":"AMQPConnection":private]=> - string(1) "/" - ["port":"AMQPConnection":private]=> - int(5672) - ["read_timeout":"AMQPConnection":private]=> - float(0) - ["write_timeout":"AMQPConnection":private]=> - float(0) - ["connect_timeout":"AMQPConnection":private]=> - float(0) - ["rpc_timeout":"AMQPConnection":private]=> - float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> - int(131072) - ["heartbeat":"AMQPConnection":private]=> - int(0) - ["cacert":"AMQPConnection":private]=> - string(0) "" - ["key":"AMQPConnection":private]=> - string(0) "" - ["cert":"AMQPConnection":private]=> - string(0) "" - ["verify":"AMQPConnection":private]=> - bool(true) - ["sasl_method":"AMQPConnection":private]=> - int(0) - ["connection_name":"AMQPConnection":private]=> - NULL - } + %a ["channel":"AMQPExchange":private]=> - object(AMQPChannel)#2 (6) { - ["connection":"AMQPChannel":private]=> - object(AMQPConnection)#1 (18) { - ["login":"AMQPConnection":private]=> - string(5) "guest" - ["password":"AMQPConnection":private]=> - string(5) "guest" - ["host":"AMQPConnection":private]=> - string(9) "localhost" - ["vhost":"AMQPConnection":private]=> - string(1) "/" - ["port":"AMQPConnection":private]=> - int(5672) - ["read_timeout":"AMQPConnection":private]=> - float(0) - ["write_timeout":"AMQPConnection":private]=> - float(0) - ["connect_timeout":"AMQPConnection":private]=> - float(0) - ["rpc_timeout":"AMQPConnection":private]=> - float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> - int(131072) - ["heartbeat":"AMQPConnection":private]=> - int(0) - ["cacert":"AMQPConnection":private]=> - string(0) "" - ["key":"AMQPConnection":private]=> - string(0) "" - ["cert":"AMQPConnection":private]=> - string(0) "" - ["verify":"AMQPConnection":private]=> - bool(true) - ["sasl_method":"AMQPConnection":private]=> - int(0) - ["connection_name":"AMQPConnection":private]=> - NULL - } - ["prefetch_count":"AMQPChannel":private]=> - int(3) - ["prefetch_size":"AMQPChannel":private]=> - int(0) - ["global_prefetch_count":"AMQPChannel":private]=> - int(0) - ["global_prefetch_size":"AMQPChannel":private]=> - int(0) - ["consumers":"AMQPChannel":private]=> - array(0) { - } - } + %a ["name":"AMQPExchange":private]=> string(%d) "test.exchange.%f" ["type":"AMQPExchange":private]=> @@ -371,7 +107,7 @@ object(AMQPExchange)#4 (9) { bool(false) ["durable":"AMQPExchange":private]=> bool(false) - ["auto_delete":"AMQPExchange":private]=> + ["autoDelete":"AMQPExchange":private]=> bool(true) ["internal":"AMQPExchange":private]=> bool(false) diff --git a/tests/amqpexchange_set_flags.phpt b/tests/amqpexchange_set_flags.phpt index 40349876..6779e9ee 100644 --- a/tests/amqpexchange_set_flags.phpt +++ b/tests/amqpexchange_set_flags.phpt @@ -2,7 +2,7 @@ AMQPExchange setFlags() --SKIPIF-- - object(AMQPConnection)#1 (18) { - ["login":"AMQPConnection":private]=> - string(5) "guest" - ["password":"AMQPConnection":private]=> - string(5) "guest" - ["host":"AMQPConnection":private]=> - string(9) "localhost" - ["vhost":"AMQPConnection":private]=> - string(1) "/" - ["port":"AMQPConnection":private]=> - int(5672) - ["read_timeout":"AMQPConnection":private]=> - float(0) - ["write_timeout":"AMQPConnection":private]=> - float(0) - ["connect_timeout":"AMQPConnection":private]=> - float(0) - ["rpc_timeout":"AMQPConnection":private]=> - float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> - int(131072) - ["heartbeat":"AMQPConnection":private]=> - int(0) - ["cacert":"AMQPConnection":private]=> - string(0) "" - ["key":"AMQPConnection":private]=> - string(0) "" - ["cert":"AMQPConnection":private]=> - string(0) "" - ["verify":"AMQPConnection":private]=> - bool(true) - ["sasl_method":"AMQPConnection":private]=> - int(0) - ["connection_name":"AMQPConnection":private]=> - NULL - } - ["channel":"AMQPExchange":private]=> - object(AMQPChannel)#2 (6) { - ["connection":"AMQPChannel":private]=> - object(AMQPConnection)#1 (18) { - ["login":"AMQPConnection":private]=> - string(5) "guest" - ["password":"AMQPConnection":private]=> - string(5) "guest" - ["host":"AMQPConnection":private]=> - string(9) "localhost" - ["vhost":"AMQPConnection":private]=> - string(1) "/" - ["port":"AMQPConnection":private]=> - int(5672) - ["read_timeout":"AMQPConnection":private]=> - float(0) - ["write_timeout":"AMQPConnection":private]=> - float(0) - ["connect_timeout":"AMQPConnection":private]=> - float(0) - ["rpc_timeout":"AMQPConnection":private]=> - float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> - int(131072) - ["heartbeat":"AMQPConnection":private]=> - int(0) - ["cacert":"AMQPConnection":private]=> - string(0) "" - ["key":"AMQPConnection":private]=> - string(0) "" - ["cert":"AMQPConnection":private]=> - string(0) "" - ["verify":"AMQPConnection":private]=> - bool(true) - ["sasl_method":"AMQPConnection":private]=> - int(0) - ["connection_name":"AMQPConnection":private]=> - NULL - } - ["prefetch_count":"AMQPChannel":private]=> - int(3) - ["prefetch_size":"AMQPChannel":private]=> - int(0) - ["global_prefetch_count":"AMQPChannel":private]=> - int(0) - ["global_prefetch_size":"AMQPChannel":private]=> - int(0) - ["consumers":"AMQPChannel":private]=> - array(0) { - } - } + %a ["name":"AMQPExchange":private]=> string(%d) "exchange-%f" ["type":"AMQPExchange":private]=> @@ -121,7 +31,7 @@ object(AMQPExchange)#3 (9) { bool(true) ["durable":"AMQPExchange":private]=> bool(true) - ["auto_delete":"AMQPExchange":private]=> + ["autoDelete":"AMQPExchange":private]=> bool(true) ["internal":"AMQPExchange":private]=> bool(true) diff --git a/tests/amqpexchange_type.phpt b/tests/amqpexchange_type.phpt new file mode 100644 index 00000000..1c997746 --- /dev/null +++ b/tests/amqpexchange_type.phpt @@ -0,0 +1,34 @@ +--TEST-- +AMQPExchange getConnection test +--SKIPIF-- + +--FILE-- +connect(); +$ch = new AMQPChannel($cnn); + +$ex = new AMQPExchange($ch); +var_dump($ex->getType()); +$ex->setType(AMQP_EX_TYPE_FANOUT); +var_dump($ex->getType()); +$ex->setType(null); +var_dump($ex->getType()); +$ex->setType(AMQP_EX_TYPE_DIRECT); +var_dump($ex->getType()); +$ex->setType(""); +var_dump($ex->getType()); +?> +==DONE== +--EXPECT-- +NULL +string(6) "fanout" +NULL +string(6) "direct" +NULL +==DONE== \ No newline at end of file diff --git a/tests/amqpexchange_unbind.phpt b/tests/amqpexchange_unbind.phpt index ced46f7f..0997e43f 100644 --- a/tests/amqpexchange_unbind.phpt +++ b/tests/amqpexchange_unbind.phpt @@ -28,6 +28,6 @@ var_dump($ex->unbind($ex2->getName(), 'test-key-1')); ?> --EXPECT-- -bool(true) -bool(true) -bool(true) \ No newline at end of file +NULL +NULL +NULL \ No newline at end of file diff --git a/tests/amqpexchange_unbind_with_arguments.phpt b/tests/amqpexchange_unbind_with_arguments.phpt index e95e4b7b..3a0955db 100644 --- a/tests/amqpexchange_unbind_with_arguments.phpt +++ b/tests/amqpexchange_unbind_with_arguments.phpt @@ -30,6 +30,6 @@ var_dump($ex->unbind($ex2->getName(), 'test', array('test' => 'passed', 'at' => ?> --EXPECT-- -bool(true) -bool(true) -bool(true) \ No newline at end of file +NULL +NULL +NULL \ No newline at end of file diff --git a/tests/amqpexchange_unbind_without_key.phpt b/tests/amqpexchange_unbind_without_key.phpt index d8a4b791..bbd77760 100644 --- a/tests/amqpexchange_unbind_without_key.phpt +++ b/tests/amqpexchange_unbind_without_key.phpt @@ -28,6 +28,6 @@ var_dump($ex->unbind($ex2->getName())); ?> --EXPECT-- -bool(true) -bool(true) -bool(true) \ No newline at end of file +NULL +NULL +NULL \ No newline at end of file diff --git a/tests/amqpexchange_unbind_without_key_with_arguments.phpt b/tests/amqpexchange_unbind_without_key_with_arguments.phpt index 3db697c7..863b2777 100644 --- a/tests/amqpexchange_unbind_without_key_with_arguments.phpt +++ b/tests/amqpexchange_unbind_without_key_with_arguments.phpt @@ -33,9 +33,9 @@ var_dump($ex->unbind($ex2->getName(), '', array('test' => 'passed', 'at' => $tim ?> --EXPECT-- -bool(true) -bool(true) -bool(true) -bool(true) -bool(true) -bool(true) \ No newline at end of file +NULL +NULL +NULL +NULL +NULL +NULL \ No newline at end of file diff --git a/tests/amqpexchange_var_dump.phpt b/tests/amqpexchange_var_dump.phpt index e1249b2d..5bd41cdd 100644 --- a/tests/amqpexchange_var_dump.phpt +++ b/tests/amqpexchange_var_dump.phpt @@ -2,7 +2,7 @@ AMQPExchange var_dump --SKIPIF-- - object(AMQPConnection)#1 (18) { - ["login":"AMQPConnection":private]=> - string(5) "guest" - ["password":"AMQPConnection":private]=> - string(5) "guest" - ["host":"AMQPConnection":private]=> - string(9) "localhost" - ["vhost":"AMQPConnection":private]=> - string(1) "/" - ["port":"AMQPConnection":private]=> - int(5672) - ["read_timeout":"AMQPConnection":private]=> - float(0) - ["write_timeout":"AMQPConnection":private]=> - float(0) - ["connect_timeout":"AMQPConnection":private]=> - float(0) - ["rpc_timeout":"AMQPConnection":private]=> - float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> - int(131072) - ["heartbeat":"AMQPConnection":private]=> - int(0) - ["cacert":"AMQPConnection":private]=> - string(0) "" - ["key":"AMQPConnection":private]=> - string(0) "" - ["cert":"AMQPConnection":private]=> - string(0) "" - ["verify":"AMQPConnection":private]=> - bool(true) - ["sasl_method":"AMQPConnection":private]=> - int(0) - ["connection_name":"AMQPConnection":private]=> - NULL - } + %a ["channel":"AMQPExchange":private]=> - object(AMQPChannel)#2 (6) { - ["connection":"AMQPChannel":private]=> - object(AMQPConnection)#1 (18) { - ["login":"AMQPConnection":private]=> - string(5) "guest" - ["password":"AMQPConnection":private]=> - string(5) "guest" - ["host":"AMQPConnection":private]=> - string(9) "localhost" - ["vhost":"AMQPConnection":private]=> - string(1) "/" - ["port":"AMQPConnection":private]=> - int(5672) - ["read_timeout":"AMQPConnection":private]=> - float(0) - ["write_timeout":"AMQPConnection":private]=> - float(0) - ["connect_timeout":"AMQPConnection":private]=> - float(0) - ["rpc_timeout":"AMQPConnection":private]=> - float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> - int(131072) - ["heartbeat":"AMQPConnection":private]=> - int(0) - ["cacert":"AMQPConnection":private]=> - string(0) "" - ["key":"AMQPConnection":private]=> - string(0) "" - ["cert":"AMQPConnection":private]=> - string(0) "" - ["verify":"AMQPConnection":private]=> - bool(true) - ["sasl_method":"AMQPConnection":private]=> - int(0) - ["connection_name":"AMQPConnection":private]=> - NULL - } - ["prefetch_count":"AMQPChannel":private]=> - int(3) - ["prefetch_size":"AMQPChannel":private]=> - int(0) - ["global_prefetch_count":"AMQPChannel":private]=> - int(0) - ["global_prefetch_size":"AMQPChannel":private]=> - int(0) - ["consumers":"AMQPChannel":private]=> - array(0) { - } - } + %a ["name":"AMQPExchange":private]=> string(%d) "exchange-%f" ["type":"AMQPExchange":private]=> @@ -120,7 +32,7 @@ object(AMQPExchange)#3 (9) { bool(false) ["durable":"AMQPExchange":private]=> bool(false) - ["auto_delete":"AMQPExchange":private]=> + ["autoDelete":"AMQPExchange":private]=> bool(false) ["internal":"AMQPExchange":private]=> bool(false) @@ -130,97 +42,9 @@ object(AMQPExchange)#3 (9) { } object(AMQPExchange)#3 (9) { ["connection":"AMQPExchange":private]=> - object(AMQPConnection)#1 (18) { - ["login":"AMQPConnection":private]=> - string(5) "guest" - ["password":"AMQPConnection":private]=> - string(5) "guest" - ["host":"AMQPConnection":private]=> - string(9) "localhost" - ["vhost":"AMQPConnection":private]=> - string(1) "/" - ["port":"AMQPConnection":private]=> - int(5672) - ["read_timeout":"AMQPConnection":private]=> - float(0) - ["write_timeout":"AMQPConnection":private]=> - float(0) - ["connect_timeout":"AMQPConnection":private]=> - float(0) - ["rpc_timeout":"AMQPConnection":private]=> - float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> - int(131072) - ["heartbeat":"AMQPConnection":private]=> - int(0) - ["cacert":"AMQPConnection":private]=> - string(0) "" - ["key":"AMQPConnection":private]=> - string(0) "" - ["cert":"AMQPConnection":private]=> - string(0) "" - ["verify":"AMQPConnection":private]=> - bool(true) - ["sasl_method":"AMQPConnection":private]=> - int(0) - ["connection_name":"AMQPConnection":private]=> - NULL - } + %a ["channel":"AMQPExchange":private]=> - object(AMQPChannel)#2 (6) { - ["connection":"AMQPChannel":private]=> - object(AMQPConnection)#1 (18) { - ["login":"AMQPConnection":private]=> - string(5) "guest" - ["password":"AMQPConnection":private]=> - string(5) "guest" - ["host":"AMQPConnection":private]=> - string(9) "localhost" - ["vhost":"AMQPConnection":private]=> - string(1) "/" - ["port":"AMQPConnection":private]=> - int(5672) - ["read_timeout":"AMQPConnection":private]=> - float(0) - ["write_timeout":"AMQPConnection":private]=> - float(0) - ["connect_timeout":"AMQPConnection":private]=> - float(0) - ["rpc_timeout":"AMQPConnection":private]=> - float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> - int(131072) - ["heartbeat":"AMQPConnection":private]=> - int(0) - ["cacert":"AMQPConnection":private]=> - string(0) "" - ["key":"AMQPConnection":private]=> - string(0) "" - ["cert":"AMQPConnection":private]=> - string(0) "" - ["verify":"AMQPConnection":private]=> - bool(true) - ["sasl_method":"AMQPConnection":private]=> - int(0) - ["connection_name":"AMQPConnection":private]=> - NULL - } - ["prefetch_count":"AMQPChannel":private]=> - int(3) - ["prefetch_size":"AMQPChannel":private]=> - int(0) - ["global_prefetch_count":"AMQPChannel":private]=> - int(0) - ["global_prefetch_size":"AMQPChannel":private]=> - int(0) - ["consumers":"AMQPChannel":private]=> - array(0) { - } - } + %a ["name":"AMQPExchange":private]=> string(%d) "exchange-%f" ["type":"AMQPExchange":private]=> @@ -229,7 +53,7 @@ object(AMQPExchange)#3 (9) { bool(false) ["durable":"AMQPExchange":private]=> bool(false) - ["auto_delete":"AMQPExchange":private]=> + ["autoDelete":"AMQPExchange":private]=> bool(false) ["internal":"AMQPExchange":private]=> bool(false) diff --git a/tests/amqpqueue-cancel-no-consumers.phpt b/tests/amqpqueue-cancel-no-consumers.phpt index db55e5f1..11fa2c31 100644 --- a/tests/amqpqueue-cancel-no-consumers.phpt +++ b/tests/amqpqueue-cancel-no-consumers.phpt @@ -23,7 +23,7 @@ $exchange_name = 'exchnage-test-.' . $microtime; $queue_1 = new \AMQPQueue($extChannel); $queue_1->setName($queue_name); $queue_1->declareQueue(); -$queue_1->purge(); +var_dump($queue_1->purge()); $exchange = new \AMQPExchange($extChannel); $exchange->setType(AMQP_EX_TYPE_DIRECT); @@ -42,4 +42,5 @@ $queue_1->cancel($consumer_tag); echo "Canceled", PHP_EOL; --EXPECTF-- +int(0) Canceled diff --git a/tests/amqpqueue_attributes.phpt b/tests/amqpqueue_attributes.phpt index 3bf44905..0824b5bd 100644 --- a/tests/amqpqueue_attributes.phpt +++ b/tests/amqpqueue_attributes.phpt @@ -11,10 +11,10 @@ $ch = new AMQPChannel($cnn); $q = new AMQPQueue($ch); -$q->setArguments($arr = array('existent' => 'value', 'false' => false)); +var_dump($q->setArguments($arr = array('existent' => 'value', 'false' => false))); echo 'Initial args: ', count($arr), ', queue args: ', count($q->getArguments()), PHP_EOL; -$q->setArgument('foo', 'bar'); +var_dump($q->setArgument('foo', 'bar')); echo 'Initial args: ', count($arr), ', queue args: ', count($q->getArguments()), PHP_EOL; foreach (array('existent', 'false', 'nonexistent') as $key) { @@ -23,8 +23,10 @@ foreach (array('existent', 'false', 'nonexistent') as $key) { ?> --EXPECT-- +NULL Initial args: 2, queue args: 2 +NULL Initial args: 2, queue args: 3 existent: true, 'value' false: true, false -nonexistent: false, false +nonexistent: false, NULL diff --git a/tests/amqpqueue_bind_basic.phpt b/tests/amqpqueue_bind_basic.phpt index bfa89eb9..63df92d7 100644 --- a/tests/amqpqueue_bind_basic.phpt +++ b/tests/amqpqueue_bind_basic.phpt @@ -23,4 +23,4 @@ $queue->delete(); $ex->delete(); ?> --EXPECT-- -bool(true) +NULL diff --git a/tests/amqpqueue_bind_basic_empty_routing_key.phpt b/tests/amqpqueue_bind_basic_empty_routing_key.phpt index 21fc2449..cf497901 100644 --- a/tests/amqpqueue_bind_basic_empty_routing_key.phpt +++ b/tests/amqpqueue_bind_basic_empty_routing_key.phpt @@ -12,15 +12,19 @@ $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); $ex->setName('exchange-' . microtime(true)); $ex->setType(AMQP_EX_TYPE_DIRECT); -$ex->declareExchange(); +var_dump($ex->declareExchange()); $queue = new AMQPQueue($ch); $queue->setName("queue-" . microtime(true)); -$queue->declareQueue(); +var_dump($queue->declareQueue()); var_dump($queue->bind($ex->getName())); -$queue->delete(); -$ex->delete(); +var_dump($queue->delete()); +var_dump($ex->delete()); ?> --EXPECT-- -bool(true) +NULL +int(0) +NULL +int(0) +NULL diff --git a/tests/amqpqueue_bind_basic_headers_arguments.phpt b/tests/amqpqueue_bind_basic_headers_arguments.phpt index dffe3085..ba7ee13c 100644 --- a/tests/amqpqueue_bind_basic_headers_arguments.phpt +++ b/tests/amqpqueue_bind_basic_headers_arguments.phpt @@ -12,17 +12,21 @@ $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); $ex->setName('exchange-' . microtime(true)); $ex->setType(AMQP_EX_TYPE_HEADERS); -$ex->declareExchange(); +var_dump($ex->declareExchange()); $queue = new AMQPQueue($ch); $queue->setName("queue-" . microtime(true)); -$queue->declareQueue(); +var_dump($queue->declareQueue()); $arguments = array('x-match' => 'all', 'type' => 'custom'); var_dump($queue->bind($ex->getName(), '', $arguments)); -$queue->delete(); -$ex->delete(); +var_dump($queue->delete()); +var_dump($ex->delete()); ?> --EXPECT-- -bool(true) +NULL +int(0) +NULL +int(0) +NULL diff --git a/tests/amqpqueue_bind_null_routing_key.phpt b/tests/amqpqueue_bind_null_routing_key.phpt index 758f3840..533a9a10 100644 --- a/tests/amqpqueue_bind_null_routing_key.phpt +++ b/tests/amqpqueue_bind_null_routing_key.phpt @@ -12,15 +12,19 @@ $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); $ex->setName('exchange-' . microtime(true)); $ex->setType(AMQP_EX_TYPE_DIRECT); -$ex->declareExchange(); +var_dump($ex->declareExchange()); $queue = new AMQPQueue($ch); $queue->setName("queue-" . microtime(true)); -$queue->declareQueue(); -echo $queue->bind($ex->getName(), null) ? 'true' : 'false'; +var_dump($queue->declareQueue()); +var_dump($queue->bind($ex->getName(), null)); -$queue->delete(); -$ex->delete(); +var_dump($queue->delete()); +var_dump($ex->delete()); ?> --EXPECT-- -true +NULL +int(0) +NULL +int(0) +NULL diff --git a/tests/amqpqueue_consume_basic.phpt b/tests/amqpqueue_consume_basic.phpt index c7e67749..18ac0442 100644 --- a/tests/amqpqueue_consume_basic.phpt +++ b/tests/amqpqueue_consume_basic.phpt @@ -75,25 +75,25 @@ AMQPEnvelope isRedelivery: bool(false) getContentEncoding: - string(0) "" + NULL getType: - string(0) "" + NULL getTimeStamp: int(0) getPriority: int(0) getExpiration: - string(0) "" + NULL getUserId: - string(0) "" + NULL getAppId: - string(0) "" + NULL getMessageId: - string(0) "" + NULL getReplyTo: - string(0) "" + NULL getCorrelationId: - string(0) "" + NULL getHeaders: array(1) { ["foo"]=> @@ -119,25 +119,25 @@ AMQPEnvelope isRedelivery: bool(false) getContentEncoding: - string(0) "" + NULL getType: - string(0) "" + NULL getTimeStamp: int(0) getPriority: int(0) getExpiration: - string(0) "" + NULL getUserId: - string(0) "" + NULL getAppId: - string(0) "" + NULL getMessageId: - string(0) "" + NULL getReplyTo: - string(0) "" + NULL getCorrelationId: - string(0) "" + NULL getHeaders: array(0) { } diff --git a/tests/amqpqueue_declare_basic.phpt b/tests/amqpqueue_declare_basic.phpt index 68b98a69..ee08e616 100644 --- a/tests/amqpqueue_declare_basic.phpt +++ b/tests/amqpqueue_declare_basic.phpt @@ -14,12 +14,16 @@ $ex->setType(AMQP_EX_TYPE_DIRECT); $ex->declareExchange(); $queue = new AMQPQueue($ch); -$queue->setName("queue-" . microtime(true)); -$queue->declareQueue(); +var_dump($queue->setName("queue-" . microtime(true))); +var_dump($queue->declareQueue()); var_dump($queue->bind($ex->getName(), 'routing.key')); -$queue->delete(); -$ex->delete(); +var_dump($queue->delete()); +var_dump($ex->delete()); ?> --EXPECT-- -bool(true) +NULL +int(0) +NULL +int(0) +NULL diff --git a/tests/amqpqueue_declare_with_arguments.phpt b/tests/amqpqueue_declare_with_arguments.phpt index f92ae505..065e79b3 100644 --- a/tests/amqpqueue_declare_with_arguments.phpt +++ b/tests/amqpqueue_declare_with_arguments.phpt @@ -14,16 +14,20 @@ $ex->setType(AMQP_EX_TYPE_DIRECT); $ex->declareExchange(); $queue = new AMQPQueue($ch); -$queue->setName("queue-" . microtime(true)); -$queue->setArgument('x-dead-letter-exchange', ''); -$queue->setArgument('x-dead-letter-routing-key', 'some key'); -$queue->setArgument('x-message-ttl', 42); -$queue->setFlags(AMQP_AUTODELETE); -$res = $queue->declareQueue(); +var_dump($queue->setName("queue-" . microtime(true))); +var_dump($queue->setArgument('x-dead-letter-exchange', '')); +var_dump($queue->setArgument('x-dead-letter-routing-key', 'some key')); +var_dump($queue->setArgument('x-message-ttl', 42)); +var_dump($queue->setFlags(AMQP_AUTODELETE)); +var_dump($queue->declareQueue()); -var_dump($res); - -$queue->delete(); +var_dump($queue->delete()); ?> --EXPECT-- +NULL +NULL +NULL +NULL +NULL +int(0) int(0) diff --git a/tests/amqpqueue_get_basic.phpt b/tests/amqpqueue_get_basic.phpt index 759e896d..29d7b09d 100644 --- a/tests/amqpqueue_get_basic.phpt +++ b/tests/amqpqueue_get_basic.phpt @@ -58,25 +58,25 @@ AMQPEnvelope isRedelivery: bool(false) getContentEncoding: - string(0) "" + NULL getType: - string(0) "" + NULL getTimeStamp: int(0) getPriority: int(0) getExpiration: - string(0) "" + NULL getUserId: - string(0) "" + NULL getAppId: - string(0) "" + NULL getMessageId: - string(0) "" + NULL getReplyTo: - string(0) "" + NULL getCorrelationId: - string(0) "" + NULL getHeaders: array(1) { ["foo"]=> @@ -102,25 +102,25 @@ AMQPEnvelope isRedelivery: bool(false) getContentEncoding: - string(0) "" + NULL getType: - string(0) "" + NULL getTimeStamp: int(0) getPriority: int(0) getExpiration: - string(0) "" + NULL getUserId: - string(0) "" + NULL getAppId: - string(0) "" + NULL getMessageId: - string(0) "" + NULL getReplyTo: - string(0) "" + NULL getCorrelationId: - string(0) "" + NULL getHeaders: array(0) { } @@ -144,28 +144,28 @@ AMQPEnvelope isRedelivery: bool(false) getContentEncoding: - string(0) "" + NULL getType: - string(0) "" + NULL getTimeStamp: int(0) getPriority: int(0) getExpiration: - string(0) "" + NULL getUserId: - string(0) "" + NULL getAppId: - string(0) "" + NULL getMessageId: - string(0) "" + NULL getReplyTo: - string(0) "" + NULL getCorrelationId: - string(0) "" + NULL getHeaders: array(0) { } call #3 -bool(false) +NULL diff --git a/tests/amqpqueue_get_connection.phpt b/tests/amqpqueue_get_connection.phpt index d88c7f76..fcb885d7 100644 --- a/tests/amqpqueue_get_connection.phpt +++ b/tests/amqpqueue_get_connection.phpt @@ -2,7 +2,7 @@ AMQPQueue getConnection test --SKIPIF-- diff --git a/tests/amqpqueue_get_empty_body.phpt b/tests/amqpqueue_get_empty_body.phpt index 89e9ab1f..b301b277 100644 --- a/tests/amqpqueue_get_empty_body.phpt +++ b/tests/amqpqueue_get_empty_body.phpt @@ -32,7 +32,7 @@ echo "'" . $msg->getBody() . "'\n"; $msg = $q->get(AMQP_AUTOACK); -if ($msg === FALSE) { +if ($msg === null) { echo "No more messages\n"; } diff --git a/tests/amqpqueue_nested_headers.phpt b/tests/amqpqueue_nested_headers.phpt index b24da4d5..d6933521 100644 --- a/tests/amqpqueue_nested_headers.phpt +++ b/tests/amqpqueue_nested_headers.phpt @@ -76,7 +76,7 @@ array(1) { ["time"]=> object(AMQPTimestamp)#%d (1) { ["timestamp":"AMQPTimestamp":private]=> - string(10) "%s" + float(%d) } ["exchange"]=> string(%d) "exchange-%f" diff --git a/tests/amqpqueue_setArgument.phpt b/tests/amqpqueue_setArgument.phpt index 1ffc3c5a..3e999118 100644 --- a/tests/amqpqueue_setArgument.phpt +++ b/tests/amqpqueue_setArgument.phpt @@ -38,100 +38,12 @@ var_dump($q_dead); --EXPECTF-- object(AMQPQueue)#3 (9) { ["connection":"AMQPQueue":private]=> - object(AMQPConnection)#1 (18) { - ["login":"AMQPConnection":private]=> - string(5) "guest" - ["password":"AMQPConnection":private]=> - string(5) "guest" - ["host":"AMQPConnection":private]=> - string(9) "localhost" - ["vhost":"AMQPConnection":private]=> - string(1) "/" - ["port":"AMQPConnection":private]=> - int(5672) - ["read_timeout":"AMQPConnection":private]=> - float(0) - ["write_timeout":"AMQPConnection":private]=> - float(0) - ["connect_timeout":"AMQPConnection":private]=> - float(0) - ["rpc_timeout":"AMQPConnection":private]=> - float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> - int(131072) - ["heartbeat":"AMQPConnection":private]=> - int(0) - ["cacert":"AMQPConnection":private]=> - string(0) "" - ["key":"AMQPConnection":private]=> - string(0) "" - ["cert":"AMQPConnection":private]=> - string(0) "" - ["verify":"AMQPConnection":private]=> - bool(true) - ["sasl_method":"AMQPConnection":private]=> - int(0) - ["connection_name":"AMQPConnection":private]=> - NULL - } + %a ["channel":"AMQPQueue":private]=> - object(AMQPChannel)#2 (6) { - ["connection":"AMQPChannel":private]=> - object(AMQPConnection)#1 (18) { - ["login":"AMQPConnection":private]=> - string(5) "guest" - ["password":"AMQPConnection":private]=> - string(5) "guest" - ["host":"AMQPConnection":private]=> - string(9) "localhost" - ["vhost":"AMQPConnection":private]=> - string(1) "/" - ["port":"AMQPConnection":private]=> - int(5672) - ["read_timeout":"AMQPConnection":private]=> - float(0) - ["write_timeout":"AMQPConnection":private]=> - float(0) - ["connect_timeout":"AMQPConnection":private]=> - float(0) - ["rpc_timeout":"AMQPConnection":private]=> - float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> - int(131072) - ["heartbeat":"AMQPConnection":private]=> - int(0) - ["cacert":"AMQPConnection":private]=> - string(0) "" - ["key":"AMQPConnection":private]=> - string(0) "" - ["cert":"AMQPConnection":private]=> - string(0) "" - ["verify":"AMQPConnection":private]=> - bool(true) - ["sasl_method":"AMQPConnection":private]=> - int(0) - ["connection_name":"AMQPConnection":private]=> - NULL - } - ["prefetch_count":"AMQPChannel":private]=> - int(3) - ["prefetch_size":"AMQPChannel":private]=> - int(0) - ["global_prefetch_count":"AMQPChannel":private]=> - int(0) - ["global_prefetch_size":"AMQPChannel":private]=> - int(0) - ["consumers":"AMQPChannel":private]=> - array(0) { - } - } + %a ["name":"AMQPQueue":private]=> string(%d) "test.queue.%f" - ["consumer_tag":"AMQPQueue":private]=> + ["consumerTag":"AMQPQueue":private]=> NULL ["passive":"AMQPQueue":private]=> bool(false) @@ -139,7 +51,7 @@ object(AMQPQueue)#3 (9) { bool(false) ["exclusive":"AMQPQueue":private]=> bool(false) - ["auto_delete":"AMQPQueue":private]=> + ["autoDelete":"AMQPQueue":private]=> bool(true) ["arguments":"AMQPQueue":private]=> array(0) { @@ -147,100 +59,12 @@ object(AMQPQueue)#3 (9) { } object(AMQPQueue)#4 (9) { ["connection":"AMQPQueue":private]=> - object(AMQPConnection)#1 (18) { - ["login":"AMQPConnection":private]=> - string(5) "guest" - ["password":"AMQPConnection":private]=> - string(5) "guest" - ["host":"AMQPConnection":private]=> - string(9) "localhost" - ["vhost":"AMQPConnection":private]=> - string(1) "/" - ["port":"AMQPConnection":private]=> - int(5672) - ["read_timeout":"AMQPConnection":private]=> - float(0) - ["write_timeout":"AMQPConnection":private]=> - float(0) - ["connect_timeout":"AMQPConnection":private]=> - float(0) - ["rpc_timeout":"AMQPConnection":private]=> - float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> - int(131072) - ["heartbeat":"AMQPConnection":private]=> - int(0) - ["cacert":"AMQPConnection":private]=> - string(0) "" - ["key":"AMQPConnection":private]=> - string(0) "" - ["cert":"AMQPConnection":private]=> - string(0) "" - ["verify":"AMQPConnection":private]=> - bool(true) - ["sasl_method":"AMQPConnection":private]=> - int(0) - ["connection_name":"AMQPConnection":private]=> - NULL - } + %a ["channel":"AMQPQueue":private]=> - object(AMQPChannel)#2 (6) { - ["connection":"AMQPChannel":private]=> - object(AMQPConnection)#1 (18) { - ["login":"AMQPConnection":private]=> - string(5) "guest" - ["password":"AMQPConnection":private]=> - string(5) "guest" - ["host":"AMQPConnection":private]=> - string(9) "localhost" - ["vhost":"AMQPConnection":private]=> - string(1) "/" - ["port":"AMQPConnection":private]=> - int(5672) - ["read_timeout":"AMQPConnection":private]=> - float(0) - ["write_timeout":"AMQPConnection":private]=> - float(0) - ["connect_timeout":"AMQPConnection":private]=> - float(0) - ["rpc_timeout":"AMQPConnection":private]=> - float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> - int(131072) - ["heartbeat":"AMQPConnection":private]=> - int(0) - ["cacert":"AMQPConnection":private]=> - string(0) "" - ["key":"AMQPConnection":private]=> - string(0) "" - ["cert":"AMQPConnection":private]=> - string(0) "" - ["verify":"AMQPConnection":private]=> - bool(true) - ["sasl_method":"AMQPConnection":private]=> - int(0) - ["connection_name":"AMQPConnection":private]=> - NULL - } - ["prefetch_count":"AMQPChannel":private]=> - int(3) - ["prefetch_size":"AMQPChannel":private]=> - int(0) - ["global_prefetch_count":"AMQPChannel":private]=> - int(0) - ["global_prefetch_size":"AMQPChannel":private]=> - int(0) - ["consumers":"AMQPChannel":private]=> - array(0) { - } - } + %a ["name":"AMQPQueue":private]=> string(%d) "test.queue.dead.%f" - ["consumer_tag":"AMQPQueue":private]=> + ["consumerTag":"AMQPQueue":private]=> NULL ["passive":"AMQPQueue":private]=> bool(false) @@ -248,7 +72,7 @@ object(AMQPQueue)#4 (9) { bool(false) ["exclusive":"AMQPQueue":private]=> bool(false) - ["auto_delete":"AMQPQueue":private]=> + ["autoDelete":"AMQPQueue":private]=> bool(true) ["arguments":"AMQPQueue":private]=> array(3) { @@ -262,100 +86,12 @@ object(AMQPQueue)#4 (9) { } object(AMQPQueue)#4 (9) { ["connection":"AMQPQueue":private]=> - object(AMQPConnection)#1 (18) { - ["login":"AMQPConnection":private]=> - string(5) "guest" - ["password":"AMQPConnection":private]=> - string(5) "guest" - ["host":"AMQPConnection":private]=> - string(9) "localhost" - ["vhost":"AMQPConnection":private]=> - string(1) "/" - ["port":"AMQPConnection":private]=> - int(5672) - ["read_timeout":"AMQPConnection":private]=> - float(0) - ["write_timeout":"AMQPConnection":private]=> - float(0) - ["connect_timeout":"AMQPConnection":private]=> - float(0) - ["rpc_timeout":"AMQPConnection":private]=> - float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> - int(131072) - ["heartbeat":"AMQPConnection":private]=> - int(0) - ["cacert":"AMQPConnection":private]=> - string(0) "" - ["key":"AMQPConnection":private]=> - string(0) "" - ["cert":"AMQPConnection":private]=> - string(0) "" - ["verify":"AMQPConnection":private]=> - bool(true) - ["sasl_method":"AMQPConnection":private]=> - int(0) - ["connection_name":"AMQPConnection":private]=> - NULL - } + %a ["channel":"AMQPQueue":private]=> - object(AMQPChannel)#2 (6) { - ["connection":"AMQPChannel":private]=> - object(AMQPConnection)#1 (18) { - ["login":"AMQPConnection":private]=> - string(5) "guest" - ["password":"AMQPConnection":private]=> - string(5) "guest" - ["host":"AMQPConnection":private]=> - string(9) "localhost" - ["vhost":"AMQPConnection":private]=> - string(1) "/" - ["port":"AMQPConnection":private]=> - int(5672) - ["read_timeout":"AMQPConnection":private]=> - float(0) - ["write_timeout":"AMQPConnection":private]=> - float(0) - ["connect_timeout":"AMQPConnection":private]=> - float(0) - ["rpc_timeout":"AMQPConnection":private]=> - float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> - int(131072) - ["heartbeat":"AMQPConnection":private]=> - int(0) - ["cacert":"AMQPConnection":private]=> - string(0) "" - ["key":"AMQPConnection":private]=> - string(0) "" - ["cert":"AMQPConnection":private]=> - string(0) "" - ["verify":"AMQPConnection":private]=> - bool(true) - ["sasl_method":"AMQPConnection":private]=> - int(0) - ["connection_name":"AMQPConnection":private]=> - NULL - } - ["prefetch_count":"AMQPChannel":private]=> - int(3) - ["prefetch_size":"AMQPChannel":private]=> - int(0) - ["global_prefetch_count":"AMQPChannel":private]=> - int(0) - ["global_prefetch_size":"AMQPChannel":private]=> - int(0) - ["consumers":"AMQPChannel":private]=> - array(0) { - } - } + %a ["name":"AMQPQueue":private]=> string(%d) "test.queue.dead.%f" - ["consumer_tag":"AMQPQueue":private]=> + ["consumerTag":"AMQPQueue":private]=> NULL ["passive":"AMQPQueue":private]=> bool(false) @@ -363,7 +99,7 @@ object(AMQPQueue)#4 (9) { bool(false) ["exclusive":"AMQPQueue":private]=> bool(false) - ["auto_delete":"AMQPQueue":private]=> + ["autoDelete":"AMQPQueue":private]=> bool(true) ["arguments":"AMQPQueue":private]=> array(2) { diff --git a/tests/amqpqueue_unbind_basic_empty_routing_key.phpt b/tests/amqpqueue_unbind_basic_empty_routing_key.phpt index d7861539..74bf9b58 100644 --- a/tests/amqpqueue_unbind_basic_empty_routing_key.phpt +++ b/tests/amqpqueue_unbind_basic_empty_routing_key.phpt @@ -24,5 +24,5 @@ $queue->delete(); $ex->delete(); ?> --EXPECT-- -bool(true) -bool(true) +NULL +NULL diff --git a/tests/amqpqueue_unbind_basic_headers_arguments.phpt b/tests/amqpqueue_unbind_basic_headers_arguments.phpt index a79e705b..be3c3fba 100644 --- a/tests/amqpqueue_unbind_basic_headers_arguments.phpt +++ b/tests/amqpqueue_unbind_basic_headers_arguments.phpt @@ -27,5 +27,5 @@ $queue->delete(); $ex->delete(); ?> --EXPECT-- -bool(true) -bool(true) +NULL +NULL diff --git a/tests/amqpqueue_var_dump.phpt b/tests/amqpqueue_var_dump.phpt index 29d428a7..69b48dd5 100644 --- a/tests/amqpqueue_var_dump.phpt +++ b/tests/amqpqueue_var_dump.phpt @@ -2,7 +2,7 @@ AMQPQueue var_dump --SKIPIF-- setName('queue_var_dump'); $q->declareQueue(); var_dump($q); ?> ---EXPECT-- +--EXPECTF-- object(AMQPQueue)#4 (9) { ["connection":"AMQPQueue":private]=> - object(AMQPConnection)#1 (18) { - ["login":"AMQPConnection":private]=> - string(5) "guest" - ["password":"AMQPConnection":private]=> - string(5) "guest" - ["host":"AMQPConnection":private]=> - string(9) "localhost" - ["vhost":"AMQPConnection":private]=> - string(1) "/" - ["port":"AMQPConnection":private]=> - int(5672) - ["read_timeout":"AMQPConnection":private]=> - float(0) - ["write_timeout":"AMQPConnection":private]=> - float(0) - ["connect_timeout":"AMQPConnection":private]=> - float(0) - ["rpc_timeout":"AMQPConnection":private]=> - float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> - int(131072) - ["heartbeat":"AMQPConnection":private]=> - int(0) - ["cacert":"AMQPConnection":private]=> - string(0) "" - ["key":"AMQPConnection":private]=> - string(0) "" - ["cert":"AMQPConnection":private]=> - string(0) "" - ["verify":"AMQPConnection":private]=> - bool(true) - ["sasl_method":"AMQPConnection":private]=> - int(0) - ["connection_name":"AMQPConnection":private]=> - NULL - } + %a ["channel":"AMQPQueue":private]=> - object(AMQPChannel)#2 (6) { - ["connection":"AMQPChannel":private]=> - object(AMQPConnection)#1 (18) { - ["login":"AMQPConnection":private]=> - string(5) "guest" - ["password":"AMQPConnection":private]=> - string(5) "guest" - ["host":"AMQPConnection":private]=> - string(9) "localhost" - ["vhost":"AMQPConnection":private]=> - string(1) "/" - ["port":"AMQPConnection":private]=> - int(5672) - ["read_timeout":"AMQPConnection":private]=> - float(0) - ["write_timeout":"AMQPConnection":private]=> - float(0) - ["connect_timeout":"AMQPConnection":private]=> - float(0) - ["rpc_timeout":"AMQPConnection":private]=> - float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> - int(131072) - ["heartbeat":"AMQPConnection":private]=> - int(0) - ["cacert":"AMQPConnection":private]=> - string(0) "" - ["key":"AMQPConnection":private]=> - string(0) "" - ["cert":"AMQPConnection":private]=> - string(0) "" - ["verify":"AMQPConnection":private]=> - bool(true) - ["sasl_method":"AMQPConnection":private]=> - int(0) - ["connection_name":"AMQPConnection":private]=> - NULL - } - ["prefetch_count":"AMQPChannel":private]=> - int(3) - ["prefetch_size":"AMQPChannel":private]=> - int(0) - ["global_prefetch_count":"AMQPChannel":private]=> - int(0) - ["global_prefetch_size":"AMQPChannel":private]=> - int(0) - ["consumers":"AMQPChannel":private]=> - array(0) { - } - } + %a ["name":"AMQPQueue":private]=> string(14) "queue_var_dump" - ["consumer_tag":"AMQPQueue":private]=> + ["consumerTag":"AMQPQueue":private]=> NULL ["passive":"AMQPQueue":private]=> bool(false) @@ -125,7 +37,7 @@ object(AMQPQueue)#4 (9) { bool(false) ["exclusive":"AMQPQueue":private]=> bool(false) - ["auto_delete":"AMQPQueue":private]=> + ["autoDelete":"AMQPQueue":private]=> bool(true) ["arguments":"AMQPQueue":private]=> array(0) { diff --git a/tests/amqptimestamp.phpt b/tests/amqptimestamp.phpt index 6424f8b6..9980727d 100644 --- a/tests/amqptimestamp.phpt +++ b/tests/amqptimestamp.phpt @@ -2,7 +2,7 @@ AMQPTimestamp --SKIPIF-- ')) { +if (!extension_loaded("amqp")) { print "skip"; } --FILE-- @@ -14,10 +14,6 @@ var_dump($timestamp->getTimestamp(), (string) $timestamp); $timestamp = new AMQPTimestamp(100000.1); var_dump($timestamp->getTimestamp(), (string) $timestamp); -new AMQPTimestamp(); - -new AMQPTimestamp("string"); - try { new AMQPTimestamp(AMQPTimestamp::MIN - 1); } catch (AMQPValueException $e) { @@ -32,24 +28,20 @@ try { var_dump((new ReflectionClass("AMQPTimestamp"))->isFinal()); -var_dump(AMQPTimestamp::MAX); +var_dump(number_format(AMQPTimestamp::MAX, 0, '.', '_')); var_dump(AMQPTimestamp::MIN); ?> ==END== --EXPECTF-- +float(100000) string(6) "100000" +float(100000) string(6) "100000" -string(6) "100000" -string(6) "100000" - -Warning: AMQPTimestamp::__construct() expects exactly 1 parameter, 0 given in %s on line %d - -Warning: AMQPTimestamp::__construct() expects parameter 1 to be %s, string given in %s on line %d The timestamp parameter must be greater than 0. The timestamp parameter must be less than 18446744073709551616. bool(true) -string(20) "18446744073709551616" -string(1) "0" +string(26) "18_446_744_073_709_551_616" +float(0) -==END== +==END== \ No newline at end of file diff --git a/tests/amqptimestamp_php8.phpt b/tests/amqptimestamp_php8.phpt deleted file mode 100644 index e76102fe..00000000 --- a/tests/amqptimestamp_php8.phpt +++ /dev/null @@ -1,60 +0,0 @@ ---TEST-- -AMQPTimestamp ---SKIPIF-- -getTimestamp(), (string) $timestamp); - -$timestamp = new AMQPTimestamp(100000.1); -var_dump($timestamp->getTimestamp(), (string) $timestamp); - -try { - new AMQPTimestamp(); -} catch(ArgumentCountError $e) { - echo $e->getMessage() . "\n"; -} -try { - new AMQPTimestamp("string"); -} catch(TypeError $e) { - echo $e->getMessage() . "\n"; -} - -try { - new AMQPTimestamp(AMQPTimestamp::MIN - 1); -} catch (AMQPValueException $e) { - echo $e->getMessage() . "\n"; -} - -try { - new AMQPTimestamp(INF); -} catch (AMQPValueException $e) { - echo $e->getMessage() . "\n"; -} - -var_dump((new ReflectionClass("AMQPTimestamp"))->isFinal()); - -var_dump(AMQPTimestamp::MAX); -var_dump(AMQPTimestamp::MIN); -?> - -==END== ---EXPECTF-- -string(6) "100000" -string(6) "100000" -string(6) "100000" -string(6) "100000" -AMQPTimestamp::__construct() expects exactly 1 argument, 0 given -AMQPTimestamp::__construct(): Argument #1 ($timestamp) must be of type float, string given -The timestamp parameter must be greater than 0. -The timestamp parameter must be less than 18446744073709551616. -bool(true) -string(20) "18446744073709551616" -string(1) "0" - -==END== diff --git a/tests/bug_19707.phpt b/tests/bug_19707.phpt index 488b42cf..8a180875 100644 --- a/tests/bug_19707.phpt +++ b/tests/bug_19707.phpt @@ -41,21 +41,21 @@ $ex->delete(); ?> --EXPECT-- message received from get: -getAppId => '' +getAppId => NULL getBody => 'message' -getContentEncoding => '' +getContentEncoding => NULL getContentType => 'text/plain' -getCorrelationId => '' +getCorrelationId => NULL getDeliveryTag => 1 getExchangeName => 'exchange_testing_19707' -getExpiration => '' +getExpiration => NULL getHeaders => array ( ) -getMessageId => '' +getMessageId => NULL getPriority => 0 -getReplyTo => '' +getReplyTo => NULL getRoutingKey => 'routing.key' getTimeStamp => 0 -getType => '' -getUserId => '' +getType => NULL +getUserId => NULL isRedelivery => false \ No newline at end of file diff --git a/tools/check-stubs.sh b/tools/check-stubs.sh new file mode 100755 index 00000000..e778fb22 --- /dev/null +++ b/tools/check-stubs.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +result=0 +for stub in `dirname $0`/../stubs/*.php; do + php -l `realpath $stub` + result=$(($result+$?)) +done + +test $result -gt 0 && exit 1 || exit 0 \ No newline at end of file diff --git a/tools/dev-format.sh b/tools/dev-format.sh index bb3e97a9..a2da068d 100755 --- a/tools/dev-format.sh +++ b/tools/dev-format.sh @@ -1,3 +1,5 @@ #!/usr/bin/env sh set -e -clang-format-17 -i *.c *.h \ No newline at end of file +base_dir=`dirname $0`/../ +real_base_dir=`realpath $base_dir` +clang-format-17 -i $real_base_dir/*.c $real_base_dir/*.h \ No newline at end of file diff --git a/tools/dump-reflection.php b/tools/dump-reflection.php new file mode 100644 index 00000000..0cc70cbf --- /dev/null +++ b/tools/dump-reflection.php @@ -0,0 +1,228 @@ + [], + 'constants' => [], + 'classNames' => [], +]; + +function sortByName(array $array): array { + usort( + $array, + function (array $left, array $right) { + return $left['name'] <=> $right['name']; + } + ); + + return $array; +} + +function getTypeMetadata(?ReflectionType $type): ?array { + if ($type == null) { + return null; + } + + return [ + 'name' => (string) $type, + 'nullable' => $type->allowsNull() + ]; +} + +$error = false; +function error(string $message, ...$args): void +{ + global $error; + vprintf('ERROR: ' . $message . PHP_EOL, $args); + $error = true; +} + +const MAGIC_METHODS = [ + '__construct', + '__toString', + '__wakeup', + '__clone', +]; + +function getClassMetadata(string $class): array { + $refl = new ReflectionClass($class); + $classMetadata = [ + 'name' => $refl->getName(), + 'constants' => [], + 'properties' => [], + 'methods' => [], + ]; + + foreach ($refl->getReflectionConstants() as $constant) { + if ($constant->getDeclaringClass()->getName() !== $refl->getName()) { + continue; + } + + $classMetadata['constants'][] = [ + 'name' => $class. '::' . $constant->getName(), + 'value' => $constant->getValue(), + 'visibility' => $constant->isPublic() ? 'public' : ($constant->isProtected() ? 'protected' : ($constant->isPrivate() ? 'private' : 'unknown')), + ]; + } + + foreach ($refl->getMethods() as $method) { + if ($method->getDeclaringClass()->getName() !== $refl->getName()) { + continue; + } + + $methodMetadata = [ + 'name' => $class. '::' . $method->getName(), + 'visibility' => $method->isPublic() ? 'public' : ($method->isProtected() ? 'protected' : ($method->isPrivate() ? 'private' : 'unknown')), + 'final' => $method->isFinal(), + 'static' => $method->isStatic(), + 'parameterCount' => $method->getNumberOfParameters(), + 'requiredParameterCount' => $method->getNumberOfRequiredParameters(), + 'return' => getTypeMetadata($method->getReturnType()), + 'parameters' => [], + ]; + + if (!in_array($method->getName(), MAGIC_METHODS, true) && strpos($method->getName(), '_') !== false) { + error("%s::%s contains underscore", $class, $method->getName()); + } + + $prefix = substr($method->getName(), 0, 3); + if (in_array($prefix, ['set', 'has', 'get'], true) && !in_array($method->getName(), ['set', 'has', 'get'], true)) { + $hasPlural = $refl->hasMethod($method->getName() . 's'); + $isPlural = substr($method->getName(), -1) === 's'; + + if ($prefix === 'get' && $method->getNumberOfParameters() !== 0 && !$hasPlural) { + error("%s::%s() should have no arguments", $class, $method->getName()); + } + + if ($prefix === 'set' && $isPlural) { + if ($method->getParameters()[0]->getName() !== ($expectedName = lcfirst(substr($method->getName(), 3)))) { + error("%s::%s(%s) must be \"%s\"", $class, $method->getName(), $method->getParameters()[0]->getName(), $expectedName); + } + } + + if ($prefix === 'get' && $hasPlural) { + if ($method->getNumberOfRequiredParameters() !== 1 || $method->getNumberOfParameters() !== 1) { + error("%s::%s() should have exactly one required parameter", $class, $method->getName()); + } + } + + if ($hasPlural) { + if ($method->getParameters()[0]->getName() !== ($expectedName = lcfirst(substr($method->getName(), 3) . 'Name'))) { + error("%s::%s(%s) must be \"%s\"", $class, $method->getName(), $method->getParameters()[0]->getName(), $expectedName); + } + + if ($prefix === 'set' && $method->getParameters()[1]->getName() !== ($expectedName = lcfirst(substr($method->getName(), 3) . 'Value'))) { + error("%s::%s(…, %s) must be \"%s\"", $class, $method->getName(), $method->getParameters()[1]->getName(), $expectedName); + } + } + } + + foreach ($method->getParameters() as $parameter) { + if (strpos($parameter->getName(), '_') !== false) { + error("%s::%s(…%s…) contains underscore", $class, $method->getName(), $parameter->getName()); + } + + $default = 'unknown'; + if (version_compare(PHP_VERSION, '8.0.0', '>=')) { + // Cannot set default values before 8.0 in native extension + $default = $parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : 'none'; + } + + $methodMetadata['parameters'][] = [ + 'method' => $class. '::' . $method->getName(), + 'name' => sprintf('$%s', $parameter->getName()), + 'default' => $default, + 'type' => getTypeMetadata($parameter->getType()), + 'byRef' => $parameter->isPassedByReference(), + ]; + } + + $classMetadata['methods'][] = $methodMetadata; + } + + foreach ($refl->getProperties() as $property) { + if ($property->getDeclaringClass()->getName() !== $refl->getName()) { + continue; + } + if (strpos($property->getName(), '_') !== false) { + error('Property %s::%s contains underscore', $class, $property->getName()); + } + $default = 'unknown'; + if (version_compare(PHP_VERSION, '8.0.0', '>=')) { + // Cannot set default values before 8.0 in native extension + $default = $property->isDefault() ? $property->getDefaultValue() : 'none'; + } + $propertyTypeMetadata = getTypeMetadata($property->getType()); + if ($propertyTypeMetadata === null) { + error('Property %s::%s has no type declared', $class, $property->getName()); + } + $propertyMetadata = [ + 'name' => $class . '::' . $property->getName(), + 'visibility' => $property->isPublic() ? 'public' : ($property->isProtected() ? 'protected' : ($property->isPrivate() ? 'private' : 'unknown')), + 'type' => $propertyTypeMetadata, + 'default' => $default, + ]; + + $classMetadata['properties'][] = $propertyMetadata; + } + + $classMetadata['properties'] = sortByName($classMetadata['properties']); + $classMetadata['constants'] = sortByName($classMetadata['constants']); + $classMetadata['methods'] = sortByName($classMetadata['methods']); + + return $classMetadata; +} + + +spl_autoload_register(function(string $class) { + require_once __DIR__ . '/../stubs/' . $class . '.php'; +}); + +if (!extension_loaded('amqp')) { + require_once __DIR__ . '/../stubs/AMQP.php'; +} + +foreach (get_defined_constants() as $constant => $value) { + if ($constant === 'AMQP_OS_SOCKET_TIMEOUT_ERRNO') { + // Value differs across OS, so normalize + $value = 0xDEADBEEF; + } + + if (strpos($constant, 'AMQP_') === 0) { + $symbols['constants'][] = [ + 'name' => $constant, + 'value' => $value + ]; + } +} +$symbols['constants'] = sortByName($symbols['constants']); +$symbols['classes'][] = getClassMetadata('AMQPValueException'); +$symbols['classes'][] = getClassMetadata('AMQPTimestamp'); +$symbols['classes'][] = getClassMetadata('AMQPQueueException'); +$symbols['classes'][] = getClassMetadata('AMQPQueue'); +$symbols['classes'][] = getClassMetadata('AMQPExchangeException'); +$symbols['classes'][] = getClassMetadata('AMQPExchange'); +$symbols['classes'][] = getClassMetadata('AMQPException'); +$symbols['classes'][] = getClassMetadata('AMQPEnvelopeException'); +$symbols['classes'][] = getClassMetadata('AMQPEnvelope'); +$symbols['classes'][] = getClassMetadata('AMQPDecimal'); +$symbols['classes'][] = getClassMetadata('AMQPConnectionException'); +$symbols['classes'][] = getClassMetadata('AMQPConnection'); +$symbols['classes'][] = getClassMetadata('AMQPChannelException'); +$symbols['classes'][] = getClassMetadata('AMQPChannel'); +$symbols['classes'][] = getClassMetadata('AMQPBasicProperties'); + +// Ensure we captured all AMQP classes +foreach (get_declared_classes() as $className) { + if (strpos($className, 'AMQP') === 0) { + $symbols['classNames'][] = $className; + } +} +sort($symbols['classNames']); + +$filename = $_SERVER['argv'][1] ?? null; +assert($filename !== null, 'Output filename must be passed'); + +file_put_contents($filename, json_encode($symbols, JSON_PRETTY_PRINT)); + +if ($error) { + exit(1); +} \ No newline at end of file diff --git a/tools/validate-stubs.sh b/tools/validate-stubs.sh new file mode 100755 index 00000000..e2d23f4b --- /dev/null +++ b/tools/validate-stubs.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env sh +set -e + +SHARED_JSON=`php -n -r 'echo !extension_loaded("json") ? "true" : "false";'` + +args="-n" +if [ "${SHARED_JSON}" = "true" ]; then + args="${args} -d extension=json.so" +fi + +base_dir=`dirname $0`/../ +real_base_dir=`realpath $base_dir` + +php $args $real_base_dir/tools/dump-reflection.php stubs.json +php $args -d extension=modules/amqp.so $real_base_dir/tools/dump-reflection.php impl.json + +diff -10 -u stubs.json impl.json \ No newline at end of file From 9752f27ed15faa1bf30a5f3582f8d16d653f30ca Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Sat, 29 Jul 2023 10:45:06 +0200 Subject: [PATCH 017/147] Expose better version information (#438) --- amqp.c | 8 +++++++- amqp_connection_resource.c | 14 +++++-------- config.m4 | 4 ++-- php_amqp.h | 9 +-------- php_amqp_version.h | 6 ++++++ stubs/AMQP.php | 33 ++++++++++++++++++++++++++++++- tests/amqp_version.phpt | 22 +++++++++++++++++++++ tools/dump-reflection.php | 12 +++++++++++- tools/functions.php | 40 +++++++++++++++++++++++++++++++------- 9 files changed, 119 insertions(+), 29 deletions(-) create mode 100644 php_amqp_version.h create mode 100644 tests/amqp_version.phpt diff --git a/amqp.c b/amqp.c index 380f6bd6..2d9bf48b 100644 --- a/amqp.c +++ b/amqp.c @@ -277,6 +277,13 @@ static PHP_MINIT_FUNCTION(amqp) /* {{{ */ REGISTER_INI_ENTRIES(); + REGISTER_STRING_CONSTANT("AMQP_EXTENSION_VERSION", PHP_AMQP_VERSION, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("AMQP_EXTENSION_VERSION_MAJOR", PHP_AMQP_VERSION_MAJOR, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("AMQP_EXTENSION_VERSION_MINOR", PHP_AMQP_VERSION_MINOR, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("AMQP_EXTENSION_VERSION_PATCH", PHP_AMQP_VERSION_PATCH, CONST_CS | CONST_PERSISTENT); + REGISTER_STRING_CONSTANT("AMQP_EXTENSION_VERSION_EXTRA", PHP_AMQP_VERSION_EXTRA, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("AMQP_EXTENSION_VERSION_ID", PHP_AMQP_VERSION_ID, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("AMQP_NOPARAM", AMQP_NOPARAM, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("AMQP_JUST_CONSUME", AMQP_JUST_CONSUME, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("AMQP_DURABLE", AMQP_DURABLE, CONST_CS | CONST_PERSISTENT); @@ -334,7 +341,6 @@ static PHP_MINFO_FUNCTION(amqp) /* {{{ */ { php_info_print_table_start(); php_info_print_table_header(2, "Version", PHP_AMQP_VERSION); - php_info_print_table_header(2, "Revision", PHP_AMQP_REVISION); php_info_print_table_header(2, "Compiled", __DATE__ " @ " __TIME__); php_info_print_table_header(2, "AMQP protocol version", "0-9-1"); php_info_print_table_header(2, "librabbitmq version", amqp_version()); diff --git a/amqp_connection_resource.c b/amqp_connection_resource.c index 37cc45dc..4fbf14ca 100644 --- a/amqp_connection_resource.c +++ b/amqp_connection_resource.c @@ -480,7 +480,7 @@ amqp_connection_resource *connection_resource_constructor(amqp_connection_params struct timeval *tv_ptr = &tv; char *std_datetime; - amqp_table_entry_t client_properties_entries[5]; + amqp_table_entry_t client_properties_entries[4]; amqp_table_t client_properties_table; amqp_table_entry_t custom_properties_entries[2]; @@ -580,17 +580,13 @@ amqp_connection_resource *connection_resource_constructor(amqp_connection_params client_properties_entries[1].value.kind = AMQP_FIELD_KIND_UTF8; client_properties_entries[1].value.value.bytes = amqp_cstring_bytes(PHP_AMQP_VERSION); - client_properties_entries[2].key = amqp_cstring_bytes("revision"); + client_properties_entries[2].key = amqp_cstring_bytes("connection type"); client_properties_entries[2].value.kind = AMQP_FIELD_KIND_UTF8; - client_properties_entries[2].value.value.bytes = amqp_cstring_bytes(PHP_AMQP_REVISION); + client_properties_entries[2].value.value.bytes = amqp_cstring_bytes(persistent ? "persistent" : "transient"); - client_properties_entries[3].key = amqp_cstring_bytes("connection type"); + client_properties_entries[3].key = amqp_cstring_bytes("connection started"); client_properties_entries[3].value.kind = AMQP_FIELD_KIND_UTF8; - client_properties_entries[3].value.value.bytes = amqp_cstring_bytes(persistent ? "persistent" : "transient"); - - client_properties_entries[4].key = amqp_cstring_bytes("connection started"); - client_properties_entries[4].value.kind = AMQP_FIELD_KIND_UTF8; - client_properties_entries[4].value.value.bytes = amqp_cstring_bytes(std_datetime); + client_properties_entries[3].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); diff --git a/config.m4 b/config.m4 index 873d13d1..4c042571 100644 --- a/config.m4 +++ b/config.m4 @@ -44,8 +44,8 @@ if test "$PHP_AMQP" != "no"; then AC_MSG_ERROR([librabbitmq not found]) fi - PHP_AMQP_VERSION=`$PKG_CONFIG librabbitmq --modversion` - AC_MSG_RESULT([found version $PHP_AMQP_VERSION]) + LIBRABBITMQ_VERSION=`$PKG_CONFIG librabbitmq --modversion` + AC_MSG_RESULT([found version $LIBRABBITMQ_VERSION]) if ! $PKG_CONFIG librabbitmq --atleast-version 0.10.0 ; then AC_MSG_ERROR([librabbitmq must be version 0.10.0 or greater]) diff --git a/php_amqp.h b/php_amqp.h index f2965a64..f64da86a 100644 --- a/php_amqp.h +++ b/php_amqp.h @@ -59,6 +59,7 @@ extern zend_module_entry amqp_module_entry; #include "TSRM.h" #endif +#include "php_amqp_version.h" #if PHP_VERSION_ID >= 80000 #define PHP_AMQP_COMPAT_OBJ_P(zv) Z_OBJ_P(zv) @@ -432,14 +433,6 @@ ZEND_TSRMLS_CACHE_EXTERN(); #endif #endif -#ifndef PHP_AMQP_VERSION - #define PHP_AMQP_VERSION "2.0.0dev" -#endif - -#ifndef PHP_AMQP_REVISION - #define PHP_AMQP_REVISION "release" -#endif - int php_amqp_error( amqp_rpc_reply_t reply, char **message, diff --git a/php_amqp_version.h b/php_amqp_version.h new file mode 100644 index 00000000..300dc520 --- /dev/null +++ b/php_amqp_version.h @@ -0,0 +1,6 @@ +#define PHP_AMQP_VERSION_MAJOR 2 +#define PHP_AMQP_VERSION_MINOR 0 +#define PHP_AMQP_VERSION_PATCH 0 +#define PHP_AMQP_VERSION_EXTRA "dev" +#define PHP_AMQP_VERSION "2.0.0dev" +#define PHP_AMQP_VERSION_ID 20000 diff --git a/stubs/AMQP.php b/stubs/AMQP.php index f7552c14..e63a4fcd 100644 --- a/stubs/AMQP.php +++ b/stubs/AMQP.php @@ -1,5 +1,4 @@ +--FILE-- + +==DONE== +--EXPECTF-- +string(%d) "%d.%d.%s" +int(%d) +int(%d) +int(%d) +string(%d) "%s" +int(%d) +==DONE== diff --git a/tools/dump-reflection.php b/tools/dump-reflection.php index 0cc70cbf..23469cf9 100644 --- a/tools/dump-reflection.php +++ b/tools/dump-reflection.php @@ -180,8 +180,18 @@ function getClassMetadata(string $class): array { require_once __DIR__ . '/../stubs/AMQP.php'; } +const NON_DETERMINISTIC_CONSTANTS = [ + 'AMQP_OS_SOCKET_TIMEOUT_ERRNO', + 'AMQP_EXTENSION_VERSION', + 'AMQP_EXTENSION_VERSION_MAJOR', + 'AMQP_EXTENSION_VERSION_MINOR', + 'AMQP_EXTENSION_VERSION_PATCH', + 'AMQP_EXTENSION_VERSION_EXTRA', + 'AMQP_EXTENSION_VERSION_ID', +]; + foreach (get_defined_constants() as $constant => $value) { - if ($constant === 'AMQP_OS_SOCKET_TIMEOUT_ERRNO') { + if (in_array($constant, NON_DETERMINISTIC_CONSTANTS, true)) { // Value differs across OS, so normalize $value = 0xDEADBEEF; } diff --git a/tools/functions.php b/tools/functions.php index 530de641..7a870a70 100644 --- a/tools/functions.php +++ b/tools/functions.php @@ -26,7 +26,16 @@ const MAJOR_MINOR_PATCH = '\d+\.\d+\.\d+'; const VERSION_REGEX = MAJOR_MINOR_PATCH . '(?:' . STABILITY_REGEX . ')?'; const VERSION_REGEX_DEV = MAJOR_MINOR_PATCH . 'dev'; -const HEADER_VERSION_FILE = BASE_DIR . '/php_amqp.h'; +const HEADER_VERSION_FILE = BASE_DIR . '/php_amqp_version.h'; +const HEADER_VERSION_TEMPLATE = <<<'EOS' +#define PHP_AMQP_VERSION_MAJOR {major} +#define PHP_AMQP_VERSION_MINOR {minor} +#define PHP_AMQP_VERSION_PATCH {patch} +#define PHP_AMQP_VERSION_EXTRA "{extra}" +#define PHP_AMQP_VERSION "{major}.{minor}.{patch}{extra}" +#define PHP_AMQP_VERSION_ID {id} + +EOS; const PACKAGE_XML = BASE_DIR . '/package.xml'; const ISSUE_URL_TEMPLATE = 'https://github.com/php-amqp/php-amqp/issues/%d'; const COMMIT_URL_TEMPLATE = 'https://github.com/php-amqp/php-amqp/issues/%d'; @@ -188,12 +197,29 @@ function getSourceVersion(): string function setSourceVersion(string $nextVersion): void { + [$major, $minor, $patchExtra] = explode('.', $nextVersion); + assert(preg_match('/^(?P\d+)(?P\w*)$/', $patchExtra, $matches) === 1); + $patch = $matches['patch']; + $extra = $matches['extra']; + + if ($major > 0) { + $id = sprintf('%d%02d%02d', $major, $minor, $patch); + } else { + $id = sprintf('%02d%02d', $minor, $patch); + } + assert(strlen($id) === 5); + file_put_contents( HEADER_VERSION_FILE, - preg_replace( - re(SOURCE_VERSION_REGEX), - '\1"' . $nextVersion . '"', - file_get_contents(HEADER_VERSION_FILE) + strtr( + HEADER_VERSION_TEMPLATE, + [ + '{major}' => $major, + '{minor}' => $minor, + '{patch}' => $patch, + '{extra}' => $extra, + '{id}' => $id + ] ) ); } @@ -258,7 +284,7 @@ function buildChangelog(string $nextTag, string $previousTag): string $changes For a complete list of changes see: -https://github.com/php-amqp/php-amqp/compare/${previousTag}...${nextTag} +https://github.com/php-amqp/php-amqp/compare/$previousTag...$nextTag EOT; @@ -340,7 +366,7 @@ function gitCommit(int $step, string $nextVersion, string $message): void { function gitTag(int $step, string $nextVersion): void { $nextTag = versionToTag($nextVersion); - executeCommand("git tag ${nextTag}"); + executeCommand("git tag $nextTag"); printf("%d) Run \"git push origin %s\"\n", $step, $nextTag); } From 55464360dec698a684bf3353b3afc3e33cbff39c Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Sat, 29 Jul 2023 10:50:33 +0200 Subject: [PATCH 018/147] Handle alpha/beta stability correctly --- tools/functions.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/functions.php b/tools/functions.php index 7a870a70..3eef6903 100644 --- a/tools/functions.php +++ b/tools/functions.php @@ -321,6 +321,8 @@ function setStability(string $nextVersion): void : 'stable'; $stability = $stability === 'dev' ? 'devel' : $stability; $stability = strpos($stability, 'RC') === 0 ? 'beta' : $stability; + $stability = strpos($stability, 'alpha') === 0 ? 'alpha' : $stability; + $stability = strpos($stability, 'beta') === 0 ? 'beta' : $stability; $xml->stability->release = $stability; $xml->stability->api = $stability; From 8d227904d24efdbae4eb9faee5c69d884ef744fb Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Sat, 29 Jul 2023 10:51:15 +0200 Subject: [PATCH 019/147] [RM] releasing version 2.0.0alpha1 --- package.xml | 51 ++++++++++++++++++++++++++++++++++++---------- php_amqp_version.h | 4 ++-- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/package.xml b/package.xml index ce726446..4dd6954e 100644 --- a/package.xml +++ b/package.xml @@ -22,22 +22,42 @@ pinepain@gmail.com yes - 2021-12-01 - + 2023-07-29 + - 2.0.0dev - 2.0.0dev + 2.0.0alpha1 + 2.0.0alpha1 - devel - devel + alpha + alpha PHP License - ) (https://github.com/php-amqp/php-amqp/issues/437) + - Handle alpha/beta stability correctly (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/5546436) + - Expose better version information (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/438) + - Auto-format the codebase (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/436) + - More consistent return types for AMQPEnvelope (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/435) + - Update stubs (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/0) + - Fix parameter error handling in AMQPConnection and AMQPChannel (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/434) + - Increase credentials and identifier limits (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/433) + - Reliably clear consumer tag on AMQPQueue::cancel (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/432) + - Ignore failures on experimental builds (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/25) + - Update branch name (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/7) + - Bump shivammathur/setup-php from 2.25.3 to 2.25.4 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/431) + - PHP 8.2 refactorings (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/430) + - Fix php version check for static building (Misha Kulakovsky ) (https://github.com/php-amqp/php-amqp/issues/425) + - Fix stub exception class (closes #427) (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/0) + - Document custom connection name in stubs (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/700000) + - Expose Delivery Mode through constants (Flávio Heleno ) (https://github.com/php-amqp/php-amqp/issues/420) + - Fix deprecation issue in PHP 8.1 for $consumerTag argument to AMQPQueue::consume() method (Liviu-Ionut Iosif) (https://github.com/php-amqp/php-amqp/issues/421) + - Fix: Deprecated: Creation of dynamic property (8.2) (Remi Collet ) (https://github.com/php-amqp/php-amqp/issues/418) + - Fix AMQPEnvelope::getDeliveryTag() return type (Flávio Heleno ) (https://github.com/php-amqp/php-amqp/issues/415) + - Fix ack/nack/reject param documentation (Flávio Heleno ) (https://github.com/php-amqp/php-amqp/issues/414) + - Mention time units in all timeout-related methods (Andrii Dembitskyi ) (https://github.com/php-amqp/php-amqp/issues/410) For a complete list of changes see: -https://github.com/php-amqp/php-amqp/compare/v1.11.0...latest -]]> +https://github.com/php-amqp/php-amqp/compare/v1.11.0...v2.0.0alpha1]]> @@ -72,9 +92,11 @@ https://github.com/php-amqp/php-amqp/compare/v1.11.0...latest + + @@ -94,6 +116,7 @@ https://github.com/php-amqp/php-amqp/compare/v1.11.0...latest + @@ -114,6 +137,7 @@ https://github.com/php-amqp/php-amqp/compare/v1.11.0...latest + @@ -147,6 +171,7 @@ https://github.com/php-amqp/php-amqp/compare/v1.11.0...latest + @@ -169,13 +194,14 @@ https://github.com/php-amqp/php-amqp/compare/v1.11.0...latest + - + @@ -189,6 +215,7 @@ https://github.com/php-amqp/php-amqp/compare/v1.11.0...latest + @@ -230,10 +257,11 @@ https://github.com/php-amqp/php-amqp/compare/v1.11.0...latest - + + @@ -246,6 +274,7 @@ https://github.com/php-amqp/php-amqp/compare/v1.11.0...latest + diff --git a/php_amqp_version.h b/php_amqp_version.h index 300dc520..b44a41bb 100644 --- a/php_amqp_version.h +++ b/php_amqp_version.h @@ -1,6 +1,6 @@ #define PHP_AMQP_VERSION_MAJOR 2 #define PHP_AMQP_VERSION_MINOR 0 #define PHP_AMQP_VERSION_PATCH 0 -#define PHP_AMQP_VERSION_EXTRA "dev" -#define PHP_AMQP_VERSION "2.0.0dev" +#define PHP_AMQP_VERSION_EXTRA "alpha1" +#define PHP_AMQP_VERSION "2.0.0alpha1" #define PHP_AMQP_VERSION_ID 20000 From 2ffa92c41904162fbd01adf71b408f1b7ea5c4ae Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Sat, 29 Jul 2023 11:34:19 +0200 Subject: [PATCH 020/147] [RM] back to dev 2.0.0dev --- package.xml | 74 ++++++++++++++++++++++++++++------------------ php_amqp_version.h | 4 +-- 2 files changed, 48 insertions(+), 30 deletions(-) diff --git a/package.xml b/package.xml index 4dd6954e..9f415508 100644 --- a/package.xml +++ b/package.xml @@ -23,41 +23,21 @@ yes 2023-07-29 - + - 2.0.0alpha1 - 2.0.0alpha1 + 2.0.0dev + 2.0.0dev - alpha - alpha + devel + devel PHP License - ) (https://github.com/php-amqp/php-amqp/issues/437) - - Handle alpha/beta stability correctly (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/5546436) - - Expose better version information (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/438) - - Auto-format the codebase (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/436) - - More consistent return types for AMQPEnvelope (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/435) - - Update stubs (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/0) - - Fix parameter error handling in AMQPConnection and AMQPChannel (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/434) - - Increase credentials and identifier limits (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/433) - - Reliably clear consumer tag on AMQPQueue::cancel (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/432) - - Ignore failures on experimental builds (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/25) - - Update branch name (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/7) - - Bump shivammathur/setup-php from 2.25.3 to 2.25.4 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/431) - - PHP 8.2 refactorings (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/430) - - Fix php version check for static building (Misha Kulakovsky ) (https://github.com/php-amqp/php-amqp/issues/425) - - Fix stub exception class (closes #427) (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/0) - - Document custom connection name in stubs (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/700000) - - Expose Delivery Mode through constants (Flávio Heleno ) (https://github.com/php-amqp/php-amqp/issues/420) - - Fix deprecation issue in PHP 8.1 for $consumerTag argument to AMQPQueue::consume() method (Liviu-Ionut Iosif) (https://github.com/php-amqp/php-amqp/issues/421) - - Fix: Deprecated: Creation of dynamic property (8.2) (Remi Collet ) (https://github.com/php-amqp/php-amqp/issues/418) - - Fix AMQPEnvelope::getDeliveryTag() return type (Flávio Heleno ) (https://github.com/php-amqp/php-amqp/issues/415) - - Fix ack/nack/reject param documentation (Flávio Heleno ) (https://github.com/php-amqp/php-amqp/issues/414) - - Mention time units in all timeout-related methods (Andrii Dembitskyi ) (https://github.com/php-amqp/php-amqp/issues/410) + +https://github.com/php-amqp/php-amqp/compare/v2.0.0alpha1...latest +]]> @@ -310,6 +290,44 @@ https://github.com/php-amqp/php-amqp/compare/v1.11.0...v2.0.0alpha1]]> + + 2023-07-29 + + + 2.0.0alpha1 + 2.0.0alpha1 + + + alpha + alpha + + PHP License + ) (https://github.com/php-amqp/php-amqp/issues/437) + - Handle alpha/beta stability correctly (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/5546436) + - Expose better version information (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/438) + - Auto-format the codebase (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/436) + - More consistent return types for AMQPEnvelope (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/435) + - Update stubs (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/0) + - Fix parameter error handling in AMQPConnection and AMQPChannel (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/434) + - Increase credentials and identifier limits (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/433) + - Reliably clear consumer tag on AMQPQueue::cancel (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/432) + - Ignore failures on experimental builds (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/25) + - Update branch name (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/7) + - Bump shivammathur/setup-php from 2.25.3 to 2.25.4 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/431) + - PHP 8.2 refactorings (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/430) + - Fix php version check for static building (Misha Kulakovsky ) (https://github.com/php-amqp/php-amqp/issues/425) + - Fix stub exception class (closes #427) (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/0) + - Document custom connection name in stubs (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/700000) + - Expose Delivery Mode through constants (Flávio Heleno ) (https://github.com/php-amqp/php-amqp/issues/420) + - Fix deprecation issue in PHP 8.1 for $consumerTag argument to AMQPQueue::consume() method (Liviu-Ionut Iosif) (https://github.com/php-amqp/php-amqp/issues/421) + - Fix: Deprecated: Creation of dynamic property (8.2) (Remi Collet ) (https://github.com/php-amqp/php-amqp/issues/418) + - Fix AMQPEnvelope::getDeliveryTag() return type (Flávio Heleno ) (https://github.com/php-amqp/php-amqp/issues/415) + - Fix ack/nack/reject param documentation (Flávio Heleno ) (https://github.com/php-amqp/php-amqp/issues/414) + - Mention time units in all timeout-related methods (Andrii Dembitskyi ) (https://github.com/php-amqp/php-amqp/issues/410) + +For a complete list of changes see: +https://github.com/php-amqp/php-amqp/compare/v1.11.0...v2.0.0alpha1]]> + 2021-12-01 diff --git a/php_amqp_version.h b/php_amqp_version.h index b44a41bb..300dc520 100644 --- a/php_amqp_version.h +++ b/php_amqp_version.h @@ -1,6 +1,6 @@ #define PHP_AMQP_VERSION_MAJOR 2 #define PHP_AMQP_VERSION_MINOR 0 #define PHP_AMQP_VERSION_PATCH 0 -#define PHP_AMQP_VERSION_EXTRA "alpha1" -#define PHP_AMQP_VERSION "2.0.0alpha1" +#define PHP_AMQP_VERSION_EXTRA "dev" +#define PHP_AMQP_VERSION "2.0.0dev" #define PHP_AMQP_VERSION_ID 20000 From e9c89383da09749b65786bb49a94db590a973f79 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Sun, 30 Jul 2023 13:55:32 +0200 Subject: [PATCH 021/147] New Docker-based development environment (#440) --- .appveyor.yml | 43 -- .env | 1 + .github/workflows/test.yaml | 32 +- DEVELOPMENT.md | 90 +++ README.md | 197 ++---- Vagrantfile | 128 ---- amqp_basic_properties.c | 2 - amqp_channel.c | 1 - amqp_channel.h | 2 + amqp_connection.c | 9 +- amqp_connection_resource.c | 60 +- amqp_envelope.c | 4 - amqp_envelope.h | 1 - amqp_envelope_exception.c | 1 - amqp_exchange.c | 2 - amqp_exchange.h | 3 +- amqp_queue.c | 2 - amqp_queue.h | 3 +- amqp_timestamp.c | 1 - appveyor/build.ps1 | 19 - appveyor/install.ps1 | 36 -- appveyor/package.ps1 | 20 - composer.json | 8 +- docker-compose.yml | 83 +++ infra/php/Dockerfile | 25 + infra/rabbitmq/definitions.json | 44 ++ infra/rabbitmq/enabled_plugins | 1 + infra/rabbitmq/rabbitmq.conf | 12 + infra/tls/Dockerfile | 4 + infra/tls/certificates/.gitignore | 1 + {tools => infra/tools}/functions.php | 2 +- infra/tools/pamqp-build | 23 + infra/tools/pamqp-certificates-generate | 39 ++ infra/tools/pamqp-docker-setup | 24 + .../tools/pamqp-dump-reflection | 5 +- infra/tools/pamqp-format | 8 + .../tools/pamqp-install-librabbitmq | 4 +- .../tools/pamqp-release-cut | 1 + .../tools/pamqp-release-finalize | 1 + infra/tools/pamqp-stubs-lint | 11 + .../tools/pamqp-stubs-validate | 10 +- provision/.bashrc | 127 ---- provision/apache/000-default.conf | 33 - provision/apache/ports.conf | 15 - provision/nginx/default | 21 - provision/php/amqp.ini | 3 - provision/php/www.conf | 414 ------------ provision/provision.sh | 119 ---- provision/rabbitmq.config | 601 ------------------ provision/test_certs/certgen.sh | 20 - provision/test_certs/client/cert.pem | 19 - provision/test_certs/client/key.pem | 27 - provision/test_certs/client/req.pem | 17 - provision/test_certs/sasl-client/cert.pem | 19 - provision/test_certs/sasl-client/key.pem | 27 - provision/test_certs/sasl-client/req.pem | 17 - provision/test_certs/server/cert.pem | 19 - provision/test_certs/server/key.pem | 27 - provision/test_certs/server/req.pem | 17 - provision/test_certs/testca/cacert.pem | 21 - provision/test_certs/testca/private/cakey.pem | 28 - ...ection_construct_with_connect_timeout.phpt | 2 +- tests/amqpconnection_ssl.phpt | 141 ---- tests/amqpconnection_ssl_by_cert.phpt | 164 ----- tests/amqpconnection_tls_basic.phpt | 112 ++++ tests/amqpconnection_tls_mtls.phpt | 116 ++++ tests/amqpconnection_tls_sasl.phpt | 120 ++++ tests/bug_19840.phpt | 2 +- tools/check-stubs.sh | 9 - tools/dev-build.sh | 5 - tools/dev-format.sh | 5 - 71 files changed, 865 insertions(+), 2365 deletions(-) delete mode 100644 .appveyor.yml create mode 100644 .env create mode 100644 DEVELOPMENT.md delete mode 100644 Vagrantfile delete mode 100644 appveyor/build.ps1 delete mode 100644 appveyor/install.ps1 delete mode 100644 appveyor/package.ps1 create mode 100644 docker-compose.yml create mode 100644 infra/php/Dockerfile create mode 100644 infra/rabbitmq/definitions.json create mode 100644 infra/rabbitmq/enabled_plugins create mode 100644 infra/rabbitmq/rabbitmq.conf create mode 100644 infra/tls/Dockerfile create mode 100644 infra/tls/certificates/.gitignore rename {tools => infra/tools}/functions.php (99%) create mode 100755 infra/tools/pamqp-build create mode 100755 infra/tools/pamqp-certificates-generate create mode 100755 infra/tools/pamqp-docker-setup rename tools/dump-reflection.php => infra/tools/pamqp-dump-reflection (98%) mode change 100644 => 100755 create mode 100755 infra/tools/pamqp-format rename provision/install_rabbitmq-c.sh => infra/tools/pamqp-install-librabbitmq (96%) rename tools/make-release.php => infra/tools/pamqp-release-cut (97%) mode change 100644 => 100755 rename tools/make-dev.php => infra/tools/pamqp-release-finalize (96%) mode change 100644 => 100755 create mode 100755 infra/tools/pamqp-stubs-lint rename tools/validate-stubs.sh => infra/tools/pamqp-stubs-validate (52%) delete mode 100644 provision/.bashrc delete mode 100644 provision/apache/000-default.conf delete mode 100644 provision/apache/ports.conf delete mode 100644 provision/nginx/default delete mode 100644 provision/php/amqp.ini delete mode 100644 provision/php/www.conf delete mode 100644 provision/provision.sh delete mode 100644 provision/rabbitmq.config delete mode 100644 provision/test_certs/certgen.sh delete mode 100644 provision/test_certs/client/cert.pem delete mode 100644 provision/test_certs/client/key.pem delete mode 100644 provision/test_certs/client/req.pem delete mode 100644 provision/test_certs/sasl-client/cert.pem delete mode 100644 provision/test_certs/sasl-client/key.pem delete mode 100644 provision/test_certs/sasl-client/req.pem delete mode 100644 provision/test_certs/server/cert.pem delete mode 100644 provision/test_certs/server/key.pem delete mode 100644 provision/test_certs/server/req.pem delete mode 100644 provision/test_certs/testca/cacert.pem delete mode 100644 provision/test_certs/testca/private/cakey.pem delete mode 100644 tests/amqpconnection_ssl.phpt delete mode 100644 tests/amqpconnection_ssl_by_cert.phpt create mode 100644 tests/amqpconnection_tls_basic.phpt create mode 100644 tests/amqpconnection_tls_mtls.phpt create mode 100644 tests/amqpconnection_tls_sasl.phpt delete mode 100755 tools/check-stubs.sh delete mode 100755 tools/dev-build.sh delete mode 100755 tools/dev-format.sh diff --git a/.appveyor.yml b/.appveyor.yml deleted file mode 100644 index effb11b0..00000000 --- a/.appveyor.yml +++ /dev/null @@ -1,43 +0,0 @@ -image: Visual Studio 2019 -version: '{branch}.{build}' - -clone_folder: c:\projects\amqp - -install: - - ps: appveyor\install.ps1 - -cache: - - c:\build-cache -> .appveyor.yml, appveyor\install.ps1 - -environment: - BIN_SDK_VER: 2.2.0 - matrix: - - PHP_VER: 8.0.8 - ARCH: x64 - TS: 1 - VC: vs16 - DEP: librabbitmq-0.11.0 - - PHP_VER: 8.0.8 - ARCH: x64 - TS: 0 - VC: vs16 - DEP: librabbitmq-0.11.0 - - PHP_VER: 8.0.8 - ARCH: x86 - TS: 1 - VC: vs16 - DEP: librabbitmq-0.11.0 - - PHP_VER: 8.0.8 - ARCH: x86 - TS: 1 - VC: vs16 - DEP: librabbitmq-0.11.0 - -build_script: - - ps: appveyor\build.ps1 - -after_build: - - ps: appveyor\package.ps1 - -notifications: - - provider: GitHubPullRequest diff --git a/.env b/.env new file mode 100644 index 00000000..f9610f54 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +PHP_AMQP_SSL_HOST=rabbitmq.example.org \ No newline at end of file diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5cffeefb..6d0f5c0c 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -8,6 +8,7 @@ on: env: TEST_TIMEOUT: 120 CFLAGS: -D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror + PHP_AMQP_SSL_HOST: rabbitmq.example.org jobs: checkstyle: @@ -52,16 +53,16 @@ jobs: coverage: none - name: Check stubs - run: ./tools/check-stubs.sh + run: ./infra/tools/pamqp-stubs-lint - name: Build librabbitmq - run: sudo ./provision/install_rabbitmq-c.sh master + run: ./infra/tools/pamqp-install-librabbitmq master - name: Build PHP extension run: phpize && ./configure && make - name: Validate stubs - run: ./tools/validate-stubs.sh + run: ./infra/tools/pamqp-stubs-validate test: name: Test php-${{ matrix.php-version }}${{ matrix.php-thread-safe && '-zts' || '' }} librabbitmq-${{ matrix.librabbitmq-version }} ${{ matrix.test-php-args == '-m' && 'memory leaks' || '' }} @@ -87,19 +88,20 @@ jobs: php-thread-safe: true librabbitmq-version: 'master' test-php-args: '-m' - services: - rabbitmq: - image: rabbitmq:3 - ports: - - 5671:5671 - - 5672:5672 - - 15671:15671 - - 15672:15672 steps: - name: Checkout uses: actions/checkout@v3.5.3 + - name: Configure hostnames + run: sudo echo "127.0.0.1 ${{ env.PHP_AMQP_SSL_HOST }}" | sudo tee -a /etc/hosts + + - name: Generate test certificates + run: docker compose up ca + + - name: Start RabbitMQ + run: docker compose up -d rabbitmq + - name: Install packages run: sudo apt-get install -y cmake valgrind @@ -108,13 +110,14 @@ jobs: with: php-version: ${{ matrix.php-version }} coverage: none + extensions: simplexml env: phpts: ${{ matrix.php-thread-safe && 'ts' || 'nts' }} - name: Build librabbitmq - run: sudo ./provision/install_rabbitmq-c.sh ${{ matrix.librabbitmq-version }} + run: ./infra/tools/pamqp-install-librabbitmq ${{ matrix.librabbitmq-version }} - - name: Debug librabbitmq + - name: Print librabbitmq version run: pkg-config librabbitmq --debug - name: Build PHP extension @@ -123,6 +126,9 @@ jobs: - name: Test PHP extension run: make test | tee result.txt + - name: Dump RabbitMQ logs + run: docker compose logs + - name: Benchmark PHP extension run: php -n -c './tmp-php.ini' -d "extension_dir=./modules/" -d "extension=amqp.so" benchmark.php diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md new file mode 100644 index 00000000..1bedf6cf --- /dev/null +++ b/DEVELOPMENT.md @@ -0,0 +1,90 @@ +# PHP AMQP extension development + +PHP AMQP comes with a Docker based development environment that offers containers with multiple PHP versions as well +as a properly configured RabbitMQ instance. The development environment supports building the library against multiple +PHP versions in parallel. + +## Getting started + +To start the development environment, run this command: + +```commandline +docker compose up +``` + +The command will start the development environment in the foreground. This is quite nice as it will conveniently surface +all the logs, especially the RabbitMQ logs. + +## The environment + +Four different development containers are provided at the moment: + +- `debian-74`: PHP 7.4 on Debian 11 ("Bullseye") +- `debian-80`: PHP 8.0 on Debian 12 ("Bookworm") +- `debian-81`: PHP 8.1 on Debian 12 ("Bookworm") +- `debian-82`: PHP 8.1 on Debian 12 ("Bookworm") + +To enter the container, run this command: + +``` +docker compose exec debian-82 bash +``` + +You will automatically land in `/src/build/debian-82`, which is the container specific build dir. The whole source +tree is mounted to `/src`. + +### Building the extension + +To build the extension, a helper tool is available: + +```commandline +pamqp-build +``` + +Once you have made a change, run `pamqp-build` again. `pamqp-build` will try and only build what is necessary. If you +want to build from scratch, run `pamqp-build`. + +🧠 The few development tools available all start with `pamqp-`, so typing `pamqp` and then hitting Tab +gives you a list of tools available. + +### Running tests + +Once you have built the extension it’s a good idea to make sure that all tests are passing before you make your change. + +Run this command: + +```commandline +make test +``` + +To inspect a test failure, you can view the result file relative from the container build directory, as there is a +symlink available to make that as simple as possible: + +```commandline +cat tests/amqp_some_test.out +``` + +### Formatting + +Discussing coding style is as much as it is futile, so PHP AMQP using clang-format to automatically format the source +code. Run this command to format: + +```commandline +pamqp-format +``` + +### Validating stubs + +When PHP AMQP’s API changes, it is very important that reflection info is correct and in sync with the stubs. For that +reason `pamqp-stubs-validate` exists to validate that the two sources of information are in sync. + +```commandline +pamqp-stubs-validate +``` + +# Release management + +Say we want to release "1.10.11" next. We first run `./infra/tools/pamqp-release-cut 1.10.11`. This will update the +version numbers and pre-populate the changelog with the latest git commits between the previous version and now. It will +prompt you to edit the changelog. Once the release is done it tells you what to do next. +Run `./infra/tools/pamqp-release-finalize 1.10.12dev` to bring latest back into development mode afterward. diff --git a/README.md b/README.md index deee9f4b..0b4a5baf 100644 --- a/README.md +++ b/README.md @@ -2,166 +2,103 @@ Object-oriented PHP bindings for the AMQP C library (https://github.com/alanxz/rabbitmq-c) - ### Requirements: - - PHP >= 7.4 with either ZTS or non-ZTS version. - - [RabbitMQ C library](https://github.com/alanxz/rabbitmq-c), commonly known as librabbitmq - (since php-amqp >= 2.0.0 librabbitmq >= 0.10.0, - see [release notes](https://pecl.php.net/package-changelog.php?package=amqp)). - - to run tests [RabbitMQ server](https://www.rabbitmq.com/) >= 3.4.0 required. - +- PHP >= 7.4 with either ZTS or non-ZTS version. +- [RabbitMQ C library](https://github.com/alanxz/rabbitmq-c), commonly known as librabbitmq + (since php-amqp >= 2.0.0 librabbitmq >= 0.10.0, + see [release notes](https://pecl.php.net/package-changelog.php?package=amqp)). +- to run tests [RabbitMQ server](https://www.rabbitmq.com/) >= 3.4.0 required. ### Installation #### Linux - Some systems has php-amqp extension in their repo or available via external repositories, so it is MAY be the preferable - way to install. - - RPM packages are available in Fedora and EPEL (for RHEL and CentOS) official repositories, - see [php-pecl-amqp](https://apps.fedoraproject.org/packages/php-pecl-amqp) - - Fresh `php-pecl-amqp` and `librabbitmq` RPMs available via [remi repo](http://rpms.remirepo.net/). - - If you want to stay on the bleeding edge and have the latest version, install php-amqp extension from - [PECL](http://pecl.php.net/package/amqp) or compile from sources - (follow [PHP official docs instruction](http://us1.php.net/manual/en/install.pecl.phpize.php)). - + +Some systems have php-amqp extension available in their package repositories or available via an external repository so it is MAY be the preferable +way to install. + +Fresh `php-pecl-amqp` and `librabbitmq` RPMs available via [remi repo](http://rpms.remirepo.net/). + +If you want to stay on the bleeding edge and have the latest version, install php-amqp extension from +[PECL](http://pecl.php.net/package/amqp) or compile from sources +(follow [PHP official docs instruction](http://us1.php.net/manual/en/install.pecl.phpize.php)). + #### Windows - - Before download, check if your PHP installation is thread safe or non-thread safe by entering php -i|findstr "Thread" in your terminal - - Download thread safe or non-thread safe version of the extension for your PHP version from https://pecl.php.net/package/amqp. Look for the "DLL" link next to each release in the list of available releases - - After download, copy the `rabbitmq.4.dll` and `rabbitmq.4.pdb` files to the PHP root folder and copy `php_amqp.dll` and `php_amqp.pdb` files to `PHP\ext` folder - - Add `extension=amqp` to the `php.ini` file - - Check if the module is properly installed with php -m + +- Before download, check if your PHP installation is thread safe or non-thread safe by entering php -i|findstr " + Thread" in your terminal +- Download thread safe or non-thread safe version of the extension for your PHP version + from https://pecl.php.net/package/amqp. Look for the "DLL" link next to each release in the list of available releases +- After download, copy the `rabbitmq.4.dll` and `rabbitmq.4.pdb` files to the PHP root folder and copy `php_amqp.dll` + and `php_amqp.pdb` files to `PHP\ext` folder +- Add `extension=amqp` to the `php.ini` file +- Check if the module is properly installed with php -m ### Documentation -View [RabbitMQ official tutorials](http://www.rabbitmq.com/getstarted.html) +View [RabbitMQ official tutorials](http://www.rabbitmq.com/getstarted.html) and [php-amqp specific examples](https://github.com/rabbitmq/rabbitmq-tutorials/tree/main/php-amqp). There are also available [stub files](https://github.com/php-amqp/php-amqp/tree/latest/stubs) with accurate PHPDoc which may be also used in your IDE for code completion, navigation and documentation in-place. -Finally, check out the [tests](https://github.com/php-amqp/php-amqp/tree/latest/tests) to see typical usage and edge cases. - +Finally, check out the [tests](https://github.com/php-amqp/php-amqp/tree/latest/tests) to see typical usage and edge +cases. + ### Notes - - Max channels per connection means how many concurrent channels per connection may be opened at the same time - (this limit may be increased later to max AMQP protocol number - 65532 without any problem). +- Max channels per connection means how many concurrent channels per connection may be opened at the same time + (this limit may be increased later to max AMQP protocol number - 65532 without any problem). +- Nested header arrays may contain only string values. +- You can't share none of AMQP API objects (none of `AMQPConnection`, `AMQPChannel`, `AMQPQueue`, `AMQPExchange`) + between threads. + You have to use separate connection and so on per thread. - - Nested header arrays may contain only string values. - - - You can't share none of AMQP API objects (none of `AMQPConnection`, `AMQPChannel`, `AMQPQueue`, `AMQPExchange`) between threads. - You have to use separate connection and so on per thread. - ### Related libraries -* [enqueue/amqp-ext](https://github.com/php-enqueue/amqp-ext) is a [amqp interop](https://github.com/queue-interop/queue-interop#amqp-interop) compatible wrapper. +* [enqueue/amqp-ext](https://github.com/php-enqueue/amqp-ext) is + a [amqp interop](https://github.com/queue-interop/queue-interop#amqp-interop) compatible wrapper. #### Persistent connection - Limitations: +Limitations: - - there may be only one persistent connection per unique credentials (login+password+host+port+vhost). - If there will be an attempt to create another persistent connection with the same credentials, an exception will be thrown. - - channels on persistent connections are not persistent: they are destroyed between requests. - - heartbeats are limited to blocking calls only, so if there are no any operations on a connection or no active - consumer set, connection may be closed by the broker as dead. +- there may only be one persistent connection per unique credentials (login+password+host+port+vhost). + If there will be an attempt to create another persistent connection with the same credentials, an exception will be + thrown. +- channels on persistent connections are not persistent: they are destroyed between requests. +- heartbeats are limited to blocking calls only, so if there are no any operations on a connection or no active + consumer set, connection may be closed by the broker as dead. -*Developers note: alternatively for built-in persistent connection support [raphf](http://pecl.php.net/package/raphf) pecl extension may be used.* +*Developers note: alternatively for built-in persistent connection support [raphf](http://pecl.php.net/package/raphf) +pecl extension may be used.* ### How to report a problem - - 1. First, search through the closed issues and [stackoverflow.com](http://stackoverflow.com). - 3. Submit an issue with short and definitive title that describe your problem - 4. Provide platform info, PHP interpreter version, SAPI mode (cli, fpm, cgi, etc) extension is used in, php-amqp extension version, librabbitmq version, make tools version. - 5. Description should provide information on how to reproduce a problem ([gist](https://gist.github.com/) is the most preferable way to include large sources) in a definitive way. Use [Vagrant](http://www.vagrantup.com/) to replicate unusual environments. - 6. If stack trace is generated, include it in full via [gist](https://gist.github.com/) or the important part (if you definitely know what you are doing) directly in the description. - -#### Things to check before reporting a problem - - Some of them, the list is not complete. - - 1. You are running on correct machine in correct environment and your platform meets your application requirement. - 2. librabbimq is installed and discoverable in your environment so php-amqp extension can load it. - 3. php-amqp extension present in system (find `amqp.so` or `amqp.dll` if you are on windows), it is loaded (`php --ri amqp` produced some info), and there are no underlying abstraction that MAY emulate php-amqp work. - 5. You hav correct RabbitMQ credentials. - 6. You are using the latest php-amqp, librabbitmq, RabbitMQ and sometimes PHP version itself. Sometimes your problem is already solved. - 7. Other extensions disabled (especially useful when PHP interpreter crashes and you get stack trace and segmentation fault). - - -## Development - - There is a Vagrant environment with pre-installed software and libraries necessary to build, test and run the php-amqp extension. - - To start it, just type `vagrant up` and then `vagrant ssh` in php-amqp directory. - Services available out of the box are: +1. First, search through the closed issues and [stackoverflow.com](http://stackoverflow.com). +2. Submit an issue with short and definitive title that describe your problem +3. Provide platform info, PHP interpreter version, SAPI mode (cli, fpm, cgi, etc) extension is used in, php-amqp + extension version, librabbitmq version, make tools version. +4. Description should provide information on how to reproduce a problem ([gist](https://gist.github.com/) is the most + preferable way to include large sources) in a definitive way. Use [Vagrant](http://www.vagrantup.com/) to replicate + unusual environments. +5. If stack trace is generated, include it in full via [gist](https://gist.github.com/) or the important part (if you + definitely know what you are doing) directly in the description. - - Apache2 - on [192.168.33.10:8080](http://192.168.33.10:8080) - - nginx - on [192.168.33.10:80](http://192.168.33.10:80) - - RabbitMQ on [192.168.33.10:15672](http://192.168.33.10:15672/#/login/guest/guest) with guest access (login: `guest`, password: `guest`) - -Additional tools are pre-installed to make development process as simple as possible: - -##### valgrind - -Valgrind is ready to help find memory-related problems if you `export TEST_PHP_ARGS=-m` before running tests. - -##### phpbrew - -[phpbrew](https://github.com/phpbrew/phpbrew) waits to help you to test extension on various PHP versions. -`phpbrew install 5.6 +debug+default+fpm` is a nice start. To switch to some version just use `phpbrew switch `. - -To start php-fpm just run `phpbrew fpm start` (don't forget to run `sudo service stop php5-fpm` befor). - -This development environment out of the box ready for php-fpm and cli extension usage, if need to test it when php -used as apache module, refer to [Apache2 support on phpbrew wiki](https://github.com/phpbrew/phpbrew/wiki/Cookbook#apache2-support). -Keep in mind that `+apxs2` conficts with `+fpm` and it is a bit tricky to specify which libphp .so will be loaded. - -##### tshark - -> [tshark](https://www.wireshark.org/docs/man-pages/tshark.html) - Dump and analyze network traffic -> -> ... TShark is able to detect, read and write the same capture files that are supported by Wireshark. - -To use it you probably have to set network privileges for dumpcap first(see -[Platform-Specific information about capture privileges](https://wiki.wireshark.org/CaptureSetup/CapturePrivileges) Wireshark docs page -and [running wireshark “Lua: Error during loading”](http://askubuntu.com/questions/454734/running-wireshark-lua-error-during-loading) SO question): - - `sudo setcap 'CAP_NET_RAW+eip CAP_NET_ADMIN+eip' /usr/bin/dumpcap` - -To start capturing, run `tshark -i lo` to see output in terminal or `tshark -i lo -w capture.log` to save capture and -analyze it later (even with [AMQP](https://wiki.wireshark.org/AMQP) protocol Wireshark plugin). You may filter AMQP packages -using `-Y amqp` attribute, just give a try - `tshark -i lo -Y amqp`. - -> NOTE: -w provides raw packet data, not text. If you want text output you need to redirect stdout (e.g. using '>'), don't use the -w option for this. - -#### Formatting - -Run `./tools/dev-format.sh` to automatically format all `.c` and `.h` files. Note: this requires `clang-format` >=17. - -#### Configuring a RabbitMQ server +#### Things to check before reporting a problem -If you need to tweak RabbitMQ server params use default config -[rabbitmq.conf.example](https://github.com/rabbitmq/rabbitmq-server/blob/main/deps/rabbit/docs/rabbitmq.conf.example) -([raw](https://raw.githubusercontent.com/rabbitmq/rabbitmq-server/main/deps/rabbit/docs/rabbitmq.conf.example)) -from [official RabbitmMQ repo](https://github.com/rabbitmq/rabbitmq-server), so it may look like -`sudo curl https://raw.githubusercontent.com/rabbitmq/rabbitmq-server/main/deps/rabbit/docs/rabbitmq.conf.example /etc/rabbitmq/rabbitmq.config` - -To reset RabbitMQ application run in CLI (as privileged user) `rabbitmqctl stop_app && rabbitmqctl reset && rabbitmqctl start_app`. +Some of them, the list is not complete. -#### Keeping track of the workers - It is a good practice to keep php processes (i.e workers/consumers) under control. Usually, system administrators write their own scripts which ask services about current status or performs some desired actions. Usually request is sent via UNIX signals.
- Because amqp consume method is blocking, pcntl extension seems to be useless. - - [php-signal-handler](https://github.com/RST-com-pl/php-signal-handler) extension uses signal syscall, - so it will work even if blocking method was executed. - Some use cases are presented on extension's github page and examples are available [here](https://github.com/php-amqp/php-amqp/pull/89). +1. You are running on correct machine in correct environment and your platform meets your application requirement. +2. librabbitmq is installed and discoverable in your environment so php-amqp extension can load it. +3. php-amqp extension present in system (find `amqp.so` or `amqp.dll` if you are on windows), it is + loaded (`php --ri amqp` produced some info), and there are no underlying abstraction that MAY emulate php-amqp work. +4. You hav correct RabbitMQ credentials. +5. You are using the latest php-amqp, librabbitmq, RabbitMQ and sometimes PHP version itself. Sometimes your problem is + already solved. +6. Other extensions disabled (especially useful when PHP interpreter crashes, and you get a stack trace and segmentation + fault). +## Development -#### Rolling a release -Say we want to release "1.1000.0" next. We first run `php tools/make-release.php 1.1000.0`. This will update the version -numbers and pre-populate the changelog with the latest git commits between the previous version and now. It will prompt -you to edit the changelog in between. Once the release is done it tells you what to do next. -Run `php tools/make-dev.php 1.1000.1` to bring latest back into development mode afterwards. +See [DEVELOPMENT.md](DEVELOPMENT.md) for details. diff --git a/Vagrantfile b/Vagrantfile deleted file mode 100644 index 9339fa78..00000000 --- a/Vagrantfile +++ /dev/null @@ -1,128 +0,0 @@ -# -*- mode: ruby -*- -# vi: set ft=ruby : - -# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! -VAGRANTFILE_API_VERSION = "2" - -Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| - # All Vagrant configuration is done here. The most common configuration - # options are documented and commented below. For a complete reference, - # please see the online documentation at vagrantup.com. - - # Every Vagrant virtual environment requires a box to build off of. - - config.vm.box = "bento/ubuntu-16.04" - - # Disable automatic box update checking. If you disable this, then - # boxes will only be checked for updates when the user runs - # `vagrant box outdated`. This is not recommended. - # config.vm.box_check_update = false - - # Create a forwarded port mapping which allows access to a specific port - # within the machine from a port on the host machine. In the example below, - # accessing "localhost:8080" will access port 80 on the guest machine. - # config.vm.network "forwarded_port", guest: 80, host: 8080 - - # Create a private network, which allows host-only access to the machine - # using a specific IP. - config.vm.network "private_network", ip: "192.168.33.10" - - # Create a public network, which generally matched to bridged network. - # Bridged networks make the machine appear as another physical device on - # your network. - # config.vm.network "public_network" - - # If true, then any SSH connections made will enable agent forwarding. - # Default value: false - # config.ssh.forward_agent = true - - # Share an additional folder to the guest VM. The first argument is - # the path on the host to the actual folder. The second argument is - # the path on the guest to mount the folder. And the optional third - # argument is a set of non-required options. - # config.vm.synced_folder "../data", "/vagrant_data" - - # Provider-specific configuration so you can fine-tune various - # backing providers for Vagrant. These expose provider-specific options. - # Example for VirtualBox: - # - config.vm.provider "virtualbox" do |vb| - # Don't boot with headless mode - # vb.gui = true - - # Use VBoxManage to customize the VM. For example to change memory: - vb.customize ["modifyvm", :id, "--memory", "2048"] - end - # - # View the documentation for the provider you're using for more - # information on available options. - - # Enable provisioning with CFEngine. CFEngine Community packages are - # automatically installed. For example, configure the host as a - # policy server and optionally a policy file to run: - # - # config.vm.provision "cfengine" do |cf| - # cf.am_policy_hub = true - # # cf.run_file = "motd.cf" - # end - # - # You can also configure and bootstrap a client to an existing - # policy server: - # - # config.vm.provision "cfengine" do |cf| - # cf.policy_server_address = "10.0.2.15" - # end - - # Enable provisioning with Puppet stand alone. Puppet manifests - # are contained in a directory path relative to this Vagrantfile. - # You will need to create the manifests directory and a manifest in - # the file default.pp in the manifests_path directory. - # - # config.vm.provision "puppet" do |puppet| - # puppet.manifests_path = "manifests" - # puppet.manifest_file = "default.pp" - # end - - # Enable provisioning with chef solo, specifying a cookbooks path, roles - # path, and data_bags path (all relative to this Vagrantfile), and adding - # some recipes and/or roles. - # - # config.vm.provision "chef_solo" do |chef| - # chef.cookbooks_path = "../my-recipes/cookbooks" - # chef.roles_path = "../my-recipes/roles" - # chef.data_bags_path = "../my-recipes/data_bags" - # chef.add_recipe "mysql" - # chef.add_role "web" - # - # # You may also specify custom JSON attributes: - # chef.json = { mysql_password: "foo" } - # end - - # Enable provisioning with chef server, specifying the chef server URL, - # and the path to the validation key (relative to this Vagrantfile). - # - # The Opscode Platform uses HTTPS. Substitute your organization for - # ORGNAME in the URL and validation key. - # - # If you have your own Chef Server, use the appropriate URL, which may be - # HTTP instead of HTTPS depending on your configuration. Also change the - # validation key to validation.pem. - # - # config.vm.provision "chef_client" do |chef| - # chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME" - # chef.validation_key_path = "ORGNAME-validator.pem" - # end - # - # If you're using the Opscode platform, your validator client is - # ORGNAME-validator, replacing ORGNAME with your organization name. - # - # If you have your own Chef Server, the default validation client name is - # chef-validator, unless you changed the configuration. - # - # chef.validation_client_name = "ORGNAME-validator" - - config.vm.synced_folder ".", "/home/vagrant/php-amqp" - #config.vm.synced_folder "../rabbitmq-c", "/home/vagrant/rabbitmq-c" - - config.vm.provision "shell", path: './provision/provision.sh', privileged: false -end diff --git a/amqp_basic_properties.c b/amqp_basic_properties.c index 40aca91b..54ea02b6 100644 --- a/amqp_basic_properties.c +++ b/amqp_basic_properties.c @@ -26,8 +26,6 @@ #endif #include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" #include "zend_exceptions.h" #include "Zend/zend_interfaces.h" diff --git a/amqp_channel.c b/amqp_channel.c index cd492792..5fa92e7c 100644 --- a/amqp_channel.c +++ b/amqp_channel.c @@ -26,7 +26,6 @@ #include "php.h" #include "php_ini.h" -#include "ext/standard/info.h" #include "zend_exceptions.h" #ifdef PHP_WIN32 diff --git a/amqp_channel.h b/amqp_channel.h index b66f0865..80e60dee 100644 --- a/amqp_channel.h +++ b/amqp_channel.h @@ -20,6 +20,8 @@ | - Jonathan Tansavatdi | +----------------------------------------------------------------------+ */ +#include "php.h" + extern zend_class_entry *amqp_channel_class_entry; void php_amqp_close_channel(amqp_channel_resource *channel_resource, zend_bool check_errors); diff --git a/amqp_connection.c b/amqp_connection.c index 54c48132..b99867b9 100644 --- a/amqp_connection.c +++ b/amqp_connection.c @@ -41,14 +41,11 @@ #include #include #endif + #if HAVE_LIBRABBITMQ_NEW_LAYOUT #include - #include - #include #else #include - #include - #include #endif #ifdef PHP_WIN32 @@ -62,10 +59,6 @@ #include "amqp_connection_resource.h" #include "amqp_connection.h" -#ifndef E_DEPRECATED - #define E_DEPRECATED E_WARNING -#endif - zend_class_entry *amqp_connection_class_entry; #define this_ce amqp_connection_class_entry diff --git a/amqp_connection_resource.c b/amqp_connection_resource.c index 4fbf14ca..18cbf001 100644 --- a/amqp_connection_resource.c +++ b/amqp_connection_resource.c @@ -26,8 +26,6 @@ #endif #include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" #include "ext/standard/datetime.h" #include "zend_exceptions.h" @@ -61,7 +59,6 @@ #include #endif -//#include "amqp_basic_properties.h" #include "amqp_methods_handling.h" #include "amqp_connection_resource.h" #include "amqp_channel.h" @@ -507,35 +504,49 @@ amqp_connection_resource *connection_resource_constructor(amqp_connection_params return NULL; } - } else { - resource->socket = amqp_tcp_socket_new(resource->connection_state); - if (!resource->socket) { - zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: could not create socket.", 0); + + if (amqp_ssl_socket_set_cacert(resource->socket, params->cacert) != AMQP_STATUS_OK) { + zend_throw_exception( + amqp_connection_exception_class_entry, + "Socket error: could not set CA certificate.", + 0 + ); + connection_resource_destructor(resource, persistent); return NULL; } - } - - if (params->cacert && amqp_ssl_socket_set_cacert(resource->socket, params->cacert)) { - zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: could not set CA certificate.", 0); - - return NULL; - } - if (params->cacert) { #if AMQP_VERSION_MAJOR * 100 + AMQP_VERSION_MINOR * 10 + AMQP_VERSION_PATCH >= 80 amqp_ssl_socket_set_verify_peer(resource->socket, params->verify); amqp_ssl_socket_set_verify_hostname(resource->socket, params->verify); #else amqp_ssl_socket_set_verify(resource->socket, params->verify); #endif - } - if (params->cert && params->key && amqp_ssl_socket_set_key(resource->socket, params->cert, params->key)) { - zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: could not setting client cert.", 0); + if (params->cert && params->key) { + int client_cert_result = amqp_ssl_socket_set_key(resource->socket, params->cert, params->key); + if (client_cert_result != AMQP_STATUS_OK) { + zend_throw_exception_ex( + amqp_connection_exception_class_entry, + 0, + "Socket error: could not set client cert, %s", + amqp_error_string2(client_cert_result) + ); + connection_resource_destructor(resource, persistent); - return NULL; + return NULL; + } + } + + } else { + resource->socket = amqp_tcp_socket_new(resource->connection_state); + + if (!resource->socket) { + zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: could not create socket.", 0); + + return NULL; + } } if (params->connect_timeout > 0) { @@ -546,10 +557,15 @@ amqp_connection_resource *connection_resource_constructor(amqp_connection_params } /* Try to connect and verify that no error occurred */ - if (amqp_socket_open_noblock(resource->socket, params->host, params->port, tv_ptr)) { - - zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: could not connect to host.", 0); + int connection_result = amqp_socket_open_noblock(resource->socket, params->host, params->port, tv_ptr); + if (connection_result != AMQP_STATUS_OK) { + zend_throw_exception_ex( + amqp_connection_exception_class_entry, + 0, + "Socket error: could not connect to host, %s", + amqp_error_string2(connection_result) + ); connection_resource_destructor(resource, persistent); return NULL; diff --git a/amqp_envelope.c b/amqp_envelope.c index def39b5c..c817c0b0 100644 --- a/amqp_envelope.c +++ b/amqp_envelope.c @@ -25,8 +25,6 @@ #endif #include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" #include "zend_exceptions.h" #ifdef PHP_WIN32 @@ -37,10 +35,8 @@ #endif #include "win32/signal.h" #else - #include #include - #endif #if HAVE_LIBRABBITMQ_NEW_LAYOUT diff --git a/amqp_envelope.h b/amqp_envelope.h index 277e059a..ac42a8df 100644 --- a/amqp_envelope.h +++ b/amqp_envelope.h @@ -20,7 +20,6 @@ | - Jonathan Tansavatdi | +----------------------------------------------------------------------+ */ - #include "php_amqp.h" extern zend_class_entry *amqp_envelope_class_entry; diff --git a/amqp_envelope_exception.c b/amqp_envelope_exception.c index 450ffbf1..388958dc 100644 --- a/amqp_envelope_exception.c +++ b/amqp_envelope_exception.c @@ -25,7 +25,6 @@ #endif #include "php.h" -#include "php_ini.h" #include "zend_exceptions.h" #include "php_amqp.h" diff --git a/amqp_exchange.c b/amqp_exchange.c index 07327b09..ceb5b505 100644 --- a/amqp_exchange.c +++ b/amqp_exchange.c @@ -25,8 +25,6 @@ #endif #include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" #include "zend_exceptions.h" #ifdef PHP_WIN32 diff --git a/amqp_exchange.h b/amqp_exchange.h index a590db89..91235455 100644 --- a/amqp_exchange.h +++ b/amqp_exchange.h @@ -20,7 +20,8 @@ | - Jonathan Tansavatdi | +----------------------------------------------------------------------+ */ -extern zend_class_entry *amqp_exchange_class_entry; +#include "php.h" +extern zend_class_entry *amqp_exchange_class_entry; PHP_MINIT_FUNCTION(amqp_exchange); diff --git a/amqp_queue.c b/amqp_queue.c index 367fbbe8..c9708563 100644 --- a/amqp_queue.c +++ b/amqp_queue.c @@ -26,7 +26,6 @@ #include "php.h" #include "php_ini.h" -#include "ext/standard/info.h" #include "zend_exceptions.h" #ifdef PHP_WIN32 @@ -63,7 +62,6 @@ #include "amqp_envelope.h" #include "amqp_queue.h" #include "amqp_type.h" -#include "php_amqp.h" zend_class_entry *amqp_queue_class_entry; #define this_ce amqp_queue_class_entry diff --git a/amqp_queue.h b/amqp_queue.h index 396d2140..4a65dcf0 100644 --- a/amqp_queue.h +++ b/amqp_queue.h @@ -20,7 +20,8 @@ | - Jonathan Tansavatdi | +----------------------------------------------------------------------+ */ -extern zend_class_entry *amqp_queue_class_entry; +#include "php.h" +extern zend_class_entry *amqp_queue_class_entry; PHP_MINIT_FUNCTION(amqp_queue); diff --git a/amqp_timestamp.c b/amqp_timestamp.c index de15834d..437a124b 100644 --- a/amqp_timestamp.c +++ b/amqp_timestamp.c @@ -25,7 +25,6 @@ #endif #include "php.h" -#include "php_ini.h" #include "zend_exceptions.h" #include "php_amqp.h" #include "ext/standard/php_math.h" diff --git a/appveyor/build.ps1 b/appveyor/build.ps1 deleted file mode 100644 index 1602328d..00000000 --- a/appveyor/build.ps1 +++ /dev/null @@ -1,19 +0,0 @@ -$ErrorActionPreference = "Stop" - -cd c:\projects\amqp -#echo "@echo off" | Out-File -Encoding "ASCII" task.bat -#echo "" | Out-File -Encoding "ASCII" -Append task.bat -echo "" | Out-File -Encoding "ASCII" task.bat -# echo "call phpsdk_deps -d c:\build-cache\deps -c" | Out-File -Encoding "ASCII" -Append task.bat -# echo "if errorlevel 7 call phpsdk_deps -d c:\build-cache\deps -un" | Out-File -Encoding "ASCII" -Append task.bat -echo "call phpize 2>&1" | Out-File -Encoding "ASCII" -Append task.bat -echo "call configure --with-php-build=c:\build-cache\deps --with-amqp --enable-debug-pack 2>&1" | Out-File -Encoding "ASCII" -Append task.bat -echo "nmake /nologo 2>&1" | Out-File -Encoding "ASCII" -Append task.bat -echo "exit %errorlevel%" | Out-File -Encoding "ASCII" -Append task.bat -$here = (Get-Item -Path "." -Verbose).FullName -$runner = 'c:\build-cache\php-sdk-' + $env:BIN_SDK_VER + '\phpsdk' + '-' + $env:VC + '-' + $env:ARCH + '.bat' -$task = $here + '\task.bat' -& $runner -t $task -if (-not $?) { - throw "build failed with errorlevel $LastExitCode" -} diff --git a/appveyor/install.ps1 b/appveyor/install.ps1 deleted file mode 100644 index 7c2bdc04..00000000 --- a/appveyor/install.ps1 +++ /dev/null @@ -1,36 +0,0 @@ -if (-not (Test-Path c:\build-cache)) { - mkdir c:\build-cache -} -$bname = 'php-sdk-' + $env:BIN_SDK_VER + '.zip' -if (-not (Test-Path c:\build-cache\$bname)) { - Invoke-WebRequest "https://github.com/microsoft/php-sdk-binary-tools/archive/$bname" -OutFile "c:\build-cache\$bname" -} -$dname0 = 'php-sdk-binary-tools-php-sdk-' + $env:BIN_SDK_VER -$dname1 = 'php-sdk-' + $env:BIN_SDK_VER -if (-not (Test-Path c:\build-cache\$dname1)) { - 7z x c:\build-cache\$bname -oc:\build-cache - move c:\build-cache\$dname0 c:\build-cache\$dname1 -} -$ts_part = '' -if ('0' -eq $env:TS) { $ts_part = '-nts' } -$bname = 'php-devel-pack-' + $env:PHP_VER + $ts_part + '-Win32-' + $env:VC + '-' + $env:ARCH + '.zip' -if (-not (Test-Path c:\build-cache\$bname)) { - Invoke-WebRequest "http://windows.php.net/downloads/releases/archives/$bname" -OutFile "c:\build-cache\$bname" - if (-not (Test-Path c:\build-cache\$bname)) { - Invoke-WebRequest "http://windows.php.net/downloads/releases/$bname" -OutFile "c:\build-cache\$bname" - } -} -$dname0 = 'php-' + $env:PHP_VER + '-devel-' + $env:VC + '-' + $env:ARCH -$dname1 = 'php-' + $env:PHP_VER + $ts_part + '-devel-' + $env:VC + '-' + $env:ARCH -if (-not (Test-Path c:\build-cache\$dname1)) { - 7z x c:\build-cache\$bname -oc:\build-cache - if ($dname0 -ne $dname1) { - move c:\build-cache\$dname0 c:\build-cache\$dname1 - } -} -$env:PATH = 'c:\build-cache\' + $dname1 + ';' + $env:PATH -$bname = $env:DEP + '-' + $env:VC + '-' + $env:ARCH + '.zip' -if (-not (Test-Path c:\build-cache\$bname)) { - Invoke-WebRequest "http://windows.php.net/downloads/pecl/deps/$bname" -OutFile "c:\build-cache\$bname" - 7z x c:\build-cache\$bname -oc:\build-cache\deps -} diff --git a/appveyor/package.ps1 b/appveyor/package.ps1 deleted file mode 100644 index 878361e8..00000000 --- a/appveyor/package.ps1 +++ /dev/null @@ -1,20 +0,0 @@ -$ts_part = '' -if ('0' -eq $env:TS) { $ts_part = '-nts' } -$arch_part = '' -if ('x64' -eq $env:ARCH) { $arch_part = '-x86_64' } -if ($env:APPVEYOR_REPO_TAG -eq "true") { - $bname = 'php_amqp-' + $env:APPVEYOR_REPO_TAG_NAME + '-' + $env:PHP_VER.substring(0, 3) + '-' + $env:VC + $ts_part + $arch_part -} else { - #$bname = 'php_amqp-' + $env:APPVEYOR_REPO_COMMIT.substring(0, 8) + '-' + $env:PHP_VER.substring(0, 3) + '-' + $env:VC + $ts_part + $arch_part - $bname = 'php_amqp-' + $env:PHP_VER.substring(0, 3) + '-' + $env:VC + $ts_part + $arch_part -} -$zip_bname = $bname + '.zip' -$dll_bname = $bname + '.dll' -$dir = 'c:\projects\amqp\'; -if ('x64' -eq $env:ARCH) { $dir = $dir + 'x64\' } -$dir = $dir + 'Release' -if ('1' -eq $env:TS) { $dir = $dir + '_TS' } -cp $dir\php_amqp.dll $dir\$dll_bname -cp c:\build-cache\deps\LICENSE-MIT $dir\LICENSE-MIT.LIBRABBITMQ -& 7z a c:\$zip_bname $dir\$dll_bname $dir\php_amqp.pdb c:\projects\amqp\LICENSE c:\build-cache\deps\bin\rabbitmq.4.* $dir\LICENSE-MIT.LIBRABBITMQ -Push-AppveyorArtifact c:\$zip_bname diff --git a/composer.json b/composer.json index 86c911e3..d4fd786f 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "pdezwart/php-amqp", + "name": "php-amqp/php-amqp", "type": "library", "description": "PHP AMQP Binding Library", "keywords": [ @@ -8,12 +8,12 @@ "message", "queue" ], - "homepage": "https://github.com/pdezwart/php-amqp", + "homepage": "https://github.com/php-amqp/php-amqp", "license": "PHP-3.01", "authors": [ { - "name": "Pieter de Zwart", - "email": "pdezwart@php.net", + "name": "Lars Strojny", + "email": "lstrojny@php.net", "role": "lead" } ], diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..6e90803d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,83 @@ +version: "3.9" + +services: + rabbitmq: + image: rabbitmq:3-management-alpine + volumes: + - type: bind + source: ./infra/rabbitmq/rabbitmq.conf + target: /etc/rabbitmq/rabbitmq.conf + read_only: true + - type: bind + source: ./infra/rabbitmq/enabled_plugins + target: /etc/rabbitmq/enabled_plugins + read_only: true + - type: bind + source: ./infra/rabbitmq/definitions.json + target: /etc/rabbitmq/definitions.json + read_only: true + - type: bind + source: ./infra/tls/certificates + target: /etc/rabbitmq/certificates + read_only: true + ports: + # Plain TCP + - "5672:5672/tcp" + # SSL + - "5671:5671/tcp" + # Management console + - "15672:15672/tcp" + depends_on: + ca: + condition: service_completed_successfully + extra_hosts: + - "${PHP_AMQP_SSL_HOST}:127.0.0.1" + restart: always + + ca: + build: + context: infra/tls + volumes: + - ./:/src + + debian-74: &php-base + build: &php-base-build + context: infra/php + target: dev + additional_contexts: + php-core: docker-image://php:7.4-zts-bullseye + volumes: + - ./:/src + depends_on: + - rabbitmq + ulimits: + core: -1 + working_dir: /src/build/debian-74 + env_file: .env + links: + - "rabbitmq:${PHP_AMQP_SSL_HOST}" + + debian-80: + <<: *php-base + build: + <<: *php-base-build + additional_contexts: + php-core: docker-image://php:8.0-fpm-bullseye + working_dir: /src/build/debian-80 + + debian-81: + <<: *php-base + build: + <<: *php-base-build + additional_contexts: + php-core: docker-image://php:8.1-fpm-bookworm + working_dir: /src/build/debian-81 + + debian-82: + <<: *php-base + build: + <<: *php-base-build + target: dev-all + additional_contexts: + php-core: docker-image://php:8.2-fpm-bookworm + working_dir: /src/build/debian-82 diff --git a/infra/php/Dockerfile b/infra/php/Dockerfile new file mode 100644 index 00000000..74920eaa --- /dev/null +++ b/infra/php/Dockerfile @@ -0,0 +1,25 @@ +# syntax=docker/dockerfile:1.4 +FROM php-core AS dev + +RUN set -xe; \ + apt-get update -yqq && \ + pecl channel-update pecl.php.net + +RUN apt-get install -yqq build-essential +RUN apt-get install -yqq librabbitmq-dev +RUN apt-get install -yqq socat +RUN apt-get install -yqq gdb + +RUN echo 'PATH=$PATH:/src/infra/tools' >> /etc/bash.bashrc +RUN echo 'CFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror"' >> /etc/bash.bashrc + +CMD PHP_AMQP_DOCKER_ENTRYPOINT=1 php /src/infra/tools/pamqp-docker-setup && \ + # Forward localhost:5672 to rabbitmq:5672 (Plain TCP) so that the testsuite can access RabbitMQ on localhost + socat tcp-listen:5672,reuseaddr,fork tcp:rabbitmq:5672 + +FROM dev AS dev-all +RUN apt-get install -yqq gnupg2 +RUN echo "deb https://apt.llvm.org/bookworm/ llvm-toolchain-bookworm main" > /etc/apt/sources.list.d/llvm.list +RUN curl https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - +RUN apt-get update -yqq +RUN apt-get install -yqq clang-format-17 \ No newline at end of file diff --git a/infra/rabbitmq/definitions.json b/infra/rabbitmq/definitions.json new file mode 100644 index 00000000..782e2f7a --- /dev/null +++ b/infra/rabbitmq/definitions.json @@ -0,0 +1,44 @@ +{ + "users": [ + { + "name": "guest", + "password": "guest", + "tags": [ + "administrator" + ] + }, + { + "name": "CN=sasl-client.example.org,O=Example Org,L=Lisboa,ST=Lisboa,C=PT", + "password": "", + "tags": [ + "administrator" + ] + } + ], + "permissions": [ + { + "configure": ".*", + "read": ".*", + "user": "guest", + "vhost": "/", + "write": ".*" + }, + { + "configure": ".*", + "read": ".*", + "user": "CN=sasl-client.example.org,O=Example Org,L=Lisboa,ST=Lisboa,C=PT", + "vhost": "/", + "write": ".*" + } + ], + "vhosts": [ + { + "limits": [], + "metadata": { + "description": "Default virtual host", + "tags": [] + }, + "name": "/" + } + ] +} \ No newline at end of file diff --git a/infra/rabbitmq/enabled_plugins b/infra/rabbitmq/enabled_plugins new file mode 100644 index 00000000..9fee0096 --- /dev/null +++ b/infra/rabbitmq/enabled_plugins @@ -0,0 +1 @@ +[rabbitmq_management,rabbitmq_auth_mechanism_ssl]. \ No newline at end of file diff --git a/infra/rabbitmq/rabbitmq.conf b/infra/rabbitmq/rabbitmq.conf new file mode 100644 index 00000000..7f4430ce --- /dev/null +++ b/infra/rabbitmq/rabbitmq.conf @@ -0,0 +1,12 @@ +listeners.ssl.default = 5671 + +ssl_options.cacertfile = /etc/rabbitmq/certificates/testca/cacert.pem +ssl_options.certfile = /etc/rabbitmq/certificates/server/cert.pem +ssl_options.keyfile = /etc/rabbitmq/certificates/server/key.pem +ssl_options.verify = verify_peer +ssl_options.fail_if_no_peer_cert = false + +auth_mechanisms.0 = PLAIN +auth_mechanisms.1 = EXTERNAL + +load_definitions = /etc/rabbitmq/definitions.json diff --git a/infra/tls/Dockerfile b/infra/tls/Dockerfile new file mode 100644 index 00000000..b614bd15 --- /dev/null +++ b/infra/tls/Dockerfile @@ -0,0 +1,4 @@ +FROM alpine:3 +RUN apk add openssl +RUN apk add acl +CMD /src/infra/tools/pamqp-certificates-generate /src/infra/tls/certificates diff --git a/infra/tls/certificates/.gitignore b/infra/tls/certificates/.gitignore new file mode 100644 index 00000000..72e8ffc0 --- /dev/null +++ b/infra/tls/certificates/.gitignore @@ -0,0 +1 @@ +* diff --git a/tools/functions.php b/infra/tools/functions.php similarity index 99% rename from tools/functions.php rename to infra/tools/functions.php index 3eef6903..4c6396b2 100644 --- a/tools/functions.php +++ b/infra/tools/functions.php @@ -21,7 +21,7 @@ use function tempnam; use function trim; -const BASE_DIR = __DIR__ . '/../'; +const BASE_DIR = __DIR__ . '/../../'; const STABILITY_REGEX = '(?:alpha|beta|dev|RC)\d*'; const MAJOR_MINOR_PATCH = '\d+\.\d+\.\d+'; const VERSION_REGEX = MAJOR_MINOR_PATCH . '(?:' . STABILITY_REGEX . ')?'; diff --git a/infra/tools/pamqp-build b/infra/tools/pamqp-build new file mode 100755 index 00000000..538053eb --- /dev/null +++ b/infra/tools/pamqp-build @@ -0,0 +1,23 @@ +#!/usr/bin/env sh + +set -o errexit +set -o nounset + +base_dir=`dirname $0`/../../ +real_base_dir=`realpath $base_dir` + +mode="${1:-}" + +if test ! -x $real_base_dir/configure -o "$mode" = "clean"; then + (cd $real_base_dir && phpize) +fi + +if test ! -f Makefile -o "$mode" = "clean"; then + $real_base_dir/configure +fi + +if test "$mode" = "clean"; then + make clean +fi + +make \ No newline at end of file diff --git a/infra/tools/pamqp-certificates-generate b/infra/tools/pamqp-certificates-generate new file mode 100755 index 00000000..dd74a2aa --- /dev/null +++ b/infra/tools/pamqp-certificates-generate @@ -0,0 +1,39 @@ +#!/usr/bin/env sh + +set -o errexit +set -o nounset + +cert_dir="${1:-}" + +if test -z "$cert_dir"; then + echo "`basename $0` " + exit 1 +fi + +mkdir -p $cert_dir +rm -rf $cert_dir/* + +mkdir -p $cert_dir/testca/private $cert_dir/server $cert_dir/sasl-client $cert_dir/client + +(cd $cert_dir/testca && + openssl req -new -x509 -keyout private/cakey.pem -out cacert.pem -days 365 -nodes -subj "/C=PT/ST=Lisboa/L=Lisboa/O=Example Org") + +(cd $cert_dir/server && + openssl genrsa -out key.pem 2048 && + openssl req -new -key key.pem -out req.pem -subj "/C=PT/ST=Lisboa/L=Lisboa/O=Example Org/CN=*.example.org" && + openssl x509 -req -in req.pem -CA ../testca/cacert.pem -CAkey ../testca/private/cakey.pem -CAcreateserial -out cert.pem -days 365) + +(cd $cert_dir/sasl-client && + openssl genrsa -out key.pem 2048 && + openssl req -new -key key.pem -out req.pem -subj "/C=PT/ST=Lisboa/L=Lisboa/O=Example Org/CN=sasl-client.example.org" && + openssl x509 -req -in req.pem -CA ../testca/cacert.pem -CAkey ../testca/private/cakey.pem -CAcreateserial -out cert.pem -days 365) + +(cd $cert_dir/client && + openssl genrsa -out key.pem 2048 && + openssl req -new -key key.pem -out req.pem -subj "/C=PT/ST=Lisboa/L=Lisboa/O=Example Org/CN=client.example.org" && + openssl x509 -req -in req.pem -CA ../testca/cacert.pem -CAkey ../testca/private/cakey.pem -CAcreateserial -out cert.pem -days 365) + +# Set permissions for the different images consuming the certificates +# - 100 is the UID of the rabbitmq user of the rabbitmq image that runs the rabbitmq process +# - 1001 is the UID of the GitHub Action runner user that runs the tests +setfacl -R -m u:100:rX -m u:1001:rX $cert_dir diff --git a/infra/tools/pamqp-docker-setup b/infra/tools/pamqp-docker-setup new file mode 100755 index 00000000..8347c044 --- /dev/null +++ b/infra/tools/pamqp-docker-setup @@ -0,0 +1,24 @@ +#!/usr/bin/env php + [], @@ -173,11 +174,11 @@ function getClassMetadata(string $class): array { spl_autoload_register(function(string $class) { - require_once __DIR__ . '/../stubs/' . $class . '.php'; + require_once __DIR__ . '/../../stubs/' . $class . '.php'; }); if (!extension_loaded('amqp')) { - require_once __DIR__ . '/../stubs/AMQP.php'; + require_once __DIR__ . '/../../stubs/AMQP.php'; } const NON_DETERMINISTIC_CONSTANTS = [ diff --git a/infra/tools/pamqp-format b/infra/tools/pamqp-format new file mode 100755 index 00000000..265c20a3 --- /dev/null +++ b/infra/tools/pamqp-format @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +set -o errexit +set -o nounset + +base_dir=`dirname $0`/../../ + +clang-format-17 -i $base_dir/*.c $base_dir/*.h \ No newline at end of file diff --git a/provision/install_rabbitmq-c.sh b/infra/tools/pamqp-install-librabbitmq similarity index 96% rename from provision/install_rabbitmq-c.sh rename to infra/tools/pamqp-install-librabbitmq index 3af4b4e5..c78d16d8 100755 --- a/provision/install_rabbitmq-c.sh +++ b/infra/tools/pamqp-install-librabbitmq @@ -1,6 +1,5 @@ -#!/bin/sh +#!/usr/bin/env sh -# Setup a sane environment set -o errexit set -o nounset @@ -32,6 +31,7 @@ mkdir -p $BUILD_TMP # Download and extract the source code curl -sSLf "https://codeload.github.com/alanxz/rabbitmq-c/tar.gz/$LIBRABBITMQ_VERSION" | tar xz --directory=$BUILD_TMP +export CFLAGS="" cd $BUILD_TMP/rabbitmq-c-* sed -e "s:@VERSION@:@RMQ_VERSION@:g" -i librabbitmq.pc.in diff --git a/tools/make-release.php b/infra/tools/pamqp-release-cut old mode 100644 new mode 100755 similarity index 97% rename from tools/make-release.php rename to infra/tools/pamqp-release-cut index 8347585f..d551053f --- a/tools/make-release.php +++ b/infra/tools/pamqp-release-cut @@ -1,3 +1,4 @@ +#!/usr/bin/env php &/dev/null; then - # We have color support; assume it's compliant with Ecma-48 - # (ISO/IEC-6429). (Lack of such support is extremely rare, and such - # a case would tend to support setf rather than setaf.) - color_prompt=yes - else - color_prompt= - fi -fi - -if [ "$color_prompt" = yes ]; then - PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' -else - PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' -fi -unset color_prompt force_color_prompt - -# If this is an xterm set the title to user@host:dir -case "$TERM" in -xterm*|rxvt*) - PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" - ;; -*) - ;; -esac - -# enable color support of ls and also add handy aliases -if [ -x /usr/bin/dircolors ]; then - test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" - alias ls='ls --color=auto' - #alias dir='dir --color=auto' - #alias vdir='vdir --color=auto' - - alias grep='grep --color=auto' - alias fgrep='fgrep --color=auto' - alias egrep='egrep --color=auto' -fi - -# some more ls aliases -alias ll='ls -alF' -alias la='ls -A' -alias l='ls -CF' - -# Add an "alert" alias for long running commands. Use like so: -# sleep 10; alert -alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' - -# Alias definitions. -# You may want to put all your additions into a separate file like -# ~/.bash_aliases, instead of adding them here directly. -# See /usr/share/doc/bash-doc/examples in the bash-doc package. - -if [ -f ~/.bash_aliases ]; then - . ~/.bash_aliases -fi - -# enable programmable completion features (you don't need to enable -# this, if it's already enabled in /etc/bash.bashrc and /etc/profile -# sources /etc/bash.bashrc). -if ! shopt -oq posix; then - if [ -f /usr/share/bash-completion/bash_completion ]; then - . /usr/share/bash-completion/bash_completion - elif [ -f /etc/bash_completion ]; then - . /etc/bash_completion - fi -fi - -PHPBREW_SET_PROMPT=1 - -source ~/.phpbrew/bashrc - -if [ $(id -u) -eq 0 ]; -then - PS1='${debian_chroot:+()}\[\e[01;31m\]\u\[\e[0m\]@\[\e[01;31m\]\h\[\e[0m\] (\[\e[0;36m\]$(phpbrew_current_php_version)\[\e[0m\]):\[\033[01;34m\]\w\[\033[00m\]# ' -else - PS1='${debian_chroot:+()}\[\e[01;32m\]\u\[\e[0m\]@\[\e[01;32m\]\h\[\e[0m\] (\[\e[0;36m\]$(phpbrew_current_php_version)\[\e[0m\]):\[\033[01;34m\]\w\[\033[00m\]$ ' -fi - -EDITOR=vim \ No newline at end of file diff --git a/provision/apache/000-default.conf b/provision/apache/000-default.conf deleted file mode 100644 index ad10d426..00000000 --- a/provision/apache/000-default.conf +++ /dev/null @@ -1,33 +0,0 @@ - - # The ServerName directive sets the request scheme, hostname and port that - # the server uses to identify itself. This is used when creating - # redirection URLs. In the context of virtual hosts, the ServerName - # specifies what hostname must appear in the request's Host: header to - # match this virtual host. For the default virtual host (this file) this - # value is not decisive as it is used as a last resort host regardless. - # However, you must set it for any further virtual host explicitly. - #ServerName www.example.com - - ServerAdmin webmaster@localhost - DocumentRoot /var/www/html - - DirectoryIndex index.php index-apache.html - - # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, - # error, crit, alert, emerg. - # It is also possible to configure the loglevel for particular - # modules, e.g. - #LogLevel info ssl:warn - - ErrorLog ${APACHE_LOG_DIR}/error.log - CustomLog ${APACHE_LOG_DIR}/access.log combined - - # For most configuration files from conf-available/, which are - # enabled or disabled at a global level, it is possible to - # include a line for only one particular virtual host. For example the - # following line enables the CGI configuration for this host only - # after it has been globally disabled with "a2disconf". - #Include conf-available/serve-cgi-bin.conf - - -# vim: syntax=apache ts=4 sw=4 sts=4 sr noet diff --git a/provision/apache/ports.conf b/provision/apache/ports.conf deleted file mode 100644 index 03d5dd24..00000000 --- a/provision/apache/ports.conf +++ /dev/null @@ -1,15 +0,0 @@ -# If you just change the port or add more ports here, you will likely also -# have to change the VirtualHost statement in -# /etc/apache2/sites-enabled/000-default.conf - -Listen 8080 - - - Listen 443 - - - - Listen 443 - - -# vim: syntax=apache ts=4 sw=4 sts=4 sr noet diff --git a/provision/nginx/default b/provision/nginx/default deleted file mode 100644 index 39cc12ac..00000000 --- a/provision/nginx/default +++ /dev/null @@ -1,21 +0,0 @@ -server { - listen 80 default_server; - listen [::]:80 default_server ipv6only=on; - - root /var/www/html; - - server_name _; - - location / { - try_files $uri $uri/ /index.php?$args; - index index.php index-nginx.html; - } - - location ~ \.php$ { - fastcgi_pass 127.0.0.1:9000; - fastcgi_index index.php; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - include fastcgi_params; - fastcgi_intercept_errors off; - } -} diff --git a/provision/php/amqp.ini b/provision/php/amqp.ini deleted file mode 100644 index 38bfff19..00000000 --- a/provision/php/amqp.ini +++ /dev/null @@ -1,3 +0,0 @@ -; configuration for php AMQP module -; priority=10 -extension=amqp.so diff --git a/provision/php/www.conf b/provision/php/www.conf deleted file mode 100644 index 0bf9ef99..00000000 --- a/provision/php/www.conf +++ /dev/null @@ -1,414 +0,0 @@ -; Start a new pool named 'www'. -; the variable $pool can be used in any directive and will be replaced by the -; pool name ('www' here) -[www] - -; Per pool prefix -; It only applies on the following directives: -; - 'access.log' -; - 'slowlog' -; - 'listen' (unixsocket) -; - 'chroot' -; - 'chdir' -; - 'php_values' -; - 'php_admin_values' -; When not set, the global prefix (or /usr) applies instead. -; Note: This directive can also be relative to the global prefix. -; Default Value: none -;prefix = /path/to/pools/$pool - -; Unix user/group of processes -; Note: The user is mandatory. If the group is not set, the default user's group -; will be used. -user = www-data -group = www-data - -; The address on which to accept FastCGI requests. -; Valid syntaxes are: -; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on -; a specific port; -; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on -; a specific port; -; 'port' - to listen on a TCP socket to all addresses -; (IPv6 and IPv4-mapped) on a specific port; -; '/path/to/unix/socket' - to listen on a unix socket. -; Note: This value is mandatory. -;listen = /run/php/php7.0-fpm.sock -listen = 127.0.0.1:9000 - -; Set listen(2) backlog. -; Default Value: 511 (-1 on FreeBSD and OpenBSD) -;listen.backlog = 511 - -; Set permissions for unix socket, if one is used. In Linux, read/write -; permissions must be set in order to allow connections from a web server. Many -; BSD-derived systems allow connections regardless of permissions. -; Default Values: user and group are set as the running user -; mode is set to 0660 -listen.owner = www-data -listen.group = www-data -;listen.mode = 0660 -; When POSIX Access Control Lists are supported you can set them using -; these options, value is a comma separated list of user/group names. -; When set, listen.owner and listen.group are ignored -;listen.acl_users = -;listen.acl_groups = - -; List of addresses (IPv4/IPv6) of FastCGI clients which are allowed to connect. -; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original -; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address -; must be separated by a comma. If this value is left blank, connections will be -; accepted from any ip address. -; Default Value: any -;listen.allowed_clients = 127.0.0.1 - -; Specify the nice(2) priority to apply to the pool processes (only if set) -; The value can vary from -19 (highest priority) to 20 (lower priority) -; Note: - It will only work if the FPM master process is launched as root -; - The pool processes will inherit the master process priority -; unless it specified otherwise -; Default Value: no set -; process.priority = -19 - -; Choose how the process manager will control the number of child processes. -; Possible Values: -; static - a fixed number (pm.max_children) of child processes; -; dynamic - the number of child processes are set dynamically based on the -; following directives. With this process management, there will be -; always at least 1 children. -; pm.max_children - the maximum number of children that can -; be alive at the same time. -; pm.start_servers - the number of children created on startup. -; pm.min_spare_servers - the minimum number of children in 'idle' -; state (waiting to process). If the number -; of 'idle' processes is less than this -; number then some children will be created. -; pm.max_spare_servers - the maximum number of children in 'idle' -; state (waiting to process). If the number -; of 'idle' processes is greater than this -; number then some children will be killed. -; ondemand - no children are created at startup. Children will be forked when -; new requests will connect. The following parameter are used: -; pm.max_children - the maximum number of children that -; can be alive at the same time. -; pm.process_idle_timeout - The number of seconds after which -; an idle process will be killed. -; Note: This value is mandatory. -pm = dynamic - -; The number of child processes to be created when pm is set to 'static' and the -; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'. -; This value sets the limit on the number of simultaneous requests that will be -; served. Equivalent to the ApacheMaxClients directive with mpm_prefork. -; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP -; CGI. The below defaults are based on a server without much resources. Don't -; forget to tweak pm.* to fit your needs. -; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand' -; Note: This value is mandatory. -pm.max_children = 5 - -; The number of child processes created on startup. -; Note: Used only when pm is set to 'dynamic' -; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2 -pm.start_servers = 2 - -; The desired minimum number of idle server processes. -; Note: Used only when pm is set to 'dynamic' -; Note: Mandatory when pm is set to 'dynamic' -pm.min_spare_servers = 1 - -; The desired maximum number of idle server processes. -; Note: Used only when pm is set to 'dynamic' -; Note: Mandatory when pm is set to 'dynamic' -pm.max_spare_servers = 3 - -; The number of seconds after which an idle process will be killed. -; Note: Used only when pm is set to 'ondemand' -; Default Value: 10s -;pm.process_idle_timeout = 10s; - -; The number of requests each child process should execute before respawning. -; This can be useful to work around memory leaks in 3rd party libraries. For -; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. -; Default Value: 0 -;pm.max_requests = 500 - -; The URI to view the FPM status page. If this value is not set, no URI will be -; recognized as a status page. It shows the following informations: -; pool - the name of the pool; -; process manager - static, dynamic or ondemand; -; start time - the date and time FPM has started; -; start since - number of seconds since FPM has started; -; accepted conn - the number of request accepted by the pool; -; listen queue - the number of request in the queue of pending -; connections (see backlog in listen(2)); -; max listen queue - the maximum number of requests in the queue -; of pending connections since FPM has started; -; listen queue len - the size of the socket queue of pending connections; -; idle processes - the number of idle processes; -; active processes - the number of active processes; -; total processes - the number of idle + active processes; -; max active processes - the maximum number of active processes since FPM -; has started; -; max children reached - number of times, the process limit has been reached, -; when pm tries to start more children (works only for -; pm 'dynamic' and 'ondemand'); -; Value are updated in real time. -; Example output: -; pool: www -; process manager: static -; start time: 01/Jul/2011:17:53:49 +0200 -; start since: 62636 -; accepted conn: 190460 -; listen queue: 0 -; max listen queue: 1 -; listen queue len: 42 -; idle processes: 4 -; active processes: 11 -; total processes: 15 -; max active processes: 12 -; max children reached: 0 -; -; By default the status page output is formatted as text/plain. Passing either -; 'html', 'xml' or 'json' in the query string will return the corresponding -; output syntax. Example: -; http://www.foo.bar/status -; http://www.foo.bar/status?json -; http://www.foo.bar/status?html -; http://www.foo.bar/status?xml -; -; By default the status page only outputs short status. Passing 'full' in the -; query string will also return status for each pool process. -; Example: -; http://www.foo.bar/status?full -; http://www.foo.bar/status?json&full -; http://www.foo.bar/status?html&full -; http://www.foo.bar/status?xml&full -; The Full status returns for each process: -; pid - the PID of the process; -; state - the state of the process (Idle, Running, ...); -; start time - the date and time the process has started; -; start since - the number of seconds since the process has started; -; requests - the number of requests the process has served; -; request duration - the duration in ?s of the requests; -; request method - the request method (GET, POST, ...); -; request URI - the request URI with the query string; -; content length - the content length of the request (only with POST); -; user - the user (PHP_AUTH_USER) (or '-' if not set); -; script - the main script called (or '-' if not set); -; last request cpu - the %cpu the last request consumed -; it's always 0 if the process is not in Idle state -; because CPU calculation is done when the request -; processing has terminated; -; last request memory - the max amount of memory the last request consumed -; it's always 0 if the process is not in Idle state -; because memory calculation is done when the request -; processing has terminated; -; If the process is in Idle state, then informations are related to the -; last request the process has served. Otherwise informations are related to -; the current request being served. -; Example output: -; ************************ -; pid: 31330 -; state: Running -; start time: 01/Jul/2011:17:53:49 +0200 -; start since: 63087 -; requests: 12808 -; request duration: 1250261 -; request method: GET -; request URI: /test_mem.php?N=10000 -; content length: 0 -; user: - -; script: /home/fat/web/docs/php/test_mem.php -; last request cpu: 0.00 -; last request memory: 0 -; -; Note: There is a real-time FPM status monitoring sample web page available -; It's available in: /usr/share/php/7.0/fpm/status.html -; -; Note: The value must start with a leading slash (/). The value can be -; anything, but it may not be a good idea to use the .php extension or it -; may conflict with a real PHP file. -; Default Value: not set -;pm.status_path = /status - -; The ping URI to call the monitoring page of FPM. If this value is not set, no -; URI will be recognized as a ping page. This could be used to test from outside -; that FPM is alive and responding, or to -; - create a graph of FPM availability (rrd or such); -; - remove a server from a group if it is not responding (load balancing); -; - trigger alerts for the operating team (24/7). -; Note: The value must start with a leading slash (/). The value can be -; anything, but it may not be a good idea to use the .php extension or it -; may conflict with a real PHP file. -; Default Value: not set -;ping.path = /ping - -; This directive may be used to customize the response of a ping request. The -; response is formatted as text/plain with a 200 response code. -; Default Value: pong -;ping.response = pong - -; The access log file -; Default: not set -;access.log = log/$pool.access.log - -; The access log format. -; The following syntax is allowed -; %%: the '%' character -; %C: %CPU used by the request -; it can accept the following format: -; - %{user}C for user CPU only -; - %{system}C for system CPU only -; - %{total}C for user + system CPU (default) -; %d: time taken to serve the request -; it can accept the following format: -; - %{seconds}d (default) -; - %{miliseconds}d -; - %{mili}d -; - %{microseconds}d -; - %{micro}d -; %e: an environment variable (same as $_ENV or $_SERVER) -; it must be associated with embraces to specify the name of the env -; variable. Some exemples: -; - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e -; - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e -; %f: script filename -; %l: content-length of the request (for POST request only) -; %m: request method -; %M: peak of memory allocated by PHP -; it can accept the following format: -; - %{bytes}M (default) -; - %{kilobytes}M -; - %{kilo}M -; - %{megabytes}M -; - %{mega}M -; %n: pool name -; %o: output header -; it must be associated with embraces to specify the name of the header: -; - %{Content-Type}o -; - %{X-Powered-By}o -; - %{Transfert-Encoding}o -; - .... -; %p: PID of the child that serviced the request -; %P: PID of the parent of the child that serviced the request -; %q: the query string -; %Q: the '?' character if query string exists -; %r: the request URI (without the query string, see %q and %Q) -; %R: remote IP address -; %s: status (response code) -; %t: server time the request was received -; it can accept a strftime(3) format: -; %d/%b/%Y:%H:%M:%S %z (default) -; The strftime(3) format must be encapsuled in a %{}t tag -; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t -; %T: time the log has been written (the request has finished) -; it can accept a strftime(3) format: -; %d/%b/%Y:%H:%M:%S %z (default) -; The strftime(3) format must be encapsuled in a %{}t tag -; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t -; %u: remote user -; -; Default: "%R - %u %t \"%m %r\" %s" -;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%" - -; The log file for slow requests -; Default Value: not set -; Note: slowlog is mandatory if request_slowlog_timeout is set -;slowlog = log/$pool.log.slow - -; The timeout for serving a single request after which a PHP backtrace will be -; dumped to the 'slowlog' file. A value of '0s' means 'off'. -; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) -; Default Value: 0 -;request_slowlog_timeout = 0 - -; The timeout for serving a single request after which the worker process will -; be killed. This option should be used when the 'max_execution_time' ini option -; does not stop script execution for some reason. A value of '0' means 'off'. -; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) -; Default Value: 0 -;request_terminate_timeout = 0 - -; Set open file descriptor rlimit. -; Default Value: system defined value -;rlimit_files = 1024 - -; Set max core size rlimit. -; Possible Values: 'unlimited' or an integer greater or equal to 0 -; Default Value: system defined value -;rlimit_core = 0 - -; Chroot to this directory at the start. This value must be defined as an -; absolute path. When this value is not set, chroot is not used. -; Note: you can prefix with '$prefix' to chroot to the pool prefix or one -; of its subdirectories. If the pool prefix is not set, the global prefix -; will be used instead. -; Note: chrooting is a great security feature and should be used whenever -; possible. However, all PHP paths will be relative to the chroot -; (error_log, sessions.save_path, ...). -; Default Value: not set -;chroot = - -; Chdir to this directory at the start. -; Note: relative path can be used. -; Default Value: current directory or / when chroot -;chdir = /var/www - -; Redirect worker stdout and stderr into main error log. If not set, stdout and -; stderr will be redirected to /dev/null according to FastCGI specs. -; Note: on highloaded environement, this can cause some delay in the page -; process time (several ms). -; Default Value: no -;catch_workers_output = yes - -; Clear environment in FPM workers -; Prevents arbitrary environment variables from reaching FPM worker processes -; by clearing the environment in workers before env vars specified in this -; pool configuration are added. -; Setting to "no" will make all environment variables available to PHP code -; via getenv(), $_ENV and $_SERVER. -; Default Value: yes -;clear_env = no - -; Limits the extensions of the main script FPM will allow to parse. This can -; prevent configuration mistakes on the web server side. You should only limit -; FPM to .php extensions to prevent malicious users to use other extensions to -; execute php code. -; Note: set an empty value to allow all extensions. -; Default Value: .php -;security.limit_extensions = .php .php3 .php4 .php5 .php7 - -; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from -; the current environment. -; Default Value: clean env -;env[HOSTNAME] = $HOSTNAME -;env[PATH] = /usr/local/bin:/usr/bin:/bin -;env[TMP] = /tmp -;env[TMPDIR] = /tmp -;env[TEMP] = /tmp - -; Additional php.ini defines, specific to this pool of workers. These settings -; overwrite the values previously defined in the php.ini. The directives are the -; same as the PHP SAPI: -; php_value/php_flag - you can set classic ini defines which can -; be overwritten from PHP call 'ini_set'. -; php_admin_value/php_admin_flag - these directives won't be overwritten by -; PHP call 'ini_set' -; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no. - -; Defining 'extension' will load the corresponding shared extension from -; extension_dir. Defining 'disable_functions' or 'disable_classes' will not -; overwrite previously defined php.ini values, but will append the new value -; instead. - -; Note: path INI options can be relative and will be expanded with the prefix -; (pool, global or /usr) - -; Default Value: nothing is defined by default except the values in php.ini and -; specified at startup with the -d argument -;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com -;php_flag[display_errors] = off -;php_admin_value[error_log] = /var/log/fpm-php.www.log -;php_admin_flag[log_errors] = on -;php_admin_value[memory_limit] = 32M diff --git a/provision/provision.sh b/provision/provision.sh deleted file mode 100644 index d6380645..00000000 --- a/provision/provision.sh +++ /dev/null @@ -1,119 +0,0 @@ -#!/bin/bash - -echo Provisioning... -sudo apt-get update -sudo apt-get -y autoremove - -# Make sure these tools installed -sudo DEBIAN_FRONTEND=noninteractive apt-get install -y git htop curl tshark pkgconf -# Add PPA with fresh PHP 5: -sudo add-apt-repository -u -y ppa:ondrej/php - -# Install available php from packages -sudo apt-get install -y php7.0 php7.0-cli php7.0-dev php7.0-fpm - -sudo cp ~/php-amqp/provision/php/www.conf /etc/php/7.0/fpm/pool.d/www.conf -sudo service php7.0-fpm restart - -# Install phpbrew to manage php versions - -curl -L -O -s https://github.com/phpbrew/phpbrew/raw/master/phpbrew -chmod +x phpbrew -sudo mv phpbrew /usr/bin/phpbrew -phpbrew init - -cp ~/php-amqp/provision/.bashrc ~/.bashrc - -sudo mkdir -p /var/www/html/ -sudo chown -R vagrant:vagrant /var/www - -# Requirements to build php from sources -sudo apt-get install -y \ - libxml2-dev \ - libcurl4-openssl-dev \ - libjpeg-dev \ - libpng-dev \ - libxpm-dev \ - libmcrypt-dev \ - libmysqlclient-dev \ - libpq-dev \ - libicu-dev \ - libfreetype6-dev \ - libldap2-dev \ - libxslt-dev \ - libbz2-dev \ - libreadline-dev \ - autoconf \ - libtool \ - pkg-config \ - valgrind - -# Benchmarking... -sudo apt-get install -y apache2-utils -# For Apache-based installation -sudo apt-get install -y apache2 libapache2-mod-php7.0 - -# Move Apache to port 8080 -sudo cp ~/php-amqp/provision/apache/000-default.conf /etc/apache2/sites-available/000-default.conf -sudo cp ~/php-amqp/provision/apache/ports.conf /etc/apache2/ports.conf -sudo service apache2 restart - -sudo cp -f /var/www/html/index.html /var/www/html/index-apache.html - -sudo bash -c "echo ' /var/www/html/index.php" - -# For Nginx-based installation -sudo apt-get install -y nginx -sudo cp ~/php-amqp/provision/nginx/default /etc/nginx/sites-available/default -sudo service nginx restart -sudo cp -f /usr/share/nginx/html/index.html /var/www/html/index-nginx.html - -# add hosts entry for rabbitmq.example.org -sudo bash -c 'grep -q rabbitmq.example.org /etc/hosts || echo "127.0.0.1 rabbitmq.example.org rabbitmq" >> /etc/hosts' - -# Install and configure RabbitMQ -wget -qO - https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add - -sudo add-apt-repository 'deb http://www.rabbitmq.com/debian/ testing main' -sudo apt-get update -#sudo apt-get install --only-upgrade -y rabbitmq-server -sudo apt-get install -y rabbitmq-server -sudo rabbitmq-plugins enable rabbitmq_management -sudo rabbitmq-plugins enable rabbitmq_auth_mechanism_ssl -sudo rabbitmqctl add_user "sasl-client.example.org" dummy -sudo rabbitmqctl set_permissions -p / "sasl-client.example.org" ".*" ".*" ".*" -sudo rabbitmqctl clear_password "sasl-client.example.org" - -sudo cp ~/php-amqp/provision/rabbitmq.config /etc/rabbitmq/ -sudo service rabbitmq-server restart - -# Note: it may be good idea to checkout latest stable rabbitmq-c version, but master branch for dev reasons also good -cd ~ -git clone -q git://github.com/alanxz/rabbitmq-c.git -cd rabbitmq-c -sudo apt-get install -y cmake -mkdir build && cd build -cmake .. -sudo cmake --build . --target install -# or install packaged version: -#sudo apt-get install -y librabbitmq1 librabbitmq-dev librabbitmq-dbg - -# Do it manually when you need it, -#cd ~/php-amqp -#phpize --clean && phpize && ./configure && sudo make install -#sudo cp ~/php-amqp/provision/php/amqp.ini /etc/php/7.0/mods-available/ -#sudo phpenmod amqp -#sudo service php7.0-fpm restart - -# For debugging segfault when amqp fails in php-fpm mode: -#sudo sh -c "echo '/home/vagrant/php-amqp/coredump-%e.%p' > /proc/sys/kernel/core_pattern" - -# To test with typical dev configuration - with xdebug: -#sudo apt-get install -y php5-xdebug - -# Cleanup unused stuff -sudo apt-get autoremove -y - -# At this point it is good idea to do `phpbrew install 5.6` (or other version you want to test extension with) -# and `phpbrew ext install ~/php-amqp/` - -date > /home/vagrant/vagrant_provisioned_at diff --git a/provision/rabbitmq.config b/provision/rabbitmq.config deleted file mode 100644 index a3a6ad21..00000000 --- a/provision/rabbitmq.config +++ /dev/null @@ -1,601 +0,0 @@ -%% -*- mode: erlang -*- -%% ---------------------------------------------------------------------------- -%% RabbitMQ Sample Configuration File. -%% -%% See http://www.rabbitmq.com/configure.html for details. -%% ---------------------------------------------------------------------------- -[ - {rabbit, - [%% - %% Network Connectivity - %% ==================== - %% - - %% By default, RabbitMQ will listen on all interfaces, using - %% the standard (reserved) AMQP port. - %% - %% {tcp_listeners, [5672]}, - - %% To listen on a specific interface, provide a tuple of {IpAddress, Port}. - %% For example, to listen only on localhost for both IPv4 and IPv6: - %% - %% {tcp_listeners, [{"127.0.0.1", 5672}, - %% {"::1", 5672}]}, - - %% SSL listeners are configured in the same fashion as TCP listeners, - %% including the option to control the choice of interface. - %% - %% {ssl_listeners, [5671]}, - {ssl_listeners, [5671]}, - {ssl_options, [{cacertfile,"/home/vagrant/php-amqp/provision/test_certs/testca/cacert.pem"}, - {certfile,"/home/vagrant/php-amqp/provision/test_certs/server/cert.pem"}, - {keyfile,"/home/vagrant/php-amqp/provision/test_certs/server/key.pem"}, - {verify,verify_peer}, - %% {verify,verify_none}, - {fail_if_no_peer_cert,true} - ]}, - - %% Maximum time for AMQP 0-8/0-9/0-9-1 handshake (after socket connection - %% and SSL handshake), in milliseconds. - %% - %% {handshake_timeout, 10000}, - - %% Log levels (currently just used for connection logging). - %% One of 'debug', 'info', 'warning', 'error' or 'none', in decreasing - %% order of verbosity. Defaults to 'info'. - %% - {log_levels, [{connection, debug}, {channel, debug}]}, - - %% Set to 'true' to perform reverse DNS lookups when accepting a - %% connection. Hostnames will then be shown instead of IP addresses - %% in rabbitmqctl and the management plugin. - %% - %% {reverse_dns_lookups, true}, - - %% - %% Security / AAA - %% ============== - %% - - %% The default "guest" user is only permitted to access the server - %% via a loopback interface (e.g. localhost). - %% {loopback_users, [<<"guest">>]}, - %% - %% Uncomment the following line if you want to allow access to the - %% guest user from anywhere on the network. - {loopback_users, []}, - - %% Configuring SSL. - %% See http://www.rabbitmq.com/ssl.html for full documentation. - %% - %% {ssl_options, [{cacertfile, "/path/to/testca/cacert.pem"}, - %% {certfile, "/path/to/server/cert.pem"}, - %% {keyfile, "/path/to/server/key.pem"}, - %% {verify, verify_peer}, - %% {fail_if_no_peer_cert, false}]}, - - %% Choose the available SASL mechanism(s) to expose. - %% The two default (built in) mechanisms are 'PLAIN' and - %% 'AMQPLAIN'. Additional mechanisms can be added via - %% plugins. - %% - %% See http://www.rabbitmq.com/authentication.html for more details. - %% - %% {auth_mechanisms, ['PLAIN', 'AMQPLAIN']}, - - %% Select an authentication database to use. RabbitMQ comes bundled - %% with a built-in auth-database, based on mnesia. - %% - %% {auth_backends, [rabbit_auth_backend_internal]}, - - %% Configurations supporting the rabbitmq_auth_mechanism_ssl and - %% rabbitmq_auth_backend_ldap plugins. - %% - %% NB: These options require that the relevant plugin is enabled. - %% See http://www.rabbitmq.com/plugins.html for further details. - - %% The RabbitMQ-auth-mechanism-ssl plugin makes it possible to - %% authenticate a user based on the client's SSL certificate. - %% - %% To use auth-mechanism-ssl, add to or replace the auth_mechanisms - %% list with the entry 'EXTERNAL'. - %% - {auth_mechanisms, ['PLAIN', 'EXTERNAL']}, - - %% The rabbitmq_auth_backend_ldap plugin allows the broker to - %% perform authentication and authorisation by deferring to an - %% external LDAP server. - %% - %% For more information about configuring the LDAP backend, see - %% http://www.rabbitmq.com/ldap.html. - %% - %% Enable the LDAP auth backend by adding to or replacing the - %% auth_backends entry: - %% - %% {auth_backends, [rabbit_auth_backend_ldap]}, - - %% This pertains to both the rabbitmq_auth_mechanism_ssl plugin and - %% STOMP ssl_cert_login configurations. See the rabbitmq_stomp - %% configuration section later in this file and the README in - %% https://github.com/rabbitmq/rabbitmq-auth-mechanism-ssl for further - %% details. - %% - %% To use the SSL cert's CN instead of its DN as the username - %% - {ssl_cert_login_from, common_name} - - %% SSL handshake timeout, in milliseconds. - %% - %% {ssl_handshake_timeout, 5000}, - - %% - %% Default User / VHost - %% ==================== - %% - - %% On first start RabbitMQ will create a vhost and a user. These - %% config items control what gets created. See - %% http://www.rabbitmq.com/access-control.html for further - %% information about vhosts and access control. - %% - %% {default_vhost, <<"/">>}, - %% {default_user, <<"guest">>}, - %% {default_pass, <<"guest">>}, - %% {default_permissions, [<<".*">>, <<".*">>, <<".*">>]}, - - %% Tags for default user - %% - %% For more details about tags, see the documentation for the - %% Management Plugin at http://www.rabbitmq.com/management.html. - %% - %% {default_user_tags, [administrator]}, - - %% - %% Additional network and protocol related configuration - %% ===================================================== - %% - - %% Set the default AMQP heartbeat delay (in seconds). - %% - %% {heartbeat, 600}, - - %% Set the max permissible size of an AMQP frame (in bytes). - %% - %% {frame_max, 131072}, - - %% Set the max permissible number of channels per connection. - %% 0 means "no limit". - %% - %% {channel_max, 128}, - - %% Customising Socket Options. - %% - %% See (http://www.erlang.org/doc/man/inet.html#setopts-2) for - %% further documentation. - %% - %% {tcp_listen_options, [binary, - %% {packet, raw}, - %% {reuseaddr, true}, - %% {backlog, 128}, - %% {nodelay, true}, - %% {exit_on_close, false}]}, - - %% - %% Resource Limits & Flow Control - %% ============================== - %% - %% See http://www.rabbitmq.com/memory.html for full details. - - %% Memory-based Flow Control threshold. - %% - %% {vm_memory_high_watermark, 0.4}, - - %% Fraction of the high watermark limit at which queues start to - %% page message out to disc in order to free up memory. - %% - %% Values greater than 0.9 can be dangerous and should be used carefully. - %% - %% {vm_memory_high_watermark_paging_ratio, 0.5}, - - %% Set disk free limit (in bytes). Once free disk space reaches this - %% lower bound, a disk alarm will be set - see the documentation - %% listed above for more details. - %% - %% {disk_free_limit, 50000000}, - - %% Alternatively, we can set a limit relative to total available RAM. - %% - %% Values lower than 1.0 can be dangerous and should be used carefully. - %% {disk_free_limit, {mem_relative, 2.0}}, - - %% - %% Misc/Advanced Options - %% ===================== - %% - %% NB: Change these only if you understand what you are doing! - %% - - %% To announce custom properties to clients on connection: - %% - %% {server_properties, []}, - - %% How to respond to cluster partitions. - %% See http://www.rabbitmq.com/partitions.html for further details. - %% - %% {cluster_partition_handling, ignore}, - - %% Make clustering happen *automatically* at startup - only applied - %% to nodes that have just been reset or started for the first time. - %% See http://www.rabbitmq.com/clustering.html#auto-config for - %% further details. - %% - %% {cluster_nodes, {['rabbit@my.host.com'], disc}}, - - %% Interval (in milliseconds) at which we send keepalive messages - %% to other cluster members. Note that this is not the same thing - %% as net_ticktime; missed keepalive messages will not cause nodes - %% to be considered down. - %% - %% {cluster_keepalive_interval, 10000}, - - %% Set (internal) statistics collection granularity. - %% - %% {collect_statistics, none}, - - %% Statistics collection interval (in milliseconds). - %% - %% {collect_statistics_interval, 5000}, - - %% Explicitly enable/disable hipe compilation. - %% - %% {hipe_compile, true}, - - %% Timeout used when waiting for Mnesia tables in a cluster to - %% become available. - %% - %% {mnesia_table_loading_timeout, 30000}, - - %% Size in bytes below which to embed messages in the queue index. See - %% http://www.rabbitmq.com/persistence-conf.html - %% - %% {queue_index_embed_msgs_below, 4096} - - ]}, - - %% ---------------------------------------------------------------------------- - %% Advanced Erlang Networking/Clustering Options. - %% - %% See http://www.rabbitmq.com/clustering.html for details - %% ---------------------------------------------------------------------------- - {kernel, - [%% Sets the net_kernel tick time. - %% Please see http://erlang.org/doc/man/kernel_app.html and - %% http://www.rabbitmq.com/nettick.html for further details. - %% - %% {net_ticktime, 60} - ]}, - - %% ---------------------------------------------------------------------------- - %% RabbitMQ Management Plugin - %% - %% See http://www.rabbitmq.com/management.html for details - %% ---------------------------------------------------------------------------- - - {rabbitmq_management, - [%% Pre-Load schema definitions from the following JSON file. See - %% http://www.rabbitmq.com/management.html#load-definitions - %% - %% {load_definitions, "/path/to/schema.json"}, - - %% Log all requests to the management HTTP API to a file. - %% - %% {http_log_dir, "/path/to/access.log"}, - - %% Change the port on which the HTTP listener listens, - %% specifying an interface for the web server to bind to. - %% Also set the listener to use SSL and provide SSL options. - %% - %% {listener, [{port, 12345}, - %% {ip, "127.0.0.1"}, - %% {ssl, true}, - %% {ssl_opts, [{cacertfile, "/path/to/cacert.pem"}, - %% {certfile, "/path/to/cert.pem"}, - %% {keyfile, "/path/to/key.pem"}]}]}, - - %% One of 'basic', 'detailed' or 'none'. See - %% http://www.rabbitmq.com/management.html#fine-stats for more details. - %% {rates_mode, basic}, - - %% Configure how long aggregated data (such as message rates and queue - %% lengths) is retained. Please read the plugin's documentation in - %% http://www.rabbitmq.com/management.html#configuration for more - %% details. - %% - %% {sample_retention_policies, - %% [{global, [{60, 5}, {3600, 60}, {86400, 1200}]}, - %% {basic, [{60, 5}, {3600, 60}]}, - %% {detailed, [{10, 5}]}]} - ]}, - - %% ---------------------------------------------------------------------------- - %% RabbitMQ Shovel Plugin - %% - %% See http://www.rabbitmq.com/shovel.html for details - %% ---------------------------------------------------------------------------- - - {rabbitmq_shovel, - [{shovels, - [%% A named shovel worker. - %% {my_first_shovel, - %% [ - - %% List the source broker(s) from which to consume. - %% - %% {sources, - %% [%% URI(s) and pre-declarations for all source broker(s). - %% {brokers, ["amqp://user:password@host.domain/my_vhost"]}, - %% {declarations, []} - %% ]}, - - %% List the destination broker(s) to publish to. - %% {destinations, - %% [%% A singular version of the 'brokers' element. - %% {broker, "amqp://"}, - %% {declarations, []} - %% ]}, - - %% Name of the queue to shovel messages from. - %% - %% {queue, <<"your-queue-name-goes-here">>}, - - %% Optional prefetch count. - %% - %% {prefetch_count, 10}, - - %% when to acknowledge messages: - %% - no_ack: never (auto) - %% - on_publish: after each message is republished - %% - on_confirm: when the destination broker confirms receipt - %% - %% {ack_mode, on_confirm}, - - %% Overwrite fields of the outbound basic.publish. - %% - %% {publish_fields, [{exchange, <<"my_exchange">>}, - %% {routing_key, <<"from_shovel">>}]}, - - %% Static list of basic.properties to set on re-publication. - %% - %% {publish_properties, [{delivery_mode, 2}]}, - - %% The number of seconds to wait before attempting to - %% reconnect in the event of a connection failure. - %% - %% {reconnect_delay, 2.5} - - %% ]} %% End of my_first_shovel - ]} - %% Rather than specifying some values per-shovel, you can specify - %% them for all shovels here. - %% - %% {defaults, [{prefetch_count, 0}, - %% {ack_mode, on_confirm}, - %% {publish_fields, []}, - %% {publish_properties, [{delivery_mode, 2}]}, - %% {reconnect_delay, 2.5}]} - ]}, - - %% ---------------------------------------------------------------------------- - %% RabbitMQ Stomp Adapter - %% - %% See http://www.rabbitmq.com/stomp.html for details - %% ---------------------------------------------------------------------------- - - {rabbitmq_stomp, - [%% Network Configuration - the format is generally the same as for the broker - - %% Listen only on localhost (ipv4 & ipv6) on a specific port. - %% {tcp_listeners, [{"127.0.0.1", 61613}, - %% {"::1", 61613}]}, - - %% Listen for SSL connections on a specific port. - %% {ssl_listeners, [61614]}, - - %% Additional SSL options - - %% Extract a name from the client's certificate when using SSL. - %% - %% {ssl_cert_login, true}, - - %% Set a default user name and password. This is used as the default login - %% whenever a CONNECT frame omits the login and passcode headers. - %% - %% Please note that setting this will allow clients to connect without - %% authenticating! - %% - %% {default_user, [{login, "guest"}, - %% {passcode, "guest"}]}, - - %% If a default user is configured, or you have configured use SSL client - %% certificate based authentication, you can choose to allow clients to - %% omit the CONNECT frame entirely. If set to true, the client is - %% automatically connected as the default user or user supplied in the - %% SSL certificate whenever the first frame sent on a session is not a - %% CONNECT frame. - %% - %% {implicit_connect, true} - ]}, - - %% ---------------------------------------------------------------------------- - %% RabbitMQ MQTT Adapter - %% - %% See https://github.com/rabbitmq/rabbitmq-mqtt/blob/stable/README.md - %% for details - %% ---------------------------------------------------------------------------- - - {rabbitmq_mqtt, - [%% Set the default user name and password. Will be used as the default login - %% if a connecting client provides no other login details. - %% - %% Please note that setting this will allow clients to connect without - %% authenticating! - %% - %% {default_user, <<"guest">>}, - %% {default_pass, <<"guest">>}, - - %% Enable anonymous access. If this is set to false, clients MUST provide - %% login information in order to connect. See the default_user/default_pass - %% configuration elements for managing logins without authentication. - %% - %% {allow_anonymous, true}, - - %% If you have multiple chosts, specify the one to which the - %% adapter connects. - %% - %% {vhost, <<"/">>}, - - %% Specify the exchange to which messages from MQTT clients are published. - %% - %% {exchange, <<"amq.topic">>}, - - %% Specify TTL (time to live) to control the lifetime of non-clean sessions. - %% - %% {subscription_ttl, 1800000}, - - %% Set the prefetch count (governing the maximum number of unacknowledged - %% messages that will be delivered). - %% - %% {prefetch, 10}, - - %% TCP/SSL Configuration (as per the broker configuration). - %% - %% {tcp_listeners, [1883]}, - %% {ssl_listeners, []}, - - %% TCP/Socket options (as per the broker configuration). - %% - %% {tcp_listen_options, [binary, - %% {packet, raw}, - %% {reuseaddr, true}, - %% {backlog, 128}, - %% {nodelay, true}]} - ]}, - - %% ---------------------------------------------------------------------------- - %% RabbitMQ AMQP 1.0 Support - %% - %% See https://github.com/rabbitmq/rabbitmq-amqp1.0/blob/stable/README.md - %% for details - %% ---------------------------------------------------------------------------- - - {rabbitmq_amqp1_0, - [%% Connections that are not authenticated with SASL will connect as this - %% account. See the README for more information. - %% - %% Please note that setting this will allow clients to connect without - %% authenticating! - %% - %% {default_user, "guest"}, - - %% Enable protocol strict mode. See the README for more information. - %% - %% {protocol_strict_mode, false} - ]}, - - %% ---------------------------------------------------------------------------- - %% RabbitMQ LDAP Plugin - %% - %% See http://www.rabbitmq.com/ldap.html for details. - %% - %% ---------------------------------------------------------------------------- - - {rabbitmq_auth_backend_ldap, - [%% - %% Connecting to the LDAP server(s) - %% ================================ - %% - - %% Specify servers to bind to. You *must* set this in order for the plugin - %% to work properly. - %% - %% {servers, ["your-server-name-goes-here"]}, - - %% Connect to the LDAP server using SSL - %% - %% {use_ssl, false}, - - %% Specify the LDAP port to connect to - %% - %% {port, 389}, - - %% LDAP connection timeout, in milliseconds or 'infinity' - %% - %% {timeout, infinity}, - - %% Enable logging of LDAP queries. - %% One of - %% - false (no logging is performed) - %% - true (verbose logging of the logic used by the plugin) - %% - network (as true, but additionally logs LDAP network traffic) - %% - %% Defaults to false. - %% - %% {log, false}, - - %% - %% Authentication - %% ============== - %% - - %% Pattern to convert the username given through AMQP to a DN before - %% binding - %% - %% {user_dn_pattern, "cn=${username},ou=People,dc=example,dc=com"}, - - %% Alternatively, you can convert a username to a Distinguished - %% Name via an LDAP lookup after binding. See the documentation for - %% full details. - - %% When converting a username to a dn via a lookup, set these to - %% the name of the attribute that represents the user name, and the - %% base DN for the lookup query. - %% - %% {dn_lookup_attribute, "userPrincipalName"}, - %% {dn_lookup_base, "DC=gopivotal,DC=com"}, - - %% Controls how to bind for authorisation queries and also to - %% retrieve the details of users logging in without presenting a - %% password (e.g., SASL EXTERNAL). - %% One of - %% - as_user (to bind as the authenticated user - requires a password) - %% - anon (to bind anonymously) - %% - {UserDN, Password} (to bind with a specified user name and password) - %% - %% Defaults to 'as_user'. - %% - %% {other_bind, as_user}, - - %% - %% Authorisation - %% ============= - %% - - %% The LDAP plugin can perform a variety of queries against your - %% LDAP server to determine questions of authorisation. See - %% http://www.rabbitmq.com/ldap.html#authorisation for more - %% information. - - %% Set the query to use when determining vhost access - %% - %% {vhost_access_query, {in_group, - %% "ou=${vhost}-users,ou=vhosts,dc=example,dc=com"}}, - - %% Set the query to use when determining resource (e.g., queue) access - %% - %% {resource_access_query, {constant, true}}, - - %% Set queries to determine which tags a user has - %% - %% {tag_queries, []} - ]} -]. diff --git a/provision/test_certs/certgen.sh b/provision/test_certs/certgen.sh deleted file mode 100644 index 2f03a0e7..00000000 --- a/provision/test_certs/certgen.sh +++ /dev/null @@ -1,20 +0,0 @@ -mkdir testca; cd testca; mkdir private -openssl req -new -x509 -keyout private/cakey.pem -out cacert.pem -days 365 -nodes -subj "/C=PT/ST=Lisboa/L=Lisboa/O=Example Org" - -cd .. -mkdir server;cd server -openssl genrsa -out key.pem 2048 -openssl req -new -key key.pem -out req.pem -subj "/C=PT/ST=Lisboa/L=Lisboa/O=Example Org/CN=*.example.org" -openssl x509 -req -in req.pem -CA ../testca/cacert.pem -CAkey ../testca/private/cakey.pem -CAcreateserial -out cert.pem -days 365 - -cd .. -mkdir sasl-client; cd sasl-client -openssl genrsa -out key.pem 2048 -openssl req -new -key key.pem -out req.pem -subj "/C=PT/ST=Lisboa/L=Lisboa/O=Example Org/CN=sasl-client.example.org" -openssl x509 -req -in req.pem -CA ../testca/cacert.pem -CAkey ../testca/private/cakey.pem -CAcreateserial -out cert.pem -days 365 - -cd .. -mkdir client; cd client -openssl genrsa -out key.pem 2048 -openssl req -new -key key.pem -out req.pem -subj "/C=PT/ST=Lisboa/L=Lisboa/O=Example Org/CN=client.example.org" -openssl x509 -req -in req.pem -CA ../testca/cacert.pem -CAkey ../testca/private/cakey.pem -CAcreateserial -out cert.pem -days 365 \ No newline at end of file diff --git a/provision/test_certs/client/cert.pem b/provision/test_certs/client/cert.pem deleted file mode 100644 index d81cf23e..00000000 --- a/provision/test_certs/client/cert.pem +++ /dev/null @@ -1,19 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIDIzCCAgsCCQD/3A+eiHuqpzANBgkqhkiG9w0BAQsFADBFMQswCQYDVQQGEwJQ -VDEPMA0GA1UECAwGTGlzYm9hMQ8wDQYDVQQHDAZMaXNib2ExFDASBgNVBAoMC0V4 -YW1wbGUgT3JnMB4XDTE4MDYxMDEwMzA0MFoXDTE5MDYxMDEwMzA0MFowYjELMAkG -A1UEBhMCUFQxDzANBgNVBAgMBkxpc2JvYTEPMA0GA1UEBwwGTGlzYm9hMRQwEgYD -VQQKDAtFeGFtcGxlIE9yZzEbMBkGA1UEAwwSY2xpZW50LmV4YW1wbGUub3JnMIIB -IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzmgZMCuXgmc4moKvweny7mXT -gKL8GNpB9uLwpmr0np4veWZh2b5WFFy6oma/4hS072PRXR1+miaEZHvlCgRopKp7 -Lm4CF45E8YamG0MjfTxWtTf+JAXjYibijl94GQLkXmMM9OBY080r01szP2RXxkfU -3UMf0HjiDcj5YyJn2LVwkgqRx6JYcTNm/wRhk82vw6nclB6jeZ0OcJK/4lrNCaX/ -VfPTnyZoCXRteFGBiCWmf/Y2uvtjUqpwSAIDvNQaV6WrcmdTBt8szbigc1wR2WyX -NR3WKy2aCPOPbbsCLDA/bilFnKUN0Ho53g3e8J0VUZv4G9WZKf2GrhHWax3lAQID -AQABMA0GCSqGSIb3DQEBCwUAA4IBAQBY/0zo+2kz2ws1X0nRfz1J0cPvamlQj/jI -C1G6h964nDjmcljmvybWlX/TCWDjtTS/bkEjUSZhAAqfF5Zt44g1WkwE03vzdPgF -hN06NNbc5dQMYFa5cUnHbE3gkbN31qCf8T/IjzOBaqxDspwZyzvAXQwKFPke6TuA -XjYinMlEVNL3TytEf5PhdDjvssrRRR/lKHdFF9ABTN8w/UWyMKrawuYrWynk/IdH -F0i9GAPvULeZKHpYytwtwwitnucxsVJkkz0JVJcsrGRgwiy4zmIjSjATVD4kB+Dy -MAcQTltJIAu/PSPFWvVAA73Wh87FdqGb2rWBKfer9MdzX4h7HnQO ------END CERTIFICATE----- diff --git a/provision/test_certs/client/key.pem b/provision/test_certs/client/key.pem deleted file mode 100644 index 2f52b074..00000000 --- a/provision/test_certs/client/key.pem +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEpAIBAAKCAQEAzmgZMCuXgmc4moKvweny7mXTgKL8GNpB9uLwpmr0np4veWZh -2b5WFFy6oma/4hS072PRXR1+miaEZHvlCgRopKp7Lm4CF45E8YamG0MjfTxWtTf+ -JAXjYibijl94GQLkXmMM9OBY080r01szP2RXxkfU3UMf0HjiDcj5YyJn2LVwkgqR -x6JYcTNm/wRhk82vw6nclB6jeZ0OcJK/4lrNCaX/VfPTnyZoCXRteFGBiCWmf/Y2 -uvtjUqpwSAIDvNQaV6WrcmdTBt8szbigc1wR2WyXNR3WKy2aCPOPbbsCLDA/bilF -nKUN0Ho53g3e8J0VUZv4G9WZKf2GrhHWax3lAQIDAQABAoIBAFeW/1Fcvk+9Q9z1 -pmYQxGF8XpORFo/pVuLRDTRh4OrKz/ShiNahGeBMNXsjRTxIczu/TSJJmOcLf1Uw -6lIk6s8t9VYPot2iJwmjjSu2gwHrMBR47WUWBpcpTy0BwHJEsuqG+AGWjrtarsVj -R00YZNMkumUmzgJmue8FoSb7e7wPB8IPmlxAj0DheqnOVwfBCMJTCNCbmA2fLJen -avLFzoURjlT6SlcQEv8cmz7jMskbwCTSlgCw5VtdYAQQLN4UnSfbMmInVNY2sSlM -uVlKdU8UxhA1QoW9EUju9q0zI7wD0W8k6+jaRxLe8LBkwI0jh/nAcZtaKs5cQdxp -/dDb8U0CgYEA7X8Uj2bjHaq7BNZY60BdDDMVwxxfSJhl99nhaACRNFk5JSSoZDCH -GIB+DN+SiNH/Voh65Grnotf/i+bvG0TbjAVOrK35T7F2dvHZ8OeyR1EAl9EgW3z7 -c5Wjj+XwqhJL2fW01xcxOoR/Qs6Y7WsFaWM9PI+OqV16pVyR26eZ6ScCgYEA3nzs -7eXs79oPmRd011+P9843j3hHETqHdH2GtZ1ZwycmhcJsjUo0G9tCOSFcxDjKiUpG -Hkic4yueF/p0cd6ClSW9B8Hh8NX2B/oGxtWERB3dN7mtKwxPvniJ5FZe2U9np8ib -zQynU/Z5nIRbK4Oone/bfmatQggKEmJM5iClCZcCgYEAhHSWu+/PBTG+QlFloDby -biZjocDGJ4/Pdu8OdtmyIjcM1vld7RrfjbvEEVvzttkgBlvx5kj1TW4YOSef/V5m -7+3Z1hblcBvyjR4PxfsDBCFaKlHZMQ1AlFNFuLCui7vOkA4oQLnPm+pfq5vb0LYa -e498jLUoBK99ApLhSldsUIsCgYAFcgFKgUofRLMFCDHv44LeicmKVWNH5KrUCw50 -+3jq8dZbh7qoapyD4gXo6AwhMVKjsZGtxBEy7ipcY+DduJhxlg7eVbx17IatA02P -KEKoeCKl7oFygEajXsfhMsv3fZ4H2T0W86xUvb+UORkSI5LI6snwegrbht7YPFet -ejcP2QKBgQCv+TNpIFFMlhWwCbzp/I1sKM1QrQWI+Io+djxlyzxU4lFX2VX2xM9s -k6maQT5VA7PHvQ+/aMTusVHVC6Rw2/b6rjej4zs0Z+pFXXR8Z2IJGBPMUZC9SKgi -pUZjKSy0fXI2aR4QaNuZeYOYz6IR5TAhnCku8U+BAqaQ/uTtxj3J5w== ------END RSA PRIVATE KEY----- diff --git a/provision/test_certs/client/req.pem b/provision/test_certs/client/req.pem deleted file mode 100644 index 8cbba5ed..00000000 --- a/provision/test_certs/client/req.pem +++ /dev/null @@ -1,17 +0,0 @@ ------BEGIN CERTIFICATE REQUEST----- -MIICpzCCAY8CAQAwYjELMAkGA1UEBhMCUFQxDzANBgNVBAgMBkxpc2JvYTEPMA0G -A1UEBwwGTGlzYm9hMRQwEgYDVQQKDAtFeGFtcGxlIE9yZzEbMBkGA1UEAwwSY2xp -ZW50LmV4YW1wbGUub3JnMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA -zmgZMCuXgmc4moKvweny7mXTgKL8GNpB9uLwpmr0np4veWZh2b5WFFy6oma/4hS0 -72PRXR1+miaEZHvlCgRopKp7Lm4CF45E8YamG0MjfTxWtTf+JAXjYibijl94GQLk -XmMM9OBY080r01szP2RXxkfU3UMf0HjiDcj5YyJn2LVwkgqRx6JYcTNm/wRhk82v -w6nclB6jeZ0OcJK/4lrNCaX/VfPTnyZoCXRteFGBiCWmf/Y2uvtjUqpwSAIDvNQa -V6WrcmdTBt8szbigc1wR2WyXNR3WKy2aCPOPbbsCLDA/bilFnKUN0Ho53g3e8J0V -UZv4G9WZKf2GrhHWax3lAQIDAQABoAAwDQYJKoZIhvcNAQELBQADggEBAEgsC/yd -GAoFCtNvwLsdbZBSWiFroImdD0lU01sY7UtXzEdosjYESZkXVz2b1sh2TRKleCq6 -Go99vW/AYqu2ietx6Np2bO7uNS0VwjWDaqCZbpw/fTPXPORF6sirqmoq03g15EGf -1xM90dD1/EMuAiszTnhtprmr7j3fFIqN1x/9wHYVNEgUaNxCeevbX9LzHYzajzvu -hkzT8YRxASSUex/1FfJOY+UYYwf46bKlB0tlmDuLXWKSrnBDJUTKwundLerdj/y5 -gZ6evfkxwvZOvr4JTYPcq2NwbhMzTkSnHOSK2AhzLsFVSA6CWTBTFHwQNDSblQdq -FMjb5jvuyG83DTA= ------END CERTIFICATE REQUEST----- diff --git a/provision/test_certs/sasl-client/cert.pem b/provision/test_certs/sasl-client/cert.pem deleted file mode 100644 index 7c4faa69..00000000 --- a/provision/test_certs/sasl-client/cert.pem +++ /dev/null @@ -1,19 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIDKDCCAhACCQDa/hd6atDdTzANBgkqhkiG9w0BAQsFADBFMQswCQYDVQQGEwJQ -VDEPMA0GA1UECAwGTGlzYm9hMQ8wDQYDVQQHDAZMaXNib2ExFDASBgNVBAoMC0V4 -YW1wbGUgT3JnMB4XDTE4MDYxMDEwMzAzOVoXDTE5MDYxMDEwMzAzOVowZzELMAkG -A1UEBhMCUFQxDzANBgNVBAgMBkxpc2JvYTEPMA0GA1UEBwwGTGlzYm9hMRQwEgYD -VQQKDAtFeGFtcGxlIE9yZzEgMB4GA1UEAwwXc2FzbC1jbGllbnQuZXhhbXBsZS5v -cmcwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDD+p1IkyU1/E+A2B7T -YIQV5+F/S4MTBI5VYx7WKzH6PgeUxNTBTyTPC6KzYtfTg+Yo6NRQ9QwwO1oSB+1e -2HBi1avvUGHeV+6Gbou0odoTlu/MbBFNnqfsLzvtm9vzgh3kBgdeaNuD/EDKa9yU -/MKCKoOK0fXsZzbMWxdWTHe5UYrhQFaX8QaM0+rH/payIGWEtdmA6L3oCPqRAKws -svMADZT01duuS0/igVY7ZsbqMxFWwg9fstahY00mRZgbeAtcQEdHP/NIzEMH9/U3 -RRK3g2QmQX9EWPb8YLEro/prrHukL7XjyRhMMjtJf9h7beT/u9Vik2N0/KY1m9vA -V293AgMBAAEwDQYJKoZIhvcNAQELBQADggEBAB2/5h/xW5CoE0/TU3sR64Vyp1yf -og4jSnLISX3PFZU6I5U9m4JuH79tOItWyJmwgFLtk+sBThbh6qHNO6wvFlu0BMlW -RuAAmvk2wohNNcbCQRYp4fSKYoWd/1swK72KBAXW4rqXR7mofA6uybtPMDvKH6UC -XqPV532EcovNbncWFGCl32ryIeGUvEtQh43I+ds2G2YYslSqs/0B4ZZ5YHudG6PY -075cez6N/4tTS0gi5RnbsaFvfoXuQ7nfIpXIcYPmSvKA0du1/qCMHZ4u2suHsrrl -s5PZnDqiP7+UvCPWMUh9DvA2n2sjucPWtNW73zstmIAeBbp2+HW/oHCHwfg= ------END CERTIFICATE----- diff --git a/provision/test_certs/sasl-client/key.pem b/provision/test_certs/sasl-client/key.pem deleted file mode 100644 index e01aa555..00000000 --- a/provision/test_certs/sasl-client/key.pem +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEowIBAAKCAQEAw/qdSJMlNfxPgNge02CEFefhf0uDEwSOVWMe1isx+j4HlMTU -wU8kzwuis2LX04PmKOjUUPUMMDtaEgftXthwYtWr71Bh3lfuhm6LtKHaE5bvzGwR -TZ6n7C877Zvb84Id5AYHXmjbg/xAymvclPzCgiqDitH17Gc2zFsXVkx3uVGK4UBW -l/EGjNPqx/6WsiBlhLXZgOi96Aj6kQCsLLLzAA2U9NXbrktP4oFWO2bG6jMRVsIP -X7LWoWNNJkWYG3gLXEBHRz/zSMxDB/f1N0USt4NkJkF/RFj2/GCxK6P6a6x7pC+1 -48kYTDI7SX/Ye23k/7vVYpNjdPymNZvbwFdvdwIDAQABAoIBAAZ32AcULC8685jK -CUJqthFPBOdBo8LV7Kiuy86/wDeFIpTrZiY3KXzX4nfPNFZbzRXekVtWqx9QZimg -L1ppBFSOvsz4NzKybkHrlhrRGLR6z9FMY8nPCbXG3VB7S2gfDEOBW27nQQ97HNxR -cQdNzFGle4/yXA6AXZOjEgMcJPttwb7yJ/kOGCWN/yFtmt8TORIjnY25WZWCkdIz -REVkfSBGlN5TISoX49UAnAxAxVLMlyw+6m2JHYuk7smrfhxcgrWNGm+UL5zCcK3M -ruDXDxo6JXcJ/8Tj9TnsJ0Tj5HYzZiLTbwGttsrZaTqLH8TbWre7EvJOEN4k4vgX -82I8VPECgYEA6JJvYnPvaaniT4r8gFgH746pjxndBt6t7gRMpQ8iE67+RidqAeNt -4iXAd0XlELWCFS5Mb4zzgF8W9qdnhWPhCYA12Nz0wz26ivzRv02IVoVBcMefU7ka -kuccfiDSfnJgxq1rTXnLFC4703GDwgi9MD8QhP/H2sxa3LVdCdZj1Q8CgYEA17iE -n/dCrwlGB7gCaCwpuSS3d5LZJCz2SluTbLQkCyKzF8dirfmbwD4uOWXYokE/P/6N -NyUOvjPNaT4YNgEDpeQcbDRAKHmbE4DAG+56lPy7ax9CU3E89PZzC4G+vh9sGJds -ui73c2vvDvcR8jvgsJmjEUIgunYBZ2NCE9CoTxkCgYEAnZHo6TlHMb2p2N5/qKz7 -43AyrQOG3oqsKKC9FO+l1NQw7nLxvYnK/vc46RZv1dxD3/nYS5Ohvo2uTzqoRpWe -+ALneKBrLIR8CIK10PjEsGnkJnb5GY5F1NXEVigCtSzlKHaCRqGH14pjeiRkcmfd -VfzEQnfRfgoKXZJ7EJkyVj0CgYA38Z5TbehZRGpo7guRwIJBhYge9nJhs1dcCUu+ -USlXyfPwIsEwpR8DSBzsvcDks08X5Yfx2SZtpTmMJZJZzwGHMBU+6n4JASB6elVX -6QzZPoHMUhr9UMyiKpfDUC6LV9LMvdhwoGWEBWXF18VLsMOgiPeFLkUWlivfCBrG -0MIVYQKBgEnK29Wm6ukYxLV9j1RufN4ivTSny5cViyfWPB7GN9rWAeyFn9pkL6+q -O0O08dPRJTAi9/7fQmJNi/+w0Ui3ty6dEPTVWBkxqd3LfRYRo+wOt+9tE4CI4PkC -d63+MvyalKXyUY8at2+oWJ8lOJ6QyBtHsYQoNfzHUlR0JyS0AHln ------END RSA PRIVATE KEY----- diff --git a/provision/test_certs/sasl-client/req.pem b/provision/test_certs/sasl-client/req.pem deleted file mode 100644 index ea0fcdb5..00000000 --- a/provision/test_certs/sasl-client/req.pem +++ /dev/null @@ -1,17 +0,0 @@ ------BEGIN CERTIFICATE REQUEST----- -MIICrDCCAZQCAQAwZzELMAkGA1UEBhMCUFQxDzANBgNVBAgMBkxpc2JvYTEPMA0G -A1UEBwwGTGlzYm9hMRQwEgYDVQQKDAtFeGFtcGxlIE9yZzEgMB4GA1UEAwwXc2Fz -bC1jbGllbnQuZXhhbXBsZS5vcmcwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK -AoIBAQDD+p1IkyU1/E+A2B7TYIQV5+F/S4MTBI5VYx7WKzH6PgeUxNTBTyTPC6Kz -YtfTg+Yo6NRQ9QwwO1oSB+1e2HBi1avvUGHeV+6Gbou0odoTlu/MbBFNnqfsLzvt -m9vzgh3kBgdeaNuD/EDKa9yU/MKCKoOK0fXsZzbMWxdWTHe5UYrhQFaX8QaM0+rH -/payIGWEtdmA6L3oCPqRAKwssvMADZT01duuS0/igVY7ZsbqMxFWwg9fstahY00m -RZgbeAtcQEdHP/NIzEMH9/U3RRK3g2QmQX9EWPb8YLEro/prrHukL7XjyRhMMjtJ -f9h7beT/u9Vik2N0/KY1m9vAV293AgMBAAGgADANBgkqhkiG9w0BAQsFAAOCAQEA -YToEWLnXTEHvvHFtnypKJUmKuM4iVCYZ91BnATI302PQNObg/DpNxslsaOMQ/AD8 -sHHr2DCnKZvofzCwSkSleMqsUn8Z6WGkI5jrW/umDXlfdgwWD4NqmiwYB5uebVYU -cQje2nJJX7ERxnqSVMz1JjQLIbIe/eq8PJ8tdkLy2lzc6p3HrvNphnyb/hidRt5y -ydeOjQx71/eur3EVKigXcMdoLI9P/Ilo7ju9H4FjGsW1eRDn9LY/YvaJfze/yMNz -tGgwcZZHKdjTyg/WZeVgdYQJInR81FLD82AgNr3fsKB2QMNtT7mwB5bAx6zKCBhP -VVXvUmqBv2i5lEVOn1l1gA== ------END CERTIFICATE REQUEST----- diff --git a/provision/test_certs/server/cert.pem b/provision/test_certs/server/cert.pem deleted file mode 100644 index 7831b2b7..00000000 --- a/provision/test_certs/server/cert.pem +++ /dev/null @@ -1,19 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIDHjCCAgYCCQCvidFhSQh+AzANBgkqhkiG9w0BAQsFADBFMQswCQYDVQQGEwJQ -VDEPMA0GA1UECAwGTGlzYm9hMQ8wDQYDVQQHDAZMaXNib2ExFDASBgNVBAoMC0V4 -YW1wbGUgT3JnMB4XDTE4MDYxMDEwMzAzOVoXDTE5MDYxMDEwMzAzOVowXTELMAkG -A1UEBhMCUFQxDzANBgNVBAgMBkxpc2JvYTEPMA0GA1UEBwwGTGlzYm9hMRQwEgYD -VQQKDAtFeGFtcGxlIE9yZzEWMBQGA1UEAwwNKi5leGFtcGxlLm9yZzCCASIwDQYJ -KoZIhvcNAQEBBQADggEPADCCAQoCggEBALYkPyHJFpch8hZ8H3qlKjay737i4ic+ -g6V9urG1p+jmo1QnKzVV++4Pl26owPoe+T50SKLhhTFHJMEWeFB56Z9i58bhTalF -vv6XF6W0rx62Dqd9joBn5ij/90EjCOKXhDV/ec9s4l3mjXV9EHa8H89q5lxW5RcZ -KIcXJQgvWVkPAOCvGg9DnYnQLZhvKSwU3rfrdvkTVyoGiNjemQh42ca5JSF0Oi8B -4siqdAgsa7uYsS2DzBTsHCDucDkSYSrWe+oS/vDRC86A2eZk4abVIcBlHOlxcwMT -OKQ3oH3czOr3Ly8a8tTien3+5AfwZPjHxRDHeEU2Edyx9TnhO9wrdq8CAwEAATAN -BgkqhkiG9w0BAQsFAAOCAQEAI1cqejtWM50BEUAzRXKPhrQFYqbStoOPMIFOQe41 -ytb7dSSh0qNhESoUSsCqNEGknMWdj8G7H0CxM+ti5TRVoKXjzrV+Ga6kyH6Mn9wL -hrf84jl6EJFIlJkyz6/khLDH5HsCk0AAkxb9pr7HEjqWO3MrE9cdoHxOunb/qqme -KIKtNNEE9HPuzfQHTQBKTi2QmcUj2AZn9kW1BbR3dye9mkGv19L3E3eWmzcYedN4 -OCxmAj01j8WN2cQ/fD3mNJUtr7eoN6hx51Z9s5+LQtULpKRDwbygxNXwEeVsqy17 -e6BUVOoUk+b1tTbUqtL/jM3XerGaHNdJzVZKO/K0Ywapzw== ------END CERTIFICATE----- diff --git a/provision/test_certs/server/key.pem b/provision/test_certs/server/key.pem deleted file mode 100644 index a5e9815a..00000000 --- a/provision/test_certs/server/key.pem +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEpQIBAAKCAQEAtiQ/IckWlyHyFnwfeqUqNrLvfuLiJz6DpX26sbWn6OajVCcr -NVX77g+XbqjA+h75PnRIouGFMUckwRZ4UHnpn2LnxuFNqUW+/pcXpbSvHrYOp32O -gGfmKP/3QSMI4peENX95z2ziXeaNdX0Qdrwfz2rmXFblFxkohxclCC9ZWQ8A4K8a -D0OdidAtmG8pLBTet+t2+RNXKgaI2N6ZCHjZxrklIXQ6LwHiyKp0CCxru5ixLYPM -FOwcIO5wORJhKtZ76hL+8NELzoDZ5mThptUhwGUc6XFzAxM4pDegfdzM6vcvLxry -1OJ6ff7kB/Bk+MfFEMd4RTYR3LH1OeE73Ct2rwIDAQABAoIBAQCYs4q6KHxn+G2d -rDI4AICDm0BugIhZnm+ALwh2NHWxLKuBwdTXwl6UFz495/zhtVYApjy/UZL43UxT -FSOJVKwolCL8+abCY1bc2o9YvUKT3M4sXXc67+BmPzJryZOJZL3SnCzjWcXuM3wl -I9TJtq50lorKn48w7kar+xtw4UFnB2KXRnM7TZiS7kGmRNKZx+VvH3praiBLcwke -ZgBmfdZUIHDbvRHahqQ9TeXp02J83zY32yBlTnOlV6jkfpSh41fYCvOihKzkwv2v -78FBI+y6f9Sn2sXC5bqyV1W1t9Y6eDFIUNn+Cg36yl2gNH6u5eG4Rw7zDJj0PIOj -3n+hktoBAoGBAOKUEsorPvzzbdzHfh05oXOWxPqehJY5sjm9Td2Yx0nyQjkf33PT -bXX+3MzJ1LaLER0EnBmJ7VPyjaguMf1NxaWrfykzRILtVbynn5Plk8IfDcvl+jFW -oJdcg19L7Ey53VVdeCtTCqBmYrsUZF+s4/C6CpFZpj5F96KCOFVhYnWZAoGBAM3L -AMEySk/sYZ+XzqNvt9uXNmULN3oqiUqz30/hBAcGKCzhnARr3clb+7WYbbd/12fr -ZWwqwiHYcgKn11PCRAGnOxFRCr+N5ev0dSiNDBTKbvPKvKwj0jZqD8NL0bsmJlH9 -KY1wYUN7Ph1r7uCaSzm7yPH7FrQgGHD7fTLRLOuHAoGBAMAN4Utqks6YjJQqqPSe -yAKRVtBUk3A+4ZpdouXlvW8poQaIxMCKA2uUJ5aSsfI1OMFPCf3/0qJoo7hdx9O9 -G36NOpEyuqz7/cOWlgYoADH4XpppisRNeHw0V8rsMRTsKvdT7itTDVvezWtkIpyS -kPeYyqJfyjFY30npdVSx4mJpAoGASO3NCapBzYsOmZkZwK+hr28p9qr/8QpL9y5B -UDSE0dxrtmQJf0OeqHIxhIxNLX9fndM88RVCEO58kNZcJ7Grmg5ij2Nx9Kpbtb+/ -GSzLAD8xDLJnJHXZVDFH/sTKwZDmeZ3G8PnHbjupqpGKaQwk5oPW1XJO/Gx3XOqy -1qRsT9cCgYEAilHVQmFJWhWzFqvFV2wmt8KtxvyfDGU7HAP3417AQhQUv0ZvSZ1U -snH5kFc+OlZs1+86QyvIgiRl2nInVyEzGHZqE0/pp77nsZQcNX0xQGBa9x+3bM1f -6DB4+W9pC3oiU16mXytqDdmAQ93Vkb+WCxqDk/JgTl24ByxVsOgllY0= ------END RSA PRIVATE KEY----- diff --git a/provision/test_certs/server/req.pem b/provision/test_certs/server/req.pem deleted file mode 100644 index 911fe6a3..00000000 --- a/provision/test_certs/server/req.pem +++ /dev/null @@ -1,17 +0,0 @@ ------BEGIN CERTIFICATE REQUEST----- -MIICojCCAYoCAQAwXTELMAkGA1UEBhMCUFQxDzANBgNVBAgMBkxpc2JvYTEPMA0G -A1UEBwwGTGlzYm9hMRQwEgYDVQQKDAtFeGFtcGxlIE9yZzEWMBQGA1UEAwwNKi5l -eGFtcGxlLm9yZzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALYkPyHJ -Fpch8hZ8H3qlKjay737i4ic+g6V9urG1p+jmo1QnKzVV++4Pl26owPoe+T50SKLh -hTFHJMEWeFB56Z9i58bhTalFvv6XF6W0rx62Dqd9joBn5ij/90EjCOKXhDV/ec9s -4l3mjXV9EHa8H89q5lxW5RcZKIcXJQgvWVkPAOCvGg9DnYnQLZhvKSwU3rfrdvkT -VyoGiNjemQh42ca5JSF0Oi8B4siqdAgsa7uYsS2DzBTsHCDucDkSYSrWe+oS/vDR -C86A2eZk4abVIcBlHOlxcwMTOKQ3oH3czOr3Ly8a8tTien3+5AfwZPjHxRDHeEU2 -Edyx9TnhO9wrdq8CAwEAAaAAMA0GCSqGSIb3DQEBCwUAA4IBAQCwq50gKVOAiT9U -QFHC6pC8l4fexD7/pATf28XNa8ILwsETmNNAIbU+ESulWm921Nrxv1TjK+6qdvs6 -gZrnt6fyJ8mHt5fHqQoLUyLjWnlSoAAF5EFdCNtASlhOXVlhy5N2h+D5wsKMV6a6 -jNGQzAgyQNf6AAEEM2J47JfrYOgiEY/WBYK6O39VNhxyPIFbnkJIZIEI4lbHZCub -xRWMNyDV4ngZGZmu9r6SzVjG1XDPc65Z3qg2LvzDZad7/fEpkLbxfZI9JcCXvMm4 -u6f6LUYgXDe2BXuXeF1Mo4Y8x7A6Wt5RuZibNq+Ls00D7P+ilvQjBy2F9laI2Sqw -wHp0RISb ------END CERTIFICATE REQUEST----- diff --git a/provision/test_certs/testca/cacert.pem b/provision/test_certs/testca/cacert.pem deleted file mode 100644 index 49deb2ca..00000000 --- a/provision/test_certs/testca/cacert.pem +++ /dev/null @@ -1,21 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIDXTCCAkWgAwIBAgIJALr5iv/qdSQuMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV -BAYTAlBUMQ8wDQYDVQQIDAZMaXNib2ExDzANBgNVBAcMBkxpc2JvYTEUMBIGA1UE -CgwLRXhhbXBsZSBPcmcwHhcNMTgwNjEwMTAzMDM5WhcNMTkwNjEwMTAzMDM5WjBF -MQswCQYDVQQGEwJQVDEPMA0GA1UECAwGTGlzYm9hMQ8wDQYDVQQHDAZMaXNib2Ex -FDASBgNVBAoMC0V4YW1wbGUgT3JnMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB -CgKCAQEAsSAEBvCMGgZUqA+gIpviF3TigeVdMi3wu+9QmIviUcoIAXHr9zMxUyAP -dxzEzJwhKkLXpLSt5uSUb07UUg32cLQdMmPbecuug41vdCsTz/6RaZlB9UKddYIO -M4FQ31GElOfM3PsDIHjENQsarVTyt+lhIOXQdVCCkP0ebBa53pJwp0NOSl+ay+eq -W7MQn56pFaD+AWd7SEAd2c/YV/aWU/sKHDIz/Ud/5ayFS4hZ6HU8lTqyeROzXYBL -z85wcp+xTwUbvCJXTVZ3C6N+88bpi+9/1ORtSSOj7chIQ8ZdX+c58dCo1nJxw6fY -HAwYSRsllSOIVVmtlL/oBLrYCM3+wwIDAQABo1AwTjAdBgNVHQ4EFgQUxBYlRH1g -hokMTkwNbZaB4PRG7+swHwYDVR0jBBgwFoAUxBYlRH1ghokMTkwNbZaB4PRG7+sw -DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAEn3kN7VPWnFu1sIveQII -Sh2zQQYdgMS1zCnTVsZykhCliNBKwlUm6k/GEucibiggL56PESH1sUNwDK7bCR9k -ngLAeA5YcNPyGLw0x0wcz0JH9rPqF+z5tHI1IeIEzilkWUim0MGf30B/jfn6+d3v -gCk9OM7+bbTvZAvLhslHGKpgNwMEEAWzj3O4rvxp7M50VQ5XT3lvRXgeSUTeoepT -Jq7WQOKVNPrWxGOHDqhnQz33yd7m1M0hge/W0IrlkwXY0/SDtuETv+xqAiUHYlNl -s3INAWNFIMX/d7vBA4hsTujJMA9VzE+5jYQC+juXWsse61jW1eA+Fiu6m6lkXQE3 -Aw== ------END CERTIFICATE----- diff --git a/provision/test_certs/testca/private/cakey.pem b/provision/test_certs/testca/private/cakey.pem deleted file mode 100644 index 22214fb4..00000000 --- a/provision/test_certs/testca/private/cakey.pem +++ /dev/null @@ -1,28 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCxIAQG8IwaBlSo -D6Aim+IXdOKB5V0yLfC771CYi+JRyggBcev3MzFTIA93HMTMnCEqQtektK3m5JRv -TtRSDfZwtB0yY9t5y66DjW90KxPP/pFpmUH1Qp11gg4zgVDfUYSU58zc+wMgeMQ1 -CxqtVPK36WEg5dB1UIKQ/R5sFrneknCnQ05KX5rL56pbsxCfnqkVoP4BZ3tIQB3Z -z9hX9pZT+wocMjP9R3/lrIVLiFnodTyVOrJ5E7NdgEvPznByn7FPBRu8IldNVncL -o37zxumL73/U5G1JI6PtyEhDxl1f5znx0KjWcnHDp9gcDBhJGyWVI4hVWa2Uv+gE -utgIzf7DAgMBAAECggEAFdOoK2LBIQPesscaKKmk9tcEgpVNIr3eiIo5GFNElGed -DPCI73FzhpbQ0RDOf5hNzfNmt3k8ZNOOJxlDuMjXsZPAdVEw3pVm7/ch4OLeEieA -q86i/iIzXSOltFsfKCXXfLID4Mdd30aChzbTFsD9GAS+X1tykMJXFJ7cfN1gEjks -+6puuQ3PNpn3A8/jzcJn1b8eGfuxpJLclWbi2Fs2mLA4ZNnLXt+/IaTfJpSTteRD -cPvfIVekIageihx+2BFfZGaM+BTAwTRb/TnWS+I7eRPnPLu4CL9/auxOoZPE8SRE -lSczfo3QPpXNpgQw/VKnFP5BsRwKsPArUWX99kP3AQKBgQDdNf1JNBmCXSmfJeEp -NIlv6oHDCcx65KoZRujQA4p5Z4fOJ8VZo8GAfiT6Au6xJKZxK8i34xgrbhcSsXIL -ztL94gd/p90BJy+qyBOvNSb2ZjHv3WA1Au0lBGIAKt+xsLTZIpf5DavnnWTbOq74 -vxpcQnGp9ZR2oPpGINKz+AIx4wKBgQDM+x5iTEWUbO4MS4ljoCPhjEfPSHGtlUYZ -nRAbPw4w1Wku3GQ5TF1cDDyVMOXq37QgElvJOVWCUKe6ICqotg0hTRp5wtBHIAex -942rzpWSrY7kRAHZixPgFks5lTYXbn4lrYAtw2ifT8khRr3mTmupgjNeVK8ol+Gl -ZA4zJWcVoQKBgQCYpNO1utzLZ0v8ROA9VcJs1s5Z7p4KQ1XZAWRPfdIE+lrs9+an -d2dkKieL2ZAp7pdnyoXD1lHsThhfztBas4pGpLz16riHPioXV961bSEIr/ZPhVwI -2I8Zlw+k+/DGJaB1oPhrZHK17ZcV7EWm4f/nn/XdCNg8j9KDp8ydYUrqbwKBgAjc -Xh7fry5QWyX66fB9jq+EUeJa/lcDmeknifezjRh9UTOuYUK801hUSxYj6/xwOSgd -wwv6x4B/nhCErXNnkz+6Roe27Sv17X869UvU/VA+4mtpqS7PPUe1jwDpO1Jd+2QD -kQPpa49fcpFWroTTJQJJ15CfVocJsb5liduaJU+hAoGBANhM7PdXv0kfeVlEAqGW -lXU6UXNYmEU0jmTcG+qr8lirr4xT8q8J1dPf3Eieu8q+9LdTI1wcKL3O9dtmZudR -fdMPBpVCfmI6e9APwnDN/vMoYlfAUptkgfrBmBzZt0jP79p5v5of4ObG7QfqYPgr -BWup9HG/UkSnk46Tc9z2V+6S ------END PRIVATE KEY----- diff --git a/tests/amqpconnection_construct_with_connect_timeout.phpt b/tests/amqpconnection_construct_with_connect_timeout.phpt index b89339d1..cf58d586 100644 --- a/tests/amqpconnection_construct_with_connect_timeout.phpt +++ b/tests/amqpconnection_construct_with_connect_timeout.phpt @@ -37,7 +37,7 @@ try { ?> --EXPECTF-- Parameter 'connect_timeout' must be greater than or equal to zero. -Socket error: could not connect to host. +Socket error: could not connect to host, request timed out error: %f limit: %f timings OK diff --git a/tests/amqpconnection_ssl.phpt b/tests/amqpconnection_ssl.phpt deleted file mode 100644 index c4d88e0f..00000000 --- a/tests/amqpconnection_ssl.phpt +++ /dev/null @@ -1,141 +0,0 @@ ---TEST-- -AMQPConnection - ssl support ---SKIPIF-- - - ---FILE-- - gethostname(), //'vagrant-ubuntu-wily-64', - 'port' => 5671, - - 'verify' => false, - - 'cacert' => __DIR__ . "/../provision/test_certs/testca/cacert.pem", - 'cert' => __DIR__ . "/../provision/test_certs/client/cert.pem", - 'key' => __DIR__ . "/../provision/test_certs/client/key.pem", -); - -$cnn = new AMQPConnection($credentials); - -var_dump($cnn); - -$cnn->connect(); - -echo ($cnn->isConnected() ? 'connected' : 'disconnected'), PHP_EOL; - -echo PHP_EOL; - -$cnn = new AMQPConnection(); -$cnn->setPort(5671); -$cnn->setCACert(__DIR__ . "/../provision/test_certs/testca/cacert.pem"); -$cnn->setCert(__DIR__ . "/../provision/test_certs/client/cert.pem"); -$cnn->setKey(__DIR__ . "/../provision/test_certs/client/key.pem"); -$cnn->setVerify(false); -var_dump($cnn); - -$cnn->connect(); - -echo ($cnn->isConnected() ? 'connected' : 'disconnected'), PHP_EOL; - -//sleep(100); - -?> ---EXPECTF-- -object(AMQPConnection)#1 (18) { - ["login":"AMQPConnection":private]=> - string(5) "guest" - ["password":"AMQPConnection":private]=> - string(5) "guest" - ["host":"AMQPConnection":private]=> - string(9) "localhost" - ["vhost":"AMQPConnection":private]=> - string(1) "/" - ["port":"AMQPConnection":private]=> - int(5671) - ["read_timeout":"AMQPConnection":private]=> - float(0) - ["write_timeout":"AMQPConnection":private]=> - float(0) - ["connect_timeout":"AMQPConnection":private]=> - float(0) - ["rpc_timeout":"AMQPConnection":private]=> - float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> - int(131072) - ["heartbeat":"AMQPConnection":private]=> - int(0) - ["cacert":"AMQPConnection":private]=> - string(%d) "%s/provision/test_certs/testca/cacert.pem" - ["key":"AMQPConnection":private]=> - string(%d) "%s/provision/test_certs/client/key.pem" - ["cert":"AMQPConnection":private]=> - string(%d) "%s/provision/test_certs/client/cert.pem" - ["verify":"AMQPConnection":private]=> - bool(false) - ["sasl_method":"AMQPConnection":private]=> - int(0) - ["connection_name":"AMQPConnection":private]=> - NULL -} -connected - -object(AMQPConnection)#2 (18) { - ["login":"AMQPConnection":private]=> - string(5) "guest" - ["password":"AMQPConnection":private]=> - string(5) "guest" - ["host":"AMQPConnection":private]=> - string(9) "localhost" - ["vhost":"AMQPConnection":private]=> - string(1) "/" - ["port":"AMQPConnection":private]=> - int(5671) - ["read_timeout":"AMQPConnection":private]=> - float(0) - ["write_timeout":"AMQPConnection":private]=> - float(0) - ["connect_timeout":"AMQPConnection":private]=> - float(0) - ["rpc_timeout":"AMQPConnection":private]=> - float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> - int(131072) - ["heartbeat":"AMQPConnection":private]=> - int(0) - ["cacert":"AMQPConnection":private]=> - string(%d) "%s/provision/test_certs/testca/cacert.pem" - ["key":"AMQPConnection":private]=> - string(%d) "%s/provision/test_certs/client/key.pem" - ["cert":"AMQPConnection":private]=> - string(%d) "%s/provision/test_certs/client/cert.pem" - ["verify":"AMQPConnection":private]=> - bool(false) - ["sasl_method":"AMQPConnection":private]=> - int(0) - ["connection_name":"AMQPConnection":private]=> - NULL -} -connected diff --git a/tests/amqpconnection_ssl_by_cert.phpt b/tests/amqpconnection_ssl_by_cert.phpt deleted file mode 100644 index 0a5c39e3..00000000 --- a/tests/amqpconnection_ssl_by_cert.phpt +++ /dev/null @@ -1,164 +0,0 @@ ---TEST-- -AMQPConnection - ssl support / authentication using certificates ---SKIPIF-- - - ---FILE-- - hostname must be in same domain -e.g. rabbitmq.example.org -if verify = true -=> you need a /etc/hosts entry, so that the server can resolve the name supplied by the client -127.0.0.1 rabbitmq.example.org rabbitmq -CN in client certificate must also match CN scheme -CN in server is *.example.org -CN in clients used are e.g.: - client.example.org - sasl-client.example.org -users have to exist with appropriate rights in rabbitmq -you can validate authentication by looking at /var/log/rabbitmq/rabbit@vagrant-sasl.log -connection <0.1104.0> (127.0.0.1:48898 -> 127.0.0.1:5671): user 'sasl-client.example.org' authenticated and granted access to vhost '/' -*/ -$credentials = array( - 'host' => 'rabbitmq.example.org', - 'port' => 5671, - - 'verify' => true, - - 'cacert' => __DIR__ . "/../provision/test_certs/testca/cacert.pem", - 'cert' => __DIR__ . "/../provision/test_certs/sasl-client/cert.pem", - 'key' => __DIR__ . "/../provision/test_certs/sasl-client/key.pem", - 'sasl_method' => 1 -); - -$cnn = new AMQPConnection($credentials); -$cnn->setSaslMethod(1); - -var_dump($cnn); - -$cnn->connect(); - -echo ($cnn->isConnected() ? 'connected' : 'disconnected'), PHP_EOL; - -echo PHP_EOL; - -$cnn = new AMQPConnection(); -$cnn->setHost('localhost'); -$cnn->setPort(5671); -$cnn->setCACert(__DIR__ . "/../provision/test_certs/testca/cacert.pem"); -$cnn->setCert(__DIR__ . "/../provision/test_certs/sasl-client/cert.pem"); -$cnn->setKey(__DIR__ . "/../provision/test_certs/sasl-client/key.pem"); -$cnn->setSaslMethod(1); -$cnn->setVerify(true); -var_dump($cnn); -try { - $cnn->connect(); -} catch(Exception $e) { - echo get_class($e), "({$e->getCode()}): ", $e->getMessage(), PHP_EOL; -} - -echo ($cnn->isConnected() ? 'connected' : 'disconnected'), PHP_EOL; - -//sleep(100); - -?> ---EXPECTF-- -object(AMQPConnection)#1 (18) { - ["login":"AMQPConnection":private]=> - string(5) "guest" - ["password":"AMQPConnection":private]=> - string(5) "guest" - ["host":"AMQPConnection":private]=> - string(20) "rabbitmq.example.org" - ["vhost":"AMQPConnection":private]=> - string(1) "/" - ["port":"AMQPConnection":private]=> - int(5671) - ["read_timeout":"AMQPConnection":private]=> - float(0) - ["write_timeout":"AMQPConnection":private]=> - float(0) - ["connect_timeout":"AMQPConnection":private]=> - float(0) - ["rpc_timeout":"AMQPConnection":private]=> - float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> - int(131072) - ["heartbeat":"AMQPConnection":private]=> - int(0) - ["cacert":"AMQPConnection":private]=> - string(%d) "%s/provision/test_certs/testca/cacert.pem" - ["key":"AMQPConnection":private]=> - string(%d) "%s/provision/test_certs/sasl-client/key.pem" - ["cert":"AMQPConnection":private]=> - string(%d) "%s/provision/test_certs/sasl-client/cert.pem" - ["verify":"AMQPConnection":private]=> - bool(true) - ["sasl_method":"AMQPConnection":private]=> - int(1) - ["connection_name":"AMQPConnection":private]=> - NULL -} -connected - -object(AMQPConnection)#2 (18) { - ["login":"AMQPConnection":private]=> - string(5) "guest" - ["password":"AMQPConnection":private]=> - string(5) "guest" - ["host":"AMQPConnection":private]=> - string(9) "localhost" - ["vhost":"AMQPConnection":private]=> - string(1) "/" - ["port":"AMQPConnection":private]=> - int(5671) - ["read_timeout":"AMQPConnection":private]=> - float(0) - ["write_timeout":"AMQPConnection":private]=> - float(0) - ["connect_timeout":"AMQPConnection":private]=> - float(0) - ["rpc_timeout":"AMQPConnection":private]=> - float(0) - ["channel_max":"AMQPConnection":private]=> - int(256) - ["frame_max":"AMQPConnection":private]=> - int(131072) - ["heartbeat":"AMQPConnection":private]=> - int(0) - ["cacert":"AMQPConnection":private]=> - string(%d) "%s/provision/test_certs/testca/cacert.pem" - ["key":"AMQPConnection":private]=> - string(%d) "%s/provision/test_certs/sasl-client/key.pem" - ["cert":"AMQPConnection":private]=> - string(%d) "%s/provision/test_certs/sasl-client/cert.pem" - ["verify":"AMQPConnection":private]=> - bool(true) - ["sasl_method":"AMQPConnection":private]=> - int(1) - ["connection_name":"AMQPConnection":private]=> - NULL -} -AMQPConnectionException(0): Socket error: could not connect to host. -disconnected diff --git a/tests/amqpconnection_tls_basic.phpt b/tests/amqpconnection_tls_basic.phpt new file mode 100644 index 00000000..8676f4ca --- /dev/null +++ b/tests/amqpconnection_tls_basic.phpt @@ -0,0 +1,112 @@ +--TEST-- +AMQPConnection - TLS - CA validation only +--SKIPIF-- + +--FILE-- + 5671, + 'host' => getenv('PHP_AMQP_SSL_HOST'), + 'cacert' => __DIR__ . "/../infra/tls/certificates/testca/cacert.pem", +); + +$cnn = new AMQPConnection($credentials); + +var_dump($cnn); + +$cnn->connect(); + +echo ($cnn->isConnected() ? 'connected' : 'disconnected'), PHP_EOL; + +echo PHP_EOL; + +$cnn = new AMQPConnection(); +$cnn->setPort(5671); +$cnn->setHost(getenv('PHP_AMQP_SSL_HOST')); +$cnn->setCACert(__DIR__ . "/../infra/tls/certificates/testca/cacert.pem"); +var_dump($cnn); + +$cnn->connect(); + +echo ($cnn->isConnected() ? 'connected' : 'disconnected'), PHP_EOL; +?> +--EXPECTF-- +object(AMQPConnection)#1 (18) { + ["login":"AMQPConnection":private]=> + string(5) "guest" + ["password":"AMQPConnection":private]=> + string(5) "guest" + ["host":"AMQPConnection":private]=> + string(%d) "%s" + ["vhost":"AMQPConnection":private]=> + string(1) "/" + ["port":"AMQPConnection":private]=> + int(5671) + ["readTimeout":"AMQPConnection":private]=> + float(0) + ["writeTimeout":"AMQPConnection":private]=> + float(0) + ["connectTimeout":"AMQPConnection":private]=> + float(0) + ["rpcTimeout":"AMQPConnection":private]=> + float(0) + ["frameMax":"AMQPConnection":private]=> + int(131072) + ["channelMax":"AMQPConnection":private]=> + int(256) + ["heartbeat":"AMQPConnection":private]=> + int(0) + ["cacert":"AMQPConnection":private]=> + string(%d) "%s/testca/cacert.pem" + ["key":"AMQPConnection":private]=> + NULL + ["cert":"AMQPConnection":private]=> + NULL + ["verify":"AMQPConnection":private]=> + bool(true) + ["saslMethod":"AMQPConnection":private]=> + int(0) + ["connectionName":"AMQPConnection":private]=> + NULL +} +connected + +object(AMQPConnection)#2 (18) { + ["login":"AMQPConnection":private]=> + string(5) "guest" + ["password":"AMQPConnection":private]=> + string(5) "guest" + ["host":"AMQPConnection":private]=> + string(%d) "%s" + ["vhost":"AMQPConnection":private]=> + string(1) "/" + ["port":"AMQPConnection":private]=> + int(5671) + ["readTimeout":"AMQPConnection":private]=> + float(0) + ["writeTimeout":"AMQPConnection":private]=> + float(0) + ["connectTimeout":"AMQPConnection":private]=> + float(0) + ["rpcTimeout":"AMQPConnection":private]=> + float(0) + ["frameMax":"AMQPConnection":private]=> + int(131072) + ["channelMax":"AMQPConnection":private]=> + int(256) + ["heartbeat":"AMQPConnection":private]=> + int(0) + ["cacert":"AMQPConnection":private]=> + string(%d) "%s/testca/cacert.pem" + ["key":"AMQPConnection":private]=> + NULL + ["cert":"AMQPConnection":private]=> + NULL + ["verify":"AMQPConnection":private]=> + bool(true) + ["saslMethod":"AMQPConnection":private]=> + int(0) + ["connectionName":"AMQPConnection":private]=> + NULL +} +connected diff --git a/tests/amqpconnection_tls_mtls.phpt b/tests/amqpconnection_tls_mtls.phpt new file mode 100644 index 00000000..035903f8 --- /dev/null +++ b/tests/amqpconnection_tls_mtls.phpt @@ -0,0 +1,116 @@ +--TEST-- +AMQPConnection - TLS - mTLS support +--SKIPIF-- + +--FILE-- + 5671, + 'host' => getenv('PHP_AMQP_SSL_HOST'), + 'cacert' => __DIR__ . "/../infra/tls/certificates/testca/cacert.pem", + 'cert' => __DIR__ . "/../infra/tls/certificates/client/cert.pem", + 'key' => __DIR__ . "/../infra/tls/certificates/client/key.pem", +); + +$cnn = new AMQPConnection($credentials); + +var_dump($cnn); + +$cnn->connect(); + +echo ($cnn->isConnected() ? 'connected' : 'disconnected'), PHP_EOL; + +echo PHP_EOL; + +$cnn = new AMQPConnection(); +$cnn->setPort(5671); +$cnn->setHost(getenv('PHP_AMQP_SSL_HOST')); +$cnn->setCACert(__DIR__ . "/../infra/tls/certificates/testca/cacert.pem"); +$cnn->setCert(__DIR__ . "/../infra/tls/certificates/client/cert.pem"); +$cnn->setKey(__DIR__ . "/../infra/tls/certificates/client/key.pem"); +var_dump($cnn); + +$cnn->connect(); + +echo ($cnn->isConnected() ? 'connected' : 'disconnected'), PHP_EOL; +?> +--EXPECTF-- +object(AMQPConnection)#1 (18) { + ["login":"AMQPConnection":private]=> + string(5) "guest" + ["password":"AMQPConnection":private]=> + string(5) "guest" + ["host":"AMQPConnection":private]=> + string(%d) "%s" + ["vhost":"AMQPConnection":private]=> + string(1) "/" + ["port":"AMQPConnection":private]=> + int(5671) + ["readTimeout":"AMQPConnection":private]=> + float(0) + ["writeTimeout":"AMQPConnection":private]=> + float(0) + ["connectTimeout":"AMQPConnection":private]=> + float(0) + ["rpcTimeout":"AMQPConnection":private]=> + float(0) + ["frameMax":"AMQPConnection":private]=> + int(131072) + ["channelMax":"AMQPConnection":private]=> + int(256) + ["heartbeat":"AMQPConnection":private]=> + int(0) + ["cacert":"AMQPConnection":private]=> + string(%d) "%s/testca/cacert.pem" + ["key":"AMQPConnection":private]=> + string(%d) "%s/client/key.pem" + ["cert":"AMQPConnection":private]=> + string(%d) "%s/client/cert.pem" + ["verify":"AMQPConnection":private]=> + bool(true) + ["saslMethod":"AMQPConnection":private]=> + int(0) + ["connectionName":"AMQPConnection":private]=> + NULL +} +connected + +object(AMQPConnection)#2 (18) { + ["login":"AMQPConnection":private]=> + string(5) "guest" + ["password":"AMQPConnection":private]=> + string(5) "guest" + ["host":"AMQPConnection":private]=> + string(%d) "%s" + ["vhost":"AMQPConnection":private]=> + string(1) "/" + ["port":"AMQPConnection":private]=> + int(5671) + ["readTimeout":"AMQPConnection":private]=> + float(0) + ["writeTimeout":"AMQPConnection":private]=> + float(0) + ["connectTimeout":"AMQPConnection":private]=> + float(0) + ["rpcTimeout":"AMQPConnection":private]=> + float(0) + ["frameMax":"AMQPConnection":private]=> + int(131072) + ["channelMax":"AMQPConnection":private]=> + int(256) + ["heartbeat":"AMQPConnection":private]=> + int(0) + ["cacert":"AMQPConnection":private]=> + string(%d) "%s/testca/cacert.pem" + ["key":"AMQPConnection":private]=> + string(%d) "%s/client/key.pem" + ["cert":"AMQPConnection":private]=> + string(%d) "%s/client/cert.pem" + ["verify":"AMQPConnection":private]=> + bool(true) + ["saslMethod":"AMQPConnection":private]=> + int(0) + ["connectionName":"AMQPConnection":private]=> + NULL +} +connected diff --git a/tests/amqpconnection_tls_sasl.phpt b/tests/amqpconnection_tls_sasl.phpt new file mode 100644 index 00000000..9a52c504 --- /dev/null +++ b/tests/amqpconnection_tls_sasl.phpt @@ -0,0 +1,120 @@ +--TEST-- +AMQPConnection - TLS - SASL authentication +--SKIPIF-- + +--FILE-- + getenv('PHP_AMQP_SSL_HOST'), + 'port' => 5671, + 'cacert' => __DIR__ . "/../infra/tls/certificates/testca/cacert.pem", + 'cert' => __DIR__ . "/../infra/tls/certificates/sasl-client/cert.pem", + 'key' => __DIR__ . "/../infra/tls/certificates/sasl-client/key.pem", + 'sasl_method' => AMQP_SASL_METHOD_EXTERNAL, +); + +$cnn = new AMQPConnection($credentials); +$cnn->setSaslMethod(1); + +var_dump($cnn); + +$cnn->connect(); + +echo ($cnn->isConnected() ? 'connected' : 'disconnected'), PHP_EOL; + +echo PHP_EOL; + +$cnn = new AMQPConnection(); +$cnn->setHost(getenv('PHP_AMQP_SSL_HOST')); +$cnn->setPort(5671); +$cnn->setCACert(__DIR__ . "/../infra/tls/certificates/testca/cacert.pem"); +$cnn->setCert(__DIR__ . "/../infra/tls/certificates/sasl-client/cert.pem"); +$cnn->setKey(__DIR__ . "/../infra/tls/certificates/sasl-client/key.pem"); +$cnn->setSaslMethod(AMQP_SASL_METHOD_EXTERNAL); + +var_dump($cnn); + +$cnn->connect(); + +echo ($cnn->isConnected() ? 'connected' : 'disconnected'), PHP_EOL; +?> +--EXPECTF-- +object(AMQPConnection)#1 (18) { + ["login":"AMQPConnection":private]=> + string(5) "guest" + ["password":"AMQPConnection":private]=> + string(5) "guest" + ["host":"AMQPConnection":private]=> + string(%d) "%s" + ["vhost":"AMQPConnection":private]=> + string(1) "/" + ["port":"AMQPConnection":private]=> + int(5671) + ["readTimeout":"AMQPConnection":private]=> + float(0) + ["writeTimeout":"AMQPConnection":private]=> + float(0) + ["connectTimeout":"AMQPConnection":private]=> + float(0) + ["rpcTimeout":"AMQPConnection":private]=> + float(0) + ["frameMax":"AMQPConnection":private]=> + int(131072) + ["channelMax":"AMQPConnection":private]=> + int(256) + ["heartbeat":"AMQPConnection":private]=> + int(0) + ["cacert":"AMQPConnection":private]=> + string(%d) "%s/testca/cacert.pem" + ["key":"AMQPConnection":private]=> + string(%d) "%s/sasl-client/key.pem" + ["cert":"AMQPConnection":private]=> + string(%d) "%s/sasl-client/cert.pem" + ["verify":"AMQPConnection":private]=> + bool(true) + ["saslMethod":"AMQPConnection":private]=> + int(1) + ["connectionName":"AMQPConnection":private]=> + NULL +} +connected + +object(AMQPConnection)#2 (18) { + ["login":"AMQPConnection":private]=> + string(5) "guest" + ["password":"AMQPConnection":private]=> + string(5) "guest" + ["host":"AMQPConnection":private]=> + string(%d) "%s" + ["vhost":"AMQPConnection":private]=> + string(1) "/" + ["port":"AMQPConnection":private]=> + int(5671) + ["readTimeout":"AMQPConnection":private]=> + float(0) + ["writeTimeout":"AMQPConnection":private]=> + float(0) + ["connectTimeout":"AMQPConnection":private]=> + float(0) + ["rpcTimeout":"AMQPConnection":private]=> + float(0) + ["frameMax":"AMQPConnection":private]=> + int(131072) + ["channelMax":"AMQPConnection":private]=> + int(256) + ["heartbeat":"AMQPConnection":private]=> + int(0) + ["cacert":"AMQPConnection":private]=> + string(%d) "%s/testca/cacert.pem" + ["key":"AMQPConnection":private]=> + string(%d) "%s/sasl-client/key.pem" + ["cert":"AMQPConnection":private]=> + string(%d) "%s/sasl-client/cert.pem" + ["verify":"AMQPConnection":private]=> + bool(true) + ["saslMethod":"AMQPConnection":private]=> + int(1) + ["connectionName":"AMQPConnection":private]=> + NULL +} +connected diff --git a/tests/bug_19840.phpt b/tests/bug_19840.phpt index 083d8f75..3ccf4129 100644 --- a/tests/bug_19840.phpt +++ b/tests/bug_19840.phpt @@ -19,4 +19,4 @@ try { } ?> --EXPECT-- -AMQPConnectionException(0): Socket error: could not connect to host. \ No newline at end of file +AMQPConnectionException(0): Socket error: could not connect to host, hostname lookup failed \ No newline at end of file diff --git a/tools/check-stubs.sh b/tools/check-stubs.sh deleted file mode 100755 index e778fb22..00000000 --- a/tools/check-stubs.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env sh - -result=0 -for stub in `dirname $0`/../stubs/*.php; do - php -l `realpath $stub` - result=$(($result+$?)) -done - -test $result -gt 0 && exit 1 || exit 0 \ No newline at end of file diff --git a/tools/dev-build.sh b/tools/dev-build.sh deleted file mode 100755 index 8723080d..00000000 --- a/tools/dev-build.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env sh -set -e -phpize -CFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror" ./configure -make clean all \ No newline at end of file diff --git a/tools/dev-format.sh b/tools/dev-format.sh deleted file mode 100755 index a2da068d..00000000 --- a/tools/dev-format.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env sh -set -e -base_dir=`dirname $0`/../ -real_base_dir=`realpath $base_dir` -clang-format-17 -i $real_base_dir/*.c $real_base_dir/*.h \ No newline at end of file From dd631107db33bc331ee89086a586221eed8ea809 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Sun, 30 Jul 2023 21:45:45 +0200 Subject: [PATCH 022/147] Widen lowest supported librabbitmq version to >=0.8.0 (#441) --- .github/workflows/test.yaml | 4 ++-- README.md | 5 ++--- amqp_type.h | 2 +- config.m4 | 16 ++++++++++------ infra/tools/pamqp-install-librabbitmq | 6 +++++- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 6d0f5c0c..e68a2e42 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -67,7 +67,7 @@ jobs: test: name: Test php-${{ matrix.php-version }}${{ matrix.php-thread-safe && '-zts' || '' }} librabbitmq-${{ matrix.librabbitmq-version }} ${{ matrix.test-php-args == '-m' && 'memory leaks' || '' }} # librabbitmq < 0.11 needs older OpenSSL version - runs-on: ${{ matrix.librabbitmq-version == 'v0.10.0' && 'ubuntu-20.04' || 'ubuntu-22.04' }} + runs-on: ${{ (matrix.librabbitmq-version == 'v0.10.0' || matrix.librabbitmq-version == 'v0.9.0' || matrix.librabbitmq-version == 'v0.8.0') && 'ubuntu-20.04' || 'ubuntu-22.04' }} env: TEST_PHP_ARGS: ${{ matrix.test-php-args }} @@ -77,7 +77,7 @@ jobs: matrix: php-version: ['8.2', '8.1', '8.0', '7.4'] php-thread-safe: [true, false] - librabbitmq-version: ['master', 'v0.13.0', 'v0.11.0', 'v0.10.0'] + librabbitmq-version: ['master', 'v0.13.0', 'v0.12.0', 'v0.11.0', 'v0.10.0', 'v0.9.0', 'v0.8.0'] include: - php-version: '8.2' php-thread-safe: false diff --git a/README.md b/README.md index 0b4a5baf..36fab88c 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,8 @@ Object-oriented PHP bindings for the AMQP C library (https://github.com/alanxz/r ### Requirements: - PHP >= 7.4 with either ZTS or non-ZTS version. -- [RabbitMQ C library](https://github.com/alanxz/rabbitmq-c), commonly known as librabbitmq - (since php-amqp >= 2.0.0 librabbitmq >= 0.10.0, - see [release notes](https://pecl.php.net/package-changelog.php?package=amqp)). +- Starting with php-amqp 2.0.0 at least version 0.8.0 of [librabbitmq](https://github.com/alanxz/rabbitmq-c) is + required (at least 0.10.0 is recommended) - to run tests [RabbitMQ server](https://www.rabbitmq.com/) >= 3.4.0 required. ### Installation diff --git a/amqp_type.h b/amqp_type.h index 16505bc1..17218418 100644 --- a/amqp_type.h +++ b/amqp_type.h @@ -26,7 +26,7 @@ #include "php.h" -#if AMQP_VERSION_MINOR >= 13 +#if HAVE_LIBRABBITMQ_NEW_LAYOUT #include #else #include diff --git a/config.m4 b/config.m4 index 4c042571..87a80a1e 100644 --- a/config.m4 +++ b/config.m4 @@ -47,10 +47,14 @@ if test "$PHP_AMQP" != "no"; then LIBRABBITMQ_VERSION=`$PKG_CONFIG librabbitmq --modversion` AC_MSG_RESULT([found version $LIBRABBITMQ_VERSION]) - if ! $PKG_CONFIG librabbitmq --atleast-version 0.10.0 ; then - AC_MSG_ERROR([librabbitmq must be version 0.10.0 or greater]) + if ! $PKG_CONFIG librabbitmq --atleast-version 0.8.0 ; then + AC_MSG_ERROR([librabbitmq must be version 0.8.0 or greater]) fi + if ! $PKG_CONFIG librabbitmq --atleast-version 0.10.0 ; then + AC_MSG_WARN([librabbitmq 0.10.0 or greater recommended, current version is $LIBRABBITMQ_VERSION]) + fi + if test -r `$PKG_CONFIG librabbitmq --variable=includedir`/$NEW_LAYOUT; then HAVE_LIBRABBITMQ_NEW_LAYOUT=1 fi @@ -134,12 +138,12 @@ if test "$PHP_AMQP" != "no"; then IFS=$ac_IFS LIBRABBITMQ_API_VERSION=`expr [$]1 \* 1000000 + [$]2 \* 1000 + [$]3` - if test "$LIBRABBITMQ_API_VERSION" -lt 5001 ; then - AC_MSG_ERROR([librabbitmq must be version 0.5.2 or greater, $ac_cv_librabbitmq_version version given instead]) + if test "$LIBRABBITMQ_API_VERSION" -lt 8000 ; then + AC_MSG_ERROR([librabbitmq must be version 0.8.0 or greater, $ac_cv_librabbitmq_version version given instead]) fi - if test "$LIBRABBITMQ_API_VERSION" -lt 6000 ; then - AC_MSG_WARN([librabbitmq 0.6.0 or greater recommended, current version is $ac_cv_librabbitmq_version]) + if test "$LIBRABBITMQ_API_VERSION" -lt 10000 ; then + AC_MSG_WARN([librabbitmq 0.10.0 or greater recommended, current version is $ac_cv_librabbitmq_version]) fi else AC_MSG_ERROR([could not determine librabbitmq version]) diff --git a/infra/tools/pamqp-install-librabbitmq b/infra/tools/pamqp-install-librabbitmq index c78d16d8..19e1b5c4 100755 --- a/infra/tools/pamqp-install-librabbitmq +++ b/infra/tools/pamqp-install-librabbitmq @@ -43,7 +43,11 @@ cmake .. cmake --build . --parallel $(nproc) # Install -sudo cmake --build . --target install +sudo="" +if ! test `id -u` -eq 0; then + sudo="sudo" +fi +$sudo cmake --build . --target install # Cleanup rm -rf $BUILD_TMP From 6b70572b5dbbdbf259a6f0c685bc129742f02f38 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Sun, 30 Jul 2023 22:39:12 +0200 Subject: [PATCH 023/147] Prevent duplicate builds (#442) --- .github/workflows/test.yaml | 277 +++++++++++++++++++----------------- 1 file changed, 149 insertions(+), 128 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e68a2e42..e86b85a6 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,136 +1,157 @@ name: Test on: - push: - pull_request: - types: [opened, synchronize, reopened] + push: + pull_request: + types: [ opened, synchronize, reopened ] env: - TEST_TIMEOUT: 120 - CFLAGS: -D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror - PHP_AMQP_SSL_HOST: rabbitmq.example.org + TEST_TIMEOUT: 120 + CFLAGS: -D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror + PHP_AMQP_SSL_HOST: rabbitmq.example.org jobs: - checkstyle: - name: Check C formatting - runs-on: ubuntu-22.04 - steps: - - name: install clang-format - uses: myci-actions/add-deb-repo@11 - with: - repo: "deb https://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" - repo-name: llvm - keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - install: clang-format-17 - - - name: Checkout - uses: actions/checkout@v3.5.3 - - - name: Check style - run: clang-format-17 --dry-run --Werror *.c *.h - - stubs: - name: Check stubs php-${{ matrix.php-version }} - runs-on: ubuntu-22.04 - - strategy: - fail-fast: false - matrix: - php-version: ["8.2", "8.1", "8.0", "7.4"] - - steps: - - name: Checkout - uses: actions/checkout@v3.5.3 - - - name: Install packages - run: sudo apt-get install -y cmake valgrind - - - name: Setup PHP - uses: shivammathur/setup-php@2.25.4 - with: - php-version: ${{ matrix.php-version }} - extensions: json - coverage: none - - - name: Check stubs - run: ./infra/tools/pamqp-stubs-lint - - - name: Build librabbitmq - run: ./infra/tools/pamqp-install-librabbitmq master - - - name: Build PHP extension - run: phpize && ./configure && make - - - name: Validate stubs - run: ./infra/tools/pamqp-stubs-validate - - test: - name: Test php-${{ matrix.php-version }}${{ matrix.php-thread-safe && '-zts' || '' }} librabbitmq-${{ matrix.librabbitmq-version }} ${{ matrix.test-php-args == '-m' && 'memory leaks' || '' }} - # librabbitmq < 0.11 needs older OpenSSL version - runs-on: ${{ (matrix.librabbitmq-version == 'v0.10.0' || matrix.librabbitmq-version == 'v0.9.0' || matrix.librabbitmq-version == 'v0.8.0') && 'ubuntu-20.04' || 'ubuntu-22.04' }} - + dedup: + name: Prevent duplicate builds + continue-on-error: true + runs-on: ubuntu-22.04 + outputs: + should_skip: ${{ steps.skip_check.outputs.should_skip }} + steps: + - id: skip_check + uses: fkirc/skip-duplicate-actions@v5.3.0 + with: + skip_after_successful_duplicate: 'true' + cancel_others: 'true' + concurrent_skipping: 'same_content_newer' + + checkstyle: + name: Check C formatting + runs-on: ubuntu-22.04 + needs: dedup + if: needs.dedup.outputs.should_skip != 'true' + + steps: + - name: install clang-format + uses: myci-actions/add-deb-repo@11 + with: + repo: "deb https://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" + repo-name: llvm + keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key + install: clang-format-17 + + - name: Checkout + uses: actions/checkout@v3.5.3 + + - name: Check style + run: clang-format-17 --dry-run --Werror *.c *.h + + stubs: + name: Check stubs php-${{ matrix.php-version }} + runs-on: ubuntu-22.04 + needs: dedup + if: needs.dedup.outputs.should_skip != 'true' + + strategy: + fail-fast: false + matrix: + php-version: [ "8.2", "8.1", "8.0", "7.4" ] + + steps: + - name: Checkout + uses: actions/checkout@v3.5.3 + + - name: Install packages + run: sudo apt-get install -y cmake valgrind + + - name: Setup PHP + uses: shivammathur/setup-php@2.25.4 + with: + php-version: ${{ matrix.php-version }} + extensions: json + coverage: none + + - name: Check stubs + run: ./infra/tools/pamqp-stubs-lint + + - name: Build librabbitmq + run: ./infra/tools/pamqp-install-librabbitmq master + + - name: Build PHP extension + run: phpize && ./configure && make + + - name: Validate stubs + run: ./infra/tools/pamqp-stubs-validate + + test: + name: Test php-${{ matrix.php-version }}${{ matrix.php-thread-safe && '-zts' || '' }} librabbitmq-${{ matrix.librabbitmq-version }} ${{ matrix.test-php-args == '-m' && 'memory leaks' || '' }} + # librabbitmq < 0.11 needs older OpenSSL version + runs-on: ${{ (matrix.librabbitmq-version == 'v0.10.0' || matrix.librabbitmq-version == 'v0.9.0' || matrix.librabbitmq-version == 'v0.8.0') && 'ubuntu-20.04' || 'ubuntu-22.04' }} + needs: dedup + if: needs.dedup.outputs.should_skip != 'true' + + env: + TEST_PHP_ARGS: ${{ matrix.test-php-args }} + + strategy: + fail-fast: false + matrix: + php-version: [ '8.2', '8.1', '8.0', '7.4' ] + php-thread-safe: [ true, false ] + librabbitmq-version: [ 'master', 'v0.13.0', 'v0.12.0', 'v0.11.0', 'v0.10.0', 'v0.9.0', 'v0.8.0' ] + include: + - php-version: '8.2' + php-thread-safe: false + librabbitmq-version: 'master' + test-php-args: '-m' + + - php-version: '8.1' + php-thread-safe: true + librabbitmq-version: 'master' + test-php-args: '-m' + + steps: + - name: Checkout + uses: actions/checkout@v3.5.3 + + - name: Configure hostnames + run: sudo echo "127.0.0.1 ${{ env.PHP_AMQP_SSL_HOST }}" | sudo tee -a /etc/hosts + + - name: Generate test certificates + run: docker compose up ca + + - name: Start RabbitMQ + run: docker compose up -d rabbitmq + + - name: Install packages + run: sudo apt-get install -y cmake valgrind + + - name: Setup PHP + uses: shivammathur/setup-php@2.25.4 + with: + php-version: ${{ matrix.php-version }} + coverage: none + extensions: simplexml env: - TEST_PHP_ARGS: ${{ matrix.test-php-args }} - - strategy: - fail-fast: false - matrix: - php-version: ['8.2', '8.1', '8.0', '7.4'] - php-thread-safe: [true, false] - librabbitmq-version: ['master', 'v0.13.0', 'v0.12.0', 'v0.11.0', 'v0.10.0', 'v0.9.0', 'v0.8.0'] - include: - - php-version: '8.2' - php-thread-safe: false - librabbitmq-version: 'master' - test-php-args: '-m' - - - php-version: '8.1' - php-thread-safe: true - librabbitmq-version: 'master' - test-php-args: '-m' - - steps: - - name: Checkout - uses: actions/checkout@v3.5.3 - - - name: Configure hostnames - run: sudo echo "127.0.0.1 ${{ env.PHP_AMQP_SSL_HOST }}" | sudo tee -a /etc/hosts - - - name: Generate test certificates - run: docker compose up ca - - - name: Start RabbitMQ - run: docker compose up -d rabbitmq - - - name: Install packages - run: sudo apt-get install -y cmake valgrind - - - name: Setup PHP - uses: shivammathur/setup-php@2.25.4 - with: - php-version: ${{ matrix.php-version }} - coverage: none - extensions: simplexml - env: - phpts: ${{ matrix.php-thread-safe && 'ts' || 'nts' }} - - - name: Build librabbitmq - run: ./infra/tools/pamqp-install-librabbitmq ${{ matrix.librabbitmq-version }} - - - name: Print librabbitmq version - run: pkg-config librabbitmq --debug - - - name: Build PHP extension - run: phpize && ./configure && make - - - name: Test PHP extension - run: make test | tee result.txt - - - name: Dump RabbitMQ logs - run: docker compose logs - - - name: Benchmark PHP extension - run: php -n -c './tmp-php.ini' -d "extension_dir=./modules/" -d "extension=amqp.so" benchmark.php - - - name: Dump report - run: sh test-report.sh + phpts: ${{ matrix.php-thread-safe && 'ts' || 'nts' }} + + - name: Build librabbitmq + run: ./infra/tools/pamqp-install-librabbitmq ${{ matrix.librabbitmq-version }} + + - name: Print librabbitmq version + run: pkg-config librabbitmq --debug + + - name: Build PHP extension + run: phpize && ./configure && make + + - name: Test PHP extension + run: make test | tee result.txt + + - name: Dump RabbitMQ logs + run: docker compose logs + + - name: Benchmark PHP extension + run: php -n -c './tmp-php.ini' -d "extension_dir=./modules/" -d "extension=amqp.so" benchmark.php + + - name: Dump report + run: sh test-report.sh From 9cd0f3e7b5c31beda01dac94d4db98b2acce4356 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Sun, 30 Jul 2023 22:46:01 +0200 Subject: [PATCH 024/147] [RM] releasing version 2.0.0alpha2 --- package.xml | 24 +++++++++++++----------- php_amqp_version.h | 4 ++-- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/package.xml b/package.xml index 9f415508..ec2af139 100644 --- a/package.xml +++ b/package.xml @@ -22,22 +22,23 @@ pinepain@gmail.com yes - 2023-07-29 - + 2023-07-30 + - 2.0.0dev - 2.0.0dev + 2.0.0alpha2 + 2.0.0alpha2 - devel - devel + alpha + alpha PHP License - =0.8.0 (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/441) + - New Docker-based development environment (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/440) + - Prevent duplicate builds (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/442) For a complete list of changes see: -https://github.com/php-amqp/php-amqp/compare/v2.0.0alpha1...latest -]]> +https://github.com/php-amqp/php-amqp/compare/v2.0.0alpha1...v2.0.0alpha2]]> @@ -148,8 +149,9 @@ https://github.com/php-amqp/php-amqp/compare/v2.0.0alpha1...latest - - + + + diff --git a/php_amqp_version.h b/php_amqp_version.h index 300dc520..ab84af23 100644 --- a/php_amqp_version.h +++ b/php_amqp_version.h @@ -1,6 +1,6 @@ #define PHP_AMQP_VERSION_MAJOR 2 #define PHP_AMQP_VERSION_MINOR 0 #define PHP_AMQP_VERSION_PATCH 0 -#define PHP_AMQP_VERSION_EXTRA "dev" -#define PHP_AMQP_VERSION "2.0.0dev" +#define PHP_AMQP_VERSION_EXTRA "alpha2" +#define PHP_AMQP_VERSION "2.0.0alpha2" #define PHP_AMQP_VERSION_ID 20000 From c0193c00e1d886a8e216468fce6fc94c9f8db523 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Sun, 30 Jul 2023 22:46:23 +0200 Subject: [PATCH 025/147] Fix tag creation during release management --- infra/tools/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/tools/functions.php b/infra/tools/functions.php index 4c6396b2..3bb039c9 100644 --- a/infra/tools/functions.php +++ b/infra/tools/functions.php @@ -368,7 +368,7 @@ function gitCommit(int $step, string $nextVersion, string $message): void { function gitTag(int $step, string $nextVersion): void { $nextTag = versionToTag($nextVersion); - executeCommand("git tag $nextTag"); + executeCommand(sprintf("git tag %s -m '[RM] release %s'", $nextTag, $nextVersion)); printf("%d) Run \"git push origin %s\"\n", $step, $nextTag); } From f6d636ffdd8102ab7fd071ab88c3b64ce7933496 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Mon, 31 Jul 2023 00:06:11 +0200 Subject: [PATCH 026/147] Deterministic configuration for PHP CLI (#443) --- config.m4 | 2 +- infra/tools/pamqp-dump-reflection | 4 +-- infra/tools/pamqp-php-cli-deterministic | 36 +++++++++++++++++++++++++ infra/tools/pamqp-stubs-validate | 14 +++------- php-test-bin | 3 --- 5 files changed, 43 insertions(+), 16 deletions(-) create mode 100755 infra/tools/pamqp-php-cli-deterministic delete mode 100755 php-test-bin diff --git a/config.m4 b/config.m4 index 87a80a1e..e10b4705 100644 --- a/config.m4 +++ b/config.m4 @@ -7,7 +7,7 @@ PHP_ARG_WITH(librabbitmq-dir, for amqp, [ --with-librabbitmq-dir[=DIR] Set the path to librabbitmq install prefix.], yes) dnl Set test wrapper binary to ignore any local ini settings -PHP_EXECUTABLE="\$(top_srcdir)/php-test-bin" +PHP_EXECUTABLE="\$(top_srcdir)/infra/tools/pamqp-php-cli-deterministic" if test "$PHP_AMQP" != "no"; then AC_MSG_CHECKING([for supported PHP versions]) diff --git a/infra/tools/pamqp-dump-reflection b/infra/tools/pamqp-dump-reflection index e2f4ac59..6608d1cc 100755 --- a/infra/tools/pamqp-dump-reflection +++ b/infra/tools/pamqp-dump-reflection @@ -17,13 +17,13 @@ function sortByName(array $array): array { return $array; } -function getTypeMetadata(?ReflectionType $type): ?array { +function getTypeMetadata(?ReflectionNamedType $type): ?array { if ($type == null) { return null; } return [ - 'name' => (string) $type, + 'name' => $type->getName(), 'nullable' => $type->allowsNull() ]; } diff --git a/infra/tools/pamqp-php-cli-deterministic b/infra/tools/pamqp-php-cli-deterministic new file mode 100755 index 00000000..0231a3ca --- /dev/null +++ b/infra/tools/pamqp-php-cli-deterministic @@ -0,0 +1,36 @@ +#!/usr/bin/env sh + +set -o errexit +set -o nounset + +cache_dir=${XDG_CACHE_HOME:-${HOME}/.cache} +cached_script=${XDG_CACHE_HOME:-${HOME}/.cache}/pamqp-php-cli-deterministic-cached.sh + +if ! test -f "$cached_script"; then + extensions="json simplexml sodium" + args="-n \ + -d date.timezone=UTC \ + -d precision=20 \ + -d zend.enable_gc=On \ + -d display_errors=On \ + -d display_startup_errors=On \ + -d error_reporting=-1" + + extension_dir=$(php -r "echo ini_get('extension_dir');") + + for extension in $extensions; do + code="echo extension_loaded('$extension') ? 'true' : 'false';" + exists=$(php -r "$code") + bundled=$(php -n -r "$code") + if test "$exists" = "true" -a "${bundled}" = "false"; then + args="${args} -d extension=$extension_dir/$extension.so" + fi + done + + mkdir -p "$cache_dir" + echo "$(which php) $args \$@" > $cached_script.$$ + chmod +x $cached_script.$$ + mv $cached_script.$$ $cached_script +fi + +. $cached_script $@ diff --git a/infra/tools/pamqp-stubs-validate b/infra/tools/pamqp-stubs-validate index d32b03ce..981be2dc 100755 --- a/infra/tools/pamqp-stubs-validate +++ b/infra/tools/pamqp-stubs-validate @@ -3,17 +3,11 @@ set -o errexit set -o nounset -SHARED_JSON=`php -n -r 'echo !extension_loaded("json") ? "true" : "false";'` - -args="-n" -if [ "${SHARED_JSON}" = "true" ]; then - args="${args} -d extension=json.so" -fi - -base_dir=`dirname $0`/../../ +tools_dir=`dirname $0` +base_dir=$tools_dir/../../ real_base_dir=`realpath $base_dir` -php $args $real_base_dir/infra/tools/pamqp-dump-reflection stubs.json -php $args -d extension=modules/amqp.so $real_base_dir/infra/tools/pamqp-dump-reflection impl.json +$tools_dir/pamqp-php-cli-deterministic $real_base_dir/infra/tools/pamqp-dump-reflection stubs.json +$tools_dir/pamqp-php-cli-deterministic -d extension=modules/amqp.so $real_base_dir/infra/tools/pamqp-dump-reflection impl.json diff -10 -u stubs.json impl.json \ No newline at end of file diff --git a/php-test-bin b/php-test-bin deleted file mode 100755 index f9052648..00000000 --- a/php-test-bin +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -# Isolate tests better by running PHP without any ini files during test -`which php` -n $@ From 433b214adbe51880e49a9c545300d5fc0ab87446 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Mon, 31 Jul 2023 00:41:16 +0200 Subject: [PATCH 027/147] Parallelize test execution (#444) Especially impactful for valgrind based tests --- .github/workflows/test.yaml | 8 ++-- infra/php/Dockerfile | 1 + tests/003-channel-consumers.phpt | 12 +++--- tests/004-queue-consume-nested.phpt | 40 +++++++++--------- tests/004-queue-consume-orphaned.phpt | 8 ++-- .../amqpconnection_connect_login_failure.phpt | 4 +- ...mqpconnection_heartbeat_with_consumer.phpt | 4 +- tests/amqpenvelope_get_accessors.phpt | 8 ++-- tests/amqpenvelope_var_dump.phpt | 2 +- tests/amqpexchange-declare-segfault.phpt | 2 +- tests/amqpexchange_bind.phpt | 4 +- tests/amqpexchange_bind_with_arguments.phpt | 4 +- tests/amqpexchange_bind_without_key.phpt | 4 +- ...hange_bind_without_key_with_arguments.phpt | 4 +- tests/amqpexchange_declare_basic.phpt | 2 +- tests/amqpexchange_declare_existent.phpt | 4 +- tests/amqpexchange_declare_without_type.phpt | 2 +- tests/amqpexchange_invalid_type.phpt | 2 +- tests/amqpexchange_publish_basic.phpt | 2 +- tests/amqpexchange_publish_confirms.phpt | 6 +-- ...amqpexchange_publish_confirms_consume.phpt | 4 +- ...mqpexchange_publish_empty_routing_key.phpt | 2 +- tests/amqpexchange_publish_mandatory.phpt | 6 +-- ...mqpexchange_publish_mandatory_consume.phpt | 6 +-- ...h_mandatory_multiple_channels_pitfall.phpt | 4 +- ...amqpexchange_publish_null_routing_key.phpt | 2 +- ...pexchange_publish_with_decimal_header.phpt | 4 +- tests/amqpexchange_publish_with_null.phpt | Bin 2022 -> 2032 bytes .../amqpexchange_publish_with_properties.phpt | 4 +- ...ish_with_properties_ignore_num_header.phpt | 2 +- ...ties_ignore_unsupported_header_values.phpt | 2 +- ...publish_with_properties_nested_header.phpt | 4 +- ...blish_with_properties_user_id_failure.phpt | 6 +-- ...xchange_publish_with_timestamp_header.phpt | 4 +- tests/amqpexchange_setArgument.phpt | 16 +++---- tests/amqpexchange_set_flags.phpt | 4 +- tests/amqpexchange_unbind.phpt | 4 +- tests/amqpexchange_unbind_with_arguments.phpt | 4 +- tests/amqpexchange_unbind_without_key.phpt | 4 +- ...nge_unbind_without_key_with_arguments.phpt | 4 +- tests/amqpexchange_var_dump.phpt | 6 +-- tests/amqpqueue_bind_basic.phpt | 4 +- ...mqpqueue_bind_basic_empty_routing_key.phpt | 4 +- ...mqpqueue_bind_basic_headers_arguments.phpt | 4 +- tests/amqpqueue_bind_null_routing_key.phpt | 4 +- tests/amqpqueue_consume_basic.phpt | 8 ++-- tests/amqpqueue_consume_multiple.phpt | 4 +- ...amqpqueue_consume_multiple_no_doubles.phpt | 2 +- tests/amqpqueue_consume_nonexistent.phpt | 6 +-- tests/amqpqueue_declare_basic.phpt | 4 +- tests/amqpqueue_declare_with_arguments.phpt | 4 +- tests/amqpqueue_delete_basic.phpt | 4 +- tests/amqpqueue_empty_name.phpt | 2 +- tests/amqpqueue_get_basic.phpt | 10 ++--- tests/amqpqueue_get_empty_body.phpt | 4 +- tests/amqpqueue_get_headers.phpt | 4 +- tests/amqpqueue_get_nonexistent.phpt | 6 +-- tests/amqpqueue_headers_with_bool.phpt | 4 +- tests/amqpqueue_headers_with_float.phpt | 4 +- tests/amqpqueue_headers_with_null.phpt | 4 +- tests/amqpqueue_nack.phpt | 4 +- tests/amqpqueue_nested_arrays.phpt | 4 +- tests/amqpqueue_nested_headers.phpt | 12 +++--- tests/amqpqueue_setArgument.phpt | 12 +++--- ...pqueue_unbind_basic_empty_routing_key.phpt | 4 +- ...pqueue_unbind_basic_headers_arguments.phpt | 4 +- tests/bug_17831.phpt | 2 +- tests/bug_19707.phpt | 2 +- tests/bug_351.phpt | 4 +- tests/bug_gh53-2.phpt | 4 +- 70 files changed, 177 insertions(+), 176 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e86b85a6..7c7329b0 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -84,21 +84,21 @@ jobs: run: ./infra/tools/pamqp-stubs-validate test: - name: Test php-${{ matrix.php-version }}${{ matrix.php-thread-safe && '-zts' || '' }} librabbitmq-${{ matrix.librabbitmq-version }} ${{ matrix.test-php-args == '-m' && 'memory leaks' || '' }} + name: ${{ matrix.test-php-args == '-m' && 'Memtest' || 'Test' }} php-${{ matrix.php-version }}${{ matrix.php-thread-safe && '-ts' || '-nts' }} librabbitmq-${{ matrix.librabbitmq-version }} # librabbitmq < 0.11 needs older OpenSSL version - runs-on: ${{ (matrix.librabbitmq-version == 'v0.10.0' || matrix.librabbitmq-version == 'v0.9.0' || matrix.librabbitmq-version == 'v0.8.0') && 'ubuntu-20.04' || 'ubuntu-22.04' }} + runs-on: ${{ (matrix.librabbitmq-version == '0.10.0' || matrix.librabbitmq-version == '0.9.0' || matrix.librabbitmq-version == '0.8.0') && 'ubuntu-20.04' || 'ubuntu-22.04' }} needs: dedup if: needs.dedup.outputs.should_skip != 'true' env: - TEST_PHP_ARGS: ${{ matrix.test-php-args }} + TEST_PHP_ARGS: -j4 ${{ matrix.test-php-args }} strategy: fail-fast: false matrix: php-version: [ '8.2', '8.1', '8.0', '7.4' ] php-thread-safe: [ true, false ] - librabbitmq-version: [ 'master', 'v0.13.0', 'v0.12.0', 'v0.11.0', 'v0.10.0', 'v0.9.0', 'v0.8.0' ] + librabbitmq-version: [ 'master', '0.13.0', '0.12.0', '0.11.0', '0.10.0', '0.9.0', '0.8.0' ] include: - php-version: '8.2' php-thread-safe: false diff --git a/infra/php/Dockerfile b/infra/php/Dockerfile index 74920eaa..bc8e1ae2 100644 --- a/infra/php/Dockerfile +++ b/infra/php/Dockerfile @@ -9,6 +9,7 @@ RUN apt-get install -yqq build-essential RUN apt-get install -yqq librabbitmq-dev RUN apt-get install -yqq socat RUN apt-get install -yqq gdb +RUN apt-get install -yqq valgrind RUN echo 'PATH=$PATH:/src/infra/tools' >> /etc/bash.bashrc RUN echo 'CFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror"' >> /etc/bash.bashrc diff --git a/tests/003-channel-consumers.phpt b/tests/003-channel-consumers.phpt index 361d0cda..1fb0311c 100644 --- a/tests/003-channel-consumers.phpt +++ b/tests/003-channel-consumers.phpt @@ -12,18 +12,18 @@ $connection->connect(); $channel1 = new AMQPChannel($connection); $q1 = new AMQPQueue($channel1); -$q1->setName('q1-' . microtime(true)); +$q1->setName('q1-' . bin2hex(random_bytes(32))); $q1->declareQueue(); $channel2 = new AMQPChannel($connection); $q2_0 = new AMQPQueue($channel2); -$q2_0->setName('q2.0-' . microtime(true)); +$q2_0->setName('q2.0-' . bin2hex(random_bytes(32))); $q2_0->declareQueue(); $q2_1 = new AMQPQueue($channel2); -$q2_1->setName('q2.1-' . microtime(true)); +$q2_1->setName('q2.1-' . bin2hex(random_bytes(32))); $q2_1->declareQueue(); @@ -72,10 +72,10 @@ Channel holds consumer: c1: 1, c2: 2 Consumers belongs to their channels: c1: - test-consumer-0: q1-%f + test-consumer-0: q1-%s c2: - test-consumer-2-0: q2.0-%f - test-consumer-2-1: q2.1-%f + test-consumer-2-0: q2.0-%s + test-consumer-2-1: q2.1-%s Consumer removed after canceling: c1: 0, c2: 2 Consumer still stored after source variable been destroyed: c1: 0, c2: 2 diff --git a/tests/004-queue-consume-nested.phpt b/tests/004-queue-consume-nested.phpt index e9965dbf..a56417eb 100644 --- a/tests/004-queue-consume-nested.phpt +++ b/tests/004-queue-consume-nested.phpt @@ -10,12 +10,12 @@ AMQPQueue - nested consumers function test(AMQPChannel $channel1) { $ex1 = new AMQPExchange($channel1); - $ex1->setName('ex1-' . microtime(true)); + $ex1->setName('ex1-' . bin2hex(random_bytes(32))); $ex1->setType(AMQP_EX_TYPE_FANOUT); $ex1->declareExchange(); $q1 = new AMQPQueue($channel1); - $q1->setName('q1-' . microtime(true)); + $q1->setName('q1-' . bin2hex(random_bytes(32))); $q1->declareQueue(); $q1->bind($ex1->getName()); @@ -36,12 +36,12 @@ function test(AMQPChannel $channel1) $channel2 = new \AMQPChannel($queue->getConnection()); $ex2 = new AMQPExchange($channel2); - $ex2->setName('ex2-' . microtime(true)); + $ex2->setName('ex2-' . bin2hex(random_bytes(32))); $ex2->setType(AMQP_EX_TYPE_FANOUT); $ex2->declareExchange(); $q2 = new AMQPQueue($channel2); - $q2->setName('q2-' . microtime(true)); + $q2->setName('q2-' . bin2hex(random_bytes(32))); $q2->declareQueue(); $q2->bind($ex2->getName()); @@ -88,20 +88,20 @@ test($channel2); ?> --EXPECTF-- With default prefetch = 3 -1: ex1-%f [message 1 - 0] amq.ctag-%s - amq.ctag-%s (q1-%f): valid queue -2: ex1-%f [message 1 - 1] amq.ctag-%s - amq.ctag-%s (q1-%f): valid queue -2: ex1-%f [message 1 - 2] amq.ctag-%s - amq.ctag-%s (q1-%f): valid queue -2: ex1-%f [message 1 - 3] amq.ctag-%s - amq.ctag-%s (q1-%f): valid queue -1: ex2-%f [message 2 - 0] amq.ctag-%s - amq.ctag-%s (q2-%f): valid queue -2: ex2-%f [message 2 - 1] amq.ctag-%s - amq.ctag-%s (q2-%f): valid queue -1: ex2-%f [message 2 - 2] amq.ctag-%s - amq.ctag-%s (q2-%f): valid queue -2: ex2-%f [message 2 - 3] amq.ctag-%s - amq.ctag-%s (q2-%f): valid queue +1: ex1-%s [message 1 - 0] amq.ctag-%s - amq.ctag-%s (q1-%s): valid queue +2: ex1-%s [message 1 - 1] amq.ctag-%s - amq.ctag-%s (q1-%s): valid queue +2: ex1-%s [message 1 - 2] amq.ctag-%s - amq.ctag-%s (q1-%s): valid queue +2: ex1-%s [message 1 - 3] amq.ctag-%s - amq.ctag-%s (q1-%s): valid queue +1: ex2-%s [message 2 - 0] amq.ctag-%s - amq.ctag-%s (q2-%s): valid queue +2: ex2-%s [message 2 - 1] amq.ctag-%s - amq.ctag-%s (q2-%s): valid queue +1: ex2-%s [message 2 - 2] amq.ctag-%s - amq.ctag-%s (q2-%s): valid queue +2: ex2-%s [message 2 - 3] amq.ctag-%s - amq.ctag-%s (q2-%s): valid queue With prefetch = 1 -1: ex1-%f [message 1 - 0] amq.ctag-%s - amq.ctag-%s (q1-%f): valid queue -2: ex1-%f [message 1 - 1] amq.ctag-%s - amq.ctag-%s (q1-%f): valid queue -2: ex2-%f [message 2 - 0] amq.ctag-%s - amq.ctag-%s (q2-%f): valid queue -2: ex2-%f [message 2 - 1] amq.ctag-%s - amq.ctag-%s (q2-%f): valid queue -1: ex2-%f [message 2 - 2] amq.ctag-%s - amq.ctag-%s (q2-%f): valid queue -2: ex%d-%f [message %d - %d] amq.ctag-%s - amq.ctag-%s (q%d-%f): valid queue -1: ex%d-%f [message %d - %d] amq.ctag-%s - amq.ctag-%s (q%d-%f): valid queue -2: ex1-%f [message 1 - 3] amq.ctag-%s - amq.ctag-%s (q1-%f): valid queue +1: ex1-%s [message 1 - 0] amq.ctag-%s - amq.ctag-%s (q1-%s): valid queue +2: ex1-%s [message 1 - 1] amq.ctag-%s - amq.ctag-%s (q1-%s): valid queue +2: ex2-%s [message 2 - 0] amq.ctag-%s - amq.ctag-%s (q2-%s): valid queue +2: ex2-%s [message 2 - 1] amq.ctag-%s - amq.ctag-%s (q2-%s): valid queue +1: ex2-%s [message 2 - 2] amq.ctag-%s - amq.ctag-%s (q2-%s): valid queue +2: ex%d-%s [message %d - %d] amq.ctag-%s - amq.ctag-%s (q%d-%s): valid queue +1: ex%d-%s [message %d - %d] amq.ctag-%s - amq.ctag-%s (q%d-%s): valid queue +2: ex1-%s [message 1 - 3] amq.ctag-%s - amq.ctag-%s (q1-%s): valid queue diff --git a/tests/004-queue-consume-orphaned.phpt b/tests/004-queue-consume-orphaned.phpt index eddc10cb..2a64e168 100644 --- a/tests/004-queue-consume-orphaned.phpt +++ b/tests/004-queue-consume-orphaned.phpt @@ -12,12 +12,12 @@ $connection->connect(); $channel1 = new AMQPChannel($connection); $ex1 = new AMQPExchange($channel1); -$ex1->setName('ex1-' . microtime(true)); +$ex1->setName('ex1-' . bin2hex(random_bytes(32))); $ex1->setType(AMQP_EX_TYPE_FANOUT); $ex1->declareExchange(); $q1 = new AMQPQueue($channel1); -$q1->setName('q1-' . microtime(true)); +$q1->setName('q1-' . bin2hex(random_bytes(32))); $q1->declareQueue(); $q1->bind($ex1->getName()); @@ -34,7 +34,7 @@ $q1->cancel(); $q1 = null; $q2 = new AMQPQueue($channel1); -$q2->setName('q1-' . microtime(true)); +$q2->setName('q1-' . bin2hex(random_bytes(32))); $q2->declareQueue(); $q2->bind($ex1->getName()); @@ -93,7 +93,7 @@ object(AMQPEnvelope)#6 (20) { ["isRedelivery":"AMQPEnvelope":private]=> bool(false) ["exchangeName":"AMQPEnvelope":private]=> - string(%d) "ex1-%f" + string(%d) "ex1-%s" ["routingKey":"AMQPEnvelope":private]=> string(0) "" } diff --git a/tests/amqpconnection_connect_login_failure.phpt b/tests/amqpconnection_connect_login_failure.phpt index 191fd214..3b72a4ec 100644 --- a/tests/amqpconnection_connect_login_failure.phpt +++ b/tests/amqpconnection_connect_login_failure.phpt @@ -9,8 +9,8 @@ AMQPConnection connect login failure //ini_set('amqp.write_timeout', 60); $cnn = new AMQPConnection(); -$cnn->setLogin('nonexistent-login-'.microtime(true)); -$cnn->setPassword('nonexistent-password-'.microtime(true)); +$cnn->setLogin('nonexistent-login-'. bin2hex(random_bytes(32))); +$cnn->setPassword('nonexistent-password-'. bin2hex(random_bytes(32))); //var_dump($cnn); diff --git a/tests/amqpconnection_heartbeat_with_consumer.phpt b/tests/amqpconnection_heartbeat_with_consumer.phpt index 40945cc1..713e8ea4 100644 --- a/tests/amqpconnection_heartbeat_with_consumer.phpt +++ b/tests/amqpconnection_heartbeat_with_consumer.phpt @@ -13,8 +13,8 @@ var_dump($cnn); $ch = new AMQPChannel($cnn); -$q_dead_name = 'test.queue.dead.' . microtime(true); -$q_name = 'test.queue.' . microtime(true); +$q_dead_name = 'test.queue.dead.' . bin2hex(random_bytes(32)); +$q_name = 'test.queue.' . bin2hex(random_bytes(32)); $e = new AMQPExchange($ch); diff --git a/tests/amqpenvelope_get_accessors.phpt b/tests/amqpenvelope_get_accessors.phpt index 33fd3f1a..e0c7816c 100644 --- a/tests/amqpenvelope_get_accessors.phpt +++ b/tests/amqpenvelope_get_accessors.phpt @@ -11,12 +11,12 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); // Declare a new exchange $ex = new AMQPExchange($ch); -$ex->setName('exchange-'.microtime(true)); +$ex->setName('exchange-'. bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); // Create a new queue $q = new AMQPQueue($ch); -$q->setName('queue1' . microtime(true)); +$q->setName('queue1' . bin2hex(random_bytes(32))); $q->declareQueue(); // Bind it on the exchange to routing.key $q->bind($ex->getName(), 'routing.*'); @@ -77,7 +77,7 @@ object(AMQPEnvelope)#5 (20) { ["isRedelivery":"AMQPEnvelope":private]=> bool(false) ["exchangeName":"AMQPEnvelope":private]=> - string(%d) "exchange-%f" + string(%d) "exchange-%s" ["routingKey":"AMQPEnvelope":private]=> string(9) "routing.1" } @@ -95,7 +95,7 @@ AMQPEnvelope getDeliveryMode: int(1) getExchangeName: - string(%d) "exchange-%f" + string(%d) "exchange-%s" isRedelivery: bool(false) getContentEncoding: diff --git a/tests/amqpenvelope_var_dump.phpt b/tests/amqpenvelope_var_dump.phpt index 4944b891..330c1365 100644 --- a/tests/amqpenvelope_var_dump.phpt +++ b/tests/amqpenvelope_var_dump.phpt @@ -19,7 +19,7 @@ $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); // Create a new queue $q = new AMQPQueue($ch); -$q->setName('queue1' . microtime(true)); +$q->setName('queue1' . bin2hex(random_bytes(32))); $q->declareQueue(); // Bind it on the exchange to routing.key $q->bind($ex->getName(), 'routing.*'); diff --git a/tests/amqpexchange-declare-segfault.phpt b/tests/amqpexchange-declare-segfault.phpt index af1d1bde..d8f23929 100644 --- a/tests/amqpexchange-declare-segfault.phpt +++ b/tests/amqpexchange-declare-segfault.phpt @@ -7,7 +7,7 @@ AMQPExchange $cnn = new AMQPConnection(); $cnn->connect(); -$name = "exchange-" . microtime(true); +$name = "exchange-" . bin2hex(random_bytes(32)); $ex = new AMQPExchange(new AMQPChannel($cnn)); $ex->setName($name); diff --git a/tests/amqpexchange_bind.phpt b/tests/amqpexchange_bind.phpt index 09b537cc..67f278f0 100644 --- a/tests/amqpexchange_bind.phpt +++ b/tests/amqpexchange_bind.phpt @@ -11,13 +11,13 @@ $ch = new AMQPChannel($cnn); // Declare a new exchange $ex = new AMQPExchange($ch); -$ex->setName('exchange-' . microtime(true)); +$ex->setName('exchange-' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); // Declare a new exchange $ex2 = new AMQPExchange($ch); -$ex2->setName('exchange2-' . microtime(true)); +$ex2->setName('exchange2-' . bin2hex(random_bytes(32))); $ex2->setType(AMQP_EX_TYPE_FANOUT); $ex2->declareExchange(); diff --git a/tests/amqpexchange_bind_with_arguments.phpt b/tests/amqpexchange_bind_with_arguments.phpt index 5c121238..f2c686ab 100644 --- a/tests/amqpexchange_bind_with_arguments.phpt +++ b/tests/amqpexchange_bind_with_arguments.phpt @@ -11,13 +11,13 @@ $ch = new AMQPChannel($cnn); // Declare a new exchange $ex = new AMQPExchange($ch); -$ex->setName('exchange-' . microtime(true)); +$ex->setName('exchange-' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); // Declare a new exchange $ex2 = new AMQPExchange($ch); -$ex2->setName('exchange2-' . microtime(true)); +$ex2->setName('exchange2-' . bin2hex(random_bytes(32))); $ex2->setType(AMQP_EX_TYPE_FANOUT); $ex2->declareExchange(); diff --git a/tests/amqpexchange_bind_without_key.phpt b/tests/amqpexchange_bind_without_key.phpt index 98521721..8d25a762 100644 --- a/tests/amqpexchange_bind_without_key.phpt +++ b/tests/amqpexchange_bind_without_key.phpt @@ -11,13 +11,13 @@ $ch = new AMQPChannel($cnn); // Declare a new exchange $ex = new AMQPExchange($ch); -$ex->setName('exchange-' . microtime(true)); +$ex->setName('exchange-' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); // Declare a new exchange $ex2 = new AMQPExchange($ch); -$ex2->setName('exchange2-' . microtime(true)); +$ex2->setName('exchange2-' . bin2hex(random_bytes(32))); $ex2->setType(AMQP_EX_TYPE_FANOUT); $ex2->declareExchange(); diff --git a/tests/amqpexchange_bind_without_key_with_arguments.phpt b/tests/amqpexchange_bind_without_key_with_arguments.phpt index 103d237b..a68a71e4 100644 --- a/tests/amqpexchange_bind_without_key_with_arguments.phpt +++ b/tests/amqpexchange_bind_without_key_with_arguments.phpt @@ -11,13 +11,13 @@ $ch = new AMQPChannel($cnn); // Declare a new exchange $ex = new AMQPExchange($ch); -$ex->setName('exchange-' . microtime(true)); +$ex->setName('exchange-' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); // Declare a new exchange $ex2 = new AMQPExchange($ch); -$ex2->setName('exchange2-' . microtime(true)); +$ex2->setName('exchange2-' . bin2hex(random_bytes(32))); $ex2->setType(AMQP_EX_TYPE_FANOUT); $ex2->declareExchange(); diff --git a/tests/amqpexchange_declare_basic.phpt b/tests/amqpexchange_declare_basic.phpt index 99af7153..eaa90183 100644 --- a/tests/amqpexchange_declare_basic.phpt +++ b/tests/amqpexchange_declare_basic.phpt @@ -10,7 +10,7 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -var_dump($ex->setName("exchange-" . microtime(true))); +var_dump($ex->setName("exchange-" . bin2hex(random_bytes(32)))); var_dump($ex->setType(AMQP_EX_TYPE_FANOUT)); var_dump($ex->declareExchange()); ?> diff --git a/tests/amqpexchange_declare_existent.phpt b/tests/amqpexchange_declare_existent.phpt index d136d3ab..0a55649c 100644 --- a/tests/amqpexchange_declare_existent.phpt +++ b/tests/amqpexchange_declare_existent.phpt @@ -11,7 +11,7 @@ $ch = new AMQPChannel($cnn); echo 'Channel id: ', $ch->getChannelId(), PHP_EOL; -$exchangge_name = "exchange-" . microtime(true); +$exchangge_name = "exchange-" . bin2hex(random_bytes(32)); $ex = new AMQPExchange($ch); $ex->setName($exchangge_name); @@ -41,7 +41,7 @@ try { --EXPECTF-- Channel id: 1 Exchange declared: NULL -AMQPExchangeException(406): Server channel error: 406, message: PRECONDITION_FAILED - %s exchange 'exchange-%f' in vhost '/'%s +AMQPExchangeException(406): Server channel error: 406, message: PRECONDITION_FAILED - %s exchange 'exchange-%s' in vhost '/'%s Channel connected: false Connection connected: true AMQPChannelException(0): Could not create exchange. No channel available. \ No newline at end of file diff --git a/tests/amqpexchange_declare_without_type.phpt b/tests/amqpexchange_declare_without_type.phpt index ea77cd04..eec35306 100644 --- a/tests/amqpexchange_declare_without_type.phpt +++ b/tests/amqpexchange_declare_without_type.phpt @@ -9,7 +9,7 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); -$exchangge_name = "exchange-" . microtime(true); +$exchangge_name = "exchange-" . bin2hex(random_bytes(32)); $ex = new AMQPExchange($ch); $ex->setName($exchangge_name); diff --git a/tests/amqpexchange_invalid_type.phpt b/tests/amqpexchange_invalid_type.phpt index 191cebb9..99cb7490 100644 --- a/tests/amqpexchange_invalid_type.phpt +++ b/tests/amqpexchange_invalid_type.phpt @@ -10,7 +10,7 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName("exchange-" . microtime(true)); +$ex->setName("exchange-" . bin2hex(random_bytes(32))); $ex->setType("invalid_exchange_type"); echo "Channel ", $ch->isConnected() ? 'connected' : 'disconnected', PHP_EOL; diff --git a/tests/amqpexchange_publish_basic.phpt b/tests/amqpexchange_publish_basic.phpt index 4f99ca78..3f49d562 100644 --- a/tests/amqpexchange_publish_basic.phpt +++ b/tests/amqpexchange_publish_basic.phpt @@ -10,7 +10,7 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName("exchange-" . microtime(true)); +$ex->setName("exchange-" . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); var_dump($ex->publish('message', 'routing.key')); diff --git a/tests/amqpexchange_publish_confirms.phpt b/tests/amqpexchange_publish_confirms.phpt index 7e0456f0..870d54b2 100644 --- a/tests/amqpexchange_publish_confirms.phpt +++ b/tests/amqpexchange_publish_confirms.phpt @@ -30,7 +30,7 @@ try { $ex1 = new AMQPExchange($ch); -$ex1->setName("exchange-" . microtime(true)); +$ex1->setName("exchange-" . bin2hex(random_bytes(32))); $ex1->setType(AMQP_EX_TYPE_FANOUT); $ex1->setFlags(AMQP_AUTODELETE); $ex1->declareExchange(); @@ -89,7 +89,7 @@ try { $ex1->delete(); $ex2 = new AMQPExchange($ch); -$ex2->setName("exchange-nonexistent-" . microtime(true)); +$ex2->setName("exchange-nonexistent-" . bin2hex(random_bytes(32))); var_dump($ex2->publish('message 2', 'routing.key')); try { @@ -124,4 +124,4 @@ array(2) { bool(false) } NULL -AMQPChannelException(404): Server channel error: 404, message: NOT_FOUND - no exchange 'exchange-nonexistent-%f' in vhost '/' +AMQPChannelException(404): Server channel error: 404, message: NOT_FOUND - no exchange 'exchange-nonexistent-%s' in vhost '/' diff --git a/tests/amqpexchange_publish_confirms_consume.phpt b/tests/amqpexchange_publish_confirms_consume.phpt index e29ef7c1..2e3880c1 100644 --- a/tests/amqpexchange_publish_confirms_consume.phpt +++ b/tests/amqpexchange_publish_confirms_consume.phpt @@ -21,7 +21,7 @@ $ch = new AMQPChannel($cnn); $ch->confirmSelect(); $ex = new AMQPExchange($ch); -$ex->setName("exchange-" . microtime(true)); +$ex->setName("exchange-" . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->setFlags(AMQP_AUTODELETE); $ex->declareExchange(); @@ -30,7 +30,7 @@ var_dump($ex->publish('message 1', 'routing.key', AMQP_MANDATORY)); // Create a new queue $q = new AMQPQueue($ch); -$q->setName('queue-' . microtime(true)); +$q->setName('queue-' . bin2hex(random_bytes(32))); $q->setFlags(AMQP_AUTODELETE); $q->declareQueue(); diff --git a/tests/amqpexchange_publish_empty_routing_key.phpt b/tests/amqpexchange_publish_empty_routing_key.phpt index 782d38f0..0583e013 100644 --- a/tests/amqpexchange_publish_empty_routing_key.phpt +++ b/tests/amqpexchange_publish_empty_routing_key.phpt @@ -10,7 +10,7 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName("exchange-" . microtime(true)); +$ex->setName("exchange-" . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); var_dump($ex->publish('message')); diff --git a/tests/amqpexchange_publish_mandatory.phpt b/tests/amqpexchange_publish_mandatory.phpt index c0ba2448..3efaaa8e 100644 --- a/tests/amqpexchange_publish_mandatory.phpt +++ b/tests/amqpexchange_publish_mandatory.phpt @@ -31,7 +31,7 @@ try { $ex = new AMQPExchange($ch); -$ex->setName("exchange-" . microtime(true)); +$ex->setName("exchange-" . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->setFlags(AMQP_AUTODELETE); $ex->declareExchange(); @@ -41,7 +41,7 @@ var_dump($ex->publish('message 2', 'routing.key', AMQP_MANDATORY)); // Create a new queue $q = new AMQPQueue($ch); -$q->setName('queue-' . microtime(true)); +$q->setName('queue-' . bin2hex(random_bytes(32))); $q->setFlags(AMQP_AUTODELETE); $q->declareQueue(); @@ -86,7 +86,7 @@ array(6) { [1]=> string(8) "NO_ROUTE" [2]=> - string(%d) "exchange-%f" + string(%d) "exchange-%s" [3]=> string(11) "routing.key" [4]=> diff --git a/tests/amqpexchange_publish_mandatory_consume.phpt b/tests/amqpexchange_publish_mandatory_consume.phpt index 524bcf9f..09f68bad 100644 --- a/tests/amqpexchange_publish_mandatory_consume.phpt +++ b/tests/amqpexchange_publish_mandatory_consume.phpt @@ -21,7 +21,7 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName("exchange-" . microtime(true)); +$ex->setName("exchange-" . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->setFlags(AMQP_AUTODELETE); $ex->declareExchange(); @@ -30,7 +30,7 @@ var_dump($ex->publish('message 1', 'routing.key', AMQP_MANDATORY)); // Create a new queue $q = new AMQPQueue($ch); -$q->setName('queue-' . microtime(true)); +$q->setName('queue-' . bin2hex(random_bytes(32))); $q->setFlags(AMQP_AUTODELETE); $q->declareQueue(); @@ -84,7 +84,7 @@ array(6) { [1]=> string(8) "NO_ROUTE" [2]=> - string(%d) "exchange-%f" + string(%d) "exchange-%s" [3]=> string(11) "routing.key" [4]=> diff --git a/tests/amqpexchange_publish_mandatory_multiple_channels_pitfall.phpt b/tests/amqpexchange_publish_mandatory_multiple_channels_pitfall.phpt index 0cc98bc6..a03812ee 100644 --- a/tests/amqpexchange_publish_mandatory_multiple_channels_pitfall.phpt +++ b/tests/amqpexchange_publish_mandatory_multiple_channels_pitfall.phpt @@ -34,7 +34,7 @@ try { } -$exchange_name = "exchange-" . microtime(true); +$exchange_name = "exchange-" . bin2hex(random_bytes(32)); $ex1 = new AMQPExchange($ch1); $ex1->setName($exchange_name); @@ -51,7 +51,7 @@ var_dump($ex2->publish('message 2-2', 'routing.key', AMQP_MANDATORY)); // Create a new queue $q = new AMQPQueue($ch1); -$q->setName('queue-' . microtime(true)); +$q->setName('queue-' . bin2hex(random_bytes(32))); $q->setFlags(AMQP_AUTODELETE); $q->declareQueue(); diff --git a/tests/amqpexchange_publish_null_routing_key.phpt b/tests/amqpexchange_publish_null_routing_key.phpt index 8da9f2fc..65e1f613 100644 --- a/tests/amqpexchange_publish_null_routing_key.phpt +++ b/tests/amqpexchange_publish_null_routing_key.phpt @@ -10,7 +10,7 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName("exchange-" . microtime(true)); +$ex->setName("exchange-" . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); var_dump($ex->publish('message', null)); diff --git a/tests/amqpexchange_publish_with_decimal_header.phpt b/tests/amqpexchange_publish_with_decimal_header.phpt index c098de99..7dc23baf 100644 --- a/tests/amqpexchange_publish_with_decimal_header.phpt +++ b/tests/amqpexchange_publish_with_decimal_header.phpt @@ -12,12 +12,12 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName("exchange-" . microtime(true)); +$ex->setName("exchange-" . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); $q = new AMQPQueue($ch); -$q->setName('queue-' . microtime(true)); +$q->setName('queue-' . bin2hex(random_bytes(32))); $q->declareQueue(); $q->bind($ex->getName()); diff --git a/tests/amqpexchange_publish_with_null.phpt b/tests/amqpexchange_publish_with_null.phpt index 7032dddddcd7af4d88ca0261327d9fa28830f0fa..2f8a6929d0ff772a96c67df7f0b541a0a3e71eda 100644 GIT binary patch delta 37 scmaFH|ABwQdPa$)%siuv)C!HF#JrUJ-1wx*lGI`iVconnect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName("exchange-" . microtime(true)); +$ex->setName("exchange-" . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); @@ -86,7 +86,7 @@ AMQPEnvelope getDeliveryMode: int(1) getExchangeName: - string(%d) "exchange-%f" + string(%d) "exchange-%s" isRedelivery: bool(false) getContentEncoding: diff --git a/tests/amqpexchange_publish_with_properties_ignore_num_header.phpt b/tests/amqpexchange_publish_with_properties_ignore_num_header.phpt index c8343982..56b4d729 100644 --- a/tests/amqpexchange_publish_with_properties_ignore_num_header.phpt +++ b/tests/amqpexchange_publish_with_properties_ignore_num_header.phpt @@ -10,7 +10,7 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName("exchange-" . microtime(true)); +$ex->setName("exchange-" . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); 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 3e1716df..cf7243b0 100644 --- a/tests/amqpexchange_publish_with_properties_ignore_unsupported_header_values.phpt +++ b/tests/amqpexchange_publish_with_properties_ignore_unsupported_header_values.phpt @@ -10,7 +10,7 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName("exchange-" . microtime(true)); +$ex->setName("exchange-" . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); diff --git a/tests/amqpexchange_publish_with_properties_nested_header.phpt b/tests/amqpexchange_publish_with_properties_nested_header.phpt index ccdc7a89..6c3831e1 100644 --- a/tests/amqpexchange_publish_with_properties_nested_header.phpt +++ b/tests/amqpexchange_publish_with_properties_nested_header.phpt @@ -12,12 +12,12 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName("exchange-" . microtime(true)); +$ex->setName("exchange-" . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); $q = new AMQPQueue($ch); -$q->setName('queue-' . microtime(true)); +$q->setName('queue-' . bin2hex(random_bytes(32))); $q->declareQueue(); $q->bind($ex->getName()); diff --git a/tests/amqpexchange_publish_with_properties_user_id_failure.phpt b/tests/amqpexchange_publish_with_properties_user_id_failure.phpt index 09458cfb..dbcf050c 100644 --- a/tests/amqpexchange_publish_with_properties_user_id_failure.phpt +++ b/tests/amqpexchange_publish_with_properties_user_id_failure.phpt @@ -10,7 +10,7 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName("exchange-" . microtime(true)); +$ex->setName("exchange-" . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); @@ -19,7 +19,7 @@ echo "Connection ", $cnn->isConnected() ? 'connected' : 'disconnected', PHP_EOL; try { // NOTE: basic.publish is asynchronous, so ... - var_dump($ex->publish('message', 'routing.key', AMQP_NOPARAM, array('user_id' => 'unknown-' . microtime(true)))); + var_dump($ex->publish('message', 'routing.key', AMQP_NOPARAM, array('user_id' => 'unknown-' . bin2hex(random_bytes(32))))); } catch (AMQPException $e) { echo get_class($e), "({$e->getCode()}): ", $e->getMessage(), PHP_EOL; } @@ -49,6 +49,6 @@ Connection connected NULL Channel connected Connection connected -AMQPQueueException(406): Server channel error: 406, message: PRECONDITION_FAILED - user_id property set to 'unknown-%f' but authenticated user was 'guest' +AMQPQueueException(406): Server channel error: 406, message: PRECONDITION_FAILED - user_id property set to 'unknown-%s' but authenticated user was 'guest' Channel disconnected Connection connected \ No newline at end of file diff --git a/tests/amqpexchange_publish_with_timestamp_header.phpt b/tests/amqpexchange_publish_with_timestamp_header.phpt index 39dfafb4..a66ce013 100644 --- a/tests/amqpexchange_publish_with_timestamp_header.phpt +++ b/tests/amqpexchange_publish_with_timestamp_header.phpt @@ -12,12 +12,12 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName("exchange-" . microtime(true)); +$ex->setName("exchange-" . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); $q = new AMQPQueue($ch); -$q->setName('queue-' . microtime(true)); +$q->setName('queue-' . bin2hex(random_bytes(32))); $q->declareQueue(); $q->bind($ex->getName()); diff --git a/tests/amqpexchange_setArgument.phpt b/tests/amqpexchange_setArgument.phpt index 8a715bca..bf1a60a9 100644 --- a/tests/amqpexchange_setArgument.phpt +++ b/tests/amqpexchange_setArgument.phpt @@ -12,8 +12,8 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $heartbeat = 10; -$e_name_ae = 'test.exchange.ae.' . microtime(true); -$e_name = 'test.exchange.' . microtime(true); +$e_name_ae = 'test.exchange.ae.' . bin2hex(random_bytes(32)); +$e_name = 'test.exchange.' . bin2hex(random_bytes(32)); $ex_ae = new AMQPExchange($ch); $ex_ae->setName($e_name_ae); @@ -48,7 +48,7 @@ object(AMQPExchange)#3 (9) { ["channel":"AMQPExchange":private]=> %a ["name":"AMQPExchange":private]=> - string(%d) "test.exchange.ae.%f" + string(%d) "test.exchange.ae.%s" ["type":"AMQPExchange":private]=> string(6) "fanout" ["passive":"AMQPExchange":private]=> @@ -69,7 +69,7 @@ object(AMQPExchange)#4 (9) { ["channel":"AMQPExchange":private]=> %a ["name":"AMQPExchange":private]=> - string(%d) "test.exchange.%f" + string(%d) "test.exchange.%s" ["type":"AMQPExchange":private]=> string(6) "fanout" ["passive":"AMQPExchange":private]=> @@ -85,11 +85,11 @@ object(AMQPExchange)#4 (9) { ["x-ha-policy"]=> string(3) "all" ["alternate-exchange"]=> - string(%d) "test.exchange.ae.%f" + string(%d) "test.exchange.ae.%s" ["x-empty-string"]=> string(0) "" ["x-alternate-exchange-one-more-time"]=> - string(%d) "test.exchange.ae.%f" + string(%d) "test.exchange.ae.%s" ["x-numeric-argument"]=> int(100000) } @@ -100,7 +100,7 @@ object(AMQPExchange)#4 (9) { ["channel":"AMQPExchange":private]=> %a ["name":"AMQPExchange":private]=> - string(%d) "test.exchange.%f" + string(%d) "test.exchange.%s" ["type":"AMQPExchange":private]=> string(6) "fanout" ["passive":"AMQPExchange":private]=> @@ -116,7 +116,7 @@ object(AMQPExchange)#4 (9) { ["x-ha-policy"]=> string(3) "all" ["alternate-exchange"]=> - string(%d) "test.exchange.ae.%f" + string(%d) "test.exchange.ae.%s" ["x-empty-string"]=> string(0) "" ["x-numeric-argument"]=> diff --git a/tests/amqpexchange_set_flags.phpt b/tests/amqpexchange_set_flags.phpt index 6779e9ee..17e2b696 100644 --- a/tests/amqpexchange_set_flags.phpt +++ b/tests/amqpexchange_set_flags.phpt @@ -12,7 +12,7 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); // Declare a new exchange $ex = new AMQPExchange($ch); -$ex->setName('exchange-' . microtime(true)); +$ex->setName('exchange-' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->setArguments(array("x-ha-policy" => "all")); $ex->setFlags(AMQP_PASSIVE | AMQP_DURABLE | AMQP_AUTODELETE | AMQP_INTERNAL); @@ -24,7 +24,7 @@ object(AMQPExchange)#3 (9) { ["connection":"AMQPExchange":private]=> %a ["name":"AMQPExchange":private]=> - string(%d) "exchange-%f" + string(%d) "exchange-%s" ["type":"AMQPExchange":private]=> string(6) "fanout" ["passive":"AMQPExchange":private]=> diff --git a/tests/amqpexchange_unbind.phpt b/tests/amqpexchange_unbind.phpt index 0997e43f..4586f6a4 100644 --- a/tests/amqpexchange_unbind.phpt +++ b/tests/amqpexchange_unbind.phpt @@ -11,13 +11,13 @@ $ch = new AMQPChannel($cnn); // Declare a new exchange $ex = new AMQPExchange($ch); -$ex->setName('exchange-unbind-' . microtime(true)); +$ex->setName('exchange-unbind-' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); // Declare a new exchange $ex2 = new AMQPExchange($ch); -$ex2->setName('exchange2-unbind-' . microtime(true)); +$ex2->setName('exchange2-unbind-' . bin2hex(random_bytes(32))); $ex2->setType(AMQP_EX_TYPE_FANOUT); $ex2->declareExchange(); diff --git a/tests/amqpexchange_unbind_with_arguments.phpt b/tests/amqpexchange_unbind_with_arguments.phpt index 3a0955db..0faecff3 100644 --- a/tests/amqpexchange_unbind_with_arguments.phpt +++ b/tests/amqpexchange_unbind_with_arguments.phpt @@ -11,13 +11,13 @@ $ch = new AMQPChannel($cnn); // Declare a new exchange $ex = new AMQPExchange($ch); -$ex->setName('exchange-unbind-' . microtime(true)); +$ex->setName('exchange-unbind-' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); // Declare a new exchange $ex2 = new AMQPExchange($ch); -$ex2->setName('exchange2-exchange-unbind-' . microtime(true)); +$ex2->setName('exchange2-exchange-unbind-' . bin2hex(random_bytes(32))); $ex2->setType(AMQP_EX_TYPE_FANOUT); $ex2->declareExchange(); diff --git a/tests/amqpexchange_unbind_without_key.phpt b/tests/amqpexchange_unbind_without_key.phpt index bbd77760..12904c55 100644 --- a/tests/amqpexchange_unbind_without_key.phpt +++ b/tests/amqpexchange_unbind_without_key.phpt @@ -11,13 +11,13 @@ $ch = new AMQPChannel($cnn); // Declare a new exchange $ex = new AMQPExchange($ch); -$ex->setName('exchange-unbind-' . microtime(true)); +$ex->setName('exchange-unbind-' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); // Declare a new exchange $ex2 = new AMQPExchange($ch); -$ex2->setName('exchange2-unbind-' . microtime(true)); +$ex2->setName('exchange2-unbind-' . bin2hex(random_bytes(32))); $ex2->setType(AMQP_EX_TYPE_FANOUT); $ex2->declareExchange(); diff --git a/tests/amqpexchange_unbind_without_key_with_arguments.phpt b/tests/amqpexchange_unbind_without_key_with_arguments.phpt index 863b2777..d1e9e225 100644 --- a/tests/amqpexchange_unbind_without_key_with_arguments.phpt +++ b/tests/amqpexchange_unbind_without_key_with_arguments.phpt @@ -11,13 +11,13 @@ $ch = new AMQPChannel($cnn); // Declare a new exchange $ex = new AMQPExchange($ch); -$ex->setName('exchange-unbind-' . microtime(true)); +$ex->setName('exchange-unbind-' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); // Declare a new exchange $ex2 = new AMQPExchange($ch); -$ex2->setName('exchange2-unbind-' . microtime(true)); +$ex2->setName('exchange2-unbind-' . bin2hex(random_bytes(32))); $ex2->setType(AMQP_EX_TYPE_FANOUT); $ex2->declareExchange(); diff --git a/tests/amqpexchange_var_dump.phpt b/tests/amqpexchange_var_dump.phpt index 5bd41cdd..e75bb6d0 100644 --- a/tests/amqpexchange_var_dump.phpt +++ b/tests/amqpexchange_var_dump.phpt @@ -12,7 +12,7 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); // Declare a new exchange $ex = new AMQPExchange($ch); -$ex->setName('exchange-' . microtime(true)); +$ex->setName('exchange-' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); var_dump($ex); $ex->setArguments(array("x-ha-policy" => "all")); @@ -25,7 +25,7 @@ object(AMQPExchange)#3 (9) { ["channel":"AMQPExchange":private]=> %a ["name":"AMQPExchange":private]=> - string(%d) "exchange-%f" + string(%d) "exchange-%s" ["type":"AMQPExchange":private]=> string(6) "fanout" ["passive":"AMQPExchange":private]=> @@ -46,7 +46,7 @@ object(AMQPExchange)#3 (9) { ["channel":"AMQPExchange":private]=> %a ["name":"AMQPExchange":private]=> - string(%d) "exchange-%f" + string(%d) "exchange-%s" ["type":"AMQPExchange":private]=> string(6) "fanout" ["passive":"AMQPExchange":private]=> diff --git a/tests/amqpqueue_bind_basic.phpt b/tests/amqpqueue_bind_basic.phpt index 63df92d7..f515edfd 100644 --- a/tests/amqpqueue_bind_basic.phpt +++ b/tests/amqpqueue_bind_basic.phpt @@ -10,12 +10,12 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName('exchange-' . microtime(true)); +$ex->setName('exchange-' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_DIRECT); $ex->declareExchange(); $queue = new AMQPQueue($ch); -$queue->setName("queue-" . microtime(true)); +$queue->setName("queue-" . bin2hex(random_bytes(32))); $queue->declareQueue(); var_dump($queue->bind($ex->getName(), 'routing.key')); diff --git a/tests/amqpqueue_bind_basic_empty_routing_key.phpt b/tests/amqpqueue_bind_basic_empty_routing_key.phpt index cf497901..2d71bc7f 100644 --- a/tests/amqpqueue_bind_basic_empty_routing_key.phpt +++ b/tests/amqpqueue_bind_basic_empty_routing_key.phpt @@ -10,12 +10,12 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName('exchange-' . microtime(true)); +$ex->setName('exchange-' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_DIRECT); var_dump($ex->declareExchange()); $queue = new AMQPQueue($ch); -$queue->setName("queue-" . microtime(true)); +$queue->setName("queue-" . bin2hex(random_bytes(32))); var_dump($queue->declareQueue()); var_dump($queue->bind($ex->getName())); diff --git a/tests/amqpqueue_bind_basic_headers_arguments.phpt b/tests/amqpqueue_bind_basic_headers_arguments.phpt index ba7ee13c..0ae97026 100644 --- a/tests/amqpqueue_bind_basic_headers_arguments.phpt +++ b/tests/amqpqueue_bind_basic_headers_arguments.phpt @@ -10,12 +10,12 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName('exchange-' . microtime(true)); +$ex->setName('exchange-' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_HEADERS); var_dump($ex->declareExchange()); $queue = new AMQPQueue($ch); -$queue->setName("queue-" . microtime(true)); +$queue->setName("queue-" . bin2hex(random_bytes(32))); var_dump($queue->declareQueue()); $arguments = array('x-match' => 'all', 'type' => 'custom'); diff --git a/tests/amqpqueue_bind_null_routing_key.phpt b/tests/amqpqueue_bind_null_routing_key.phpt index 533a9a10..d0ca5b02 100644 --- a/tests/amqpqueue_bind_null_routing_key.phpt +++ b/tests/amqpqueue_bind_null_routing_key.phpt @@ -10,12 +10,12 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName('exchange-' . microtime(true)); +$ex->setName('exchange-' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_DIRECT); var_dump($ex->declareExchange()); $queue = new AMQPQueue($ch); -$queue->setName("queue-" . microtime(true)); +$queue->setName("queue-" . bin2hex(random_bytes(32))); var_dump($queue->declareQueue()); var_dump($queue->bind($ex->getName(), null)); diff --git a/tests/amqpqueue_consume_basic.phpt b/tests/amqpqueue_consume_basic.phpt index 18ac0442..2fe68157 100644 --- a/tests/amqpqueue_consume_basic.phpt +++ b/tests/amqpqueue_consume_basic.phpt @@ -13,13 +13,13 @@ $ch = new AMQPChannel($cnn); // Declare a new exchange $ex = new AMQPExchange($ch); -$ex->setName('exchange-' . microtime(true)); +$ex->setName('exchange-' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); // Create a new queue $q = new AMQPQueue($ch); -$q->setName('queue-' . microtime(true)); +$q->setName('queue-' . bin2hex(random_bytes(32))); $q->declareQueue(); // Bind it on the exchange to routing.key @@ -71,7 +71,7 @@ AMQPEnvelope getDeliveryMode: int(1) getExchangeName: - string(%d) "exchange-%f" + string(%d) "exchange-%s" isRedelivery: bool(false) getContentEncoding: @@ -115,7 +115,7 @@ AMQPEnvelope getDeliveryMode: int(2) getExchangeName: - string(%d) "exchange-%f" + string(%d) "exchange-%s" isRedelivery: bool(false) getContentEncoding: diff --git a/tests/amqpqueue_consume_multiple.phpt b/tests/amqpqueue_consume_multiple.phpt index e3982814..7184ee16 100644 --- a/tests/amqpqueue_consume_multiple.phpt +++ b/tests/amqpqueue_consume_multiple.phpt @@ -73,9 +73,9 @@ $q2->cancel(); ?> --EXPECTF-- Message: message1, routing key: routing.one, consumer tag: amq.ctag-%s -Queue: queue-one-%f, consumer tag: amq.ctag-%s +Queue: queue-one-%s, consumer tag: amq.ctag-%s Queue and message consumer tag matches Message: message2, routing key: routing.two, consumer tag: amq.ctag-%s -Queue: queue-two-%f, consumer tag: amq.ctag-%s +Queue: queue-two-%s, consumer tag: amq.ctag-%s Queue and message consumer tag matches diff --git a/tests/amqpqueue_consume_multiple_no_doubles.phpt b/tests/amqpqueue_consume_multiple_no_doubles.phpt index 59790abd..f59cadc4 100644 --- a/tests/amqpqueue_consume_multiple_no_doubles.phpt +++ b/tests/amqpqueue_consume_multiple_no_doubles.phpt @@ -13,7 +13,7 @@ $ch = new AMQPChannel($cnn); // Create a new queue $q = new AMQPQueue($ch); -$q->setName('queue-' . microtime(true)); +$q->setName('queue-' . bin2hex(random_bytes(32))); $q->declareQueue(); var_dump($q->getConsumerTag()); diff --git a/tests/amqpqueue_consume_nonexistent.phpt b/tests/amqpqueue_consume_nonexistent.phpt index 6ccdf65e..4e4c1250 100644 --- a/tests/amqpqueue_consume_nonexistent.phpt +++ b/tests/amqpqueue_consume_nonexistent.phpt @@ -15,13 +15,13 @@ $ch = new AMQPChannel($cnn); // Declare a new exchange $ex = new AMQPExchange($ch); -$ex->setName('exchange-' . microtime(true)); +$ex->setName('exchange-' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); // Create a new queue $q = new AMQPQueue($ch); -$q->setName('nonexistent-' . microtime(true)); +$q->setName('nonexistent-' . bin2hex(random_bytes(32))); try { $q->consume('noop'); @@ -31,4 +31,4 @@ try { ?> --EXPECTF-- -AMQPQueueException(404): Server channel error: 404, message: NOT_FOUND - no queue 'nonexistent-%f' in vhost '/' +AMQPQueueException(404): Server channel error: 404, message: NOT_FOUND - no queue 'nonexistent-%s' in vhost '/' diff --git a/tests/amqpqueue_declare_basic.phpt b/tests/amqpqueue_declare_basic.phpt index ee08e616..f0c2c190 100644 --- a/tests/amqpqueue_declare_basic.phpt +++ b/tests/amqpqueue_declare_basic.phpt @@ -9,12 +9,12 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName('exchange-' . microtime(true)); +$ex->setName('exchange-' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_DIRECT); $ex->declareExchange(); $queue = new AMQPQueue($ch); -var_dump($queue->setName("queue-" . microtime(true))); +var_dump($queue->setName("queue-" . bin2hex(random_bytes(32)))); var_dump($queue->declareQueue()); var_dump($queue->bind($ex->getName(), 'routing.key')); diff --git a/tests/amqpqueue_declare_with_arguments.phpt b/tests/amqpqueue_declare_with_arguments.phpt index 065e79b3..5f173eb1 100644 --- a/tests/amqpqueue_declare_with_arguments.phpt +++ b/tests/amqpqueue_declare_with_arguments.phpt @@ -9,12 +9,12 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName('exchange-' . microtime(true)); +$ex->setName('exchange-' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_DIRECT); $ex->declareExchange(); $queue = new AMQPQueue($ch); -var_dump($queue->setName("queue-" . microtime(true))); +var_dump($queue->setName("queue-" . bin2hex(random_bytes(32)))); var_dump($queue->setArgument('x-dead-letter-exchange', '')); var_dump($queue->setArgument('x-dead-letter-routing-key', 'some key')); var_dump($queue->setArgument('x-message-ttl', 42)); diff --git a/tests/amqpqueue_delete_basic.phpt b/tests/amqpqueue_delete_basic.phpt index a18e59ff..4d817f02 100644 --- a/tests/amqpqueue_delete_basic.phpt +++ b/tests/amqpqueue_delete_basic.phpt @@ -9,12 +9,12 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName('exchange-' . microtime(true)); +$ex->setName('exchange-' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); $queue = new AMQPQueue($ch); -$queue->setName("queue-" . microtime(true)); +$queue->setName("queue-" . bin2hex(random_bytes(32))); $queue->declareQueue(); $queue->bind($ex->getName()); diff --git a/tests/amqpqueue_empty_name.phpt b/tests/amqpqueue_empty_name.phpt index 959c3f8d..c13daf92 100644 --- a/tests/amqpqueue_empty_name.phpt +++ b/tests/amqpqueue_empty_name.phpt @@ -9,7 +9,7 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName('exchange-' . microtime(true)); +$ex->setName('exchange-' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_DIRECT); $ex->declareExchange(); diff --git a/tests/amqpqueue_get_basic.phpt b/tests/amqpqueue_get_basic.phpt index 29d7b09d..4635a2c4 100644 --- a/tests/amqpqueue_get_basic.phpt +++ b/tests/amqpqueue_get_basic.phpt @@ -13,13 +13,13 @@ $ch = new AMQPChannel($cnn); // Declare a new exchange $ex = new AMQPExchange($ch); -$ex->setName('exchange-'. microtime(true)); +$ex->setName('exchange-'. bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); // Create a new queue $q = new AMQPQueue($ch); -$q->setName('queue-' . microtime(true)); +$q->setName('queue-' . bin2hex(random_bytes(32))); $q->declareQueue(); // Bind it on the exchange to routing.key @@ -54,7 +54,7 @@ AMQPEnvelope getDeliveryMode: int(1) getExchangeName: - string(%d) "exchange-%f" + string(%d) "exchange-%s" isRedelivery: bool(false) getContentEncoding: @@ -98,7 +98,7 @@ AMQPEnvelope getDeliveryMode: int(1) getExchangeName: - string(%d) "exchange-%f" + string(%d) "exchange-%s" isRedelivery: bool(false) getContentEncoding: @@ -140,7 +140,7 @@ AMQPEnvelope getDeliveryMode: int(1) getExchangeName: - string(%d) "exchange-%f" + string(%d) "exchange-%s" isRedelivery: bool(false) getContentEncoding: diff --git a/tests/amqpqueue_get_empty_body.phpt b/tests/amqpqueue_get_empty_body.phpt index b301b277..0e65bcb0 100644 --- a/tests/amqpqueue_get_empty_body.phpt +++ b/tests/amqpqueue_get_empty_body.phpt @@ -11,13 +11,13 @@ $ch = new AMQPChannel($cnn); // Declare a new exchange $ex = new AMQPExchange($ch); -$ex->setName('exchange' . microtime(true)); +$ex->setName('exchange' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); // Create a new queue $q = new AMQPQueue($ch); -$q->setName('queue1' . microtime(true)); +$q->setName('queue1' . bin2hex(random_bytes(32))); $q->declareQueue(); // Bind it on the exchange to routing.key diff --git a/tests/amqpqueue_get_headers.phpt b/tests/amqpqueue_get_headers.phpt index cf60247f..b589f7a8 100644 --- a/tests/amqpqueue_get_headers.phpt +++ b/tests/amqpqueue_get_headers.phpt @@ -11,13 +11,13 @@ $ch = new AMQPChannel($cnn); // Declare a new exchange $ex = new AMQPExchange($ch); -$ex->setName('exchange' . microtime(true)); +$ex->setName('exchange' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); // Create a new queue $q = new AMQPQueue($ch); -$q->setName('queue1' . microtime(true)); +$q->setName('queue1' . bin2hex(random_bytes(32))); $q->declareQueue(); // Bind it on the exchange to routing.key diff --git a/tests/amqpqueue_get_nonexistent.phpt b/tests/amqpqueue_get_nonexistent.phpt index 30c661f8..586b622d 100644 --- a/tests/amqpqueue_get_nonexistent.phpt +++ b/tests/amqpqueue_get_nonexistent.phpt @@ -13,13 +13,13 @@ $ch = new AMQPChannel($cnn); // Declare a new exchange $ex = new AMQPExchange($ch); -$ex->setName('exchange-' . microtime(true)); +$ex->setName('exchange-' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); // Create a new queue $q = new AMQPQueue($ch); -$q->setName('nonexistent-' . microtime(true)); +$q->setName('nonexistent-' . bin2hex(random_bytes(32))); try { $q->get(); @@ -29,4 +29,4 @@ try { ?> --EXPECTF-- -AMQPQueueException(404): Server channel error: 404, message: NOT_FOUND - no queue 'nonexistent-%f' in vhost '/' +AMQPQueueException(404): Server channel error: 404, message: NOT_FOUND - no queue 'nonexistent-%s' in vhost '/' diff --git a/tests/amqpqueue_headers_with_bool.phpt b/tests/amqpqueue_headers_with_bool.phpt index ac2bd222..d9b4e1c0 100644 --- a/tests/amqpqueue_headers_with_bool.phpt +++ b/tests/amqpqueue_headers_with_bool.phpt @@ -10,11 +10,11 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName('exchange' . microtime(true)); +$ex->setName('exchange' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_TOPIC); $ex->declareExchange(); $q = new AMQPQueue($ch); -$q->setName('queue1' . microtime(true)); +$q->setName('queue1' . bin2hex(random_bytes(32))); $q->declareQueue(); $q->bind($ex->getName(), '#'); diff --git a/tests/amqpqueue_headers_with_float.phpt b/tests/amqpqueue_headers_with_float.phpt index 2a9349fa..a2d55aba 100644 --- a/tests/amqpqueue_headers_with_float.phpt +++ b/tests/amqpqueue_headers_with_float.phpt @@ -10,11 +10,11 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName('exchange' . microtime(true)); +$ex->setName('exchange' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_TOPIC); $ex->declareExchange(); $q = new AMQPQueue($ch); -$q->setName('queue1' . microtime(true)); +$q->setName('queue1' . bin2hex(random_bytes(32))); $q->declareQueue(); $q->bind($ex->getName(), '#'); diff --git a/tests/amqpqueue_headers_with_null.phpt b/tests/amqpqueue_headers_with_null.phpt index b1b219a3..f663395e 100644 --- a/tests/amqpqueue_headers_with_null.phpt +++ b/tests/amqpqueue_headers_with_null.phpt @@ -10,11 +10,11 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName('exchange' . microtime(true)); +$ex->setName('exchange' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_TOPIC); $ex->declareExchange(); $q = new AMQPQueue($ch); -$q->setName('queue1' . microtime(true)); +$q->setName('queue1' . bin2hex(random_bytes(32))); $q->declareQueue(); $q->bind($ex->getName(), '#'); diff --git a/tests/amqpqueue_nack.phpt b/tests/amqpqueue_nack.phpt index d6765fba..64a688bf 100644 --- a/tests/amqpqueue_nack.phpt +++ b/tests/amqpqueue_nack.phpt @@ -12,14 +12,14 @@ $ch = new AMQPChannel($cnn); // Declare a new exchange $ex = new AMQPExchange($ch); -$ex->setName('testnack' . microtime(true)); +$ex->setName('testnack' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); $exchangeName = $ex->getName(); // Create a new queue $q = new AMQPQueue($ch); -$q->setName('testnack' . microtime(true)); +$q->setName('testnack' . bin2hex(random_bytes(32))); $q->declareQueue(); $q->bind($exchangeName, '#'); diff --git a/tests/amqpqueue_nested_arrays.phpt b/tests/amqpqueue_nested_arrays.phpt index bbf2e9ea..366bb6c6 100644 --- a/tests/amqpqueue_nested_arrays.phpt +++ b/tests/amqpqueue_nested_arrays.phpt @@ -10,11 +10,11 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName('exchange' . microtime(true)); +$ex->setName('exchange' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_TOPIC); $ex->declareExchange(); $q = new AMQPQueue($ch); -$q->setName('queue1' . microtime(true)); +$q->setName('queue1' . bin2hex(random_bytes(32))); $q->declareQueue(); $q->bind($ex->getName(), '#'); diff --git a/tests/amqpqueue_nested_headers.phpt b/tests/amqpqueue_nested_headers.phpt index d6933521..4c93e58f 100644 --- a/tests/amqpqueue_nested_headers.phpt +++ b/tests/amqpqueue_nested_headers.phpt @@ -11,23 +11,23 @@ $ch = new AMQPChannel($cnn); // create an error exchange and bind a queue to it: $errorXchange = new AMQPExchange($ch); -$errorXchange->setName('errorXchange' . microtime(true)); +$errorXchange->setName('errorXchange' . bin2hex(random_bytes(32))); $errorXchange->setType(AMQP_EX_TYPE_TOPIC); $errorXchange->declareExchange(); $errorQ = new AMQPQueue($ch); -$errorQ->setName('errorQueue' . microtime(true)); +$errorQ->setName('errorQueue' . bin2hex(random_bytes(32))); $errorQ->declareQueue(); $errorQ->bind($errorXchange->getName(), '#'); // Declare a new exchange and queue using this dead-letter-exchange: $ex = new AMQPExchange($ch); -$ex->setName('exchange-' . microtime(true)); +$ex->setName('exchange-' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_TOPIC); $ex->declareExchange(); $q = new AMQPQueue($ch); -$q->setName('queue-' . microtime(true)); +$q->setName('queue-' . bin2hex(random_bytes(32))); $q->setArgument('x-dead-letter-exchange', $errorXchange->getName()); $q->declareQueue(); $q->bind($ex->getName(), '#'); @@ -72,14 +72,14 @@ array(1) { ["reason"]=> string(8) "rejected" ["queue"]=> - string(%d) "queue-%f" + string(%d) "queue-%s" ["time"]=> object(AMQPTimestamp)#%d (1) { ["timestamp":"AMQPTimestamp":private]=> float(%d) } ["exchange"]=> - string(%d) "exchange-%f" + string(%d) "exchange-%s" ["routing-keys"]=> array(1) { [0]=> diff --git a/tests/amqpqueue_setArgument.phpt b/tests/amqpqueue_setArgument.phpt index 3e999118..d5c72f9e 100644 --- a/tests/amqpqueue_setArgument.phpt +++ b/tests/amqpqueue_setArgument.phpt @@ -12,8 +12,8 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $heartbeat = 10; -$q_dead_name = 'test.queue.dead.' . microtime(true); -$q_name = 'test.queue.' . microtime(true); +$q_dead_name = 'test.queue.dead.' . bin2hex(random_bytes(32)); +$q_name = 'test.queue.' . bin2hex(random_bytes(32)); $q = new AMQPQueue($ch); $q->setName($q_name); @@ -42,7 +42,7 @@ object(AMQPQueue)#3 (9) { ["channel":"AMQPQueue":private]=> %a ["name":"AMQPQueue":private]=> - string(%d) "test.queue.%f" + string(%d) "test.queue.%s" ["consumerTag":"AMQPQueue":private]=> NULL ["passive":"AMQPQueue":private]=> @@ -63,7 +63,7 @@ object(AMQPQueue)#4 (9) { ["channel":"AMQPQueue":private]=> %a ["name":"AMQPQueue":private]=> - string(%d) "test.queue.dead.%f" + string(%d) "test.queue.dead.%s" ["consumerTag":"AMQPQueue":private]=> NULL ["passive":"AMQPQueue":private]=> @@ -79,7 +79,7 @@ object(AMQPQueue)#4 (9) { ["x-dead-letter-exchange"]=> string(0) "" ["x-dead-letter-routing-key"]=> - string(%d) "test.queue.%f" + string(%d) "test.queue.%s" ["x-message-ttl"]=> int(100000) } @@ -90,7 +90,7 @@ object(AMQPQueue)#4 (9) { ["channel":"AMQPQueue":private]=> %a ["name":"AMQPQueue":private]=> - string(%d) "test.queue.dead.%f" + string(%d) "test.queue.dead.%s" ["consumerTag":"AMQPQueue":private]=> NULL ["passive":"AMQPQueue":private]=> diff --git a/tests/amqpqueue_unbind_basic_empty_routing_key.phpt b/tests/amqpqueue_unbind_basic_empty_routing_key.phpt index 74bf9b58..893da3c0 100644 --- a/tests/amqpqueue_unbind_basic_empty_routing_key.phpt +++ b/tests/amqpqueue_unbind_basic_empty_routing_key.phpt @@ -10,12 +10,12 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName('exchange-' . microtime(true)); +$ex->setName('exchange-' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_DIRECT); $ex->declareExchange(); $queue = new AMQPQueue($ch); -$queue->setName("queue-" . microtime(true)); +$queue->setName("queue-" . bin2hex(random_bytes(32))); $queue->declareQueue(); var_dump($queue->bind($ex->getName())); var_dump($queue->unbind($ex->getName())); diff --git a/tests/amqpqueue_unbind_basic_headers_arguments.phpt b/tests/amqpqueue_unbind_basic_headers_arguments.phpt index be3c3fba..d3470a69 100644 --- a/tests/amqpqueue_unbind_basic_headers_arguments.phpt +++ b/tests/amqpqueue_unbind_basic_headers_arguments.phpt @@ -10,12 +10,12 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName('exchange-' . microtime(true)); +$ex->setName('exchange-' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_DIRECT); $ex->declareExchange(); $queue = new AMQPQueue($ch); -$queue->setName("queue-" . microtime(true)); +$queue->setName("queue-" . bin2hex(random_bytes(32))); $queue->declareQueue(); $arguments = array('x-match' => 'all', 'type' => 'custom'); diff --git a/tests/bug_17831.phpt b/tests/bug_17831.phpt index 52e6bd91..f4d14cc0 100644 --- a/tests/bug_17831.phpt +++ b/tests/bug_17831.phpt @@ -10,7 +10,7 @@ $c->connect(); $ch = new AMQPChannel($c); $ex = new AMQPExchange($ch); -$ex->setName("exchange-" . microtime(true)); +$ex->setName("exchange-" . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); try { diff --git a/tests/bug_19707.phpt b/tests/bug_19707.phpt index 8a180875..20343601 100644 --- a/tests/bug_19707.phpt +++ b/tests/bug_19707.phpt @@ -15,7 +15,7 @@ $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); $q = new AMQPQueue($ch); -$q->setName('queue' . microtime(true)); +$q->setName('queue' . bin2hex(random_bytes(32))); $q->setFlags(AMQP_DURABLE); $q->declareQueue(); diff --git a/tests/bug_351.phpt b/tests/bug_351.phpt index e272e111..cfa5a33c 100644 --- a/tests/bug_351.phpt +++ b/tests/bug_351.phpt @@ -10,12 +10,12 @@ $cnn->connect(); $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setName('exchange' . microtime(true)); +$ex->setName('exchange' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declareExchange(); $q = new AMQPQueue($ch); -$q->setName('queue1' . microtime(true)); +$q->setName('queue1' . bin2hex(random_bytes(32))); $q->declareQueue(); $q->bind($ex->getName(), '*'); diff --git a/tests/bug_gh53-2.phpt b/tests/bug_gh53-2.phpt index 08674a1a..3ced2e90 100644 --- a/tests/bug_gh53-2.phpt +++ b/tests/bug_gh53-2.phpt @@ -10,12 +10,12 @@ $connection->connect(); $channel = new AMQPChannel($connection); $exchange = new AMQPExchange($channel); -$exchange->setName('exchange' . microtime(true)); +$exchange->setName('exchange' . bin2hex(random_bytes(32))); $exchange->setType(AMQP_EX_TYPE_TOPIC); $exchange->declareExchange(); $queue = new AMQPQueue($channel); -$queue->setName('queue1' . microtime(true)); +$queue->setName('queue1' . bin2hex(random_bytes(32))); $queue->declareQueue(); $queue->bind($exchange->getName(), '#'); From 014a0b995827c20337bb6240b4b3d873d031ee2e Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Mon, 31 Jul 2023 11:07:20 +0200 Subject: [PATCH 028/147] Check coding style and formatting of stub files (#447) --- .github/dependabot.yml | 8 + .github/workflows/test.yaml | 7 +- .gitignore | 1 - composer.json | 15 +- composer.lock | 330 +++++++++++++++++++++++++++ ecs.php | 117 ++++++++++ infra/php/Dockerfile | 4 + infra/tools/functions.php | 44 ++-- infra/tools/pamqp-format | 2 +- infra/tools/pamqp-format-check | 6 + infra/tools/pamqp-stubs-format | 6 + infra/tools/pamqp-stubs-format-check | 12 + stubs/AMQP.php | 18 +- stubs/AMQPBasicProperties.php | 18 +- stubs/AMQPChannel.php | 76 ++---- stubs/AMQPConnection.php | 97 ++------ stubs/AMQPDecimal.php | 14 +- stubs/AMQPEnvelope.php | 5 + stubs/AMQPEnvelopeException.php | 1 + stubs/AMQPExchange.php | 141 +++++------- stubs/AMQPQueue.php | 188 +++++++-------- stubs/AMQPTimestamp.php | 10 +- 22 files changed, 746 insertions(+), 374 deletions(-) create mode 100644 composer.lock create mode 100644 ecs.php create mode 100755 infra/tools/pamqp-format-check create mode 100755 infra/tools/pamqp-stubs-format create mode 100755 infra/tools/pamqp-stubs-format-check diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 1a2f2fc5..3f6eb6b7 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,3 +5,11 @@ updates: schedule: interval: daily open-pull-requests-limit: 30 + + - package-ecosystem: composer + directory: / + schedule: + interval: daily + open-pull-requests-limit: 30 + allow: + - dependency-type: all diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 7c7329b0..501a3555 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -32,7 +32,7 @@ jobs: if: needs.dedup.outputs.should_skip != 'true' steps: - - name: install clang-format + - name: Install clang-format uses: myci-actions/add-deb-repo@11 with: repo: "deb https://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" @@ -44,7 +44,7 @@ jobs: uses: actions/checkout@v3.5.3 - name: Check style - run: clang-format-17 --dry-run --Werror *.c *.h + run: ./infra/tools/pamqp-format-check stubs: name: Check stubs php-${{ matrix.php-version }} @@ -83,6 +83,9 @@ jobs: - name: Validate stubs run: ./infra/tools/pamqp-stubs-validate + - name: Check stub coding style + run: ./infra/tools/pamqp-stubs-format-check + test: name: ${{ matrix.test-php-args == '-m' && 'Memtest' || 'Test' }} php-${{ matrix.php-version }}${{ matrix.php-thread-safe && '-ts' || '-nts' }} librabbitmq-${{ matrix.librabbitmq-version }} # librabbitmq < 0.11 needs older OpenSSL version diff --git a/.gitignore b/.gitignore index 0544517a..a46b16af 100644 --- a/.gitignore +++ b/.gitignore @@ -44,7 +44,6 @@ CMakeLists.txt # CLion .idea/ /vendor/ -/composer.lock /config.h.in~ /configure~ diff --git a/composer.json b/composer.json index d4fd786f..f6f76b2b 100644 --- a/composer.json +++ b/composer.json @@ -18,11 +18,18 @@ } ], "require": { - "php": ">=7.4", - "ext-dom": "*", - "ext-simplexml": "*" + "php": ">=7.4" }, "require-dev": { - "ext-json": "*" + "ext-json": "*", + "ext-dom": "*", + "ext-simplexml": "*", + "symplify/easy-coding-standard": "*", + "slevomat/coding-standard": "^8.13" + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": false + } } } diff --git a/composer.lock b/composer.lock new file mode 100644 index 00000000..fd91135d --- /dev/null +++ b/composer.lock @@ -0,0 +1,330 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "485d9b9a9c05994c0b1c905e172de702", + "packages": [], + "packages-dev": [ + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/composer-installer.git", + "reference": "4be43904336affa5c2f70744a348312336afd0da" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/composer-installer/zipball/4be43904336affa5c2f70744a348312336afd0da", + "reference": "4be43904336affa5c2f70744a348312336afd0da", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" + }, + "require-dev": { + "composer/composer": "*", + "ext-json": "*", + "ext-zip": "*", + "php-parallel-lint/php-parallel-lint": "^1.3.1", + "phpcompatibility/php-compatibility": "^9.0", + "yoast/phpunit-polyfills": "^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/composer-installer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "homepage": "http://www.dealerdirect.com", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcbf", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/composer-installer/issues", + "source": "https://github.com/PHPCSStandards/composer-installer" + }, + "time": "2023-01-05T11:28:13+00:00" + }, + { + "name": "phpstan/phpdoc-parser", + "version": "1.23.0", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpdoc-parser.git", + "reference": "a2b24135c35852b348894320d47b3902a94bc494" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/a2b24135c35852b348894320d47b3902a94bc494", + "reference": "a2b24135c35852b348894320d47b3902a94bc494", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "doctrine/annotations": "^2.0", + "nikic/php-parser": "^4.15", + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^1.5", + "phpstan/phpstan-phpunit": "^1.1", + "phpstan/phpstan-strict-rules": "^1.0", + "phpunit/phpunit": "^9.5", + "symfony/process": "^5.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "PHPStan\\PhpDocParser\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPDoc parser with support for nullable, intersection and generic types", + "support": { + "issues": "https://github.com/phpstan/phpdoc-parser/issues", + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.23.0" + }, + "time": "2023-07-23T22:17:56+00:00" + }, + { + "name": "slevomat/coding-standard", + "version": "8.13.4", + "source": { + "type": "git", + "url": "https://github.com/slevomat/coding-standard.git", + "reference": "4b2af2fb17773656d02fbfb5d18024ebd19fe322" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/4b2af2fb17773656d02fbfb5d18024ebd19fe322", + "reference": "4b2af2fb17773656d02fbfb5d18024ebd19fe322", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7 || ^1.0", + "php": "^7.2 || ^8.0", + "phpstan/phpdoc-parser": "^1.23.0", + "squizlabs/php_codesniffer": "^3.7.1" + }, + "require-dev": { + "phing/phing": "2.17.4", + "php-parallel-lint/php-parallel-lint": "1.3.2", + "phpstan/phpstan": "1.10.26", + "phpstan/phpstan-deprecation-rules": "1.1.3", + "phpstan/phpstan-phpunit": "1.3.13", + "phpstan/phpstan-strict-rules": "1.5.1", + "phpunit/phpunit": "7.5.20|8.5.21|9.6.8|10.2.6" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-master": "8.x-dev" + } + }, + "autoload": { + "psr-4": { + "SlevomatCodingStandard\\": "SlevomatCodingStandard/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", + "keywords": [ + "dev", + "phpcs" + ], + "support": { + "issues": "https://github.com/slevomat/coding-standard/issues", + "source": "https://github.com/slevomat/coding-standard/tree/8.13.4" + }, + "funding": [ + { + "url": "https://github.com/kukulich", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/slevomat/coding-standard", + "type": "tidelift" + } + ], + "time": "2023-07-25T10:28:55+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.7.2", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ed8e00df0a83aa96acf703f8c2979ff33341f879", + "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", + "source": "https://github.com/squizlabs/PHP_CodeSniffer", + "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + }, + "time": "2023-02-22T23:07:41+00:00" + }, + { + "name": "symplify/easy-coding-standard", + "version": "12.0.6", + "source": { + "type": "git", + "url": "https://github.com/easy-coding-standard/easy-coding-standard.git", + "reference": "7372622f5d9126ec50b0923d7eb6b778fac575a5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/7372622f5d9126ec50b0923d7eb6b778fac575a5", + "reference": "7372622f5d9126ec50b0923d7eb6b778fac575a5", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "conflict": { + "friendsofphp/php-cs-fixer": "<3.0", + "squizlabs/php_codesniffer": "<3.6", + "symplify/coding-standard": "<11.3" + }, + "bin": [ + "bin/ecs" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Use Coding Standard with 0-knowledge of PHP-CS-Fixer and PHP_CodeSniffer", + "keywords": [ + "Code style", + "automation", + "fixer", + "static analysis" + ], + "support": { + "issues": "https://github.com/easy-coding-standard/easy-coding-standard/issues", + "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.0.6" + }, + "funding": [ + { + "url": "https://www.paypal.me/rectorphp", + "type": "custom" + }, + { + "url": "https://github.com/tomasvotruba", + "type": "github" + } + ], + "time": "2023-07-25T17:12:00+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=7.4" + }, + "platform-dev": { + "ext-json": "*", + "ext-dom": "*", + "ext-simplexml": "*" + }, + "plugin-api-version": "2.3.0" +} diff --git a/ecs.php b/ecs.php new file mode 100644 index 00000000..701e644a --- /dev/null +++ b/ecs.php @@ -0,0 +1,117 @@ +paths([__DIR__ . '/stubs', __DIR__ . '/infra']); + + // this way you add a single rule + $ecsConfig->rules( + [ + NoUnusedImportsFixer::class, + PhpdocIndentFixer::class, + OrderedImportsFixer::class, + FullyQualifiedStrictTypesFixer::class, + GlobalNamespaceImportFixer::class, + NoLeadingImportSlashFixer::class, + StaticLambdaFixer::class, + ReferenceUsedNamesOnlySniff::class, + ] + ); + + $ecsConfig->rules( + [ + StandaloneLinePromotedPropertyFixer::class, + BlankLineAfterOpeningTagFixer::class, + MethodChainingIndentationFixer::class, + CastSpacesFixer::class, + ClassAttributesSeparationFixer::class, + SingleTraitInsertPerStatementFixer::class, + FunctionTypehintSpaceFixer::class, + NoBlankLinesAfterClassOpeningFixer::class, + NoSinglelineWhitespaceBeforeSemicolonsFixer::class, + PhpdocSingleLineVarSpacingFixer::class, + NoLeadingNamespaceWhitespaceFixer::class, + NoSpacesAroundOffsetFixer::class, + NoWhitespaceInBlankLineFixer::class, + ReturnTypeDeclarationFixer::class, + SpaceAfterSemicolonFixer::class, + TernaryOperatorSpacesFixer::class, + MethodArgumentSpaceFixer::class, + LanguageConstructSpacingSniff::class, + ] + ); + $ecsConfig->ruleWithConfiguration(ClassAttributesSeparationFixer::class, [ + 'elements' => [ + 'const' => 'one', + 'property' => 'one', + 'method' => 'one', + ], + ]); + $ecsConfig->ruleWithConfiguration(ConcatSpaceFixer::class, [ + 'spacing' => 'one', + ]); + $ecsConfig->ruleWithConfiguration(SuperfluousWhitespaceSniff::class, [ + 'ignoreBlankLines' => false, + ]); + $ecsConfig->ruleWithConfiguration(BinaryOperatorSpacesFixer::class, [ + 'operators' => [ + '=>' => 'single_space', + '=' => 'single_space', + ], + ]); + + $ecsConfig->sets([ + SetList::CLEAN_CODE, + SetList::ARRAY, + SetList::DOCBLOCK, + SetList::NAMESPACES, + SetList::COMMENTS, + SetList::CONTROL_STRUCTURES, + SetList::SYMPLIFY, + SetList::PSR_12, + ]); + + $ecsConfig->ruleWithConfiguration(GeneralPhpdocAnnotationRemoveFixer::class, [ + 'annotations' => ['author', 'package', 'category'], + ]); + $ecsConfig->ruleWithConfiguration(PhpdocAlignFixer::class, [ + 'align' => 'left', + ]); +}; \ No newline at end of file diff --git a/infra/php/Dockerfile b/infra/php/Dockerfile index bc8e1ae2..bdcd68f6 100644 --- a/infra/php/Dockerfile +++ b/infra/php/Dockerfile @@ -10,10 +10,14 @@ RUN apt-get install -yqq librabbitmq-dev RUN apt-get install -yqq socat RUN apt-get install -yqq gdb RUN apt-get install -yqq valgrind +RUN apt-get install -yqq git +RUN apt-get install -yqq unzip RUN echo 'PATH=$PATH:/src/infra/tools' >> /etc/bash.bashrc RUN echo 'CFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror"' >> /etc/bash.bashrc +COPY --from=composer /usr/bin/composer /usr/local/bin/composer + CMD PHP_AMQP_DOCKER_ENTRYPOINT=1 php /src/infra/tools/pamqp-docker-setup && \ # Forward localhost:5672 to rabbitmq:5672 (Plain TCP) so that the testsuite can access RabbitMQ on localhost socat tcp-listen:5672,reuseaddr,fork tcp:rabbitmq:5672 diff --git a/infra/tools/functions.php b/infra/tools/functions.php index 3bb039c9..d2eb59d6 100644 --- a/infra/tools/functions.php +++ b/infra/tools/functions.php @@ -1,4 +1,5 @@ ' . VERSION_REGEX . ')"'; function re(string ...$regex): string @@ -139,9 +137,9 @@ function setDate(DateTimeImmutable $now): void $xml->time = $now->format('H:i:s'); } -function addFilesToPackageXml(SimpleXMLElement $dir, string $expression, string $role): void { +function addFilesToPackageXml(SimpleXMLElement $dir, string $expression, string $role): void +{ foreach (glob(BASE_DIR . $expression) as $file) { - $file = str_replace(realpath(BASE_DIR) . '/', '', realpath($file)); if ($file === 'config.h') { @@ -154,7 +152,8 @@ function addFilesToPackageXml(SimpleXMLElement $dir, string $expression, string } } -function removeFromPackageXmlNodes(SimpleXMLElement $el, string $expression): void { +function removeFromPackageXmlNodes(SimpleXMLElement $el, string $expression): void +{ $nodesToDelete = []; foreach ($el->children() as $file) { @@ -170,7 +169,8 @@ function removeFromPackageXmlNodes(SimpleXMLElement $el, string $expression): vo } } -function updateFiles(): void { +function updateFiles(): void +{ $xml = simplexml_import_dom(packageXml()); assert($xml !== null); $sourceExpression = '*.[ch]'; @@ -218,7 +218,7 @@ function setSourceVersion(string $nextVersion): void '{minor}' => $minor, '{patch}' => $patch, '{extra}' => $extra, - '{id}' => $id + '{id}' => $id, ] ) ); @@ -272,7 +272,7 @@ function buildChangelog(string $nextTag, string $previousTag): string $issueId = $matches['issueId']; } - $url = $issueId ? sprintf(ISSUE_URL_TEMPLATE, $issueId): sprintf(COMMIT_URL_TEMPLATE, $commit); + $url = $issueId ? sprintf(ISSUE_URL_TEMPLATE, $issueId) : sprintf(COMMIT_URL_TEMPLATE, $commit); $committer = strpos($committerEmail, '@users.noreply.github.com') !== false ? $committerName : sprintf('%s <%s>', $committerName, $committerEmail); @@ -281,17 +281,18 @@ function buildChangelog(string $nextTag, string $previousTag): string $changes = implode(PHP_EOL, $changeLines); $changelog = <<stability->api = $stability; } -function executeCommand(string $command): string { +function executeCommand(string $command): string +{ exec($command, $output, $returnCode); if ($returnCode !== 0) { @@ -341,23 +343,26 @@ function executeCommand(string $command): string { return implode("\n", $output); } -function validatePackage(): void { +function validatePackage(): void +{ executeCommand('pecl package-validate'); } -function peclPackage(int $step, string $nextVersion): void { +function peclPackage(int $step, string $nextVersion): void +{ executeCommand('pecl package'); $archive = 'amqp-' . $nextVersion . '.tgz'; if (!file_exists(BASE_DIR . $archive)) { - echo "Could find $archive\n"; + echo "Could find {$archive}\n"; exit(1); } printf("%d) Upload %s to PECL\n", $step, $archive); } -function gitCommit(int $step, string $nextVersion, string $message): void { +function gitCommit(int $step, string $nextVersion, string $message): void +{ executeCommand( sprintf('git commit -m "[RM] %s %s" %s %s', $message, $nextVersion, HEADER_VERSION_FILE, PACKAGE_XML) ); @@ -365,7 +370,8 @@ function gitCommit(int $step, string $nextVersion, string $message): void { printf("%d) Run \"git push origin latest\"\n", $step); } -function gitTag(int $step, string $nextVersion): void { +function gitTag(int $step, string $nextVersion): void +{ $nextTag = versionToTag($nextVersion); executeCommand(sprintf("git tag %s -m '[RM] release %s'", $nextTag, $nextVersion)); diff --git a/infra/tools/pamqp-format b/infra/tools/pamqp-format index 265c20a3..04f50cda 100755 --- a/infra/tools/pamqp-format +++ b/infra/tools/pamqp-format @@ -5,4 +5,4 @@ set -o nounset base_dir=`dirname $0`/../../ -clang-format-17 -i $base_dir/*.c $base_dir/*.h \ No newline at end of file +clang-format-17 -i $base_dir/*.c $base_dir/*.h $@ \ No newline at end of file diff --git a/infra/tools/pamqp-format-check b/infra/tools/pamqp-format-check new file mode 100755 index 00000000..3922cf94 --- /dev/null +++ b/infra/tools/pamqp-format-check @@ -0,0 +1,6 @@ +#!/usr/bin/env sh + +set -o errexit +set -o nounset + +$(dirname $0)/pamqp-format --dry-run --Werror \ No newline at end of file diff --git a/infra/tools/pamqp-stubs-format b/infra/tools/pamqp-stubs-format new file mode 100755 index 00000000..adeef1e2 --- /dev/null +++ b/infra/tools/pamqp-stubs-format @@ -0,0 +1,6 @@ +#!/usr/bin/env sh + +set -o errexit +set -o nounset + +$(dirname $0)/pamqp-stubs-format-check --fix \ No newline at end of file diff --git a/infra/tools/pamqp-stubs-format-check b/infra/tools/pamqp-stubs-format-check new file mode 100755 index 00000000..8216996c --- /dev/null +++ b/infra/tools/pamqp-stubs-format-check @@ -0,0 +1,12 @@ +#!/usr/bin/env sh + +set -o errexit +set -o nounset + +base_dir=`dirname $0`/../../ + +if test ! -x $base_dir/vendor/bin/ecs; then + composer --working-dir=$base_dir install +fi + +$base_dir/vendor/bin/ecs --config=$base_dir/ecs.php $@ \ No newline at end of file diff --git a/stubs/AMQP.php b/stubs/AMQP.php index e63a4fcd..463c64d1 100644 --- a/stubs/AMQP.php +++ b/stubs/AMQP.php @@ -112,25 +112,17 @@ */ const AMQP_EX_TYPE_HEADERS = 'headers'; -/** - * - */ + const AMQP_OS_SOCKET_TIMEOUT_ERRNO = 536870947; -/** - * - */ + const PHP_AMQP_MAX_CHANNELS = 256; -/** - * - */ + const AMQP_SASL_METHOD_PLAIN = 0; -/** - * - */ + const AMQP_SASL_METHOD_EXTERNAL = 1; /** @@ -156,7 +148,7 @@ /** * Extension minor version */ -const AMQP_EXTENSION_VERSION_MINOR = 1; +const AMQP_EXTENSION_VERSION_MINOR = 1; /** * Extension patch version diff --git a/stubs/AMQPBasicProperties.php b/stubs/AMQPBasicProperties.php index 259b5da7..a256c161 100644 --- a/stubs/AMQPBasicProperties.php +++ b/stubs/AMQPBasicProperties.php @@ -6,31 +6,41 @@ class AMQPBasicProperties { private ?string $contentType = null; + private ?string $contentEncoding = null; + private array $headers = []; + private int $deliveryMode = AMQP_DELIVERY_MODE_TRANSIENT; + private int $priority = 0; + private ?string $correlationId = null; + private ?string $replyTo = null; + private ?string $expiration = null; + private ?string $messageId = null; + private ?int $timestamp = null; + private ?string $type = null; + private ?string $userId = null; + private ?string $appId = null; + private ?string $clusterId = null; /** * @param ?string $contentType * @param ?string $contentEncoding - * @param array $headers - * @param int $deliveryMode - * @param int $priority * @param ?string $correlationId * @param ?string $replyTo * @param ?string $expiration * @param ?string $messageId - * @param ?int $timestamp + * @param ?int $timestamp * @param ?string $type * @param ?string $userId * @param ?string $appId diff --git a/stubs/AMQPChannel.php b/stubs/AMQPChannel.php index 0413337a..5ce11422 100644 --- a/stubs/AMQPChannel.php +++ b/stubs/AMQPChannel.php @@ -6,36 +6,39 @@ class AMQPChannel { private AMQPConnection $connection; + private ?int $prefetchCount = null; + private ?int $prefetchSize; + private ?int $globalPrefetchCount; + private ?int $globalPrefetchSize; + private array $consumers = []; /** - * Commit a pending transaction. + * Create an instance of an AMQPChannel object. * - * @throws AMQPChannelException If no transaction was started prior to - * calling this method. - * @throws AMQPConnectionException If the connection to the broker was lost. + * @param AMQPConnection $connection An instance of AMQPConnection + * with an active connection to a + * broker. * - * @return void + * @throws AMQPConnectionException If the connection to the broker + * was lost. */ - public function commitTransaction(): void + public function __construct(AMQPConnection $connection) { } /** - * Create an instance of an AMQPChannel object. - * - * @param AMQPConnection $connection An instance of AMQPConnection - * with an active connection to a - * broker. + * Commit a pending transaction. * - * @throws AMQPConnectionException If the connection to the broker - * was lost. + * @throws AMQPChannelException If no transaction was started prior to + * calling this method. + * @throws AMQPConnectionException If the connection to the broker was lost. */ - public function __construct(AMQPConnection $connection) + public function commitTransaction(): void { } @@ -50,8 +53,6 @@ public function isConnected(): bool /** * Closes the channel. - * - * @return void */ public function close(): void { @@ -81,13 +82,11 @@ public function getChannelId(): int * flag set, the client will not do any prefetching of data, regardless of * the QOS settings. * - * @param integer $size The window size, in octets, to prefetch. - * @param integer $count The number of messages to prefetch. - * @param bool $global TRUE for global, FALSE for consumer. FALSE by default. + * @param integer $size The window size, in octets, to prefetch. + * @param integer $count The number of messages to prefetch. + * @param bool $global TRUE for global, FALSE for consumer. FALSE by default. * * @throws AMQPConnectionException If the connection to the broker was lost. - * - * @return void */ public function qos(int $size, int $count, bool $global = false): void { @@ -99,11 +98,9 @@ public function qos(int $size, int $count, bool $global = false): void * Rollback an existing transaction. AMQPChannel::startTransaction() must * be called prior to this. * - * @throws AMQPChannelException If no transaction was started prior to - * calling this method. + * @throws AMQPChannelException If no transaction was started prior to + * calling this method. * @throws AMQPConnectionException If the connection to the broker was lost. - * - * @return void */ public function rollbackTransaction(): void { @@ -118,8 +115,6 @@ public function rollbackTransaction(): void * @param integer $count The number of messages to prefetch. * * @throws AMQPConnectionException If the connection to the broker was lost. - * - * @return void */ public function setPrefetchCount(int $count): void { @@ -147,8 +142,6 @@ public function getPrefetchCount(): int * @param integer $size The window size, in octets, to prefetch. * * @throws AMQPConnectionException If the connection to the broker was lost. - * - * @return void */ public function setPrefetchSize(int $size): void { @@ -172,8 +165,6 @@ public function getPrefetchSize(): int * @param integer $count The number of messages to prefetch. * * @throws AMQPConnectionException If the connection to the broker was lost. - * - * @return void */ public function setGlobalPrefetchCount(int $count): void { @@ -201,8 +192,6 @@ public function getGlobalPrefetchCount(): int * @param integer $size The window size, in octets, to prefetch. * * @throws AMQPConnectionException If the connection to the broker was lost. - * - * @return void */ public function setGlobalPrefetchSize(int $size): void { @@ -224,8 +213,6 @@ public function getGlobalPrefetchSize(): int * AMQPChannel::commitTransaction() or AMQPChannel::rollbackTransaction(). * * @throws AMQPConnectionException If the connection to the broker was lost. - * - * @return void */ public function startTransaction(): void { @@ -233,8 +220,6 @@ public function startTransaction(): void /** * Get the AMQPConnection object in use - * - * @return AMQPConnection */ public function getConnection(): AMQPConnection { @@ -242,9 +227,6 @@ public function getConnection(): AMQPConnection /** * Redeliver unacknowledged messages. - * - * @param bool $requeue - * @return void */ public function basicRecover(bool $requeue = true): void { @@ -252,8 +234,6 @@ public function basicRecover(bool $requeue = true): void /** * Set the channel to use publisher acknowledgements. This can only used on a non-transactional channel. - * - * @return void */ public function confirmSelect(): void { @@ -262,7 +242,6 @@ public function confirmSelect(): void /** * Set callback to process basic.ack and basic.nac AMQP server methods (applicable when channel in confirm mode). * - * * Callback functions with all arguments have the following signature: * * function ack_callback(int $delivery_tag, bool $multiple) : bool; @@ -272,10 +251,6 @@ public function confirmSelect(): void * * Note, basic.nack server method will only be delivered if an internal error occurs in the Erlang process * responsible for a queue (see https://www.rabbitmq.com/confirms.html for details). - * - * @param callable|null $ackCallback - * @param callable|null $nackCallback - * @return void */ public function setConfirmCallback(?callable $ackCallback, callable $nackCallback = null): void { @@ -289,8 +264,6 @@ public function setConfirmCallback(?callable $ackCallback, callable $nackCallbac * @param float $timeout Timeout in seconds. May be fractional. * * @throws AMQPQueueException If timeout occurs. - * - * @return void */ public function waitForConfirm(float $timeout = 0.0): void { @@ -309,9 +282,6 @@ public function waitForConfirm(float $timeout = 0.0): void * string $body) : bool; * * and should return boolean false when wait loop should be canceled. - * - * @param callable|null $returnCallback - * @return void */ public function setReturnCallback(?callable $returnCallback): void { @@ -323,8 +293,6 @@ public function setReturnCallback(?callable $returnCallback): void * @param float $timeout Timeout in seconds. May be fractional. * * @throws AMQPQueueException If timeout occurs. - * - * @return void */ public function waitForBasicReturn(float $timeout = 0.0): void { diff --git a/stubs/AMQPConnection.php b/stubs/AMQPConnection.php index e6fbfbba..d4fd548c 100644 --- a/stubs/AMQPConnection.php +++ b/stubs/AMQPConnection.php @@ -6,22 +6,39 @@ class AMQPConnection { private string $login; + private string $password; + private string $host; + private string $vhost; + private int $port; + private float $readTimeout; + private float $writeTimeout; + private float $connectTimeout; + private float $rpcTimeout; + private int $channelMax; + private int $frameMax; + private int $heartbeat; + private ?string $cacert; + private ?string $key; + private ?string $cert; + private bool $verify = true; + private int $saslMethod = AMQP_SASL_METHOD_PLAIN; + private ?string $connectionName; /** @@ -96,7 +113,6 @@ public function isPersistent(): bool * This method will initiate a connection with the AMQP broker. * * @throws AMQPConnectionException - * @return void */ public function connect(): void { @@ -108,7 +124,6 @@ public function connect(): void * This method will close an open connection with the AMQP broker. * * @throws AMQPConnectionException When attempting to disconnect a persistent connection - * @return void */ public function disconnect(): void { @@ -118,7 +133,6 @@ public function disconnect(): void * Close any open transient connections and initiate a new one with the AMQP broker. * * @throws AMQPConnectionException - * @return void */ public function reconnect(): void { @@ -131,7 +145,6 @@ public function reconnect(): void * or reuse an existing one if present. * * @throws AMQPConnectionException - * @return void */ public function pconnect(): void { @@ -144,7 +157,6 @@ public function pconnect(): void * broker. * * @throws AMQPConnectionException When attempting to disconnect a transient connection - * @return void */ public function pdisconnect(): void { @@ -154,7 +166,6 @@ public function pdisconnect(): void * Close any open persistent connections and initiate a new one with the AMQP broker. * * @throws AMQPConnectionException - * @return void */ public function preconnect(): void { @@ -205,15 +216,12 @@ public function getVhost(): string { } - /** * Set the hostname used to connect to the AMQP broker. * * @param string $host The hostname of the AMQP broker. * * @throws AMQPConnectionException If host is longer then 1024 characters. - * - * @return void */ public function setHost(string $host): void { @@ -226,8 +234,6 @@ public function setHost(string $host): void * with the AMQP broker. * * @throws AMQPConnectionException If login is longer then 32 characters. - * - * @return void */ public function setLogin(string $login): void { @@ -240,8 +246,6 @@ public function setLogin(string $login): void * with the AMQP broker. * * @throws AMQPConnectionException If password is longer then 32characters. - * - * @return void */ public function setPassword(string $password): void { @@ -254,8 +258,6 @@ public function setPassword(string $password): void * * @throws AMQPConnectionException If port is longer not between * 1 and 65535. - * - * @return void */ public function setPort(int $port): void { @@ -268,8 +270,6 @@ public function setPort(int $port): void * broker. * * @throws AMQPConnectionException If host is longer then 32 characters. - * - * @return void */ public function setVhost(string $vhost): void { @@ -280,11 +280,7 @@ public function setVhost(string $vhost): void * * @deprecated use AMQPConnection::setReadTimeout($timeout) instead * - * @param float $timeout - * * @throws AMQPConnectionException If timeout is less than 0. - * - * @return void */ public function setTimeout(float $timeout): void { @@ -295,8 +291,6 @@ public function setTimeout(float $timeout): void * from AMQP broker * * @deprecated use AMQPConnection::getReadTimeout() instead - * - * @return float */ public function getTimeout(): float { @@ -305,11 +299,7 @@ public function getTimeout(): float /** * Sets the interval of time (in seconds) to wait for income activity from AMQP broker * - * @param float $timeout - * * @throws AMQPConnectionException If timeout is less than 0. - * - * @return void */ public function setReadTimeout(float $timeout): void { @@ -318,8 +308,6 @@ public function setReadTimeout(float $timeout): void /** * Get the configured interval of time (in seconds) to wait for income activity * from AMQP broker - * - * @return float */ public function getReadTimeout(): float { @@ -328,11 +316,7 @@ public function getReadTimeout(): float /** * Sets the interval of time (in seconds) to wait for outcome activity to AMQP broker * - * @param float $timeout - * * @throws AMQPConnectionException If timeout is less than 0. - * - * @return void */ public function setWriteTimeout(float $timeout): void { @@ -341,8 +325,6 @@ public function setWriteTimeout(float $timeout): void /** * Get the configured interval of time (in seconds) to wait for outcome activity * to AMQP broker - * - * @return float */ public function getWriteTimeout(): float { @@ -350,8 +332,6 @@ public function getWriteTimeout(): float /** * Get the configured timeout (in seconds) for connecting to the AMQP broker - * - * @return float */ public function getConnectTimeout(): float { @@ -360,11 +340,7 @@ public function getConnectTimeout(): float /** * Sets the interval of time to wait (in seconds) for RPC activity to AMQP broker * - * @param float $timeout - * * @throws AMQPConnectionException If timeout is less than 0. - * - * @return void */ public function setRpcTimeout(float $timeout): void { @@ -373,8 +349,6 @@ public function setRpcTimeout(float $timeout): void /** * Get the configured interval of time (in seconds) to wait for RPC activity * to AMQP broker - * - * @return float */ public function getRpcTimeout(): float { @@ -382,8 +356,6 @@ public function getRpcTimeout(): float /** * Return last used channel id during current connection session. - * - * @return int */ public function getUsedChannels(): int { @@ -394,8 +366,6 @@ public function getUsedChannels(): int * * When connection is connected, effective connection value returned, which is normally the same as original * correspondent value passed to constructor, otherwise original value passed to constructor returned. - * - * @return int */ public function getMaxChannels(): int { @@ -406,8 +376,6 @@ public function getMaxChannels(): int * * When connection is connected, effective connection value returned, which is normally the same as original * correspondent value passed to constructor, otherwise original value passed to constructor returned. - * - * @return int */ public function getMaxFrameSize(): int { @@ -418,8 +386,6 @@ public function getMaxFrameSize(): int * * When connection is connected, effective connection value returned, which is normally the same as original * correspondent value passed to constructor, otherwise original value passed to constructor returned. - * - * @return int */ public function getHeartbeatInterval(): int { @@ -427,8 +393,6 @@ public function getHeartbeatInterval(): int /** * Get path to the CA cert file in PEM format - * - * @return string|null */ public function getCACert(): ?string { @@ -436,9 +400,6 @@ public function getCACert(): ?string /** * Set path to the CA cert file in PEM format - * - * @param string|null $cacert - * @return void */ public function setCACert(?string $cacert): void { @@ -446,8 +407,6 @@ public function setCACert(?string $cacert): void /** * Get path to the client certificate in PEM format - * - * @return string|null */ public function getCert(): ?string { @@ -457,7 +416,6 @@ public function getCert(): ?string * Set path to the client certificate in PEM format * * @param string $cert - * @return void */ public function setCert(?string $cert): void { @@ -465,8 +423,6 @@ public function setCert(?string $cert): void /** * Get path to the client key in PEM format - * - * @return string|null */ public function getKey(): ?string { @@ -474,9 +430,6 @@ public function getKey(): ?string /** * Set path to the client key in PEM format - * - * @param string|null $key - * @return void */ public function setKey(?string $key): void { @@ -484,8 +437,6 @@ public function setKey(?string $key): void /** * Get whether peer verification enabled or disabled - * - * @return bool */ public function getVerify(): bool { @@ -493,9 +444,6 @@ public function getVerify(): bool /** * Enable or disable peer verification - * - * @param bool $verify - * @return void */ public function setVerify(bool $verify): void { @@ -505,30 +453,19 @@ public function setVerify(bool $verify): void * set authentication method * * @param int $saslMethod AMQP_SASL_METHOD_PLAIN | AMQP_SASL_METHOD_EXTERNAL - * @return void */ public function setSaslMethod(int $saslMethod): void { } - /** - * @return int - */ public function getSaslMethod(): int { } - /** - * @param string|null $connectionName - * @return void - */ public function setConnectionName(?string $connectionName): void { } - /** - * @return string|null - */ public function getConnectionName(): ?string { } diff --git a/stubs/AMQPDecimal.php b/stubs/AMQPDecimal.php index e82ffdaa..b84a7a26 100644 --- a/stubs/AMQPDecimal.php +++ b/stubs/AMQPDecimal.php @@ -8,42 +8,38 @@ final class AMQPDecimal /** * @var int */ - const EXPONENT_MIN = 0; + public const EXPONENT_MIN = 0; /** * @var int */ - const EXPONENT_MAX = 255; + public const EXPONENT_MAX = 255; /** * @var int */ - const SIGNIFICAND_MIN = 0; + public const SIGNIFICAND_MIN = 0; /** * @var int */ - const SIGNIFICAND_MAX = 4294967295; + public const SIGNIFICAND_MAX = 4294967295; private int $exponent; + private int $significand; /** - * @param int $exponent - * @param int $significand - * * @throws AMQPValueException */ public function __construct(int $exponent, int $significand) { } - /** @return int */ public function getExponent(): int { } - /** @return int */ public function getSignificand(): int { } diff --git a/stubs/AMQPEnvelope.php b/stubs/AMQPEnvelope.php index 2793fa94..76581c46 100644 --- a/stubs/AMQPEnvelope.php +++ b/stubs/AMQPEnvelope.php @@ -6,10 +6,15 @@ class AMQPEnvelope extends AMQPBasicProperties { private string $body = ''; + private ?string $consumerTag = null; + private ?int $deliveryTag = null; + private bool $isRedelivery = false; + private ?string $exchangeName = null; + private string $routingKey = ''; public function __construct() diff --git a/stubs/AMQPEnvelopeException.php b/stubs/AMQPEnvelopeException.php index 91959bad..fb77bbca 100644 --- a/stubs/AMQPEnvelopeException.php +++ b/stubs/AMQPEnvelopeException.php @@ -6,6 +6,7 @@ class AMQPEnvelopeException extends AMQPException { private AMQPEnvelope $envelope; + public function getEnvelope(): AMQPEnvelope { } diff --git a/stubs/AMQPExchange.php b/stubs/AMQPExchange.php index b8741cf8..d936bd52 100644 --- a/stubs/AMQPExchange.php +++ b/stubs/AMQPExchange.php @@ -6,77 +6,81 @@ class AMQPExchange { private AMQPConnection $connection; + private AMQPChannel $channel; + private ?string $name = null; + private ?string $type = null; + private bool $passive = false; + private bool $durable = false; + private bool $autoDelete = false; + private bool $internal = false; + private array $arguments = []; /** - * Bind to another exchange. + * Create an instance of AMQPExchange. * - * Bind an exchange to another exchange using the specified routing key. + * Returns a new instance of an AMQPExchange object, associated with the + * given AMQPChannel object. * - * @param string $exchangeName Name of the exchange to bind. - * @param string|null $routingKey The routing key to use for binding. - * @param array $arguments Additional binding arguments. + * @param AMQPChannel $channel A valid AMQPChannel object, connected + * to a broker. * - * @return void - *@throws AMQPChannelException If the channel is not open. - * @throws AMQPConnectionException If the connection to the broker was lost. - * @throws AMQPExchangeException On failure. + * @throws AMQPExchangeException When amqp_channel is not connected to + * a broker. + * @throws AMQPConnectionException If the connection to the broker was + * lost. */ - public function bind(string $exchangeName, ?string $routingKey = null, array $arguments = array()): void + public function __construct(AMQPChannel $channel) { } /** - * Remove binding to another exchange. + * Bind to another exchange. * - * Remove a routing key binding on an another exchange from the given exchange. + * Bind an exchange to another exchange using the specified routing key. * * @param string $exchangeName Name of the exchange to bind. - * @param string|null $routingKey The routing key to use for binding. - * @param array $arguments Additional binding arguments. + * @param string|null $routingKey The routing key to use for binding. + * @param array $arguments Additional binding arguments. * - * @return void - *@throws AMQPChannelException If the channel is not open. + * @throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. - * @throws AMQPExchangeException On failure. + * @throws AMQPExchangeException On failure. */ - public function unbind(string $exchangeName, ?string $routingKey = null, array $arguments = array()): void + public function bind(string $exchangeName, ?string $routingKey = null, array $arguments = []): void { } /** - * Create an instance of AMQPExchange. + * Remove binding to another exchange. * - * Returns a new instance of an AMQPExchange object, associated with the - * given AMQPChannel object. + * Remove a routing key binding on an another exchange from the given exchange. * - * @param AMQPChannel $channel A valid AMQPChannel object, connected - * to a broker. + * @param string $exchangeName Name of the exchange to bind. + * @param string|null $routingKey The routing key to use for binding. + * @param array $arguments Additional binding arguments. * - * @throws AMQPExchangeException When amqp_channel is not connected to - * a broker. - * @throws AMQPConnectionException If the connection to the broker was - * lost. + * @throws AMQPChannelException If the channel is not open. + * @throws AMQPConnectionException If the connection to the broker was lost. + * @throws AMQPExchangeException On failure. */ - public function __construct(AMQPChannel $channel) + public function unbind(string $exchangeName, ?string $routingKey = null, array $arguments = []): void { } /** * Declare a new exchange on the broker. * - * @throws AMQPExchangeException On failure. - * @throws AMQPChannelException If the channel is not open. + * @throws AMQPExchangeException On failure. + * @throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. - * - * @return void */ public function declareExchange(): void { @@ -85,11 +89,9 @@ public function declareExchange(): void /** * Declare a new exchange on the broker. * - * @throws AMQPExchangeException On failure. - * @throws AMQPChannelException If the channel is not open. + * @throws AMQPExchangeException On failure. + * @throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. - * - * @return void */ public function declare(): void { @@ -98,18 +100,16 @@ public function declare(): void /** * Delete the exchange from the broker. * - * @param string $exchangeName Optional name of exchange to delete. If not specified it uses the name of the - * exchange object - * @param integer $flags Optionally AMQP_IFUNUSED can be specified - * to indicate the exchange should not be - * deleted until no clients are connected to - * it. + * @param string $exchangeName Optional name of exchange to delete. If not specified it uses the name of the + * exchange object + * @param integer $flags Optionally AMQP_IFUNUSED can be specified + * to indicate the exchange should not be + * deleted until no clients are connected to + * it. * - * @throws AMQPExchangeException On failure. - * @throws AMQPChannelException If the channel is not open. + * @throws AMQPExchangeException On failure. + * @throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. - * - * @return void */ public function delete(?string $exchangeName = null, int $flags = AMQP_NOPARAM): void { @@ -138,6 +138,7 @@ public function getArgument(string $argumentName) public function hasArgument(string $argumentName): bool { } + /** * Get all arguments set on the given exchange. * @@ -180,36 +181,32 @@ public function getType(): ?string * * Publish a message to the exchange represented by the AMQPExchange object. * - * @param string $message The message to publish. - * @param string|null $routingKey The optional routing key to which to - * publish to. - * @param integer $flags One or more of AMQP_MANDATORY and - * AMQP_IMMEDIATE. - * @param array $headers One of content_type, content_encoding, - * message_id, user_id, app_id, delivery_mode, - * priority, timestamp, expiration, type - * or reply_to, headers. - * @throws AMQPChannelException If the channel is not open. + * @param string $message The message to publish. + * @param string|null $routingKey The optional routing key to which to + * publish to. + * @param integer $flags One or more of AMQP_MANDATORY and + * AMQP_IMMEDIATE. + * @param array $headers One of content_type, content_encoding, + * message_id, user_id, app_id, delivery_mode, + * priority, timestamp, expiration, type + * or reply_to, headers. + * @throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. - * @throws AMQPExchangeException On failure. - * @return void + * @throws AMQPExchangeException On failure. */ public function publish( string $message, ?string $routingKey = null, int $flags = AMQP_NOPARAM, array $headers = [] - ): void - { + ): void { } /** * Set the value for the given key. * - * @param string $argumentName Name of the argument to set. + * @param string $argumentName Name of the argument to set. * @param string|integer $argumentValue Value of the argument to set. - * - * @return void */ public function setArgument(string $argumentName, $argumentValue): void { @@ -219,8 +216,6 @@ public function setArgument(string $argumentName, $argumentValue): void * Set all arguments on the exchange. * * @param array $arguments An array of key/value pairs of arguments. - * - * @return void */ public function setArguments(array $arguments): void { @@ -230,11 +225,9 @@ public function setArguments(array $arguments): void * Set the flags on an exchange. * * @param integer $flags A bitmask of flags. This call currently only - * considers the following flags: - * AMQP_DURABLE, AMQP_PASSIVE - * (and AMQP_DURABLE, if librabbitmq version >= 0.5.3) - * - * @return void + * considers the following flags: + * AMQP_DURABLE, AMQP_PASSIVE + * (and AMQP_DURABLE, if librabbitmq version >= 0.5.3) */ public function setFlags(?int $flags): void { @@ -244,8 +237,6 @@ public function setFlags(?int $flags): void * Set the name of the exchange. * * @param string|null $exchangeName The name of the exchange to set as string. - * - * @return void */ public function setName(?string $exchangeName): void { @@ -258,8 +249,6 @@ public function setName(?string $exchangeName): void * AMQP_EX_TYPE_FANOUT, AMQP_EX_TYPE_HEADERS or AMQP_EX_TYPE_TOPIC. * * @param string|null $exchangeType The type of exchange as a string. - * - * @return void */ public function setType(?string $exchangeType): void { @@ -267,8 +256,6 @@ public function setType(?string $exchangeType): void /** * Get the AMQPChannel object in use - * - * @return AMQPChannel */ public function getChannel(): AMQPChannel { @@ -276,8 +263,6 @@ public function getChannel(): AMQPChannel /** * Get the AMQPConnection object in use - * - * @return AMQPConnection */ public function getConnection(): AMQPConnection { diff --git a/stubs/AMQPQueue.php b/stubs/AMQPQueue.php index 1b9aafab..1ea3ba33 100644 --- a/stubs/AMQPQueue.php +++ b/stubs/AMQPQueue.php @@ -6,13 +6,21 @@ class AMQPQueue { private AMQPConnection $connection; + private AMQPChannel$channel; + private ?string $name = null; + private ?string $consumerTag = null; + private bool $passive = false; + private bool $durable = false; + private bool $exclusive = false; + private bool $autoDelete = true; + private array $arguments = []; /** @@ -20,8 +28,8 @@ class AMQPQueue * * @param AMQPChannel $channel The amqp channel to use. * - * @throws AMQPQueueException When amqp_channel is not connected to a - * broker. + * @throws AMQPQueueException When amqp_channel is not connected to a + * broker. * @throws AMQPConnectionException If the connection to the broker was lost. */ public function __construct(AMQPChannel $channel) @@ -36,12 +44,11 @@ public function __construct(AMQPChannel $channel) * AMQPQueue::consume() * * @param integer $deliveryTag The message delivery tag of which to - * acknowledge receipt. - * @param integer $flags The only valid flag that can be passed is - * AMQP_MULTIPLE. + * acknowledge receipt. + * @param integer $flags The only valid flag that can be passed is + * AMQP_MULTIPLE. * @throws AMQPConnectionException If the connection to the broker was lost. - * @throws AMQPChannelException If the channel is not open. - * @return void + * @throws AMQPChannelException If the channel is not open. */ public function ack(int $deliveryTag, int $flags = AMQP_NOPARAM): void { @@ -51,13 +58,12 @@ public function ack(int $deliveryTag, int $flags = AMQP_NOPARAM): void * Bind the given queue to a routing key on an exchange. * * @param string $exchangeName Name of the exchange to bind to. - * @param string $routingKey Pattern or routing key to bind with. - * @param array $arguments Additional binding arguments. + * @param string $routingKey Pattern or routing key to bind with. + * @param array $arguments Additional binding arguments. * @throws AMQPConnectionException If the connection to the broker was lost. - * @throws AMQPChannelException If the channel is not open. - * @return void + * @throws AMQPChannelException If the channel is not open. */ - public function bind(string $exchangeName, ?string $routingKey = null, array $arguments = array()): void + public function bind(string $exchangeName, ?string $routingKey = null, array $arguments = []): void { } @@ -65,19 +71,18 @@ public function bind(string $exchangeName, ?string $routingKey = null, array $ar * Cancel a queue that is already bound to an exchange and routing key. * * @param string $consumerTag The consumer tag to cancel. If no tag is provided, - * or it is empty string, the latest consumer - * tag on this queue will be taken and after - * the successful cancellation request it will set to null. - * If the consumer_tag parameter is empty and the latest - * consumer tag is empty, no `basic.cancel` request will be - * sent. - * If either the consumer tag passed matches the latest tag - * or no consumer tag was passed and the latest tag was used - * the internal consumer tag will be set to null, so that - * `AMQPQueue::getConsumerTag()` will return null afterwards. + * or it is empty string, the latest consumer + * tag on this queue will be taken and after + * the successful cancellation request it will set to null. + * If the consumer_tag parameter is empty and the latest + * consumer tag is empty, no `basic.cancel` request will be + * sent. + * If either the consumer tag passed matches the latest tag + * or no consumer tag was passed and the latest tag was used + * the internal consumer tag will be set to null, so that + * `AMQPQueue::getConsumerTag()` will return null afterwards. * @throws AMQPConnectionException If the connection to the broker was lost. - * @throws AMQPChannelException If the channel is not open. - * @return void + * @throws AMQPChannelException If the channel is not open. */ public function cancel(string $consumerTag = ''): void { @@ -89,38 +94,36 @@ public function cancel(string $consumerTag = ''): void * Blocking function that will retrieve the next message from the queue as * it becomes available and will pass it off to the callback. * - * @param callable|null $callback A callback function to which the - * consumed message will be passed. The - * function must accept at a minimum - * one parameter, an AMQPEnvelope object, - * and an optional second parameter - * the AMQPQueue object from which callback - * was invoked. The AMQPQueue::consume() will - * not return the processing thread back to - * the PHP script until the callback - * function returns FALSE. - * If the callback is omitted or null is passed, - * then the messages delivered to this client will - * be made available to the first real callback - * registered. That allows one to have a single - * callback consuming from multiple queues. - * @param integer $flags A bitmask of any of the flags: AMQP_AUTOACK, - * AMQP_JUST_CONSUME. Note: when AMQP_JUST_CONSUME - * flag used all other flags are ignored and - * $consumerTag parameter has no sense. - * AMQP_JUST_CONSUME flag prevent from sending - * `basic.consume` request and just run $callback - * if it provided. Calling method with empty $callback - * and AMQP_JUST_CONSUME makes no sense. - * @param string|null $consumerTag A string describing this consumer. Used - * for canceling subscriptions with cancel(). - * - * @throws AMQPChannelException If the channel is not open. + * @param callable|null $callback A callback function to which the + * consumed message will be passed. The + * function must accept at a minimum + * one parameter, an AMQPEnvelope object, + * and an optional second parameter + * the AMQPQueue object from which callback + * was invoked. The AMQPQueue::consume() will + * not return the processing thread back to + * the PHP script until the callback + * function returns FALSE. + * If the callback is omitted or null is passed, + * then the messages delivered to this client will + * be made available to the first real callback + * registered. That allows one to have a single + * callback consuming from multiple queues. + * @param integer $flags A bitmask of any of the flags: AMQP_AUTOACK, + * AMQP_JUST_CONSUME. Note: when AMQP_JUST_CONSUME + * flag used all other flags are ignored and + * $consumerTag parameter has no sense. + * AMQP_JUST_CONSUME flag prevent from sending + * `basic.consume` request and just run $callback + * if it provided. Calling method with empty $callback + * and AMQP_JUST_CONSUME makes no sense. + * @param string|null $consumerTag A string describing this consumer. Used + * for canceling subscriptions with cancel(). + * + * @throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. - * @throws AMQPEnvelopeException When no queue found for envelope. - * @throws AMQPQueueException If timeout occurs or queue is not exists. - * - * @return void + * @throws AMQPEnvelopeException When no queue found for envelope. + * @throws AMQPQueueException If timeout occurs or queue is not exists. */ public function consume( callable $callback = null, @@ -132,9 +135,9 @@ public function consume( /** * Declare a new queue on the broker. * - * @throws AMQPChannelException If the channel is not open. + * @throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. - * @throws AMQPQueueException On failure. + * @throws AMQPQueueException On failure. * * @return integer the message count. */ @@ -145,9 +148,9 @@ public function declareQueue(): int /** * Declare a new queue on the broker. * - * @throws AMQPChannelException If the channel is not open. + * @throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. - * @throws AMQPQueueException On failure. + * @throws AMQPQueueException On failure. * * @return integer the message count. */ @@ -160,12 +163,12 @@ public function declare(): int * * This includes its entire contents of unread or unacknowledged messages. * - * @param integer $flags Optionally AMQP_IFUNUSED can be specified - * to indicate the queue should not be - * deleted until no clients are connected to - * it. + * @param integer $flags Optionally AMQP_IFUNUSED can be specified + * to indicate the queue should not be + * deleted until no clients are connected to + * it. * - * @throws AMQPChannelException If the channel is not open. + * @throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. * * @return integer The number of deleted messages. @@ -191,11 +194,9 @@ public function delete(int $flags = AMQP_NOPARAM): int * value is not provided, it will use the * value of ini-setting amqp.auto_ack. * - * @throws AMQPChannelException If the channel is not open. + * @throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. - * @throws AMQPQueueException If queue is not exist. - * - * @return AMQPEnvelope|null + * @throws AMQPQueueException If queue is not exist. */ public function get(int $flags = AMQP_NOPARAM): ?AMQPEnvelope { @@ -207,8 +208,8 @@ public function get(int $flags = AMQP_NOPARAM): ?AMQPEnvelope * @param string $argumentName The key to look up. * * @return string|integer|null The string or integer value associated - * with the given key, or false if the key - * is not set. + * with the given key, or false if the key + * is not set. */ public function getArgument(string $argumentName) { @@ -256,12 +257,11 @@ public function getName(): ?string * undefined. * * @param integer $deliveryTag Delivery tag of last message to reject. - * @param integer $flags AMQP_REQUEUE to requeue the message(s), - * AMQP_MULTIPLE to nack all previous - * unacked messages as well. + * @param integer $flags AMQP_REQUEUE to requeue the message(s), + * AMQP_MULTIPLE to nack all previous + * unacked messages as well. * @throws AMQPConnectionException If the connection to the broker was lost. - * @throws AMQPChannelException If the channel is not open. - * @return void + * @throws AMQPChannelException If the channel is not open. */ public function nack(int $deliveryTag, int $flags = AMQP_NOPARAM): void { @@ -277,10 +277,9 @@ public function nack(int $deliveryTag, int $flags = AMQP_NOPARAM): void * flag are not eligible. * * @param integer $deliveryTag Delivery tag of the message to reject. - * @param integer $flags AMQP_REQUEUE to requeue the message(s). + * @param integer $flags AMQP_REQUEUE to requeue the message(s). * @throws AMQPConnectionException If the connection to the broker was lost. - * @throws AMQPChannelException If the channel is not open. - * @return void + * @throws AMQPChannelException If the channel is not open. */ public function reject(int $deliveryTag, int $flags = AMQP_NOPARAM): void { @@ -291,10 +290,8 @@ public function reject(int $deliveryTag, int $flags = AMQP_NOPARAM): void * * Returns the number of purged messages * - * @throws AMQPChannelException If the channel is not open. + * @throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. - * - * @return int */ public function purge(): int { @@ -303,10 +300,8 @@ public function purge(): int /** * Set a queue argument. * - * @param string $argumentName The key to set. - * @param mixed $argumentValue The value to set. - * - * @return void + * @param string $argumentName The key to set. + * @param mixed $argumentValue The value to set. */ public function setArgument(string $argumentName, $argumentValue): void { @@ -318,8 +313,6 @@ public function setArgument(string $argumentName, $argumentValue): void * All other argument settings will be wiped. * * @param array $arguments An array of key/value pairs of arguments. - * - * @return void */ public function setArguments(array $arguments): void { @@ -328,7 +321,7 @@ public function setArguments(array $arguments): void /** * Check whether a queue has specific argument. * - * @param string $argumentName The key to check. + * @param string $argumentName The key to check. * * @return boolean */ @@ -342,8 +335,6 @@ public function hasArgument(string $argumentName): bool * @param integer $flags A bitmask of flags: * AMQP_DURABLE, AMQP_PASSIVE, * AMQP_EXCLUSIVE, AMQP_AUTODELETE. - * - * @return void */ public function setFlags(int $flags): void { @@ -353,8 +344,6 @@ public function setFlags(int $flags): void * Set the queue name. * * @param string $name The name of the queue. - * - * @return void */ public function setName(string $name): void { @@ -364,20 +353,17 @@ public function setName(string $name): void * Remove a routing key binding on an exchange from the given queue. * * @param string $exchangeName The name of the exchange on which the queue is bound. - * @param string $routingKey The binding routing key used by the - * @param array $arguments Additional binding arguments. + * @param string $routingKey The binding routing key used by the + * @param array $arguments Additional binding arguments. * @throws AMQPConnectionException If the connection to the broker was lost. - * @throws AMQPChannelException If the channel is not open. - * @return void + * @throws AMQPChannelException If the channel is not open. */ - public function unbind(string $exchangeName, ?string $routingKey = null, array $arguments = array()): void + public function unbind(string $exchangeName, ?string $routingKey = null, array $arguments = []): void { } /** * Get the AMQPChannel object in use - * - * @return AMQPChannel */ public function getChannel(): AMQPChannel { @@ -385,8 +371,6 @@ public function getChannel(): AMQPChannel /** * Get the AMQPConnection object in use - * - * @return AMQPConnection */ public function getConnection(): AMQPConnection { @@ -394,8 +378,6 @@ public function getConnection(): AMQPConnection /** * Get latest consumer tag. If no consumer available or the latest on was canceled null will be returned. - * - * @return string|null */ public function getConsumerTag(): ?string { diff --git a/stubs/AMQPTimestamp.php b/stubs/AMQPTimestamp.php index 2ceb569e..5b19fbd6 100644 --- a/stubs/AMQPTimestamp.php +++ b/stubs/AMQPTimestamp.php @@ -8,29 +8,27 @@ final class AMQPTimestamp /** * @var float */ - const MIN = 0.0; + public const MIN = 0.0; /** * @var float */ - const MAX = 18446744073709551616; + public const MAX = 18446744073709551616; private float $timestamp; /** - * @param float $timestamp - * * @throws AMQPValueException */ public function __construct(float $timestamp) { } - public function getTimestamp(): float + public function __toString(): string { } - public function __toString(): string + public function getTimestamp(): float { } } From 1928a395bb5c585131570716a3139c1145a3698b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 31 Jul 2023 12:44:02 +0200 Subject: [PATCH 029/147] Bump shivammathur/setup-php from 2.25.4 to 2.25.5 (#449) --- .github/workflows/test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 501a3555..6b9f30d5 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -65,7 +65,7 @@ jobs: run: sudo apt-get install -y cmake valgrind - name: Setup PHP - uses: shivammathur/setup-php@2.25.4 + uses: shivammathur/setup-php@2.25.5 with: php-version: ${{ matrix.php-version }} extensions: json @@ -130,7 +130,7 @@ jobs: run: sudo apt-get install -y cmake valgrind - name: Setup PHP - uses: shivammathur/setup-php@2.25.4 + uses: shivammathur/setup-php@2.25.5 with: php-version: ${{ matrix.php-version }} coverage: none From 59968afd9e400227fae1970d245ad90fc9c524da Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Mon, 31 Jul 2023 12:44:13 +0200 Subject: [PATCH 030/147] Skip SSL tests if certificates are missing (#450) --- .env | 5 ++++- .github/workflows/test.yaml | 1 + infra/php/Dockerfile | 1 - infra/tools/pamqp-build | 2 +- tests/amqpconnection_tls_basic.phpt | 5 ++++- tests/amqpconnection_tls_mtls.phpt | 7 ++++++- tests/amqpconnection_tls_sasl.phpt | 7 ++++++- 7 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.env b/.env index f9610f54..7f5e3ad6 100644 --- a/.env +++ b/.env @@ -1 +1,4 @@ -PHP_AMQP_SSL_HOST=rabbitmq.example.org \ No newline at end of file +PHP_AMQP_SSL_HOST=rabbitmq.example.org +MAKEFLAGS="-j16" +CFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror" +TEST_PHP_ARGS="-j16" diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 6b9f30d5..255882c8 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -9,6 +9,7 @@ env: TEST_TIMEOUT: 120 CFLAGS: -D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror PHP_AMQP_SSL_HOST: rabbitmq.example.org + MAKEFLAGS: -j4 jobs: dedup: diff --git a/infra/php/Dockerfile b/infra/php/Dockerfile index bdcd68f6..603382c8 100644 --- a/infra/php/Dockerfile +++ b/infra/php/Dockerfile @@ -14,7 +14,6 @@ RUN apt-get install -yqq git RUN apt-get install -yqq unzip RUN echo 'PATH=$PATH:/src/infra/tools' >> /etc/bash.bashrc -RUN echo 'CFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror"' >> /etc/bash.bashrc COPY --from=composer /usr/bin/composer /usr/local/bin/composer diff --git a/infra/tools/pamqp-build b/infra/tools/pamqp-build index 538053eb..6a67e2ff 100755 --- a/infra/tools/pamqp-build +++ b/infra/tools/pamqp-build @@ -20,4 +20,4 @@ if test "$mode" = "clean"; then make clean fi -make \ No newline at end of file +make diff --git a/tests/amqpconnection_tls_basic.phpt b/tests/amqpconnection_tls_basic.phpt index 8676f4ca..e831e9be 100644 --- a/tests/amqpconnection_tls_basic.phpt +++ b/tests/amqpconnection_tls_basic.phpt @@ -1,7 +1,10 @@ --TEST-- AMQPConnection - TLS - CA validation only --SKIPIF-- - + --FILE-- + --FILE-- + --FILE-- Date: Mon, 31 Jul 2023 19:21:47 +0200 Subject: [PATCH 031/147] Fix mangled header on MacOS --- amqp_type.c | 5 +++-- .../amqpexchange_publish_with_properties_nested_header.phpt | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/amqp_type.c b/amqp_type.c index 81cda00e..743fc470 100644 --- a/amqp_type.c +++ b/amqp_type.c @@ -132,7 +132,7 @@ void php_amqp_type_internal_convert_zval_to_amqp_table( /* Convert to strings non-string keys */ char str[32]; - key_len = sprintf(str, "%lu", index); + key_len = snprintf(str, 32, "%lu", index); key = str; } else { /* Skip things that are not strings */ @@ -145,6 +145,8 @@ void php_amqp_type_internal_convert_zval_to_amqp_table( key = ZSTR_VAL(zkey); } + string_key = estrndup(key, key_len); + /* Build the value */ table_entry = &amqp_table->entries[amqp_table->num_entries++]; field = &table_entry->value; @@ -156,7 +158,6 @@ void php_amqp_type_internal_convert_zval_to_amqp_table( continue; } - string_key = estrndup(key, key_len); table_entry->key = amqp_cstring_bytes(string_key); ZEND_HASH_FOREACH_END(); } diff --git a/tests/amqpexchange_publish_with_properties_nested_header.phpt b/tests/amqpexchange_publish_with_properties_nested_header.phpt index 6c3831e1..84d5f6d0 100644 --- a/tests/amqpexchange_publish_with_properties_nested_header.phpt +++ b/tests/amqpexchange_publish_with_properties_nested_header.phpt @@ -34,7 +34,7 @@ $headers = array( $ex->publish('message', 'routing.key', AMQP_NOPARAM, array('headers' => $headers)); -$message =$q->get(AMQP_AUTOACK); +$message = $q->get(AMQP_AUTOACK); var_dump($message->getHeaders()); var_dump($headers); echo $message->getHeaders() === $headers ? 'same' : 'differs'; @@ -55,7 +55,7 @@ $headers = array( $ex->publish('message', 'routing.key', AMQP_NOPARAM, array('headers' => $headers)); -$message =$q->get(AMQP_AUTOACK); +$message = $q->get(AMQP_AUTOACK); var_dump($message->getHeaders()); var_dump($headers); echo $message->getHeaders() === $headers ? 'same' : 'differs'; From cbc7884edb2cd018ab64b714fb011f3c81103ea9 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Mon, 31 Jul 2023 01:30:27 +0200 Subject: [PATCH 032/147] Move test-report.sh into infra --- .github/workflows/test.yaml | 2 +- .gitignore | 2 +- infra/tools/pamqp-test-report | 20 ++++++++++++++++++++ test-report.sh | 11 ----------- 4 files changed, 22 insertions(+), 13 deletions(-) create mode 100755 infra/tools/pamqp-test-report delete mode 100755 test-report.sh diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 255882c8..55c49748 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -158,4 +158,4 @@ jobs: run: php -n -c './tmp-php.ini' -d "extension_dir=./modules/" -d "extension=amqp.so" benchmark.php - name: Dump report - run: sh test-report.sh + run: ./infra/tools/pamqp-test-report diff --git a/.gitignore b/.gitignore index a46b16af..5cec8c69 100644 --- a/.gitignore +++ b/.gitignore @@ -29,7 +29,7 @@ ltmain.sh missing mkinstalldirs modules/* -run-tests.php +infra/tools/run-tests.php tests/* !tests/*.phpt !tests/_test_helpers.php.inc diff --git a/infra/tools/pamqp-test-report b/infra/tools/pamqp-test-report new file mode 100755 index 00000000..37a7be97 --- /dev/null +++ b/infra/tools/pamqp-test-report @@ -0,0 +1,20 @@ +#!/usr/bin/env sh + +set -o errexit +set -o nounset + +base_dir=`dirname $0`/../../ +real_base_dir=`realpath $base_dir` + +result=$(find $base_dir/tests -type f -and -name "*.diff" -or -name "*.out" -or -name "*.mem" | + sort | + while read -r file; do + echo "FILE: ${file}" + cat "$file" + printf "\n" +done) + +if [ -n "$result" ]; then + echo "$result" + exit 1 +fi diff --git a/test-report.sh b/test-report.sh deleted file mode 100755 index a376883a..00000000 --- a/test-report.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -result=`find tests -type f -and -name "*.diff" -or -name "*.out" -or -name "*.mem" | sort | while read file; do - echo "FILE: ${file}" - cat "$file" - echo "\n" -done` - -if [ -n "$result" ]; then - echo "$result" - exit 1 -fi From c8e3a4e1cb3137cbb1f9388006f01a9330513abb Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 2 Aug 2023 13:08:49 +0200 Subject: [PATCH 033/147] Document BC changes --- UPGRADING.md | 525 ++++++++++++++++++++++++++++++++++++++ infra/tools/pamqp-diff-bc | 337 ++++++++++++++++++++++++ 2 files changed, 862 insertions(+) create mode 100644 UPGRADING.md create mode 100755 infra/tools/pamqp-diff-bc diff --git a/UPGRADING.md b/UPGRADING.md new file mode 100644 index 00000000..03a96dc0 --- /dev/null +++ b/UPGRADING.md @@ -0,0 +1,525 @@ +# Breaking changes in 2.0.0 + +## `AMQPBasicProperties` breaking changes + +### Public method type changes + +```diff + __construct( +- string $content_type = '', ++ ?string $contentType = null, +- string $content_encoding = '', ++ ?string $contentEncoding = null, + array $headers = [], +- int $delivery_mode = 2, ++ int $deliveryMode = 1, + int $priority = 0, +- string $correlation_id = '', ++ ?string $correlationId = null, +- string $reply_to = '', ++ ?string $replyTo = null, +- string $expiration = '', ++ ?string $expiration = null, +- string $message_id = '', ++ ?string $messageId = null, +- int $timestamp = 0, ++ ?int $timestamp = null, +- string $type = '', ++ ?string $type = null, +- string $user_id = '', ++ ?string $userId = null, +- string $app_id = '', ++ ?string $appId = null, +- string $cluster_id = '' ++ ?string $clusterId = null + ) +``` +```diff +- getContentType(): string ++ getContentType(): ?string + +``` +```diff +- getContentEncoding(): string ++ getContentEncoding(): ?string + +``` +```diff +- getCorrelationId(): string ++ getCorrelationId(): ?string + +``` +```diff +- getReplyTo(): string ++ getReplyTo(): ?string + +``` +```diff +- getExpiration(): string ++ getExpiration(): ?string + +``` +```diff +- getMessageId(): string ++ getMessageId(): ?string + +``` +```diff +- getTimestamp(): string ++ getTimestamp(): ?int + +``` +```diff +- getType(): string ++ getType(): ?string + +``` +```diff +- getUserId(): string ++ getUserId(): ?string + +``` +```diff +- getAppId(): string ++ getAppId(): ?string + +``` +```diff +- getClusterId(): string ++ getClusterId(): ?string + +``` + +## `AMQPChannel` breaking changes + +### Public method type changes + +```diff +- commitTransaction(): bool ++ commitTransaction(): void + +``` +```diff +- qos(int $size, int $count, bool $global): bool ++ qos(int $size, int $count, bool $global = false): void + +``` +```diff +- rollbackTransaction(): bool ++ rollbackTransaction(): void + +``` +```diff +- setPrefetchCount(int $count): bool ++ setPrefetchCount(int $count): void + +``` +```diff +- setPrefetchSize(int $size): bool ++ setPrefetchSize(int $size): void + +``` +```diff +- setGlobalPrefetchCount(int $count): bool ++ setGlobalPrefetchCount(int $count): void + +``` +```diff +- setGlobalPrefetchSize(int $size): bool ++ setGlobalPrefetchSize(int $size): void + +``` +```diff +- startTransaction(): bool ++ startTransaction(): void + +``` +```diff +- setConfirmCallback(?callable $ack_callback = null, ?callable $nack_callback = null): void ++ setConfirmCallback(?callable $ackCallback, ?callable $nackCallback = null): void + +``` +```diff +- setReturnCallback(?callable $return_callback = null): void ++ setReturnCallback(?callable $returnCallback): void + +``` + +### Parameter name changes + +```diff +- __construct(AMQPConnection $amqp_connection) ++ __construct(AMQPConnection $connection) + +``` + + +## `AMQPConnection` breaking changes + +### Public method type changes + +```diff +- connect(): bool ++ connect(): void + +``` +```diff +- disconnect(): bool ++ disconnect(): void + +``` +```diff +- pconnect(): bool ++ pconnect(): void + +``` +```diff +- pdisconnect(): bool ++ pdisconnect(): void + +``` +```diff +- reconnect(): bool ++ reconnect(): void + +``` +```diff +- preconnect(): bool ++ preconnect(): void + +``` +```diff +- setHost(string $host): bool ++ setHost(string $host): void + +``` +```diff +- setLogin(string $login): bool ++ setLogin(string $login): void + +``` +```diff +- setPassword(string $password): bool ++ setPassword(string $password): void + +``` +```diff +- setPort(int $port): bool ++ setPort(int $port): void + +``` +```diff +- setVhost(string $vhost): bool ++ setVhost(string $vhost): void + +``` +```diff +- setTimeout(float $timeout): bool ++ setTimeout(float $timeout): void + +``` +```diff +- setReadTimeout(float $timeout): bool ++ setReadTimeout(float $timeout): void + +``` +```diff +- setWriteTimeout(float $timeout): bool ++ setWriteTimeout(float $timeout): void + +``` +```diff +- setRpcTimeout(float $timeout): bool ++ setRpcTimeout(float $timeout): void + +``` +```diff +- getCACert(): string ++ getCACert(): ?string + +``` +```diff +- setCACert(string $cacert): void ++ setCACert(?string $cacert): void + +``` +```diff +- getCert(): string ++ getCert(): ?string + +``` +```diff +- setCert(string $cert): void ++ setCert(?string $cert): void + +``` +```diff +- getKey(): string ++ getKey(): ?string + +``` +```diff +- setKey(string $key): void ++ setKey(?string $key): void + +``` + +### Parameter name changes + +```diff +- setSaslMethod(int $method): void ++ setSaslMethod(int $saslMethod): void + +``` + + +## `AMQPDecimal` breaking changes + +### Public method type changes + +```diff +- __construct(unknown $exponent, unknown $significand) ++ __construct(int $exponent, int $significand) + +``` + +## `AMQPEnvelope` breaking changes + +### Public method type changes + +```diff +- getConsumerTag(): string ++ getConsumerTag(): ?string + +``` +```diff +- getDeliveryTag(): string ++ getDeliveryTag(): ?int + +``` +```diff +- getExchangeName(): string ++ getExchangeName(): ?string + +``` +```diff +- getHeader(string $header_key): string|bool ++ getHeader(string $headerName): ?string + +``` + +### Parameter name changes + +```diff +- hasHeader(string $header_key): bool ++ hasHeader(string $headerName): bool + +``` + + +## `AMQPExchange` breaking changes + +### Public method type changes + +```diff +- bind(string $exchange_name, string $routing_key = '', array $arguments = []): bool ++ bind(string $exchangeName, ?string $routingKey = null, array $arguments = []): void + +``` +```diff +- unbind(string $exchange_name, string $routing_key = '', array $arguments = []): bool ++ unbind(string $exchangeName, ?string $routingKey = null, array $arguments = []): void + +``` +```diff +- declareExchange(): bool ++ declareExchange(): void + +``` +```diff +- delete(string $exchangeName = null, int $flags = 0): bool ++ delete(?string $exchangeName = null, int $flags = 0): void + +``` +```diff +- getName(): string ++ getName(): ?string + +``` +```diff +- getType(): string ++ getType(): ?string + +``` +```diff +- publish(string $message, string $routing_key = null, int $flags = 0, array $attributes = []): bool ++ publish(string $message, ?string $routingKey = null, int $flags = 0, array $headers = []): void + +``` +```diff +- setArgument(string $key, string|int $value): bool ++ setArgument(string $argumentName, string|int $argumentValue): void + +``` +```diff +- setArguments(array $arguments): bool ++ setArguments(array $arguments): void + +``` +```diff +- setName(string $exchange_name): void ++ setName(?string $exchangeName): void + +``` +```diff +- setType(string $exchange_type): void ++ setType(?string $exchangeType): void + +``` + +### Parameter name changes + +```diff +- __construct(AMQPChannel $amqp_channel) ++ __construct(AMQPChannel $channel) + +``` + +```diff +- getArgument(string $key): string|int|bool ++ getArgument(string $argumentName): string|int|bool + +``` + +```diff +- hasArgument(string $key): bool ++ hasArgument(string $argumentName): bool + +``` + + +## `AMQPQueue` breaking changes + +### Public method type changes + +```diff +- ack(string $delivery_tag, int $flags = 0): bool ++ ack(int $deliveryTag, int $flags = 0): void + +``` +```diff +- bind(string $exchange_name, string $routing_key = null, array $arguments = []): bool ++ bind(string $exchangeName, ?string $routingKey = null, array $arguments = []): void + +``` +```diff +- cancel(string $consumer_tag = ''): bool ++ cancel(string $consumerTag = ''): void + +``` +```diff +- consume(?callable $callback = null, int $flags = 0, string $consumerTag = null): void ++ consume(?callable $callback = null, int $flags = 0, ?string $consumerTag = null): void + +``` +```diff +- get(int $flags = 0): AMQPEnvelope|bool ++ get(int $flags = 0): ?AMQPEnvelope + +``` +```diff +- getArgument(string $key): string|int|bool ++ getArgument(string $argumentName): ?string|?int + +``` +```diff +- getName(): string ++ getName(): ?string + +``` +```diff +- nack(string $delivery_tag, int $flags = 0): bool ++ nack(int $deliveryTag, int $flags = 0): void + +``` +```diff +- reject(string $delivery_tag, int $flags = 0): bool ++ reject(int $deliveryTag, int $flags = 0): void + +``` +```diff +- purge(): bool ++ purge(): int + +``` +```diff +- setArgument(string $key, mixed $value): bool ++ setArgument(string $argumentName, mixed $argumentValue): void + +``` +```diff +- setArguments(array $arguments): bool ++ setArguments(array $arguments): void + +``` +```diff +- setFlags(int $flags): bool ++ setFlags(int $flags): void + +``` +```diff +- setName(string $queue_name): bool ++ setName(string $name): void + +``` +```diff +- unbind(string $exchange_name, string $routing_key = null, array $arguments = []): bool ++ unbind(string $exchangeName, ?string $routingKey = null, array $arguments = []): void + +``` + +### Parameter name changes + +```diff +- __construct(AMQPChannel $amqp_channel) ++ __construct(AMQPChannel $channel) + +``` + +```diff +- hasArgument(string $key): bool ++ hasArgument(string $argumentName): bool + +``` + + +## `AMQPTimestamp` breaking changes + +### Public constant changes + +```diff +- const MIN = '0' ++ const MIN = 0.0 + +``` + +```diff +- const MAX = '18446744073709551616' ++ const MAX = 1.8446744073709552E+19 + +``` + + +### Public method type changes + +```diff +- __construct(string $timestamp) ++ __construct(float $timestamp) + +``` +```diff +- getTimestamp(): string ++ getTimestamp(): float + +``` + diff --git a/infra/tools/pamqp-diff-bc b/infra/tools/pamqp-diff-bc new file mode 100755 index 00000000..1005d023 --- /dev/null +++ b/infra/tools/pamqp-diff-bc @@ -0,0 +1,337 @@ +#!/usr/bin/env php +implements|extends)\s+(?[A-Za-z_]+)/', + static function ($matches) use ($className) { + $suffix = strpos($matches['class'], 'AMQP') === 0 ? + (pamqp_string_ends_with($className, PREV_SUFFIX) ? PREV_SUFFIX : NEXT_SUFFIX) + : ''; + + return $matches['stmt'] . ' ' . $matches['class'] . $suffix; + }, + $source + ); + $source = preg_replace('/^<\?php.*/', '', $source); + eval($source); +}); + +function compare(string $className) +{ + $prev = new ReflectionClass($className . PREV_SUFFIX); + $next = new ReflectionClass($className . NEXT_SUFFIX); + + $prevConstantNames = array_keys($prev->getConstants()); + $nextConstantNames = array_keys($prev->getConstants()); + + $removedConstantNames = array_diff($prevConstantNames, $nextConstantNames); + + $removedConstants = []; + foreach ($removedConstantNames as $removedConstantName) { + $removedConstants[] = sprintf(' * `%s`', $removedConstantName); + } + + $prevMethodNames = getMethodNames($prev); + $nextMethodNames = getMethodNames($next); + $removedMethodNames = array_diff($prevMethodNames, $nextMethodNames); + + $removedMethods = []; + foreach ($removedMethodNames as $removedMethodName) { + $removedMethods[] = sprintf(' * `%s()`', $removedMethodName); + } + + $constantChanges = []; + foreach ($prevConstantNames as $prevConstantName) { + $prevValue = $prev->getConstant($prevConstantName); + $nextValue = $next->getConstant($prevConstantName); + + if ($prevValue === $nextValue) { + continue; + } + + $prevConst = sprintf('const %s = %s', $prevConstantName, var_export($prevValue, true)); + $nextConst = sprintf('const %s = %s', $prevConstantName, var_export($nextValue, true)); + + $constantChanges[] = sprintf("```diff\n%s\n```\n", diff($prevConst, $nextConst)); + } + + $methodTypeChanges = []; + $methodParameterNameChanges = []; + foreach ($prevMethodNames as $methodName) { + $prevSignature = getParameterString($className, $prev->getMethod($methodName)); + $nextSignature = getParameterString($className, $next->getMethod($methodName)); + + if (strtolower($prevSignature) == strtolower($nextSignature)) { + continue; + } + + $prevSignatureNorm = getParameterString($className, $prev->getMethod($methodName), true); + $nextSignatureNorm = getParameterString($className, $next->getMethod($methodName), true); + + if (strtolower($prevSignatureNorm) === strtolower($nextSignatureNorm)) { + $methodParameterNameChanges[] = sprintf("```diff\n%s\n```\n", diff($prevSignature, $nextSignature)); + continue; + } + + $methodTypeChanges[] = sprintf("```diff\n%s\n```", diff($prevSignature, $nextSignature)); + } + + $report = [ + ...($removedConstants ? ["### Constant removals\n", ...$removedConstants, ''] : []), + ...($removedMethods ? ["### Public method removals\n", ...$removedMethods, ''] : []), + ...($constantChanges ? ["### Public constant changes\n", ...$constantChanges, ''] : []), + ...($methodTypeChanges ? ["### Public method type changes\n", ...$methodTypeChanges, ''] : []), + ...($methodParameterNameChanges ? ["### Parameter name changes\n", ...$methodParameterNameChanges, ''] : []), + ]; + + return $report ? [sprintf("## `%s` breaking changes\n", $className), ...$report] : []; +} + +function diff(string $prev, string $next): string +{ + if (strpos($prev, "\n") === false && strpos($next, "\n") === false) { + return sprintf("- %s\n+ %s\n", $prev, $next); + } + + if (substr_count($prev, "\n") === substr_count($next, "\n")) { + return implode("\n", array_map(static function ($old, $new) { + return $old === $new ? sprintf(' %s', $new) : sprintf("- %s\n+ %s", $old, $new); + }, explode("\n", $prev), explode("\n", $next))); + } + + $oldFile = tmpfile(); + $newFile = tmpfile(); + + fwrite($oldFile, $prev); + fwrite($newFile, $next); + + exec( + sprintf( + 'diff --suppress-common-lines -d -u %s %s', + escapeshellarg(stream_get_meta_data($oldFile)['uri']), + escapeshellarg(stream_get_meta_data($newFile)['uri']) + ), + $output, + $exitCode + ); + + assert($exitCode === 1); + + return implode( + "\n", + array_filter( + $output, + static function (string $line) { + return !in_array(substr($line, 0, 3), ['---', '+++', '\\ N', '@@ '], true); + } + ) + ); +} + +function getMethodNames(ReflectionClass $class): array +{ + return array_map( + static function (ReflectionMethod $m) { + return $m->getName(); + }, + array_filter( + $class->getMethods(ReflectionMethod::IS_PUBLIC), + static function (ReflectionMethod $method) use ($class) { + return $method->getDeclaringClass() + ->getName() === $class->getName(); + } + ) + ); +} + +const BASE_TYPE_REGEX = '(string|bool(?:ean)?|int(?:eger)?|double|float|array|object|resource|[A-Za-z_\\\]+(?:\[\])?)'; +const TYPE_REGEX = BASE_TYPE_REGEX . '(?:\s*\|\s*(' . BASE_TYPE_REGEX . '))*'; + +function getParamTypeFromDocBlock(string $docComment, string $parameter): ?string +{ + if (!preg_match('/@param\s+(?' . TYPE_REGEX . ')\s+' . '\$' . $parameter . '/', $docComment, $matches)) { + return null; + } + + return normalizeType($matches['type']); +} + +function getReturnTypeFromDocBlock(string $docComment): ?string +{ + if (!preg_match('/@return\s+(?' . TYPE_REGEX . ')/', $docComment, $matches)) { + return null; + } + + return normalizeType($matches['type']); +} + +function normalizeType(string $type): string +{ + $types = []; + foreach (explode('|', str_replace(' ', '', $type)) as $actualType) { + switch (strtolower($actualType)) { + case 'boolean': + $actualType = 'bool'; + break; + case 'integer': + $actualType = 'int'; + break; + case 'double': + $actualType = 'float'; + break; + case 'int': + case 'float': + case 'string': + case 'bool': + case 'object': + case 'resource': + case 'null': + case 'array': + $actualType = strtolower($actualType); + break; + default: + $actualType = $actualType; + break; + } + // Normalize typed arrays as array + if (pamqp_string_ends_with($actualType, '[]')) { + $actualType = 'array'; + } + $types[] = $actualType; + } + + if (count($types) > 1 && in_array('null', $types, true)) { + $types = array_map(static function ($type) { + return '?' . $type; + }, array_filter($types, static function ($type) { + return $type !== 'null'; + })); + } + + return implode('|', $types); +} + +function getParameterString(string $className, ReflectionMethod $method, bool $normalizeNames = false): string +{ + $parameters = []; + + foreach ($method->getParameters() as $pos => $reflParameter) { + $parameterTokens = []; + $typeFound = false; + if ($reflParameter->hasType()) { + $typeFound = true; + $parameterTokens[] = ($reflParameter->allowsNull() || ($reflParameter->isDefaultValueAvailable() && $reflParameter->getDefaultValue() === null) ? '?' : '') . $reflParameter->getType()->getName(); + } elseif ($method->getDocComment()) { + $docBlockParamType = getParamTypeFromDocBlock($method->getDocComment(), $reflParameter->getName()); + if ($docBlockParamType !== null) { + $typeFound = true; + $parameterTokens[] = $docBlockParamType; + } + } + if (!$typeFound) { + $parameterTokens[] = 'unknown'; + } + $parameterTokens[] = sprintf('$%s', $normalizeNames ? chr($pos + 97) : $reflParameter->getName()); + + if ($reflParameter->isDefaultValueAvailable()) { + $parameterTokens[] = '='; + $defaultValue = $reflParameter->getDefaultValue(); + $parameterTokens[] = $defaultValue === [] ? '[]' : ($defaultValue === null ? 'null' : var_export( + $defaultValue, + true + )); + } + + $parameters[] = implode(' ', $parameterTokens); + } + + $returnTypeTokens = []; + $returnTypeFound = false; + if ($method->hasReturnType()) { + $returnTypeFound = true; + $returnType = $method->getReturnType(); + $returnTypeTokens[] = ':'; + $returnTypeTokens[] = ($returnType->allowsNull() ? '?' : '') . $returnType->getName(); + } elseif ($method->getDocComment()) { + $docBlockReturnType = getReturnTypeFromDocBlock($method->getDocComment()); + if ($docBlockReturnType !== null) { + $returnTypeFound = true; + $returnTypeTokens[] = ':'; + $returnTypeTokens[] = $docBlockReturnType; + } + } + if (!$returnTypeFound && $method->getName() !== '__construct') { + $returnTypeTokens[] = ':'; + $returnTypeTokens[] = 'void'; + } + + $signature = sprintf('%s(%s)%s', $method->getName(), implode(', ', $parameters), implode(' ', $returnTypeTokens)); + + if (strlen($signature) <= 120) { + return $signature; + } + + return sprintf( + "%s(\n %s\n)%s", + $method->getName(), + implode(",\n ", $parameters), + implode(' ', $returnTypeTokens) + ); +} + +$report = []; +const CLASSES = [ + 'AMQPBasicProperties', + 'AMQPChannel', + 'AMQPChannelException', + 'AMQPConnection', + 'AMQPConnectionException', + 'AMQPDecimal', + 'AMQPEnvelope', + 'AMQPEnvelopeException', + 'AMQPException', + 'AMQPExchange', + 'AMQPExchangeException', + 'AMQPQueue', + 'AMQPQueueException', + 'AMQPTimestamp', + 'AMQPValueException', +]; + +require $next . '/AMQP.php'; + +foreach (CLASSES as $class) { + $report = [...$report, ...compare($class)]; +} +echo implode(PHP_EOL, $report); +echo PHP_EOL; From 0f088b18dac8d27cb86ea6d86d37da2c163af38c Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 2 Aug 2023 18:12:31 +0200 Subject: [PATCH 034/147] Validate argument parsing, add AMQPExchange::removeArgument() and AMQPQueue::removeArgument() (#452) --- .github/workflows/test.yaml | 6 +- UPGRADING.md | 58 ++++-- amqp_connection.c | 31 +-- amqp_exchange.c | 28 ++- amqp_queue.c | 37 +++- infra/tools/pamqp-arguments-validate | 185 ++++++++++++++++++ infra/tools/pamqp-diff-bc | 29 ++- infra/tools/pamqp-docker-setup | 5 +- infra/tools/pamqp-dump-reflection | 94 +++++---- infra/tools/pamqp-release-cut | 1 + infra/tools/pamqp-release-finalize | 1 + stubs/AMQPExchange.php | 17 +- stubs/AMQPQueue.php | 31 +-- .../amqpconnection_setPort_out_of_range.phpt | 2 +- tests/amqpconnection_validation.phpt | 8 +- tests/amqpexchange_attributes.phpt | 21 +- tests/amqpexchange_delete_null_name.phpt | 25 +++ tests/amqpexchange_setArgument.phpt | 12 +- tests/amqpqueue_attributes.phpt | 12 +- tests/amqpqueue_bind_null_routing_key.phpt | 4 +- .../amqpqueue_consume_null_consumer_key.phpt | 46 +++++ tests/amqpqueue_setArgument.phpt | 12 +- tests/amqpqueue_setFlags.phpt | 20 ++ ...pqueue_unbind_basic_empty_routing_key.phpt | 5 + 24 files changed, 562 insertions(+), 128 deletions(-) create mode 100755 infra/tools/pamqp-arguments-validate create mode 100644 tests/amqpexchange_delete_null_name.phpt create mode 100644 tests/amqpqueue_consume_null_consumer_key.phpt create mode 100644 tests/amqpqueue_setFlags.phpt diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 55c49748..2118c81b 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -87,6 +87,10 @@ jobs: - name: Check stub coding style run: ./infra/tools/pamqp-stubs-format-check + - name: Validate argument parsing + run: ./infra/tools/pamqp-php-cli-deterministic -d extension=modules/amqp.so ./infra/tools/pamqp-arguments-validate + if: matrix.php-version == '8.2' + test: name: ${{ matrix.test-php-args == '-m' && 'Memtest' || 'Test' }} php-${{ matrix.php-version }}${{ matrix.php-thread-safe && '-ts' || '-nts' }} librabbitmq-${{ matrix.librabbitmq-version }} # librabbitmq < 0.11 needs older OpenSSL version @@ -155,7 +159,7 @@ jobs: run: docker compose logs - name: Benchmark PHP extension - run: php -n -c './tmp-php.ini' -d "extension_dir=./modules/" -d "extension=amqp.so" benchmark.php + run: ./infra/tools/pamqp-php-cli-deterministic -d extension=modules/amqp.so benchmark.php - name: Dump report run: ./infra/tools/pamqp-test-report diff --git a/UPGRADING.md b/UPGRADING.md index 03a96dc0..fb606485 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -156,6 +156,12 @@ ## `AMQPConnection` breaking changes +### Public method additions + +* `getConnectTimeout(): float` +* `setConnectionName(?string $connectionName): void` +* `getConnectionName(): ?string` + ### Public method type changes ```diff @@ -303,7 +309,7 @@ ``` ```diff -- getHeader(string $header_key): string|bool +- getHeader(string $header_key): bool|string + getHeader(string $headerName): ?string ``` @@ -317,8 +323,24 @@ ``` +## `AMQPEnvelopeException` breaking changes + +### Public method additions + +* `getEnvelope(): AMQPEnvelope` + ## `AMQPExchange` breaking changes +### Change in semantics + +* `setArgument(string $argumentName, null)` no longer unsets the argument `$key` but sets it to `null` instead. To remove an argument use `removeArgument(string $argumentName)` instead +* `getArgument(string $argumentName)` now throws an `AMQPExchangeException` if the argument does not exist. It returned false previously + +### Public method additions + +* `declare(): void` +* `removeArgument(string $argumentName): void` + ### Public method type changes ```diff @@ -340,6 +362,11 @@ - delete(string $exchangeName = null, int $flags = 0): bool + delete(?string $exchangeName = null, int $flags = 0): void +``` +```diff +- getArgument(string $key): bool|int|string ++ getArgument(string $argumentName): bool|float|int|string|null + ``` ```diff - getName(): string @@ -357,8 +384,8 @@ ``` ```diff -- setArgument(string $key, string|int $value): bool -+ setArgument(string $argumentName, string|int $argumentValue): void +- setArgument(string $key, int|string $value): bool ++ setArgument(string $argumentName, bool|float|int|string|null $argumentValue): void ``` ```diff @@ -385,12 +412,6 @@ ``` -```diff -- getArgument(string $key): string|int|bool -+ getArgument(string $argumentName): string|int|bool - -``` - ```diff - hasArgument(string $key): bool + hasArgument(string $argumentName): bool @@ -400,6 +421,16 @@ ## `AMQPQueue` breaking changes +### Change in semantics + +* `setArgument(string $key, null)` no longer unsets the argument `$key` but sets it to `null` instead. To remove an argument use `removeArgument(string $key)` instead +* `getArgument(string $argumentName)` now throws an `AMQPQueueException` if the argument does not exist. It returned false previously + +### Public method additions + +* `declare(): int` +* `removeArgument(string $argumentName): void` + ### Public method type changes ```diff @@ -428,8 +459,8 @@ ``` ```diff -- getArgument(string $key): string|int|bool -+ getArgument(string $argumentName): ?string|?int +- getArgument(string $key): bool|int|string ++ getArgument(string $argumentName): bool|float|int|string|null ``` ```diff @@ -454,7 +485,7 @@ ``` ```diff - setArgument(string $key, mixed $value): bool -+ setArgument(string $argumentName, mixed $argumentValue): void ++ setArgument(string $argumentName, bool|float|int|string|null $argumentValue): void ``` ```diff @@ -464,7 +495,7 @@ ``` ```diff - setFlags(int $flags): bool -+ setFlags(int $flags): void ++ setFlags(?int $flags): void ``` ```diff @@ -522,4 +553,3 @@ + getTimestamp(): float ``` - diff --git a/amqp_connection.c b/amqp_connection.c index b99867b9..40c2859d 100644 --- a/amqp_connection.c +++ b/amqp_connection.c @@ -499,7 +499,7 @@ static PHP_METHOD(amqp_connection_class, __construct) zend_throw_exception_ex( amqp_connection_exception_class_entry, 0, - "Parameter 'port' must be a valid port number between %d and %d.", + "Parameter 'port' must be a valid port number between %d and %d.", PHP_AMQP_MIN_PORT, PHP_AMQP_MAX_PORT ); @@ -1165,36 +1165,21 @@ static PHP_METHOD(amqp_connection_class, getPort) set the port */ static PHP_METHOD(amqp_connection_class, setPort) { - zval *zvalPort; int port; /* Get the port from the method params */ - if (zend_parse_parameters(ZEND_NUM_ARGS(), "z/", &zvalPort) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &port) == FAILURE) { return; } - /* Parse out the port*/ - switch (Z_TYPE_P(zvalPort)) { - case IS_DOUBLE: - port = (int) Z_DVAL_P(zvalPort); - break; - case IS_LONG: - port = (int) Z_LVAL_P(zvalPort); - break; - case IS_STRING: - convert_to_long(zvalPort); - port = (int) Z_LVAL_P(zvalPort); - break; - default: - port = 0; - } - /* Check the port value */ - if (port <= 0 || port > 65535) { - zend_throw_exception( + if (!php_amqp_is_valid_port(port)) { + zend_throw_exception_ex( amqp_connection_exception_class_entry, - "Invalid port given. Value must be between 1 and 65535.", - 0 + 0, + "Parameter 'port' must be a valid port number between %d and %d.", + PHP_AMQP_MIN_PORT, + PHP_AMQP_MAX_PORT ); return; } diff --git a/amqp_exchange.c b/amqp_exchange.c index ceb5b505..bd7f623e 100644 --- a/amqp_exchange.c +++ b/amqp_exchange.c @@ -241,7 +241,8 @@ static PHP_METHOD(amqp_exchange_class, getArgument) } if ((tmp = zend_hash_str_find(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len)) == NULL) { - RETURN_FALSE; + zend_throw_exception_ex(amqp_exchange_exception_class_entry, 0, "The argument \"%s\" does not exist", key); + return; } RETURN_ZVAL(tmp, 1, 0); @@ -304,8 +305,6 @@ static PHP_METHOD(amqp_exchange_class, setArgument) switch (Z_TYPE_P(value)) { case IS_NULL: - zend_hash_str_del_ind(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len); - break; case IS_TRUE: case IS_FALSE: case IS_LONG: @@ -326,6 +325,22 @@ static PHP_METHOD(amqp_exchange_class, setArgument) /* }}} */ +/* {{{ proto AMQPExchange::removeArgument(key) */ +static PHP_METHOD(amqp_exchange_class, removeArgument) +{ + zval rv; + + char *key = NULL; + size_t key_len = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &key, &key_len) == FAILURE) { + return; + } + + zend_hash_str_del(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len); +} +/* }}} */ + /* {{{ proto AMQPExchange::declareExchange(); declare Exchange */ @@ -403,7 +418,7 @@ static PHP_METHOD(amqp_exchange_class, delete) size_t name_len = 0; zend_long flags = AMQP_NOPARAM; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|sl", &name, &name_len, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!l", &name, &name_len, &flags) == FAILURE) { return; } @@ -837,6 +852,10 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_exchange_class_setArgument, ZEND_ARG_INFO(0, argumentValue) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_exchange_class_removeArgument, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, argumentName, IS_STRING, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_exchange_class_setArguments, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) ZEND_ARG_ARRAY_INFO(0, arguments, 0) ZEND_END_ARG_INFO() @@ -889,6 +908,7 @@ zend_function_entry amqp_exchange_class_functions[] = { PHP_ME(amqp_exchange_class, getArgument, arginfo_amqp_exchange_class_getArgument, ZEND_ACC_PUBLIC) PHP_ME(amqp_exchange_class, getArguments, arginfo_amqp_exchange_class_getArguments, ZEND_ACC_PUBLIC) PHP_ME(amqp_exchange_class, setArgument, arginfo_amqp_exchange_class_setArgument, ZEND_ACC_PUBLIC) + PHP_ME(amqp_exchange_class, removeArgument, arginfo_amqp_exchange_class_removeArgument, ZEND_ACC_PUBLIC) PHP_ME(amqp_exchange_class, setArguments, arginfo_amqp_exchange_class_setArguments, ZEND_ACC_PUBLIC) PHP_ME(amqp_exchange_class, hasArgument, arginfo_amqp_exchange_class_hasArgument, ZEND_ACC_PUBLIC) diff --git a/amqp_queue.c b/amqp_queue.c index c9708563..a6990df3 100644 --- a/amqp_queue.c +++ b/amqp_queue.c @@ -213,7 +213,8 @@ static PHP_METHOD(amqp_queue_class, getArgument) } if ((tmp = zend_hash_str_find(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len)) == NULL) { - RETURN_NULL(); + zend_throw_exception_ex(amqp_queue_exception_class_entry, 0, "The argument \"%s\" does not exist", key); + return; } RETURN_ZVAL(tmp, 1, 0); @@ -278,8 +279,6 @@ static PHP_METHOD(amqp_queue_class, setArgument) switch (Z_TYPE_P(value)) { case IS_NULL: - zend_hash_str_del_ind(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len); - break; case IS_TRUE: case IS_FALSE: case IS_LONG: @@ -290,8 +289,8 @@ static PHP_METHOD(amqp_queue_class, setArgument) break; default: zend_throw_exception( - amqp_exchange_exception_class_entry, - "The value parameter must be of type NULL, int, double or string.", + amqp_queue_exception_class_entry, + "The value parameter must be of type bool, int, double, string, or null.", 0 ); return; @@ -300,6 +299,23 @@ static PHP_METHOD(amqp_queue_class, setArgument) /* }}} */ +/* {{{ proto AMQPQueue::removeArgument(key) +Get the queue name */ +static PHP_METHOD(amqp_queue_class, removeArgument) +{ + zval rv; + + char *key = NULL; + size_t key_len = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &key, &key_len) == FAILURE) { + return; + } + + zend_hash_str_del_ind(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len); +} +/* }}} */ + /* {{{ proto int AMQPQueue::declareQueue(); declare queue */ @@ -533,7 +549,7 @@ static PHP_METHOD(amqp_queue_class, consume) size_t consumer_tag_len = 0; zend_long flags = INI_INT("amqp.auto_ack") ? AMQP_AUTOACK : AMQP_NOPARAM; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|f!ls", &fci, &fci_cache, &flags, &consumer_tag, &consumer_tag_len) == + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|f!ls!", &fci, &fci_cache, &flags, &consumer_tag, &consumer_tag_len) == FAILURE) { return; } @@ -1069,7 +1085,7 @@ static PHP_METHOD(amqp_queue_class, unbind) if (zend_parse_parameters( ZEND_NUM_ARGS(), - "s|sa", + "s|s!a", &exchange_name, &exchange_name_len, &keyname, @@ -1209,7 +1225,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_getFlags, ZEND_ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_setFlags, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) - ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 1) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_queue_class_getArgument, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) @@ -1224,6 +1240,10 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_setArgument, ZE ZEND_ARG_INFO(0, argumentValue) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_removeArgument, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, argumentName, IS_STRING, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_hasArgument, ZEND_SEND_BY_VAL, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, argumentName, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -1304,6 +1324,7 @@ zend_function_entry amqp_queue_class_functions[] = { PHP_ME(amqp_queue_class, getArgument, arginfo_amqp_queue_class_getArgument, ZEND_ACC_PUBLIC) PHP_ME(amqp_queue_class, getArguments, arginfo_amqp_queue_class_getArguments, ZEND_ACC_PUBLIC) PHP_ME(amqp_queue_class, setArgument, arginfo_amqp_queue_class_setArgument, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, removeArgument, arginfo_amqp_queue_class_removeArgument, ZEND_ACC_PUBLIC) PHP_ME(amqp_queue_class, setArguments, arginfo_amqp_queue_class_setArguments, ZEND_ACC_PUBLIC) PHP_ME(amqp_queue_class, hasArgument, arginfo_amqp_queue_class_hasArgument, ZEND_ACC_PUBLIC) diff --git a/infra/tools/pamqp-arguments-validate b/infra/tools/pamqp-arguments-validate new file mode 100755 index 00000000..e318c410 --- /dev/null +++ b/infra/tools/pamqp-arguments-validate @@ -0,0 +1,185 @@ +#!/usr/bin/env php +getMethods() as $method) { + if ($method->getName() == 'declare') { + continue; + } + + if ($method->getDeclaringClass()->getName() !== $class) { + continue; + } + + assert(preg_match('/ + PHP_METHOD\(.*?,\s*' . preg_quote($method->getName(), '/') . '\).*? + \{.*? + ((?zend_parse_parameters)\(.+?,\s*\"(?.*?)\"|PHP_AMQP_NOPARAMS|zend_parse_parameters_none) + /xs', $source, $matches), $class . ' ' . $method->getName()); + + $parametersString = $matches['def'] ?? ''; + + try { + [$types, $numberOfRequiredParameters] = parseParameterString($parametersString); + } catch (Throwable $t) { + throw new RuntimeException(sprintf( + 'Could not parse parameter string "%s" for %s::%s', + $parametersString, + $class, + $method->getName() + ), 0, $t); + } + + if ($method->getNumberOfRequiredParameters() !== $numberOfRequiredParameters) { + error( + '%s::%s(): Number of required parameters do not match. Parameter parsing: %d (%s). Reflection: %d', + $class, + $method->getName(), + $numberOfRequiredParameters, + $parametersString, + $method->getNumberOfRequiredParameters() + ); + } + + if ($method->getNumberOfParameters() !== count($types)) { + error( + '%s::%s(): Number of parameters do not match. Parameter parsing: %d (%s). Reflection: %d', + $class, + $method->getName(), + count($types), + $parametersString, + $method->getNumberOfParameters() + ); + } + + foreach ($method->getParameters() as $pos => $parameter) { + $reflectionType = $parameter->hasType() ? ($parameter->getType()->isBuiltin() ? $parameter->getType()->getName() : 'object') : 'mixed'; + + if ($reflectionType !== $types[$pos]['type']) { + error( + '%s::%s(): type parsing and Reflection info do not match. Parameter parsing: %s (%s). Reflection: %s', + $class, + $method->getName(), + $types[$pos]['type'], + $parametersString, + $reflectionType + ); + } + + $reflectionNullable = $parameter->allowsNull(); + if ($reflectionNullable !== $types[$pos]['nullable']) { + error( + '%s::%s(%s): type parsing and Reflection nullability differs. Parameter parsing: %s (%s). Reflection: %s', + $class, + $method->getName(), + $parameter->getName(), + $types[$pos]['nullable'] ? 'nullable' : 'not nullable', + $parametersString, + $reflectionNullable ? 'nullable' : 'not nullable' + ); + } + } + } +} + +$isError = false; +function error(string $message, ...$args): void +{ + global $isError; + $isError = true; + vprintf('ERROR: ' . $message . PHP_EOL, $args); +} + +function parseParameterString(string $str): array +{ + $types = [ + 's' => 'string', + 'O' => 'object', + 'l' => 'int', + 'a' => 'array', + 'f' => 'callable', + 'd' => 'float', + 'b' => 'bool', + 'z' => 'mixed', + ]; + $parameters = []; + $requiredCount = null; + $count = 0; + foreach (str_split($str) as $pos => $char) { + if (isset($types[$char])) { + if (isset($currentInfo)) { + $parameters[] = $currentInfo; + } + $currentInfo = [ + 'type' => $types[$char], + 'nullable' => $types[$char] === 'mixed', + ]; + $count++; + } elseif ($char == '!') { + $currentInfo['nullable'] = true; + } elseif ($char === '|') { + $requiredCount = $count; + } elseif ($char === '/') { + // Ignored + } else { + throw new InvalidArgumentException($char); + } + } + + if ($requiredCount === null) { + $requiredCount = $count; + } + + if (isset($currentInfo)) { + $parameters[] = $currentInfo; + } + + return [$parameters, $requiredCount]; +} + +foreach (CLASSES as $class) { + validate($class); +} + +exit((int) $isError); diff --git a/infra/tools/pamqp-diff-bc b/infra/tools/pamqp-diff-bc index 1005d023..07ebe5b0 100755 --- a/infra/tools/pamqp-diff-bc +++ b/infra/tools/pamqp-diff-bc @@ -53,23 +53,32 @@ function compare(string $className) $prevConstantNames = array_keys($prev->getConstants()); $nextConstantNames = array_keys($prev->getConstants()); - $removedConstantNames = array_diff($prevConstantNames, $nextConstantNames); + $addedConstantNames = array_diff($nextConstantNames, $prevConstantNames); $removedConstants = []; foreach ($removedConstantNames as $removedConstantName) { $removedConstants[] = sprintf(' * `%s`', $removedConstantName); } + $addedConstants = []; + foreach ($addedConstantNames as $addedConstantName) { + $addedConstants[] = sprintf(' * `%s`', $addedConstantName); + } + $prevMethodNames = getMethodNames($prev); $nextMethodNames = getMethodNames($next); - $removedMethodNames = array_diff($prevMethodNames, $nextMethodNames); $removedMethods = []; - foreach ($removedMethodNames as $removedMethodName) { + foreach (array_diff($prevMethodNames, $nextMethodNames) as $removedMethodName) { $removedMethods[] = sprintf(' * `%s()`', $removedMethodName); } + $addedMethods = []; + foreach (array_diff($nextMethodNames, $prevMethodNames) as $addedMethodName) { + $addedMethods[] = sprintf(' * `%s`', getParameterString($className, $next->getMethod($addedMethodName))); + } + $constantChanges = []; foreach ($prevConstantNames as $prevConstantName) { $prevValue = $prev->getConstant($prevConstantName); @@ -107,9 +116,11 @@ function compare(string $className) } $report = [ + ...($addedConstants ? ["### Constant additions\n", ...$addedConstants, ''] : []), ...($removedConstants ? ["### Constant removals\n", ...$removedConstants, ''] : []), - ...($removedMethods ? ["### Public method removals\n", ...$removedMethods, ''] : []), ...($constantChanges ? ["### Public constant changes\n", ...$constantChanges, ''] : []), + ...($addedMethods ? ["### Public method additions\n", ...$addedMethods, ''] : []), + ...($removedMethods ? ["### Public method removals\n", ...$removedMethods, ''] : []), ...($methodTypeChanges ? ["### Public method type changes\n", ...$methodTypeChanges, ''] : []), ...($methodParameterNameChanges ? ["### Parameter name changes\n", ...$methodParameterNameChanges, ''] : []), ]; @@ -230,7 +241,7 @@ function normalizeType(string $type): string $types[] = $actualType; } - if (count($types) > 1 && in_array('null', $types, true)) { + if (count($types) == 2 && in_array('null', $types, true)) { $types = array_map(static function ($type) { return '?' . $type; }, array_filter($types, static function ($type) { @@ -238,6 +249,14 @@ function normalizeType(string $type): string })); } + sort($types); + $index = array_search('null', $types, true); + if ($index !== false) { + unset($types[$index]); + // Sort to the end + $types[] = 'null'; + } + return implode('|', $types); } diff --git a/infra/tools/pamqp-docker-setup b/infra/tools/pamqp-docker-setup index 8347c044..07f5f84d 100755 --- a/infra/tools/pamqp-docker-setup +++ b/infra/tools/pamqp-docker-setup @@ -1,6 +1,7 @@ #!/usr/bin/env php [], ]; -function sortByName(array $array): array { - usort( - $array, - function (array $left, array $right) { - return $left['name'] <=> $right['name']; - } - ); +function sortByName(array $array): array +{ + usort($array, static function (array $left, array $right) { + return $left['name'] <=> $right['name']; + }); return $array; } -function getTypeMetadata(?ReflectionNamedType $type): ?array { +function getTypeMetadata(?ReflectionNamedType $type): ?array +{ if ($type == null) { return null; } return [ 'name' => $type->getName(), - 'nullable' => $type->allowsNull() + 'nullable' => $type->allowsNull(), ]; } @@ -36,19 +35,15 @@ function error(string $message, ...$args): void $error = true; } -const MAGIC_METHODS = [ - '__construct', - '__toString', - '__wakeup', - '__clone', -]; +const MAGIC_METHODS = ['__construct', '__toString', '__wakeup', '__clone']; -function getClassMetadata(string $class): array { +function getClassMetadata(string $class): array +{ $refl = new ReflectionClass($class); $classMetadata = [ 'name' => $refl->getName(), 'constants' => [], - 'properties' => [], + 'properties' => [], 'methods' => [], ]; @@ -58,7 +53,7 @@ function getClassMetadata(string $class): array { } $classMetadata['constants'][] = [ - 'name' => $class. '::' . $constant->getName(), + 'name' => $class . '::' . $constant->getName(), 'value' => $constant->getValue(), 'visibility' => $constant->isPublic() ? 'public' : ($constant->isProtected() ? 'protected' : ($constant->isPrivate() ? 'private' : 'unknown')), ]; @@ -70,7 +65,7 @@ function getClassMetadata(string $class): array { } $methodMetadata = [ - 'name' => $class. '::' . $method->getName(), + 'name' => $class . '::' . $method->getName(), 'visibility' => $method->isPublic() ? 'public' : ($method->isProtected() ? 'protected' : ($method->isPrivate() ? 'private' : 'unknown')), 'final' => $method->isFinal(), 'static' => $method->isStatic(), @@ -81,44 +76,75 @@ function getClassMetadata(string $class): array { ]; if (!in_array($method->getName(), MAGIC_METHODS, true) && strpos($method->getName(), '_') !== false) { - error("%s::%s contains underscore", $class, $method->getName()); + error('%s::%s contains underscore', $class, $method->getName()); } $prefix = substr($method->getName(), 0, 3); - if (in_array($prefix, ['set', 'has', 'get'], true) && !in_array($method->getName(), ['set', 'has', 'get'], true)) { + if (in_array($prefix, ['set', 'has', 'get'], true) && !in_array( + $method->getName(), + ['set', 'has', 'get'], + true + )) { $hasPlural = $refl->hasMethod($method->getName() . 's'); $isPlural = substr($method->getName(), -1) === 's'; if ($prefix === 'get' && $method->getNumberOfParameters() !== 0 && !$hasPlural) { - error("%s::%s() should have no arguments", $class, $method->getName()); + error('%s::%s() should have no arguments', $class, $method->getName()); } if ($prefix === 'set' && $isPlural) { - if ($method->getParameters()[0]->getName() !== ($expectedName = lcfirst(substr($method->getName(), 3)))) { - error("%s::%s(%s) must be \"%s\"", $class, $method->getName(), $method->getParameters()[0]->getName(), $expectedName); + if ($method->getParameters()[0]->getName() !== ($expectedName = lcfirst( + substr($method->getName(), 3) + ))) { + error( + '%s::%s(%s) must be "%s"', + $class, + $method->getName(), + $method->getParameters()[0] + ->getName(), + $expectedName + ); } } if ($prefix === 'get' && $hasPlural) { if ($method->getNumberOfRequiredParameters() !== 1 || $method->getNumberOfParameters() !== 1) { - error("%s::%s() should have exactly one required parameter", $class, $method->getName()); + error('%s::%s() should have exactly one required parameter', $class, $method->getName()); } } if ($hasPlural) { - if ($method->getParameters()[0]->getName() !== ($expectedName = lcfirst(substr($method->getName(), 3) . 'Name'))) { - error("%s::%s(%s) must be \"%s\"", $class, $method->getName(), $method->getParameters()[0]->getName(), $expectedName); + if ($method->getParameters()[0]->getName() !== ($expectedName = lcfirst( + substr($method->getName(), 3) . 'Name' + ))) { + error( + '%s::%s(%s) must be "%s"', + $class, + $method->getName(), + $method->getParameters()[0] + ->getName(), + $expectedName + ); } - if ($prefix === 'set' && $method->getParameters()[1]->getName() !== ($expectedName = lcfirst(substr($method->getName(), 3) . 'Value'))) { - error("%s::%s(…, %s) must be \"%s\"", $class, $method->getName(), $method->getParameters()[1]->getName(), $expectedName); + if ($prefix === 'set' && $method->getParameters()[1]->getName() !== ($expectedName = lcfirst( + substr($method->getName(), 3) . 'Value' + ))) { + error( + '%s::%s(…, %s) must be "%s"', + $class, + $method->getName(), + $method->getParameters()[1] + ->getName(), + $expectedName + ); } } } foreach ($method->getParameters() as $parameter) { if (strpos($parameter->getName(), '_') !== false) { - error("%s::%s(…%s…) contains underscore", $class, $method->getName(), $parameter->getName()); + error('%s::%s(…%s…) contains underscore', $class, $method->getName(), $parameter->getName()); } $default = 'unknown'; @@ -128,7 +154,7 @@ function getClassMetadata(string $class): array { } $methodMetadata['parameters'][] = [ - 'method' => $class. '::' . $method->getName(), + 'method' => $class . '::' . $method->getName(), 'name' => sprintf('$%s', $parameter->getName()), 'default' => $default, 'type' => getTypeMetadata($parameter->getType()), @@ -173,7 +199,7 @@ function getClassMetadata(string $class): array { } -spl_autoload_register(function(string $class) { +spl_autoload_register(function (string $class) { require_once __DIR__ . '/../../stubs/' . $class . '.php'; }); @@ -200,7 +226,7 @@ foreach (get_defined_constants() as $constant => $value) { if (strpos($constant, 'AMQP_') === 0) { $symbols['constants'][] = [ 'name' => $constant, - 'value' => $value + 'value' => $value, ]; } } @@ -236,4 +262,4 @@ file_put_contents($filename, json_encode($symbols, JSON_PRETTY_PRINT)); if ($error) { exit(1); -} \ No newline at end of file +} diff --git a/infra/tools/pamqp-release-cut b/infra/tools/pamqp-release-cut index d551053f..98944261 100755 --- a/infra/tools/pamqp-release-cut +++ b/infra/tools/pamqp-release-cut @@ -1,5 +1,6 @@ #!/usr/bin/env php --EXPECT-- -Invalid port given. Value must be between 1 and 65535. \ No newline at end of file +Parameter 'port' must be a valid port number between 1 and 65535. \ No newline at end of file diff --git a/tests/amqpconnection_validation.phpt b/tests/amqpconnection_validation.phpt index 813cf7c6..60e6c7c4 100644 --- a/tests/amqpconnection_validation.phpt +++ b/tests/amqpconnection_validation.phpt @@ -75,10 +75,10 @@ AMQPConnectionException: Parameter 'vhost' exceeds 512 character limit. AMQPConnectionException: Parameter 'vhost' exceeds 512 characters limit. getVhost after constructor: vhost getVhost after setter: vhost -AMQPConnectionException: Parameter 'port' must be a valid port number between 1 and 65535. -AMQPConnectionException: Invalid port given. Value must be between 1 and 65535. -AMQPConnectionException: Parameter 'port' must be a valid port number between 1 and 65535. -AMQPConnectionException: Invalid port given. Value must be between 1 and 65535. +AMQPConnectionException: Parameter 'port' must be a valid port number between 1 and 65535. +AMQPConnectionException: Parameter 'port' must be a valid port number between 1 and 65535. +AMQPConnectionException: Parameter 'port' must be a valid port number between 1 and 65535. +AMQPConnectionException: Parameter 'port' must be a valid port number between 1 and 65535. getPort after constructor: 1234 getPort after setter: 1234 diff --git a/tests/amqpexchange_attributes.phpt b/tests/amqpexchange_attributes.phpt index b242b7c5..c0769829 100644 --- a/tests/amqpexchange_attributes.phpt +++ b/tests/amqpexchange_attributes.phpt @@ -15,20 +15,29 @@ $ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); -$ex->setArguments($arr = array('existent' => 'value', 'false' => false)); +$ex->setArguments($arr = array('existent' => 'value', 'false' => false, 'null' => null)); echo 'Initial args: ', count($arr), ', exchange args: ', count($ex->getArguments()), PHP_EOL; $ex->setArgument('foo', 'bar'); echo 'Initial args: ', count($arr), ', exchange args: ', count($ex->getArguments()), PHP_EOL; -foreach (array('existent', 'false', 'nonexistent') as $key) { - echo "$key: ", var_export($ex->hasArgument($key), true), ', ', var_export($ex->getArgument($key)), PHP_EOL; +foreach (array('existent', 'false', 'null', 'nonexistent') as $key) { + echo "$key: "; + var_export($ex->hasArgument($key)); + echo ', '; + try { + var_export($ex->getArgument($key)); + } catch (AMQPExchangeException $e) { + echo "Ex: " . $e->getMessage(); + } + echo PHP_EOL; } ?> --EXPECT-- -Initial args: 2, exchange args: 2 -Initial args: 2, exchange args: 3 +Initial args: 3, exchange args: 3 +Initial args: 3, exchange args: 4 existent: true, 'value' false: true, false -nonexistent: false, false +null: true, NULL +nonexistent: false, Ex: The argument "nonexistent" does not exist diff --git a/tests/amqpexchange_delete_null_name.phpt b/tests/amqpexchange_delete_null_name.phpt new file mode 100644 index 00000000..cfc94f32 --- /dev/null +++ b/tests/amqpexchange_delete_null_name.phpt @@ -0,0 +1,25 @@ +--TEST-- +AMQPExchange::delete with explicit null as exchange name +--SKIPIF-- + +--FILE-- +connect(); +$chan = new AMQPChannel($con); + +$ex = new AMQPExchange($chan); +$ex->setName('test.queue.' . bin2hex(random_bytes(32))); +$ex->setType(AMQP_EX_TYPE_DIRECT); +$ex->declareExchange(); + +$ex->delete(null); + +// Deleting with explicit null deleted the current exchange, so we should be able to redeclare +$ex->setType(AMQP_EX_TYPE_FANOUT); +$ex->declare(); +$ex->delete(); +?> +==DONE== +--EXPECT-- +==DONE== diff --git a/tests/amqpexchange_setArgument.phpt b/tests/amqpexchange_setArgument.phpt index bf1a60a9..a3379c13 100644 --- a/tests/amqpexchange_setArgument.phpt +++ b/tests/amqpexchange_setArgument.phpt @@ -35,10 +35,12 @@ $ex->setArgument("alternate-exchange", $e_name_ae); $ex->setArgument('x-empty-string', ''); $ex->setArgument('x-alternate-exchange-one-more-time', $e_name_ae); $ex->setArgument('x-numeric-argument', $heartbeat * 10 * 1000); +$ex->setArgument('x-null-argument', null); $ex->declareExchange(); var_dump($ex); -$ex->setArgument('x-alternate-exchange-one-more-time', null); // remov key +$ex->removeArgument('x-null-argument'); +$ex->removeArgument('x-does-not-exist'); var_dump($ex); ?> --EXPECTF-- @@ -81,7 +83,7 @@ object(AMQPExchange)#4 (9) { ["internal":"AMQPExchange":private]=> bool(false) ["arguments":"AMQPExchange":private]=> - array(5) { + array(6) { ["x-ha-policy"]=> string(3) "all" ["alternate-exchange"]=> @@ -92,6 +94,8 @@ object(AMQPExchange)#4 (9) { string(%d) "test.exchange.ae.%s" ["x-numeric-argument"]=> int(100000) + ["x-null-argument"]=> + NULL } } object(AMQPExchange)#4 (9) { @@ -112,13 +116,15 @@ object(AMQPExchange)#4 (9) { ["internal":"AMQPExchange":private]=> bool(false) ["arguments":"AMQPExchange":private]=> - array(4) { + array(5) { ["x-ha-policy"]=> string(3) "all" ["alternate-exchange"]=> string(%d) "test.exchange.ae.%s" ["x-empty-string"]=> string(0) "" + ["x-alternate-exchange-one-more-time"]=> + string(%d) "test.exchange.ae.%s" ["x-numeric-argument"]=> int(100000) } diff --git a/tests/amqpqueue_attributes.phpt b/tests/amqpqueue_attributes.phpt index 0824b5bd..fb7bcc14 100644 --- a/tests/amqpqueue_attributes.phpt +++ b/tests/amqpqueue_attributes.phpt @@ -18,7 +18,15 @@ var_dump($q->setArgument('foo', 'bar')); echo 'Initial args: ', count($arr), ', queue args: ', count($q->getArguments()), PHP_EOL; foreach (array('existent', 'false', 'nonexistent') as $key) { - echo "$key: ", var_export($q->hasArgument($key), true), ', ', var_export($q->getArgument($key)), PHP_EOL; + echo "$key: "; + var_export($q->hasArgument($key)); + echo ', '; + try { + var_export($q->getArgument($key)); + } catch (AMQPQueueException $e) { + echo 'Ex: ', $e->getMessage(); + } + echo PHP_EOL; } ?> @@ -29,4 +37,4 @@ NULL Initial args: 2, queue args: 3 existent: true, 'value' false: true, false -nonexistent: false, NULL +nonexistent: false, Ex: The argument "nonexistent" does not exist diff --git a/tests/amqpqueue_bind_null_routing_key.phpt b/tests/amqpqueue_bind_null_routing_key.phpt index d0ca5b02..57881e3a 100644 --- a/tests/amqpqueue_bind_null_routing_key.phpt +++ b/tests/amqpqueue_bind_null_routing_key.phpt @@ -1,5 +1,5 @@ --TEST-- -AMQPQueue +AMQPQueue bind/unbind with explicit null routing key --SKIPIF-- --FILE-- @@ -18,6 +18,7 @@ $queue = new AMQPQueue($ch); $queue->setName("queue-" . bin2hex(random_bytes(32))); var_dump($queue->declareQueue()); var_dump($queue->bind($ex->getName(), null)); +var_dump($queue->unbind($ex->getName(), null)); var_dump($queue->delete()); var_dump($ex->delete()); @@ -26,5 +27,6 @@ var_dump($ex->delete()); NULL int(0) NULL +NULL int(0) NULL diff --git a/tests/amqpqueue_consume_null_consumer_key.phpt b/tests/amqpqueue_consume_null_consumer_key.phpt new file mode 100644 index 00000000..d8944f8e --- /dev/null +++ b/tests/amqpqueue_consume_null_consumer_key.phpt @@ -0,0 +1,46 @@ +--TEST-- +AMQPQueue::consume basic +--SKIPIF-- + +--FILE-- +connect(); + +$ch = new AMQPChannel($cnn); + +// Declare a new exchange +$ex = new AMQPExchange($ch); +$ex->setName('exchange-' . bin2hex(random_bytes(32))); +$ex->setType(AMQP_EX_TYPE_FANOUT); +$ex->declareExchange(); + +// Create a new queue +$q = new AMQPQueue($ch); +$q->setName('queue-' . bin2hex(random_bytes(32))); +$q->declareQueue(); + +// Bind it on the exchange to routing.key +$q->bind($ex->getName()); + +// Publish a message to the exchange with a routing key +$ex->publish('message1'); + +$count = 0; + +function consume($message, $queue) { + global $count; + var_dump($count++); + return false; +} + +$q->consume(null, AMQP_AUTOACK, null); + +$q->delete(); +$ex->delete(); +?> +==DONE== +--EXPECTF-- +==DONE== \ No newline at end of file diff --git a/tests/amqpqueue_setArgument.phpt b/tests/amqpqueue_setArgument.phpt index d5c72f9e..34219813 100644 --- a/tests/amqpqueue_setArgument.phpt +++ b/tests/amqpqueue_setArgument.phpt @@ -28,11 +28,13 @@ $q_dead->setName($q_dead_name); $q_dead->setArgument('x-dead-letter-exchange', ''); $q_dead->setArgument('x-dead-letter-routing-key', $q_name); $q_dead->setArgument('x-message-ttl', $heartbeat * 10 * 1000); +$q_dead->setArgument('x-null', null); $q_dead->setFlags(AMQP_AUTODELETE); $q_dead->declareQueue(); var_dump($q_dead); -$q_dead->setArgument('x-dead-letter-routing-key', null); // removes this key +$q_dead->removeArgument('x-null'); +$q_dead->removeArgument('x-does-not-exist'); var_dump($q_dead); ?> --EXPECTF-- @@ -75,13 +77,15 @@ object(AMQPQueue)#4 (9) { ["autoDelete":"AMQPQueue":private]=> bool(true) ["arguments":"AMQPQueue":private]=> - array(3) { + array(4) { ["x-dead-letter-exchange"]=> string(0) "" ["x-dead-letter-routing-key"]=> string(%d) "test.queue.%s" ["x-message-ttl"]=> int(100000) + ["x-null"]=> + NULL } } object(AMQPQueue)#4 (9) { @@ -102,9 +106,11 @@ object(AMQPQueue)#4 (9) { ["autoDelete":"AMQPQueue":private]=> bool(true) ["arguments":"AMQPQueue":private]=> - array(2) { + array(3) { ["x-dead-letter-exchange"]=> string(0) "" + ["x-dead-letter-routing-key"]=> + string(%d) "test.queue.%s" ["x-message-ttl"]=> int(100000) } diff --git a/tests/amqpqueue_setFlags.phpt b/tests/amqpqueue_setFlags.phpt new file mode 100644 index 00000000..f420d078 --- /dev/null +++ b/tests/amqpqueue_setFlags.phpt @@ -0,0 +1,20 @@ +--TEST-- +AMQPQueue::setFlags(null) +--SKIPIF-- + +--FILE-- +connect(); + +$ch = new AMQPChannel($cnn); + +$q = new AMQPQueue($ch); +$q->setFlags(null); +var_dump($q->getFlags()) + +?> +==DONE== +--EXPECTF-- +int(0) +==DONE== diff --git a/tests/amqpqueue_unbind_basic_empty_routing_key.phpt b/tests/amqpqueue_unbind_basic_empty_routing_key.phpt index 893da3c0..31e70f75 100644 --- a/tests/amqpqueue_unbind_basic_empty_routing_key.phpt +++ b/tests/amqpqueue_unbind_basic_empty_routing_key.phpt @@ -20,9 +20,14 @@ $queue->declareQueue(); var_dump($queue->bind($ex->getName())); var_dump($queue->unbind($ex->getName())); +var_dump($queue->bind($ex->getName(), null)); +var_dump($queue->unbind($ex->getName(), null)); + $queue->delete(); $ex->delete(); ?> --EXPECT-- NULL NULL +NULL +NULL From 127e9767956460f2d1d133a8b0ff7b5752ccf0d8 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 2 Aug 2023 18:12:51 +0200 Subject: [PATCH 035/147] Document pseudo-bool method changes --- UPGRADING.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/UPGRADING.md b/UPGRADING.md index fb606485..c34f6a8c 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -156,6 +156,10 @@ ## `AMQPConnection` breaking changes +### Change in semantics + +* `connect()`, `pconnect()`, `disconnect()`, `set*()` etc. no longer return true or throw an exception but instead are void and throw + ### Public method additions * `getConnectTimeout(): float` @@ -333,6 +337,7 @@ ### Change in semantics +* `declareExchange()`, `bind()` , etc. no longer return true or throw an exception but instead are void and throw * `setArgument(string $argumentName, null)` no longer unsets the argument `$key` but sets it to `null` instead. To remove an argument use `removeArgument(string $argumentName)` instead * `getArgument(string $argumentName)` now throws an `AMQPExchangeException` if the argument does not exist. It returned false previously @@ -423,6 +428,8 @@ ### Change in semantics +* `declareQueue`, `ack()`, `nack()`, `bind()`, etc. etc. methods no longer return true or throw an exception but instead are void and throw +* `get()` now either return null instead of false if no message was received * `setArgument(string $key, null)` no longer unsets the argument `$key` but sets it to `null` instead. To remove an argument use `removeArgument(string $key)` instead * `getArgument(string $argumentName)` now throws an `AMQPQueueException` if the argument does not exist. It returned false previously From 9a501c133ceb513e74f98df7df378d8e2c75b5d1 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 2 Aug 2023 23:16:49 +0200 Subject: [PATCH 036/147] Mention upgrade guide in README --- README.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 36fab88c..bc44df4a 100644 --- a/README.md +++ b/README.md @@ -35,13 +35,16 @@ If you want to stay on the bleeding edge and have the latest version, install ph ### Documentation -View [RabbitMQ official tutorials](http://www.rabbitmq.com/getstarted.html) -and [php-amqp specific examples](https://github.com/rabbitmq/rabbitmq-tutorials/tree/main/php-amqp). +Check out the official [RabbitMQ tutorials](http://www.rabbitmq.com/getstarted.html) +as well as the [php-amqp specific examples](https://github.com/rabbitmq/rabbitmq-tutorials/tree/main/php-amqp). -There are also available [stub files](https://github.com/php-amqp/php-amqp/tree/latest/stubs) with accurate PHPDoc which -may be also used in your IDE for code completion, navigation and documentation in-place. +There are also [stub files](https://github.com/php-amqp/php-amqp/tree/latest/stubs) available that document the API of +PHP AMQP. These stubs can also be used in your IDE for code completion, navigation and documentation. -Finally, check out the [tests](https://github.com/php-amqp/php-amqp/tree/latest/tests) to see typical usage and edge +Check out the [upgrading guide](https://github.com/php-amqp/php-amqp/tree/latest/UPGRADING.md) to check +breaking changes between versions, e.g. from 1.x to 2.x. + +Finally, check out the [tests](https://github.com/php-amqp/php-amqp/tree/latest/tests) to see usage examples and edge cases. ### Notes From 9032b22be5ecdf1fc63b5b46ce60b124a3a54e3f Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 2 Aug 2023 23:19:41 +0200 Subject: [PATCH 037/147] [RM] releasing version 2.0.0beta1 --- package.xml | 33 +++++++++++++++++++++++---------- php_amqp_version.h | 4 ++-- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/package.xml b/package.xml index ec2af139..f9c45ded 100644 --- a/package.xml +++ b/package.xml @@ -22,23 +22,33 @@ pinepain@gmail.com yes - 2023-07-30 - + 2023-08-02 + - 2.0.0alpha2 - 2.0.0alpha2 + 2.0.0beta1 + 2.0.0beta1 - alpha - alpha + beta + beta PHP License - =0.8.0 (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/441) - - New Docker-based development environment (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/440) - - Prevent duplicate builds (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/442) + ) (https://github.com/php-amqp/php-amqp/issues/0) + - Document pseudo-bool method changes (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/0) + - Fix mangled header on MacOS (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/60) + - Validate argument parsing, add AMQPExchange::removeArgument() and AMQPQueue::removeArgument() (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/452) + - Skip SSL tests if certificates are missing (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/450) + - Bump shivammathur/setup-php from 2.25.4 to 2.25.5 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/449) + - Check coding style and formatting of stub files (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/447) + - Parallelize test execution (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/444) + - Deterministic configuration for PHP CLI (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/443) + - Fix tag creation during release management (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/0) + - Move test-report.sh into infra (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/0) + +💡Check out https://github.com/php-amqp/php-amqp/tree/latest/UPGRADING.md for backward incompatible changes For a complete list of changes see: -https://github.com/php-amqp/php-amqp/compare/v2.0.0alpha1...v2.0.0alpha2]]> +https://github.com/php-amqp/php-amqp/compare/v2.0.0alpha2...v2.0.0beta1]]> @@ -173,6 +183,7 @@ https://github.com/php-amqp/php-amqp/compare/v2.0.0alpha1...v2.0.0alpha2]]> + @@ -215,6 +226,7 @@ https://github.com/php-amqp/php-amqp/compare/v2.0.0alpha1...v2.0.0alpha2]]> + @@ -235,6 +247,7 @@ https://github.com/php-amqp/php-amqp/compare/v2.0.0alpha1...v2.0.0alpha2]]> + diff --git a/php_amqp_version.h b/php_amqp_version.h index ab84af23..315b0cbe 100644 --- a/php_amqp_version.h +++ b/php_amqp_version.h @@ -1,6 +1,6 @@ #define PHP_AMQP_VERSION_MAJOR 2 #define PHP_AMQP_VERSION_MINOR 0 #define PHP_AMQP_VERSION_PATCH 0 -#define PHP_AMQP_VERSION_EXTRA "alpha2" -#define PHP_AMQP_VERSION "2.0.0alpha2" +#define PHP_AMQP_VERSION_EXTRA "beta1" +#define PHP_AMQP_VERSION "2.0.0beta1" #define PHP_AMQP_VERSION_ID 20000 From 17b2f177c2d655e045e2f03375d7ad7bc24d5b45 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 2 Aug 2023 23:32:45 +0200 Subject: [PATCH 038/147] [RM] back to dev 2.0.0dev --- package.xml | 56 ++++++++++++++++++++++++++++++---------------- php_amqp_version.h | 4 ++-- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/package.xml b/package.xml index f9c45ded..03d0b6c2 100644 --- a/package.xml +++ b/package.xml @@ -23,32 +23,21 @@ yes 2023-08-02 - + - 2.0.0beta1 - 2.0.0beta1 + 2.0.0dev + 2.0.0dev - beta - beta + devel + devel PHP License - ) (https://github.com/php-amqp/php-amqp/issues/0) - - Document pseudo-bool method changes (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/0) - - Fix mangled header on MacOS (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/60) - - Validate argument parsing, add AMQPExchange::removeArgument() and AMQPQueue::removeArgument() (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/452) - - Skip SSL tests if certificates are missing (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/450) - - Bump shivammathur/setup-php from 2.25.4 to 2.25.5 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/449) - - Check coding style and formatting of stub files (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/447) - - Parallelize test execution (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/444) - - Deterministic configuration for PHP CLI (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/443) - - Fix tag creation during release management (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/0) - - Move test-report.sh into infra (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/0) - -💡Check out https://github.com/php-amqp/php-amqp/tree/latest/UPGRADING.md for backward incompatible changes + +https://github.com/php-amqp/php-amqp/compare/v2.0.0beta1...latest +]]> @@ -305,6 +294,35 @@ https://github.com/php-amqp/php-amqp/compare/v2.0.0alpha2...v2.0.0beta1]]> + + 2023-08-02 + + + 2.0.0beta1 + 2.0.0beta1 + + + beta + beta + + PHP License + ) (https://github.com/php-amqp/php-amqp/issues/0) + - Document pseudo-bool method changes (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/0) + - Fix mangled header on MacOS (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/60) + - Validate argument parsing, add AMQPExchange::removeArgument() and AMQPQueue::removeArgument() (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/452) + - Skip SSL tests if certificates are missing (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/450) + - Bump shivammathur/setup-php from 2.25.4 to 2.25.5 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/449) + - Check coding style and formatting of stub files (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/447) + - Parallelize test execution (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/444) + - Deterministic configuration for PHP CLI (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/443) + - Fix tag creation during release management (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/0) + - Move test-report.sh into infra (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/0) + +💡Check out https://github.com/php-amqp/php-amqp/tree/latest/UPGRADING.md for backward incompatible changes + +For a complete list of changes see: +https://github.com/php-amqp/php-amqp/compare/v2.0.0alpha2...v2.0.0beta1]]> + 2023-07-29 diff --git a/php_amqp_version.h b/php_amqp_version.h index 315b0cbe..300dc520 100644 --- a/php_amqp_version.h +++ b/php_amqp_version.h @@ -1,6 +1,6 @@ #define PHP_AMQP_VERSION_MAJOR 2 #define PHP_AMQP_VERSION_MINOR 0 #define PHP_AMQP_VERSION_PATCH 0 -#define PHP_AMQP_VERSION_EXTRA "beta1" -#define PHP_AMQP_VERSION "2.0.0beta1" +#define PHP_AMQP_VERSION_EXTRA "dev" +#define PHP_AMQP_VERSION "2.0.0dev" #define PHP_AMQP_VERSION_ID 20000 From e7437a9e7d3ff5054d90a7613de77c87a424cdce Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 3 Aug 2023 08:09:38 +0200 Subject: [PATCH 039/147] Fix segfault in setPort (#455) --- amqp_connection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amqp_connection.c b/amqp_connection.c index 40c2859d..d8f71b12 100644 --- a/amqp_connection.c +++ b/amqp_connection.c @@ -1165,7 +1165,7 @@ static PHP_METHOD(amqp_connection_class, getPort) set the port */ static PHP_METHOD(amqp_connection_class, setPort) { - int port; + zend_long port; /* Get the port from the method params */ if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &port) == FAILURE) { From 1f3c14bd2181d3b40f9af62992a110d7b69d6543 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Thu, 3 Aug 2023 08:18:06 +0200 Subject: [PATCH 040/147] Include stdint.h for PHP >= 8.0 on Windows (#456) Patch by Jan Ehrhardt (Jan-E), https://github.com/php-amqp/php-amqp/issues/424#issuecomment-1663227587 --- amqp.c | 2 +- amqp_basic_properties.c | 2 +- amqp_channel.c | 2 +- amqp_connection.c | 2 +- amqp_connection_resource.c | 2 +- amqp_envelope.c | 2 +- amqp_exchange.c | 2 +- amqp_queue.c | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/amqp.c b/amqp.c index 2d9bf48b..d3e77fed 100644 --- a/amqp.c +++ b/amqp.c @@ -32,7 +32,7 @@ #ifdef PHP_WIN32 #if PHP_VERSION_ID >= 80000 - #include "main/php_stdint.h" + #include #else #include "win32/php_stdint.h" #endif diff --git a/amqp_basic_properties.c b/amqp_basic_properties.c index 54ea02b6..bf92ab10 100644 --- a/amqp_basic_properties.c +++ b/amqp_basic_properties.c @@ -40,7 +40,7 @@ #ifdef PHP_WIN32 #include "win32/unistd.h" #if PHP_VERSION_ID >= 80000 - #include "main/php_stdint.h" + #include #else #include "win32/php_stdint.h" #endif diff --git a/amqp_channel.c b/amqp_channel.c index 5fa92e7c..d48f0d1f 100644 --- a/amqp_channel.c +++ b/amqp_channel.c @@ -30,7 +30,7 @@ #ifdef PHP_WIN32 #if PHP_VERSION_ID >= 80000 - #include "main/php_stdint.h" + #include #else #include "win32/php_stdint.h" #endif diff --git a/amqp_connection.c b/amqp_connection.c index d8f71b12..ed5c6507 100644 --- a/amqp_connection.c +++ b/amqp_connection.c @@ -32,7 +32,7 @@ #ifdef PHP_WIN32 #if PHP_VERSION_ID >= 80000 - #include "main/php_stdint.h" + #include #else #include "win32/php_stdint.h" #endif diff --git a/amqp_connection_resource.c b/amqp_connection_resource.c index 18cbf001..7cf2abba 100644 --- a/amqp_connection_resource.c +++ b/amqp_connection_resource.c @@ -31,7 +31,7 @@ #ifdef PHP_WIN32 #if PHP_VERSION_ID >= 80000 - #include "main/php_stdint.h" + #include #else #include "win32/php_stdint.h" #endif diff --git a/amqp_envelope.c b/amqp_envelope.c index c817c0b0..748a104c 100644 --- a/amqp_envelope.c +++ b/amqp_envelope.c @@ -29,7 +29,7 @@ #ifdef PHP_WIN32 #if PHP_VERSION_ID >= 80000 - #include "main/php_stdint.h" + #include #else #include "win32/php_stdint.h" #endif diff --git a/amqp_exchange.c b/amqp_exchange.c index bd7f623e..6c2ae5ad 100644 --- a/amqp_exchange.c +++ b/amqp_exchange.c @@ -29,7 +29,7 @@ #ifdef PHP_WIN32 #if PHP_VERSION_ID >= 80000 - #include "main/php_stdint.h" + #include #else #include "win32/php_stdint.h" #endif diff --git a/amqp_queue.c b/amqp_queue.c index a6990df3..5fb10278 100644 --- a/amqp_queue.c +++ b/amqp_queue.c @@ -30,7 +30,7 @@ #ifdef PHP_WIN32 #if PHP_VERSION_ID >= 80000 - #include "main/php_stdint.h" + #include #else #include "win32/php_stdint.h" #endif From 9e3fc879849138a7a285bab86618eb1450465df3 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Thu, 3 Aug 2023 08:22:40 +0200 Subject: [PATCH 041/147] [RM] releasing version 2.0.0beta2 --- package.xml | 20 +++++++++++--------- php_amqp_version.h | 4 ++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/package.xml b/package.xml index 03d0b6c2..2a0fb56b 100644 --- a/package.xml +++ b/package.xml @@ -22,22 +22,24 @@ pinepain@gmail.com yes - 2023-08-02 - + 2023-08-03 + - 2.0.0dev - 2.0.0dev + 2.0.0beta2 + 2.0.0beta2 - devel - devel + beta + beta PHP License - = 8.0 on Windows (Jan Ehrhardt) (https://github.com/php-amqp/php-amqp/issues/456) + - Fix segfault in setPort (Remi Collet ) (https://github.com/php-amqp/php-amqp/issues/455) + +💡Check out https://github.com/php-amqp/php-amqp/tree/latest/UPGRADING.md for backward incompatible changes For a complete list of changes see: -https://github.com/php-amqp/php-amqp/compare/v2.0.0beta1...latest -]]> +https://github.com/php-amqp/php-amqp/compare/v2.0.0beta1...v2.0.0beta2]]> diff --git a/php_amqp_version.h b/php_amqp_version.h index 300dc520..88d4745d 100644 --- a/php_amqp_version.h +++ b/php_amqp_version.h @@ -1,6 +1,6 @@ #define PHP_AMQP_VERSION_MAJOR 2 #define PHP_AMQP_VERSION_MINOR 0 #define PHP_AMQP_VERSION_PATCH 0 -#define PHP_AMQP_VERSION_EXTRA "dev" -#define PHP_AMQP_VERSION "2.0.0dev" +#define PHP_AMQP_VERSION_EXTRA "beta2" +#define PHP_AMQP_VERSION "2.0.0beta2" #define PHP_AMQP_VERSION_ID 20000 From faa6dfd138017c0918d2181832a3dc65fc326e37 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Thu, 3 Aug 2023 08:24:13 +0200 Subject: [PATCH 042/147] [RM] back to dev 2.0.0dev --- package.xml | 38 ++++++++++++++++++++++++++++---------- php_amqp_version.h | 4 ++-- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/package.xml b/package.xml index 2a0fb56b..9cece098 100644 --- a/package.xml +++ b/package.xml @@ -23,23 +23,21 @@ yes 2023-08-03 - + - 2.0.0beta2 - 2.0.0beta2 + 2.0.0dev + 2.0.0dev - beta - beta + devel + devel PHP License - = 8.0 on Windows (Jan Ehrhardt) (https://github.com/php-amqp/php-amqp/issues/456) - - Fix segfault in setPort (Remi Collet ) (https://github.com/php-amqp/php-amqp/issues/455) - -💡Check out https://github.com/php-amqp/php-amqp/tree/latest/UPGRADING.md for backward incompatible changes + +https://github.com/php-amqp/php-amqp/compare/v2.0.0beta2...latest +]]> @@ -296,6 +294,26 @@ https://github.com/php-amqp/php-amqp/compare/v2.0.0beta1...v2.0.0beta2]]> + + 2023-08-03 + + + 2.0.0beta2 + 2.0.0beta2 + + + beta + beta + + PHP License + = 8.0 on Windows (Jan Ehrhardt) (https://github.com/php-amqp/php-amqp/issues/456) + - Fix segfault in setPort (Remi Collet ) (https://github.com/php-amqp/php-amqp/issues/455) + +💡Check out https://github.com/php-amqp/php-amqp/tree/latest/UPGRADING.md for backward incompatible changes + +For a complete list of changes see: +https://github.com/php-amqp/php-amqp/compare/v2.0.0beta1...v2.0.0beta2]]> + 2023-08-02 diff --git a/php_amqp_version.h b/php_amqp_version.h index 88d4745d..300dc520 100644 --- a/php_amqp_version.h +++ b/php_amqp_version.h @@ -1,6 +1,6 @@ #define PHP_AMQP_VERSION_MAJOR 2 #define PHP_AMQP_VERSION_MINOR 0 #define PHP_AMQP_VERSION_PATCH 0 -#define PHP_AMQP_VERSION_EXTRA "beta2" -#define PHP_AMQP_VERSION "2.0.0beta2" +#define PHP_AMQP_VERSION_EXTRA "dev" +#define PHP_AMQP_VERSION "2.0.0dev" #define PHP_AMQP_VERSION_ID 20000 From 044386f1d8e676fbddc733e79599657244af496b Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Thu, 3 Aug 2023 10:39:02 +0200 Subject: [PATCH 043/147] Stricter CFLAGS for GH actions --- .env | 2 +- .github/workflows/test.yaml | 2 +- infra/php/Dockerfile | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.env b/.env index 7f5e3ad6..6d1dd4eb 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ PHP_AMQP_SSL_HOST=rabbitmq.example.org MAKEFLAGS="-j16" -CFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror" +CFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-strong -fstack-clash-protection -Wall -Werror" TEST_PHP_ARGS="-j16" diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 2118c81b..1c9698fc 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -7,7 +7,7 @@ on: env: TEST_TIMEOUT: 120 - CFLAGS: -D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror + CFLAGS: -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fstack-clash-protection -Wall -Werror -cf-protection PHP_AMQP_SSL_HOST: rabbitmq.example.org MAKEFLAGS: -j4 diff --git a/infra/php/Dockerfile b/infra/php/Dockerfile index 603382c8..1efda92b 100644 --- a/infra/php/Dockerfile +++ b/infra/php/Dockerfile @@ -12,6 +12,7 @@ RUN apt-get install -yqq gdb RUN apt-get install -yqq valgrind RUN apt-get install -yqq git RUN apt-get install -yqq unzip +RUN apt-get install -yqq clang RUN echo 'PATH=$PATH:/src/infra/tools' >> /etc/bash.bashrc From 2938d96e691c90e3b4a78512e212334274a7c4e8 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Thu, 3 Aug 2023 10:40:22 +0200 Subject: [PATCH 044/147] Revert "Stricter CFLAGS for GH actions" This reverts commit 044386f1d8e676fbddc733e79599657244af496b. --- .env | 2 +- .github/workflows/test.yaml | 2 +- infra/php/Dockerfile | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.env b/.env index 6d1dd4eb..7f5e3ad6 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ PHP_AMQP_SSL_HOST=rabbitmq.example.org MAKEFLAGS="-j16" -CFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-strong -fstack-clash-protection -Wall -Werror" +CFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror" TEST_PHP_ARGS="-j16" diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1c9698fc..2118c81b 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -7,7 +7,7 @@ on: env: TEST_TIMEOUT: 120 - CFLAGS: -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fstack-clash-protection -Wall -Werror -cf-protection + CFLAGS: -D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror PHP_AMQP_SSL_HOST: rabbitmq.example.org MAKEFLAGS: -j4 diff --git a/infra/php/Dockerfile b/infra/php/Dockerfile index 1efda92b..603382c8 100644 --- a/infra/php/Dockerfile +++ b/infra/php/Dockerfile @@ -12,7 +12,6 @@ RUN apt-get install -yqq gdb RUN apt-get install -yqq valgrind RUN apt-get install -yqq git RUN apt-get install -yqq unzip -RUN apt-get install -yqq clang RUN echo 'PATH=$PATH:/src/infra/tools' >> /etc/bash.bashrc From c7591b836afc5c1da637dce048bfe1c70d149d68 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Thu, 3 Aug 2023 12:09:32 +0200 Subject: [PATCH 045/147] Build with the clang compiler on CI (#457) --- .github/workflows/test.yaml | 6 ++++-- amqp.c | 2 +- infra/php/Dockerfile | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 2118c81b..f1ee978e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -92,7 +92,7 @@ jobs: if: matrix.php-version == '8.2' test: - name: ${{ matrix.test-php-args == '-m' && 'Memtest' || 'Test' }} php-${{ matrix.php-version }}${{ matrix.php-thread-safe && '-ts' || '-nts' }} librabbitmq-${{ matrix.librabbitmq-version }} + name: ${{ matrix.test-php-args == '-m' && 'Memtest' || 'Test' }} php-${{ matrix.php-version }}${{ matrix.php-thread-safe && '-ts' || '-nts' }} librabbitmq-${{ matrix.librabbitmq-version }} ${{ matrix.compiler }} # librabbitmq < 0.11 needs older OpenSSL version runs-on: ${{ (matrix.librabbitmq-version == '0.10.0' || matrix.librabbitmq-version == '0.9.0' || matrix.librabbitmq-version == '0.8.0') && 'ubuntu-20.04' || 'ubuntu-22.04' }} needs: dedup @@ -100,6 +100,7 @@ jobs: env: TEST_PHP_ARGS: -j4 ${{ matrix.test-php-args }} + CC: ${{ matrix.compiler }} strategy: fail-fast: false @@ -107,6 +108,7 @@ jobs: php-version: [ '8.2', '8.1', '8.0', '7.4' ] php-thread-safe: [ true, false ] librabbitmq-version: [ 'master', '0.13.0', '0.12.0', '0.11.0', '0.10.0', '0.9.0', '0.8.0' ] + compiler: [gcc, clang] include: - php-version: '8.2' php-thread-safe: false @@ -132,7 +134,7 @@ jobs: run: docker compose up -d rabbitmq - name: Install packages - run: sudo apt-get install -y cmake valgrind + run: sudo apt-get install -y cmake valgrind ${{ matrix.compiler }} - name: Setup PHP uses: shivammathur/setup-php@2.25.5 diff --git a/amqp.c b/amqp.c index d3e77fed..c169c8d3 100644 --- a/amqp.c +++ b/amqp.c @@ -217,7 +217,7 @@ PHP_INI_BEGIN() PHP_INI_ENTRY("amqp.cert", DEFAULT_CERT, PHP_INI_ALL, NULL) PHP_INI_ENTRY("amqp.key", DEFAULT_KEY, PHP_INI_ALL, NULL) PHP_INI_ENTRY("amqp.verify", DEFAULT_VERIFY, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("amqp.sasl_method", DEFAULT_SASL_METHOD, PHP_INI_ALL, NULL) + PHP_INI_ENTRY("amqp.sasl_method", (const char *) DEFAULT_SASL_METHOD, PHP_INI_ALL, NULL) PHP_INI_END() ZEND_DECLARE_MODULE_GLOBALS(amqp) diff --git a/infra/php/Dockerfile b/infra/php/Dockerfile index 603382c8..1efda92b 100644 --- a/infra/php/Dockerfile +++ b/infra/php/Dockerfile @@ -12,6 +12,7 @@ RUN apt-get install -yqq gdb RUN apt-get install -yqq valgrind RUN apt-get install -yqq git RUN apt-get install -yqq unzip +RUN apt-get install -yqq clang RUN echo 'PATH=$PATH:/src/infra/tools' >> /etc/bash.bashrc From c5b259b826d2be685ce7809bfd017eb74fbf28a8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 4 Aug 2023 09:30:46 +0200 Subject: [PATCH 046/147] Bump phpstan/phpdoc-parser from 1.23.0 to 1.23.1 (#458) --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index fd91135d..b4223b1b 100644 --- a/composer.lock +++ b/composer.lock @@ -87,16 +87,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.23.0", + "version": "1.23.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "a2b24135c35852b348894320d47b3902a94bc494" + "reference": "846ae76eef31c6d7790fac9bc399ecee45160b26" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/a2b24135c35852b348894320d47b3902a94bc494", - "reference": "a2b24135c35852b348894320d47b3902a94bc494", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/846ae76eef31c6d7790fac9bc399ecee45160b26", + "reference": "846ae76eef31c6d7790fac9bc399ecee45160b26", "shasum": "" }, "require": { @@ -128,9 +128,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.23.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.23.1" }, - "time": "2023-07-23T22:17:56+00:00" + "time": "2023-08-03T16:32:59+00:00" }, { "name": "slevomat/coding-standard", From 045ec20b4357d6f6a16ea6941e2cabf68a7c345c Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Fri, 11 Aug 2023 09:23:02 +0200 Subject: [PATCH 047/147] Gracefully handle zero as a heartbeat value (#459) --- amqp.c | 2 +- tests/amqpconnection_validation.phpt | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/amqp.c b/amqp.c index c169c8d3..1cfc7b3b 100644 --- a/amqp.c +++ b/amqp.c @@ -101,7 +101,7 @@ zend_bool php_amqp_is_valid_channel_max(zend_long val) { return val > 0 && val < zend_bool php_amqp_is_valid_frame_size_max(zend_long val) { return val > 0 && val <= PHP_AMQP_MAX_FRAME_SIZE; } -zend_bool php_amqp_is_valid_heartbeat(zend_long val) { return val > 0 && val <= PHP_AMQP_MAX_HEARTBEAT; } +zend_bool php_amqp_is_valid_heartbeat(zend_long val) { return val >= 0 && val <= PHP_AMQP_MAX_HEARTBEAT; } zend_bool php_amqp_is_valid_prefetch_size(zend_long val) { return val >= 0 && val <= PHP_AMQP_MAX_PREFETCH_SIZE; } diff --git a/tests/amqpconnection_validation.phpt b/tests/amqpconnection_validation.phpt index 60e6c7c4..c0fcee6f 100644 --- a/tests/amqpconnection_validation.phpt +++ b/tests/amqpconnection_validation.phpt @@ -15,13 +15,13 @@ $parameters = [ ['vhost', 'setVhost', 'getVhost', [str_repeat('X', 513), 'vhost']], ['port', 'setPort', 'getPort', [-1, 65536, 1234]], ['timeout', 'setTimeout', 'getTimeout', [-1], 10], - ['read_timeout', 'setReadTimeout', 'getReadTimeout', [-1], 20], - ['write_timeout', 'setWriteTimeout', 'getWriteTimeout', [-1], 30], - ['connect_timeout', null, 'getConnectTimeout', [-1], 40], - ['rpc_timeout', 'setRpcTimeout', 'getRpcTimeout', [-1], 50], - ['frame_max', null, 'getMaxFrameSize', [-1, PHP_INT_MAX + 1], 128], - ['channel_max', null, 'getMaxChannels', [-1, 257], 128], - ['heartbeat', null, 'getHeartbeatInterval', [-1, PHP_INT_MAX + 1], 250], + ['read_timeout', 'setReadTimeout', 'getReadTimeout', [-1, 20]], + ['write_timeout', 'setWriteTimeout', 'getWriteTimeout', [-1, 30]], + ['connect_timeout', null, 'getConnectTimeout', [-1, 40]], + ['rpc_timeout', 'setRpcTimeout', 'getRpcTimeout', [-1, 50]], + ['frame_max', null, 'getMaxFrameSize', [-1, PHP_INT_MAX + 1, 128]], + ['channel_max', null, 'getMaxChannels', [-1, 257, 128]], + ['heartbeat', null, 'getHeartbeatInterval', [-1, PHP_INT_MAX + 1, 250, 0]], ]; foreach ($parameters as $args) { @@ -89,15 +89,26 @@ Deprecated: AMQPConnection::setTimeout(): AMQPConnection::setTimeout($timeout) m AMQPConnectionException: Parameter 'timeout' must be greater than or equal to zero. AMQPConnectionException: Parameter 'read_timeout' must be greater than or equal to zero. AMQPConnectionException: Parameter 'readTimeout' must be greater than or equal to zero. +getReadTimeout after constructor: 20 +getReadTimeout after setter: 20 AMQPConnectionException: Parameter 'write_timeout' must be greater than or equal to zero. AMQPConnectionException: Parameter 'writeTimeout' must be greater than or equal to zero. +getWriteTimeout after constructor: 30 +getWriteTimeout after setter: 30 AMQPConnectionException: Parameter 'connect_timeout' must be greater than or equal to zero. +getConnectTimeout after constructor: 40 AMQPConnectionException: Parameter 'rpc_timeout' must be greater than or equal to zero. AMQPConnectionException: Parameter 'rpcTimeout' must be greater than or equal to zero. +getRpcTimeout after constructor: 50 +getRpcTimeout after setter: 50 AMQPConnectionException: Parameter 'frame_max' is out of range. AMQPConnectionException: Parameter 'frame_max' is out of range. +getMaxFrameSize after constructor: 128 AMQPConnectionException: Parameter 'channel_max' is out of range. AMQPConnectionException: Parameter 'channel_max' is out of range. +getMaxChannels after constructor: 128 AMQPConnectionException: Parameter 'heartbeat' is out of range. AMQPConnectionException: Parameter 'heartbeat' is out of range. +getHeartbeatInterval after constructor: 250 +getHeartbeatInterval after constructor: 0 ==DONE== \ No newline at end of file From c7d76c700b4ff1ee6714907ad3f574509fb58b01 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Tue, 15 Aug 2023 12:01:04 +0200 Subject: [PATCH 048/147] Prevent reuse of channel ID of broken channels (#460) --- .clang-format | 3 ++ amqp_basic_properties.c | 28 +++++++++---------- amqp_channel.c | 49 +++++++++++++++++++++++---------- amqp_channel.h | 2 +- amqp_connection.c | 56 +++++++++++++++++++------------------- amqp_connection_resource.c | 2 +- amqp_decimal.c | 4 +-- amqp_envelope.c | 14 +++++----- amqp_envelope_exception.c | 2 +- amqp_exchange.c | 16 +++++------ amqp_queue.c | 20 ++++++-------- amqp_timestamp.c | 4 +-- infra/php/Dockerfile | 2 +- tests/bug_gh50-1.phpt | 2 +- tests/bug_gh50-3.phpt | 4 +-- 15 files changed, 112 insertions(+), 96 deletions(-) diff --git a/.clang-format b/.clang-format index a79780cd..86a24b08 100644 --- a/.clang-format +++ b/.clang-format @@ -29,6 +29,9 @@ Macros: - "ZEND_HASH_FOREACH_STR_KEY(a, b)=do {" - "ZEND_HASH_FOREACH_STR_KEY_VAL(a, b, c)=do {" - "ZEND_HASH_FOREACH_END=} while(true)" + - "PHP_AMQP_MAYBE_ERROR(a, b)=(a && b)" +StatementMacros: + - PHP_AMQP_NOPARAMS BraceWrapping: AfterCaseLabel: false AfterClass: false diff --git a/amqp_basic_properties.c b/amqp_basic_properties.c index bf92ab10..27b03058 100644 --- a/amqp_basic_properties.c +++ b/amqp_basic_properties.c @@ -226,7 +226,7 @@ static PHP_METHOD(AMQPBasicProperties, __construct) static PHP_METHOD(AMQPBasicProperties, getContentType) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("contentType"); } /* }}} */ @@ -235,7 +235,7 @@ static PHP_METHOD(AMQPBasicProperties, getContentType) static PHP_METHOD(AMQPBasicProperties, getContentEncoding) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("contentEncoding"); } /* }}} */ @@ -244,7 +244,7 @@ static PHP_METHOD(AMQPBasicProperties, getContentEncoding) static PHP_METHOD(AMQPBasicProperties, getHeaders) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("headers"); } /* }}} */ @@ -253,7 +253,7 @@ static PHP_METHOD(AMQPBasicProperties, getHeaders) static PHP_METHOD(AMQPBasicProperties, getDeliveryMode) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("deliveryMode"); } /* }}} */ @@ -262,7 +262,7 @@ static PHP_METHOD(AMQPBasicProperties, getDeliveryMode) static PHP_METHOD(AMQPBasicProperties, getPriority) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("priority"); } /* }}} */ @@ -271,7 +271,7 @@ static PHP_METHOD(AMQPBasicProperties, getPriority) static PHP_METHOD(AMQPBasicProperties, getCorrelationId) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("correlationId"); } /* }}} */ @@ -280,7 +280,7 @@ static PHP_METHOD(AMQPBasicProperties, getCorrelationId) static PHP_METHOD(AMQPBasicProperties, getReplyTo) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("replyTo"); } /* }}} */ @@ -290,7 +290,7 @@ check amqp envelope */ static PHP_METHOD(AMQPBasicProperties, getExpiration) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("expiration"); } /* }}} */ @@ -299,7 +299,7 @@ static PHP_METHOD(AMQPBasicProperties, getExpiration) static PHP_METHOD(AMQPBasicProperties, getMessageId) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("messageId"); } /* }}} */ @@ -308,7 +308,7 @@ static PHP_METHOD(AMQPBasicProperties, getMessageId) static PHP_METHOD(AMQPBasicProperties, getTimestamp) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("timestamp"); } /* }}} */ @@ -317,7 +317,7 @@ static PHP_METHOD(AMQPBasicProperties, getTimestamp) static PHP_METHOD(AMQPBasicProperties, getType) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("type"); } /* }}} */ @@ -326,7 +326,7 @@ static PHP_METHOD(AMQPBasicProperties, getType) static PHP_METHOD(AMQPBasicProperties, getUserId) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("userId"); } /* }}} */ @@ -335,7 +335,7 @@ static PHP_METHOD(AMQPBasicProperties, getUserId) static PHP_METHOD(AMQPBasicProperties, getAppId) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("appId"); } /* }}} */ @@ -344,7 +344,7 @@ static PHP_METHOD(AMQPBasicProperties, getAppId) static PHP_METHOD(AMQPBasicProperties, getClusterId) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("clusterId"); } /* }}} */ diff --git a/amqp_channel.c b/amqp_channel.c index d48f0d1f..64b1fc00 100644 --- a/amqp_channel.c +++ b/amqp_channel.c @@ -65,7 +65,7 @@ zend_class_entry *amqp_channel_class_entry; zend_object_handlers amqp_channel_object_handlers; -void php_amqp_close_channel(amqp_channel_resource *channel_resource, zend_bool check_errors) +void php_amqp_close_channel(amqp_channel_resource *channel_resource, zend_bool throw) { assert(channel_resource != NULL); @@ -90,16 +90,35 @@ void php_amqp_close_channel(amqp_channel_resource *channel_resource, zend_bool c if (connection_resource && connection_resource->is_connected && channel_resource->channel_id > 0) { assert(connection_resource != NULL); - amqp_channel_close(connection_resource->connection_state, channel_resource->channel_id, AMQP_REPLY_SUCCESS); + amqp_rpc_reply_t close_res = + amqp_channel_close(connection_resource->connection_state, channel_resource->channel_id, AMQP_REPLY_SUCCESS); - amqp_rpc_reply_t res = amqp_get_rpc_reply(connection_resource->connection_state); + if (throw && PHP_AMQP_MAYBE_ERROR(close_res, channel_resource)) { + php_amqp_zend_throw_exception_short(close_res, amqp_channel_exception_class_entry); + goto err; + } - if (check_errors && PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { - php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); - return; + if (close_res.reply_type != AMQP_RESPONSE_NORMAL) { + goto err; + } + + amqp_rpc_reply_t reply_res = amqp_get_rpc_reply(connection_resource->connection_state); + if (throw && PHP_AMQP_MAYBE_ERROR(reply_res, channel_resource)) { + php_amqp_zend_throw_exception_short(reply_res, amqp_channel_exception_class_entry); + goto err; + } + + if (reply_res.reply_type != AMQP_RESPONSE_NORMAL) { + goto err; } php_amqp_maybe_release_buffers_on_channel(connection_resource, channel_resource); + return; + + err: + // Mark failed slot as used + connection_resource->used_slots++; + return; } } @@ -444,7 +463,7 @@ static PHP_METHOD(amqp_channel_class, isConnected) { amqp_channel_resource *channel_resource; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); @@ -458,7 +477,7 @@ static PHP_METHOD(amqp_channel_class, close) { amqp_channel_resource *channel_resource; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); @@ -474,7 +493,7 @@ static PHP_METHOD(amqp_channel_class, getChannelId) { amqp_channel_resource *channel_resource; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); @@ -569,7 +588,7 @@ get the number of prefetches */ static PHP_METHOD(amqp_channel_class, getPrefetchCount) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("prefetchCount") } /* }}} */ @@ -656,7 +675,7 @@ get the number of prefetches */ static PHP_METHOD(amqp_channel_class, getPrefetchSize) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("prefetchSize") } /* }}} */ @@ -723,7 +742,7 @@ get the number of prefetches */ static PHP_METHOD(amqp_channel_class, getGlobalPrefetchCount) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("globalPrefetchCount") } /* }}} */ @@ -790,7 +809,7 @@ get the number of prefetches */ static PHP_METHOD(amqp_channel_class, getGlobalPrefetchSize) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("globalPrefetchSize") } /* }}} */ @@ -980,7 +999,7 @@ Get the AMQPConnection object in use */ static PHP_METHOD(amqp_channel_class, getConnection) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("connection") } /* }}} */ @@ -1366,7 +1385,7 @@ PHP_METHOD(amqp_channel_class, waitForConfirm) static PHP_METHOD(amqp_channel_class, getConsumers) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("consumers"); } /* }}} */ diff --git a/amqp_channel.h b/amqp_channel.h index 80e60dee..ca4dcb59 100644 --- a/amqp_channel.h +++ b/amqp_channel.h @@ -24,6 +24,6 @@ extern zend_class_entry *amqp_channel_class_entry; -void php_amqp_close_channel(amqp_channel_resource *channel_resource, zend_bool check_errors); +void php_amqp_close_channel(amqp_channel_resource *channel_resource, zend_bool throw); PHP_MINIT_FUNCTION(amqp_channel); diff --git a/amqp_connection.c b/amqp_connection.c index ed5c6507..a2b6a836 100644 --- a/amqp_connection.c +++ b/amqp_connection.c @@ -814,7 +814,7 @@ static PHP_METHOD(amqp_connection_class, isConnected) { amqp_connection_object *connection; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() /* Get the connection object out of the store */ connection = PHP_AMQP_GET_CONNECTION(getThis()); @@ -830,7 +830,7 @@ static PHP_METHOD(amqp_connection_class, connect) { amqp_connection_object *connection; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() /* Get the connection object out of the store */ connection = PHP_AMQP_GET_CONNECTION(getThis()); @@ -859,7 +859,7 @@ static PHP_METHOD(amqp_connection_class, pconnect) { amqp_connection_object *connection; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() /* Get the connection object out of the store */ connection = PHP_AMQP_GET_CONNECTION(getThis()); @@ -892,7 +892,7 @@ static PHP_METHOD(amqp_connection_class, pdisconnect) { amqp_connection_object *connection; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() /* Get the connection object out of the store */ connection = PHP_AMQP_GET_CONNECTION(getThis()); @@ -927,7 +927,7 @@ static PHP_METHOD(amqp_connection_class, disconnect) { amqp_connection_object *connection; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() /* Get the connection object out of the store */ connection = PHP_AMQP_GET_CONNECTION(getThis()); @@ -962,7 +962,7 @@ static PHP_METHOD(amqp_connection_class, reconnect) { amqp_connection_object *connection; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() /* Get the connection object out of the store */ connection = PHP_AMQP_GET_CONNECTION(getThis()); @@ -997,7 +997,7 @@ static PHP_METHOD(amqp_connection_class, preconnect) { amqp_connection_object *connection; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() /* Get the connection object out of the store */ connection = PHP_AMQP_GET_CONNECTION(getThis()); @@ -1033,7 +1033,7 @@ get the login */ static PHP_METHOD(amqp_connection_class, getLogin) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("login"); } /* }}} */ @@ -1071,7 +1071,7 @@ get the password */ static PHP_METHOD(amqp_connection_class, getPassword) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("password"); } /* }}} */ @@ -1116,7 +1116,7 @@ get the host */ static PHP_METHOD(amqp_connection_class, getHost) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("host"); } /* }}} */ @@ -1155,7 +1155,7 @@ get the port */ static PHP_METHOD(amqp_connection_class, getPort) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("port"); } /* }}} */ @@ -1193,7 +1193,7 @@ get the vhost */ static PHP_METHOD(amqp_connection_class, getVhost) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("vhost"); } /* }}} */ @@ -1237,7 +1237,7 @@ static PHP_METHOD(amqp_connection_class, getTimeout) ); zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("readTimeout"); } /* }}} */ @@ -1293,7 +1293,7 @@ get the read timeout */ static PHP_METHOD(amqp_connection_class, getReadTimeout) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("readTimeout"); } /* }}} */ @@ -1341,7 +1341,7 @@ get write timeout */ static PHP_METHOD(amqp_connection_class, getWriteTimeout) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("writeTimeout"); } /* }}} */ @@ -1389,7 +1389,7 @@ get rpc timeout */ static PHP_METHOD(amqp_connection_class, getConnectTimeout) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("connectTimeout"); } /* }}} */ @@ -1399,7 +1399,7 @@ get rpc timeout */ static PHP_METHOD(amqp_connection_class, getRpcTimeout) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("rpcTimeout"); } /* }}} */ @@ -1449,7 +1449,7 @@ static PHP_METHOD(amqp_connection_class, getUsedChannels) amqp_connection_object *connection; /* Get the timeout from the method params */ - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() /* Get the connection object out of the store */ connection = PHP_AMQP_GET_CONNECTION(getThis()); @@ -1471,7 +1471,7 @@ PHP_METHOD(amqp_connection_class, getMaxChannels) zval rv; amqp_connection_object *connection; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() /* Get the connection object out of the store */ connection = PHP_AMQP_GET_CONNECTION(getThis()); @@ -1491,7 +1491,7 @@ static PHP_METHOD(amqp_connection_class, getMaxFrameSize) zval rv; amqp_connection_object *connection; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() /* Get the connection object out of the store */ connection = PHP_AMQP_GET_CONNECTION(getThis()); @@ -1511,7 +1511,7 @@ static PHP_METHOD(amqp_connection_class, getHeartbeatInterval) zval rv; amqp_connection_object *connection; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() /* Get the connection object out of the store */ connection = PHP_AMQP_GET_CONNECTION(getThis()); @@ -1530,7 +1530,7 @@ static PHP_METHOD(amqp_connection_class, isPersistent) { amqp_connection_object *connection; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() connection = PHP_AMQP_GET_CONNECTION(getThis()); @@ -1543,7 +1543,7 @@ static PHP_METHOD(amqp_connection_class, isPersistent) static PHP_METHOD(amqp_connection_class, getCACert) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("cacert"); } /* }}} */ @@ -1570,7 +1570,7 @@ static PHP_METHOD(amqp_connection_class, setCACert) static PHP_METHOD(amqp_connection_class, getCert) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("cert"); } /* }}} */ @@ -1597,7 +1597,7 @@ static PHP_METHOD(amqp_connection_class, setCert) static PHP_METHOD(amqp_connection_class, getKey) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("key"); } /* }}} */ @@ -1625,7 +1625,7 @@ static PHP_METHOD(amqp_connection_class, setKey) static PHP_METHOD(amqp_connection_class, getVerify) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("verify"); } /* }}} */ @@ -1648,7 +1648,7 @@ get sasl method */ static PHP_METHOD(amqp_connection_class, getSaslMethod) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("saslMethod"); } /* }}} */ @@ -1682,7 +1682,7 @@ static PHP_METHOD(amqp_connection_class, setSaslMethod) static PHP_METHOD(amqp_connection_class, getConnectionName) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("connectionName"); } /* }}} */ diff --git a/amqp_connection_resource.c b/amqp_connection_resource.c index 7cf2abba..dd6ef528 100644 --- a/amqp_connection_resource.c +++ b/amqp_connection_resource.c @@ -422,7 +422,7 @@ amqp_channel_t php_amqp_connection_resource_get_available_channel_id(amqp_connec amqp_channel_t slot; - for (slot = 0; slot < resource->max_slots; slot++) { + for (slot = resource->used_slots; slot < resource->max_slots; slot++) { if (resource->slots[slot] == 0) { return (amqp_channel_t) (slot + 1); } diff --git a/amqp_decimal.c b/amqp_decimal.c index 9c368e2e..7a4a9684 100644 --- a/amqp_decimal.c +++ b/amqp_decimal.c @@ -86,7 +86,7 @@ Get exponent */ static PHP_METHOD(amqp_decimal_class, getExponent) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("exponent"); } @@ -97,7 +97,7 @@ Get E */ static PHP_METHOD(amqp_decimal_class, getSignificand) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("significand"); } diff --git a/amqp_envelope.c b/amqp_envelope.c index 748a104c..43c1ea63 100644 --- a/amqp_envelope.c +++ b/amqp_envelope.c @@ -118,7 +118,7 @@ void convert_amqp_envelope_to_zval(amqp_envelope_t *amqp_envelope, zval *envelop /* {{{ proto AMQPEnvelope::__construct() */ static PHP_METHOD(amqp_envelope_class, __construct) { - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() /* BC */ php_amqp_basic_properties_set_empty_headers(getThis()); @@ -131,7 +131,7 @@ static PHP_METHOD(amqp_envelope_class, getBody) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() zval *zv = PHP_AMQP_READ_THIS_PROP("body"); @@ -147,7 +147,7 @@ static PHP_METHOD(amqp_envelope_class, getBody) static PHP_METHOD(amqp_envelope_class, getRoutingKey) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("routingKey"); } /* }}} */ @@ -156,7 +156,7 @@ static PHP_METHOD(amqp_envelope_class, getRoutingKey) static PHP_METHOD(amqp_envelope_class, getDeliveryTag) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("deliveryTag"); } /* }}} */ @@ -165,7 +165,7 @@ static PHP_METHOD(amqp_envelope_class, getDeliveryTag) static PHP_METHOD(amqp_envelope_class, getConsumerTag) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("consumerTag"); } /* }}} */ @@ -174,7 +174,7 @@ static PHP_METHOD(amqp_envelope_class, getConsumerTag) static PHP_METHOD(amqp_envelope_class, getExchangeName) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("exchangeName"); } /* }}} */ @@ -183,7 +183,7 @@ static PHP_METHOD(amqp_envelope_class, getExchangeName) static PHP_METHOD(amqp_envelope_class, isRedelivery) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("isRedelivery"); } /* }}} */ diff --git a/amqp_envelope_exception.c b/amqp_envelope_exception.c index 388958dc..debd5b07 100644 --- a/amqp_envelope_exception.c +++ b/amqp_envelope_exception.c @@ -36,7 +36,7 @@ Get AMQPEnvelope object */ static PHP_METHOD(amqp_envelope_exception_class, getEnvelope) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("envelope"); } diff --git a/amqp_exchange.c b/amqp_exchange.c index 6c2ae5ad..194853f5 100644 --- a/amqp_exchange.c +++ b/amqp_exchange.c @@ -101,7 +101,7 @@ static PHP_METHOD(amqp_exchange_class, getName) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() if (PHP_AMQP_READ_THIS_PROP_STRLEN("name") > 0) { PHP_AMQP_RETURN_THIS_PROP("name"); @@ -147,7 +147,7 @@ static PHP_METHOD(amqp_exchange_class, getFlags) zend_long flags = AMQP_NOPARAM; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() if (PHP_AMQP_READ_THIS_PROP_BOOL("passive")) { flags |= AMQP_PASSIVE; @@ -198,7 +198,7 @@ static PHP_METHOD(amqp_exchange_class, getType) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() if (PHP_AMQP_READ_THIS_PROP_STRLEN("type") > 0) { PHP_AMQP_RETURN_THIS_PROP("type"); @@ -269,7 +269,7 @@ Get the exchange arguments */ static PHP_METHOD(amqp_exchange_class, getArguments) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("arguments"); } /* }}} */ @@ -351,9 +351,7 @@ static PHP_METHOD(amqp_exchange_class, declareExchange) amqp_channel_resource *channel_resource; amqp_table_t *arguments; - if (zend_parse_parameters_none() == FAILURE) { - return; - } + PHP_AMQP_NOPARAMS() channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not declare exchange."); @@ -795,7 +793,7 @@ Get the AMQPChannel object in use */ static PHP_METHOD(amqp_exchange_class, getChannel) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("channel"); } /* }}} */ @@ -805,7 +803,7 @@ Get the AMQPConnection object in use */ static PHP_METHOD(amqp_exchange_class, getConnection) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("connection"); } /* }}} */ diff --git a/amqp_queue.c b/amqp_queue.c index 5fb10278..f9d19903 100644 --- a/amqp_queue.c +++ b/amqp_queue.c @@ -108,7 +108,7 @@ static PHP_METHOD(amqp_queue_class, getName) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() if (PHP_AMQP_READ_THIS_PROP_STRLEN("name") > 0) { PHP_AMQP_RETURN_THIS_PROP("name"); @@ -154,7 +154,7 @@ static PHP_METHOD(amqp_queue_class, getFlags) zend_long flags = 0; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() if (PHP_AMQP_READ_THIS_PROP_BOOL("passive")) { flags |= AMQP_PASSIVE; @@ -243,7 +243,7 @@ Get the queue arguments */ static PHP_METHOD(amqp_queue_class, getArguments) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("arguments"); } /* }}} */ @@ -329,9 +329,7 @@ static PHP_METHOD(amqp_queue_class, declareQueue) amqp_table_t *arguments; zend_long message_count; - if (zend_parse_parameters_none() == FAILURE) { - return; - } + PHP_AMQP_NOPARAMS() channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not declare queue."); @@ -959,9 +957,7 @@ static PHP_METHOD(amqp_queue_class, purge) amqp_channel_resource *channel_resource; - if (zend_parse_parameters_none() == FAILURE) { - return; - } + PHP_AMQP_NOPARAMS() channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not purge queue."); @@ -1184,7 +1180,7 @@ Get the AMQPChannel object in use */ static PHP_METHOD(amqp_queue_class, getChannel) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("channel"); } /* }}} */ @@ -1194,7 +1190,7 @@ Get the AMQPConnection object in use */ static PHP_METHOD(amqp_queue_class, getConnection) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("connection"); } /* }}} */ @@ -1204,7 +1200,7 @@ Get latest consumer tag*/ static PHP_METHOD(amqp_queue_class, getConsumerTag) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("consumerTag"); } diff --git a/amqp_timestamp.c b/amqp_timestamp.c index 437a124b..40e495e8 100644 --- a/amqp_timestamp.c +++ b/amqp_timestamp.c @@ -75,7 +75,7 @@ Get timestamp */ static PHP_METHOD(amqp_timestamp_class, getTimestamp) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() PHP_AMQP_RETURN_THIS_PROP("timestamp"); } @@ -87,7 +87,7 @@ Return timestamp as string */ static PHP_METHOD(amqp_timestamp_class, __toString) { zval rv; - PHP_AMQP_NOPARAMS(); + PHP_AMQP_NOPARAMS() zval *timestamp = zend_read_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("timestamp"), 0, &rv); diff --git a/infra/php/Dockerfile b/infra/php/Dockerfile index 1efda92b..ce698652 100644 --- a/infra/php/Dockerfile +++ b/infra/php/Dockerfile @@ -24,7 +24,7 @@ CMD PHP_AMQP_DOCKER_ENTRYPOINT=1 php /src/infra/tools/pamqp-docker-setup && \ FROM dev AS dev-all RUN apt-get install -yqq gnupg2 -RUN echo "deb https://apt.llvm.org/bookworm/ llvm-toolchain-bookworm main" > /etc/apt/sources.list.d/llvm.list +RUN echo "deb https://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-17 main" > /etc/apt/sources.list.d/llvm.list RUN curl https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - RUN apt-get update -yqq RUN apt-get install -yqq clang-format-17 \ No newline at end of file diff --git a/tests/bug_gh50-1.phpt b/tests/bug_gh50-1.phpt index 280ff761..203c03f9 100644 --- a/tests/bug_gh50-1.phpt +++ b/tests/bug_gh50-1.phpt @@ -23,5 +23,5 @@ for ($i = 0; $i < 3; $i++) { --EXPECT-- int(1) int(2) -int(1) +int(3) ==DONE== diff --git a/tests/bug_gh50-3.phpt b/tests/bug_gh50-3.phpt index f63e3a61..f79da443 100644 --- a/tests/bug_gh50-3.phpt +++ b/tests/bug_gh50-3.phpt @@ -40,8 +40,8 @@ for ($i = 0; $i < 3; $i++) { --EXPECT-- int(1) int(2) -int(1) +int(3) int(1) int(2) -int(1) +int(3) ==DONE== From e7989c9fd86a902056936f8557bce601bd358cd9 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Tue, 15 Aug 2023 12:06:30 +0200 Subject: [PATCH 049/147] Document lack of reliability of AMQPConnection::isConnected (#306) --- stubs/AMQPConnection.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/stubs/AMQPConnection.php b/stubs/AMQPConnection.php index d4fd548c..2a5d7f81 100644 --- a/stubs/AMQPConnection.php +++ b/stubs/AMQPConnection.php @@ -88,7 +88,8 @@ public function __construct(array $credentials = []) /** * Check whether the connection to the AMQP broker is still valid. * - * It does so by checking the return status of the last connect-command. + * Cannot reliably detect dropped connections or unusual socket errors, as it does not actively + * engage the socket. * * @return boolean True if connected, false otherwise. */ @@ -99,9 +100,10 @@ public function isConnected(): bool /** * Whether connection persistent. * - * When no connection is established, it will always return false + * When no connection is established, it will always return false. The same disclaimer as for + * {@see AMQPConnection::isConnected()} applies. * - * @return boolean + * @return boolean True if persistently connected, false otherwise. */ public function isPersistent(): bool { From afe3736c67be258cdea9bbee6d0988d82508eab0 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 16 Aug 2023 00:06:59 +0200 Subject: [PATCH 050/147] Handle nested AMQP value serialization/deserialization (#461) --- README.md | 37 ++- amqp_basic_properties.c | 375 +++++++++++++++------------- amqp_basic_properties.h | 8 +- amqp_methods_handling.c | 2 +- amqp_type.c | 77 +++--- amqp_type.h | 10 - php_amqp.h | 1 + stubs/AMQPQueue.php | 2 +- tests/amqpqueue_nested_headers.phpt | 49 +++- 9 files changed, 306 insertions(+), 255 deletions(-) diff --git a/README.md b/README.md index bc44df4a..03622005 100644 --- a/README.md +++ b/README.md @@ -47,39 +47,30 @@ breaking changes between versions, e.g. from 1.x to 2.x. Finally, check out the [tests](https://github.com/php-amqp/php-amqp/tree/latest/tests) to see usage examples and edge cases. -### Notes +### Notes & limitations -- Max channels per connection means how many concurrent channels per connection may be opened at the same time - (this limit may be increased later to max AMQP protocol number - 65532 without any problem). -- Nested header arrays may contain only string values. -- You can't share none of AMQP API objects (none of `AMQPConnection`, `AMQPChannel`, `AMQPQueue`, `AMQPExchange`) - between threads. - You have to use separate connection and so on per thread. - -### Related libraries - -* [enqueue/amqp-ext](https://github.com/php-enqueue/amqp-ext) is - a [amqp interop](https://github.com/queue-interop/queue-interop#amqp-interop) compatible wrapper. - -#### Persistent connection - -Limitations: - -- there may only be one persistent connection per unique credentials (login+password+host+port+vhost). +- You can't share any of AMQP API objects (`AMQPConnection`, `AMQPChannel`, `AMQPQueue`, `AMQPExchange`) + between threads. Use a separate connection per thread. +- There may only be one persistent connection + per [connection information](https://github.com/search?q=repo%3Aphp-amqp%2Fphp-amqp+amqp_conn_res_h&type=code). If there will be an attempt to create another persistent connection with the same credentials, an exception will be thrown. -- channels on persistent connections are not persistent: they are destroyed between requests. -- heartbeats are limited to blocking calls only, so if there are no any operations on a connection or no active +- Channels on persistent connections are not persistent: they are destroyed between requests. +- Heartbeats are limited to blocking calls only, so if there are no any operations on a connection or no active consumer set, connection may be closed by the broker as dead. -*Developers note: alternatively for built-in persistent connection support [raphf](http://pecl.php.net/package/raphf) -pecl extension may be used.* +### Related libraries + +* [enqueue/amqp-ext](https://github.com/php-enqueue/amqp-ext) is + an [amqp interop](https://github.com/queue-interop/queue-interop#amqp-interop) compatible wrapper +* [symfony/amqp-messenger](https://symfony.com/components/AMQP%20Messenger) provides AMQP integration + for [symfony/messenger](https://symfony.com/doc/current/messenger.html), the popular messaging component by Symfony. ### How to report a problem 1. First, search through the closed issues and [stackoverflow.com](http://stackoverflow.com). 2. Submit an issue with short and definitive title that describe your problem -3. Provide platform info, PHP interpreter version, SAPI mode (cli, fpm, cgi, etc) extension is used in, php-amqp +3. Provide platform info, PHP interpreter version, SAPI mode (cli, fpm, cgi, etc) the extension is used in, php-amqp extension version, librabbitmq version, make tools version. 4. Description should provide information on how to reproduce a problem ([gist](https://gist.github.com/) is the most preferable way to include large sources) in a definitive way. Use [Vagrant](http://www.vagrantup.com/) to replicate diff --git a/amqp_basic_properties.c b/amqp_basic_properties.c index 27b03058..9504ba47 100644 --- a/amqp_basic_properties.c +++ b/amqp_basic_properties.c @@ -60,11 +60,14 @@ #include "amqp_timestamp.h" #include "amqp_decimal.h" +void php_amqp_basic_properties_table_to_zval_internal(amqp_table_t *table, zval *result, uint8_t depth); +void php_amqp_basic_properties_array_to_zval_internal(amqp_array_t *array, zval *result, uint8_t depth); +zend_bool php_amqp_basic_properties_value_to_zval_internal(amqp_field_value_t *value, zval *result, uint8_t depth); + zend_class_entry *amqp_basic_properties_class_entry; #define this_ce amqp_basic_properties_class_entry - -void php_amqp_basic_properties_convert_to_zval(amqp_basic_properties_t *props, zval *obj) +void php_amqp_basic_properties_to_zval(amqp_basic_properties_t *props, zval *obj) { object_init_ex(obj, this_ce); @@ -240,7 +243,7 @@ static PHP_METHOD(AMQPBasicProperties, getContentEncoding) } /* }}} */ -/* {{{ proto AMQPBasicProperties::getCorrelationId() */ +/* {{{ proto AMQPBasicProperties::getHeaders() */ static PHP_METHOD(AMQPBasicProperties, getHeaders) { zval rv; @@ -559,203 +562,218 @@ PHP_MINIT_FUNCTION(amqp_basic_properties) return SUCCESS; } - -void parse_amqp_table(amqp_table_t *table, zval *result) +zend_bool php_amqp_basic_properties_value_to_zval_internal(amqp_field_value_t *value, zval *result, uint8_t depth) { - int i; - zend_bool has_value = 0; + if (depth >= PHP_AMQP_RECURSION_DEPTH_LIMIT) { + zend_throw_exception_ex( + amqp_exception_class_entry, + 0, + "Recursion depth limit of %d reached while serializing value", + PHP_AMQP_RECURSION_DEPTH_LIMIT + ); + return 0; + } - zval value; + switch (value->kind) { + case AMQP_FIELD_KIND_BOOLEAN: + ZVAL_BOOL(result, value->value.boolean); + break; - assert(Z_TYPE_P(result) == IS_ARRAY); + case AMQP_FIELD_KIND_I8: + ZVAL_LONG(result, value->value.i8); + break; - for (i = 0; i < table->num_entries; i++) { - ZVAL_UNDEF(&value); - has_value = 1; + case AMQP_FIELD_KIND_U8: + ZVAL_LONG(result, value->value.u8); + break; - amqp_table_entry_t *entry = &(table->entries[i]); - switch (entry->value.kind) { - case AMQP_FIELD_KIND_BOOLEAN: - ZVAL_BOOL(&value, entry->value.value.boolean); - break; - case AMQP_FIELD_KIND_I8: - ZVAL_LONG(&value, entry->value.value.i8); - break; - case AMQP_FIELD_KIND_U8: - ZVAL_LONG(&value, entry->value.value.u8); - break; - case AMQP_FIELD_KIND_I16: - ZVAL_LONG(&value, entry->value.value.i16); - break; - case AMQP_FIELD_KIND_U16: - ZVAL_LONG(&value, entry->value.value.u16); - break; - case AMQP_FIELD_KIND_I32: - ZVAL_LONG(&value, entry->value.value.i32); - break; - case AMQP_FIELD_KIND_U32: - ZVAL_LONG(&value, entry->value.value.u32); - break; - case AMQP_FIELD_KIND_I64: - ZVAL_LONG(&value, entry->value.value.i64); - break; - case AMQP_FIELD_KIND_U64: - if (entry->value.value.u64 > LONG_MAX) { - ZVAL_DOUBLE(&value, entry->value.value.u64); - } else { - ZVAL_LONG(&value, entry->value.value.u64); - } - break; - case AMQP_FIELD_KIND_F32: - ZVAL_DOUBLE(&value, entry->value.value.f32); - break; - case AMQP_FIELD_KIND_F64: - ZVAL_DOUBLE(&value, entry->value.value.f64); - break; - case AMQP_FIELD_KIND_UTF8: - case AMQP_FIELD_KIND_BYTES: - ZVAL_STRINGL(&value, entry->value.value.bytes.bytes, entry->value.value.bytes.len); - break; - case AMQP_FIELD_KIND_ARRAY: { - int j; - array_init(&value); - for (j = 0; j < entry->value.value.array.num_entries; ++j) { - switch (entry->value.value.array.entries[j].kind) { - case AMQP_FIELD_KIND_UTF8: - add_next_index_stringl( - &value, - entry->value.value.array.entries[j].value.bytes.bytes, - entry->value.value.array.entries[j].value.bytes.len - ); - break; - case AMQP_FIELD_KIND_TABLE: { - zval subtable; - ZVAL_UNDEF(&subtable); - array_init(&subtable); - - parse_amqp_table(&(entry->value.value.array.entries[j].value.table), &subtable); - add_next_index_zval(&value, &subtable); - } break; - default: - break; - } - } - } break; - case AMQP_FIELD_KIND_TABLE: - array_init(&value); - parse_amqp_table(&(entry->value.value.table), &value); - break; - - case AMQP_FIELD_KIND_TIMESTAMP: { - zval timestamp; - ZVAL_UNDEF(×tamp); - - ZVAL_DOUBLE(×tamp, entry->value.value.u64); - object_init_ex(&value, amqp_timestamp_class_entry); - - zend_call_method_with_1_params( - PHP_AMQP_COMPAT_OBJ_P(&value), - amqp_timestamp_class_entry, - NULL, - "__construct", - NULL, - ×tamp - ); - break; - } + case AMQP_FIELD_KIND_I16: + ZVAL_LONG(result, value->value.i16); + break; - case AMQP_FIELD_KIND_VOID: - ZVAL_NULL(&value); - break; - case AMQP_FIELD_KIND_DECIMAL: { - - zval e; - zval n; - ZVAL_UNDEF(&e); - ZVAL_UNDEF(&n); - - ZVAL_LONG(&e, entry->value.value.decimal.decimals); - ZVAL_LONG(&n, entry->value.value.decimal.value); - - object_init_ex(&value, amqp_decimal_class_entry); - - zend_call_method_with_2_params( - PHP_AMQP_COMPAT_OBJ_P(&value), - amqp_decimal_class_entry, - NULL, - "__construct", - NULL, - &e, - &n - ); - - zval_ptr_dtor(&e); - zval_ptr_dtor(&n); - break; + case AMQP_FIELD_KIND_U16: + ZVAL_LONG(result, value->value.u16); + break; + + case AMQP_FIELD_KIND_I32: + ZVAL_LONG(result, value->value.i32); + break; + + case AMQP_FIELD_KIND_U32: + ZVAL_LONG(result, value->value.u32); + break; + + case AMQP_FIELD_KIND_I64: + ZVAL_LONG(result, value->value.i64); + break; + + case AMQP_FIELD_KIND_U64: + if (value->value.u64 > LONG_MAX) { + ZVAL_DOUBLE(result, value->value.u64); + } else { + ZVAL_LONG(result, value->value.u64); } - default: - has_value = 0; - break; + break; + + case AMQP_FIELD_KIND_F32: + ZVAL_DOUBLE(result, value->value.f32); + break; + + case AMQP_FIELD_KIND_F64: + ZVAL_DOUBLE(result, value->value.f64); + break; + + case AMQP_FIELD_KIND_UTF8: + case AMQP_FIELD_KIND_BYTES: + ZVAL_STRINGL(result, value->value.bytes.bytes, value->value.bytes.len); + break; + + case AMQP_FIELD_KIND_VOID: + ZVAL_NULL(result); + break; + + case AMQP_FIELD_KIND_ARRAY: + array_init(result); + php_amqp_basic_properties_array_to_zval_internal(&(value->value.array), result, depth); + break; + + case AMQP_FIELD_KIND_TABLE: + array_init(result); + php_amqp_basic_properties_table_to_zval_internal(&(value->value.table), result, depth); + break; + + case AMQP_FIELD_KIND_TIMESTAMP: { + zval timestamp; + ZVAL_UNDEF(×tamp); + + ZVAL_DOUBLE(×tamp, value->value.u64); + object_init_ex(result, amqp_timestamp_class_entry); + + zend_call_method_with_1_params( + PHP_AMQP_COMPAT_OBJ_P(result), + amqp_timestamp_class_entry, + NULL, + "__construct", + NULL, + ×tamp + ); + break; + } + + case AMQP_FIELD_KIND_DECIMAL: { + zval e; + zval n; + ZVAL_UNDEF(&e); + ZVAL_UNDEF(&n); + + ZVAL_LONG(&e, value->value.decimal.decimals); + ZVAL_LONG(&n, value->value.decimal.value); + + object_init_ex(result, amqp_decimal_class_entry); + + zend_call_method_with_2_params( + PHP_AMQP_COMPAT_OBJ_P(result), + amqp_decimal_class_entry, + NULL, + "__construct", + NULL, + &e, + &n + ); + + zval_ptr_dtor(&e); + zval_ptr_dtor(&n); + break; } - if (has_value) { + default: + return 0; + } + + return 1; +} + +void php_amqp_basic_properties_array_to_zval_internal(amqp_array_t *array, zval *result, uint8_t depth) +{ + assert(Z_TYPE_P(result) == IS_ARRAY); + + int i; + for (i = 0; i < array->num_entries; ++i) { + zval result_nested; + ZVAL_UNDEF(&result_nested); + if (php_amqp_basic_properties_value_to_zval_internal(&(array->entries[i]), &result_nested, depth)) { + add_next_index_zval(result, &result_nested); + } else if (!Z_ISUNDEF(result_nested)) { + zval_ptr_dtor(&result_nested); + } + } +} + +void php_amqp_basic_properties_table_to_zval_internal(amqp_table_t *table, zval *result, uint8_t depth) +{ + int i; + zval result_nested; + + assert(Z_TYPE_P(result) == IS_ARRAY); + + for (i = 0; i < table->num_entries; ++i) { + amqp_table_entry_t *entry = &(table->entries[i]); + ZVAL_UNDEF(&result_nested); + if (php_amqp_basic_properties_value_to_zval_internal(&(entry->value), &result_nested, depth)) { char *key = estrndup(entry->key.bytes, (unsigned) entry->key.len); - add_assoc_zval(result, key, &value); + add_assoc_zval(result, key, &result_nested); efree(key); - } else { - if (!Z_ISUNDEF(value)) { - zval_ptr_dtor(&value); - } + } else if (!Z_ISUNDEF(result_nested)) { + zval_ptr_dtor(&result_nested); } } - return; } -void php_amqp_basic_properties_extract(amqp_basic_properties_t *p, zval *obj) +void php_amqp_basic_properties_extract(amqp_basic_properties_t *props, zval *obj) { zval headers; ZVAL_UNDEF(&headers); array_init(&headers); - if (p->_flags & AMQP_BASIC_CONTENT_TYPE_FLAG) { + if (props->_flags & AMQP_BASIC_CONTENT_TYPE_FLAG) { zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("contentType"), - (const char *) p->content_type.bytes, - (size_t) p->content_type.len + (const char *) props->content_type.bytes, + (size_t) props->content_type.len ); } else { /* BC */ zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("contentType")); } - if (p->_flags & AMQP_BASIC_CONTENT_ENCODING_FLAG) { + if (props->_flags & AMQP_BASIC_CONTENT_ENCODING_FLAG) { zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("contentEncoding"), - (const char *) p->content_encoding.bytes, - (size_t) p->content_encoding.len + (const char *) props->content_encoding.bytes, + (size_t) props->content_encoding.len ); } else { /* BC */ zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("contentEncoding")); } - if (p->_flags & AMQP_BASIC_HEADERS_FLAG) { - parse_amqp_table(&(p->headers), &headers); + if (props->_flags & AMQP_BASIC_HEADERS_FLAG) { + php_amqp_basic_properties_table_to_zval_internal(&(props->headers), &headers, 0); } zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("headers"), &headers); - if (p->_flags & AMQP_BASIC_DELIVERY_MODE_FLAG) { + if (props->_flags & AMQP_BASIC_DELIVERY_MODE_FLAG) { zend_update_property_long( this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("deliveryMode"), - (zend_long) p->delivery_mode + (zend_long) props->delivery_mode ); } else { /* BC */ @@ -767,110 +785,115 @@ void php_amqp_basic_properties_extract(amqp_basic_properties_t *p, zval *obj) ); } - if (p->_flags & AMQP_BASIC_PRIORITY_FLAG) { - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("priority"), (zend_long) p->priority); + if (props->_flags & AMQP_BASIC_PRIORITY_FLAG) { + zend_update_property_long( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(obj), + ZEND_STRL("priority"), + (zend_long) props->priority + ); } else { /* BC */ zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("priority"), 0); } - if (p->_flags & AMQP_BASIC_CORRELATION_ID_FLAG) { + if (props->_flags & AMQP_BASIC_CORRELATION_ID_FLAG) { zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("correlationId"), - (const char *) p->correlation_id.bytes, - (size_t) p->correlation_id.len + (const char *) props->correlation_id.bytes, + (size_t) props->correlation_id.len ); } else { /* BC */ zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("correlationId")); } - if (p->_flags & AMQP_BASIC_REPLY_TO_FLAG) { + if (props->_flags & AMQP_BASIC_REPLY_TO_FLAG) { zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("replyTo"), - (const char *) p->reply_to.bytes, - (size_t) p->reply_to.len + (const char *) props->reply_to.bytes, + (size_t) props->reply_to.len ); } else { /* BC */ zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("replyTo")); } - if (p->_flags & AMQP_BASIC_EXPIRATION_FLAG) { + if (props->_flags & AMQP_BASIC_EXPIRATION_FLAG) { zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("expiration"), - (const char *) p->expiration.bytes, - (size_t) p->expiration.len + (const char *) props->expiration.bytes, + (size_t) props->expiration.len ); } else { /* BC */ zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("expiration")); } - if (p->_flags & AMQP_BASIC_MESSAGE_ID_FLAG) { + if (props->_flags & AMQP_BASIC_MESSAGE_ID_FLAG) { zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("messageId"), - (const char *) p->message_id.bytes, - (size_t) p->message_id.len + (const char *) props->message_id.bytes, + (size_t) props->message_id.len ); } else { /* BC */ zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("messageId")); } - if (p->_flags & AMQP_BASIC_TIMESTAMP_FLAG) { + if (props->_flags & AMQP_BASIC_TIMESTAMP_FLAG) { zend_update_property_long( this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("timestamp"), - (zend_long) p->timestamp + (zend_long) props->timestamp ); } else { /* BC */ zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("timestamp"), 0); } - if (p->_flags & AMQP_BASIC_TYPE_FLAG) { + if (props->_flags & AMQP_BASIC_TYPE_FLAG) { zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("type"), - (const char *) p->type.bytes, - (size_t) p->type.len + (const char *) props->type.bytes, + (size_t) props->type.len ); } else { /* BC */ zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("type")); } - if (p->_flags & AMQP_BASIC_USER_ID_FLAG) { + if (props->_flags & AMQP_BASIC_USER_ID_FLAG) { zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("userId"), - (const char *) p->user_id.bytes, - (size_t) p->user_id.len + (const char *) props->user_id.bytes, + (size_t) props->user_id.len ); } else { /* BC */ zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("userId")); } - if (p->_flags & AMQP_BASIC_APP_ID_FLAG) { + if (props->_flags & AMQP_BASIC_APP_ID_FLAG) { zend_update_property_stringl( this_ce, PHP_AMQP_COMPAT_OBJ_P(obj), ZEND_STRL("appId"), - (const char *) p->app_id.bytes, - (size_t) p->app_id.len + (const char *) props->app_id.bytes, + (size_t) props->app_id.len ); } else { /* BC */ diff --git a/amqp_basic_properties.h b/amqp_basic_properties.h index bd27e92f..e8a5cf92 100644 --- a/amqp_basic_properties.h +++ b/amqp_basic_properties.h @@ -26,12 +26,8 @@ extern zend_class_entry *amqp_basic_properties_class_entry; -void parse_amqp_table(amqp_table_t *table, zval *result); -void php_amqp_basic_properties_extract(amqp_basic_properties_t *p, zval *obj); - - -void php_amqp_basic_properties_convert_to_zval(amqp_basic_properties_t *props, zval *obj); +void php_amqp_basic_properties_extract(amqp_basic_properties_t *props, zval *obj); +void php_amqp_basic_properties_to_zval(amqp_basic_properties_t *props, zval *obj); void php_amqp_basic_properties_set_empty_headers(zval *obj); - PHP_MINIT_FUNCTION(amqp_basic_properties); diff --git a/amqp_methods_handling.c b/amqp_methods_handling.c index 306cdbde..ead7dbff 100644 --- a/amqp_methods_handling.c +++ b/amqp_methods_handling.c @@ -143,7 +143,7 @@ int php_amqp_call_basic_return_callback(amqp_basic_return_t *m, amqp_message_t * add_next_index_stringl(¶ms, m->exchange.bytes, m->exchange.len); add_next_index_stringl(¶ms, m->routing_key.bytes, m->routing_key.len); - php_amqp_basic_properties_convert_to_zval(&msg->properties, &basic_properties); + php_amqp_basic_properties_to_zval(&msg->properties, &basic_properties); add_next_index_zval(¶ms, &basic_properties); Z_ADDREF_P(&basic_properties); diff --git a/amqp_type.c b/amqp_type.c index 743fc470..225eb931 100644 --- a/amqp_type.c +++ b/amqp_type.c @@ -30,6 +30,7 @@ #include #endif #include "Zend/zend_interfaces.h" +#include "Zend/zend_exceptions.h" #include "amqp_decimal.h" #include "amqp_timestamp.h" #include "amqp_type.h" @@ -38,8 +39,12 @@ #define strtoimax _strtoi64 #endif -static void php_amqp_type_internal_free_amqp_array(amqp_array_t *array); -static void php_amqp_type_internal_free_amqp_table(amqp_table_t *object, zend_bool clear_root); +static void php_amqp_type_free_amqp_array_internal(amqp_array_t *array); +static void php_amqp_type_free_amqp_table_internal(amqp_table_t *object, zend_bool clear_root); +void php_amqp_type_internal_zval_to_amqp_array(zval *value, amqp_array_t *arguments, uint8_t depth); +void php_amqp_type_zval_to_amqp_container_internal(zval *array, amqp_field_value_t **field, uint8_t depth); +void php_amqp_type_zval_to_amqp_table_internal(zval *array, amqp_table_t *amqp_table, uint8_t depth); +zend_bool php_amqp_zval_to_amqp_value_internal(zval *value, amqp_field_value_t **field_ptr, char *key, uint8_t depth); amqp_bytes_t php_amqp_type_char_to_amqp_long(char const *cstr, size_t len) { @@ -78,12 +83,12 @@ char *php_amqp_type_amqp_bytes_to_char(amqp_bytes_t bytes) return res; } -void php_amqp_type_internal_convert_zval_array(zval *php_array, amqp_field_value_t **field, zend_bool allow_int_keys) +void php_amqp_type_zval_to_amqp_container_internal(zval *array, amqp_field_value_t **field, uint8_t depth) { HashTable *ht; zend_string *key; - ht = Z_ARRVAL_P(php_array); + ht = Z_ARRVAL_P(array); zend_bool is_amqp_array = 1; @@ -96,39 +101,35 @@ void php_amqp_type_internal_convert_zval_array(zval *php_array, amqp_field_value if (is_amqp_array) { (*field)->kind = AMQP_FIELD_KIND_ARRAY; - php_amqp_type_internal_convert_zval_to_amqp_array(php_array, &(*field)->value.array); + php_amqp_type_internal_zval_to_amqp_array(array, &(*field)->value.array, depth); } else { (*field)->kind = AMQP_FIELD_KIND_TABLE; - php_amqp_type_internal_convert_zval_to_amqp_table(php_array, &(*field)->value.table, allow_int_keys); + php_amqp_type_zval_to_amqp_table_internal(array, &(*field)->value.table, depth); } } -void php_amqp_type_internal_convert_zval_to_amqp_table( - zval *php_array, - amqp_table_t *amqp_table, - zend_bool allow_int_keys -) +void php_amqp_type_zval_to_amqp_table_internal(zval *array, amqp_table_t *amqp_table, uint8_t depth) { HashTable *ht; - zval *value; + zval *value_nested; zend_string *zkey; zend_ulong index; char *key; unsigned key_len; - ht = Z_ARRVAL_P(php_array); + ht = Z_ARRVAL_P(array); amqp_table->entries = (amqp_table_entry_t *) ecalloc((size_t) zend_hash_num_elements(ht), sizeof(amqp_table_entry_t)); amqp_table->num_entries = 0; - ZEND_HASH_FOREACH_KEY_VAL(ht, index, zkey, value) + ZEND_HASH_FOREACH_KEY_VAL(ht, index, zkey, value_nested) char *string_key; amqp_table_entry_t *table_entry; amqp_field_value_t *field; /* Now pull the key */ if (!zkey) { - if (allow_int_keys) { + if (depth > 0) { /* Convert to strings non-string keys */ char str[32]; @@ -147,11 +148,11 @@ void php_amqp_type_internal_convert_zval_to_amqp_table( string_key = estrndup(key, key_len); - /* Build the value */ + /* Build the array */ table_entry = &amqp_table->entries[amqp_table->num_entries++]; field = &table_entry->value; - if (!php_amqp_type_internal_convert_php_to_amqp_field_value(value, &field, key)) { + if (!php_amqp_zval_to_amqp_value_internal(value_nested, &field, key, depth + 1)) { /* Reset entries counter back */ amqp_table->num_entries--; @@ -162,25 +163,25 @@ void php_amqp_type_internal_convert_zval_to_amqp_table( ZEND_HASH_FOREACH_END(); } -void php_amqp_type_internal_convert_zval_to_amqp_array(zval *zval_arguments, amqp_array_t *arguments) +void php_amqp_type_internal_zval_to_amqp_array(zval *value, amqp_array_t *arguments, uint8_t depth) { HashTable *ht; - zval *value; + zval *value_nested; zend_string *zkey; - ht = Z_ARRVAL_P(zval_arguments); + ht = Z_ARRVAL_P(value); /* Allocate all the memory necessary for storing the arguments */ arguments->entries = (amqp_field_value_t *) ecalloc((size_t) zend_hash_num_elements(ht), sizeof(amqp_field_value_t)); arguments->num_entries = 0; - ZEND_HASH_FOREACH_STR_KEY_VAL(ht, zkey, value) + ZEND_HASH_FOREACH_STR_KEY_VAL(ht, zkey, value_nested) amqp_field_value_t *field = &arguments->entries[arguments->num_entries++]; - if (!php_amqp_type_internal_convert_php_to_amqp_field_value(value, &field, ZSTR_VAL(zkey))) { + if (!php_amqp_zval_to_amqp_value_internal(value_nested, &field, ZSTR_VAL(zkey), depth)) { /* Reset entries counter back */ arguments->num_entries--; @@ -189,14 +190,24 @@ void php_amqp_type_internal_convert_zval_to_amqp_array(zval *zval_arguments, amq ZEND_HASH_FOREACH_END (); } -zend_bool php_amqp_type_internal_convert_php_to_amqp_field_value(zval *value, amqp_field_value_t **fieldPtr, char *key) +zend_bool php_amqp_zval_to_amqp_value_internal(zval *value, amqp_field_value_t **field_ptr, char *key, uint8_t depth) { zend_bool result; char type[16]; amqp_field_value_t *field; + if (depth >= PHP_AMQP_RECURSION_DEPTH_LIMIT) { + zend_throw_exception_ex( + amqp_exception_class_entry, + 0, + "Recursion depth limit of %d reached while serializing value", + PHP_AMQP_RECURSION_DEPTH_LIMIT + ); + return 0; + } + result = 1; - field = *fieldPtr; + field = *field_ptr; switch (Z_TYPE_P(value)) { case IS_TRUE: @@ -227,7 +238,7 @@ zend_bool php_amqp_type_internal_convert_php_to_amqp_field_value(zval *value, am break; case IS_ARRAY: - php_amqp_type_internal_convert_zval_array(value, &field, 1); + php_amqp_type_zval_to_amqp_container_internal(value, &field, depth + 1); break; case IS_NULL: field->kind = AMQP_FIELD_KIND_VOID; @@ -303,13 +314,13 @@ amqp_table_t *php_amqp_type_convert_zval_to_amqp_table(zval *php_array) /* In setArguments, we are overwriting all the existing values */ amqp_table = (amqp_table_t *) emalloc(sizeof(amqp_table_t)); - php_amqp_type_internal_convert_zval_to_amqp_table(php_array, amqp_table, 0); + php_amqp_type_zval_to_amqp_table_internal(php_array, amqp_table, 0); return amqp_table; } -static void php_amqp_type_internal_free_amqp_array(amqp_array_t *array) +static void php_amqp_type_free_amqp_array_internal(amqp_array_t *array) { if (!array) { return; @@ -322,10 +333,10 @@ static void php_amqp_type_internal_free_amqp_array(amqp_array_t *array) switch (entry->kind) { case AMQP_FIELD_KIND_TABLE: - php_amqp_type_internal_free_amqp_table(&entry->value.table, 0); + php_amqp_type_free_amqp_table_internal(&entry->value.table, 0); break; case AMQP_FIELD_KIND_ARRAY: - php_amqp_type_internal_free_amqp_array(&entry->value.array); + php_amqp_type_free_amqp_array_internal(&entry->value.array); break; case AMQP_FIELD_KIND_UTF8: if (entry->value.bytes.bytes) { @@ -343,7 +354,7 @@ static void php_amqp_type_internal_free_amqp_array(amqp_array_t *array) } } -static void php_amqp_type_internal_free_amqp_table(amqp_table_t *object, zend_bool clear_root) +static void php_amqp_type_free_amqp_table_internal(amqp_table_t *object, zend_bool clear_root) { if (!object) { return; @@ -358,10 +369,10 @@ static void php_amqp_type_internal_free_amqp_table(amqp_table_t *object, zend_bo switch (entry->value.kind) { case AMQP_FIELD_KIND_TABLE: - php_amqp_type_internal_free_amqp_table(&entry->value.value.table, 0); + php_amqp_type_free_amqp_table_internal(&entry->value.value.table, 0); break; case AMQP_FIELD_KIND_ARRAY: - php_amqp_type_internal_free_amqp_array(&entry->value.value.array); + php_amqp_type_free_amqp_array_internal(&entry->value.value.array); break; case AMQP_FIELD_KIND_UTF8: if (entry->value.value.bytes.bytes) { @@ -380,4 +391,4 @@ static void php_amqp_type_internal_free_amqp_table(amqp_table_t *object, zend_bo } } -void php_amqp_type_free_amqp_table(amqp_table_t *object) { php_amqp_type_internal_free_amqp_table(object, 1); } +void php_amqp_type_free_amqp_table(amqp_table_t *object) { php_amqp_type_free_amqp_table_internal(object, 1); } diff --git a/amqp_type.h b/amqp_type.h index 17218418..6dac1c86 100644 --- a/amqp_type.h +++ b/amqp_type.h @@ -40,13 +40,3 @@ amqp_bytes_t php_amqp_type_char_to_amqp_long(char const *cstr, size_t len); amqp_table_t *php_amqp_type_convert_zval_to_amqp_table(zval *php_array); void php_amqp_type_free_amqp_table(amqp_table_t *object); - -/** Internal functions */ -zend_bool php_amqp_type_internal_convert_php_to_amqp_field_value(zval *value, amqp_field_value_t **fieldPtr, char *key); -void php_amqp_type_internal_convert_zval_array(zval *php_array, amqp_field_value_t **field, zend_bool allow_int_keys); -void php_amqp_type_internal_convert_zval_to_amqp_table( - zval *php_array, - amqp_table_t *amqp_table, - zend_bool allow_int_keys -); -void php_amqp_type_internal_convert_zval_to_amqp_array(zval *php_array, amqp_array_t *amqp_array); diff --git a/php_amqp.h b/php_amqp.h index f64da86a..cfd16126 100644 --- a/php_amqp.h +++ b/php_amqp.h @@ -405,6 +405,7 @@ static inline amqp_channel_object *php_amqp_channel_object_fetch(zend_object *ob #define AMQP_ERROR_CATEGORY_MASK (1 << 29) +#define PHP_AMQP_RECURSION_DEPTH_LIMIT (1 << 7) #ifdef PHP_WIN32 #define AMQP_OS_SOCKET_TIMEOUT_ERRNO AMQP_ERROR_CATEGORY_MASK | WSAETIMEDOUT diff --git a/stubs/AMQPQueue.php b/stubs/AMQPQueue.php index a69b79d4..e60451d4 100644 --- a/stubs/AMQPQueue.php +++ b/stubs/AMQPQueue.php @@ -7,7 +7,7 @@ class AMQPQueue { private AMQPConnection $connection; - private AMQPChannel$channel; + private AMQPChannel $channel; private ?string $name = null; diff --git a/tests/amqpqueue_nested_headers.phpt b/tests/amqpqueue_nested_headers.phpt index 4c93e58f..bcf3e0ea 100644 --- a/tests/amqpqueue_nested_headers.phpt +++ b/tests/amqpqueue_nested_headers.phpt @@ -37,8 +37,10 @@ $q->bind($ex->getName(), '#'); $ex->publish( 'body', 'routing.1', AMQP_NOPARAM, array( 'headers' => array( - 'foo' => 'bar', - 'baz' => array('a', 'bc', 'def') + 'foo' => 'fval', + 'bar' => array(array('aa', 'bb', array('bar_nested' => 'nested'))), + 'baz' => array('a', 'bc', 'def', 123, 'g'), + 'bla' => array('one' => 2), ) ) ); @@ -53,19 +55,24 @@ $msg = $errorQ->get(AMQP_AUTOACK); $header = $msg->getHeader('x-death'); -echo isset($header[0]['count']) ? 'with' : 'without', ' count ', PHP_EOL; +echo isset($header[0]['count']) ? 'count found' : 'count not found', PHP_EOL; unset($header[0]['count']); var_dump($header); +var_dump($msg->getHeader('foo')); +var_dump($msg->getHeader('bar')); +var_dump($msg->getHeader('baz')); +var_dump($msg->getHeader('bla')); $ex->delete(); $q->delete(); $errorXchange->delete(); $errorQ->delete(); ?> +==DONE== --EXPECTF-- -%s +count %s array(1) { [0]=> array(5) { @@ -86,4 +93,36 @@ array(1) { string(9) "routing.1" } } -} \ No newline at end of file +} +string(4) "fval" +array(1) { + [0]=> + array(3) { + [0]=> + string(2) "aa" + [1]=> + string(2) "bb" + [2]=> + array(1) { + ["bar_nested"]=> + string(6) "nested" + } + } +} +array(5) { + [0]=> + string(1) "a" + [1]=> + string(2) "bc" + [2]=> + string(3) "def" + [3]=> + int(123) + [4]=> + string(1) "g" +} +array(1) { + ["one"]=> + int(2) +} +==DONE== \ No newline at end of file From d85189df9b8f5b115a0ac399395201832a4106ba Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 16 Aug 2023 00:10:57 +0200 Subject: [PATCH 051/147] [RM] releasing version 2.0.0RC1 --- package.xml | 21 ++++++++++++--------- php_amqp_version.h | 4 ++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/package.xml b/package.xml index 9cece098..79c3886d 100644 --- a/package.xml +++ b/package.xml @@ -22,22 +22,25 @@ pinepain@gmail.com yes - 2023-08-03 - + 2023-08-15 + - 2.0.0dev - 2.0.0dev + 2.0.0RC1 + 2.0.0RC1 - devel - devel + beta + beta PHP License - ) (https://github.com/php-amqp/php-amqp/issues/461) + - Document lack of reliability of AMQPConnection::isConnected (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/306) + - Prevent reuse of channel ID of broken channels (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/460) + - Gracefully handle zero as a heartbeat value (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/459) + - Build with the clang compiler on CI (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/457) For a complete list of changes see: -https://github.com/php-amqp/php-amqp/compare/v2.0.0beta2...latest -]]> +https://github.com/php-amqp/php-amqp/compare/v2.0.0beta2...v2.0.0RC1]]> diff --git a/php_amqp_version.h b/php_amqp_version.h index 300dc520..1fb61b2e 100644 --- a/php_amqp_version.h +++ b/php_amqp_version.h @@ -1,6 +1,6 @@ #define PHP_AMQP_VERSION_MAJOR 2 #define PHP_AMQP_VERSION_MINOR 0 #define PHP_AMQP_VERSION_PATCH 0 -#define PHP_AMQP_VERSION_EXTRA "dev" -#define PHP_AMQP_VERSION "2.0.0dev" +#define PHP_AMQP_VERSION_EXTRA "RC1" +#define PHP_AMQP_VERSION "2.0.0RC1" #define PHP_AMQP_VERSION_ID 20000 From b38df31b6f5d04547a1ed927ac1b7dd7b87a96ba Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 16 Aug 2023 00:13:13 +0200 Subject: [PATCH 052/147] [RM] back to dev 2.0.0dev --- package.xml | 40 +++++++++++++++++++++++++++++----------- php_amqp_version.h | 4 ++-- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/package.xml b/package.xml index 79c3886d..5d748d43 100644 --- a/package.xml +++ b/package.xml @@ -23,24 +23,21 @@ yes 2023-08-15 - + - 2.0.0RC1 - 2.0.0RC1 + 2.0.0dev + 2.0.0dev - beta - beta + devel + devel PHP License - ) (https://github.com/php-amqp/php-amqp/issues/461) - - Document lack of reliability of AMQPConnection::isConnected (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/306) - - Prevent reuse of channel ID of broken channels (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/460) - - Gracefully handle zero as a heartbeat value (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/459) - - Build with the clang compiler on CI (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/457) + +https://github.com/php-amqp/php-amqp/compare/v2.0.0RC1...latest +]]> @@ -297,6 +294,27 @@ https://github.com/php-amqp/php-amqp/compare/v2.0.0beta2...v2.0.0RC1]]> + + 2023-08-15 + + + 2.0.0RC1 + 2.0.0RC1 + + + beta + beta + + PHP License + ) (https://github.com/php-amqp/php-amqp/issues/461) + - Document lack of reliability of AMQPConnection::isConnected (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/306) + - Prevent reuse of channel ID of broken channels (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/460) + - Gracefully handle zero as a heartbeat value (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/459) + - Build with the clang compiler on CI (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/457) + +For a complete list of changes see: +https://github.com/php-amqp/php-amqp/compare/v2.0.0beta2...v2.0.0RC1]]> + 2023-08-03 diff --git a/php_amqp_version.h b/php_amqp_version.h index 1fb61b2e..300dc520 100644 --- a/php_amqp_version.h +++ b/php_amqp_version.h @@ -1,6 +1,6 @@ #define PHP_AMQP_VERSION_MAJOR 2 #define PHP_AMQP_VERSION_MINOR 0 #define PHP_AMQP_VERSION_PATCH 0 -#define PHP_AMQP_VERSION_EXTRA "RC1" -#define PHP_AMQP_VERSION "2.0.0RC1" +#define PHP_AMQP_VERSION_EXTRA "dev" +#define PHP_AMQP_VERSION "2.0.0dev" #define PHP_AMQP_VERSION_ID 20000 From 4ee6159a2da26b1126f35e4dbda53b65881cbbb2 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 16 Aug 2023 00:24:18 +0200 Subject: [PATCH 053/147] Fix generated commit URLs in changelogs --- infra/tools/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/tools/functions.php b/infra/tools/functions.php index d2eb59d6..98ff884f 100644 --- a/infra/tools/functions.php +++ b/infra/tools/functions.php @@ -39,7 +39,7 @@ EOS; const PACKAGE_XML = BASE_DIR . '/package.xml'; const ISSUE_URL_TEMPLATE = 'https://github.com/php-amqp/php-amqp/issues/%d'; -const COMMIT_URL_TEMPLATE = 'https://github.com/php-amqp/php-amqp/issues/%d'; +const COMMIT_URL_TEMPLATE = 'https://github.com/php-amqp/php-amqp/commit/%s'; const COMMIT_MESSAGE_CHANGELOG_IGNORED = ['[RM]', 'Back to dev']; const SOURCE_VERSION_REGEX = '(#define\s+PHP_AMQP_VERSION\s+)"(?P' . VERSION_REGEX . ')"'; From 6c98bf1a15dae87a709a38b59f5693c6d88f77aa Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 16 Aug 2023 08:38:30 +0200 Subject: [PATCH 054/147] Allow bitmask flags arguments to be nullable where previously AMQP_NOPARAM/zero was required (#462) --- UPGRADING.md | 27 ++++++++----- amqp.c | 18 ++++----- amqp_basic_properties.c | 4 +- amqp_channel.c | 6 +-- amqp_channel.h | 2 +- amqp_connection.c | 4 +- amqp_connection.h | 2 +- amqp_connection_resource.c | 2 +- amqp_connection_resource.h | 2 +- amqp_exchange.c | 26 ++++++++---- amqp_queue.c | 51 ++++++++++++++---------- amqp_type.c | 12 +++--- infra/tools/pamqp-diff-bc | 2 +- php_amqp.h | 26 ++++++------ stubs/AMQPExchange.php | 4 +- stubs/AMQPQueue.php | 17 ++++---- tests/amqpenvelope_get_accessors.phpt | 4 +- tests/amqpenvelope_var_dump.phpt | 2 +- tests/amqpexchange_delete_null_name.phpt | 2 +- tests/amqpqueue_delete_basic.phpt | 2 +- tests/amqpqueue_nack.phpt | 2 +- tests/bug_gh155_direct_reply_to.phpt | 2 +- 22 files changed, 122 insertions(+), 97 deletions(-) diff --git a/UPGRADING.md b/UPGRADING.md index c34f6a8c..41c2ce39 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -162,9 +162,9 @@ ### Public method additions -* `getConnectTimeout(): float` -* `setConnectionName(?string $connectionName): void` -* `getConnectionName(): ?string` + * `getConnectTimeout(): float` + * `setConnectionName(?string $connectionName): void` + * `getConnectionName(): ?string` ### Public method type changes @@ -331,7 +331,7 @@ ### Public method additions -* `getEnvelope(): AMQPEnvelope` + * `getEnvelope(): AMQPEnvelope` ## `AMQPExchange` breaking changes @@ -365,7 +365,7 @@ ``` ```diff - delete(string $exchangeName = null, int $flags = 0): bool -+ delete(?string $exchangeName = null, int $flags = 0): void ++ delete(?string $exchangeName = null, ?int $flags = null): void ``` ```diff @@ -385,7 +385,7 @@ ``` ```diff - publish(string $message, string $routing_key = null, int $flags = 0, array $attributes = []): bool -+ publish(string $message, ?string $routingKey = null, int $flags = 0, array $headers = []): void ++ publish(string $message, ?string $routingKey = null, ?int $flags = null, array $headers = []): void ``` ```diff @@ -442,7 +442,7 @@ ```diff - ack(string $delivery_tag, int $flags = 0): bool -+ ack(int $deliveryTag, int $flags = 0): void ++ ack(int $deliveryTag, ?int $flags = null): void ``` ```diff @@ -457,12 +457,17 @@ ``` ```diff - consume(?callable $callback = null, int $flags = 0, string $consumerTag = null): void -+ consume(?callable $callback = null, int $flags = 0, ?string $consumerTag = null): void ++ consume(?callable $callback = null, ?int $flags = null, ?string $consumerTag = null): void + +``` +```diff +- delete(int $flags = 0): int ++ delete(?int $flags = null): int ``` ```diff - get(int $flags = 0): AMQPEnvelope|bool -+ get(int $flags = 0): ?AMQPEnvelope ++ get(?int $flags = null): ?AMQPEnvelope ``` ```diff @@ -477,12 +482,12 @@ ``` ```diff - nack(string $delivery_tag, int $flags = 0): bool -+ nack(int $deliveryTag, int $flags = 0): void ++ nack(int $deliveryTag, ?int $flags = null): void ``` ```diff - reject(string $delivery_tag, int $flags = 0): bool -+ reject(int $deliveryTag, int $flags = 0): void ++ reject(int $deliveryTag, ?int $flags = null): void ``` ```diff diff --git a/amqp.c b/amqp.c index 1cfc7b3b..7b43fb01 100644 --- a/amqp.c +++ b/amqp.c @@ -83,29 +83,29 @@ zend_function_entry amqp_functions[] = { }; /* }}} */ -zend_bool php_amqp_is_valid_identifier(zend_string *val) +bool php_amqp_is_valid_identifier(zend_string *val) { return ZSTR_LEN(val) > 0 && ZSTR_LEN(val) <= PHP_AMQP_MAX_IDENTIFIER_LENGTH; } -zend_bool php_amqp_is_valid_credential(zend_string *val) +bool php_amqp_is_valid_credential(zend_string *val) { return ZSTR_LEN(val) > 0 && ZSTR_LEN(val) <= PHP_AMQP_MAX_CREDENTIALS_LENGTH; } -zend_bool php_amqp_is_valid_port(zend_long val) { return val >= PHP_AMQP_MIN_PORT && val <= PHP_AMQP_MAX_PORT; } +bool php_amqp_is_valid_port(zend_long val) { return val >= PHP_AMQP_MIN_PORT && val <= PHP_AMQP_MAX_PORT; } -zend_bool php_amqp_is_valid_timeout(double timeout) { return timeout >= 0; } +bool php_amqp_is_valid_timeout(double timeout) { return timeout >= 0; } -zend_bool php_amqp_is_valid_channel_max(zend_long val) { return val > 0 && val <= PHP_AMQP_DEFAULT_CHANNEL_MAX; } +bool php_amqp_is_valid_channel_max(zend_long val) { return val > 0 && val <= PHP_AMQP_DEFAULT_CHANNEL_MAX; } -zend_bool php_amqp_is_valid_frame_size_max(zend_long val) { return val > 0 && val <= PHP_AMQP_MAX_FRAME_SIZE; } +bool php_amqp_is_valid_frame_size_max(zend_long val) { return val > 0 && val <= PHP_AMQP_MAX_FRAME_SIZE; } -zend_bool php_amqp_is_valid_heartbeat(zend_long val) { return val >= 0 && val <= PHP_AMQP_MAX_HEARTBEAT; } +bool php_amqp_is_valid_heartbeat(zend_long val) { return val >= 0 && val <= PHP_AMQP_MAX_HEARTBEAT; } -zend_bool php_amqp_is_valid_prefetch_size(zend_long val) { return val >= 0 && val <= PHP_AMQP_MAX_PREFETCH_SIZE; } +bool php_amqp_is_valid_prefetch_size(zend_long val) { return val >= 0 && val <= PHP_AMQP_MAX_PREFETCH_SIZE; } -zend_bool php_amqp_is_valid_prefetch_count(zend_long val) { return val >= 0 && val <= PHP_AMQP_MAX_PREFETCH_COUNT; } +bool php_amqp_is_valid_prefetch_count(zend_long val) { return val >= 0 && val <= PHP_AMQP_MAX_PREFETCH_COUNT; } static ZEND_INI_MH(onUpdateIdentifier) { diff --git a/amqp_basic_properties.c b/amqp_basic_properties.c index 9504ba47..a380c505 100644 --- a/amqp_basic_properties.c +++ b/amqp_basic_properties.c @@ -62,7 +62,7 @@ void php_amqp_basic_properties_table_to_zval_internal(amqp_table_t *table, zval *result, uint8_t depth); void php_amqp_basic_properties_array_to_zval_internal(amqp_array_t *array, zval *result, uint8_t depth); -zend_bool php_amqp_basic_properties_value_to_zval_internal(amqp_field_value_t *value, zval *result, uint8_t depth); +bool php_amqp_basic_properties_value_to_zval_internal(amqp_field_value_t *value, zval *result, uint8_t depth); zend_class_entry *amqp_basic_properties_class_entry; #define this_ce amqp_basic_properties_class_entry @@ -562,7 +562,7 @@ PHP_MINIT_FUNCTION(amqp_basic_properties) return SUCCESS; } -zend_bool php_amqp_basic_properties_value_to_zval_internal(amqp_field_value_t *value, zval *result, uint8_t depth) +bool php_amqp_basic_properties_value_to_zval_internal(amqp_field_value_t *value, zval *result, uint8_t depth) { if (depth >= PHP_AMQP_RECURSION_DEPTH_LIMIT) { zend_throw_exception_ex( diff --git a/amqp_channel.c b/amqp_channel.c index 64b1fc00..2b746e73 100644 --- a/amqp_channel.c +++ b/amqp_channel.c @@ -65,7 +65,7 @@ zend_class_entry *amqp_channel_class_entry; zend_object_handlers amqp_channel_object_handlers; -void php_amqp_close_channel(amqp_channel_resource *channel_resource, zend_bool throw) +void php_amqp_close_channel(amqp_channel_resource *channel_resource, bool throw) { assert(channel_resource != NULL); @@ -823,7 +823,7 @@ static PHP_METHOD(amqp_channel_class, qos) amqp_channel_resource *channel_resource; zend_long prefetch_size; zend_long prefetch_count; - zend_bool global = 0; + bool global = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|b", &prefetch_size, &prefetch_count, &global) == FAILURE) { return; @@ -1012,7 +1012,7 @@ static PHP_METHOD(amqp_channel_class, basicRecover) amqp_rpc_reply_t res; - zend_bool requeue = 1; + bool requeue = 1; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &requeue) == FAILURE) { return; diff --git a/amqp_channel.h b/amqp_channel.h index ca4dcb59..76c72609 100644 --- a/amqp_channel.h +++ b/amqp_channel.h @@ -24,6 +24,6 @@ extern zend_class_entry *amqp_channel_class_entry; -void php_amqp_close_channel(amqp_channel_resource *channel_resource, zend_bool throw); +void php_amqp_close_channel(amqp_channel_resource *channel_resource, bool throw); PHP_MINIT_FUNCTION(amqp_channel); diff --git a/amqp_connection.c b/amqp_connection.c index a2b6a836..443329a7 100644 --- a/amqp_connection.c +++ b/amqp_connection.c @@ -176,7 +176,7 @@ void php_amqp_disconnect_force(amqp_connection_resource *resource) * handles connecting to amqp * called by connect(), pconnect(), reconnect(), preconnect() */ -int php_amqp_connect(amqp_connection_object *connection, zend_bool persistent, INTERNAL_FUNCTION_PARAMETERS) +int php_amqp_connect(amqp_connection_object *connection, bool persistent, INTERNAL_FUNCTION_PARAMETERS) { zval rv; @@ -1633,7 +1633,7 @@ static PHP_METHOD(amqp_connection_class, getVerify) /* {{{ proto amqp::setVerify(bool verify) */ static PHP_METHOD(amqp_connection_class, setVerify) { - zend_bool verify = 1; + bool verify = 1; if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &verify) == FAILURE) { return; diff --git a/amqp_connection.h b/amqp_connection.h index a2d0df4c..fbdca86f 100644 --- a/amqp_connection.h +++ b/amqp_connection.h @@ -24,7 +24,7 @@ extern zend_class_entry *amqp_connection_class_entry; -int php_amqp_connect(amqp_connection_object *amqp_connection, zend_bool persistent, INTERNAL_FUNCTION_PARAMETERS); +int php_amqp_connect(amqp_connection_object *amqp_connection, bool persistent, INTERNAL_FUNCTION_PARAMETERS); void php_amqp_disconnect_force(amqp_connection_resource *resource); diff --git a/amqp_connection_resource.c b/amqp_connection_resource.c index dd6ef528..9ae6a549 100644 --- a/amqp_connection_resource.c +++ b/amqp_connection_resource.c @@ -471,7 +471,7 @@ int php_amqp_connection_resource_unregister_channel(amqp_connection_resource *re /* Creating and destroying resource */ -amqp_connection_resource *connection_resource_constructor(amqp_connection_params *params, zend_bool persistent) +amqp_connection_resource *connection_resource_constructor(amqp_connection_params *params, bool persistent) { struct timeval tv = {0}; struct timeval *tv_ptr = &tv; diff --git a/amqp_connection_resource.h b/amqp_connection_resource.h index 7d3c22fe..45f0b114 100644 --- a/amqp_connection_resource.h +++ b/amqp_connection_resource.h @@ -94,7 +94,7 @@ int php_amqp_connection_resource_register_channel( ); /* Creating and destroying resource */ -amqp_connection_resource *connection_resource_constructor(amqp_connection_params *params, zend_bool persistent); +amqp_connection_resource *connection_resource_constructor(amqp_connection_params *params, bool persistent); ZEND_RSRC_DTOR_FUNC(amqp_connection_resource_dtor_persistent); ZEND_RSRC_DTOR_FUNC(amqp_connection_resource_dtor); diff --git a/amqp_exchange.c b/amqp_exchange.c index 194853f5..6a31b083 100644 --- a/amqp_exchange.c +++ b/amqp_exchange.c @@ -175,14 +175,13 @@ Set the exchange parameters */ static PHP_METHOD(amqp_exchange_class, setFlags) { zend_long flags = AMQP_NOPARAM; - zend_bool flags_is_null = 1; + bool flags_is_null = 1; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l!", &flags, &flags_is_null) == FAILURE) { return; } - /* Set the flags based on the bitmask we were given */ - flags = flags ? flags & PHP_AMQP_EXCHANGE_FLAGS : flags; + flags = flags & PHP_AMQP_EXCHANGE_FLAGS; zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("passive"), IS_PASSIVE(flags)); zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("durable"), IS_DURABLE(flags)); @@ -415,8 +414,9 @@ static PHP_METHOD(amqp_exchange_class, delete) char *name = NULL; size_t name_len = 0; zend_long flags = AMQP_NOPARAM; + bool flags_is_null = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!l", &name, &name_len, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!l!", &name, &name_len, &flags, &flags_is_null) == FAILURE) { return; } @@ -464,6 +464,7 @@ static PHP_METHOD(amqp_exchange_class, publish) char *msg = NULL; size_t msg_len = 0; zend_long flags = AMQP_NOPARAM; + bool flags_is_null = 1; #ifndef PHP_WIN32 /* Storage for previous signal handler during SIGPIPE override */ @@ -472,8 +473,17 @@ static PHP_METHOD(amqp_exchange_class, publish) amqp_basic_properties_t props; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s!la/", &msg, &msg_len, &key_name, &key_len, &flags, &ini_arr) == - FAILURE) { + if (zend_parse_parameters( + ZEND_NUM_ARGS(), + "s|s!l!a/", + &msg, + &msg_len, + &key_name, + &key_len, + &flags, + &flags_is_null, + &ini_arr + ) == FAILURE) { return; } @@ -875,13 +885,13 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_exchange_class_delete, ZEND_RETURN_VALUE, 0, IS_VOID, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, exchangeName, IS_STRING, 1, "null") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "AMQP_NOPARAM") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_exchange_class_publish, ZEND_RETURN_VALUE, 1, IS_VOID, 0) ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, routingKey, IS_STRING, 1, "null") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "AMQP_NOPARAM") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, headers, IS_ARRAY, 0, "[]") ZEND_END_ARG_INFO() diff --git a/amqp_queue.c b/amqp_queue.c index f9d19903..1ca5998d 100644 --- a/amqp_queue.c +++ b/amqp_queue.c @@ -181,15 +181,14 @@ static PHP_METHOD(amqp_queue_class, getFlags) Set the queue parameters */ static PHP_METHOD(amqp_queue_class, setFlags) { - zend_long flags; - zend_bool flags_is_null = 1; + zend_long flags = AMQP_NOPARAM; + bool flags_is_null = 1; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l!", &flags, &flags_is_null) == FAILURE) { return; } - /* Set the flags based on the bitmask we were given */ - flags = flags ? flags & PHP_AMQP_QUEUE_FLAGS : flags; + flags = flags & PHP_AMQP_QUEUE_FLAGS; zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("passive"), IS_PASSIVE(flags)); zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("durable"), IS_DURABLE(flags)); @@ -454,9 +453,9 @@ static PHP_METHOD(amqp_queue_class, get) zval message; zend_long flags = INI_INT("amqp.auto_ack") ? AMQP_AUTOACK : AMQP_NOPARAM; + bool flags_is_null = 1; - /* Parse out the method parameters */ - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!", &flags, &flags_is_null) == FAILURE) { return; } @@ -546,9 +545,18 @@ static PHP_METHOD(amqp_queue_class, consume) char *consumer_tag = NULL; size_t consumer_tag_len = 0; zend_long flags = INI_INT("amqp.auto_ack") ? AMQP_AUTOACK : AMQP_NOPARAM; + bool flags_is_null = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|f!ls!", &fci, &fci_cache, &flags, &consumer_tag, &consumer_tag_len) == - FAILURE) { + if (zend_parse_parameters( + ZEND_NUM_ARGS(), + "|f!l!s!", + &fci, + &fci_cache, + &flags, + &flags_is_null, + &consumer_tag, + &consumer_tag_len + ) == FAILURE) { return; } @@ -814,8 +822,9 @@ static PHP_METHOD(amqp_queue_class, ack) zend_long deliveryTag = 0; zend_long flags = AMQP_NOPARAM; + bool flags_is_null = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l", &deliveryTag, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l!", &deliveryTag, &flags, &flags_is_null) == FAILURE) { return; } @@ -862,8 +871,9 @@ static PHP_METHOD(amqp_queue_class, nack) zend_long deliveryTag = 0; zend_long flags = AMQP_NOPARAM; + bool flags_is_null = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l", &deliveryTag, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l!", &deliveryTag, &flags, &flags_is_null) == FAILURE) { return; } @@ -911,8 +921,9 @@ static PHP_METHOD(amqp_queue_class, reject) zend_long deliveryTag = 0; zend_long flags = AMQP_NOPARAM; + bool flags_is_null = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l", &deliveryTag, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l!", &deliveryTag, &flags, &flags_is_null) == FAILURE) { return; } @@ -1009,8 +1020,7 @@ static PHP_METHOD(amqp_queue_class, cancel) zval *channel_zv = PHP_AMQP_READ_THIS_PROP("channel"); zval *consumers = zend_read_property(amqp_channel_class_entry, PHP_AMQP_COMPAT_OBJ_P(channel_zv), ZEND_STRL("consumers"), 0, &rv); - zend_bool previous_consumer_tag_exists = - (zend_bool) (IS_STRING == Z_TYPE_P(PHP_AMQP_READ_THIS_PROP("consumerTag"))); + bool previous_consumer_tag_exists = (bool) (IS_STRING == Z_TYPE_P(PHP_AMQP_READ_THIS_PROP("consumerTag"))); if (IS_ARRAY != Z_TYPE_P(consumers)) { zend_throw_exception( @@ -1134,10 +1144,11 @@ static PHP_METHOD(amqp_queue_class, delete) amqp_channel_resource *channel_resource; zend_long flags = AMQP_NOPARAM; + bool flags_is_null = 1; zend_long message_count; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!", &flags, &flags_is_null) == FAILURE) { return; } @@ -1258,28 +1269,28 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_bind, ZEND_RETU ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_amqp_queue_class_get, ZEND_SEND_BY_VAL, 0, AMQPEnvelope, 1) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "AMQP_NOPARAM") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_consume, ZEND_SEND_BY_VAL, 0, IS_VOID, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, callback, IS_CALLABLE, 1, "null") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "AMQP_NOPARAM") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, consumerTag, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_ack, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) ZEND_ARG_TYPE_INFO(0, deliveryTag, IS_LONG, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "AMQP_NOPARAM") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_nack, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) ZEND_ARG_TYPE_INFO(0, deliveryTag, IS_LONG, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "AMQP_NOPARAM") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_reject, ZEND_SEND_BY_VAL, 1, IS_VOID, 0) ZEND_ARG_TYPE_INFO(0, deliveryTag, IS_LONG, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "AMQP_NOPARAM") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_purge, ZEND_SEND_BY_VAL, 0, IS_LONG, 0) @@ -1296,7 +1307,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_unbind, ZEND_RE ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_delete, ZEND_SEND_BY_VAL, 0, IS_LONG, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "AMQP_NOPARAM") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(arginfo_amqp_queue_class_getChannel, AMQPChannel, 0) diff --git a/amqp_type.c b/amqp_type.c index 225eb931..bd7e6afe 100644 --- a/amqp_type.c +++ b/amqp_type.c @@ -40,11 +40,11 @@ #endif static void php_amqp_type_free_amqp_array_internal(amqp_array_t *array); -static void php_amqp_type_free_amqp_table_internal(amqp_table_t *object, zend_bool clear_root); +static void php_amqp_type_free_amqp_table_internal(amqp_table_t *object, bool clear_root); void php_amqp_type_internal_zval_to_amqp_array(zval *value, amqp_array_t *arguments, uint8_t depth); void php_amqp_type_zval_to_amqp_container_internal(zval *array, amqp_field_value_t **field, uint8_t depth); void php_amqp_type_zval_to_amqp_table_internal(zval *array, amqp_table_t *amqp_table, uint8_t depth); -zend_bool php_amqp_zval_to_amqp_value_internal(zval *value, amqp_field_value_t **field_ptr, char *key, uint8_t depth); +bool php_amqp_zval_to_amqp_value_internal(zval *value, amqp_field_value_t **field_ptr, char *key, uint8_t depth); amqp_bytes_t php_amqp_type_char_to_amqp_long(char const *cstr, size_t len) { @@ -90,7 +90,7 @@ void php_amqp_type_zval_to_amqp_container_internal(zval *array, amqp_field_value ht = Z_ARRVAL_P(array); - zend_bool is_amqp_array = 1; + bool is_amqp_array = 1; ZEND_HASH_FOREACH_STR_KEY(ht, key) if (key) { @@ -190,9 +190,9 @@ void php_amqp_type_internal_zval_to_amqp_array(zval *value, amqp_array_t *argume ZEND_HASH_FOREACH_END (); } -zend_bool php_amqp_zval_to_amqp_value_internal(zval *value, amqp_field_value_t **field_ptr, char *key, uint8_t depth) +bool php_amqp_zval_to_amqp_value_internal(zval *value, amqp_field_value_t **field_ptr, char *key, uint8_t depth) { - zend_bool result; + bool result; char type[16]; amqp_field_value_t *field; @@ -354,7 +354,7 @@ static void php_amqp_type_free_amqp_array_internal(amqp_array_t *array) } } -static void php_amqp_type_free_amqp_table_internal(amqp_table_t *object, zend_bool clear_root) +static void php_amqp_type_free_amqp_table_internal(amqp_table_t *object, bool clear_root) { if (!object) { return; diff --git a/infra/tools/pamqp-diff-bc b/infra/tools/pamqp-diff-bc index 07ebe5b0..034d4d1f 100755 --- a/infra/tools/pamqp-diff-bc +++ b/infra/tools/pamqp-diff-bc @@ -8,7 +8,7 @@ $prev = $_SERVER['argv'][1] ?? null; $next = $_SERVER['argv'][2] ?? null; assert($prev !== null, 'First argument must be path to previous stubs version'); -assert($next !== null, 'First argument must be path to next stubs version'); +assert($next !== null, 'Second argument must be path to next stubs version'); function pamqp_string_ends_with(string $haystack, string $needle): bool { diff --git a/php_amqp.h b/php_amqp.h index cfd16126..e8986f2b 100644 --- a/php_amqp.h +++ b/php_amqp.h @@ -27,6 +27,8 @@ #include "config.h" #endif +#include + /* True global resources - no need for thread safety here */ extern zend_class_entry *amqp_exception_class_entry, *amqp_connection_exception_class_entry, *amqp_channel_exception_class_entry, *amqp_exchange_exception_class_entry, *amqp_queue_exception_class_entry, @@ -189,9 +191,9 @@ struct _amqp_channel_object { }; struct _amqp_connection_resource { - zend_bool is_connected; - zend_bool is_persistent; - zend_bool is_dirty; + bool is_connected; + bool is_persistent; + bool is_dirty; zend_resource *resource; amqp_connection_object *parent; amqp_channel_t max_slots; @@ -463,14 +465,14 @@ void php_amqp_maybe_release_buffers_on_channel( amqp_channel_resource *channel_resource ); -zend_bool php_amqp_is_valid_identifier(zend_string *val); -zend_bool php_amqp_is_valid_credential(zend_string *val); -zend_bool php_amqp_is_valid_port(zend_long val); -zend_bool php_amqp_is_valid_timeout(double timeout); -zend_bool php_amqp_is_valid_channel_max(zend_long val); -zend_bool php_amqp_is_valid_frame_size_max(zend_long val); -zend_bool php_amqp_is_valid_heartbeat(zend_long val); -zend_bool php_amqp_is_valid_prefetch_count(zend_long val); -zend_bool php_amqp_is_valid_prefetch_size(zend_long val); +bool php_amqp_is_valid_identifier(zend_string *val); +bool php_amqp_is_valid_credential(zend_string *val); +bool php_amqp_is_valid_port(zend_long val); +bool php_amqp_is_valid_timeout(double timeout); +bool php_amqp_is_valid_channel_max(zend_long val); +bool php_amqp_is_valid_frame_size_max(zend_long val); +bool php_amqp_is_valid_heartbeat(zend_long val); +bool php_amqp_is_valid_prefetch_count(zend_long val); +bool php_amqp_is_valid_prefetch_size(zend_long val); #endif /* PHP_AMQP_H */ diff --git a/stubs/AMQPExchange.php b/stubs/AMQPExchange.php index a3e241c9..f7aebc1a 100644 --- a/stubs/AMQPExchange.php +++ b/stubs/AMQPExchange.php @@ -111,7 +111,7 @@ public function declare(): void * @throws AMQPChannelException If the channel is not open. * @throws AMQPConnectionException If the connection to the broker was lost. */ - public function delete(?string $exchangeName = null, int $flags = AMQP_NOPARAM): void + public function delete(?string $exchangeName = null, ?int $flags = null): void { } @@ -195,7 +195,7 @@ public function getType(): ?string public function publish( string $message, ?string $routingKey = null, - int $flags = AMQP_NOPARAM, + ?int $flags = null, array $headers = [] ): void { } diff --git a/stubs/AMQPQueue.php b/stubs/AMQPQueue.php index e60451d4..a650ef12 100644 --- a/stubs/AMQPQueue.php +++ b/stubs/AMQPQueue.php @@ -50,7 +50,7 @@ public function __construct(AMQPChannel $channel) * @throws AMQPConnectionException If the connection to the broker was lost. * @throws AMQPChannelException If the channel is not open. */ - public function ack(int $deliveryTag, int $flags = AMQP_NOPARAM): void + public function ack(int $deliveryTag, ?int $flags = null): void { } @@ -125,11 +125,8 @@ public function cancel(string $consumerTag = ''): void * @throws AMQPEnvelopeException When no queue found for envelope. * @throws AMQPQueueException If timeout occurs or queue is not exists. */ - public function consume( - callable $callback = null, - int $flags = AMQP_NOPARAM, - ?string $consumerTag = null - ): void { + public function consume(callable $callback = null, ?int $flags = null, ?string $consumerTag = null): void + { } /** @@ -173,7 +170,7 @@ public function declare(): int * * @return integer The number of deleted messages. */ - public function delete(int $flags = AMQP_NOPARAM): int + public function delete(?int $flags = null): int { } @@ -198,7 +195,7 @@ public function delete(int $flags = AMQP_NOPARAM): int * @throws AMQPConnectionException If the connection to the broker was lost. * @throws AMQPQueueException If queue is not exist. */ - public function get(int $flags = AMQP_NOPARAM): ?AMQPEnvelope + public function get(?int $flags = null): ?AMQPEnvelope { } @@ -261,7 +258,7 @@ public function getName(): ?string * @throws AMQPConnectionException If the connection to the broker was lost. * @throws AMQPChannelException If the channel is not open. */ - public function nack(int $deliveryTag, int $flags = AMQP_NOPARAM): void + public function nack(int $deliveryTag, ?int $flags = null): void { } @@ -279,7 +276,7 @@ public function nack(int $deliveryTag, int $flags = AMQP_NOPARAM): void * @throws AMQPConnectionException If the connection to the broker was lost. * @throws AMQPChannelException If the channel is not open. */ - public function reject(int $deliveryTag, int $flags = AMQP_NOPARAM): void + public function reject(int $deliveryTag, ?int $flags = null): void { } diff --git a/tests/amqpenvelope_get_accessors.phpt b/tests/amqpenvelope_get_accessors.phpt index e0c7816c..52923e7c 100644 --- a/tests/amqpenvelope_get_accessors.phpt +++ b/tests/amqpenvelope_get_accessors.phpt @@ -21,10 +21,10 @@ $q->declareQueue(); // Bind it on the exchange to routing.key $q->bind($ex->getName(), 'routing.*'); // Publish a message to the exchange with a routing key -$ex->publish('message', 'routing.1', AMQP_NOPARAM, array('headers' => array('foo' => 'bar'))); +$ex->publish('message', 'routing.1', null, array('headers' => array('foo' => 'bar'))); // Read from the queue -$msg = $q->get(); +$msg = $q->get(null); var_dump($msg); dump_message($msg); diff --git a/tests/amqpenvelope_var_dump.phpt b/tests/amqpenvelope_var_dump.phpt index 330c1365..0ea191a8 100644 --- a/tests/amqpenvelope_var_dump.phpt +++ b/tests/amqpenvelope_var_dump.phpt @@ -29,7 +29,7 @@ $ex->publish('message', 'routing.1', AMQP_NOPARAM, array("headers" => array("tes // Read from the queue $q->consume("consumeThings"); -$q->consume("consumeThings"); +$q->consume("consumeThings", null); ?> --EXPECTF-- object(AMQPEnvelope)#5 (20) { diff --git a/tests/amqpexchange_delete_null_name.phpt b/tests/amqpexchange_delete_null_name.phpt index cfc94f32..19199952 100644 --- a/tests/amqpexchange_delete_null_name.phpt +++ b/tests/amqpexchange_delete_null_name.phpt @@ -13,7 +13,7 @@ $ex->setName('test.queue.' . bin2hex(random_bytes(32))); $ex->setType(AMQP_EX_TYPE_DIRECT); $ex->declareExchange(); -$ex->delete(null); +$ex->delete(null, null); // Deleting with explicit null deleted the current exchange, so we should be able to redeclare $ex->setType(AMQP_EX_TYPE_FANOUT); diff --git a/tests/amqpqueue_delete_basic.phpt b/tests/amqpqueue_delete_basic.phpt index 4d817f02..b2b231ad 100644 --- a/tests/amqpqueue_delete_basic.phpt +++ b/tests/amqpqueue_delete_basic.phpt @@ -19,7 +19,7 @@ $queue->declareQueue(); $queue->bind($ex->getName()); var_dump($queue->delete()); -var_dump($queue->delete()); +var_dump($queue->delete(null)); $queue->declareQueue(); $queue->bind($ex->getName()); diff --git a/tests/amqpqueue_nack.phpt b/tests/amqpqueue_nack.phpt index 64a688bf..8b630c0c 100644 --- a/tests/amqpqueue_nack.phpt +++ b/tests/amqpqueue_nack.phpt @@ -38,7 +38,7 @@ $q->nack($env->getDeliveryTag(), AMQP_REQUEUE); // read again $env2 = $q->get(AMQP_NOPARAM); if (false !== $env2) { - $q->ack($env2->getDeliveryTag()); + $q->ack($env2->getDeliveryTag(), null); echo $env2->getBody() . PHP_EOL; echo $env2->isRedelivery() ? 'true' : 'false'; echo PHP_EOL; diff --git a/tests/bug_gh155_direct_reply_to.phpt b/tests/bug_gh155_direct_reply_to.phpt index f3a901cb..29f9f340 100644 --- a/tests/bug_gh155_direct_reply_to.phpt +++ b/tests/bug_gh155_direct_reply_to.phpt @@ -48,7 +48,7 @@ $q_reply->declareQueue(); echo 'Publishing response...' . PHP_EOL; -$exchange->publish('response', $reply_to, AMQP_NOPARAM); +$exchange->publish('response', $reply_to); echo 'Waiting for reply...' . PHP_EOL; From f5eaf8a8997fc139793defd9bb8fa6fe49c3ff29 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Thu, 17 Aug 2023 14:49:24 +0200 Subject: [PATCH 055/147] Configurable serialization/deserialization depth (#463) --- amqp.c | 30 +++++++++++++++++++++++++++++- amqp_basic_properties.c | 22 +++++++++++----------- amqp_type.c | 22 +++++++++++----------- php_amqp.h | 5 +++-- 4 files changed, 54 insertions(+), 25 deletions(-) diff --git a/amqp.c b/amqp.c index 7b43fb01..c97106ac 100644 --- a/amqp.c +++ b/amqp.c @@ -217,19 +217,47 @@ PHP_INI_BEGIN() PHP_INI_ENTRY("amqp.cert", DEFAULT_CERT, PHP_INI_ALL, NULL) PHP_INI_ENTRY("amqp.key", DEFAULT_KEY, PHP_INI_ALL, NULL) PHP_INI_ENTRY("amqp.verify", DEFAULT_VERIFY, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("amqp.sasl_method", (const char *) DEFAULT_SASL_METHOD, PHP_INI_ALL, NULL) + PHP_INI_ENTRY("amqp.sasl_method", PHP_AMQP_STRINGIFY(DEFAULT_SASL_METHOD), PHP_INI_ALL, NULL) + STD_PHP_INI_ENTRY( + "amqp.serialization_depth", + DEFAULT_SERIALIZATION_DEPTH, + PHP_INI_ALL, + OnUpdateLongGEZero, + serialization_depth, + zend_amqp_globals, + amqp_globals + ) + STD_PHP_INI_ENTRY( + "amqp.deserialization_depth", + DEFAULT_SERIALIZATION_DEPTH, + PHP_INI_ALL, + OnUpdateLongGEZero, + deserialization_depth, + zend_amqp_globals, + amqp_globals + ) PHP_INI_END() ZEND_DECLARE_MODULE_GLOBALS(amqp) static PHP_GINIT_FUNCTION(amqp) /* {{{ */ { +#if defined(COMPILE_DL_AMQP) && defined(ZTS) + ZEND_TSRMLS_CACHE_UPDATE(); +#endif + + memset(amqp_globals, 0, sizeof(*amqp_globals)); + amqp_globals->error_message = NULL; amqp_globals->error_code = 0; } /* }}} */ static PHP_MINIT_FUNCTION(amqp) /* {{{ */ { +#if defined(COMPILE_DL_AMQP) && defined(ZTS) + ZEND_TSRMLS_CACHE_UPDATE(); +#endif + zend_class_entry ce; /* Set up the connection resource */ diff --git a/amqp_basic_properties.c b/amqp_basic_properties.c index a380c505..d9977901 100644 --- a/amqp_basic_properties.c +++ b/amqp_basic_properties.c @@ -60,9 +60,9 @@ #include "amqp_timestamp.h" #include "amqp_decimal.h" -void php_amqp_basic_properties_table_to_zval_internal(amqp_table_t *table, zval *result, uint8_t depth); -void php_amqp_basic_properties_array_to_zval_internal(amqp_array_t *array, zval *result, uint8_t depth); -bool php_amqp_basic_properties_value_to_zval_internal(amqp_field_value_t *value, zval *result, uint8_t depth); +void php_amqp_basic_properties_table_to_zval_internal(amqp_table_t *table, zval *result, zend_ulong depth); +void php_amqp_basic_properties_array_to_zval_internal(amqp_array_t *array, zval *result, zend_ulong depth); +bool php_amqp_basic_properties_value_to_zval_internal(amqp_field_value_t *value, zval *result, zend_ulong depth); zend_class_entry *amqp_basic_properties_class_entry; #define this_ce amqp_basic_properties_class_entry @@ -562,14 +562,14 @@ PHP_MINIT_FUNCTION(amqp_basic_properties) return SUCCESS; } -bool php_amqp_basic_properties_value_to_zval_internal(amqp_field_value_t *value, zval *result, uint8_t depth) +bool php_amqp_basic_properties_value_to_zval_internal(amqp_field_value_t *value, zval *result, zend_ulong depth) { - if (depth >= PHP_AMQP_RECURSION_DEPTH_LIMIT) { + if (depth > PHP_AMQP_G(deserialization_depth)) { zend_throw_exception_ex( amqp_exception_class_entry, 0, - "Recursion depth limit of %d reached while serializing value", - PHP_AMQP_RECURSION_DEPTH_LIMIT + "Maximum deserialization depth limit of %ld reached while deserializing value", + PHP_AMQP_G(deserialization_depth) ); return 0; } @@ -693,7 +693,7 @@ bool php_amqp_basic_properties_value_to_zval_internal(amqp_field_value_t *value, return 1; } -void php_amqp_basic_properties_array_to_zval_internal(amqp_array_t *array, zval *result, uint8_t depth) +void php_amqp_basic_properties_array_to_zval_internal(amqp_array_t *array, zval *result, zend_ulong depth) { assert(Z_TYPE_P(result) == IS_ARRAY); @@ -701,7 +701,7 @@ void php_amqp_basic_properties_array_to_zval_internal(amqp_array_t *array, zval for (i = 0; i < array->num_entries; ++i) { zval result_nested; ZVAL_UNDEF(&result_nested); - if (php_amqp_basic_properties_value_to_zval_internal(&(array->entries[i]), &result_nested, depth)) { + if (php_amqp_basic_properties_value_to_zval_internal(&(array->entries[i]), &result_nested, depth + 1)) { add_next_index_zval(result, &result_nested); } else if (!Z_ISUNDEF(result_nested)) { zval_ptr_dtor(&result_nested); @@ -709,7 +709,7 @@ void php_amqp_basic_properties_array_to_zval_internal(amqp_array_t *array, zval } } -void php_amqp_basic_properties_table_to_zval_internal(amqp_table_t *table, zval *result, uint8_t depth) +void php_amqp_basic_properties_table_to_zval_internal(amqp_table_t *table, zval *result, zend_ulong depth) { int i; zval result_nested; @@ -719,7 +719,7 @@ void php_amqp_basic_properties_table_to_zval_internal(amqp_table_t *table, zval for (i = 0; i < table->num_entries; ++i) { amqp_table_entry_t *entry = &(table->entries[i]); ZVAL_UNDEF(&result_nested); - if (php_amqp_basic_properties_value_to_zval_internal(&(entry->value), &result_nested, depth)) { + if (php_amqp_basic_properties_value_to_zval_internal(&(entry->value), &result_nested, depth + 1)) { char *key = estrndup(entry->key.bytes, (unsigned) entry->key.len); add_assoc_zval(result, key, &result_nested); efree(key); diff --git a/amqp_type.c b/amqp_type.c index bd7e6afe..5b60d195 100644 --- a/amqp_type.c +++ b/amqp_type.c @@ -41,10 +41,10 @@ static void php_amqp_type_free_amqp_array_internal(amqp_array_t *array); static void php_amqp_type_free_amqp_table_internal(amqp_table_t *object, bool clear_root); -void php_amqp_type_internal_zval_to_amqp_array(zval *value, amqp_array_t *arguments, uint8_t depth); -void php_amqp_type_zval_to_amqp_container_internal(zval *array, amqp_field_value_t **field, uint8_t depth); -void php_amqp_type_zval_to_amqp_table_internal(zval *array, amqp_table_t *amqp_table, uint8_t depth); -bool php_amqp_zval_to_amqp_value_internal(zval *value, amqp_field_value_t **field_ptr, char *key, uint8_t depth); +void php_amqp_type_internal_zval_to_amqp_array(zval *value, amqp_array_t *arguments, zend_ulong depth); +void php_amqp_type_zval_to_amqp_container_internal(zval *array, amqp_field_value_t **field, zend_ulong depth); +void php_amqp_type_zval_to_amqp_table_internal(zval *array, amqp_table_t *amqp_table, zend_ulong depth); +bool php_amqp_zval_to_amqp_value_internal(zval *value, amqp_field_value_t **field_ptr, char *key, zend_ulong depth); amqp_bytes_t php_amqp_type_char_to_amqp_long(char const *cstr, size_t len) { @@ -83,7 +83,7 @@ char *php_amqp_type_amqp_bytes_to_char(amqp_bytes_t bytes) return res; } -void php_amqp_type_zval_to_amqp_container_internal(zval *array, amqp_field_value_t **field, uint8_t depth) +void php_amqp_type_zval_to_amqp_container_internal(zval *array, amqp_field_value_t **field, zend_ulong depth) { HashTable *ht; zend_string *key; @@ -108,7 +108,7 @@ void php_amqp_type_zval_to_amqp_container_internal(zval *array, amqp_field_value } } -void php_amqp_type_zval_to_amqp_table_internal(zval *array, amqp_table_t *amqp_table, uint8_t depth) +void php_amqp_type_zval_to_amqp_table_internal(zval *array, amqp_table_t *amqp_table, zend_ulong depth) { HashTable *ht; zval *value_nested; @@ -163,7 +163,7 @@ void php_amqp_type_zval_to_amqp_table_internal(zval *array, amqp_table_t *amqp_t ZEND_HASH_FOREACH_END(); } -void php_amqp_type_internal_zval_to_amqp_array(zval *value, amqp_array_t *arguments, uint8_t depth) +void php_amqp_type_internal_zval_to_amqp_array(zval *value, amqp_array_t *arguments, zend_ulong depth) { HashTable *ht; @@ -190,18 +190,18 @@ void php_amqp_type_internal_zval_to_amqp_array(zval *value, amqp_array_t *argume ZEND_HASH_FOREACH_END (); } -bool php_amqp_zval_to_amqp_value_internal(zval *value, amqp_field_value_t **field_ptr, char *key, uint8_t depth) +bool php_amqp_zval_to_amqp_value_internal(zval *value, amqp_field_value_t **field_ptr, char *key, zend_ulong depth) { bool result; char type[16]; amqp_field_value_t *field; - if (depth >= PHP_AMQP_RECURSION_DEPTH_LIMIT) { + if (depth > PHP_AMQP_G(serialization_depth)) { zend_throw_exception_ex( amqp_exception_class_entry, 0, - "Recursion depth limit of %d reached while serializing value", - PHP_AMQP_RECURSION_DEPTH_LIMIT + "Maximum serialization depth of %ld reached while serializing value", + PHP_AMQP_G(serialization_depth) ); return 0; } diff --git a/php_amqp.h b/php_amqp.h index e8986f2b..1e479330 100644 --- a/php_amqp.h +++ b/php_amqp.h @@ -256,7 +256,6 @@ struct _amqp_connection_object { #define PHP_AMQP_STRINGIFY(value) PHP_AMQP_TO_STRING(value) #define PHP_AMQP_TO_STRING(value) #value - #define DEFAULT_CHANNEL_MAX PHP_AMQP_STRINGIFY(PHP_AMQP_MAX_CHANNELS) #define DEFAULT_FRAME_MAX PHP_AMQP_STRINGIFY(PHP_AMQP_DEFAULT_FRAME_MAX) #define DEFAULT_HEARTBEAT PHP_AMQP_STRINGIFY(PHP_AMQP_DEFAULT_HEARTBEAT) @@ -264,7 +263,7 @@ struct _amqp_connection_object { #define DEFAULT_CERT "" #define DEFAULT_KEY "" #define DEFAULT_VERIFY "1" - +#define DEFAULT_SERIALIZATION_DEPTH "128" #define IS_PASSIVE(bitmask) (AMQP_PASSIVE & (bitmask)) ? 1 : 0 #define IS_DURABLE(bitmask) (AMQP_DURABLE & (bitmask)) ? 1 : 0 @@ -418,6 +417,8 @@ static inline amqp_channel_object *php_amqp_channel_object_fetch(zend_object *ob ZEND_BEGIN_MODULE_GLOBALS(amqp) char *error_message; zend_long error_code; +zend_long deserialization_depth; +zend_long serialization_depth; ZEND_END_MODULE_GLOBALS(amqp) ZEND_EXTERN_MODULE_GLOBALS(amqp) From 350202f8ace7167c060c5ecab28cd9518bf22a6d Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Thu, 17 Aug 2023 14:58:17 +0200 Subject: [PATCH 056/147] Cosmetics on type functions --- amqp_type.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/amqp_type.c b/amqp_type.c index 5b60d195..5fbc41ca 100644 --- a/amqp_type.c +++ b/amqp_type.c @@ -41,10 +41,15 @@ static void php_amqp_type_free_amqp_array_internal(amqp_array_t *array); static void php_amqp_type_free_amqp_table_internal(amqp_table_t *object, bool clear_root); -void php_amqp_type_internal_zval_to_amqp_array(zval *value, amqp_array_t *arguments, zend_ulong depth); -void php_amqp_type_zval_to_amqp_container_internal(zval *array, amqp_field_value_t **field, zend_ulong depth); +void php_amqp_type_zval_to_amqp_array_internal(zval *value, amqp_array_t *arguments, zend_ulong depth); +void php_amqp_type_zval_to_amqp_container_internal(zval *array, amqp_field_value_t **field_ptr, zend_ulong depth); void php_amqp_type_zval_to_amqp_table_internal(zval *array, amqp_table_t *amqp_table, zend_ulong depth); -bool php_amqp_zval_to_amqp_value_internal(zval *value, amqp_field_value_t **field_ptr, char *key, zend_ulong depth); +bool php_amqp_type_zval_to_amqp_value_internal( + zval *value, + amqp_field_value_t **field_ptr, + char *key, + zend_ulong depth +); amqp_bytes_t php_amqp_type_char_to_amqp_long(char const *cstr, size_t len) { @@ -83,10 +88,11 @@ char *php_amqp_type_amqp_bytes_to_char(amqp_bytes_t bytes) return res; } -void php_amqp_type_zval_to_amqp_container_internal(zval *array, amqp_field_value_t **field, zend_ulong depth) +void php_amqp_type_zval_to_amqp_container_internal(zval *array, amqp_field_value_t **field_ptr, zend_ulong depth) { HashTable *ht; zend_string *key; + amqp_field_value_t *field; ht = Z_ARRVAL_P(array); @@ -99,12 +105,13 @@ void php_amqp_type_zval_to_amqp_container_internal(zval *array, amqp_field_value } ZEND_HASH_FOREACH_END (); + field = *field_ptr; if (is_amqp_array) { - (*field)->kind = AMQP_FIELD_KIND_ARRAY; - php_amqp_type_internal_zval_to_amqp_array(array, &(*field)->value.array, depth); + field->kind = AMQP_FIELD_KIND_ARRAY; + php_amqp_type_zval_to_amqp_array_internal(array, &field->value.array, depth); } else { - (*field)->kind = AMQP_FIELD_KIND_TABLE; - php_amqp_type_zval_to_amqp_table_internal(array, &(*field)->value.table, depth); + field->kind = AMQP_FIELD_KIND_TABLE; + php_amqp_type_zval_to_amqp_table_internal(array, &field->value.table, depth); } } @@ -152,7 +159,7 @@ void php_amqp_type_zval_to_amqp_table_internal(zval *array, amqp_table_t *amqp_t table_entry = &amqp_table->entries[amqp_table->num_entries++]; field = &table_entry->value; - if (!php_amqp_zval_to_amqp_value_internal(value_nested, &field, key, depth + 1)) { + if (!php_amqp_type_zval_to_amqp_value_internal(value_nested, &field, key, depth + 1)) { /* Reset entries counter back */ amqp_table->num_entries--; @@ -163,7 +170,7 @@ void php_amqp_type_zval_to_amqp_table_internal(zval *array, amqp_table_t *amqp_t ZEND_HASH_FOREACH_END(); } -void php_amqp_type_internal_zval_to_amqp_array(zval *value, amqp_array_t *arguments, zend_ulong depth) +void php_amqp_type_zval_to_amqp_array_internal(zval *value, amqp_array_t *arguments, zend_ulong depth) { HashTable *ht; @@ -181,7 +188,7 @@ void php_amqp_type_internal_zval_to_amqp_array(zval *value, amqp_array_t *argume ZEND_HASH_FOREACH_STR_KEY_VAL(ht, zkey, value_nested) amqp_field_value_t *field = &arguments->entries[arguments->num_entries++]; - if (!php_amqp_zval_to_amqp_value_internal(value_nested, &field, ZSTR_VAL(zkey), depth)) { + if (!php_amqp_type_zval_to_amqp_value_internal(value_nested, &field, ZSTR_VAL(zkey), depth)) { /* Reset entries counter back */ arguments->num_entries--; @@ -190,7 +197,7 @@ void php_amqp_type_internal_zval_to_amqp_array(zval *value, amqp_array_t *argume ZEND_HASH_FOREACH_END (); } -bool php_amqp_zval_to_amqp_value_internal(zval *value, amqp_field_value_t **field_ptr, char *key, zend_ulong depth) +bool php_amqp_type_zval_to_amqp_value_internal(zval *value, amqp_field_value_t **field_ptr, char *key, zend_ulong depth) { bool result; char type[16]; From 0603851e4087b206b7961b85d7b530f7c603a0b3 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Thu, 17 Aug 2023 17:58:45 +0200 Subject: [PATCH 057/147] Make test host configurable (#464) --- .env | 1 + .github/workflows/test.yaml | 17 ++-- infra/php/Dockerfile | 5 +- tests/003-channel-consumers.phpt | 16 ++-- tests/004-queue-consume-nested.phpt | 25 ++--- tests/004-queue-consume-orphaned.phpt | 14 +-- tests/amqp_version.phpt | 4 +- tests/amqpbasicproperties.phpt | 4 +- tests/amqpchannel_basicRecover.phpt | 24 ++--- tests/amqpchannel_close.phpt | 12 +-- tests/amqpchannel_confirmSelect.phpt | 6 +- tests/amqpchannel_construct_basic.phpt | 6 +- ...l_construct_ini_global_prefetch_count.phpt | 6 +- ...el_construct_ini_global_prefetch_size.phpt | 4 + ...pchannel_construct_ini_prefetch_count.phpt | 6 +- ...qpchannel_construct_ini_prefetch_size.phpt | 4 + tests/amqpchannel_getChannelId.phpt | 6 +- tests/amqpchannel_get_connection.phpt | 6 +- .../amqpchannel_multi_channel_connection.phpt | 6 +- ...amqpchannel_set_global_prefetch_count.phpt | 6 +- .../amqpchannel_set_global_prefetch_size.phpt | 4 + ...et_prefetch_and_global_prefetch_count.phpt | 6 +- ...set_prefetch_and_global_prefetch_size.phpt | 4 + tests/amqpchannel_set_prefetch_count.phpt | 6 +- tests/amqpchannel_set_prefetch_size.phpt | 4 + tests/amqpchannel_slots_usage.phpt | 6 +- tests/amqpchannel_validation.phpt | 12 +-- tests/amqpchannel_var_dump.phpt | 12 +-- .../amqpconnection_connect_login_failure.phpt | 6 +- tests/amqpconnection_connection_getters.phpt | 7 +- tests/amqpconnection_construct_basic.phpt | 6 +- ...connection_construct_ini_read_timeout.phpt | 6 +- .../amqpconnection_construct_ini_timeout.phpt | 6 +- ...onstruct_ini_timeout_and_read_timeout.phpt | 6 +- ...nection_construct_ini_timeout_default.phpt | 6 +- ...pconnection_construct_params_by_value.phpt | 7 +- ...ection_construct_with_connect_timeout.phpt | 4 +- ...ection_construct_with_connection_name.phpt | 6 +- .../amqpconnection_construct_with_limits.phpt | 10 +- ...connection_construct_with_rpc_timeout.phpt | 6 +- ...amqpconnection_construct_with_timeout.phpt | 4 +- ...nstruct_with_timeout_and_read_timeout.phpt | 4 +- ...nnection_construct_with_write_timeout.phpt | 6 +- tests/amqpconnection_getUsedChannels.phpt | 6 +- tests/amqpconnection_heartbeat.phpt | 6 +- ...mqpconnection_heartbeat_with_consumer.phpt | 8 +- ...pconnection_heartbeat_with_persistent.phpt | 7 +- tests/amqpconnection_nullable_setters.phpt | 4 +- ...connection_persistent_construct_basic.phpt | 6 +- tests/amqpconnection_persistent_in_use.phpt | 7 +- tests/amqpconnection_persistent_reusable.phpt | 7 +- tests/amqpconnection_setConnectionName.phpt | 6 +- tests/amqpconnection_setHost.phpt | 4 +- tests/amqpconnection_setLogin.phpt | 6 +- tests/amqpconnection_setPassword.phpt | 6 +- tests/amqpconnection_setPort_int.phpt | 6 +- .../amqpconnection_setPort_out_of_range.phpt | 6 +- tests/amqpconnection_setPort_string.phpt | 6 +- .../amqpconnection_setReadTimeout_float.phpt | 6 +- tests/amqpconnection_setReadTimeout_int.phpt | 6 +- ...onnection_setReadTimeout_out_of_range.phpt | 4 +- .../amqpconnection_setReadTimeout_string.phpt | 6 +- tests/amqpconnection_setRpcTimeout_float.phpt | 6 +- tests/amqpconnection_setRpcTimeout_int.phpt | 6 +- ...connection_setRpcTimeout_out_of_range.phpt | 6 +- .../amqpconnection_setRpcTimeout_string.phpt | 6 +- tests/amqpconnection_setSaslMethod.phpt | 6 +- .../amqpconnection_setSaslMethod_invalid.phpt | 6 +- .../amqpconnection_setTimeout_deprecated.phpt | 4 +- tests/amqpconnection_setTimeout_float.phpt | 44 ++++----- tests/amqpconnection_setTimeout_int.phpt | 32 ++++--- ...mqpconnection_setTimeout_out_of_range.phpt | 40 ++++---- tests/amqpconnection_setTimeout_string.phpt | 44 ++++----- tests/amqpconnection_setVhost.phpt | 6 +- .../amqpconnection_setWriteTimeout_float.phpt | 6 +- tests/amqpconnection_setWriteTimeout_int.phpt | 6 +- ...nnection_setWriteTimeout_out_of_range.phpt | 6 +- ...amqpconnection_setWriteTimeout_string.phpt | 6 +- tests/amqpconnection_tls_basic.phpt | 1 + tests/amqpconnection_tls_mtls.phpt | 1 + tests/amqpconnection_tls_sasl.phpt | 1 + tests/amqpconnection_toomanychannels.phpt | 6 +- tests/amqpconnection_validation.phpt | 4 +- tests/amqpconnection_var_dump.phpt | 14 +-- tests/amqpdecimal.phpt | 5 +- tests/amqpenvelope_construct.phpt | 5 +- tests/amqpenvelope_get_accessors.phpt | 6 +- tests/amqpenvelope_var_dump.phpt | 7 +- tests/amqpexchange-declare-segfault.phpt | 6 +- tests/amqpexchange_attributes.phpt | 6 +- tests/amqpexchange_bind.phpt | 6 +- tests/amqpexchange_bind_with_arguments.phpt | 6 +- tests/amqpexchange_bind_without_key.phpt | 6 +- ...hange_bind_without_key_with_arguments.phpt | 6 +- tests/amqpexchange_channel_refcount.phpt | 6 +- tests/amqpexchange_construct_basic.phpt | 6 +- tests/amqpexchange_declare_basic.phpt | 6 +- tests/amqpexchange_declare_existent.phpt | 6 +- ...change_declare_with_stalled_reference.phpt | 4 +- tests/amqpexchange_declare_without_name.phpt | 6 +- tests/amqpexchange_declare_without_type.phpt | 6 +- .../amqpexchange_delete_default_exchange.phpt | 6 +- tests/amqpexchange_delete_null_name.phpt | 12 ++- tests/amqpexchange_get_channel.phpt | 6 +- tests/amqpexchange_get_connection.phpt | 6 +- tests/amqpexchange_invalid_type.phpt | 6 +- tests/amqpexchange_name.phpt | 6 +- tests/amqpexchange_publish_basic.phpt | 6 +- tests/amqpexchange_publish_confirms.phpt | 6 +- ...amqpexchange_publish_confirms_consume.phpt | 6 +- ...mqpexchange_publish_empty_routing_key.phpt | 6 +- tests/amqpexchange_publish_mandatory.phpt | 6 +- ...mqpexchange_publish_mandatory_consume.phpt | 6 +- ...h_mandatory_multiple_channels_pitfall.phpt | 6 +- ...amqpexchange_publish_null_routing_key.phpt | 6 +- tests/amqpexchange_publish_timeout.disabled | 6 +- ...pexchange_publish_with_decimal_header.phpt | 8 +- tests/amqpexchange_publish_with_null.phpt | Bin 2032 -> 2122 bytes .../amqpexchange_publish_with_properties.phpt | 6 +- ...ish_with_properties_ignore_num_header.phpt | 6 +- ...ties_ignore_unsupported_header_values.phpt | 6 +- ...publish_with_properties_nested_header.phpt | 8 +- ...blish_with_properties_user_id_failure.phpt | 6 +- ...xchange_publish_with_timestamp_header.phpt | 8 +- tests/amqpexchange_publish_xdeath.phpt | 8 +- tests/amqpexchange_setArgument.phpt | 6 +- tests/amqpexchange_set_flag.phpt | 6 +- tests/amqpexchange_set_flags.phpt | 7 +- tests/amqpexchange_type.phpt | 6 +- tests/amqpexchange_unbind.phpt | 6 +- tests/amqpexchange_unbind_with_arguments.phpt | 6 +- tests/amqpexchange_unbind_without_key.phpt | 6 +- ...nge_unbind_without_key_with_arguments.phpt | 6 +- tests/amqpexchange_var_dump.phpt | 7 +- tests/amqpqueue-cancel-no-consumers.phpt | 13 +-- tests/amqpqueue_attributes.phpt | 6 +- tests/amqpqueue_bind_basic.phpt | 6 +- ...mqpqueue_bind_basic_empty_routing_key.phpt | 6 +- ...mqpqueue_bind_basic_headers_arguments.phpt | 6 +- tests/amqpqueue_bind_null_routing_key.phpt | 6 +- tests/amqpqueue_cancel.phpt | 16 ++-- tests/amqpqueue_construct_basic.phpt | 6 +- tests/amqpqueue_consume_basic.phpt | 6 +- tests/amqpqueue_consume_multiple.phpt | 6 +- ...amqpqueue_consume_multiple_no_doubles.phpt | 6 +- tests/amqpqueue_consume_nonexistent.phpt | 6 +- .../amqpqueue_consume_null_consumer_key.phpt | 6 +- tests/amqpqueue_consume_timeout.phpt | 88 +++++++++--------- tests/amqpqueue_declare_basic.phpt | 6 +- tests/amqpqueue_declare_with_arguments.phpt | 6 +- ...pqueue_declare_with_stalled_reference.phpt | 4 +- tests/amqpqueue_delete_basic.phpt | 6 +- tests/amqpqueue_empty_name.phpt | 6 +- tests/amqpqueue_get_basic.phpt | 6 +- tests/amqpqueue_get_channel.phpt | 6 +- tests/amqpqueue_get_connection.phpt | 6 +- tests/amqpqueue_get_empty_body.phpt | 6 +- tests/amqpqueue_get_headers.phpt | 6 +- tests/amqpqueue_get_nonexistent.phpt | 6 +- tests/amqpqueue_headers_with_bool.phpt | 6 +- tests/amqpqueue_headers_with_float.phpt | 6 +- tests/amqpqueue_headers_with_null.phpt | 6 +- tests/amqpqueue_nack.phpt | 6 +- tests/amqpqueue_nested_arrays.phpt | 6 +- tests/amqpqueue_nested_headers.phpt | 6 +- tests/amqpqueue_purge_basic.phpt | 4 +- tests/amqpqueue_setArgument.phpt | 6 +- tests/amqpqueue_setFlags.phpt | 6 +- ...pqueue_unbind_basic_empty_routing_key.phpt | 6 +- ...pqueue_unbind_basic_headers_arguments.phpt | 6 +- tests/amqpqueue_var_dump.phpt | 7 +- tests/amqptimestamp.phpt | 5 +- tests/bug_17831.phpt | 12 ++- tests/bug_19707.phpt | 6 +- tests/bug_19840.phpt | 8 +- tests/bug_351.phpt | 6 +- tests/bug_385.phpt | 14 +-- tests/bug_61533.phpt | 14 ++- tests/bug_62354.phpt | 4 +- tests/bug_gh147.phpt | 12 ++- tests/bug_gh155_direct_reply_to.phpt | 16 ++-- tests/bug_gh50-1.phpt | 12 ++- tests/bug_gh50-2.phpt | 12 ++- tests/bug_gh50-3.phpt | 19 ++-- tests/bug_gh50-4.phpt | 19 ++-- tests/bug_gh53-2.phpt | 12 ++- tests/bug_gh53.phpt | 14 ++- tests/bug_gh72-1.phpt | 12 ++- tests/bug_gh72-2.phpt | 12 ++- tests/ini_validation_failure.phpt | 4 +- tests/package-version.phpt | 5 +- tests/testtest.phpt | 57 ++++++++++++ 192 files changed, 1104 insertions(+), 488 deletions(-) create mode 100644 tests/testtest.phpt diff --git a/.env b/.env index 7f5e3ad6..15705ef4 100644 --- a/.env +++ b/.env @@ -1,3 +1,4 @@ +PHP_AMQP_HOST=rabbitmq PHP_AMQP_SSL_HOST=rabbitmq.example.org MAKEFLAGS="-j16" CFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror" diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f1ee978e..2e2226af 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -8,7 +8,6 @@ on: env: TEST_TIMEOUT: 120 CFLAGS: -D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror - PHP_AMQP_SSL_HOST: rabbitmq.example.org MAKEFLAGS: -j4 jobs: @@ -99,8 +98,10 @@ jobs: if: needs.dedup.outputs.should_skip != 'true' env: - TEST_PHP_ARGS: -j4 ${{ matrix.test-php-args }} CC: ${{ matrix.compiler }} + TEST_PHP_ARGS: -j4 ${{ matrix.test-php-args }} + PHP_AMQP_HOST: localhost + PHP_AMQP_SSL_HOST: rabbitmq.example.org strategy: fail-fast: false @@ -154,11 +155,15 @@ jobs: - name: Build PHP extension run: phpize && ./configure && make - - name: Test PHP extension - run: make test | tee result.txt + - name: Run minimal test suite + run: make test | tee result-minimal.txt + env: + TEST_PHP_ARGS: -j4 + PHP_AMQP_HOST: "" + PHP_AMQP_SSL_HOST: "" - - name: Dump RabbitMQ logs - run: docker compose logs + - name: Test full test suite + run: make test | tee result-full.txt - name: Benchmark PHP extension run: ./infra/tools/pamqp-php-cli-deterministic -d extension=modules/amqp.so benchmark.php diff --git a/infra/php/Dockerfile b/infra/php/Dockerfile index ce698652..2b54ec1a 100644 --- a/infra/php/Dockerfile +++ b/infra/php/Dockerfile @@ -7,7 +7,6 @@ RUN set -xe; \ RUN apt-get install -yqq build-essential RUN apt-get install -yqq librabbitmq-dev -RUN apt-get install -yqq socat RUN apt-get install -yqq gdb RUN apt-get install -yqq valgrind RUN apt-get install -yqq git @@ -18,9 +17,7 @@ RUN echo 'PATH=$PATH:/src/infra/tools' >> /etc/bash.bashrc COPY --from=composer /usr/bin/composer /usr/local/bin/composer -CMD PHP_AMQP_DOCKER_ENTRYPOINT=1 php /src/infra/tools/pamqp-docker-setup && \ - # Forward localhost:5672 to rabbitmq:5672 (Plain TCP) so that the testsuite can access RabbitMQ on localhost - socat tcp-listen:5672,reuseaddr,fork tcp:rabbitmq:5672 +CMD PHP_AMQP_DOCKER_ENTRYPOINT=1 php /src/infra/tools/pamqp-docker-setup && sleep infinity FROM dev AS dev-all RUN apt-get install -yqq gnupg2 diff --git a/tests/003-channel-consumers.phpt b/tests/003-channel-consumers.phpt index 1fb0311c..faae6216 100644 --- a/tests/003-channel-consumers.phpt +++ b/tests/003-channel-consumers.phpt @@ -1,22 +1,24 @@ --TEST-- AMQPChannel - consumers --SKIPIF-- - + --FILE-- connect(); +$cnn = new AMQPConnection(); +$cnn->setHost(getenv('PHP_AMQP_HOST')); +$cnn->connect(); -$channel1 = new AMQPChannel($connection); +$channel1 = new AMQPChannel($cnn); $q1 = new AMQPQueue($channel1); $q1->setName('q1-' . bin2hex(random_bytes(32))); $q1->declareQueue(); -$channel2 = new AMQPChannel($connection); +$channel2 = new AMQPChannel($cnn); $q2_0 = new AMQPQueue($channel2); $q2_0->setName('q2.0-' . bin2hex(random_bytes(32))); diff --git a/tests/004-queue-consume-nested.phpt b/tests/004-queue-consume-nested.phpt index a56417eb..9f735f02 100644 --- a/tests/004-queue-consume-nested.phpt +++ b/tests/004-queue-consume-nested.phpt @@ -1,9 +1,10 @@ --TEST-- AMQPQueue - nested consumers --SKIPIF-- - + --FILE-- connect(); -$channel1 = new AMQPChannel($connection1); +$cnn1 = new AMQPConnection(); +$cnn1->setHost(getenv('PHP_AMQP_HOST')); +$cnn1->connect(); +$channel1 = new AMQPChannel($cnn1); echo 'With default prefetch = 3', PHP_EOL; test($channel1); $channel1->close(); $channel1 = null; -$connection1->disconnect(); -$connection1 = null; +$cnn1->disconnect(); +$cnn1 = null; // var_dump($channel1); -$connection2 = new AMQPConnection(); -$connection2->connect(); +$cnn2 = new AMQPConnection(); +$cnn2->setHost(getenv('PHP_AMQP_HOST')); +$cnn2->connect(); -$channel2 = new AMQPChannel($connection2); +$channel2 = new AMQPChannel($cnn2); $channel2->setPrefetchCount(1); echo 'With prefetch = 1', PHP_EOL; test($channel2); diff --git a/tests/004-queue-consume-orphaned.phpt b/tests/004-queue-consume-orphaned.phpt index 2a64e168..46aad884 100644 --- a/tests/004-queue-consume-orphaned.phpt +++ b/tests/004-queue-consume-orphaned.phpt @@ -1,15 +1,17 @@ --TEST-- AMQPQueue - orphaned envelope --SKIPIF-- - + --FILE-- connect(); +$cnn = new AMQPConnection(); +$cnn->setHost(getenv('PHP_AMQP_HOST')); +$cnn->connect(); -$channel1 = new AMQPChannel($connection); +$channel1 = new AMQPChannel($cnn); $ex1 = new AMQPExchange($channel1); $ex1->setName('ex1-' . bin2hex(random_bytes(32))); diff --git a/tests/amqp_version.phpt b/tests/amqp_version.phpt index 6fb3a7c7..d1433a16 100644 --- a/tests/amqp_version.phpt +++ b/tests/amqp_version.phpt @@ -1,7 +1,9 @@ --TEST-- AMQP extension version constants --SKIPIF-- - + --FILE-- + --FILE-- --FILE-- connect(); +$cnn_1 = new AMQPConnection(); +$cnn_1->setHost(getenv('PHP_AMQP_HOST')); +$cnn_1->connect(); -$channel_1 = new AMQPChannel($connection_1); +$channel_1 = new AMQPChannel($cnn_1); $channel_1->setPrefetchCount(5); $exchange_1 = new AMQPExchange($channel_1); @@ -45,11 +45,11 @@ $queue_1->consume(function(AMQPEnvelope $e, AMQPQueue $q) use (&$consume) { }); $queue_1->cancel(); // we have to do that to prevent redelivering to the same consumer -$connection_2 = new AMQPConnection(); -$connection_2->setReadTimeout(1); - -$connection_2->connect(); -$channel_2 = new AMQPChannel($connection_2); +$cnn_2 = new AMQPConnection(); +$cnn_2->setReadTimeout(1); +$cnn_2->setHost(getenv('PHP_AMQP_HOST')); +$cnn_2->connect(); +$channel_2 = new AMQPChannel($cnn_2); $channel_2->setPrefetchCount(8); @@ -70,7 +70,7 @@ try { echo get_class($e), "({$e->getCode()}): ", $e->getMessage(), PHP_EOL; } $queue_2->cancel(); -//var_dump($connection_2, $channel_2);die; +//var_dump($cnn_2, $channel_2);die; // yes, we do it repeatedly, basic.recover works in a slightly different way than it looks like. As it said, diff --git a/tests/amqpchannel_close.phpt b/tests/amqpchannel_close.phpt index 5f5aa4d4..ebcb8c9e 100644 --- a/tests/amqpchannel_close.phpt +++ b/tests/amqpchannel_close.phpt @@ -2,18 +2,18 @@ AMQPChannel::close --SKIPIF-- --FILE-- connect(); +$cnn_1 = new AMQPConnection(); +$cnn_1->setHost(getenv('PHP_AMQP_HOST')); +$cnn_1->connect(); -$channel_1 = new AMQPChannel($connection_1); +$channel_1 = new AMQPChannel($cnn_1); $channel_1->setPrefetchCount(5); $exchange_1 = new AMQPExchange($channel_1); diff --git a/tests/amqpchannel_confirmSelect.phpt b/tests/amqpchannel_confirmSelect.phpt index dc62926e..eec9a7d9 100644 --- a/tests/amqpchannel_confirmSelect.phpt +++ b/tests/amqpchannel_confirmSelect.phpt @@ -2,13 +2,13 @@ AMQPChannel::confirmSelect() --SKIPIF-- --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpchannel_construct_basic.phpt b/tests/amqpchannel_construct_basic.phpt index 2714111e..369ef4f9 100644 --- a/tests/amqpchannel_construct_basic.phpt +++ b/tests/amqpchannel_construct_basic.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPChannel constructor --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); echo get_class($ch) . "\n"; diff --git a/tests/amqpchannel_construct_ini_global_prefetch_count.phpt b/tests/amqpchannel_construct_ini_global_prefetch_count.phpt index 3cda5442..3b21e0ba 100644 --- a/tests/amqpchannel_construct_ini_global_prefetch_count.phpt +++ b/tests/amqpchannel_construct_ini_global_prefetch_count.phpt @@ -2,15 +2,15 @@ AMQPChannel - constructor with amqp.global_prefetch_count ini value set --SKIPIF-- --INI-- amqp.global_prefetch_count=123 --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpchannel_construct_ini_global_prefetch_size.phpt b/tests/amqpchannel_construct_ini_global_prefetch_size.phpt index 82b95932..12a57f7e 100644 --- a/tests/amqpchannel_construct_ini_global_prefetch_size.phpt +++ b/tests/amqpchannel_construct_ini_global_prefetch_size.phpt @@ -4,9 +4,12 @@ AMQPChannel - constructor with amqp.global_prefetch_size ini value set setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); $ch->setGlobalPrefetchSize(123); @@ -22,6 +25,7 @@ amqp.global_prefetch_size=123 --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpchannel_construct_ini_prefetch_count.phpt b/tests/amqpchannel_construct_ini_prefetch_count.phpt index def1c3f6..6f3a0d4b 100644 --- a/tests/amqpchannel_construct_ini_prefetch_count.phpt +++ b/tests/amqpchannel_construct_ini_prefetch_count.phpt @@ -2,15 +2,15 @@ AMQPChannel - constructor with amqp.prefetch_count ini value set --SKIPIF-- --INI-- amqp.prefetch_count=123 --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpchannel_construct_ini_prefetch_size.phpt b/tests/amqpchannel_construct_ini_prefetch_size.phpt index fc999d1c..41be13ee 100644 --- a/tests/amqpchannel_construct_ini_prefetch_size.phpt +++ b/tests/amqpchannel_construct_ini_prefetch_size.phpt @@ -4,9 +4,12 @@ AMQPChannel - constructor with amqp.prefetch_size ini value set setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); $ch->setPrefetchSize(123); @@ -22,6 +25,7 @@ amqp.prefetch_size=123 --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpchannel_getChannelId.phpt b/tests/amqpchannel_getChannelId.phpt index 1c539155..26d2a08b 100644 --- a/tests/amqpchannel_getChannelId.phpt +++ b/tests/amqpchannel_getChannelId.phpt @@ -2,13 +2,13 @@ AMQPChannel::getChannelId --SKIPIF-- --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpchannel_get_connection.phpt b/tests/amqpchannel_get_connection.phpt index b0a711f3..e24ff4c7 100644 --- a/tests/amqpchannel_get_connection.phpt +++ b/tests/amqpchannel_get_connection.phpt @@ -2,13 +2,13 @@ AMQPChannel getConnection test --SKIPIF-- --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpchannel_multi_channel_connection.phpt b/tests/amqpchannel_multi_channel_connection.phpt index dfc1323e..4f4d22dc 100644 --- a/tests/amqpchannel_multi_channel_connection.phpt +++ b/tests/amqpchannel_multi_channel_connection.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPConnection - multiple AMQPChannels per AMQPConnection --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpchannel_set_global_prefetch_count.phpt b/tests/amqpchannel_set_global_prefetch_count.phpt index a0a2ee42..959552d6 100644 --- a/tests/amqpchannel_set_global_prefetch_count.phpt +++ b/tests/amqpchannel_set_global_prefetch_count.phpt @@ -2,13 +2,13 @@ AMQPChannel::setGlobalPrefetchCount --SKIPIF-- --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpchannel_set_global_prefetch_size.phpt b/tests/amqpchannel_set_global_prefetch_size.phpt index 46d8b04a..767e95eb 100644 --- a/tests/amqpchannel_set_global_prefetch_size.phpt +++ b/tests/amqpchannel_set_global_prefetch_size.phpt @@ -4,9 +4,12 @@ AMQPChannel::setGlobalPrefetchSize setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); $ch->setGlobalPrefetchSize(123); @@ -20,6 +23,7 @@ if (!extension_loaded("amqp")) { --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpchannel_set_prefetch_and_global_prefetch_count.phpt b/tests/amqpchannel_set_prefetch_and_global_prefetch_count.phpt index 1034a0ed..cd7e5247 100644 --- a/tests/amqpchannel_set_prefetch_and_global_prefetch_count.phpt +++ b/tests/amqpchannel_set_prefetch_and_global_prefetch_count.phpt @@ -2,13 +2,13 @@ AMQPChannel - Setting both consumer and channel wide prefetch counts. --SKIPIF-- --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpchannel_set_prefetch_and_global_prefetch_size.phpt b/tests/amqpchannel_set_prefetch_and_global_prefetch_size.phpt index ef01d0c4..955daaed 100644 --- a/tests/amqpchannel_set_prefetch_and_global_prefetch_size.phpt +++ b/tests/amqpchannel_set_prefetch_and_global_prefetch_size.phpt @@ -4,9 +4,12 @@ AMQPChannel - Setting both consumer and channel wide prefetch sizes. setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); $ch->setPrefetchSize(123); @@ -21,6 +24,7 @@ if (!extension_loaded("amqp")) { --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpchannel_set_prefetch_count.phpt b/tests/amqpchannel_set_prefetch_count.phpt index c8faf5cf..46716d97 100644 --- a/tests/amqpchannel_set_prefetch_count.phpt +++ b/tests/amqpchannel_set_prefetch_count.phpt @@ -2,13 +2,13 @@ AMQPChannel::setPrefetchCount --SKIPIF-- --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpchannel_set_prefetch_size.phpt b/tests/amqpchannel_set_prefetch_size.phpt index d4154119..376f93d1 100644 --- a/tests/amqpchannel_set_prefetch_size.phpt +++ b/tests/amqpchannel_set_prefetch_size.phpt @@ -4,9 +4,12 @@ AMQPChannel::setPrefetchSize setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); $ch->setPrefetchSize(123); @@ -20,6 +23,7 @@ if (!extension_loaded("amqp")) { --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpchannel_slots_usage.phpt b/tests/amqpchannel_slots_usage.phpt index 771dc752..5186f633 100644 --- a/tests/amqpchannel_slots_usage.phpt +++ b/tests/amqpchannel_slots_usage.phpt @@ -2,13 +2,13 @@ AMQPChannel slots usage --SKIPIF-- --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); echo 'Used channels: ', $cnn->getUsedChannels(), PHP_EOL; diff --git a/tests/amqpchannel_validation.phpt b/tests/amqpchannel_validation.phpt index 51acd0df..442fa6de 100644 --- a/tests/amqpchannel_validation.phpt +++ b/tests/amqpchannel_validation.phpt @@ -2,18 +2,18 @@ AMQPChannel parameter validation --SKIPIF-- --FILE-- connect(); +$cnn = new AMQPConnection(); +$cnn->setHost(getenv('PHP_AMQP_HOST')); +$cnn->connect(); -$chan = new AMQPChannel($con); +$chan = new AMQPChannel($cnn); try { $chan->setPrefetchSize(-1); } catch (\Throwable $t) { diff --git a/tests/amqpchannel_var_dump.phpt b/tests/amqpchannel_var_dump.phpt index 4c3d2be1..10239afa 100644 --- a/tests/amqpchannel_var_dump.phpt +++ b/tests/amqpchannel_var_dump.phpt @@ -2,13 +2,13 @@ AMQPChannel var_dump --SKIPIF-- --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); @@ -17,7 +17,7 @@ $cnn->disconnect(); var_dump($ch); ?> ---EXPECT-- +--EXPECTF-- object(AMQPChannel)#2 (6) { ["connection":"AMQPChannel":private]=> object(AMQPConnection)#1 (18) { @@ -26,7 +26,7 @@ object(AMQPChannel)#2 (6) { ["password":"AMQPConnection":private]=> string(5) "guest" ["host":"AMQPConnection":private]=> - string(9) "localhost" + string(%d) "%s" ["vhost":"AMQPConnection":private]=> string(1) "/" ["port":"AMQPConnection":private]=> @@ -78,7 +78,7 @@ object(AMQPChannel)#2 (6) { ["password":"AMQPConnection":private]=> string(5) "guest" ["host":"AMQPConnection":private]=> - string(9) "localhost" + string(%d) "%s" ["vhost":"AMQPConnection":private]=> string(1) "/" ["port":"AMQPConnection":private]=> diff --git a/tests/amqpconnection_connect_login_failure.phpt b/tests/amqpconnection_connect_login_failure.phpt index 3b72a4ec..329323fd 100644 --- a/tests/amqpconnection_connect_login_failure.phpt +++ b/tests/amqpconnection_connect_login_failure.phpt @@ -1,7 +1,10 @@ --TEST-- AMQPConnection connect login failure --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->setLogin('nonexistent-login-'. bin2hex(random_bytes(32))); $cnn->setPassword('nonexistent-password-'. bin2hex(random_bytes(32))); diff --git a/tests/amqpconnection_connection_getters.phpt b/tests/amqpconnection_connection_getters.phpt index 528af416..4c213fee 100644 --- a/tests/amqpconnection_connection_getters.phpt +++ b/tests/amqpconnection_connection_getters.phpt @@ -2,13 +2,13 @@ AMQPConnection - connection-specific getters --SKIPIF-- --FILE-- setHost(getenv('PHP_AMQP_HOST')); echo 'connected: ', var_export($cnn->isConnected(), true), PHP_EOL; echo 'channel_max: ', var_export($cnn->getMaxChannels(), true), PHP_EOL; @@ -34,6 +34,7 @@ echo PHP_EOL; $cnn = new AMQPConnection(array('channel_max' => '10', 'frame_max' => 10240, 'heartbeat' => 10)); +$cnn->setHost(getenv('PHP_AMQP_HOST')); echo 'connected: ', var_export($cnn->isConnected(), true), PHP_EOL; echo 'channel_max: ', var_export($cnn->getMaxChannels(), true), PHP_EOL; diff --git a/tests/amqpconnection_construct_basic.phpt b/tests/amqpconnection_construct_basic.phpt index 087eb0fb..d7482214 100644 --- a/tests/amqpconnection_construct_basic.phpt +++ b/tests/amqpconnection_construct_basic.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPConnection constructor --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); echo get_class($cnn) . "\n"; echo $cnn->isConnected() ? 'true' : 'false', PHP_EOL; diff --git a/tests/amqpconnection_construct_ini_read_timeout.phpt b/tests/amqpconnection_construct_ini_read_timeout.phpt index b108bc30..7a91adf5 100644 --- a/tests/amqpconnection_construct_ini_read_timeout.phpt +++ b/tests/amqpconnection_construct_ini_read_timeout.phpt @@ -1,12 +1,16 @@ --TEST-- AMQPConnection constructor with amqp.read_timeout ini value set --SKIPIF-- - + --INI-- amqp.read_timeout=202.202 --FILE-- setHost(getenv('PHP_AMQP_HOST')); var_dump($cnn->getReadTimeout()); ?> --EXPECTF-- diff --git a/tests/amqpconnection_construct_ini_timeout.phpt b/tests/amqpconnection_construct_ini_timeout.phpt index e600b510..cb5b81a1 100644 --- a/tests/amqpconnection_construct_ini_timeout.phpt +++ b/tests/amqpconnection_construct_ini_timeout.phpt @@ -1,12 +1,16 @@ --TEST-- AMQPConnection constructor with amqp.timeout ini value set --SKIPIF-- - + --INI-- amqp.timeout=101.101 --FILE-- setHost(getenv('PHP_AMQP_HOST')); var_dump($cnn->getReadTimeout()); ?> --EXPECTF-- diff --git a/tests/amqpconnection_construct_ini_timeout_and_read_timeout.phpt b/tests/amqpconnection_construct_ini_timeout_and_read_timeout.phpt index 5e0050da..49047161 100644 --- a/tests/amqpconnection_construct_ini_timeout_and_read_timeout.phpt +++ b/tests/amqpconnection_construct_ini_timeout_and_read_timeout.phpt @@ -1,13 +1,17 @@ --TEST-- AMQPConnection constructor with both amqp.timeout and amqp.read_timeout ini values set --SKIPIF-- - + --INI-- amqp.timeout = 101.101 amqp.read_timeout = 202.202 --FILE-- setHost(getenv('PHP_AMQP_HOST')); var_dump($cnn->getReadTimeout()); ?> --EXPECTF-- diff --git a/tests/amqpconnection_construct_ini_timeout_default.phpt b/tests/amqpconnection_construct_ini_timeout_default.phpt index e702a095..761f82b8 100644 --- a/tests/amqpconnection_construct_ini_timeout_default.phpt +++ b/tests/amqpconnection_construct_ini_timeout_default.phpt @@ -1,12 +1,16 @@ --TEST-- AMQPConnection constructor with amqp.timeout ini value set in code to it default value --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); var_dump($cnn->getReadTimeout()); ?> --EXPECTF-- diff --git a/tests/amqpconnection_construct_params_by_value.phpt b/tests/amqpconnection_construct_params_by_value.phpt index fadc9254..7217927e 100644 --- a/tests/amqpconnection_construct_params_by_value.phpt +++ b/tests/amqpconnection_construct_params_by_value.phpt @@ -2,8 +2,9 @@ Params are passed by value in AMQPConnection::__construct() --SKIPIF-- - - + --FILE-- 'custom_connection_name' ]; -$conn = new \AMQPConnection($params); +$cnn = new AMQPConnection($params); echo gettype($params['host']) . PHP_EOL; echo gettype($params['port']) . PHP_EOL; diff --git a/tests/amqpconnection_construct_with_connect_timeout.phpt b/tests/amqpconnection_construct_with_connect_timeout.phpt index cf58d586..a0745fa7 100644 --- a/tests/amqpconnection_construct_with_connect_timeout.phpt +++ b/tests/amqpconnection_construct_with_connect_timeout.phpt @@ -1,7 +1,9 @@ --TEST-- AMQPConnection constructor with timeout parameter in credentials --SKIPIF-- - + --FILE-- + --FILE-- + --FILE-- 5, ); $cnn = new AMQPConnection($credentials); +$cnn->setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); var_dump($cnn); ?> ---EXPECT-- +--EXPECTF-- object(AMQPConnection)#1 (18) { ["login":"AMQPConnection":private]=> string(5) "guest" ["password":"AMQPConnection":private]=> string(5) "guest" ["host":"AMQPConnection":private]=> - string(9) "localhost" + string(%d) "%s" ["vhost":"AMQPConnection":private]=> string(1) "/" ["port":"AMQPConnection":private]=> diff --git a/tests/amqpconnection_construct_with_rpc_timeout.phpt b/tests/amqpconnection_construct_with_rpc_timeout.phpt index 4eb60970..ef29e52e 100644 --- a/tests/amqpconnection_construct_with_rpc_timeout.phpt +++ b/tests/amqpconnection_construct_with_rpc_timeout.phpt @@ -1,7 +1,9 @@ --TEST-- -AMQPConnection constructor with rpc_timeout parameter in creadentials +AMQPConnection constructor with rpc_timeout parameter in credentials --SKIPIF-- - + --FILE-- 303.303); diff --git a/tests/amqpconnection_construct_with_timeout.phpt b/tests/amqpconnection_construct_with_timeout.phpt index eba2397e..d18c0adc 100644 --- a/tests/amqpconnection_construct_with_timeout.phpt +++ b/tests/amqpconnection_construct_with_timeout.phpt @@ -1,7 +1,9 @@ --TEST-- AMQPConnection constructor with timeout parameter in credentials --SKIPIF-- - + --FILE-- 101.101); diff --git a/tests/amqpconnection_construct_with_timeout_and_read_timeout.phpt b/tests/amqpconnection_construct_with_timeout_and_read_timeout.phpt index 2f7eca19..9dd1f487 100644 --- a/tests/amqpconnection_construct_with_timeout_and_read_timeout.phpt +++ b/tests/amqpconnection_construct_with_timeout_and_read_timeout.phpt @@ -1,7 +1,9 @@ --TEST-- AMQPConnection constructor with both timeout and read_timeout parameters in credentials --SKIPIF-- - + --FILE-- 101.101, 'read_timeout' => 202.202); diff --git a/tests/amqpconnection_construct_with_write_timeout.phpt b/tests/amqpconnection_construct_with_write_timeout.phpt index 27e11519..a455cffb 100644 --- a/tests/amqpconnection_construct_with_write_timeout.phpt +++ b/tests/amqpconnection_construct_with_write_timeout.phpt @@ -1,7 +1,9 @@ --TEST-- -AMQPConnection constructor with write_timeout parameter in creadentials +AMQPConnection constructor with write_timeout parameter in $cnntials --SKIPIF-- - + --FILE-- 303.303); diff --git a/tests/amqpconnection_getUsedChannels.phpt b/tests/amqpconnection_getUsedChannels.phpt index 17fa5aa5..f3a58f68 100644 --- a/tests/amqpconnection_getUsedChannels.phpt +++ b/tests/amqpconnection_getUsedChannels.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPConnection::getUsedChannels() --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); echo get_class($cnn), '::getUsedChannels():', $cnn->getUsedChannels(), PHP_EOL; $cnn->connect(); echo get_class($cnn), '::getUsedChannels():', $cnn->getUsedChannels(), PHP_EOL; diff --git a/tests/amqpconnection_heartbeat.phpt b/tests/amqpconnection_heartbeat.phpt index 8717f7ea..22305f5b 100644 --- a/tests/amqpconnection_heartbeat.phpt +++ b/tests/amqpconnection_heartbeat.phpt @@ -1,12 +1,16 @@ --TEST-- AMQPConnection - heartbeats support --SKIPIF-- - + --FILE-- $heartbeat); $cnn = new AMQPConnection($credentials); +$cnn->setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); echo 'heartbeat: ', var_export($cnn->getHeartbeatInterval(), true), PHP_EOL; diff --git a/tests/amqpconnection_heartbeat_with_consumer.phpt b/tests/amqpconnection_heartbeat_with_consumer.phpt index 713e8ea4..59b19096 100644 --- a/tests/amqpconnection_heartbeat_with_consumer.phpt +++ b/tests/amqpconnection_heartbeat_with_consumer.phpt @@ -1,12 +1,16 @@ --TEST-- AMQPConnection heartbeats support (with active consumer) --SKIPIF-- - + --FILE-- $heartbeat, 'read_timeout' => $heartbeat * 20); $cnn = new AMQPConnection($credentials); +$cnn->setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); var_dump($cnn); @@ -66,7 +70,7 @@ object(AMQPConnection)#1 (18) { ["password":"AMQPConnection":private]=> string(5) "guest" ["host":"AMQPConnection":private]=> - string(9) "localhost" + string(%d) "%s" ["vhost":"AMQPConnection":private]=> string(1) "/" ["port":"AMQPConnection":private]=> diff --git a/tests/amqpconnection_heartbeat_with_persistent.phpt b/tests/amqpconnection_heartbeat_with_persistent.phpt index 79bbcd24..e11c5188 100644 --- a/tests/amqpconnection_heartbeat_with_persistent.phpt +++ b/tests/amqpconnection_heartbeat_with_persistent.phpt @@ -1,13 +1,17 @@ --TEST-- AMQPConnection - heartbeats support with persistent connections --SKIPIF-- - + --FILE-- $heartbeat); $cnn = new AMQPConnection($credentials); +$cnn->setHost(getenv('PHP_AMQP_HOST')); echo 'heartbeat: ', var_export($cnn->getHeartbeatInterval(), true), PHP_EOL; echo 'connected: ', var_export($cnn->isConnected(), true), PHP_EOL; @@ -37,6 +41,7 @@ echo 'persistent: ', var_export($cnn->isPersistent(), true), PHP_EOL; echo PHP_EOL; $cnn = new AMQPConnection($credentials); +$cnn->setHost(getenv('PHP_AMQP_HOST')); $cnn->pconnect(); echo 'heartbeat: ', var_export($cnn->getHeartbeatInterval(), true), PHP_EOL; diff --git a/tests/amqpconnection_nullable_setters.phpt b/tests/amqpconnection_nullable_setters.phpt index b7f8216a..fb57489c 100644 --- a/tests/amqpconnection_nullable_setters.phpt +++ b/tests/amqpconnection_nullable_setters.phpt @@ -1,7 +1,9 @@ --TEST-- AMQPConnection - setters and nullability --SKIPIF-- - + --FILE-- + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->pconnect(); echo get_class($cnn) . "\n"; echo $cnn->isConnected() ? 'true' : 'false', PHP_EOL; diff --git a/tests/amqpconnection_persistent_in_use.phpt b/tests/amqpconnection_persistent_in_use.phpt index 5000f9ae..60aaf147 100644 --- a/tests/amqpconnection_persistent_in_use.phpt +++ b/tests/amqpconnection_persistent_in_use.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPConnection persitent connection resource can't be used by multiple connection --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); echo get_class($cnn), PHP_EOL; $cnn->pconnect(); echo $cnn->isConnected() ? 'true' : 'false', PHP_EOL; @@ -12,6 +16,7 @@ echo $cnn->isConnected() ? 'true' : 'false', PHP_EOL; echo PHP_EOL; $cnn2 = new AMQPConnection(); +$cnn2->setHost(getenv('PHP_AMQP_HOST')); echo get_class($cnn), PHP_EOL; try { diff --git a/tests/amqpconnection_persistent_reusable.phpt b/tests/amqpconnection_persistent_reusable.phpt index 69627711..2a0d4ef7 100644 --- a/tests/amqpconnection_persistent_reusable.phpt +++ b/tests/amqpconnection_persistent_reusable.phpt @@ -1,12 +1,16 @@ --TEST-- AMQPConnection persistent connection are reusable --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->pconnect(); echo get_class($cnn), PHP_EOL; echo $cnn->isConnected() ? 'true' : 'false', PHP_EOL; @@ -25,6 +29,7 @@ if ($manual) { } $cnn = new AMQPConnection(); +$cnn->setHost(getenv('PHP_AMQP_HOST')); $cnn->pconnect(); echo get_class($cnn), PHP_EOL; echo $cnn->isConnected() ? 'true' : 'false', PHP_EOL; diff --git a/tests/amqpconnection_setConnectionName.phpt b/tests/amqpconnection_setConnectionName.phpt index ba1f85e8..26cd90f0 100644 --- a/tests/amqpconnection_setConnectionName.phpt +++ b/tests/amqpconnection_setConnectionName.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPConnection setConnectionName --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); var_dump($cnn->getConnectionName()); $cnn->setConnectionName('custom connection name'); var_dump($cnn->getConnectionName()); diff --git a/tests/amqpconnection_setHost.phpt b/tests/amqpconnection_setHost.phpt index ec6ccf85..8de4b745 100644 --- a/tests/amqpconnection_setHost.phpt +++ b/tests/amqpconnection_setHost.phpt @@ -1,7 +1,9 @@ --TEST-- AMQPConnection setHost --SKIPIF-- - + --FILE-- + --FILE-- setHost(getenv('PHP_AMQP_HOST')); var_dump($cnn->getLogin()); $cnn->setLogin('nonexistent'); var_dump($cnn->getLogin()); diff --git a/tests/amqpconnection_setPassword.phpt b/tests/amqpconnection_setPassword.phpt index 2285b0cf..53371f36 100644 --- a/tests/amqpconnection_setPassword.phpt +++ b/tests/amqpconnection_setPassword.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPConnection setPassword --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); var_dump($cnn->getPassword()); $cnn->setPassword('nonexistent'); var_dump($cnn->getPassword()); diff --git a/tests/amqpconnection_setPort_int.phpt b/tests/amqpconnection_setPort_int.phpt index d6745a3a..29d8e347 100644 --- a/tests/amqpconnection_setPort_int.phpt +++ b/tests/amqpconnection_setPort_int.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPConnection constructor --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $port = 12345; var_dump($cnn->setPort($port)); echo $cnn->getPort(), PHP_EOL; diff --git a/tests/amqpconnection_setPort_out_of_range.phpt b/tests/amqpconnection_setPort_out_of_range.phpt index 99639176..db21f23e 100644 --- a/tests/amqpconnection_setPort_out_of_range.phpt +++ b/tests/amqpconnection_setPort_out_of_range.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPConnection setPort with int out of range --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); try { $cnn->setPort(1234567890); } catch (Exception $e) { diff --git a/tests/amqpconnection_setPort_string.phpt b/tests/amqpconnection_setPort_string.phpt index 21ef8a39..61861a51 100644 --- a/tests/amqpconnection_setPort_string.phpt +++ b/tests/amqpconnection_setPort_string.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPConnection setPort with string --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $port = '12345'; var_dump($cnn->setPort($port)); var_dump($cnn->getPort()); diff --git a/tests/amqpconnection_setReadTimeout_float.phpt b/tests/amqpconnection_setReadTimeout_float.phpt index 6b289118..10b818a0 100644 --- a/tests/amqpconnection_setReadTimeout_float.phpt +++ b/tests/amqpconnection_setReadTimeout_float.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPConnection setReadTimeout float --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->setReadTimeout(.34); var_dump($cnn->getReadTimeout()); $cnn->setReadTimeout(4.7e-2); diff --git a/tests/amqpconnection_setReadTimeout_int.phpt b/tests/amqpconnection_setReadTimeout_int.phpt index 136744dd..9ebcac21 100644 --- a/tests/amqpconnection_setReadTimeout_int.phpt +++ b/tests/amqpconnection_setReadTimeout_int.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPConnection setReadTimeout int --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->setReadTimeout(3); var_dump($cnn->getReadTimeout()); ?> diff --git a/tests/amqpconnection_setReadTimeout_out_of_range.phpt b/tests/amqpconnection_setReadTimeout_out_of_range.phpt index 68d9f362..e01ee663 100644 --- a/tests/amqpconnection_setReadTimeout_out_of_range.phpt +++ b/tests/amqpconnection_setReadTimeout_out_of_range.phpt @@ -1,7 +1,9 @@ --TEST-- AMQPConnection setReadTimeout out of range --SKIPIF-- - + --FILE-- + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->setReadTimeout(".34"); var_dump($cnn->getReadTimeout()); $cnn->setReadTimeout("4.7e-2"); diff --git a/tests/amqpconnection_setRpcTimeout_float.phpt b/tests/amqpconnection_setRpcTimeout_float.phpt index 3aeb92c6..02005a98 100644 --- a/tests/amqpconnection_setRpcTimeout_float.phpt +++ b/tests/amqpconnection_setRpcTimeout_float.phpt @@ -1,11 +1,15 @@ --TEST-- AMQPConnection setRpcTimeout float --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->setRpcTimeout($timeout); var_dump($cnn->getRpcTimeout()); var_dump($timeout); diff --git a/tests/amqpconnection_setRpcTimeout_int.phpt b/tests/amqpconnection_setRpcTimeout_int.phpt index 6219b478..cd450b22 100644 --- a/tests/amqpconnection_setRpcTimeout_int.phpt +++ b/tests/amqpconnection_setRpcTimeout_int.phpt @@ -1,11 +1,15 @@ --TEST-- AMQPConnection setRpcTimeout int --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->setRpcTimeout($timeout); var_dump($cnn->getRpcTimeout()); var_dump($timeout); diff --git a/tests/amqpconnection_setRpcTimeout_out_of_range.phpt b/tests/amqpconnection_setRpcTimeout_out_of_range.phpt index ffe4cd92..e3ed13c4 100644 --- a/tests/amqpconnection_setRpcTimeout_out_of_range.phpt +++ b/tests/amqpconnection_setRpcTimeout_out_of_range.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPConnection setRpcTimeout out of range --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); try { $cnn->setRpcTimeout(-1); } catch (Exception $e) { diff --git a/tests/amqpconnection_setRpcTimeout_string.phpt b/tests/amqpconnection_setRpcTimeout_string.phpt index 807ec1f4..d1ae0da9 100644 --- a/tests/amqpconnection_setRpcTimeout_string.phpt +++ b/tests/amqpconnection_setRpcTimeout_string.phpt @@ -1,11 +1,15 @@ --TEST-- AMQPConnection setRpcTimeout string --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->setRpcTimeout($timeout); var_dump($cnn->getRpcTimeout()); var_dump($timeout); diff --git a/tests/amqpconnection_setSaslMethod.phpt b/tests/amqpconnection_setSaslMethod.phpt index 1752a1c4..a59ae360 100644 --- a/tests/amqpconnection_setSaslMethod.phpt +++ b/tests/amqpconnection_setSaslMethod.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPConnection setSaslMethod int --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->setSaslMethod(0); var_dump($cnn->getSaslMethod()); $cnn->setSaslMethod(1); diff --git a/tests/amqpconnection_setSaslMethod_invalid.phpt b/tests/amqpconnection_setSaslMethod_invalid.phpt index 5e2f35bf..da7c6406 100644 --- a/tests/amqpconnection_setSaslMethod_invalid.phpt +++ b/tests/amqpconnection_setSaslMethod_invalid.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPConnection setSaslMethod invalid --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); try { $cnn->setSaslMethod(-1); } catch (Exception $e) { diff --git a/tests/amqpconnection_setTimeout_deprecated.phpt b/tests/amqpconnection_setTimeout_deprecated.phpt index 5875df3e..92b1a624 100644 --- a/tests/amqpconnection_setTimeout_deprecated.phpt +++ b/tests/amqpconnection_setTimeout_deprecated.phpt @@ -1,7 +1,9 @@ --TEST-- AMQPConnection setTimeout deprecated --SKIPIF-- - + --FILE-- ---FILE-- -setTimeout(.34); -var_dump($cnn->getTimeout()); -$cnn->setTimeout(4.7e-2); -var_dump($cnn->getTimeout());?> ---EXPECTF-- -%s: AMQPConnection::setTimeout(): AMQPConnection::setTimeout($timeout) method is deprecated; use AMQPConnection::setReadTimeout($timeout) instead in %s on line 3 - -%s: AMQPConnection::getTimeout(): AMQPConnection::getTimeout() method is deprecated; use AMQPConnection::getReadTimeout() instead in %s on line 4 -float(0.34) - -%s: AMQPConnection::setTimeout(): AMQPConnection::setTimeout($timeout) method is deprecated; use AMQPConnection::setReadTimeout($timeout) instead in %s on line 5 - -%s: AMQPConnection::getTimeout(): AMQPConnection::getTimeout() method is deprecated; use AMQPConnection::getReadTimeout() instead in %s on line 6 -float(0.047) +--TEST-- +AMQPConnection setTimeout float +--SKIPIF-- + +--FILE-- +setTimeout(.34); +var_dump($cnn->getTimeout()); +$cnn->setTimeout(4.7e-2); +var_dump($cnn->getTimeout());?> +--EXPECTF-- +%s: AMQPConnection::setTimeout(): AMQPConnection::setTimeout($timeout) method is deprecated; use AMQPConnection::setReadTimeout($timeout) instead in %s on line 3 + +%s: AMQPConnection::getTimeout(): AMQPConnection::getTimeout() method is deprecated; use AMQPConnection::getReadTimeout() instead in %s on line 4 +float(0.34) + +%s: AMQPConnection::setTimeout(): AMQPConnection::setTimeout($timeout) method is deprecated; use AMQPConnection::setReadTimeout($timeout) instead in %s on line 5 + +%s: AMQPConnection::getTimeout(): AMQPConnection::getTimeout() method is deprecated; use AMQPConnection::getReadTimeout() instead in %s on line 6 +float(0.047) diff --git a/tests/amqpconnection_setTimeout_int.phpt b/tests/amqpconnection_setTimeout_int.phpt index 85ecabe6..06ab4022 100644 --- a/tests/amqpconnection_setTimeout_int.phpt +++ b/tests/amqpconnection_setTimeout_int.phpt @@ -1,15 +1,17 @@ ---TEST-- -AMQPConnection setTimeout int ---SKIPIF-- - ---FILE-- -setTimeout(3); -var_dump($cnn->getTimeout()); -?> ---EXPECTF-- -%s: AMQPConnection::setTimeout(): AMQPConnection::setTimeout($timeout) method is deprecated; use AMQPConnection::setReadTimeout($timeout) instead in %s on line 3 - -%s: AMQPConnection::getTimeout(): AMQPConnection::getTimeout() method is deprecated; use AMQPConnection::getReadTimeout() instead in %s on line 4 -float(3) +--TEST-- +AMQPConnection setTimeout int +--SKIPIF-- + +--FILE-- +setTimeout(3); +var_dump($cnn->getTimeout()); +?> +--EXPECTF-- +%s: AMQPConnection::setTimeout(): AMQPConnection::setTimeout($timeout) method is deprecated; use AMQPConnection::setReadTimeout($timeout) instead in %s on line 3 + +%s: AMQPConnection::getTimeout(): AMQPConnection::getTimeout() method is deprecated; use AMQPConnection::getReadTimeout() instead in %s on line 4 +float(3) diff --git a/tests/amqpconnection_setTimeout_out_of_range.phpt b/tests/amqpconnection_setTimeout_out_of_range.phpt index 6769f65c..60bfddb9 100644 --- a/tests/amqpconnection_setTimeout_out_of_range.phpt +++ b/tests/amqpconnection_setTimeout_out_of_range.phpt @@ -1,19 +1,21 @@ ---TEST-- -AMQPConnection setTimeout out of range ---SKIPIF-- - ---FILE-- -setTimeout(-1); -} catch (Exception $e) { - echo get_class($e); - echo PHP_EOL; - echo $e->getMessage(); -} -?> ---EXPECTF-- -%s: AMQPConnection::setTimeout(): AMQPConnection::setTimeout($timeout) method is deprecated; use AMQPConnection::setReadTimeout($timeout) instead in %s on line 4 -AMQPConnectionException -Parameter 'timeout' must be greater than or equal to zero. +--TEST-- +AMQPConnection setTimeout out of range +--SKIPIF-- + +--FILE-- +setTimeout(-1); +} catch (Exception $e) { + echo get_class($e); + echo PHP_EOL; + echo $e->getMessage(); +} +?> +--EXPECTF-- +%s: AMQPConnection::setTimeout(): AMQPConnection::setTimeout($timeout) method is deprecated; use AMQPConnection::setReadTimeout($timeout) instead in %s on line 4 +AMQPConnectionException +Parameter 'timeout' must be greater than or equal to zero. diff --git a/tests/amqpconnection_setTimeout_string.phpt b/tests/amqpconnection_setTimeout_string.phpt index c198b4f2..74646984 100644 --- a/tests/amqpconnection_setTimeout_string.phpt +++ b/tests/amqpconnection_setTimeout_string.phpt @@ -1,21 +1,23 @@ ---TEST-- -AMQPConnection setTimeout string ---SKIPIF-- - ---FILE-- -setTimeout(".34"); -var_dump($cnn->getTimeout()); -$cnn->setTimeout("4.7e-2"); -var_dump($cnn->getTimeout());?> ---EXPECTF-- -%s: AMQPConnection::setTimeout(): AMQPConnection::setTimeout($timeout) method is deprecated; use AMQPConnection::setReadTimeout($timeout) instead in %s on line 3 - -%s: AMQPConnection::getTimeout(): AMQPConnection::getTimeout() method is deprecated; use AMQPConnection::getReadTimeout() instead in %s on line 4 -float(0.34) - -%s: AMQPConnection::setTimeout(): AMQPConnection::setTimeout($timeout) method is deprecated; use AMQPConnection::setReadTimeout($timeout) instead in %s on line 5 - -%s: AMQPConnection::getTimeout(): AMQPConnection::getTimeout() method is deprecated; use AMQPConnection::getReadTimeout() instead in %s on line 6 -float(0.047) +--TEST-- +AMQPConnection setTimeout string +--SKIPIF-- + +--FILE-- +setTimeout(".34"); +var_dump($cnn->getTimeout()); +$cnn->setTimeout("4.7e-2"); +var_dump($cnn->getTimeout());?> +--EXPECTF-- +%s: AMQPConnection::setTimeout(): AMQPConnection::setTimeout($timeout) method is deprecated; use AMQPConnection::setReadTimeout($timeout) instead in %s on line 3 + +%s: AMQPConnection::getTimeout(): AMQPConnection::getTimeout() method is deprecated; use AMQPConnection::getReadTimeout() instead in %s on line 4 +float(0.34) + +%s: AMQPConnection::setTimeout(): AMQPConnection::setTimeout($timeout) method is deprecated; use AMQPConnection::setReadTimeout($timeout) instead in %s on line 5 + +%s: AMQPConnection::getTimeout(): AMQPConnection::getTimeout() method is deprecated; use AMQPConnection::getReadTimeout() instead in %s on line 6 +float(0.047) diff --git a/tests/amqpconnection_setVhost.phpt b/tests/amqpconnection_setVhost.phpt index 94899ae7..3e8910ca 100644 --- a/tests/amqpconnection_setVhost.phpt +++ b/tests/amqpconnection_setVhost.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPConnection setVhost --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); var_dump($cnn->getVhost()); $cnn->setVhost('nonexistent'); var_dump($cnn->getVhost()); diff --git a/tests/amqpconnection_setWriteTimeout_float.phpt b/tests/amqpconnection_setWriteTimeout_float.phpt index 8254e29e..ae3b2e6a 100644 --- a/tests/amqpconnection_setWriteTimeout_float.phpt +++ b/tests/amqpconnection_setWriteTimeout_float.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPConnection setWriteTimeout float --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->setWriteTimeout(.34); var_dump($cnn->getWriteTimeout()); $cnn->setWriteTimeout(4.7e-2); diff --git a/tests/amqpconnection_setWriteTimeout_int.phpt b/tests/amqpconnection_setWriteTimeout_int.phpt index 39d334fb..a36f322d 100644 --- a/tests/amqpconnection_setWriteTimeout_int.phpt +++ b/tests/amqpconnection_setWriteTimeout_int.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPConnection setWriteTimeout int --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->setWriteTimeout(3); var_dump($cnn->getWriteTimeout()); ?> diff --git a/tests/amqpconnection_setWriteTimeout_out_of_range.phpt b/tests/amqpconnection_setWriteTimeout_out_of_range.phpt index ec2ddb1e..bb189293 100644 --- a/tests/amqpconnection_setWriteTimeout_out_of_range.phpt +++ b/tests/amqpconnection_setWriteTimeout_out_of_range.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPConnection setWriteTimeout out of range --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); try { $cnn->setWriteTimeout(-1); } catch (Exception $e) { diff --git a/tests/amqpconnection_setWriteTimeout_string.phpt b/tests/amqpconnection_setWriteTimeout_string.phpt index 0b9f917f..9209a8c4 100644 --- a/tests/amqpconnection_setWriteTimeout_string.phpt +++ b/tests/amqpconnection_setWriteTimeout_string.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPConnection setWriteTimeout string --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->setWriteTimeout(".34"); var_dump($cnn->getWriteTimeout()); $cnn->setWriteTimeout("4.7e-2"); diff --git a/tests/amqpconnection_tls_basic.phpt b/tests/amqpconnection_tls_basic.phpt index e831e9be..0e7088c5 100644 --- a/tests/amqpconnection_tls_basic.phpt +++ b/tests/amqpconnection_tls_basic.phpt @@ -3,6 +3,7 @@ AMQPConnection - TLS - CA validation only --SKIPIF-- --FILE-- diff --git a/tests/amqpconnection_tls_mtls.phpt b/tests/amqpconnection_tls_mtls.phpt index eb572d6b..1c8d9288 100644 --- a/tests/amqpconnection_tls_mtls.phpt +++ b/tests/amqpconnection_tls_mtls.phpt @@ -3,6 +3,7 @@ AMQPConnection - TLS - mTLS support --SKIPIF-- + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $channels = array(); diff --git a/tests/amqpconnection_validation.phpt b/tests/amqpconnection_validation.phpt index c0fcee6f..dae915ea 100644 --- a/tests/amqpconnection_validation.phpt +++ b/tests/amqpconnection_validation.phpt @@ -2,9 +2,7 @@ AMQPConnection parameter validation --SKIPIF-- --FILE-- --FILE-- setHost(getenv('PHP_AMQP_HOST')); var_dump($cnn->isConnected()); var_dump($cnn); $cnn->connect(); @@ -21,7 +21,7 @@ $cnn->disconnect(); var_dump($cnn->isConnected()); var_dump($cnn); ?> ---EXPECT-- +--EXPECTF-- bool(false) object(AMQPConnection)#1 (18) { ["login":"AMQPConnection":private]=> @@ -29,7 +29,7 @@ object(AMQPConnection)#1 (18) { ["password":"AMQPConnection":private]=> string(5) "guest" ["host":"AMQPConnection":private]=> - string(9) "localhost" + string(%d) "%s" ["vhost":"AMQPConnection":private]=> string(1) "/" ["port":"AMQPConnection":private]=> @@ -69,7 +69,7 @@ object(AMQPConnection)#1 (18) { ["password":"AMQPConnection":private]=> string(5) "guest" ["host":"AMQPConnection":private]=> - string(9) "localhost" + string(%d) "%s" ["vhost":"AMQPConnection":private]=> string(1) "/" ["port":"AMQPConnection":private]=> @@ -108,7 +108,7 @@ object(AMQPConnection)#1 (18) { ["password":"AMQPConnection":private]=> string(5) "guest" ["host":"AMQPConnection":private]=> - string(9) "localhost" + string(%d) "%s" ["vhost":"AMQPConnection":private]=> string(1) "/" ["port":"AMQPConnection":private]=> diff --git a/tests/amqpdecimal.phpt b/tests/amqpdecimal.phpt index 35b1712a..b120def0 100644 --- a/tests/amqpdecimal.phpt +++ b/tests/amqpdecimal.phpt @@ -2,9 +2,8 @@ AMQPDecimal --SKIPIF-- --FILE-- --FILE-- + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); // Declare a new exchange diff --git a/tests/amqpenvelope_var_dump.phpt b/tests/amqpenvelope_var_dump.phpt index 0ea191a8..7aa10c53 100644 --- a/tests/amqpenvelope_var_dump.phpt +++ b/tests/amqpenvelope_var_dump.phpt @@ -2,14 +2,15 @@ AMQPEnvelope var_dump --SKIPIF-- --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); // Declare a new exchange diff --git a/tests/amqpexchange-declare-segfault.phpt b/tests/amqpexchange-declare-segfault.phpt index d8f23929..7139663b 100644 --- a/tests/amqpexchange-declare-segfault.phpt +++ b/tests/amqpexchange-declare-segfault.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPExchange --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $name = "exchange-" . bin2hex(random_bytes(32)); diff --git a/tests/amqpexchange_attributes.phpt b/tests/amqpexchange_attributes.phpt index c0769829..27e25598 100644 --- a/tests/amqpexchange_attributes.phpt +++ b/tests/amqpexchange_attributes.phpt @@ -2,13 +2,13 @@ AMQPExchange attributes --SKIPIF-- --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_bind.phpt b/tests/amqpexchange_bind.phpt index 67f278f0..7b1c9168 100644 --- a/tests/amqpexchange_bind.phpt +++ b/tests/amqpexchange_bind.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPExchange::bind --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_bind_with_arguments.phpt b/tests/amqpexchange_bind_with_arguments.phpt index f2c686ab..19d98a1d 100644 --- a/tests/amqpexchange_bind_with_arguments.phpt +++ b/tests/amqpexchange_bind_with_arguments.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPExchange::bind with arguments --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_bind_without_key.phpt b/tests/amqpexchange_bind_without_key.phpt index 8d25a762..b6753b97 100644 --- a/tests/amqpexchange_bind_without_key.phpt +++ b/tests/amqpexchange_bind_without_key.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPExchange::bind without key --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_bind_without_key_with_arguments.phpt b/tests/amqpexchange_bind_without_key_with_arguments.phpt index a68a71e4..8cc50014 100644 --- a/tests/amqpexchange_bind_without_key_with_arguments.phpt +++ b/tests/amqpexchange_bind_without_key_with_arguments.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPExchange::bind without key with arguments --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_channel_refcount.phpt b/tests/amqpexchange_channel_refcount.phpt index af23e4e9..e391d631 100644 --- a/tests/amqpexchange_channel_refcount.phpt +++ b/tests/amqpexchange_channel_refcount.phpt @@ -1,11 +1,15 @@ --TEST-- AMQPExchange channel refcount --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_construct_basic.phpt b/tests/amqpexchange_construct_basic.phpt index 6410ea1d..a4848d12 100644 --- a/tests/amqpexchange_construct_basic.phpt +++ b/tests/amqpexchange_construct_basic.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPExchange constructor --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_declare_basic.phpt b/tests/amqpexchange_declare_basic.phpt index eaa90183..afef0770 100644 --- a/tests/amqpexchange_declare_basic.phpt +++ b/tests/amqpexchange_declare_basic.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPExchange --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_declare_existent.phpt b/tests/amqpexchange_declare_existent.phpt index 0a55649c..ce0bdbdc 100644 --- a/tests/amqpexchange_declare_existent.phpt +++ b/tests/amqpexchange_declare_existent.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPExchange --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_declare_with_stalled_reference.phpt b/tests/amqpexchange_declare_with_stalled_reference.phpt index d80e18bf..55402817 100644 --- a/tests/amqpexchange_declare_with_stalled_reference.phpt +++ b/tests/amqpexchange_declare_with_stalled_reference.phpt @@ -1,7 +1,9 @@ --TEST-- AMQPExchange - declare with stalled reference --SKIPIF-- - + --FILE-- + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_declare_without_type.phpt b/tests/amqpexchange_declare_without_type.phpt index eec35306..856652e3 100644 --- a/tests/amqpexchange_declare_without_type.phpt +++ b/tests/amqpexchange_declare_without_type.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPExchange::declareExchange() without type set --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_delete_default_exchange.phpt b/tests/amqpexchange_delete_default_exchange.phpt index 276233f4..6ec83b52 100644 --- a/tests/amqpexchange_delete_default_exchange.phpt +++ b/tests/amqpexchange_delete_default_exchange.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPExchange::delete() --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_delete_null_name.phpt b/tests/amqpexchange_delete_null_name.phpt index 19199952..c6b1b2ae 100644 --- a/tests/amqpexchange_delete_null_name.phpt +++ b/tests/amqpexchange_delete_null_name.phpt @@ -1,12 +1,16 @@ --TEST-- AMQPExchange::delete with explicit null as exchange name --SKIPIF-- - + --FILE-- connect(); -$chan = new AMQPChannel($con); +$cnn = new AMQPConnection(); +$cnn->setHost(getenv('PHP_AMQP_HOST')); +$cnn->connect(); +$chan = new AMQPChannel($cnn); $ex = new AMQPExchange($chan); $ex->setName('test.queue.' . bin2hex(random_bytes(32))); diff --git a/tests/amqpexchange_get_channel.phpt b/tests/amqpexchange_get_channel.phpt index f235f2af..420bdb30 100644 --- a/tests/amqpexchange_get_channel.phpt +++ b/tests/amqpexchange_get_channel.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPExchange getChannel() test --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_get_connection.phpt b/tests/amqpexchange_get_connection.phpt index e5974093..4fde3ac5 100644 --- a/tests/amqpexchange_get_connection.phpt +++ b/tests/amqpexchange_get_connection.phpt @@ -2,13 +2,13 @@ AMQPExchange getConnection test --SKIPIF-- --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_invalid_type.phpt b/tests/amqpexchange_invalid_type.phpt index 99cb7490..215a1c73 100644 --- a/tests/amqpexchange_invalid_type.phpt +++ b/tests/amqpexchange_invalid_type.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPExchange --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_name.phpt b/tests/amqpexchange_name.phpt index e8ed0383..41282837 100644 --- a/tests/amqpexchange_name.phpt +++ b/tests/amqpexchange_name.phpt @@ -2,13 +2,13 @@ AMQPExchange getConnection test --SKIPIF-- --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_publish_basic.phpt b/tests/amqpexchange_publish_basic.phpt index 3f49d562..f982da4f 100644 --- a/tests/amqpexchange_publish_basic.phpt +++ b/tests/amqpexchange_publish_basic.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPExchange --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_publish_confirms.phpt b/tests/amqpexchange_publish_confirms.phpt index 870d54b2..6941f24c 100644 --- a/tests/amqpexchange_publish_confirms.phpt +++ b/tests/amqpexchange_publish_confirms.phpt @@ -1,7 +1,10 @@ --TEST-- AMQPExchange::publish() - publish with confirms --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); //$cnn->setReadTimeout(2); $cnn->connect(); diff --git a/tests/amqpexchange_publish_confirms_consume.phpt b/tests/amqpexchange_publish_confirms_consume.phpt index 2e3880c1..f98008af 100644 --- a/tests/amqpexchange_publish_confirms_consume.phpt +++ b/tests/amqpexchange_publish_confirms_consume.phpt @@ -1,7 +1,10 @@ --TEST-- AMQPExchange::publish() - publish in conform mode and handle conforms with AMQPQueue::consume() method --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->setReadTimeout(2); $cnn->connect(); diff --git a/tests/amqpexchange_publish_empty_routing_key.phpt b/tests/amqpexchange_publish_empty_routing_key.phpt index 0583e013..ee9bd062 100644 --- a/tests/amqpexchange_publish_empty_routing_key.phpt +++ b/tests/amqpexchange_publish_empty_routing_key.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPExchange publish with empty routing key --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_publish_mandatory.phpt b/tests/amqpexchange_publish_mandatory.phpt index 3efaaa8e..eeb53a1b 100644 --- a/tests/amqpexchange_publish_mandatory.phpt +++ b/tests/amqpexchange_publish_mandatory.phpt @@ -1,7 +1,10 @@ --TEST-- AMQPExchange::publish() - publish unroutable mandatory --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); //$cnn->setReadTimeout(2); $cnn->connect(); diff --git a/tests/amqpexchange_publish_mandatory_consume.phpt b/tests/amqpexchange_publish_mandatory_consume.phpt index 09f68bad..d1da3862 100644 --- a/tests/amqpexchange_publish_mandatory_consume.phpt +++ b/tests/amqpexchange_publish_mandatory_consume.phpt @@ -1,7 +1,10 @@ --TEST-- AMQPExchange::publish() - publish unroutable with mandatory flag and handle them with AMQPQueue::consume() method --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->setReadTimeout(2); $cnn->connect(); diff --git a/tests/amqpexchange_publish_mandatory_multiple_channels_pitfall.phpt b/tests/amqpexchange_publish_mandatory_multiple_channels_pitfall.phpt index a03812ee..a2360159 100644 --- a/tests/amqpexchange_publish_mandatory_multiple_channels_pitfall.phpt +++ b/tests/amqpexchange_publish_mandatory_multiple_channels_pitfall.phpt @@ -1,7 +1,10 @@ --TEST-- AMQPExchange::publish() - publish unroutable mandatory on multiple channels pitfall --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); diff --git a/tests/amqpexchange_publish_null_routing_key.phpt b/tests/amqpexchange_publish_null_routing_key.phpt index 65e1f613..09da5fc5 100644 --- a/tests/amqpexchange_publish_null_routing_key.phpt +++ b/tests/amqpexchange_publish_null_routing_key.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPExchange publish with null routing key --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_publish_timeout.disabled b/tests/amqpexchange_publish_timeout.disabled index 95529c35..01437ac2 100644 --- a/tests/amqpexchange_publish_timeout.disabled +++ b/tests/amqpexchange_publish_timeout.disabled @@ -9,10 +9,10 @@ if (getenv("SKIP_SLOW_TESTS")) print "skip slow test" ; $timeout)); -$conn->connect(); +$cnn = new AMQPConnection(array('write_timeout' => $timeout)); +$cnn->connect(); -$chan = new AMQPChannel($conn); +$chan = new AMQPChannel($cnn); $ex = new AMQPExchange($chan); $ex->setName("exchange-pub-timeout-" . time()); diff --git a/tests/amqpexchange_publish_with_decimal_header.phpt b/tests/amqpexchange_publish_with_decimal_header.phpt index 7dc23baf..cea70b38 100644 --- a/tests/amqpexchange_publish_with_decimal_header.phpt +++ b/tests/amqpexchange_publish_with_decimal_header.phpt @@ -1,12 +1,14 @@ --TEST-- AMQPExchange publish with decimal header --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_publish_with_null.phpt b/tests/amqpexchange_publish_with_null.phpt index 2f8a6929d0ff772a96c67df7f0b541a0a3e71eda..9737540fc703a5ecc6dab496180157a2b3c54d2a 100644 GIT binary patch delta 122 zcmeyse@bA2D zrQ+<&0wrs%iN!~m^71BIFq&%R<>}fLrl@PU7VE2F|hHyt1`|LEj2M$^eh8MQWlWQ=430HK}=p8x;= diff --git a/tests/amqpexchange_publish_with_properties.phpt b/tests/amqpexchange_publish_with_properties.phpt index 1cdb3e3e..4bc4bc72 100644 --- a/tests/amqpexchange_publish_with_properties.phpt +++ b/tests/amqpexchange_publish_with_properties.phpt @@ -1,12 +1,16 @@ --TEST-- AMQPExchange publish with properties --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_publish_with_properties_ignore_num_header.phpt b/tests/amqpexchange_publish_with_properties_ignore_num_header.phpt index 56b4d729..8aec9244 100644 --- a/tests/amqpexchange_publish_with_properties_ignore_num_header.phpt +++ b/tests/amqpexchange_publish_with_properties_ignore_num_header.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPExchange publish with properties - ignore numeric keys in headers --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); 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 cf7243b0..57430e4e 100644 --- a/tests/amqpexchange_publish_with_properties_ignore_unsupported_header_values.phpt +++ b/tests/amqpexchange_publish_with_properties_ignore_unsupported_header_values.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPExchange publish with properties - ignore unsupported header values (NULL, object, resources) --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_publish_with_properties_nested_header.phpt b/tests/amqpexchange_publish_with_properties_nested_header.phpt index 84d5f6d0..33c10c73 100644 --- a/tests/amqpexchange_publish_with_properties_nested_header.phpt +++ b/tests/amqpexchange_publish_with_properties_nested_header.phpt @@ -1,12 +1,14 @@ --TEST-- AMQPExchange publish with properties - nested header values --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_publish_with_properties_user_id_failure.phpt b/tests/amqpexchange_publish_with_properties_user_id_failure.phpt index dbcf050c..ee1cf0b6 100644 --- a/tests/amqpexchange_publish_with_properties_user_id_failure.phpt +++ b/tests/amqpexchange_publish_with_properties_user_id_failure.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPExchange publish with properties - user_id failure --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_publish_with_timestamp_header.phpt b/tests/amqpexchange_publish_with_timestamp_header.phpt index a66ce013..f9c9cfbe 100644 --- a/tests/amqpexchange_publish_with_timestamp_header.phpt +++ b/tests/amqpexchange_publish_with_timestamp_header.phpt @@ -1,12 +1,14 @@ --TEST-- AMQPExchange publish with timestamp header --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_publish_xdeath.phpt b/tests/amqpexchange_publish_xdeath.phpt index 437ff129..0346fccf 100644 --- a/tests/amqpexchange_publish_xdeath.phpt +++ b/tests/amqpexchange_publish_xdeath.phpt @@ -1,12 +1,14 @@ --TEST-- AMQPExchange publish with properties - nested header values --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_setArgument.phpt b/tests/amqpexchange_setArgument.phpt index a3379c13..ba1b57a2 100644 --- a/tests/amqpexchange_setArgument.phpt +++ b/tests/amqpexchange_setArgument.phpt @@ -1,12 +1,16 @@ --TEST-- AMQPExchange::setArgument() test --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_set_flag.phpt b/tests/amqpexchange_set_flag.phpt index 82cdd608..71c4cdf5 100644 --- a/tests/amqpexchange_set_flag.phpt +++ b/tests/amqpexchange_set_flag.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPExchange set flag string --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_set_flags.phpt b/tests/amqpexchange_set_flags.phpt index 17e2b696..eb33d5a1 100644 --- a/tests/amqpexchange_set_flags.phpt +++ b/tests/amqpexchange_set_flags.phpt @@ -2,12 +2,13 @@ AMQPExchange setFlags() --SKIPIF-- --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); // Declare a new exchange diff --git a/tests/amqpexchange_type.phpt b/tests/amqpexchange_type.phpt index 1c997746..7431a8f1 100644 --- a/tests/amqpexchange_type.phpt +++ b/tests/amqpexchange_type.phpt @@ -2,13 +2,13 @@ AMQPExchange getConnection test --SKIPIF-- --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_unbind.phpt b/tests/amqpexchange_unbind.phpt index 4586f6a4..01fa25ac 100644 --- a/tests/amqpexchange_unbind.phpt +++ b/tests/amqpexchange_unbind.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPExchange::unbind --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_unbind_with_arguments.phpt b/tests/amqpexchange_unbind_with_arguments.phpt index 0faecff3..a5814baa 100644 --- a/tests/amqpexchange_unbind_with_arguments.phpt +++ b/tests/amqpexchange_unbind_with_arguments.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPExchange::unbind with arguments --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_unbind_without_key.phpt b/tests/amqpexchange_unbind_without_key.phpt index 12904c55..623138fe 100644 --- a/tests/amqpexchange_unbind_without_key.phpt +++ b/tests/amqpexchange_unbind_without_key.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPExchange::unbind without key --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_unbind_without_key_with_arguments.phpt b/tests/amqpexchange_unbind_without_key_with_arguments.phpt index d1e9e225..d7c7746e 100644 --- a/tests/amqpexchange_unbind_without_key_with_arguments.phpt +++ b/tests/amqpexchange_unbind_without_key_with_arguments.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPExchange::unbind without key with arguments --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpexchange_var_dump.phpt b/tests/amqpexchange_var_dump.phpt index e75bb6d0..939816d8 100644 --- a/tests/amqpexchange_var_dump.phpt +++ b/tests/amqpexchange_var_dump.phpt @@ -2,12 +2,13 @@ AMQPExchange var_dump --SKIPIF-- --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); // Declare a new exchange diff --git a/tests/amqpqueue-cancel-no-consumers.phpt b/tests/amqpqueue-cancel-no-consumers.phpt index 11fa2c31..0d68672d 100644 --- a/tests/amqpqueue-cancel-no-consumers.phpt +++ b/tests/amqpqueue-cancel-no-consumers.phpt @@ -1,18 +1,19 @@ --TEST-- AMQPQueue - orphaned envelope --SKIPIF-- - +createContext(); -$conn = new AMQPConnection(); -$conn->connect(); +$cnn = new AMQPConnection(); +$cnn->setHost(getenv('PHP_AMQP_HOST')); +$cnn->connect(); -$extChannel = new AMQPChannel($conn); +$extChannel = new AMQPChannel($cnn); $extChannel->qos(0, 3); $microtime = microtime('true'); diff --git a/tests/amqpqueue_attributes.phpt b/tests/amqpqueue_attributes.phpt index fb7bcc14..fe8996d6 100644 --- a/tests/amqpqueue_attributes.phpt +++ b/tests/amqpqueue_attributes.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPQueue attributes --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_bind_basic.phpt b/tests/amqpqueue_bind_basic.phpt index f515edfd..d45f27c2 100644 --- a/tests/amqpqueue_bind_basic.phpt +++ b/tests/amqpqueue_bind_basic.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPQueue --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_bind_basic_empty_routing_key.phpt b/tests/amqpqueue_bind_basic_empty_routing_key.phpt index 2d71bc7f..ea9d6416 100644 --- a/tests/amqpqueue_bind_basic_empty_routing_key.phpt +++ b/tests/amqpqueue_bind_basic_empty_routing_key.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPQueue --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_bind_basic_headers_arguments.phpt b/tests/amqpqueue_bind_basic_headers_arguments.phpt index 0ae97026..6325afef 100644 --- a/tests/amqpqueue_bind_basic_headers_arguments.phpt +++ b/tests/amqpqueue_bind_basic_headers_arguments.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPQueue --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_bind_null_routing_key.phpt b/tests/amqpqueue_bind_null_routing_key.phpt index 57881e3a..bec83281 100644 --- a/tests/amqpqueue_bind_null_routing_key.phpt +++ b/tests/amqpqueue_bind_null_routing_key.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPQueue bind/unbind with explicit null routing key --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_cancel.phpt b/tests/amqpqueue_cancel.phpt index c2e94ecc..2e2b6e45 100644 --- a/tests/amqpqueue_cancel.phpt +++ b/tests/amqpqueue_cancel.phpt @@ -1,17 +1,21 @@ --TEST-- AMQPQueue cancel --SKIPIF-- - + --FILE-- connect(); - return $conn; + $cnn = new AMQPConnection(); + $cnn->setHost(getenv('PHP_AMQP_HOST')); + $cnn->connect(); + return $cnn; } -function create_channel($connection) { - $channel = new AMQPChannel($connection); +function create_channel($cnn) { + $channel = new AMQPChannel($cnn); $channel->setPrefetchCount(1); return $channel; } diff --git a/tests/amqpqueue_construct_basic.phpt b/tests/amqpqueue_construct_basic.phpt index 57ea772f..fb263bac 100644 --- a/tests/amqpqueue_construct_basic.phpt +++ b/tests/amqpqueue_construct_basic.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPQueue constructor --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_consume_basic.phpt b/tests/amqpqueue_consume_basic.phpt index 2fe68157..0c7ae1af 100644 --- a/tests/amqpqueue_consume_basic.phpt +++ b/tests/amqpqueue_consume_basic.phpt @@ -1,12 +1,16 @@ --TEST-- AMQPQueue::consume basic --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_consume_multiple.phpt b/tests/amqpqueue_consume_multiple.phpt index 7184ee16..e34d54cb 100644 --- a/tests/amqpqueue_consume_multiple.phpt +++ b/tests/amqpqueue_consume_multiple.phpt @@ -1,12 +1,16 @@ --TEST-- AMQPQueue::consume multiple --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_consume_multiple_no_doubles.phpt b/tests/amqpqueue_consume_multiple_no_doubles.phpt index f59cadc4..a2ad95e6 100644 --- a/tests/amqpqueue_consume_multiple_no_doubles.phpt +++ b/tests/amqpqueue_consume_multiple_no_doubles.phpt @@ -1,12 +1,16 @@ --TEST-- AMQPQueue::consume multiple (no doubles) --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_consume_nonexistent.phpt b/tests/amqpqueue_consume_nonexistent.phpt index 4e4c1250..cc601810 100644 --- a/tests/amqpqueue_consume_nonexistent.phpt +++ b/tests/amqpqueue_consume_nonexistent.phpt @@ -1,12 +1,16 @@ --TEST-- AMQPQueue::consume from nonexistent queue --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->setReadTimeout(10); // both are empirical values that should be far enough to deal with busy RabbitMQ broker $cnn->setWriteTimeout(10); $cnn->connect(); diff --git a/tests/amqpqueue_consume_null_consumer_key.phpt b/tests/amqpqueue_consume_null_consumer_key.phpt index d8944f8e..eb2a1e19 100644 --- a/tests/amqpqueue_consume_null_consumer_key.phpt +++ b/tests/amqpqueue_consume_null_consumer_key.phpt @@ -1,12 +1,16 @@ --TEST-- AMQPQueue::consume basic --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_consume_timeout.phpt b/tests/amqpqueue_consume_timeout.phpt index 861c911c..dcba12fe 100644 --- a/tests/amqpqueue_consume_timeout.phpt +++ b/tests/amqpqueue_consume_timeout.phpt @@ -1,42 +1,46 @@ ---TEST-- -AMQPQueue::consume with timeout ---SKIPIF-- - ---FILE-- - $timeout)); -$conn->connect(); -$chan = new AMQPChannel($conn); -$queue = new AMQPQueue($chan); -$queue->setFlags(AMQP_EXCLUSIVE); -$queue->declareQueue(); -$start = microtime(true); -try { - $queue->consume('nop'); -} catch (AMQPException $e) { - echo get_class($e), "({$e->getCode()}): ", $e->getMessage(); - echo PHP_EOL; -} -$end = microtime(true); -$error = $end - $start - $timeout; -$limit = abs(log10($timeout)); // empirical value - -echo 'timeout: ', $timeout, PHP_EOL; -echo 'takes: ', $end - $start, PHP_EOL; -echo 'error: ', $error, PHP_EOL; -echo 'limit: ', $limit, PHP_EOL; - -echo abs($error) <= $limit ? 'timings OK' : 'timings failed'; // error should be less than 5% of timeout value -$queue->delete(); -?> ---EXPECTF-- -AMQPQueueException(0): Consumer timeout exceed -timeout: %f -takes: %f -error: %f -limit: %f -timings OK +--TEST-- +AMQPQueue::consume with timeout +--SKIPIF-- + +--FILE-- + $timeout)); +$cnn->setHost(getenv('PHP_AMQP_HOST')); +$cnn->connect(); +$chan = new AMQPChannel($cnn); +$queue = new AMQPQueue($chan); +$queue->setFlags(AMQP_EXCLUSIVE); +$queue->declareQueue(); +$start = microtime(true); +try { + $queue->consume('nop'); +} catch (AMQPException $e) { + echo get_class($e), "({$e->getCode()}): ", $e->getMessage(); + echo PHP_EOL; +} +$end = microtime(true); +$error = $end - $start - $timeout; +$limit = abs(log10($timeout)); // empirical value + +echo 'timeout: ', $timeout, PHP_EOL; +echo 'takes: ', $end - $start, PHP_EOL; +echo 'error: ', $error, PHP_EOL; +echo 'limit: ', $limit, PHP_EOL; + +echo abs($error) <= $limit ? 'timings OK' : 'timings failed'; // error should be less than 5% of timeout value +$queue->delete(); +?> +--EXPECTF-- +AMQPQueueException(0): Consumer timeout exceed +timeout: %f +takes: %f +error: %f +limit: %f +timings OK diff --git a/tests/amqpqueue_declare_basic.phpt b/tests/amqpqueue_declare_basic.phpt index f0c2c190..1e4b559e 100644 --- a/tests/amqpqueue_declare_basic.phpt +++ b/tests/amqpqueue_declare_basic.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPQueue --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_declare_with_arguments.phpt b/tests/amqpqueue_declare_with_arguments.phpt index 5f173eb1..0456e37e 100644 --- a/tests/amqpqueue_declare_with_arguments.phpt +++ b/tests/amqpqueue_declare_with_arguments.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPQueue::declareQueue() - with arguments --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_declare_with_stalled_reference.phpt b/tests/amqpqueue_declare_with_stalled_reference.phpt index 0dfdd39c..3e67a465 100644 --- a/tests/amqpqueue_declare_with_stalled_reference.phpt +++ b/tests/amqpqueue_declare_with_stalled_reference.phpt @@ -1,7 +1,9 @@ --TEST-- AMQPQueue - declare with stalled reference --SKIPIF-- - + --FILE-- + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_empty_name.phpt b/tests/amqpqueue_empty_name.phpt index c13daf92..4554b651 100644 --- a/tests/amqpqueue_empty_name.phpt +++ b/tests/amqpqueue_empty_name.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPQueue declared with empty name --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_get_basic.phpt b/tests/amqpqueue_get_basic.phpt index 4635a2c4..fd160f6c 100644 --- a/tests/amqpqueue_get_basic.phpt +++ b/tests/amqpqueue_get_basic.phpt @@ -1,12 +1,16 @@ --TEST-- AMQPQueue::get basic --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_get_channel.phpt b/tests/amqpqueue_get_channel.phpt index 974efe4a..4e50c294 100644 --- a/tests/amqpqueue_get_channel.phpt +++ b/tests/amqpqueue_get_channel.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPQueue getChannel() test --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_get_connection.phpt b/tests/amqpqueue_get_connection.phpt index fcb885d7..2591197c 100644 --- a/tests/amqpqueue_get_connection.phpt +++ b/tests/amqpqueue_get_connection.phpt @@ -2,13 +2,13 @@ AMQPQueue getConnection test --SKIPIF-- --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); diff --git a/tests/amqpqueue_get_empty_body.phpt b/tests/amqpqueue_get_empty_body.phpt index 0e65bcb0..6d4757c1 100644 --- a/tests/amqpqueue_get_empty_body.phpt +++ b/tests/amqpqueue_get_empty_body.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPQueue::get empty body --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_get_headers.phpt b/tests/amqpqueue_get_headers.phpt index b589f7a8..f6c99710 100644 --- a/tests/amqpqueue_get_headers.phpt +++ b/tests/amqpqueue_get_headers.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPQueue::get headers --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_get_nonexistent.phpt b/tests/amqpqueue_get_nonexistent.phpt index 586b622d..4bd7ea5d 100644 --- a/tests/amqpqueue_get_nonexistent.phpt +++ b/tests/amqpqueue_get_nonexistent.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPQueue::get from nonexistent queue --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->setReadTimeout(10); // both are empirical values that should be far enough to deal with busy RabbitMQ broker $cnn->setWriteTimeout(10); $cnn->connect(); diff --git a/tests/amqpqueue_headers_with_bool.phpt b/tests/amqpqueue_headers_with_bool.phpt index d9b4e1c0..e1feeb82 100644 --- a/tests/amqpqueue_headers_with_bool.phpt +++ b/tests/amqpqueue_headers_with_bool.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPQueue::get headers with bool values --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_headers_with_float.phpt b/tests/amqpqueue_headers_with_float.phpt index a2d55aba..dc0fc4c9 100644 --- a/tests/amqpqueue_headers_with_float.phpt +++ b/tests/amqpqueue_headers_with_float.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPQueue::get headers with float values --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_headers_with_null.phpt b/tests/amqpqueue_headers_with_null.phpt index f663395e..c809cf32 100644 --- a/tests/amqpqueue_headers_with_null.phpt +++ b/tests/amqpqueue_headers_with_null.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPQueue::get headers --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_nack.phpt b/tests/amqpqueue_nack.phpt index 8b630c0c..2c5a23d2 100644 --- a/tests/amqpqueue_nack.phpt +++ b/tests/amqpqueue_nack.phpt @@ -1,11 +1,15 @@ --TEST-- AMQPQueue::nack --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_nested_arrays.phpt b/tests/amqpqueue_nested_arrays.phpt index 366bb6c6..d2cc4ff3 100644 --- a/tests/amqpqueue_nested_arrays.phpt +++ b/tests/amqpqueue_nested_arrays.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPQueue::get headers --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_nested_headers.phpt b/tests/amqpqueue_nested_headers.phpt index bcf3e0ea..cbceb997 100644 --- a/tests/amqpqueue_nested_headers.phpt +++ b/tests/amqpqueue_nested_headers.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPQueue::get headers --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_purge_basic.phpt b/tests/amqpqueue_purge_basic.phpt index 639b34c4..464de481 100644 --- a/tests/amqpqueue_purge_basic.phpt +++ b/tests/amqpqueue_purge_basic.phpt @@ -1,7 +1,9 @@ --TEST-- AMQPQueue --SKIPIF-- - + --FILE-- diff --git a/tests/amqpqueue_setArgument.phpt b/tests/amqpqueue_setArgument.phpt index 34219813..d56e3927 100644 --- a/tests/amqpqueue_setArgument.phpt +++ b/tests/amqpqueue_setArgument.phpt @@ -1,12 +1,16 @@ --TEST-- AMQPQueue::setArgument() test --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_setFlags.phpt b/tests/amqpqueue_setFlags.phpt index f420d078..8e84f796 100644 --- a/tests/amqpqueue_setFlags.phpt +++ b/tests/amqpqueue_setFlags.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPQueue::setFlags(null) --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_unbind_basic_empty_routing_key.phpt b/tests/amqpqueue_unbind_basic_empty_routing_key.phpt index 31e70f75..994e3c2b 100644 --- a/tests/amqpqueue_unbind_basic_empty_routing_key.phpt +++ b/tests/amqpqueue_unbind_basic_empty_routing_key.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPQueue --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_unbind_basic_headers_arguments.phpt b/tests/amqpqueue_unbind_basic_headers_arguments.phpt index d3470a69..d85b4e28 100644 --- a/tests/amqpqueue_unbind_basic_headers_arguments.phpt +++ b/tests/amqpqueue_unbind_basic_headers_arguments.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPQueue --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/amqpqueue_var_dump.phpt b/tests/amqpqueue_var_dump.phpt index 69b48dd5..f5bdeea4 100644 --- a/tests/amqpqueue_var_dump.phpt +++ b/tests/amqpqueue_var_dump.phpt @@ -2,12 +2,13 @@ AMQPQueue var_dump --SKIPIF-- --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); // Declare a new exchange diff --git a/tests/amqptimestamp.phpt b/tests/amqptimestamp.phpt index 9980727d..be0a7a89 100644 --- a/tests/amqptimestamp.phpt +++ b/tests/amqptimestamp.phpt @@ -2,9 +2,8 @@ AMQPTimestamp --SKIPIF-- --FILE-- + --FILE-- connect(); +$cnn = new AMQPConnection(); +$cnn->setHost(getenv('PHP_AMQP_HOST')); +$cnn->connect(); -$ch = new AMQPChannel($c); +$ch = new AMQPChannel($cnn); $ex = new AMQPExchange($ch); $ex->setName("exchange-" . bin2hex(random_bytes(32))); diff --git a/tests/bug_19707.phpt b/tests/bug_19707.phpt index 20343601..272730be 100644 --- a/tests/bug_19707.phpt +++ b/tests/bug_19707.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPQueue::get() doesn't return the message --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/bug_19840.phpt b/tests/bug_19840.phpt index 3ccf4129..c48410e1 100644 --- a/tests/bug_19840.phpt +++ b/tests/bug_19840.phpt @@ -1,7 +1,9 @@ --TEST-- Bug 19840: Connection Exception --SKIPIF-- - + --FILE-- connect(); + $cnn = new AMQPConnection($lServer); + $cnn->connect(); echo "No exception thrown\n"; } catch (Exception $e) { echo get_class($e), "({$e->getCode()}): ", $e->getMessage(); diff --git a/tests/bug_351.phpt b/tests/bug_351.phpt index cfa5a33c..15a33c0b 100644 --- a/tests/bug_351.phpt +++ b/tests/bug_351.phpt @@ -1,10 +1,14 @@ --TEST-- AMQPEnvelope::getBody returns false instead of empty string --SKIPIF-- - + --FILE-- setHost(getenv('PHP_AMQP_HOST')); $cnn->connect(); $ch = new AMQPChannel($cnn); diff --git a/tests/bug_385.phpt b/tests/bug_385.phpt index 881b24b9..87fa2cb2 100644 --- a/tests/bug_385.phpt +++ b/tests/bug_385.phpt @@ -1,15 +1,17 @@ --TEST-- #385 Testing consumer cleared on cancel --SKIPIF-- - + --FILE-- connect(); +$cnn = new AMQPConnection(); +$cnn->setHost(getenv('PHP_AMQP_HOST')); +$cnn->connect(); -$channel = new AMQPChannel($conn); +$channel = new AMQPChannel($cnn); $exchange = new AMQPExchange($channel); $queue = new AMQPQueue($channel); diff --git a/tests/bug_61533.phpt b/tests/bug_61533.phpt index f53c3159..ca2cb676 100644 --- a/tests/bug_61533.phpt +++ b/tests/bug_61533.phpt @@ -1,12 +1,16 @@ --TEST-- Constructing AMQPQueue with AMQPConnection segfaults --SKIPIF-- - + --FILE-- connect(); -$chan = new AMQPChannel($conn); +$cnn = new AMQPConnection(); +$cnn->setHost(getenv('PHP_AMQP_HOST')); +$cnn->connect(); +$chan = new AMQPChannel($cnn); if (!class_exists('TypeError')) { class TypeError extends Exception {} @@ -14,7 +18,7 @@ if (!class_exists('TypeError')) { try { error_reporting(error_reporting() & ~E_WARNING); - $queue = new AMQPQueue($conn); + $queue = new AMQPQueue($cnn); } catch (TypeError $e) { echo get_class($e), "({$e->getCode()}): ", $e->getMessage(), '.', PHP_EOL; // we pad exception message with dot to make EXPETF be the same on PHP 5 and PHP 7 } diff --git a/tests/bug_62354.phpt b/tests/bug_62354.phpt index 6330476c..380ae6be 100644 --- a/tests/bug_62354.phpt +++ b/tests/bug_62354.phpt @@ -1,7 +1,9 @@ --TEST-- Constructing AMQPQueue with AMQPConnection segfaults --SKIPIF-- - + --FILE-- + --FILE-- connect(); +$cnn = new AMQPConnection(); +$cnn->setHost(getenv('PHP_AMQP_HOST')); +$cnn->connect(); -$channel = new AMQPChannel($connection); +$channel = new AMQPChannel($cnn); $channel->setPrefetchCount(2); $exchange = new AMQPExchange($channel); diff --git a/tests/bug_gh155_direct_reply_to.phpt b/tests/bug_gh155_direct_reply_to.phpt index 29f9f340..fa179da0 100644 --- a/tests/bug_gh155_direct_reply_to.phpt +++ b/tests/bug_gh155_direct_reply_to.phpt @@ -1,15 +1,17 @@ --TEST-- #155 RabbitMQ's Direct reply-to (related to consume multiple) --SKIPIF-- - + --FILE-- connect(); +$cnn = new AMQPConnection(); +$cnn->setHost(getenv('PHP_AMQP_HOST')); +$cnn->connect(); -$channel = new AMQPChannel($conn); +$channel = new AMQPChannel($cnn); $exchange = new AMQPExchange($channel); @@ -39,7 +41,7 @@ echo 'Reply-to queue: ', $reply_to, PHP_EOL; echo 'Prepare response queue...' . PHP_EOL; -$channel_2 = new AMQPChannel($conn); +$channel_2 = new AMQPChannel($cnn); $q_reply = new AMQPQueue($channel_2); $q_reply->setName($reply_to); diff --git a/tests/bug_gh50-1.phpt b/tests/bug_gh50-1.phpt index 203c03f9..45e04742 100644 --- a/tests/bug_gh50-1.phpt +++ b/tests/bug_gh50-1.phpt @@ -1,15 +1,19 @@ --TEST-- Channel creation race condition (https://github.com/pdezwart/php-amqp/issues/50) (1) --SKIPIF-- - + --FILE-- connect(); +$cnn = new AMQPConnection(); +$cnn->setHost(getenv('PHP_AMQP_HOST')); +$cnn->connect(); for ($i = 0; $i < 3; $i++) { - $channel = new AMQPChannel($connection); + $channel = new AMQPChannel($cnn); var_dump($channel->getChannelId()); $queue = new AMQPQueue($channel); diff --git a/tests/bug_gh50-2.phpt b/tests/bug_gh50-2.phpt index b95b2901..74b9589a 100644 --- a/tests/bug_gh50-2.phpt +++ b/tests/bug_gh50-2.phpt @@ -1,15 +1,19 @@ --TEST-- Channel creation race condition (https://github.com/pdezwart/php-amqp/issues/50) (2) --SKIPIF-- - + --FILE-- connect(); +$cnn = new AMQPConnection(); +$cnn->setHost(getenv('PHP_AMQP_HOST')); +$cnn->connect(); for ($i = 0; $i < 3; $i++) { - $channel = new AMQPChannel($connection); + $channel = new AMQPChannel($cnn); var_dump($channel->getChannelId()); $queue = new AMQPQueue($channel); diff --git a/tests/bug_gh50-3.phpt b/tests/bug_gh50-3.phpt index f79da443..2f817a44 100644 --- a/tests/bug_gh50-3.phpt +++ b/tests/bug_gh50-3.phpt @@ -1,15 +1,19 @@ --TEST-- Channel creation race condition (https://github.com/pdezwart/php-amqp/issues/50) (3) --SKIPIF-- - + --FILE-- connect(); +$cnn = new AMQPConnection(); +$cnn->setHost(getenv('PHP_AMQP_HOST')); +$cnn->connect(); for ($i = 0; $i < 3; $i++) { - $channel = new AMQPChannel($connection); + $channel = new AMQPChannel($cnn); var_dump($channel->getChannelId()); $queue = new AMQPQueue($channel); @@ -19,12 +23,13 @@ for ($i = 0; $i < 3; $i++) { $queue->delete(); } -$connection = new AMQPConnection(); -$connection->connect(); +$cnn = new AMQPConnection(); +$cnn->setHost(getenv('PHP_AMQP_HOST')); +$cnn->connect(); for ($i = 0; $i < 3; $i++) { - $channel = new AMQPChannel($connection); + $channel = new AMQPChannel($cnn); var_dump($channel->getChannelId()); $queue = new AMQPQueue($channel); diff --git a/tests/bug_gh50-4.phpt b/tests/bug_gh50-4.phpt index eb3539dc..adba61c5 100644 --- a/tests/bug_gh50-4.phpt +++ b/tests/bug_gh50-4.phpt @@ -1,17 +1,21 @@ --TEST-- Channel creation race condition (https://github.com/pdezwart/php-amqp/issues/50) (4) --SKIPIF-- - + --FILE-- connect(); +$cnn = new AMQPConnection(); +$cnn->setHost(getenv('PHP_AMQP_HOST')); +$cnn->connect(); $channels = array(); for ($i = 0; $i < 3; $i++) { - $channel = $channels[] = new AMQPChannel($connection); + $channel = $channels[] = new AMQPChannel($cnn); var_dump($channel->getChannelId()); $queue = new AMQPQueue($channel); @@ -21,12 +25,13 @@ for ($i = 0; $i < 3; $i++) { $queue->delete(); } -$connection = new AMQPConnection(); -$connection->connect(); +$cnn = new AMQPConnection(); +$cnn->setHost(getenv('PHP_AMQP_HOST')); +$cnn->connect(); for ($i = 0; $i < 3; $i++) { - $channel = $channels[] = new AMQPChannel($connection); + $channel = $channels[] = new AMQPChannel($cnn); var_dump($channel->getChannelId()); $queue = new AMQPQueue($channel); diff --git a/tests/bug_gh53-2.phpt b/tests/bug_gh53-2.phpt index 3ced2e90..0b87682e 100644 --- a/tests/bug_gh53-2.phpt +++ b/tests/bug_gh53-2.phpt @@ -1,13 +1,17 @@ --TEST-- Upgrade to RabbitMQ 3.1.0-1: AMQPConnectionException: connection closed unexpectedly (2) --SKIPIF-- - + --FILE-- connect(); +$cnn = new AMQPConnection(); +$cnn->setHost(getenv('PHP_AMQP_HOST')); +$cnn->connect(); -$channel = new AMQPChannel($connection); +$channel = new AMQPChannel($cnn); $exchange = new AMQPExchange($channel); $exchange->setName('exchange' . bin2hex(random_bytes(32))); diff --git a/tests/bug_gh53.phpt b/tests/bug_gh53.phpt index 2ea03575..0de33273 100644 --- a/tests/bug_gh53.phpt +++ b/tests/bug_gh53.phpt @@ -1,13 +1,17 @@ --TEST-- Upgrade to RabbitMQ 3.1.0-1: AMQPConnectionException: connection closed unexpectedly --SKIPIF-- - + --FILE-- connect(); +$cnn = new AMQPConnection(); +$cnn->setHost(getenv('PHP_AMQP_HOST')); +$cnn->connect(); -$channel = new AMQPChannel($connection); +$channel = new AMQPChannel($cnn); var_dump($channel->getPrefetchSize()); var_dump($channel->getPrefetchCount()); @@ -23,7 +27,7 @@ try { echo get_class($e), "({$e->getCode()}): ", $e->getMessage(), PHP_EOL; } var_dump($channel->isConnected()); -var_dump($connection->isConnected()); +var_dump($cnn->isConnected()); var_dump($channel->getPrefetchSize()); var_dump($channel->getPrefetchCount()); diff --git a/tests/bug_gh72-1.phpt b/tests/bug_gh72-1.phpt index d1237585..ac0106ac 100644 --- a/tests/bug_gh72-1.phpt +++ b/tests/bug_gh72-1.phpt @@ -1,12 +1,16 @@ --TEST-- #72 Publishing to an exchange with an empty name is valid and should not throw an exception (1) --SKIPIF-- - + --FILE-- connect(); -$channel = new AMQPChannel($connection); +$cnn = new AMQPConnection(); +$cnn->setHost(getenv('PHP_AMQP_HOST')); +$cnn->connect(); +$channel = new AMQPChannel($cnn); $exchange = new AMQPExchange($channel); $exchange->setName(''); diff --git a/tests/bug_gh72-2.phpt b/tests/bug_gh72-2.phpt index 2abe3d29..c0ae5e2a 100644 --- a/tests/bug_gh72-2.phpt +++ b/tests/bug_gh72-2.phpt @@ -1,12 +1,16 @@ --TEST-- #72 Publishing to an exchange with an empty name is valid and should not throw an exception (2) --SKIPIF-- - + --FILE-- connect(); -$channel = new AMQPChannel($connection); +$cnn = new AMQPConnection(); +$cnn->setHost(getenv('PHP_AMQP_HOST')); +$cnn->connect(); +$channel = new AMQPChannel($cnn); $exchange = new AMQPExchange($channel); diff --git a/tests/ini_validation_failure.phpt b/tests/ini_validation_failure.phpt index 7c026de9..a0a171b9 100644 --- a/tests/ini_validation_failure.phpt +++ b/tests/ini_validation_failure.phpt @@ -2,9 +2,7 @@ Bad INI settings are rejected --SKIPIF-- --INI-- amqp.host=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx diff --git a/tests/package-version.phpt b/tests/package-version.phpt index 52ffe0e3..0a53390b 100644 --- a/tests/package-version.phpt +++ b/tests/package-version.phpt @@ -1,7 +1,10 @@ --TEST-- Compare version in package.xml and module --SKIPIF-- - + --FILE-- .*?)--[A-Z]+--/s', $content, $matches)) { + printf("%s TEST section cannot be parsed\n", basename($test)); + continue; + } + ['testCode' => $testCode] = $matches; + + if (!preg_match('/--SKIPIF--(?P.*?)--[A-Z]+--/s', $content, $matches)) { + printf("%s SKIPIF section cannot be parsed\n", basename($test)); + continue; + } + + ['skipCode' => $skipCode] = $matches; + + if (!preg_match('/if\s*\(!extension_loaded\("amqp"\)\)\s*\{?\s*print "skip";/', $skipCode)) { + printf("%s --SKIP-- does not check for the extension being present\n", basename($test)); + continue; + } + + $hostVars = ['PHP_AMQP_HOST', 'PHP_AMQP_SSL_HOST']; + foreach ($hostVars as $hostVar) { + if (strpos($testCode, $hostVar) !== false && !preg_match('/!getenv\(["\']' . $hostVar . '/', $skipCode)) { + printf("%s --TEST-- contains reference to %s but --SKIP-- does not check for it\n", basename($test), $hostVar); + continue 2; + } + + if (strpos($testCode, $hostVar) === false && strpos($skipCode, $hostVar) !== false) { + printf("%s --TEST-- contains no reference to %s but --SKIP-- checks for reference\n", basename($test), $hostVar); + continue 2; + } + } +} +?> +==DONE== +--EXPECT-- + +==DONE== \ No newline at end of file From 1fd8011916f456ec53ecd01166cc6dc78aa1e8a0 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Fri, 18 Aug 2023 12:50:24 +0200 Subject: [PATCH 058/147] Test against upcoming PHP 8.3 (#465) --- .env | 1 + .github/workflows/test.yaml | 26 +++++++++++++++++++++----- .gitignore | 2 ++ docker-compose.yml | 10 ++++++++-- infra/php/Dockerfile | 29 +++++++---------------------- 5 files changed, 39 insertions(+), 29 deletions(-) diff --git a/.env b/.env index 15705ef4..c6ec60e3 100644 --- a/.env +++ b/.env @@ -3,3 +3,4 @@ PHP_AMQP_SSL_HOST=rabbitmq.example.org MAKEFLAGS="-j16" CFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror" TEST_PHP_ARGS="-j16" +CC=clang diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 2e2226af..d52b1b2a 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -55,14 +55,16 @@ jobs: strategy: fail-fast: false matrix: - php-version: [ "8.2", "8.1", "8.0", "7.4" ] + php-version: [ "8.3", "8.2", "8.1", "8.0", "7.4" ] steps: - name: Checkout uses: actions/checkout@v3.5.3 - name: Install packages - run: sudo apt-get install -y cmake valgrind + uses: awalsh128/cache-apt-pkgs-action@v1.3.0 + with: + packages: cmake valgrind - name: Setup PHP uses: shivammathur/setup-php@2.25.5 @@ -70,6 +72,8 @@ jobs: php-version: ${{ matrix.php-version }} extensions: json coverage: none + env: + debug: true - name: Check stubs run: ./infra/tools/pamqp-stubs-lint @@ -88,7 +92,7 @@ jobs: - name: Validate argument parsing run: ./infra/tools/pamqp-php-cli-deterministic -d extension=modules/amqp.so ./infra/tools/pamqp-arguments-validate - if: matrix.php-version == '8.2' + if: matrix.php-version == '8.2' || matrix.php-version == '8.3' test: name: ${{ matrix.test-php-args == '-m' && 'Memtest' || 'Test' }} php-${{ matrix.php-version }}${{ matrix.php-thread-safe && '-ts' || '-nts' }} librabbitmq-${{ matrix.librabbitmq-version }} ${{ matrix.compiler }} @@ -106,20 +110,28 @@ jobs: strategy: fail-fast: false matrix: - php-version: [ '8.2', '8.1', '8.0', '7.4' ] + php-version: [ '8.3', '8.2', '8.1', '8.0', '7.4' ] php-thread-safe: [ true, false ] librabbitmq-version: [ 'master', '0.13.0', '0.12.0', '0.11.0', '0.10.0', '0.9.0', '0.8.0' ] compiler: [gcc, clang] include: + - php-version: '8.3' + php-thread-safe: true + librabbitmq-version: 'master' + test-php-args: '-m' + compiler: clang + - php-version: '8.2' php-thread-safe: false librabbitmq-version: 'master' test-php-args: '-m' + compiler: clang - php-version: '8.1' php-thread-safe: true librabbitmq-version: 'master' test-php-args: '-m' + compiler: gcc steps: - name: Checkout @@ -135,7 +147,10 @@ jobs: run: docker compose up -d rabbitmq - name: Install packages - run: sudo apt-get install -y cmake valgrind ${{ matrix.compiler }} + uses: awalsh128/cache-apt-pkgs-action@v1.3.0 + with: + packages: cmake valgrind ${{ matrix.compiler }} + version: ${{ (matrix.librabbitmq-version == '0.10.0' || matrix.librabbitmq-version == '0.9.0' || matrix.librabbitmq-version == '0.8.0') && 'ubuntu-20.04' || 'ubuntu-22.04' }} - name: Setup PHP uses: shivammathur/setup-php@2.25.5 @@ -145,6 +160,7 @@ jobs: extensions: simplexml env: phpts: ${{ matrix.php-thread-safe && 'ts' || 'nts' }} + debug: true - name: Build librabbitmq run: ./infra/tools/pamqp-install-librabbitmq ${{ matrix.librabbitmq-version }} diff --git a/.gitignore b/.gitignore index 5cec8c69..bd8518a9 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,5 @@ CMakeLists.txt /configure~ /impl.json /stubs.json +/run-tests.php +/stubs-old diff --git a/docker-compose.yml b/docker-compose.yml index 6e90803d..a6197951 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -43,7 +43,6 @@ services: debian-74: &php-base build: &php-base-build context: infra/php - target: dev additional_contexts: php-core: docker-image://php:7.4-zts-bullseye volumes: @@ -77,7 +76,14 @@ services: <<: *php-base build: <<: *php-base-build - target: dev-all additional_contexts: php-core: docker-image://php:8.2-fpm-bookworm working_dir: /src/build/debian-82 + + debian-83: + <<: *php-base + build: + <<: *php-base-build + additional_contexts: + php-core: docker-image://php:8.3-rc-fpm-bookworm + working_dir: /src/build/debian-83 diff --git a/infra/php/Dockerfile b/infra/php/Dockerfile index 2b54ec1a..e247adfe 100644 --- a/infra/php/Dockerfile +++ b/infra/php/Dockerfile @@ -1,27 +1,12 @@ # syntax=docker/dockerfile:1.4 FROM php-core AS dev - -RUN set -xe; \ - apt-get update -yqq && \ - pecl channel-update pecl.php.net - -RUN apt-get install -yqq build-essential -RUN apt-get install -yqq librabbitmq-dev -RUN apt-get install -yqq gdb -RUN apt-get install -yqq valgrind -RUN apt-get install -yqq git -RUN apt-get install -yqq unzip -RUN apt-get install -yqq clang - +RUN . /etc/os-release && \ + echo "deb https://apt.llvm.org/$VERSION_CODENAME llvm-toolchain-$VERSION_CODENAME-17 main" > /etc/apt/sources.list.d/llvm.list && \ + curl https://apt.llvm.org/llvm-snapshot.gpg.key > /etc/apt/trusted.gpg.d/llvm-snapshot.asc +RUN apt-get update -yqq +RUN apt-get install -yqq build-essential librabbitmq-dev +RUN apt-get install -yqq gdb valgrind clang clang-format-17 +RUN apt-get install -yqq git unzip RUN echo 'PATH=$PATH:/src/infra/tools' >> /etc/bash.bashrc - COPY --from=composer /usr/bin/composer /usr/local/bin/composer - CMD PHP_AMQP_DOCKER_ENTRYPOINT=1 php /src/infra/tools/pamqp-docker-setup && sleep infinity - -FROM dev AS dev-all -RUN apt-get install -yqq gnupg2 -RUN echo "deb https://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-17 main" > /etc/apt/sources.list.d/llvm.list -RUN curl https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - -RUN apt-get update -yqq -RUN apt-get install -yqq clang-format-17 \ No newline at end of file From 2649035410cece7ca5a6995910197d574b9520a5 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Fri, 18 Aug 2023 18:01:15 +0200 Subject: [PATCH 059/147] Ubuntu development containers (#466) --- .env | 3 +- .github/workflows/test.yaml | 52 +++++++++++++++++++-- DEVELOPMENT.md | 8 +++- docker-compose.yml | 76 ++++++++++++++++++++++++------- infra/{php => dev}/Dockerfile | 27 ++++++++--- infra/tools/valgrind-suppressions | 15 ++++++ php_amqp.h | 3 +- 7 files changed, 154 insertions(+), 30 deletions(-) rename infra/{php => dev}/Dockerfile (51%) create mode 100644 infra/tools/valgrind-suppressions diff --git a/.env b/.env index c6ec60e3..bdb94d3d 100644 --- a/.env +++ b/.env @@ -1,6 +1,7 @@ PHP_AMQP_HOST=rabbitmq PHP_AMQP_SSL_HOST=rabbitmq.example.org MAKEFLAGS="-j16" -CFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror" +CFLAGS="-g -D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror" TEST_PHP_ARGS="-j16" CC=clang +VALGRIND_OPTS="--suppressions=infra/tools/valgrind-suppressions" diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index d52b1b2a..49ffa328 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -7,7 +7,7 @@ on: env: TEST_TIMEOUT: 120 - CFLAGS: -D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror + CFLAGS: -g -D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror MAKEFLAGS: -j4 jobs: @@ -106,6 +106,7 @@ jobs: TEST_PHP_ARGS: -j4 ${{ matrix.test-php-args }} PHP_AMQP_HOST: localhost PHP_AMQP_SSL_HOST: rabbitmq.example.org + VALGRIND_OPTS: "--suppressions=infra/tools/valgrind-suppressions" strategy: fail-fast: false @@ -119,20 +120,62 @@ jobs: php-thread-safe: true librabbitmq-version: 'master' test-php-args: '-m' - compiler: clang + compiler: gcc + + - php-version: '8.3' + php-thread-safe: true + librabbitmq-version: '0.8.0' + test-php-args: '-m' + compiler: gcc + + - php-version: '8.2' + php-thread-safe: true + librabbitmq-version: 'master' + test-php-args: '-m' + compiler: gcc - php-version: '8.2' - php-thread-safe: false + php-thread-safe: true + librabbitmq-version: '0.8.0' + test-php-args: '-m' + compiler: gcc + + - php-version: '8.1' + php-thread-safe: true librabbitmq-version: 'master' test-php-args: '-m' - compiler: clang + compiler: gcc - php-version: '8.1' + php-thread-safe: true + librabbitmq-version: '0.8.0' + test-php-args: '-m' + compiler: gcc + + - php-version: '8.0' + php-thread-safe: true + librabbitmq-version: 'master' + test-php-args: '-m' + compiler: gcc + + - php-version: '8.0' + php-thread-safe: true + librabbitmq-version: '0.8.0' + test-php-args: '-m' + compiler: gcc + + - php-version: '7.4' php-thread-safe: true librabbitmq-version: 'master' test-php-args: '-m' compiler: gcc + - php-version: '7.4' + php-thread-safe: true + librabbitmq-version: '0.8.0' + test-php-args: '-m' + compiler: gcc + steps: - name: Checkout uses: actions/checkout@v3.5.3 @@ -174,6 +217,7 @@ jobs: - name: Run minimal test suite run: make test | tee result-minimal.txt env: + # Reset defaults to a) only run local tests, b) don’t run memory checks as the full test suite run will do so TEST_PHP_ARGS: -j4 PHP_AMQP_HOST: "" PHP_AMQP_SSL_HOST: "" diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 1bedf6cf..c0b88051 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -17,12 +17,16 @@ all the logs, especially the RabbitMQ logs. ## The environment -Four different development containers are provided at the moment: +Various development containers are provided: - `debian-74`: PHP 7.4 on Debian 11 ("Bullseye") - `debian-80`: PHP 8.0 on Debian 12 ("Bookworm") - `debian-81`: PHP 8.1 on Debian 12 ("Bookworm") -- `debian-82`: PHP 8.1 on Debian 12 ("Bookworm") +- `debian-82`: PHP 8.2 on Debian 12 ("Bookworm") +- `ubuntu-74`: PHP 7.4 on Ubuntu 20 ("Jammy") +- `ubuntu-80`: PHP 8.0 on Ubuntu 22 ("Jammy") +- `ubuntu-81`: PHP 8.1 on Ubuntu 22 ("Jammy") +- `ubuntu-82`: PHP 8.2 on Ubuntu 22 ("Jammy") To enter the container, run this command: diff --git a/docker-compose.yml b/docker-compose.yml index a6197951..d9f3dbea 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -40,11 +40,55 @@ services: volumes: - ./:/src - debian-74: &php-base - build: &php-base-build - context: infra/php + ubuntu-74: &ubuntu-dev + build: &ubuntu-dev-build + context: infra/dev + target: ubuntu-php + args: + php_pkg: php7.4 additional_contexts: - php-core: docker-image://php:7.4-zts-bullseye + base: docker-image://ubuntu:jammy + volumes: + - ./:/src + depends_on: + - rabbitmq + ulimits: + core: -1 + working_dir: /src/build/ubuntu-74 + env_file: .env + links: + - "rabbitmq:${PHP_AMQP_SSL_HOST}" + + ubuntu-80: + <<: *ubuntu-dev + build: + <<: *ubuntu-dev-build + args: + php_pkg: php8.0 + working_dir: /src/build/ubuntu-80 + + ubuntu-81: + <<: *ubuntu-dev + build: + <<: *ubuntu-dev-build + args: + php_pkg: php8.1 + working_dir: /src/build/ubuntu-81 + + ubuntu-82: + <<: *ubuntu-dev + build: + <<: *ubuntu-dev-build + args: + php_pkg: php8.2 + working_dir: /src/build/ubuntu-82 + + debian-74: &debian-dev + build: &debian-dev-build + context: infra/dev + target: debianish + additional_contexts: + base: docker-image://php:7.4-zts-bullseye volumes: - ./:/src depends_on: @@ -57,33 +101,33 @@ services: - "rabbitmq:${PHP_AMQP_SSL_HOST}" debian-80: - <<: *php-base + <<: *debian-dev build: - <<: *php-base-build + <<: *debian-dev-build additional_contexts: - php-core: docker-image://php:8.0-fpm-bullseye + base: docker-image://php:8.0-zts-bullseye working_dir: /src/build/debian-80 debian-81: - <<: *php-base + <<: *debian-dev build: - <<: *php-base-build + <<: *debian-dev-build additional_contexts: - php-core: docker-image://php:8.1-fpm-bookworm + base: docker-image://php:8.1-zts-bookworm working_dir: /src/build/debian-81 debian-82: - <<: *php-base + <<: *debian-dev build: - <<: *php-base-build + <<: *debian-dev-build additional_contexts: - php-core: docker-image://php:8.2-fpm-bookworm + base: docker-image://php:8.2-zts-bookworm working_dir: /src/build/debian-82 debian-83: - <<: *php-base + <<: *debian-dev build: - <<: *php-base-build + <<: *debian-dev-build additional_contexts: - php-core: docker-image://php:8.3-rc-fpm-bookworm + base: docker-image://php:8.3-rc-zts-bookworm working_dir: /src/build/debian-83 diff --git a/infra/php/Dockerfile b/infra/dev/Dockerfile similarity index 51% rename from infra/php/Dockerfile rename to infra/dev/Dockerfile index e247adfe..918f733e 100644 --- a/infra/php/Dockerfile +++ b/infra/dev/Dockerfile @@ -1,12 +1,27 @@ # syntax=docker/dockerfile:1.4 -FROM php-core AS dev +FROM base AS common +RUN echo 'PATH=$PATH:/src/infra/tools' >> /etc/bash.bashrc +COPY --from=composer /usr/bin/composer /usr/local/bin/composer +CMD PHP_AMQP_DOCKER_ENTRYPOINT=1 php /src/infra/tools/pamqp-docker-setup && sleep infinity + +# Install packages on Debian flavored distributions +FROM common AS debianish +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get update -yqq +RUN apt-get install -yqq software-properties-common curl RUN . /etc/os-release && \ - echo "deb https://apt.llvm.org/$VERSION_CODENAME llvm-toolchain-$VERSION_CODENAME-17 main" > /etc/apt/sources.list.d/llvm.list && \ - curl https://apt.llvm.org/llvm-snapshot.gpg.key > /etc/apt/trusted.gpg.d/llvm-snapshot.asc + curl https://apt.llvm.org/llvm-snapshot.gpg.key > /etc/apt/trusted.gpg.d/llvm-snapshot.asc && \ + echo "deb https://apt.llvm.org/$VERSION_CODENAME llvm-toolchain-$VERSION_CODENAME-17 main" > /etc/apt/sources.list.d/llvm.list RUN apt-get update -yqq RUN apt-get install -yqq build-essential librabbitmq-dev RUN apt-get install -yqq gdb valgrind clang clang-format-17 RUN apt-get install -yqq git unzip -RUN echo 'PATH=$PATH:/src/infra/tools' >> /etc/bash.bashrc -COPY --from=composer /usr/bin/composer /usr/local/bin/composer -CMD PHP_AMQP_DOCKER_ENTRYPOINT=1 php /src/infra/tools/pamqp-docker-setup && sleep infinity + +# Install PHP on Ubuntu +FROM debianish AS ubuntu-php +RUN apt-get install -yqq software-properties-common +RUN add-apt-repository ppa:ondrej/php +RUN sed -e "s:main:main main/debug:" -i /etc/apt/sources.list.d/ondrej-*.list +RUN apt-get update -yqq +ARG php_pkg +RUN apt-get install -yqq ${php_pkg}-dev ${php_pkg}-common-dbgsym ${php_pkg}-cli-dbgsym diff --git a/infra/tools/valgrind-suppressions b/infra/tools/valgrind-suppressions new file mode 100644 index 00000000..a3d21456 --- /dev/null +++ b/infra/tools/valgrind-suppressions @@ -0,0 +1,15 @@ +{ + "Timezone leak on Ubuntu" + Memcheck:Cond + ... + fun:__scandir64_tail + ... + fun:zend_register_ini_entries_ex + ... +} +{ + "Expected, see https://bugs.php.net/bug.php?id=76445" + Memcheck:Cond + fun:zend_string_equal_val + ... +} diff --git a/php_amqp.h b/php_amqp.h index 1e479330..5bda6476 100644 --- a/php_amqp.h +++ b/php_amqp.h @@ -106,6 +106,7 @@ extern zend_module_entry amqp_module_entry; #define PHP_AMQP_DECLARE_TYPED_PROPERTY_WITH_DEFAULT(class_entry, name, flags, type, nullable, init) \ { \ zval __val; \ + ZVAL_UNDEF(&__val); \ init(&__val); \ PHP_AMQP_DECLARE_TYPED_PROPERTY_ZVAL( \ class_entry, \ @@ -125,7 +126,7 @@ extern zend_module_entry amqp_module_entry; flags, \ PHP_AMQP_DECLARE_PROPERTY_OBJ_TYPE(__class_name, nullable), \ __val \ - ) \ + ); \ } #include "amqp_connection_resource.h" From 3f6c74b4a5b23c2313ada77442de5c1fd859f999 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Sun, 20 Aug 2023 12:01:20 +0200 Subject: [PATCH 060/147] CentOS development environment (#467) --- .env | 2 +- .github/workflows/test.yaml | 2 +- DEVELOPMENT.md | 10 +++++ docker-compose.yml | 51 +++++++++++++++++++++++-- infra/dev/Dockerfile | 21 +++++++--- infra/tools/pamqp-php-cli-deterministic | 2 +- 6 files changed, 75 insertions(+), 13 deletions(-) diff --git a/.env b/.env index bdb94d3d..ee9ced65 100644 --- a/.env +++ b/.env @@ -1,7 +1,7 @@ PHP_AMQP_HOST=rabbitmq PHP_AMQP_SSL_HOST=rabbitmq.example.org MAKEFLAGS="-j16" -CFLAGS="-g -D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror" +CFLAGS="-g -O0 -fstack-protector-strong -Wall -Werror -D_GNU_SOURCE" TEST_PHP_ARGS="-j16" CC=clang VALGRIND_OPTS="--suppressions=infra/tools/valgrind-suppressions" diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 49ffa328..990f53ae 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -7,7 +7,7 @@ on: env: TEST_TIMEOUT: 120 - CFLAGS: -g -D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wall -Werror + CFLAGS: -g -O0 -fstack-protector-strong -Wall -Werror -D_GNU_SOURCE MAKEFLAGS: -j4 jobs: diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index c0b88051..5fe15209 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -12,6 +12,12 @@ To start the development environment, run this command: docker compose up ``` +For the impatient to not wait for all containers to finish building, only start a single container: + +```commandline +docker compose up debian-82 +``` + The command will start the development environment in the foreground. This is quite nice as it will conveniently surface all the logs, especially the RabbitMQ logs. @@ -27,6 +33,10 @@ Various development containers are provided: - `ubuntu-80`: PHP 8.0 on Ubuntu 22 ("Jammy") - `ubuntu-81`: PHP 8.1 on Ubuntu 22 ("Jammy") - `ubuntu-82`: PHP 8.2 on Ubuntu 22 ("Jammy") +- `centos-74`: PHP 7.4 on Centos Stream 9 +- `centos-80`: PHP 8.0 on Centos Stream 9 +- `centos-81`: PHP 8.1 on Centos Stream 9 +- `centos-82`: PHP 8.2 on Centos Stream 9 To enter the container, run this command: diff --git a/docker-compose.yml b/docker-compose.yml index d9f3dbea..dab8732f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -40,12 +40,55 @@ services: volumes: - ./:/src + centos-74: ¢os-dev + build: ¢os-dev-build + context: infra/dev + target: redhatish + args: + php_version: "7.4" + additional_contexts: + base: docker-image://quay.io/centos/centos:stream9 + volumes: + - ./:/src + depends_on: + - rabbitmq + ulimits: + core: -1 + working_dir: /src/build/centos-74 + env_file: .env + links: + - "rabbitmq:${PHP_AMQP_SSL_HOST}" + + centos-80: + <<: *centos-dev + build: + <<: *centos-dev-build + args: + php_version: "8.0" + working_dir: /src/build/centos-80 + + centos-81: + <<: *centos-dev + build: + <<: *centos-dev-build + args: + php_version: "8.1" + working_dir: /src/build/centos-81 + + centos-82: + <<: *centos-dev + build: + <<: *centos-dev-build + args: + php_version: "8.2" + working_dir: /src/build/centos-82 + ubuntu-74: &ubuntu-dev build: &ubuntu-dev-build context: infra/dev target: ubuntu-php args: - php_pkg: php7.4 + php_version: "7.4" additional_contexts: base: docker-image://ubuntu:jammy volumes: @@ -64,7 +107,7 @@ services: build: <<: *ubuntu-dev-build args: - php_pkg: php8.0 + php_version: "8.0" working_dir: /src/build/ubuntu-80 ubuntu-81: @@ -72,7 +115,7 @@ services: build: <<: *ubuntu-dev-build args: - php_pkg: php8.1 + php_version: "8.1" working_dir: /src/build/ubuntu-81 ubuntu-82: @@ -80,7 +123,7 @@ services: build: <<: *ubuntu-dev-build args: - php_pkg: php8.2 + php_version: "8.2" working_dir: /src/build/ubuntu-82 debian-74: &debian-dev diff --git a/infra/dev/Dockerfile b/infra/dev/Dockerfile index 918f733e..b7e5e84e 100644 --- a/infra/dev/Dockerfile +++ b/infra/dev/Dockerfile @@ -1,9 +1,19 @@ # syntax=docker/dockerfile:1.4 FROM base AS common -RUN echo 'PATH=$PATH:/src/infra/tools' >> /etc/bash.bashrc +RUN echo 'PATH=$PATH:/src/infra/tools' | tee -a /etc/bashrc /etc/bash.bashrc COPY --from=composer /usr/bin/composer /usr/local/bin/composer CMD PHP_AMQP_DOCKER_ENTRYPOINT=1 php /src/infra/tools/pamqp-docker-setup && sleep infinity +FROM common AS redhatish +RUN dnf install -y 'dnf-command(config-manager)' +RUN dnf config-manager --set-enabled crb +RUN dnf install -y gcc clang libtool pkg-config autoconf gdb valgrind git unzip librabbitmq-devel +# FIXME: clang-format 17.x not available yet +RUN dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm +ARG php_version +RUN dnf module install -y php:remi-${php_version} +RUN dnf install -y php-devel + # Install packages on Debian flavored distributions FROM common AS debianish ENV DEBIAN_FRONTEND=noninteractive @@ -13,9 +23,8 @@ RUN . /etc/os-release && \ curl https://apt.llvm.org/llvm-snapshot.gpg.key > /etc/apt/trusted.gpg.d/llvm-snapshot.asc && \ echo "deb https://apt.llvm.org/$VERSION_CODENAME llvm-toolchain-$VERSION_CODENAME-17 main" > /etc/apt/sources.list.d/llvm.list RUN apt-get update -yqq -RUN apt-get install -yqq build-essential librabbitmq-dev -RUN apt-get install -yqq gdb valgrind clang clang-format-17 -RUN apt-get install -yqq git unzip +RUN apt-get install -yqq gcc clang libtool pkg-config autoconf gdb valgrind librabbitmq-dev git unzip +RUN apt-get install -yqq clang-format-17 # Install PHP on Ubuntu FROM debianish AS ubuntu-php @@ -23,5 +32,5 @@ RUN apt-get install -yqq software-properties-common RUN add-apt-repository ppa:ondrej/php RUN sed -e "s:main:main main/debug:" -i /etc/apt/sources.list.d/ondrej-*.list RUN apt-get update -yqq -ARG php_pkg -RUN apt-get install -yqq ${php_pkg}-dev ${php_pkg}-common-dbgsym ${php_pkg}-cli-dbgsym +ARG php_version +RUN apt-get install -yqq php${php_version}-dev php${php_version}-common-dbgsym php${php_version}-cli-dbgsym diff --git a/infra/tools/pamqp-php-cli-deterministic b/infra/tools/pamqp-php-cli-deterministic index 0231a3ca..9fff7aa6 100755 --- a/infra/tools/pamqp-php-cli-deterministic +++ b/infra/tools/pamqp-php-cli-deterministic @@ -28,7 +28,7 @@ if ! test -f "$cached_script"; then done mkdir -p "$cache_dir" - echo "$(which php) $args \$@" > $cached_script.$$ + echo "php $args \$@" > $cached_script.$$ chmod +x $cached_script.$$ mv $cached_script.$$ $cached_script fi From ed2a2e589b14d5a0b89cdadb1ef8c43b0f3b9d9e Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Sun, 20 Aug 2023 13:12:46 +0200 Subject: [PATCH 061/147] [RM] releasing version 2.0.0 --- package.xml | 76 ++++++++++++++++++++++++++++++++++++++++------ php_amqp_version.h | 4 +-- 2 files changed, 69 insertions(+), 11 deletions(-) diff --git a/package.xml b/package.xml index 5d748d43..5beaae06 100644 --- a/package.xml +++ b/package.xml @@ -22,22 +22,79 @@ pinepain@gmail.com yes - 2023-08-15 - + 2023-08-20 + - 2.0.0dev - 2.0.0dev + 2.0.0 + 2.0.0 - devel - devel + stable + stable PHP License - ) (https://github.com/php-amqp/php-amqp/issues/467) + - Ubuntu development containers (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/466) + - Test against upcoming PHP 8.3 (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/465) + - Make test host configurable (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/464) + - Cosmetics on type functions (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/350202f) + - Configurable serialization/deserialization depth (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/463) + - Allow bitmask flags arguments to be nullable where previously AMQP_NOPARAM/zero was required (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/462) + - Fix generated commit URLs in changelogs (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/4ee6159) + - Handle nested AMQP value serialization/deserialization (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/461) + - Document lack of reliability of AMQPConnection::isConnected (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/306) + - Prevent reuse of channel ID of broken channels (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/460) + - Gracefully handle zero as a heartbeat value (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/459) + - Build with the clang compiler on CI (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/457) + - Include stdint.h for PHP >= 8.0 on Windows (Jan Ehrhardt) (https://github.com/php-amqp/php-amqp/issues/456) + - Fix segfault in setPort (Remi Collet ) (https://github.com/php-amqp/php-amqp/issues/455) + - Document BC changes (Lars Strojny ) + - Document pseudo-bool method changes (Lars Strojny ) + - Fix mangled header on MacOS (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/60) + - Validate argument parsing, add AMQPExchange::removeArgument() and AMQPQueue::removeArgument() (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/452) + - Skip SSL tests if certificates are missing (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/450) + - Check coding style and formatting of stub files (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/447) + - Parallelize test execution (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/444) + - Deterministic configuration for PHP CLI (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/443) + - Fix tag creation during release management (Lars Strojny ) + - Move test-report.sh into infra (Lars Strojny ) + - The big fat API renovation (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/437) + - Handle alpha/beta stability correctly (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/5546436) + - Expose better version information (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/438) + - Auto-format the codebase (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/436) + - More consistent return types for AMQPEnvelope (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/435) + - Update stubs (Lars Strojny ) + - Fix parameter error handling in AMQPConnection and AMQPChannel (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/434) + - Increase credentials and identifier limits (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/433) + - Reliably clear consumer tag on AMQPQueue::cancel (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/432) + - Ignore failures on experimental builds (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/25) + - Update branch name (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/7) + - Bump shivammathur/setup-php from 2.25.3 to 2.25.4 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/431) + - PHP 8.2 refactorings (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/430) + - Fix php version check for static building (Misha Kulakovsky ) (https://github.com/php-amqp/php-amqp/issues/425) + - Fix stub exception class (closes #427) (Lars Strojny ) + - Document custom connection name in stubs (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/700000) + - Expose Delivery Mode through constants (Flávio Heleno ) (https://github.com/php-amqp/php-amqp/issues/420) + - Fix deprecation issue in PHP 8.1 for $consumerTag argument to AMQPQueue::consume() method (Liviu-Ionut Iosif) (https://github.com/php-amqp/php-amqp/issues/421) + - Fix: Deprecated: Creation of dynamic property (8.2) (Remi Collet ) (https://github.com/php-amqp/php-amqp/issues/418) + - Fix AMQPEnvelope::getDeliveryTag() return type (Flávio Heleno ) (https://github.com/php-amqp/php-amqp/issues/415) + - Fix ack/nack/reject param documentation (Flávio Heleno ) (https://github.com/php-amqp/php-amqp/issues/414) + - Mention time units in all timeout-related methods (Andrii Dembitskyi ) (https://github.com/php-amqp/php-amqp/issues/410) For a complete list of changes see: -https://github.com/php-amqp/php-amqp/compare/v2.0.0RC1...latest -]]> +https://github.com/php-amqp/php-amqp/compare/v1.11.0...v2.0.0]]> @@ -260,6 +317,7 @@ https://github.com/php-amqp/php-amqp/compare/v2.0.0RC1...latest + diff --git a/php_amqp_version.h b/php_amqp_version.h index 300dc520..52f73d26 100644 --- a/php_amqp_version.h +++ b/php_amqp_version.h @@ -1,6 +1,6 @@ #define PHP_AMQP_VERSION_MAJOR 2 #define PHP_AMQP_VERSION_MINOR 0 #define PHP_AMQP_VERSION_PATCH 0 -#define PHP_AMQP_VERSION_EXTRA "dev" -#define PHP_AMQP_VERSION "2.0.0dev" +#define PHP_AMQP_VERSION_EXTRA "" +#define PHP_AMQP_VERSION "2.0.0" #define PHP_AMQP_VERSION_ID 20000 From 75c21ddd8b0a0c1493d567b2440a0e099270e412 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Sun, 20 Aug 2023 13:14:34 +0200 Subject: [PATCH 062/147] [RM] back to dev 2.0.1dev --- package.xml | 148 +++++++++++++++++++++++++-------------------- php_amqp_version.h | 8 +-- 2 files changed, 87 insertions(+), 69 deletions(-) diff --git a/package.xml b/package.xml index 5beaae06..91bf75d1 100644 --- a/package.xml +++ b/package.xml @@ -23,78 +23,21 @@ yes 2023-08-20 - + - 2.0.0 - 2.0.0 + 2.0.1dev + 2.0.1dev - stable - stable + devel + devel PHP License - ) (https://github.com/php-amqp/php-amqp/issues/467) - - Ubuntu development containers (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/466) - - Test against upcoming PHP 8.3 (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/465) - - Make test host configurable (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/464) - - Cosmetics on type functions (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/350202f) - - Configurable serialization/deserialization depth (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/463) - - Allow bitmask flags arguments to be nullable where previously AMQP_NOPARAM/zero was required (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/462) - - Fix generated commit URLs in changelogs (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/4ee6159) - - Handle nested AMQP value serialization/deserialization (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/461) - - Document lack of reliability of AMQPConnection::isConnected (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/306) - - Prevent reuse of channel ID of broken channels (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/460) - - Gracefully handle zero as a heartbeat value (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/459) - - Build with the clang compiler on CI (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/457) - - Include stdint.h for PHP >= 8.0 on Windows (Jan Ehrhardt) (https://github.com/php-amqp/php-amqp/issues/456) - - Fix segfault in setPort (Remi Collet ) (https://github.com/php-amqp/php-amqp/issues/455) - - Document BC changes (Lars Strojny ) - - Document pseudo-bool method changes (Lars Strojny ) - - Fix mangled header on MacOS (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/60) - - Validate argument parsing, add AMQPExchange::removeArgument() and AMQPQueue::removeArgument() (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/452) - - Skip SSL tests if certificates are missing (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/450) - - Check coding style and formatting of stub files (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/447) - - Parallelize test execution (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/444) - - Deterministic configuration for PHP CLI (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/443) - - Fix tag creation during release management (Lars Strojny ) - - Move test-report.sh into infra (Lars Strojny ) - - The big fat API renovation (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/437) - - Handle alpha/beta stability correctly (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/5546436) - - Expose better version information (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/438) - - Auto-format the codebase (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/436) - - More consistent return types for AMQPEnvelope (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/435) - - Update stubs (Lars Strojny ) - - Fix parameter error handling in AMQPConnection and AMQPChannel (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/434) - - Increase credentials and identifier limits (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/433) - - Reliably clear consumer tag on AMQPQueue::cancel (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/432) - - Ignore failures on experimental builds (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/25) - - Update branch name (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/7) - - Bump shivammathur/setup-php from 2.25.3 to 2.25.4 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/431) - - PHP 8.2 refactorings (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/430) - - Fix php version check for static building (Misha Kulakovsky ) (https://github.com/php-amqp/php-amqp/issues/425) - - Fix stub exception class (closes #427) (Lars Strojny ) - - Document custom connection name in stubs (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/700000) - - Expose Delivery Mode through constants (Flávio Heleno ) (https://github.com/php-amqp/php-amqp/issues/420) - - Fix deprecation issue in PHP 8.1 for $consumerTag argument to AMQPQueue::consume() method (Liviu-Ionut Iosif) (https://github.com/php-amqp/php-amqp/issues/421) - - Fix: Deprecated: Creation of dynamic property (8.2) (Remi Collet ) (https://github.com/php-amqp/php-amqp/issues/418) - - Fix AMQPEnvelope::getDeliveryTag() return type (Flávio Heleno ) (https://github.com/php-amqp/php-amqp/issues/415) - - Fix ack/nack/reject param documentation (Flávio Heleno ) (https://github.com/php-amqp/php-amqp/issues/414) - - Mention time units in all timeout-related methods (Andrii Dembitskyi ) (https://github.com/php-amqp/php-amqp/issues/410) + +https://github.com/php-amqp/php-amqp/compare/v2.0.0...latest +]]> @@ -352,6 +295,81 @@ https://github.com/php-amqp/php-amqp/compare/v1.11.0...v2.0.0]]> + + 2023-08-20 + + + 2.0.0 + 2.0.0 + + + stable + stable + + PHP License + ) (https://github.com/php-amqp/php-amqp/issues/467) + - Ubuntu development containers (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/466) + - Test against upcoming PHP 8.3 (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/465) + - Make test host configurable (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/464) + - Cosmetics on type functions (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/350202f) + - Configurable serialization/deserialization depth (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/463) + - Allow bitmask flags arguments to be nullable where previously AMQP_NOPARAM/zero was required (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/462) + - Fix generated commit URLs in changelogs (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/4ee6159) + - Handle nested AMQP value serialization/deserialization (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/461) + - Document lack of reliability of AMQPConnection::isConnected (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/306) + - Prevent reuse of channel ID of broken channels (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/460) + - Gracefully handle zero as a heartbeat value (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/459) + - Build with the clang compiler on CI (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/457) + - Include stdint.h for PHP >= 8.0 on Windows (Jan Ehrhardt) (https://github.com/php-amqp/php-amqp/issues/456) + - Fix segfault in setPort (Remi Collet ) (https://github.com/php-amqp/php-amqp/issues/455) + - Document BC changes (Lars Strojny ) + - Document pseudo-bool method changes (Lars Strojny ) + - Fix mangled header on MacOS (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/60) + - Validate argument parsing, add AMQPExchange::removeArgument() and AMQPQueue::removeArgument() (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/452) + - Skip SSL tests if certificates are missing (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/450) + - Check coding style and formatting of stub files (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/447) + - Parallelize test execution (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/444) + - Deterministic configuration for PHP CLI (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/443) + - Fix tag creation during release management (Lars Strojny ) + - Move test-report.sh into infra (Lars Strojny ) + - The big fat API renovation (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/437) + - Handle alpha/beta stability correctly (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/5546436) + - Expose better version information (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/438) + - Auto-format the codebase (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/436) + - More consistent return types for AMQPEnvelope (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/435) + - Update stubs (Lars Strojny ) + - Fix parameter error handling in AMQPConnection and AMQPChannel (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/434) + - Increase credentials and identifier limits (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/433) + - Reliably clear consumer tag on AMQPQueue::cancel (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/432) + - Ignore failures on experimental builds (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/25) + - Update branch name (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/7) + - Bump shivammathur/setup-php from 2.25.3 to 2.25.4 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/431) + - PHP 8.2 refactorings (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/430) + - Fix php version check for static building (Misha Kulakovsky ) (https://github.com/php-amqp/php-amqp/issues/425) + - Fix stub exception class (closes #427) (Lars Strojny ) + - Document custom connection name in stubs (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/700000) + - Expose Delivery Mode through constants (Flávio Heleno ) (https://github.com/php-amqp/php-amqp/issues/420) + - Fix deprecation issue in PHP 8.1 for $consumerTag argument to AMQPQueue::consume() method (Liviu-Ionut Iosif) (https://github.com/php-amqp/php-amqp/issues/421) + - Fix: Deprecated: Creation of dynamic property (8.2) (Remi Collet ) (https://github.com/php-amqp/php-amqp/issues/418) + - Fix AMQPEnvelope::getDeliveryTag() return type (Flávio Heleno ) (https://github.com/php-amqp/php-amqp/issues/415) + - Fix ack/nack/reject param documentation (Flávio Heleno ) (https://github.com/php-amqp/php-amqp/issues/414) + - Mention time units in all timeout-related methods (Andrii Dembitskyi ) (https://github.com/php-amqp/php-amqp/issues/410) + +For a complete list of changes see: +https://github.com/php-amqp/php-amqp/compare/v1.11.0...v2.0.0]]> + 2023-08-15 diff --git a/php_amqp_version.h b/php_amqp_version.h index 52f73d26..e72f33d3 100644 --- a/php_amqp_version.h +++ b/php_amqp_version.h @@ -1,6 +1,6 @@ #define PHP_AMQP_VERSION_MAJOR 2 #define PHP_AMQP_VERSION_MINOR 0 -#define PHP_AMQP_VERSION_PATCH 0 -#define PHP_AMQP_VERSION_EXTRA "" -#define PHP_AMQP_VERSION "2.0.0" -#define PHP_AMQP_VERSION_ID 20000 +#define PHP_AMQP_VERSION_PATCH 1 +#define PHP_AMQP_VERSION_EXTRA "dev" +#define PHP_AMQP_VERSION "2.0.1dev" +#define PHP_AMQP_VERSION_ID 20001 From 00a671569c6353a65951d731a09727aa1f8e3232 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Mon, 21 Aug 2023 08:57:17 +0200 Subject: [PATCH 063/147] Fix version test for release builds --- tests/amqp_version.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/amqp_version.phpt b/tests/amqp_version.phpt index d1433a16..9b65a65f 100644 --- a/tests/amqp_version.phpt +++ b/tests/amqp_version.phpt @@ -19,6 +19,6 @@ string(%d) "%d.%d.%s" int(%d) int(%d) int(%d) -string(%d) "%s" +string(%d) "%S" int(%d) ==DONE== From 4503e537438e5d5bd650a3f1d6806d30da41cab6 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Mon, 21 Aug 2023 16:00:06 +0200 Subject: [PATCH 064/147] Replace microtime() as a randomness source --- benchmark.php | 5 +++-- tests/amqpqueue_consume_multiple.phpt | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/benchmark.php b/benchmark.php index f640dbec..dbc3a237 100644 --- a/benchmark.php +++ b/benchmark.php @@ -23,6 +23,7 @@ $conn = new AMQPConnection(); +$conn->setHost(getenv('PHP_AMQP_HOST')); $conn->connect(); $ch = new AMQPChannel($conn); @@ -30,7 +31,7 @@ $exchange = new AMQPExchange($ch); $exchange->setType(AMQP_EX_TYPE_FANOUT); $exchange->setFlags(AMQP_AUTODELETE); -$exchange->setName('benchmark_exchange_' . microtime(true)); +$exchange->setName('benchmark_exchange_' . bin2hex(random_bytes(32))); $exchange->declareExchange(); $q = new AMQPQueue($ch); @@ -70,7 +71,7 @@ $exchange = new AMQPExchange($ch); $exchange->setType(AMQP_EX_TYPE_FANOUT); $exchange->setFlags(AMQP_AUTODELETE); -$exchange->setName('benchmark_exchange_' . microtime(true)); +$exchange->setName('benchmark_exchange_' . bin2hex(random_bytes(32))); $exchange->declareExchange(); $q = new AMQPQueue($ch); diff --git a/tests/amqpqueue_consume_multiple.phpt b/tests/amqpqueue_consume_multiple.phpt index e34d54cb..233e6838 100644 --- a/tests/amqpqueue_consume_multiple.phpt +++ b/tests/amqpqueue_consume_multiple.phpt @@ -7,7 +7,7 @@ if (!getenv("PHP_AMQP_HOST")) print "skip"; ?> --FILE-- setHost(getenv('PHP_AMQP_HOST')); @@ -19,23 +19,23 @@ $ch3 = new AMQPChannel($cnn); // Declare a new exchange $ex = new AMQPExchange($ch); -$ex->setName('exchange-' . $time); +$ex->setName('exchange-' . $id); $ex->setType(AMQP_EX_TYPE_TOPIC); $ex->declareExchange(); // Create and bind queues $q1 = new AMQPQueue($ch); -$q1->setName('queue-one-' . $time); +$q1->setName('queue-one-' . $id); $q1->declareQueue(); $q1->bind($ex->getName(), 'routing.one'); $q2 = new AMQPQueue($ch2); -$q2->setName('queue-two-' . $time); +$q2->setName('queue-two-' . $id); $q2->declareQueue(); $q2->bind($ex->getName(), 'routing.two'); $q3 = new AMQPQueue($ch3); -$q3->setName('queue-three-' . $time); +$q3->setName('queue-three-' . $id); $q3->declareQueue(); $q3->bind($ex->getName(), 'routing.three'); From 4971c80ce29088523f7f12b6a2d19e7879e3107e Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Mon, 21 Aug 2023 16:01:12 +0200 Subject: [PATCH 065/147] Remove appveyor badge --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 03622005..859d6918 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# PHP AMQP bindings [![Test](https://github.com/php-amqp/php-amqp/actions/workflows/test.yaml/badge.svg)](https://github.com/php-amqp/php-amqp/actions/workflows/test.yaml) [![Build status](https://ci.appveyor.com/api/projects/status/sv5o1id5oj63w9hu/branch/latest?svg=true)](https://ci.appveyor.com/project/lstrojny/php-amqp-7lf47/branch/latest) +# PHP AMQP bindings [![Test](https://github.com/php-amqp/php-amqp/actions/workflows/test.yaml/badge.svg)](https://github.com/php-amqp/php-amqp/actions/workflows/test.yaml) Object-oriented PHP bindings for the AMQP C library (https://github.com/alanxz/rabbitmq-c) @@ -61,9 +61,9 @@ cases. ### Related libraries -* [enqueue/amqp-ext](https://github.com/php-enqueue/amqp-ext) is +- [enqueue/amqp-ext](https://github.com/php-enqueue/amqp-ext) is an [amqp interop](https://github.com/queue-interop/queue-interop#amqp-interop) compatible wrapper -* [symfony/amqp-messenger](https://symfony.com/components/AMQP%20Messenger) provides AMQP integration +- [symfony/amqp-messenger](https://symfony.com/components/AMQP%20Messenger) provides AMQP integration for [symfony/messenger](https://symfony.com/doc/current/messenger.html), the popular messaging component by Symfony. ### How to report a problem From 205854c7348cdf57eb60b6afce87403eb18548af Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 25 Aug 2023 10:07:01 +0200 Subject: [PATCH 066/147] Bump actions/checkout from 3.5.3 to 3.6.0 (#471) --- .github/workflows/test.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 990f53ae..4ac6bec1 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -41,7 +41,7 @@ jobs: install: clang-format-17 - name: Checkout - uses: actions/checkout@v3.5.3 + uses: actions/checkout@v3.6.0 - name: Check style run: ./infra/tools/pamqp-format-check @@ -59,7 +59,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3.5.3 + uses: actions/checkout@v3.6.0 - name: Install packages uses: awalsh128/cache-apt-pkgs-action@v1.3.0 @@ -178,7 +178,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3.5.3 + uses: actions/checkout@v3.6.0 - name: Configure hostnames run: sudo echo "127.0.0.1 ${{ env.PHP_AMQP_SSL_HOST }}" | sudo tee -a /etc/hosts From ff0874e232e164ba8caf985aba8fa0a5825189b3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 25 Aug 2023 13:01:14 +0200 Subject: [PATCH 067/147] Bump symplify/easy-coding-standard from 12.0.6 to 12.0.7 (#472) --- composer.lock | 12 ++++++------ stubs/AMQPConnection.php | 2 -- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/composer.lock b/composer.lock index b4223b1b..ec98b948 100644 --- a/composer.lock +++ b/composer.lock @@ -256,16 +256,16 @@ }, { "name": "symplify/easy-coding-standard", - "version": "12.0.6", + "version": "12.0.7", "source": { "type": "git", "url": "https://github.com/easy-coding-standard/easy-coding-standard.git", - "reference": "7372622f5d9126ec50b0923d7eb6b778fac575a5" + "reference": "79b5679f0dd758311770543969087b8dc46429ee" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/7372622f5d9126ec50b0923d7eb6b778fac575a5", - "reference": "7372622f5d9126ec50b0923d7eb6b778fac575a5", + "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/79b5679f0dd758311770543969087b8dc46429ee", + "reference": "79b5679f0dd758311770543969087b8dc46429ee", "shasum": "" }, "require": { @@ -298,7 +298,7 @@ ], "support": { "issues": "https://github.com/easy-coding-standard/easy-coding-standard/issues", - "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.0.6" + "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.0.7" }, "funding": [ { @@ -310,7 +310,7 @@ "type": "github" } ], - "time": "2023-07-25T17:12:00+00:00" + "time": "2023-08-24T21:43:33+00:00" } ], "aliases": [], diff --git a/stubs/AMQPConnection.php b/stubs/AMQPConnection.php index 2a5d7f81..e5440f7d 100644 --- a/stubs/AMQPConnection.php +++ b/stubs/AMQPConnection.php @@ -416,8 +416,6 @@ public function getCert(): ?string /** * Set path to the client certificate in PEM format - * - * @param string $cert */ public function setCert(?string $cert): void { From a07668cd1897322dc89d63afe1667a71bc701baa Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Fri, 25 Aug 2023 13:14:41 +0200 Subject: [PATCH 068/147] AMQPValue interface for custom value objects (#473) --- .github/workflows/test.yaml | 106 +++++-------------- amqp.c | 7 +- amqp_channel.c | 18 +--- amqp_decimal.c | 22 +++- amqp_queue.c | 15 ++- amqp_timestamp.c | 22 +++- amqp_type.c | 14 +++ amqp_value.c | 49 +++++++++ amqp_value.h | 27 +++++ config.m4 | 2 +- config.w32 | 2 +- infra/tools/pamqp-arguments-validate | 13 ++- infra/tools/pamqp-dump-reflection | 43 ++++++-- infra/tools/pamqp-matrix | 18 ++++ php_amqp.h | 1 - stubs/AMQPDecimal.php | 8 +- stubs/AMQPQueue.php | 42 ++++---- stubs/AMQPTimestamp.php | 8 +- stubs/AMQPValue.php | 11 ++ tests/amqpdecimal.phpt | 5 +- tests/amqpqueue_setArgument.phpt | 72 ++++++++++++- tests/amqptimestamp.phpt | 4 + tests/serialize-custom-amqpvalue-errors.phpt | 59 +++++++++++ tests/serialize-custom-amqpvalue.phpt | 80 ++++++++++++++ 24 files changed, 511 insertions(+), 137 deletions(-) create mode 100644 amqp_value.c create mode 100644 amqp_value.h create mode 100755 infra/tools/pamqp-matrix create mode 100644 stubs/AMQPValue.php create mode 100644 tests/serialize-custom-amqpvalue-errors.phpt create mode 100644 tests/serialize-custom-amqpvalue.phpt diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 4ac6bec1..9003c280 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -11,31 +11,43 @@ env: MAKEFLAGS: -j4 jobs: - dedup: - name: Prevent duplicate builds + prep: + name: Prepare continue-on-error: true runs-on: ubuntu-22.04 outputs: should_skip: ${{ steps.skip_check.outputs.should_skip }} + php_versions: ${{ steps.matrix.outputs.php_versions }} + librabbitmq_versions: ${{ steps.matrix.outputs.librabbitmq_versions }} + memory_build_matrix: ${{ steps.matrix.outputs.memory_build_matrix }} steps: - id: skip_check + name: Prevent duplicate builds uses: fkirc/skip-duplicate-actions@v5.3.0 with: skip_after_successful_duplicate: 'true' cancel_others: 'true' concurrent_skipping: 'same_content_newer' + - name: Checkout + uses: actions/checkout@v3.5.3 + + - name: Prepare matrix + id: matrix + run: | + infra/tools/pamqp-matrix >> "$GITHUB_OUTPUT" + checkstyle: name: Check C formatting runs-on: ubuntu-22.04 - needs: dedup - if: needs.dedup.outputs.should_skip != 'true' + needs: prep + if: needs.prep.outputs.should_skip != 'true' steps: - name: Install clang-format uses: myci-actions/add-deb-repo@11 with: - repo: "deb https://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" + repo: 'deb https://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main' repo-name: llvm keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key install: clang-format-17 @@ -49,13 +61,13 @@ jobs: stubs: name: Check stubs php-${{ matrix.php-version }} runs-on: ubuntu-22.04 - needs: dedup - if: needs.dedup.outputs.should_skip != 'true' + needs: prep + if: needs.prep.outputs.should_skip != 'true' strategy: fail-fast: false matrix: - php-version: [ "8.3", "8.2", "8.1", "8.0", "7.4" ] + php-version: ${{ fromJson(needs.prep.outputs.php_versions) }} steps: - name: Checkout @@ -92,89 +104,29 @@ jobs: - name: Validate argument parsing run: ./infra/tools/pamqp-php-cli-deterministic -d extension=modules/amqp.so ./infra/tools/pamqp-arguments-validate - if: matrix.php-version == '8.2' || matrix.php-version == '8.3' test: name: ${{ matrix.test-php-args == '-m' && 'Memtest' || 'Test' }} php-${{ matrix.php-version }}${{ matrix.php-thread-safe && '-ts' || '-nts' }} librabbitmq-${{ matrix.librabbitmq-version }} ${{ matrix.compiler }} - # librabbitmq < 0.11 needs older OpenSSL version + # librabbitmq < 0.11 needs older OpenSSL version which comes with Ubuntu 20.04 runs-on: ${{ (matrix.librabbitmq-version == '0.10.0' || matrix.librabbitmq-version == '0.9.0' || matrix.librabbitmq-version == '0.8.0') && 'ubuntu-20.04' || 'ubuntu-22.04' }} - needs: dedup - if: needs.dedup.outputs.should_skip != 'true' + needs: prep + if: needs.prep.outputs.should_skip != 'true' env: CC: ${{ matrix.compiler }} TEST_PHP_ARGS: -j4 ${{ matrix.test-php-args }} PHP_AMQP_HOST: localhost PHP_AMQP_SSL_HOST: rabbitmq.example.org - VALGRIND_OPTS: "--suppressions=infra/tools/valgrind-suppressions" + VALGRIND_OPTS: '--suppressions=infra/tools/valgrind-suppressions' strategy: fail-fast: false matrix: - php-version: [ '8.3', '8.2', '8.1', '8.0', '7.4' ] + php-version: ${{ fromJson(needs.prep.outputs.php_versions) }} php-thread-safe: [ true, false ] - librabbitmq-version: [ 'master', '0.13.0', '0.12.0', '0.11.0', '0.10.0', '0.9.0', '0.8.0' ] + librabbitmq-version: ${{ fromJson(needs.prep.outputs.librabbitmq_versions) }} compiler: [gcc, clang] - include: - - php-version: '8.3' - php-thread-safe: true - librabbitmq-version: 'master' - test-php-args: '-m' - compiler: gcc - - - php-version: '8.3' - php-thread-safe: true - librabbitmq-version: '0.8.0' - test-php-args: '-m' - compiler: gcc - - - php-version: '8.2' - php-thread-safe: true - librabbitmq-version: 'master' - test-php-args: '-m' - compiler: gcc - - - php-version: '8.2' - php-thread-safe: true - librabbitmq-version: '0.8.0' - test-php-args: '-m' - compiler: gcc - - - php-version: '8.1' - php-thread-safe: true - librabbitmq-version: 'master' - test-php-args: '-m' - compiler: gcc - - - php-version: '8.1' - php-thread-safe: true - librabbitmq-version: '0.8.0' - test-php-args: '-m' - compiler: gcc - - - php-version: '8.0' - php-thread-safe: true - librabbitmq-version: 'master' - test-php-args: '-m' - compiler: gcc - - - php-version: '8.0' - php-thread-safe: true - librabbitmq-version: '0.8.0' - test-php-args: '-m' - compiler: gcc - - - php-version: '7.4' - php-thread-safe: true - librabbitmq-version: 'master' - test-php-args: '-m' - compiler: gcc - - - php-version: '7.4' - php-thread-safe: true - librabbitmq-version: '0.8.0' - test-php-args: '-m' - compiler: gcc + include: ${{ fromJson(needs.prep.outputs.memory_build_matrix) }} steps: - name: Checkout @@ -219,8 +171,8 @@ jobs: env: # Reset defaults to a) only run local tests, b) don’t run memory checks as the full test suite run will do so TEST_PHP_ARGS: -j4 - PHP_AMQP_HOST: "" - PHP_AMQP_SSL_HOST: "" + PHP_AMQP_HOST: '' + PHP_AMQP_SSL_HOST: '' - name: Test full test suite run: make test | tee result-full.txt diff --git a/amqp.c b/amqp.c index c97106ac..d8cbcac4 100644 --- a/amqp.c +++ b/amqp.c @@ -59,6 +59,7 @@ #include "amqp_envelope_exception.h" #include "amqp_exchange.h" #include "amqp_queue.h" +#include "amqp_value.h" #include "amqp_timestamp.h" #include "amqp_decimal.h" @@ -69,9 +70,8 @@ #endif /* True global resources - no need for thread safety here */ - zend_class_entry *amqp_exception_class_entry, *amqp_connection_exception_class_entry, - *amqp_channel_exception_class_entry, *amqp_queue_exception_class_entry, *amqp_exchange_exception_class_entry, + *amqp_channel_exception_class_entry, *amqp_exchange_exception_class_entry, *amqp_queue_exception_class_entry, *amqp_value_exception_class_entry; /* {{{ amqp_functions[] @@ -274,7 +274,7 @@ static PHP_MINIT_FUNCTION(amqp) /* {{{ */ module_number ); - /* Class Exceptions */ + /* Exceptions */ INIT_CLASS_ENTRY(ce, "AMQPException", NULL); amqp_exception_class_entry = zend_register_internal_class_ex(&ce, zend_exception_get_default()); @@ -300,6 +300,7 @@ static PHP_MINIT_FUNCTION(amqp) /* {{{ */ PHP_MINIT(amqp_basic_properties)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(amqp_envelope)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(amqp_envelope_exception)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(amqp_value)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(amqp_timestamp)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(amqp_decimal)(INIT_FUNC_ARGS_PASSTHRU); diff --git a/amqp_channel.c b/amqp_channel.c index 2b746e73..98d48004 100644 --- a/amqp_channel.c +++ b/amqp_channel.c @@ -913,9 +913,7 @@ static PHP_METHOD(amqp_channel_class, startTransaction) amqp_rpc_reply_t res; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) { - return; - } + PHP_AMQP_NOPARAMS() channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not start the transaction."); @@ -943,9 +941,7 @@ static PHP_METHOD(amqp_channel_class, commitTransaction) amqp_rpc_reply_t res; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) { - return; - } + PHP_AMQP_NOPARAMS() channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not start the transaction."); @@ -972,10 +968,7 @@ static PHP_METHOD(amqp_channel_class, rollbackTransaction) amqp_rpc_reply_t res; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) { - return; - } - + PHP_AMQP_NOPARAMS() channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not rollback the transaction."); @@ -1046,9 +1039,7 @@ PHP_METHOD(amqp_channel_class, confirmSelect) amqp_channel_resource *channel_resource; amqp_rpc_reply_t res; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) { - return; - } + PHP_AMQP_NOPARAMS() channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not enable confirms mode."); @@ -1060,6 +1051,7 @@ PHP_METHOD(amqp_channel_class, confirmSelect) if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; } diff --git a/amqp_decimal.c b/amqp_decimal.c index 7a4a9684..591cc0bf 100644 --- a/amqp_decimal.c +++ b/amqp_decimal.c @@ -27,6 +27,7 @@ #include "php.h" #include "zend_exceptions.h" #include "php_amqp.h" +#include "amqp_value.h" zend_class_entry *amqp_decimal_class_entry; #define this_ce amqp_decimal_class_entry @@ -93,7 +94,7 @@ static PHP_METHOD(amqp_decimal_class, getExponent) /* }}} */ /* {{{ proto int AMQPDecimal::getSignificand() -Get E */ +Get significand */ static PHP_METHOD(amqp_decimal_class, getSignificand) { zval rv; @@ -103,6 +104,16 @@ static PHP_METHOD(amqp_decimal_class, getSignificand) } /* }}} */ +/* {{{ proto int AMQPDecimal::toAmqpValue() +Get AMQPDecimal as AMQPValue */ +static PHP_METHOD(amqp_decimal_class, toAmqpValue) +{ + PHP_AMQP_NOPARAMS() + + RETURN_ZVAL(getThis(), 1, 0); +} +/* }}} */ + ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_decimal_class_construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 2) ZEND_ARG_TYPE_INFO(0, exponent, IS_LONG, 0) @@ -115,11 +126,14 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_decimal_class_getSignificand, ZEND_SEND_BY_VAL, 0, IS_LONG, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_decimal_class_toAmqpValue, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_END_ARG_INFO() zend_function_entry amqp_decimal_class_functions[] = { PHP_ME(amqp_decimal_class, __construct, arginfo_amqp_decimal_class_construct, ZEND_ACC_PUBLIC) PHP_ME(amqp_decimal_class, getExponent, arginfo_amqp_decimal_class_getExponent, ZEND_ACC_PUBLIC) PHP_ME(amqp_decimal_class, getSignificand, arginfo_amqp_decimal_class_getSignificand, ZEND_ACC_PUBLIC) + PHP_ME(amqp_decimal_class, toAmqpValue, arginfo_amqp_decimal_class_toAmqpValue, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; @@ -131,7 +145,11 @@ PHP_MINIT_FUNCTION(amqp_decimal) INIT_CLASS_ENTRY(ce, "AMQPDecimal", amqp_decimal_class_functions); this_ce = zend_register_internal_class(&ce); - this_ce->ce_flags = this_ce->ce_flags | ZEND_ACC_FINAL; + zend_class_implements(this_ce, 1, amqp_value_class_entry); + this_ce->ce_flags |= ZEND_ACC_FINAL; +#if PHP_VERSION_ID >= 80200 + this_ce->ce_flags |= ZEND_ACC_READONLY_CLASS; +#endif zend_declare_class_constant_long(this_ce, ZEND_STRL("EXPONENT_MIN"), AMQP_DECIMAL_EXPONENT_MIN); zend_declare_class_constant_long(this_ce, ZEND_STRL("EXPONENT_MAX"), AMQP_DECIMAL_EXPONENT_MAX); diff --git a/amqp_queue.c b/amqp_queue.c index 1ca5998d..31428e50 100644 --- a/amqp_queue.c +++ b/amqp_queue.c @@ -62,6 +62,9 @@ #include "amqp_envelope.h" #include "amqp_queue.h" #include "amqp_type.h" +#include "amqp_value.h" +#include "amqp_decimal.h" +#include "amqp_timestamp.h" zend_class_entry *amqp_queue_class_entry; #define this_ce amqp_queue_class_entry @@ -277,19 +280,29 @@ static PHP_METHOD(amqp_queue_class, setArgument) } switch (Z_TYPE_P(value)) { + case IS_OBJECT: + if (!instanceof_function(Z_OBJCE_P(value), amqp_timestamp_class_entry) && + !instanceof_function(Z_OBJCE_P(value), amqp_decimal_class_entry) && + !instanceof_function(Z_OBJCE_P(value), amqp_value_class_entry)) { + goto err; + } + // Intentional fall-through case IS_NULL: case IS_TRUE: case IS_FALSE: case IS_LONG: case IS_DOUBLE: case IS_STRING: + case IS_ARRAY: zend_hash_str_add(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len, value); Z_TRY_ADDREF_P(value); break; default: + err: zend_throw_exception( amqp_queue_exception_class_entry, - "The value parameter must be of type bool, int, double, string, or null.", + "The value parameter must be of type bool, int, double, string, null, array, AMQPTimestamp, " + "AMQPDecimal, or an implementation of AMQPValue.", 0 ); return; diff --git a/amqp_timestamp.c b/amqp_timestamp.c index 40e495e8..4256b314 100644 --- a/amqp_timestamp.c +++ b/amqp_timestamp.c @@ -28,6 +28,7 @@ #include "zend_exceptions.h" #include "php_amqp.h" #include "ext/standard/php_math.h" +#include "amqp_value.h" zend_class_entry *amqp_timestamp_class_entry; #define this_ce amqp_timestamp_class_entry @@ -95,6 +96,17 @@ static PHP_METHOD(amqp_timestamp_class, __toString) } /* }}} */ +/* {{{ proto string AMQPTimestamp::toAmqpValue() +Return timestamp as AMQPValue */ +static PHP_METHOD(amqp_timestamp_class, toAmqpValue) +{ + PHP_AMQP_NOPARAMS() + + RETURN_ZVAL(getThis(), 1, 0); +} +/* }}} */ + + ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_timestamp_class_construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) ZEND_ARG_TYPE_INFO(0, timestamp, IS_DOUBLE, 0) ZEND_END_ARG_INFO() @@ -105,10 +117,14 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_timestamp_class_toString, ZEND_SEND_BY_VAL, 0, IS_STRING, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_timestamp_class_toAmqpValue, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_END_ARG_INFO() + zend_function_entry amqp_timestamp_class_functions[] = { PHP_ME(amqp_timestamp_class, __construct, arginfo_amqp_timestamp_class_construct, ZEND_ACC_PUBLIC) PHP_ME(amqp_timestamp_class, getTimestamp, arginfo_amqp_timestamp_class_getTimestamp, ZEND_ACC_PUBLIC) PHP_ME(amqp_timestamp_class, __toString, arginfo_amqp_timestamp_class_toString, ZEND_ACC_PUBLIC) + PHP_ME(amqp_timestamp_class, toAmqpValue, arginfo_amqp_timestamp_class_toAmqpValue, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; @@ -120,7 +136,11 @@ PHP_MINIT_FUNCTION(amqp_timestamp) INIT_CLASS_ENTRY(ce, "AMQPTimestamp", amqp_timestamp_class_functions); this_ce = zend_register_internal_class(&ce); - this_ce->ce_flags = this_ce->ce_flags | ZEND_ACC_FINAL; + zend_class_implements(this_ce, 1, amqp_value_class_entry); + this_ce->ce_flags |= ZEND_ACC_FINAL; +#if PHP_VERSION_ID >= 80200 + this_ce->ce_flags |= ZEND_ACC_READONLY_CLASS; +#endif PHP_AMQP_DECLARE_TYPED_PROPERTY(this_ce, "timestamp", ZEND_ACC_PRIVATE, IS_DOUBLE, 0); diff --git a/amqp_type.c b/amqp_type.c index 5fbc41ca..c43cb421 100644 --- a/amqp_type.c +++ b/amqp_type.c @@ -31,6 +31,7 @@ #endif #include "Zend/zend_interfaces.h" #include "Zend/zend_exceptions.h" +#include "amqp_value.h" #include "amqp_decimal.h" #include "amqp_timestamp.h" #include "amqp_type.h" @@ -293,6 +294,19 @@ bool php_amqp_type_zval_to_amqp_value_internal(zval *value, amqp_field_value_t * zval_ptr_dtor(&result_zv); break; + } else if (instanceof_function(Z_OBJCE_P(value), amqp_value_class_entry)) { + zval result_zv; + zend_call_method_with_0_params( + PHP_AMQP_COMPAT_OBJ_P(value), + Z_OBJCE_P(value), + NULL, + "toamqpvalue", + &result_zv + ); + bool recursion_res = php_amqp_type_zval_to_amqp_value_internal(&result_zv, field_ptr, key, depth + 1); + zval_ptr_dtor(&result_zv); + + return recursion_res; } default: switch (Z_TYPE_P(value)) { diff --git a/amqp_value.c b/amqp_value.c new file mode 100644 index 00000000..47e2ae5e --- /dev/null +++ b/amqp_value.c @@ -0,0 +1,49 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2007 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Alexandre Kalendarev akalend@mail.ru Copyright (c) 2009-2010 | + | Lead: | + | - Pieter de Zwart | + | Maintainers: | + | - Brad Rodriguez | + | - Jonathan Tansavatdi | + +----------------------------------------------------------------------+ +*/ +#ifdef HAVE_CONFIG_H + #include "config.h" +#endif + +#include "php.h" + +zend_class_entry *amqp_value_class_entry; +#define this_ce amqp_value_class_entry + +ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_value_class_toAmqpValue, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0) +ZEND_END_ARG_INFO() + +zend_function_entry amqp_value_class_functions[] = { + PHP_ABSTRACT_ME(amqp_value_class, toAmqpValue, arginfo_amqp_value_class_toAmqpValue) + + {NULL, NULL, NULL} +}; + +PHP_MINIT_FUNCTION(amqp_value) +{ + zend_class_entry ce; + + INIT_CLASS_ENTRY(ce, "AMQPValue", amqp_value_class_functions); + amqp_value_class_entry = zend_register_internal_interface(&ce); + + return SUCCESS; +} diff --git a/amqp_value.h b/amqp_value.h new file mode 100644 index 00000000..d22ba8d9 --- /dev/null +++ b/amqp_value.h @@ -0,0 +1,27 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2007 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Alexandre Kalendarev akalend@mail.ru Copyright (c) 2009-2010 | + | Lead: | + | - Pieter de Zwart | + | Maintainers: | + | - Brad Rodriguez | + | - Jonathan Tansavatdi | + +----------------------------------------------------------------------+ +*/ +#include "php.h" + +extern zend_class_entry *amqp_value_class_entry; + +PHP_MINIT_FUNCTION(amqp_value); diff --git a/config.m4 b/config.m4 index e10b4705..3e33d57d 100644 --- a/config.m4 +++ b/config.m4 @@ -162,7 +162,7 @@ if test "$PHP_AMQP" != "no"; then PHP_SUBST(AMQP_SHARED_LIBADD) - AMQP_SOURCES="amqp.c amqp_envelope_exception.c amqp_type.c amqp_exchange.c amqp_queue.c amqp_connection.c amqp_connection_resource.c amqp_channel.c amqp_envelope.c amqp_basic_properties.c amqp_methods_handling.c amqp_timestamp.c amqp_decimal.c" + AMQP_SOURCES="amqp.c amqp_envelope_exception.c amqp_type.c amqp_exchange.c amqp_queue.c amqp_connection.c amqp_connection_resource.c amqp_channel.c amqp_envelope.c amqp_basic_properties.c amqp_methods_handling.c amqp_value.c amqp_timestamp.c amqp_decimal.c" PHP_NEW_EXTENSION(amqp, $AMQP_SOURCES, $ext_shared) fi diff --git a/config.w32 b/config.w32 index 6d1111d5..4d5420bc 100644 --- a/config.w32 +++ b/config.w32 @@ -4,7 +4,7 @@ if (PHP_AMQP != "no") { if (CHECK_HEADER_ADD_INCLUDE("amqp.h", "CFLAGS_AMQP", PHP_PHP_BUILD + "\\include;" + PHP_PHP_BUILD + "\\include\\librabbitmq;" + PHP_AMQP) && CHECK_LIB("rabbitmq.4.lib", "amqp", PHP_PHP_BUILD + "\\lib;" + PHP_AMQP)) { // ADD_FLAG("CFLAGS_AMQP", "/D HAVE_AMQP_GETSOCKOPT"); - EXTENSION('amqp', 'amqp.c amqp_envelope_exception.c amqp_type.c amqp_exchange.c amqp_queue.c amqp_connection.c amqp_connection_resource.c amqp_channel.c amqp_envelope.c amqp_basic_properties.c amqp_methods_handling.c amqp_timestamp.c amqp_decimal.c'); + EXTENSION('amqp', 'amqp.c amqp_envelope_exception.c amqp_type.c amqp_exchange.c amqp_queue.c amqp_connection.c amqp_connection_resource.c amqp_channel.c amqp_envelope.c amqp_basic_properties.c amqp_methods_handling.c amqp_value.c amqp_timestamp.c amqp_decimal.c'); AC_DEFINE('HAVE_AMQP', 1); } else { WARNING("amqp not enabled; libraries and headers not found"); diff --git a/infra/tools/pamqp-arguments-validate b/infra/tools/pamqp-arguments-validate index e318c410..d0857704 100755 --- a/infra/tools/pamqp-arguments-validate +++ b/infra/tools/pamqp-arguments-validate @@ -15,6 +15,7 @@ const CLASSES = [ 'AMQPQueue', 'AMQPQueueException', 'AMQPTimestamp', + 'AMQPValue', 'AMQPValueException', ]; @@ -36,6 +37,10 @@ function validate(string $class) { $refl = new ReflectionClass($class); + if ($refl->isInterface()) { + return; + } + $source = getSource($class); if ($source === null) { @@ -107,7 +112,7 @@ function validate(string $class) ); } - $reflectionNullable = $parameter->allowsNull(); + $reflectionNullable = $parameter->allowsNull() || !$parameter->hasType(); if ($reflectionNullable !== $types[$pos]['nullable']) { error( '%s::%s(%s): type parsing and Reflection nullability differs. Parameter parsing: %s (%s). Reflection: %s', @@ -133,6 +138,10 @@ function error(string $message, ...$args): void function parseParameterString(string $str): array { + if ($str == '') { + return [[], 0]; + } + $types = [ 's' => 'string', 'O' => 'object', @@ -163,7 +172,7 @@ function parseParameterString(string $str): array } elseif ($char === '/') { // Ignored } else { - throw new InvalidArgumentException($char); + throw new InvalidArgumentException(sprintf('Cannot handle char <%s>', $char)); } } diff --git a/infra/tools/pamqp-dump-reflection b/infra/tools/pamqp-dump-reflection index 9ea7c875..7621ce5d 100755 --- a/infra/tools/pamqp-dump-reflection +++ b/infra/tools/pamqp-dump-reflection @@ -15,16 +15,28 @@ function sortByName(array $array): array return $array; } -function getTypeMetadata(?ReflectionNamedType $type): ?array +function getTypeMetadata(?ReflectionType $type): ?array { if ($type == null) { return null; } - return [ - 'name' => $type->getName(), - 'nullable' => $type->allowsNull(), - ]; + if ($type instanceof ReflectionNamedType) { + return [ + 'name' => $type->getName(), + 'nullable' => $type->allowsNull(), + 'builtin' => $type->isBuiltin(), + ]; + } + + if ($type instanceof ReflectionUnionType || $type instanceof ReflectionIntersectionType) { + return [ + 'type' => $type instanceof ReflectionUnionType ? 'union' : 'intersection', + 'types' => array_map('getTypeMetadata', $type->getTypes()), + ]; + } + + assert(false, 'Unreachable'); } $error = false; @@ -37,6 +49,15 @@ function error(string $message, ...$args): void const MAGIC_METHODS = ['__construct', '__toString', '__wakeup', '__clone']; +function getParents(ReflectionClass $r): array { + $parents = []; + while ($r = $r->getParentClass()) { + $parents[] = $r->getName(); + } + + return $parents; +} + function getClassMetadata(string $class): array { $refl = new ReflectionClass($class); @@ -45,8 +66,17 @@ function getClassMetadata(string $class): array 'constants' => [], 'properties' => [], 'methods' => [], + 'final' => $refl->isFinal(), + 'abstract' => $refl->isAbstract(), + 'interface' => $refl->isInterface(), + 'implements' => $refl->getInterfaceNames(), + 'readonly' => method_exists($refl, 'isReadonly') ? $refl->isReadonly() || strpos($refl->getDocComment(), '@readonly') !== false : null, + 'extends' => getParents($refl), ]; + sort($classMetadata['implements']); + sort($classMetadata['extends']); + foreach ($refl->getReflectionConstants() as $constant) { if ($constant->getDeclaringClass()->getName() !== $refl->getName()) { continue; @@ -246,6 +276,7 @@ $symbols['classes'][] = getClassMetadata('AMQPConnection'); $symbols['classes'][] = getClassMetadata('AMQPChannelException'); $symbols['classes'][] = getClassMetadata('AMQPChannel'); $symbols['classes'][] = getClassMetadata('AMQPBasicProperties'); +$symbols['classes'][] = getClassMetadata('AMQPValue'); // Ensure we captured all AMQP classes foreach (get_declared_classes() as $className) { @@ -258,7 +289,7 @@ sort($symbols['classNames']); $filename = $_SERVER['argv'][1] ?? null; assert($filename !== null, 'Output filename must be passed'); -file_put_contents($filename, json_encode($symbols, JSON_PRETTY_PRINT)); +file_put_contents($filename, json_encode($symbols, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR)); if ($error) { exit(1); diff --git a/infra/tools/pamqp-matrix b/infra/tools/pamqp-matrix new file mode 100755 index 00000000..b90dc3ac --- /dev/null +++ b/infra/tools/pamqp-matrix @@ -0,0 +1,18 @@ +#!/usr/bin/env node +const PHP_VERSIONS = ["8.3", "8.2", "8.1", "8.0", "7.4"] +const LIBRABBITMQ_VERSIONS = ["master", "0.13.0", "0.12.0", "0.11.0", "0.10.0", "0.9.0", "0.8.0"] + +const toOutput = (k, v) => console.log(`${k}=${JSON.stringify(v)}`) +const stringSum = (s) => ([...s].map(c => c.charCodeAt(0)).reduce((c, v) => c + v, 0)) + +const memoryBuilds = PHP_VERSIONS.flatMap(php => [LIBRABBITMQ_VERSIONS[0], LIBRABBITMQ_VERSIONS.slice(-1)[0]].map(librabbitmq => ({ + "php-version": php, + "php-thread-safe": (stringSum(php) + stringSum(librabbitmq)) % 2 === 0, + "librabbitmq-version": librabbitmq, + "test-php-args": "-m", + "compiler": "gcc" +}))) + +toOutput('php_versions', PHP_VERSIONS) +toOutput('librabbitmq_versions', LIBRABBITMQ_VERSIONS) +toOutput('memory_build_matrix', memoryBuilds) \ No newline at end of file diff --git a/php_amqp.h b/php_amqp.h index 5bda6476..1ac2144b 100644 --- a/php_amqp.h +++ b/php_amqp.h @@ -34,7 +34,6 @@ extern zend_class_entry *amqp_exception_class_entry, *amqp_connection_exception_ *amqp_channel_exception_class_entry, *amqp_exchange_exception_class_entry, *amqp_queue_exception_class_entry, *amqp_value_exception_class_entry; - typedef struct _amqp_connection_resource amqp_connection_resource; typedef struct _amqp_connection_object amqp_connection_object; typedef struct _amqp_channel_object amqp_channel_object; diff --git a/stubs/AMQPDecimal.php b/stubs/AMQPDecimal.php index b84a7a26..825d5d0d 100644 --- a/stubs/AMQPDecimal.php +++ b/stubs/AMQPDecimal.php @@ -2,8 +2,10 @@ /** * stub class representing AMQPDecimal from pecl-amqp + * + * @readonly */ -final class AMQPDecimal +final /* readonly */ class AMQPDecimal implements AMQPValue { /** * @var int @@ -43,4 +45,8 @@ public function getExponent(): int public function getSignificand(): int { } + + public function toAmqpValue() + { + } } diff --git a/stubs/AMQPQueue.php b/stubs/AMQPQueue.php index a650ef12..d9e3bc97 100644 --- a/stubs/AMQPQueue.php +++ b/stubs/AMQPQueue.php @@ -199,26 +199,6 @@ public function get(?int $flags = null): ?AMQPEnvelope { } - /** - * Get the argument associated with the given key. - * - * @param string $argumentName The key to look up. - * @throws AMQPQueueException If key does not exist - * @return bool|int|double|string|null - */ - public function getArgument(string $argumentName) - { - } - - /** - * Get all set arguments as an array of key/value pairs. - * - * @return array An array containing all the set key/value pairs. - */ - public function getArguments(): array - { - } - /** * Get all the flags currently set on the given queue. * @@ -292,11 +272,22 @@ public function purge(): int { } + /** + * Get the argument associated with the given key. + * + * @param string $argumentName The key to look up. + * @throws AMQPQueueException If key does not exist + * @return bool|int|double|string|null|array|AMQPValue|AMQPDecimal|AMQPTimestamp + */ + public function getArgument(string $argumentName) + { + } + /** * Set a queue argument. * * @param string $argumentName The argument name to set. - * @param bool|int|double|string|null $argumentValue The argument value to set. + * @param bool|int|double|string|null|array|AMQPValue|AMQPDecimal|AMQPTimestamp $argumentValue The argument value to set. */ public function setArgument(string $argumentName, $argumentValue): void { @@ -322,6 +313,15 @@ public function setArguments(array $arguments): void { } + /** + * Get all set arguments as an array of key/value pairs. + * + * @return array An array containing all the set key/value pairs. + */ + public function getArguments(): array + { + } + /** * Check whether a queue has specific argument. * diff --git a/stubs/AMQPTimestamp.php b/stubs/AMQPTimestamp.php index 5b19fbd6..0e27d538 100644 --- a/stubs/AMQPTimestamp.php +++ b/stubs/AMQPTimestamp.php @@ -2,8 +2,10 @@ /** * stub class representing AMQPTimestamp from pecl-amqp + * + * @readonly */ -final class AMQPTimestamp +final /* readonly */ class AMQPTimestamp implements AMQPValue { /** * @var float @@ -31,4 +33,8 @@ public function __toString(): string public function getTimestamp(): float { } + + public function toAmqpValue() + { + } } diff --git a/stubs/AMQPValue.php b/stubs/AMQPValue.php new file mode 100644 index 00000000..a1617127 --- /dev/null +++ b/stubs/AMQPValue.php @@ -0,0 +1,11 @@ +getExponent(), $decimal->getSignificand()); - +var_dump($decimal === $decimal->toAmqpValue()); +var_dump($decimal instanceof AMQPValue); try { new AMQPDecimal(-1, 1); @@ -49,6 +50,8 @@ var_dump(AMQPDecimal::SIGNIFICAND_MAX); --EXPECT-- int(1) int(2) +bool(true) +bool(true) Decimal exponent value must be unsigned. Decimal significand value must be unsigned. Decimal exponent value must be less than 255. diff --git a/tests/amqpqueue_setArgument.phpt b/tests/amqpqueue_setArgument.phpt index d56e3927..59df310d 100644 --- a/tests/amqpqueue_setArgument.phpt +++ b/tests/amqpqueue_setArgument.phpt @@ -26,6 +26,9 @@ $q->declareQueue(); var_dump($q); +class MyValue implements AMQPValue { + public function toAmqpValue() { return "foo"; } +} $q_dead = new AMQPQueue($ch); $q_dead->setName($q_dead_name); @@ -33,6 +36,11 @@ $q_dead->setArgument('x-dead-letter-exchange', ''); $q_dead->setArgument('x-dead-letter-routing-key', $q_name); $q_dead->setArgument('x-message-ttl', $heartbeat * 10 * 1000); $q_dead->setArgument('x-null', null); +$q_dead->setArgument('x-array', [0, 3]); +$q_dead->setArgument('x-hash', ['foo' => 'bar']); +$q_dead->setArgument('x-timestamp', new AMQPTimestamp(404)); +$q_dead->setArgument('x-decimal', new AMQPDecimal(1, 2)); +$q_dead->setArgument('x-custom-value', new MyValue()); $q_dead->setFlags(AMQP_AUTODELETE); $q_dead->declareQueue(); @@ -42,7 +50,7 @@ $q_dead->removeArgument('x-does-not-exist'); var_dump($q_dead); ?> --EXPECTF-- -object(AMQPQueue)#3 (9) { +object(AMQPQueue)#%d (%d) { ["connection":"AMQPQueue":private]=> %a ["channel":"AMQPQueue":private]=> @@ -63,7 +71,7 @@ object(AMQPQueue)#3 (9) { array(0) { } } -object(AMQPQueue)#4 (9) { +object(AMQPQueue)#%d (%d) { ["connection":"AMQPQueue":private]=> %a ["channel":"AMQPQueue":private]=> @@ -81,7 +89,7 @@ object(AMQPQueue)#4 (9) { ["autoDelete":"AMQPQueue":private]=> bool(true) ["arguments":"AMQPQueue":private]=> - array(4) { + array(%d) { ["x-dead-letter-exchange"]=> string(0) "" ["x-dead-letter-routing-key"]=> @@ -90,9 +98,36 @@ object(AMQPQueue)#4 (9) { int(100000) ["x-null"]=> NULL + ["x-array"]=> + array(2) { + [0]=> + int(0) + [1]=> + int(3) + } + ["x-hash"]=> + array(1) { + ["foo"]=> + string(3) "bar" + } + ["x-timestamp"]=> + object(AMQPTimestamp)#%d (%d) { + ["timestamp":"AMQPTimestamp":private]=> + float(404) + } + ["x-decimal"]=> + object(AMQPDecimal)#%d (%d) { + ["exponent":"AMQPDecimal":private]=> + int(1) + ["significand":"AMQPDecimal":private]=> + int(2) + } + ["x-custom-value"]=> + object(MyValue)#%d (%d) { + } } } -object(AMQPQueue)#4 (9) { +object(AMQPQueue)#%d (%d) { ["connection":"AMQPQueue":private]=> %a ["channel":"AMQPQueue":private]=> @@ -110,12 +145,39 @@ object(AMQPQueue)#4 (9) { ["autoDelete":"AMQPQueue":private]=> bool(true) ["arguments":"AMQPQueue":private]=> - array(3) { + array(%d) { ["x-dead-letter-exchange"]=> string(0) "" ["x-dead-letter-routing-key"]=> string(%d) "test.queue.%s" ["x-message-ttl"]=> int(100000) + ["x-array"]=> + array(2) { + [0]=> + int(0) + [1]=> + int(3) + } + ["x-hash"]=> + array(1) { + ["foo"]=> + string(3) "bar" + } + ["x-timestamp"]=> + object(AMQPTimestamp)#%d (%d) { + ["timestamp":"AMQPTimestamp":private]=> + float(404) + } + ["x-decimal"]=> + object(AMQPDecimal)#%d (%d) { + ["exponent":"AMQPDecimal":private]=> + int(1) + ["significand":"AMQPDecimal":private]=> + int(2) + } + ["x-custom-value"]=> + object(MyValue)#%d (%d) { + } } } diff --git a/tests/amqptimestamp.phpt b/tests/amqptimestamp.phpt index be0a7a89..f3babf28 100644 --- a/tests/amqptimestamp.phpt +++ b/tests/amqptimestamp.phpt @@ -9,6 +9,8 @@ if (!extension_loaded("amqp")) print "skip"; $timestamp = new AMQPTimestamp(100000); var_dump($timestamp->getTimestamp(), (string) $timestamp); +var_dump($timestamp === $timestamp->toAmqpValue()); +var_dump($timestamp instanceof AMQPValue); $timestamp = new AMQPTimestamp(100000.1); var_dump($timestamp->getTimestamp(), (string) $timestamp); @@ -35,6 +37,8 @@ var_dump(AMQPTimestamp::MIN); --EXPECTF-- float(100000) string(6) "100000" +bool(true) +bool(true) float(100000) string(6) "100000" The timestamp parameter must be greater than 0. diff --git a/tests/serialize-custom-amqpvalue-errors.phpt b/tests/serialize-custom-amqpvalue-errors.phpt new file mode 100644 index 00000000..e4000186 --- /dev/null +++ b/tests/serialize-custom-amqpvalue-errors.phpt @@ -0,0 +1,59 @@ +--TEST-- +Serialize custom AMQP value - errors +--SKIPIF-- + +--FILE-- +setHost(getenv('PHP_AMQP_HOST')); +$cnn->connect(); + +$ch = new AMQPChannel($cnn); + +$ex = new AMQPExchange($ch); +$ex->setName('ex-' . bin2hex(random_bytes(32))); +$ex->setType(AMQP_EX_TYPE_FANOUT); +$ex->declare(); + +class RecursiveValue implements AMQPValue { + public function toAmqpValue() + { + return $this; + } +} + +class NestedValue implements AMQPValue { + private $v; + + public function __construct($v) + { + $this->v = $v; + } + + public function toAmqpValue() + { + return $this->v; + } +} + +try { + $ex->publish('msg', null, null, ['headers' => ['x-val' => new RecursiveValue()]]); +} catch (AMQPException $e) { + var_dump($e->getMessage()); +} +$ex->publish('msg', null, null, ['headers' => ['x-val' => new NestedValue(new stdClass())]]); + +$ex->publish('msg', null, null, ['headers' => ['x-val' => new NestedValue(new NestedValue(new stdClass()))]]); + +?> +==DONE== +--EXPECTF-- +string(%d) "Maximum serialization depth of 128 reached while serializing value" + +Warning: AMQPExchange::publish(): Ignoring field 'x-val' due to unsupported value type (object) in %s on line %d + +Warning: AMQPExchange::publish(): Ignoring field 'x-val' due to unsupported value type (object) in %s on line %d +==DONE== \ No newline at end of file diff --git a/tests/serialize-custom-amqpvalue.phpt b/tests/serialize-custom-amqpvalue.phpt new file mode 100644 index 00000000..aca39792 --- /dev/null +++ b/tests/serialize-custom-amqpvalue.phpt @@ -0,0 +1,80 @@ +--TEST-- +Serialize custom AMQP value +--SKIPIF-- + +--FILE-- +setHost(getenv('PHP_AMQP_HOST')); +$cnn->connect(); + +$ch = new AMQPChannel($cnn); + +$ex = new AMQPExchange($ch); +$ex->setName('ex-' . bin2hex(random_bytes(32))); +$ex->setType(AMQP_EX_TYPE_FANOUT); +$ex->declare(); + +$q = new AMQPQueue($ch); +$q->setName('q-' . bin2hex(random_bytes(32))); +$q->declare(); +$q->bind($ex->getName()); + +class MyAmqpValue implements AMQPValue { + public function toAmqpValue() + { + return 'foo'; + } +} + +class MyNestedAmqpValue implements AMQPValue { + private $val; + public function __construct($val) { + $this->val = $val; + } + + public function toAmqpValue() { + return $this->val; + } +} + +$ex->publish('msg', null, null, ['headers' => [ + 'x-val' => new MyAmqpValue(), + 'x-nested' => new MyNestedAmqpValue(new MyAmqpValue()), + 'x-array' => [new MyNestedAmqpValue(new MyAmqpValue())], + 'x-array-nested' => new MyNestedAmqpValue([new MyNestedAmqpValue(1), 2]), + 'x-nested-decimal' => new MyNestedAmqpValue(new AMQPDecimal(1, 2345)), + 'x-nested-timestamp' => new MyNestedAmqpValue(new AMQPTimestamp(987)) +]]); + +$msg = $q->get(AMQP_AUTOACK); + +var_dump($msg->getHeader('x-val')); +var_dump($msg->getHeader('x-nested')); +var_dump($msg->getHeader('x-array')); +var_dump($msg->getHeader('x-array-nested')); +var_dump($msg->getHeader('x-nested-decimal')->getExponent()); +var_dump($msg->getHeader('x-nested-decimal')->getSignificand()); +var_dump($msg->getHeader('x-nested-timestamp')->getTimestamp()); +?> +==DONE== +--EXPECT-- +string(3) "foo" +string(3) "foo" +array(1) { + [0]=> + string(3) "foo" +} +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +int(1) +int(2345) +float(987) +==DONE== \ No newline at end of file From 0bf6b11f9a6f85cc628e74404272813ad773ec5c Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Fri, 25 Aug 2023 14:36:12 +0200 Subject: [PATCH 069/147] Use RETURN_THROWS for parameter parsing errors (#474) --- .env | 2 +- .github/workflows/test.yaml | 2 +- DEVELOPMENT.md | 16 +++++++++++++++- amqp_basic_properties.c | 2 +- amqp_channel.c | 22 +++++++++++----------- amqp_connection.c | 32 ++++++++++++++++---------------- amqp_decimal.c | 2 +- amqp_envelope.c | 4 ++-- amqp_exchange.c | 26 +++++++++++++------------- amqp_queue.c | 34 +++++++++++++++++----------------- amqp_timestamp.c | 2 +- infra/tools/pamqp-check | 12 ++++++++++++ php_amqp.h | 6 ++++++ 13 files changed, 97 insertions(+), 65 deletions(-) create mode 100755 infra/tools/pamqp-check diff --git a/.env b/.env index ee9ced65..98a8c9a6 100644 --- a/.env +++ b/.env @@ -2,6 +2,6 @@ PHP_AMQP_HOST=rabbitmq PHP_AMQP_SSL_HOST=rabbitmq.example.org MAKEFLAGS="-j16" CFLAGS="-g -O0 -fstack-protector-strong -Wall -Werror -D_GNU_SOURCE" -TEST_PHP_ARGS="-j16" +TEST_PHP_ARGS="-j16 -q" CC=clang VALGRIND_OPTS="--suppressions=infra/tools/valgrind-suppressions" diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 9003c280..7c17d14b 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -170,7 +170,7 @@ jobs: run: make test | tee result-minimal.txt env: # Reset defaults to a) only run local tests, b) don’t run memory checks as the full test suite run will do so - TEST_PHP_ARGS: -j4 + TEST_PHP_ARGS: '-j4 -q' PHP_AMQP_HOST: '' PHP_AMQP_SSL_HOST: '' diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 5fe15209..1a82e22d 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -78,15 +78,29 @@ symlink available to make that as simple as possible: cat tests/amqp_some_test.out ``` +### Run all checks locally + +Before pushing a change, run tests, lint and validate stubs, validates argument parsing, and checks formatting of both C +and PHP code: + +```commandline +pamqp-check +``` + ### Formatting Discussing coding style is as much as it is futile, so PHP AMQP using clang-format to automatically format the source -code. Run this command to format: +code. Run this command to format C code: ```commandline pamqp-format ``` +Run this to format the stubs: +```commandline +pamqp-stubs-format +``` + ### Validating stubs When PHP AMQP’s API changes, it is very important that reflection info is correct and in sync with the stubs. For that diff --git a/amqp_basic_properties.c b/amqp_basic_properties.c index d9977901..85cb77af 100644 --- a/amqp_basic_properties.c +++ b/amqp_basic_properties.c @@ -155,7 +155,7 @@ static PHP_METHOD(AMQPBasicProperties, __construct) /* s */ &cluster_id, &cluster_id_len ) == FAILURE) { - return; + RETURN_THROWS(); } zend_update_property_stringl( this_ce, diff --git a/amqp_channel.c b/amqp_channel.c index 98d48004..fddd9124 100644 --- a/amqp_channel.c +++ b/amqp_channel.c @@ -330,7 +330,7 @@ static PHP_METHOD(amqp_channel_class, __construct) "Could not create channel. No connection resource.", 0 ); - return; + RETURN_THROWS(); } if (!connection->connection_resource->is_connected) { @@ -515,7 +515,7 @@ static PHP_METHOD(amqp_channel_class, setPrefetchCount) zend_long prefetch_count; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &prefetch_count) == FAILURE) { - return; + RETURN_THROWS(); } if (!php_amqp_is_valid_prefetch_count(prefetch_count)) { @@ -603,7 +603,7 @@ static PHP_METHOD(amqp_channel_class, setPrefetchSize) zend_long prefetch_size; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &prefetch_size) == FAILURE) { - return; + RETURN_THROWS(); } if (!php_amqp_is_valid_prefetch_size(prefetch_size)) { @@ -688,7 +688,7 @@ static PHP_METHOD(amqp_channel_class, setGlobalPrefetchCount) zend_long global_prefetch_count; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &global_prefetch_count) == FAILURE) { - return; + RETURN_THROWS(); } if (!php_amqp_is_valid_prefetch_count(global_prefetch_count)) { @@ -755,7 +755,7 @@ static PHP_METHOD(amqp_channel_class, setGlobalPrefetchSize) zend_long global_prefetch_size; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &global_prefetch_size) == FAILURE) { - return; + RETURN_THROWS(); } if (!php_amqp_is_valid_prefetch_size(global_prefetch_size)) { @@ -826,7 +826,7 @@ static PHP_METHOD(amqp_channel_class, qos) bool global = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|b", &prefetch_size, &prefetch_count, &global) == FAILURE) { - return; + RETURN_THROWS(); } channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); @@ -1008,7 +1008,7 @@ static PHP_METHOD(amqp_channel_class, basicRecover) bool requeue = 1; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &requeue) == FAILURE) { - return; + RETURN_THROWS(); } channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(getThis()); @@ -1067,7 +1067,7 @@ PHP_METHOD(amqp_channel_class, setReturnCallback) zend_fcall_info_cache fcc = empty_fcall_info_cache; if (zend_parse_parameters(ZEND_NUM_ARGS(), "f!", &fci, &fcc) == FAILURE) { - return; + RETURN_THROWS(); } amqp_channel_object *channel = PHP_AMQP_GET_CHANNEL(getThis()); @@ -1098,7 +1098,7 @@ PHP_METHOD(amqp_channel_class, waitForBasicReturn) struct timeval *tv_ptr = &tv; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|d", &timeout) == FAILURE) { - return; + RETURN_THROWS(); } if (timeout < 0) { @@ -1207,7 +1207,7 @@ PHP_METHOD(amqp_channel_class, setConfirmCallback) zend_fcall_info_cache nack_fcc = empty_fcall_info_cache; if (zend_parse_parameters(ZEND_NUM_ARGS(), "f!|f!", &ack_fci, &ack_fcc, &nack_fci, &nack_fcc) == FAILURE) { - return; + RETURN_THROWS(); } amqp_channel_object *channel = PHP_AMQP_GET_CHANNEL(getThis()); @@ -1247,7 +1247,7 @@ PHP_METHOD(amqp_channel_class, waitForConfirm) struct timeval *tv_ptr = &tv; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|d", &timeout) == FAILURE) { - return; + RETURN_THROWS(); } if (timeout < 0) { diff --git a/amqp_connection.c b/amqp_connection.c index 443329a7..6b0a3018 100644 --- a/amqp_connection.c +++ b/amqp_connection.c @@ -361,7 +361,7 @@ static PHP_METHOD(amqp_connection_class, __construct) /* Parse out the method parameters */ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|a/", &ini_arr) == FAILURE) { - return; + RETURN_THROWS(); } /* Pull the login out of the $params array */ @@ -1048,7 +1048,7 @@ static PHP_METHOD(amqp_connection_class, setLogin) /* Get the login from the method params */ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &login, &login_len) == FAILURE) { - return; + RETURN_THROWS(); } /* Validate login length */ @@ -1086,7 +1086,7 @@ static PHP_METHOD(amqp_connection_class, setPassword) /* Get the password from the method params */ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &password, &password_len) == FAILURE) { - return; + RETURN_THROWS(); } /* Validate password length */ @@ -1131,7 +1131,7 @@ static PHP_METHOD(amqp_connection_class, setHost) /* Get the host from the method params */ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &host, &host_len) == FAILURE) { - return; + RETURN_THROWS(); } /* Validate host length */ @@ -1169,7 +1169,7 @@ static PHP_METHOD(amqp_connection_class, setPort) /* Get the port from the method params */ if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &port) == FAILURE) { - return; + RETURN_THROWS(); } /* Check the port value */ @@ -1207,7 +1207,7 @@ static PHP_METHOD(amqp_connection_class, setVhost) size_t vhost_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &vhost, &vhost_len) == FAILURE) { - return; + RETURN_THROWS(); } /* Validate vhost length */ @@ -1259,7 +1259,7 @@ static PHP_METHOD(amqp_connection_class, setTimeout) /* Get the timeout from the method params */ if (zend_parse_parameters(ZEND_NUM_ARGS(), "d", &read_timeout) == FAILURE) { - return; + RETURN_THROWS(); } /* Validate timeout */ @@ -1307,7 +1307,7 @@ static PHP_METHOD(amqp_connection_class, setReadTimeout) /* Get the timeout from the method params */ if (zend_parse_parameters(ZEND_NUM_ARGS(), "d", &read_timeout) == FAILURE) { - return; + RETURN_THROWS(); } /* Validate timeout */ @@ -1355,7 +1355,7 @@ static PHP_METHOD(amqp_connection_class, setWriteTimeout) /* Get the timeout from the method params */ if (zend_parse_parameters(ZEND_NUM_ARGS(), "d", &write_timeout) == FAILURE) { - return; + RETURN_THROWS(); } /* Validate timeout */ @@ -1413,7 +1413,7 @@ static PHP_METHOD(amqp_connection_class, setRpcTimeout) /* Get the timeout from the method params */ if (zend_parse_parameters(ZEND_NUM_ARGS(), "d", &rpc_timeout) == FAILURE) { - return; + RETURN_THROWS(); } /* Validate timeout */ @@ -1555,7 +1555,7 @@ static PHP_METHOD(amqp_connection_class, setCACert) size_t str_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &str, &str_len) == FAILURE) { - return; + RETURN_THROWS(); } if (str == NULL) { @@ -1582,7 +1582,7 @@ static PHP_METHOD(amqp_connection_class, setCert) size_t str_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &str, &str_len) == FAILURE) { - return; + RETURN_THROWS(); } if (str == NULL) { @@ -1609,7 +1609,7 @@ static PHP_METHOD(amqp_connection_class, setKey) size_t str_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &str, &str_len) == FAILURE) { - return; + RETURN_THROWS(); } if (str == NULL) { @@ -1636,7 +1636,7 @@ static PHP_METHOD(amqp_connection_class, setVerify) bool verify = 1; if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &verify) == FAILURE) { - return; + RETURN_THROWS(); } zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("verify"), verify); @@ -1661,7 +1661,7 @@ static PHP_METHOD(amqp_connection_class, setSaslMethod) /* Get the port from the method params */ if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &method) == FAILURE) { - return; + RETURN_THROWS(); } /* Check the method value */ @@ -1694,7 +1694,7 @@ static PHP_METHOD(amqp_connection_class, setConnectionName) size_t str_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &str, &str_len) == FAILURE) { - return; + RETURN_THROWS(); } if (str == NULL) { zend_update_property_null(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("connectionName")); diff --git a/amqp_decimal.c b/amqp_decimal.c index 591cc0bf..ee0dbe9b 100644 --- a/amqp_decimal.c +++ b/amqp_decimal.c @@ -45,7 +45,7 @@ static PHP_METHOD(amqp_decimal_class, __construct) zend_long exponent, significand; if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &exponent, &significand) == FAILURE) { - return; + RETURN_THROWS(); } if (exponent < AMQP_DECIMAL_EXPONENT_MIN) { diff --git a/amqp_envelope.c b/amqp_envelope.c index 43c1ea63..f1ca4c2c 100644 --- a/amqp_envelope.c +++ b/amqp_envelope.c @@ -199,7 +199,7 @@ static PHP_METHOD(amqp_envelope_class, getHeader) zval *tmp = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &key, &key_len) == FAILURE) { - return; + RETURN_THROWS(); } zval *zv = PHP_AMQP_READ_THIS_PROP_CE("headers", amqp_basic_properties_class_entry); @@ -223,7 +223,7 @@ static PHP_METHOD(amqp_envelope_class, hasHeader) size_t key_len; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &key, &key_len) == FAILURE) { - return; + RETURN_THROWS(); } zval *zv = PHP_AMQP_READ_THIS_PROP_CE("headers", amqp_basic_properties_class_entry); diff --git a/amqp_exchange.c b/amqp_exchange.c index 6a31b083..314a15dc 100644 --- a/amqp_exchange.c +++ b/amqp_exchange.c @@ -73,7 +73,7 @@ static PHP_METHOD(amqp_exchange_class, __construct) amqp_channel_resource *channel_resource; if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &channelObj, amqp_channel_class_entry) == FAILURE) { - return; + RETURN_THROWS(); } ZVAL_UNDEF(&arguments); @@ -120,7 +120,7 @@ static PHP_METHOD(amqp_exchange_class, setName) size_t name_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &name, &name_len) == FAILURE) { - return; + RETURN_THROWS(); } /* Verify that the name is not null and not an empty string */ @@ -178,7 +178,7 @@ static PHP_METHOD(amqp_exchange_class, setFlags) bool flags_is_null = 1; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l!", &flags, &flags_is_null) == FAILURE) { - return; + RETURN_THROWS(); } flags = flags & PHP_AMQP_EXCHANGE_FLAGS; @@ -216,7 +216,7 @@ static PHP_METHOD(amqp_exchange_class, setType) size_t type_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &type, &type_len) == FAILURE) { - return; + RETURN_THROWS(); } zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("type"), type, type_len); @@ -236,7 +236,7 @@ static PHP_METHOD(amqp_exchange_class, getArgument) size_t key_len; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &key, &key_len) == FAILURE) { - return; + RETURN_THROWS(); } if ((tmp = zend_hash_str_find(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len)) == NULL) { @@ -256,7 +256,7 @@ static PHP_METHOD(amqp_exchange_class, hasArgument) size_t key_len; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &key, &key_len) == FAILURE) { - return; + RETURN_THROWS(); } RETURN_BOOL(zend_hash_str_find(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len) != NULL); @@ -281,7 +281,7 @@ static PHP_METHOD(amqp_exchange_class, setArguments) zval *zvalArguments; if (zend_parse_parameters(ZEND_NUM_ARGS(), "a/", &zvalArguments) == FAILURE) { - return; + RETURN_THROWS(); } zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("arguments"), zvalArguments); @@ -299,7 +299,7 @@ static PHP_METHOD(amqp_exchange_class, setArgument) zval *value = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz", &key, &key_len, &value) == FAILURE) { - return; + RETURN_THROWS(); } switch (Z_TYPE_P(value)) { @@ -333,7 +333,7 @@ static PHP_METHOD(amqp_exchange_class, removeArgument) size_t key_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &key, &key_len) == FAILURE) { - return; + RETURN_THROWS(); } zend_hash_str_del(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len); @@ -417,7 +417,7 @@ static PHP_METHOD(amqp_exchange_class, delete) bool flags_is_null = 1; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!l!", &name, &name_len, &flags, &flags_is_null) == FAILURE) { - return; + RETURN_THROWS(); } channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); @@ -484,7 +484,7 @@ static PHP_METHOD(amqp_exchange_class, publish) &flags_is_null, &ini_arr ) == FAILURE) { - return; + RETURN_THROWS(); } /* By default (and for BC) content type is text/plain (may be skipped at all, then set props._flags to 0) */ @@ -701,7 +701,7 @@ static PHP_METHOD(amqp_exchange_class, bind) &keyname_len, &zvalArguments ) == FAILURE) { - return; + RETURN_THROWS(); } channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); @@ -763,7 +763,7 @@ static PHP_METHOD(amqp_exchange_class, unbind) &keyname_len, &zvalArguments ) == FAILURE) { - return; + RETURN_THROWS(); } channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); diff --git a/amqp_queue.c b/amqp_queue.c index 31428e50..3b886f32 100644 --- a/amqp_queue.c +++ b/amqp_queue.c @@ -83,7 +83,7 @@ static PHP_METHOD(amqp_queue_class, __construct) amqp_channel_resource *channel_resource; if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &channelObj, amqp_channel_class_entry) == FAILURE) { - return; + RETURN_THROWS(); } ZVAL_UNDEF(&arguments); @@ -130,7 +130,7 @@ static PHP_METHOD(amqp_queue_class, setName) size_t name_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) { - return; + RETURN_THROWS(); } if (name_len < 1 || name_len > 255) { @@ -188,7 +188,7 @@ static PHP_METHOD(amqp_queue_class, setFlags) bool flags_is_null = 1; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l!", &flags, &flags_is_null) == FAILURE) { - return; + RETURN_THROWS(); } flags = flags & PHP_AMQP_QUEUE_FLAGS; @@ -211,7 +211,7 @@ static PHP_METHOD(amqp_queue_class, getArgument) size_t key_len; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &key, &key_len) == FAILURE) { - return; + RETURN_THROWS(); } if ((tmp = zend_hash_str_find(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len)) == NULL) { @@ -232,7 +232,7 @@ static PHP_METHOD(amqp_queue_class, hasArgument) size_t key_len; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &key, &key_len) == FAILURE) { - return; + RETURN_THROWS(); } RETURN_BOOL(zend_hash_str_find(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len) != NULL); @@ -257,7 +257,7 @@ static PHP_METHOD(amqp_queue_class, setArguments) zval *zvalArguments; if (zend_parse_parameters(ZEND_NUM_ARGS(), "a/", &zvalArguments) == FAILURE) { - return; + RETURN_THROWS(); } zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("arguments"), zvalArguments); @@ -276,7 +276,7 @@ static PHP_METHOD(amqp_queue_class, setArgument) zval *value = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz", &key, &key_len, &value) == FAILURE) { - return; + RETURN_THROWS(); } switch (Z_TYPE_P(value)) { @@ -321,7 +321,7 @@ static PHP_METHOD(amqp_queue_class, removeArgument) size_t key_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &key, &key_len) == FAILURE) { - return; + RETURN_THROWS(); } zend_hash_str_del_ind(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len); @@ -417,7 +417,7 @@ static PHP_METHOD(amqp_queue_class, bind) &keyname_len, &zvalArguments ) == FAILURE) { - return; + RETURN_THROWS(); } channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); @@ -469,7 +469,7 @@ static PHP_METHOD(amqp_queue_class, get) bool flags_is_null = 1; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!", &flags, &flags_is_null) == FAILURE) { - return; + RETURN_THROWS(); } channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); @@ -570,7 +570,7 @@ static PHP_METHOD(amqp_queue_class, consume) &consumer_tag, &consumer_tag_len ) == FAILURE) { - return; + RETURN_THROWS(); } zval *channel_zv = PHP_AMQP_READ_THIS_PROP("channel"); @@ -838,7 +838,7 @@ static PHP_METHOD(amqp_queue_class, ack) bool flags_is_null = 1; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l!", &deliveryTag, &flags, &flags_is_null) == FAILURE) { - return; + RETURN_THROWS(); } channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); @@ -887,7 +887,7 @@ static PHP_METHOD(amqp_queue_class, nack) bool flags_is_null = 1; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l!", &deliveryTag, &flags, &flags_is_null) == FAILURE) { - return; + RETURN_THROWS(); } channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); @@ -937,7 +937,7 @@ static PHP_METHOD(amqp_queue_class, reject) bool flags_is_null = 1; if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l!", &deliveryTag, &flags, &flags_is_null) == FAILURE) { - return; + RETURN_THROWS(); } channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); @@ -1027,7 +1027,7 @@ static PHP_METHOD(amqp_queue_class, cancel) size_t consumer_tag_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &consumer_tag, &consumer_tag_len) == FAILURE) { - return; + RETURN_THROWS(); } zval *channel_zv = PHP_AMQP_READ_THIS_PROP("channel"); @@ -1111,7 +1111,7 @@ static PHP_METHOD(amqp_queue_class, unbind) &keyname_len, &zvalArguments ) == FAILURE) { - return; + RETURN_THROWS(); } channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); @@ -1162,7 +1162,7 @@ static PHP_METHOD(amqp_queue_class, delete) zend_long message_count; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!", &flags, &flags_is_null) == FAILURE) { - return; + RETURN_THROWS(); } channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(PHP_AMQP_READ_THIS_PROP("channel")); diff --git a/amqp_timestamp.c b/amqp_timestamp.c index 4256b314..2a426ed4 100644 --- a/amqp_timestamp.c +++ b/amqp_timestamp.c @@ -43,7 +43,7 @@ static PHP_METHOD(amqp_timestamp_class, __construct) double timestamp; if (zend_parse_parameters(ZEND_NUM_ARGS(), "d", ×tamp) == FAILURE) { - return; + RETURN_THROWS(); } if (timestamp < AMQP_TIMESTAMP_MIN) { diff --git a/infra/tools/pamqp-check b/infra/tools/pamqp-check new file mode 100755 index 00000000..a09d791b --- /dev/null +++ b/infra/tools/pamqp-check @@ -0,0 +1,12 @@ +#!/usr/bin/env sh + +set -o errexit +set -o nounset + +make test +pamqp-stubs-lint +pamqp-stubs-validate +php -d extension=modules/amqp.so $(which pamqp-arguments-validate) + +pamqp-format-check +pamqp-stubs-format-check diff --git a/php_amqp.h b/php_amqp.h index 1ac2144b..0fcdd7d6 100644 --- a/php_amqp.h +++ b/php_amqp.h @@ -73,6 +73,12 @@ extern zend_module_entry amqp_module_entry; ZEND_ARG_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) #define PHP_AMQP_DECLARE_PROPERTY_TYPE(type, nullable) ZEND_TYPE_ENCODE(type, nullable) #define PHP_AMQP_DECLARE_PROPERTY_OBJ_TYPE(class_name, nullable) ZEND_TYPE_ENCODE_CLASS(class_name, nullable) + #define RETURN_THROWS() \ + do { \ + ZEND_ASSERT(EG(exception)); \ + (void) return_value; \ + return; \ + } while (0) #endif #if PHP_VERSION_ID < 80200 #define zend_ini_parse_quantity_warn(v, name) (zend_atol(ZSTR_VAL(v), ZSTR_LEN(v))) From 877b2f41a11b10f3588d397f59d9804be5765d9a Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Fri, 25 Aug 2023 14:55:51 +0200 Subject: [PATCH 070/147] Fix auto-formatting --- .clang-format | 3 ++- amqp_value.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.clang-format b/.clang-format index 86a24b08..adc0bce2 100644 --- a/.clang-format +++ b/.clang-format @@ -23,8 +23,9 @@ BreakBeforeBraces: Custom MacroBlockBegin: "(ZEND_BEGIN_ARG_(INFO|WITH_RETURN_(TYPE|OBJ)_INFO)(_EX)?|PHP_INI_BEGIN)" MacroBlockEnd: "(ZEND_END_ARG_INFO|PHP_INI_END)" Macros: - - "PHP_ME(a, b, c, d)={a, b, c, d}," + - "PHP_ME(a, b, c, d)={a, b, c, d, e}," - "PHP_MALIAS(a, b, c, d, e)={a, b, c, d, e}," + - "PHP_ABSTRACT_ME(a, b, c)={a, b, c, d, e}," - "ZEND_HASH_FOREACH_KEY_VAL(a, b, c, d)=do {" - "ZEND_HASH_FOREACH_STR_KEY(a, b)=do {" - "ZEND_HASH_FOREACH_STR_KEY_VAL(a, b, c)=do {" diff --git a/amqp_value.c b/amqp_value.c index 47e2ae5e..7e2c9bc4 100644 --- a/amqp_value.c +++ b/amqp_value.c @@ -35,7 +35,7 @@ ZEND_END_ARG_INFO() zend_function_entry amqp_value_class_functions[] = { PHP_ABSTRACT_ME(amqp_value_class, toAmqpValue, arginfo_amqp_value_class_toAmqpValue) - {NULL, NULL, NULL} + {NULL, NULL, NULL} }; PHP_MINIT_FUNCTION(amqp_value) From e339a5fbabeec5cf8508990f67fc883911d8d30a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 27 Aug 2023 01:31:15 +0200 Subject: [PATCH 071/147] Bump actions/checkout from 3.5.3 to 3.6.0 (#475) --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 7c17d14b..3f77d4f9 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -30,7 +30,7 @@ jobs: concurrent_skipping: 'same_content_newer' - name: Checkout - uses: actions/checkout@v3.5.3 + uses: actions/checkout@v3.6.0 - name: Prepare matrix id: matrix From 949e82cdba7660a71ce875f4c476e543c7eb96dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pracha=C5=99?= Date: Wed, 6 Sep 2023 10:44:30 +0200 Subject: [PATCH 072/147] Fix double free when an error occurs in AMQPQueue::consume() (#482) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The envolope should not be used unless amqp_consume_message() replies with AMQP_RESPONSE_NORMAL. See https://github.com/alanxz/rabbitmq-c/blob/9a91cf59760471b49307535d839d38d6c9a08d66/librabbitmq/amqp_consumer.c#L162 Signed-off-by: Jan Prachař --- amqp_queue.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/amqp_queue.c b/amqp_queue.c index 3b886f32..593cdb26 100644 --- a/amqp_queue.c +++ b/amqp_queue.c @@ -681,16 +681,14 @@ static PHP_METHOD(amqp_queue_class, consume) if (AMQP_RESPONSE_LIBRARY_EXCEPTION == res.reply_type && AMQP_STATUS_TIMEOUT == res.library_error) { zend_throw_exception(amqp_queue_exception_class_entry, "Consumer timeout exceed", 0); - amqp_destroy_envelope(&envelope); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; } - if (PHP_AMQP_MAYBE_ERROR_RECOVERABLE(res, channel_resource)) { + if (AMQP_RESPONSE_NORMAL != res.reply_type) { if (PHP_AMQP_IS_ERROR_RECOVERABLE(res, channel_resource, channel)) { /* In case no message was received, continue the loop */ - amqp_destroy_envelope(&envelope); continue; } else { @@ -703,7 +701,6 @@ static PHP_METHOD(amqp_queue_class, consume) php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry); - amqp_destroy_envelope(&envelope); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; From 466c5d13fb7753a09bab3e94bafa5a91bafb3da4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 6 Sep 2023 10:49:08 +0200 Subject: [PATCH 073/147] Bump actions/checkout from 3.6.0 to 4.0.0 (#481) --- .github/workflows/test.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 3f77d4f9..8c10b6d6 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -30,7 +30,7 @@ jobs: concurrent_skipping: 'same_content_newer' - name: Checkout - uses: actions/checkout@v3.6.0 + uses: actions/checkout@v4.0.0 - name: Prepare matrix id: matrix @@ -53,7 +53,7 @@ jobs: install: clang-format-17 - name: Checkout - uses: actions/checkout@v3.6.0 + uses: actions/checkout@v4.0.0 - name: Check style run: ./infra/tools/pamqp-format-check @@ -71,7 +71,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3.6.0 + uses: actions/checkout@v4.0.0 - name: Install packages uses: awalsh128/cache-apt-pkgs-action@v1.3.0 @@ -130,7 +130,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3.6.0 + uses: actions/checkout@v4.0.0 - name: Configure hostnames run: sudo echo "127.0.0.1 ${{ env.PHP_AMQP_SSL_HOST }}" | sudo tee -a /etc/hosts From 11d642b7177ca4194ff358c8d17f89cb064d8faa Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 6 Sep 2023 11:54:49 +0200 Subject: [PATCH 074/147] Refactor AMQPQueue::consume error handling (#483) --- amqp_channel.c | 32 +++------------------- amqp_connection_resource.c | 29 ++++++++++---------- amqp_connection_resource.h | 8 +----- amqp_methods_handling.c | 55 +++++++++++++++----------------------- amqp_methods_handling.h | 24 +++-------------- amqp_queue.c | 38 +++++++++++++------------- php_amqp.h | 20 -------------- 7 files changed, 64 insertions(+), 142 deletions(-) diff --git a/amqp_channel.c b/amqp_channel.c index fddd9124..53eca3b1 100644 --- a/amqp_channel.c +++ b/amqp_channel.c @@ -1162,13 +1162,7 @@ PHP_METHOD(amqp_channel_class, waitForBasicReturn) return; } - status = php_amqp_handle_basic_return( - &PHP_AMQP_G(error_message), - channel_resource->connection_resource, - channel_resource->channel_id, - channel, - &method - ); + status = php_amqp_handle_basic_return(&PHP_AMQP_G(error_message), channel, &method); if (PHP_AMQP_RESOURCE_RESPONSE_BREAK == status) { php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); @@ -1317,31 +1311,13 @@ PHP_METHOD(amqp_channel_class, waitForConfirm) switch (method.id) { case AMQP_BASIC_ACK_METHOD: - status = php_amqp_handle_basic_ack( - &PHP_AMQP_G(error_message), - channel_resource->connection_resource, - channel_resource->channel_id, - channel, - &method - ); + status = php_amqp_handle_basic_ack(&PHP_AMQP_G(error_message), channel, &method); break; case AMQP_BASIC_NACK_METHOD: - status = php_amqp_handle_basic_nack( - &PHP_AMQP_G(error_message), - channel_resource->connection_resource, - channel_resource->channel_id, - channel, - &method - ); + status = php_amqp_handle_basic_nack(&PHP_AMQP_G(error_message), channel, &method); break; case AMQP_BASIC_RETURN_METHOD: - status = php_amqp_handle_basic_return( - &PHP_AMQP_G(error_message), - channel_resource->connection_resource, - channel_resource->channel_id, - channel, - &method - ); + status = php_amqp_handle_basic_return(&PHP_AMQP_G(error_message), channel, &method); break; default: status = AMQP_STATUS_WRONG_METHOD; diff --git a/amqp_connection_resource.c b/amqp_connection_resource.c index 9ae6a549..e617ead2 100644 --- a/amqp_connection_resource.c +++ b/amqp_connection_resource.c @@ -234,13 +234,7 @@ static void php_amqp_close_channel_from_server( } -int php_amqp_connection_resource_error_advanced( - amqp_rpc_reply_t reply, - char **message, - amqp_connection_resource *resource, - amqp_channel_t channel_id, - amqp_channel_object *channel -) +int php_amqp_connection_resource_error_advanced(amqp_rpc_reply_t reply, char **message, amqp_channel_object *channel) { assert(resource != NULL); @@ -249,7 +243,9 @@ int php_amqp_connection_resource_error_advanced( assert(AMQP_RESPONSE_LIBRARY_EXCEPTION == reply.reply_type); assert(AMQP_STATUS_UNEXPECTED_STATE == reply.library_error); - if (channel_id < 0 || AMQP_STATUS_OK != amqp_simple_wait_frame(resource->connection_state, &frame)) { + if (channel->channel_resource->channel_id < 0 || + AMQP_STATUS_OK != + amqp_simple_wait_frame(channel->channel_resource->connection_resource->connection_state, &frame)) { if (*message != NULL) { efree(*message); } @@ -258,7 +254,7 @@ int php_amqp_connection_resource_error_advanced( return PHP_AMQP_RESOURCE_RESPONSE_ERROR; } - if (channel_id != frame.channel) { + if (channel->channel_resource->channel_id != frame.channel) { spprintf(message, 0, "Library error: channel mismatch"); return PHP_AMQP_RESOURCE_RESPONSE_ERROR; } @@ -266,11 +262,16 @@ int php_amqp_connection_resource_error_advanced( if (AMQP_FRAME_METHOD == frame.frame_type) { switch (frame.payload.method.id) { case AMQP_CONNECTION_CLOSE_METHOD: { - php_amqp_close_connection_from_server(reply, message, resource); + php_amqp_close_connection_from_server(reply, message, channel->channel_resource->connection_resource); return PHP_AMQP_RESOURCE_RESPONSE_ERROR_CONNECTION_CLOSED; } case AMQP_CHANNEL_CLOSE_METHOD: { - php_amqp_close_channel_from_server(reply, message, resource, channel_id); + php_amqp_close_channel_from_server( + reply, + message, + channel->channel_resource->connection_resource, + channel->channel_resource->channel_id + ); return PHP_AMQP_RESOURCE_RESPONSE_ERROR_CHANNEL_CLOSED; } @@ -279,19 +280,19 @@ int php_amqp_connection_resource_error_advanced( * here is a message being confirmed */ - return php_amqp_handle_basic_ack(message, resource, channel_id, channel, &frame.payload.method); + return php_amqp_handle_basic_ack(message, channel, &frame.payload.method); case AMQP_BASIC_NACK_METHOD: /* if we've turned publisher confirms on, and we've published a message * here is a message being confirmed */ - return php_amqp_handle_basic_nack(message, resource, channel_id, channel, &frame.payload.method); + return php_amqp_handle_basic_nack(message, channel, &frame.payload.method); case AMQP_BASIC_RETURN_METHOD: /* if a published message couldn't be routed and the mandatory flag was set * this is what would be returned. The message then needs to be read. */ - return php_amqp_handle_basic_return(message, resource, channel_id, channel, &frame.payload.method); + return php_amqp_handle_basic_return(message, channel, &frame.payload.method); default: if (*message != NULL) { efree(*message); diff --git a/amqp_connection_resource.h b/amqp_connection_resource.h index 45f0b114..c685e75b 100644 --- a/amqp_connection_resource.h +++ b/amqp_connection_resource.h @@ -69,13 +69,7 @@ int php_amqp_connection_resource_error( amqp_connection_resource *resource, amqp_channel_t channel_id ); -int php_amqp_connection_resource_error_advanced( - amqp_rpc_reply_t reply, - char **message, - amqp_connection_resource *resource, - amqp_channel_t channel_id, - amqp_channel_object *channel -); +int php_amqp_connection_resource_error_advanced(amqp_rpc_reply_t reply, char **message, amqp_channel_object *channel); /* Socket-related functions */ int php_amqp_set_resource_read_timeout(amqp_connection_resource *resource, double read_timeout); diff --git a/amqp_methods_handling.c b/amqp_methods_handling.c index ead7dbff..8091c0a2 100644 --- a/amqp_methods_handling.c +++ b/amqp_methods_handling.c @@ -87,13 +87,7 @@ int amqp_simple_wait_method_noblock( } -int php_amqp_handle_basic_return( - char **message, - amqp_connection_resource *resource, - amqp_channel_t channel_id, - amqp_channel_object *channel, - amqp_method_t *method -) +int php_amqp_handle_basic_return(char **message, amqp_channel_object *channel, amqp_method_t *method) { amqp_rpc_reply_t ret; amqp_message_t msg; @@ -103,10 +97,20 @@ int php_amqp_handle_basic_return( amqp_basic_return_t *m = (amqp_basic_return_t *) method->decoded; - ret = amqp_read_message(resource->connection_state, channel_id, &msg, 0); + ret = amqp_read_message( + channel->channel_resource->connection_resource->connection_state, + channel->channel_resource->channel_id, + &msg, + 0 + ); if (AMQP_RESPONSE_NORMAL != ret.reply_type) { - return php_amqp_connection_resource_error(ret, message, resource, channel_id); + return php_amqp_connection_resource_error( + ret, + message, + channel->channel_resource->connection_resource, + channel->channel_resource->channel_id + ); } if (channel->callbacks.basic_return.fci.size > 0) { @@ -156,31 +160,22 @@ int php_amqp_call_basic_return_callback(amqp_basic_return_t *m, amqp_message_t * return status; } -int php_amqp_handle_basic_ack( - char **message, - amqp_connection_resource *resource, - amqp_channel_t channel_id, - amqp_channel_object *channel, - amqp_method_t *method -) +int php_amqp_handle_basic_ack(char **message, amqp_channel_object *channel, amqp_method_t *method) { - int status = PHP_AMQP_RESOURCE_RESPONSE_OK; - assert(AMQP_BASIC_ACK_METHOD == method->id); amqp_basic_ack_t *m = (amqp_basic_ack_t *) method->decoded; if (channel->callbacks.basic_ack.fci.size > 0) { - status = php_amqp_call_basic_ack_callback(m, &channel->callbacks.basic_ack); - } else { - zend_error( - E_NOTICE, - "Unhandled basic.ack method from server received. Use AMQPChannel::setConfirmCallback() to process it." - ); - status = PHP_AMQP_RESOURCE_RESPONSE_BREAK; + return php_amqp_call_basic_ack_callback(m, &channel->callbacks.basic_ack); } - return status; + zend_error( + E_NOTICE, + "Unhandled basic.ack method from server received. Use AMQPChannel::setConfirmCallback() to process it." + ); + + return PHP_AMQP_RESOURCE_RESPONSE_BREAK; } int php_amqp_call_basic_ack_callback(amqp_basic_ack_t *m, amqp_callback_bucket *cb) @@ -197,13 +192,7 @@ int php_amqp_call_basic_ack_callback(amqp_basic_ack_t *m, amqp_callback_bucket * return php_amqp_call_callback_with_params(params, cb); } -int php_amqp_handle_basic_nack( - char **message, - amqp_connection_resource *resource, - amqp_channel_t channel_id, - amqp_channel_object *channel, - amqp_method_t *method -) +int php_amqp_handle_basic_nack(char **message, amqp_channel_object *channel, amqp_method_t *method) { int status = PHP_AMQP_RESOURCE_RESPONSE_OK; diff --git a/amqp_methods_handling.h b/amqp_methods_handling.h index fe69ea07..d081ffa6 100644 --- a/amqp_methods_handling.h +++ b/amqp_methods_handling.h @@ -50,30 +50,12 @@ int amqp_simple_wait_method_noblock( int php_amqp_call_callback_with_params(zval params, amqp_callback_bucket *cb); int php_amqp_call_basic_return_callback(amqp_basic_return_t *m, amqp_message_t *msg, amqp_callback_bucket *cb); -int php_amqp_handle_basic_return( - char **message, - amqp_connection_resource *resource, - amqp_channel_t channel_id, - amqp_channel_object *channel, - amqp_method_t *method -); +int php_amqp_handle_basic_return(char **message, amqp_channel_object *channel, amqp_method_t *method); int php_amqp_call_basic_ack_callback(amqp_basic_ack_t *m, amqp_callback_bucket *cb); -int php_amqp_handle_basic_ack( - char **message, - amqp_connection_resource *resource, - amqp_channel_t channel_id, - amqp_channel_object *channel, - amqp_method_t *method -); +int php_amqp_handle_basic_ack(char **message, amqp_channel_object *channel, amqp_method_t *method); int php_amqp_call_basic_nack_callback(amqp_basic_nack_t *m, amqp_callback_bucket *cb); -int php_amqp_handle_basic_nack( - char **message, - amqp_connection_resource *resource, - amqp_channel_t channel_id, - amqp_channel_object *channel, - amqp_method_t *method -); +int php_amqp_handle_basic_nack(char **message, amqp_channel_object *channel, amqp_method_t *method); #endif diff --git a/amqp_queue.c b/amqp_queue.c index 593cdb26..364a8682 100644 --- a/amqp_queue.c +++ b/amqp_queue.c @@ -592,7 +592,7 @@ static PHP_METHOD(amqp_queue_class, consume) PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not get channel."); if (!(AMQP_JUST_CONSUME & flags)) { - /* Setup the consume */ + /* Set up the consume loop */ arguments = php_amqp_type_convert_zval_to_amqp_table(PHP_AMQP_READ_THIS_PROP("arguments")); amqp_basic_consume_ok_t *r = amqp_basic_consume( @@ -678,29 +678,29 @@ static PHP_METHOD(amqp_queue_class, consume) amqp_rpc_reply_t res = amqp_consume_message(channel_resource->connection_resource->connection_state, &envelope, tv_ptr, 0); - if (AMQP_RESPONSE_LIBRARY_EXCEPTION == res.reply_type && AMQP_STATUS_TIMEOUT == res.library_error) { - zend_throw_exception(amqp_queue_exception_class_entry, "Consumer timeout exceed", 0); - - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; - } - if (AMQP_RESPONSE_NORMAL != res.reply_type) { - if (PHP_AMQP_IS_ERROR_RECOVERABLE(res, channel_resource, channel)) { - /* In case no message was received, continue the loop */ - - continue; - } else { - /* Mark connection resource as closed to prevent sending any further requests */ - channel_resource->connection_resource->is_connected = '\0'; - - /* Close connection with all its channels */ - php_amqp_disconnect_force(channel_resource->connection_resource); + if (AMQP_RESPONSE_LIBRARY_EXCEPTION == res.reply_type) { + + // Special case consumer timeout: do not close connection but end consumption + if (AMQP_STATUS_TIMEOUT == res.library_error) { + zend_throw_exception(amqp_queue_exception_class_entry, "Consumer timeout exceed", 0); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } + + // Handle a potentially recoverable error + if (AMQP_STATUS_UNEXPECTED_STATE == res.library_error && + PHP_AMQP_RESOURCE_RESPONSE_OK <= + php_amqp_connection_resource_error_advanced(res, &PHP_AMQP_G(error_message), channel)) { + continue; + } } + /* Mark connection resource as closed to prevent sending any further requests */ + channel_resource->connection_resource->is_connected = '\0'; + php_amqp_disconnect_force(channel_resource->connection_resource); php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry); - php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; diff --git a/php_amqp.h b/php_amqp.h index 0fcdd7d6..03337a68 100644 --- a/php_amqp.h +++ b/php_amqp.h @@ -372,26 +372,6 @@ static inline amqp_channel_object *php_amqp_channel_object_fetch(zend_object *ob PHP_AMQP_RESOURCE_RESPONSE_OK != \ php_amqp_error(res, &PHP_AMQP_G(error_message), (channel_resource)->connection_resource, (channel_resource))) -#define PHP_AMQP_MAYBE_ERROR_RECOVERABLE(res, channel_resource) \ - ((AMQP_RESPONSE_NORMAL != (res).reply_type) && \ - PHP_AMQP_RESOURCE_RESPONSE_OK != php_amqp_error_advanced( \ - res, \ - &PHP_AMQP_G(error_message), \ - (channel_resource)->connection_resource, \ - (channel_resource), \ - 0 \ - )) - -#define PHP_AMQP_IS_ERROR_RECOVERABLE(res, channel_resource, channel_object) \ - (AMQP_RESPONSE_LIBRARY_EXCEPTION == (res).reply_type && AMQP_STATUS_UNEXPECTED_STATE == (res).library_error && \ - (0 <= php_amqp_connection_resource_error_advanced( \ - res, \ - &PHP_AMQP_G(error_message), \ - (channel_resource)->connection_resource, \ - (amqp_channel_t) (channel_resource ? (channel_resource)->channel_id : 0), \ - (channel_object) \ - ))) - #if ZEND_MODULE_API_NO >= 20100000 #define AMQP_OBJECT_PROPERTIES_INIT(obj, ce) object_properties_init(&(obj), ce); From a1baabc95407b7366b31ce30c7c2ebe1136d947c Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 6 Sep 2023 12:39:55 +0200 Subject: [PATCH 075/147] Implement AMQPQueue::recover() to provide the basic.recover method (fixes #478) (#484) --- amqp_queue.c | 49 +++++++++++++++++++++++++++++++ stubs/AMQPQueue.php | 17 +++++++++++ tests/amqpqueue_recover.phpt | 56 ++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 tests/amqpqueue_recover.phpt diff --git a/amqp_queue.c b/amqp_queue.c index 364a8682..09c684a9 100644 --- a/amqp_queue.c +++ b/amqp_queue.c @@ -1081,6 +1081,50 @@ static PHP_METHOD(amqp_queue_class, cancel) } /* }}} */ +/* {{{ proto int AMQPQueue::recover([boolean requeue]); +recover messages already delivered to the consumer +*/ +static PHP_METHOD(amqp_queue_class, recover) +{ + zval rv; + + amqp_channel_resource *channel_resource; + + bool requeue = 1; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &requeue) == FAILURE) { + RETURN_THROWS(); + } + + zval *channel_zv = PHP_AMQP_READ_THIS_PROP("channel"); + + channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(channel_zv); + PHP_AMQP_VERIFY_CHANNEL_RESOURCE(channel_resource, "Could not recover messages."); + + amqp_basic_recover_ok_t *r = amqp_basic_recover( + channel_resource->connection_resource->connection_state, + channel_resource->channel_id, + requeue + ); + + if (!r) { + amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); + + php_amqp_error(res, &PHP_AMQP_G(error_message), channel_resource->connection_resource, channel_resource); + + php_amqp_zend_throw_exception( + res, + amqp_queue_exception_class_entry, + PHP_AMQP_G(error_message), + PHP_AMQP_G(error_code) + ); + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); + return; + } + + php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); +} +/* }}} */ /* {{{ proto int AMQPQueue::unbind(string exchangeName, [string routingKey, array arguments]); unbind queue from exchange @@ -1303,6 +1347,10 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_reject, ZEND_SE ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 1, "null") ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_recover, ZEND_SEND_BY_VAL, 0, IS_VOID, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, requeue, _IS_BOOL, 0, "true") +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_queue_class_purge, ZEND_SEND_BY_VAL, 0, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -1354,6 +1402,7 @@ zend_function_entry amqp_queue_class_functions[] = { PHP_ME(amqp_queue_class, ack, arginfo_amqp_queue_class_ack, ZEND_ACC_PUBLIC) PHP_ME(amqp_queue_class, nack, arginfo_amqp_queue_class_nack, ZEND_ACC_PUBLIC) PHP_ME(amqp_queue_class, reject, arginfo_amqp_queue_class_reject, ZEND_ACC_PUBLIC) + PHP_ME(amqp_queue_class, recover, arginfo_amqp_queue_class_recover, ZEND_ACC_PUBLIC) PHP_ME(amqp_queue_class, purge, arginfo_amqp_queue_class_purge, ZEND_ACC_PUBLIC) PHP_ME(amqp_queue_class, cancel, arginfo_amqp_queue_class_cancel, ZEND_ACC_PUBLIC) diff --git a/stubs/AMQPQueue.php b/stubs/AMQPQueue.php index d9e3bc97..bf9225ca 100644 --- a/stubs/AMQPQueue.php +++ b/stubs/AMQPQueue.php @@ -260,6 +260,23 @@ public function reject(int $deliveryTag, ?int $flags = null): void { } + /** + * Recover unacknowledged messages delivered to the current consumer. + * + * Recover all the unacknowledged messages delivered to the current consumer. + * If $requeue is true, the broker can redeliver the messages to different + * consumers. If $requeue is false, it can only redeliver it to the current + * consumer. RabbitMQ does not implement $request = false. + * This method exposes `basic.recover` from the AMQP spec. + * + * @param bool $requeue If true, deliver to any consumer, if false, deliver to the current consumer only + * @throws AMQPConnectionException If the connection to the broker was lost. + * @throws AMQPChannelException If the channel is not open. + */ + public function recover(bool $requeue = true): void + { + } + /** * Purge the contents of a queue. * diff --git a/tests/amqpqueue_recover.phpt b/tests/amqpqueue_recover.phpt new file mode 100644 index 00000000..10fd4c05 --- /dev/null +++ b/tests/amqpqueue_recover.phpt @@ -0,0 +1,56 @@ +--TEST-- +AMQPQueue::nack +--SKIPIF-- + +--FILE-- +setHost(getenv('PHP_AMQP_HOST')); +$cnn->connect(); + +$ch = new AMQPChannel($cnn); + +$ex = new AMQPExchange($ch); +$ex->setName('testrecover-' . bin2hex(random_bytes(32))); +$ex->setType(AMQP_EX_TYPE_FANOUT); +$ex->declareExchange(); +$exchangeName = $ex->getName(); + +$q = new AMQPQueue($ch); +$q->setName('testrecover-' . bin2hex(random_bytes(32))); +$q->declareQueue(); +$q->bind($exchangeName); + +$ex->publish('message'); + +function inspectMessage(AMQPQueue $q) { + $msg = $q->get(); + echo $msg->getBody(), PHP_EOL; + echo $msg->isRedelivery() ? 'true' : 'false'; + echo PHP_EOL; +} + +inspectMessage($q); +$q->recover(); + +inspectMessage($q); +$q->recover(true); + +inspectMessage($q); + +try { + $q->recover(false); +} catch (AMQPConnectionException $e) { + echo $e->getMessage(), PHP_EOL; +} +--EXPECT-- +message +false +message +true +message +true +Server connection error: 540, message: NOT_IMPLEMENTED - requeue=false From b732f78426ae6d9b424a7c9262f995308bd9c8fe Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 6 Sep 2023 14:04:00 +0200 Subject: [PATCH 076/147] Revamp error handling (#485) --- amqp.c | 15 +++++++++++++-- amqp_connection_resource.c | 19 +++++++------------ .../amqpconnection_connect_login_failure.phpt | 4 +--- tests/amqpconnection_heartbeat.phpt | 6 ++---- ...pconnection_heartbeat_with_persistent.phpt | 6 ++---- ...h_mandatory_multiple_channels_pitfall.phpt | 2 +- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/amqp.c b/amqp.c index d8cbcac4..ef04488d 100644 --- a/amqp.c +++ b/amqp.c @@ -443,7 +443,7 @@ int php_amqp_error_advanced( break; } /* Library or other non-protocol or even protocol related errors may be here. */ - /* In most cases it designate some underlying hard errors. Fail fast. */ + /* In most cases it indicates some underlying hard errors. Fail fast. */ case PHP_AMQP_RESOURCE_RESPONSE_ERROR_CONNECTION_CLOSED: /* Mark connection resource as closed to prevent sending any further requests */ connection_resource->is_connected = '\0'; @@ -490,7 +490,18 @@ void php_amqp_zend_throw_exception( exception_ce = amqp_exception_class_entry; break; case AMQP_RESPONSE_LIBRARY_EXCEPTION: - exception_ce = amqp_exception_class_entry; + switch (reply.library_error) { + case AMQP_STATUS_CONNECTION_CLOSED: + case AMQP_STATUS_SOCKET_ERROR: + case AMQP_STATUS_SOCKET_CLOSED: + case AMQP_STATUS_SOCKET_INUSE: + case AMQP_STATUS_BROKER_UNSUPPORTED_SASL_METHOD: + case AMQP_STATUS_HOSTNAME_RESOLUTION_FAILED: + exception_ce = amqp_connection_exception_class_entry; + break; + default: + exception_ce = amqp_exception_class_entry; + } break; case AMQP_RESPONSE_SERVER_EXCEPTION: switch (reply.reply.id) { diff --git a/amqp_connection_resource.c b/amqp_connection_resource.c index e617ead2..4a894fe3 100644 --- a/amqp_connection_resource.c +++ b/amqp_connection_resource.c @@ -104,7 +104,7 @@ int php_amqp_connection_resource_error( return PHP_AMQP_RESOURCE_RESPONSE_ERROR; case AMQP_RESPONSE_LIBRARY_EXCEPTION: - spprintf(message, 0, "Library error: %s", amqp_error_string2(reply.library_error)); + spprintf(message, 0, "%s", amqp_error_string2(reply.library_error)); return PHP_AMQP_RESOURCE_RESPONSE_ERROR; case AMQP_RESPONSE_SERVER_EXCEPTION: @@ -250,12 +250,12 @@ int php_amqp_connection_resource_error_advanced(amqp_rpc_reply_t reply, char **m efree(*message); } - spprintf(message, 0, "Library error: %s", amqp_error_string2(reply.library_error)); + spprintf(message, 0, "%s", amqp_error_string2(reply.library_error)); return PHP_AMQP_RESOURCE_RESPONSE_ERROR; } if (channel->channel_resource->channel_id != frame.channel) { - spprintf(message, 0, "Library error: channel mismatch"); + spprintf(message, 0, "Channel mismatch"); return PHP_AMQP_RESOURCE_RESPONSE_ERROR; } @@ -298,12 +298,7 @@ int php_amqp_connection_resource_error_advanced(amqp_rpc_reply_t reply, char **m efree(*message); } - spprintf( - message, - 0, - "Library error: An unexpected method was received 0x%08X\n", - frame.payload.method.id - ); + spprintf(message, 0, "An unexpected method was received 0x%08X\n", frame.payload.method.id); return PHP_AMQP_RESOURCE_RESPONSE_ERROR; } } @@ -312,7 +307,7 @@ int php_amqp_connection_resource_error_advanced(amqp_rpc_reply_t reply, char **m efree(*message); } - spprintf(message, 0, "Library error: %s", amqp_error_string2(reply.library_error)); + spprintf(message, 0, "%s", amqp_error_string2(reply.library_error)); return PHP_AMQP_RESOURCE_RESPONSE_ERROR; } @@ -368,7 +363,7 @@ int php_amqp_set_resource_rpc_timeout(amqp_connection_resource *resource, double rpc_timeout.tv_usec = (int) ((timeout - floor(timeout)) * 1.e+6); if (AMQP_STATUS_OK != amqp_set_rpc_timeout(resource->connection_state, &rpc_timeout)) { - zend_throw_exception(amqp_connection_exception_class_entry, "Library error: cannot set rpc_timeout", 0); + zend_throw_exception(amqp_connection_exception_class_entry, "Cannot set rpc_timeout", 0); return 0; } #endif @@ -645,7 +640,7 @@ amqp_connection_resource *connection_resource_constructor(amqp_connection_params php_amqp_connection_resource_error(res, &message, resource, 0); - spprintf(&long_message, 0, "%s - Potential login failure.", message); + spprintf(&long_message, 0, "%s", message); zend_throw_exception(amqp_connection_exception_class_entry, long_message, PHP_AMQP_G(error_code)); efree(message); diff --git a/tests/amqpconnection_connect_login_failure.phpt b/tests/amqpconnection_connect_login_failure.phpt index 329323fd..84122aa0 100644 --- a/tests/amqpconnection_connect_login_failure.phpt +++ b/tests/amqpconnection_connect_login_failure.phpt @@ -28,10 +28,8 @@ try { } // echo ($cnn->isConnected() ? 'connected' : 'disconnected'), PHP_EOL; - -// NOTE: in real-world environment (incl. travis ci) "a socket error occurred" happens, but in vagrant environment "connection closed unexpectedly" happens. WTF? ?> --EXPECTF-- disconnected -AMQPConnectionException(%d): %s error: %s - Potential login failure. +AMQPConnectionException(403): %s disconnected \ No newline at end of file diff --git a/tests/amqpconnection_heartbeat.phpt b/tests/amqpconnection_heartbeat.phpt index 22305f5b..13816465 100644 --- a/tests/amqpconnection_heartbeat.phpt +++ b/tests/amqpconnection_heartbeat.phpt @@ -29,14 +29,12 @@ try { echo 'heartbeat: ', var_export($cnn->getHeartbeatInterval(), true), PHP_EOL; echo 'connected: ', var_export($cnn->isConnected(), true), PHP_EOL; echo 'persistent: ', var_export($cnn->isPersistent(), true), PHP_EOL; - -// NOTE: in real-world environment (incl. travis ci) "a socket error occurred" happens, but in virtual environment "connection closed unexpectedly" happens ?> ---EXPECTF-- +--EXPECTREGEX-- heartbeat: 2 connected: true persistent: false -AMQPException(0): Library error: %s +AMQPConnectionException\(0\): (a socket error occurred|connection closed unexpectedly) heartbeat: 2 connected: false persistent: false diff --git a/tests/amqpconnection_heartbeat_with_persistent.phpt b/tests/amqpconnection_heartbeat_with_persistent.phpt index e11c5188..502f1d98 100644 --- a/tests/amqpconnection_heartbeat_with_persistent.phpt +++ b/tests/amqpconnection_heartbeat_with_persistent.phpt @@ -65,10 +65,8 @@ echo 'heartbeat: ', var_export($cnn->getHeartbeatInterval(), true), PHP_EOL; echo 'connected: ', var_export($cnn->isConnected(), true), PHP_EOL; echo 'persistent: ', var_export($cnn->isPersistent(), true), PHP_EOL; echo PHP_EOL; - -// NOTE: in real-world environment (incl. travis ci) "a socket error occurred" happens, but in virtual environment "connection closed unexpectedly" happens ?> ---EXPECTF-- +--EXPECTREGEX-- heartbeat: 2 connected: false persistent: false @@ -77,7 +75,7 @@ heartbeat: 2 connected: true persistent: true -AMQPException(0): Library error: %s +AMQPConnectionException\(0\): (a socket error occurred|connection closed unexpectedly) heartbeat: 2 connected: false diff --git a/tests/amqpexchange_publish_mandatory_multiple_channels_pitfall.phpt b/tests/amqpexchange_publish_mandatory_multiple_channels_pitfall.phpt index a2360159..1674c535 100644 --- a/tests/amqpexchange_publish_mandatory_multiple_channels_pitfall.phpt +++ b/tests/amqpexchange_publish_mandatory_multiple_channels_pitfall.phpt @@ -81,5 +81,5 @@ AMQPQueueException(0): Wait timeout exceed NULL NULL NULL -AMQPException(0): Library error: unexpected method received +AMQPException(0): unexpected method received Connection active: no From 732f7e8036af57b1ef1c03c8d8c539d77fe9dc8c Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Thu, 7 Sep 2023 08:50:32 +0200 Subject: [PATCH 077/147] Remove non-ASCII characters from package.xml to work around pecl.php.net issue --- package.xml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/package.xml b/package.xml index 91bf75d1..6f7e6083 100644 --- a/package.xml +++ b/package.xml @@ -313,7 +313,7 @@ https://github.com/php-amqp/php-amqp/compare/v2.0.0...latest - Remove support for PHP 5 - Various bug fixes -💡Most use-cases should not require much changes from 1.x but check out +(!) Most use-cases should not require much changes from 1.x but check out https://github.com/php-amqp/php-amqp/tree/v2.0.0/UPGRADING.md for a detailed upgrade guide @@ -360,11 +360,11 @@ All changes (chronologically): - Fix php version check for static building (Misha Kulakovsky ) (https://github.com/php-amqp/php-amqp/issues/425) - Fix stub exception class (closes #427) (Lars Strojny ) - Document custom connection name in stubs (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/700000) - - Expose Delivery Mode through constants (Flávio Heleno ) (https://github.com/php-amqp/php-amqp/issues/420) + - Expose Delivery Mode through constants (Flavio Heleno ) (https://github.com/php-amqp/php-amqp/issues/420) - Fix deprecation issue in PHP 8.1 for $consumerTag argument to AMQPQueue::consume() method (Liviu-Ionut Iosif) (https://github.com/php-amqp/php-amqp/issues/421) - Fix: Deprecated: Creation of dynamic property (8.2) (Remi Collet ) (https://github.com/php-amqp/php-amqp/issues/418) - - Fix AMQPEnvelope::getDeliveryTag() return type (Flávio Heleno ) (https://github.com/php-amqp/php-amqp/issues/415) - - Fix ack/nack/reject param documentation (Flávio Heleno ) (https://github.com/php-amqp/php-amqp/issues/414) + - Fix AMQPEnvelope::getDeliveryTag() return type (Flavio Heleno ) (https://github.com/php-amqp/php-amqp/issues/415) + - Fix ack/nack/reject param documentation (Flavio Heleno ) (https://github.com/php-amqp/php-amqp/issues/414) - Mention time units in all timeout-related methods (Andrii Dembitskyi ) (https://github.com/php-amqp/php-amqp/issues/410) For a complete list of changes see: @@ -406,7 +406,7 @@ https://github.com/php-amqp/php-amqp/compare/v2.0.0beta2...v2.0.0RC1]]> = 8.0 on Windows (Jan Ehrhardt) (https://github.com/php-amqp/php-amqp/issues/456) - Fix segfault in setPort (Remi Collet ) (https://github.com/php-amqp/php-amqp/issues/455) -💡Check out https://github.com/php-amqp/php-amqp/tree/latest/UPGRADING.md for backward incompatible changes +(!) Check out https://github.com/php-amqp/php-amqp/tree/latest/UPGRADING.md for backward incompatible changes For a complete list of changes see: https://github.com/php-amqp/php-amqp/compare/v2.0.0beta1...v2.0.0beta2]]> @@ -435,7 +435,7 @@ https://github.com/php-amqp/php-amqp/compare/v2.0.0beta1...v2.0.0beta2]]>) (https://github.com/php-amqp/php-amqp/issues/0) - Move test-report.sh into infra (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/0) -💡Check out https://github.com/php-amqp/php-amqp/tree/latest/UPGRADING.md for backward incompatible changes +(!) Check out https://github.com/php-amqp/php-amqp/tree/latest/UPGRADING.md for backward incompatible changes For a complete list of changes see: https://github.com/php-amqp/php-amqp/compare/v2.0.0alpha2...v2.0.0beta1]]> @@ -468,11 +468,11 @@ https://github.com/php-amqp/php-amqp/compare/v2.0.0alpha2...v2.0.0beta1]]>) (https://github.com/php-amqp/php-amqp/issues/425) - Fix stub exception class (closes #427) (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/0) - Document custom connection name in stubs (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/700000) - - Expose Delivery Mode through constants (Flávio Heleno ) (https://github.com/php-amqp/php-amqp/issues/420) + - Expose Delivery Mode through constants (Flavio Heleno ) (https://github.com/php-amqp/php-amqp/issues/420) - Fix deprecation issue in PHP 8.1 for $consumerTag argument to AMQPQueue::consume() method (Liviu-Ionut Iosif) (https://github.com/php-amqp/php-amqp/issues/421) - Fix: Deprecated: Creation of dynamic property (8.2) (Remi Collet ) (https://github.com/php-amqp/php-amqp/issues/418) - - Fix AMQPEnvelope::getDeliveryTag() return type (Flávio Heleno ) (https://github.com/php-amqp/php-amqp/issues/415) - - Fix ack/nack/reject param documentation (Flávio Heleno ) (https://github.com/php-amqp/php-amqp/issues/414) + - Fix AMQPEnvelope::getDeliveryTag() return type (Flavio Heleno ) (https://github.com/php-amqp/php-amqp/issues/415) + - Fix ack/nack/reject param documentation (Flavio Heleno ) (https://github.com/php-amqp/php-amqp/issues/414) - Mention time units in all timeout-related methods (Andrii Dembitskyi ) (https://github.com/php-amqp/php-amqp/issues/410) For a complete list of changes see: @@ -509,7 +509,7 @@ https://github.com/php-amqp/php-amqp/compare/v1.11.0RC1...v1.11.0]]> beta PHP License - ) (https://github.com/php-amqp/php-amqp/issues/396) - Add installation instructions for Windows (Marcos Rezende ) (https://github.com/php-amqp/php-amqp/issues/394) - Fixes AMQPConnection Stub typo (Grégoire Pineau ) (https://github.com/php-amqp/php-amqp/issues/401) - Fix AMQPQueue stub (Gocha Ossinkine ) (https://github.com/php-amqp/php-amqp/issues/404) - SetReadTimeout accepts float param (Andrii Dembitskyi ) (https://github.com/php-amqp/php-amqp/issues/388) - Move from Travis CI to Github Actions (Vadim Borodavko ) (https://github.com/php-amqp/php-amqp/issues/391) - Release tooling: handle RC stability properly (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/71) - More robust release tooling (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/0)For a complete list of changes see:https://github.com/php-amqp/php-amqp/compare/v1.11.0beta...v1.11.0RC1]]> + ) (https://github.com/php-amqp/php-amqp/issues/396) - Add installation instructions for Windows (Marcos Rezende ) (https://github.com/php-amqp/php-amqp/issues/394) - Fixes AMQPConnection Stub typo (Gregoire Pineau ) (https://github.com/php-amqp/php-amqp/issues/401) - Fix AMQPQueue stub (Gocha Ossinkine ) (https://github.com/php-amqp/php-amqp/issues/404) - SetReadTimeout accepts float param (Andrii Dembitskyi ) (https://github.com/php-amqp/php-amqp/issues/388) - Move from Travis CI to Github Actions (Vadim Borodavko ) (https://github.com/php-amqp/php-amqp/issues/391) - Release tooling: handle RC stability properly (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/71) - More robust release tooling (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/0)For a complete list of changes see:https://github.com/php-amqp/php-amqp/compare/v1.11.0beta...v1.11.0RC1]]> 2020-04-05 @@ -551,7 +551,7 @@ https://github.com/php-amqp/php-amqp/compare/v1.11.0RC1...v1.11.0]]> stable PHP License - ) (https://github.com/pdezwart/php-amqp/issues/367) - Fix minimal librabbitmq in config.m4 and readme (Remi Collet ) (https://github.com/pdezwart/php-amqp/issues/347) - Support connection_name parameter for custom connection names in RabbitMQ (Alexandr Zolotukhin ) (https://github.com/pdezwart/php-amqp/issues/363) - Fixed build on Travis CI (Alexandr Zolotukhin ) (https://github.com/pdezwart/php-amqp/issues/365) - Make use of rpc_timeout in newer librabbitmq by introducing new constructor hash parameter (modulatix ) (https://github.com/pdezwart/php-amqp/issues/334) - Fix #355: Compile failure on php 7.4 (Christoph M. Becker ) (https://github.com/pdezwart/php-amqp/issues/359) - Update amqp_type.c (Paweł Mikołajczuk ) (https://github.com/pdezwart/php-amqp/issues/360) - Build against PHP 7.4 (Carlos Barrero ) (https://github.com/pdezwart/php-amqp/issues/361) - Pass params by value in AMQPConnection::__construct() (Sergei Karpov) (https://github.com/pdezwart/php-amqp/issues/346) - Fix explicit null-string for $routing_key in Queue::bind() and Exchange::publish() (Sergei Karpov) (https://github.com/pdezwart/php-amqp/issues/341) - No longer limited to PHP 5 (Lars Strojny ) (https://github.com/pdezwart/php-amqp/issues/0) - Fix minimal version to 5.6 (Remi Collet ) (https://github.com/pdezwart/php-amqp/issues/338) - Back to dev (Lars Strojny ) (https://github.com/pdezwart/php-amqp/issues/1)For a complete list of changes see:https://github.com/pdezwart/php-amqp/compare/v1.9.4...v1.10.0]]> + ) (https://github.com/pdezwart/php-amqp/issues/367) - Fix minimal librabbitmq in config.m4 and readme (Remi Collet ) (https://github.com/pdezwart/php-amqp/issues/347) - Support connection_name parameter for custom connection names in RabbitMQ (Alexandr Zolotukhin ) (https://github.com/pdezwart/php-amqp/issues/363) - Fixed build on Travis CI (Alexandr Zolotukhin ) (https://github.com/pdezwart/php-amqp/issues/365) - Make use of rpc_timeout in newer librabbitmq by introducing new constructor hash parameter (modulatix ) (https://github.com/pdezwart/php-amqp/issues/334) - Fix #355: Compile failure on php 7.4 (Christoph M. Becker ) (https://github.com/pdezwart/php-amqp/issues/359) - Update amqp_type.c (Pawel Mikolajczuk ) (https://github.com/pdezwart/php-amqp/issues/360) - Build against PHP 7.4 (Carlos Barrero ) (https://github.com/pdezwart/php-amqp/issues/361) - Pass params by value in AMQPConnection::__construct() (Sergei Karpov) (https://github.com/pdezwart/php-amqp/issues/346) - Fix explicit null-string for $routing_key in Queue::bind() and Exchange::publish() (Sergei Karpov) (https://github.com/pdezwart/php-amqp/issues/341) - No longer limited to PHP 5 (Lars Strojny ) (https://github.com/pdezwart/php-amqp/issues/0) - Fix minimal version to 5.6 (Remi Collet ) (https://github.com/pdezwart/php-amqp/issues/338) - Back to dev (Lars Strojny ) (https://github.com/pdezwart/php-amqp/issues/1)For a complete list of changes see:https://github.com/pdezwart/php-amqp/compare/v1.9.4...v1.10.0]]> 2017-10-19 From 35a39b20904bd1d9a2fed111ad2f01ef71c23a58 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Thu, 7 Sep 2023 08:52:04 +0200 Subject: [PATCH 078/147] [RM] releasing version 2.1.0 --- package.xml | 37 ++++++++++++++++++++++++++++--------- php_amqp_version.h | 10 +++++----- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/package.xml b/package.xml index 6f7e6083..07159f8a 100644 --- a/package.xml +++ b/package.xml @@ -22,22 +22,35 @@ pinepain@gmail.com yes - 2023-08-20 - + 2023-09-07 + - 2.0.1dev - 2.0.1dev + 2.1.0 + 2.1.0 - devel - devel + stable + stable PHP License - ) (https://github.com/php-amqp/php-amqp/issues/473) + - Implement AMQPQueue::recover() to provide the basic.recover method (fixes #478) (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/484) + - Fix double free when an error occurs in AMQPQueue::consume() (Jan Prachar ) (https://github.com/php-amqp/php-amqp/issues/482) + - Revamp error handling (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/485) + - Refactor AMQPQueue::consume error handling (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/483) + - Use RETURN_THROWS for parameter parsing errors (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/474) + - Fix auto-formatting (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/877b2f4) + - Remove appveyor badge (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/4971c80) + - Replace microtime() as a randomness source (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/4503e53) + - Fix version test for release builds (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/00a6715) + - Remove non-ASCII characters from package.xml to work around pecl.php.net issue (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/732f7e8) + - Bump actions/checkout from 3.5.3 to 3.6.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/475) + - Bump symplify/easy-coding-standard from 12.0.6 to 12.0.7 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/472) + - Bump actions/checkout from 3.5.3 to 3.6.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/471) + - Bump actions/checkout from 3.6.0 to 4.0.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/481) For a complete list of changes see: -https://github.com/php-amqp/php-amqp/compare/v2.0.0...latest -]]> +https://github.com/php-amqp/php-amqp/compare/v2.0.0...v2.1.0]]> @@ -71,6 +84,8 @@ https://github.com/php-amqp/php-amqp/compare/v2.0.0...latest + + @@ -235,6 +250,7 @@ https://github.com/php-amqp/php-amqp/compare/v2.0.0...latest + @@ -260,6 +276,8 @@ https://github.com/php-amqp/php-amqp/compare/v2.0.0...latest + + @@ -276,6 +294,7 @@ https://github.com/php-amqp/php-amqp/compare/v2.0.0...latest + diff --git a/php_amqp_version.h b/php_amqp_version.h index e72f33d3..64253f5d 100644 --- a/php_amqp_version.h +++ b/php_amqp_version.h @@ -1,6 +1,6 @@ #define PHP_AMQP_VERSION_MAJOR 2 -#define PHP_AMQP_VERSION_MINOR 0 -#define PHP_AMQP_VERSION_PATCH 1 -#define PHP_AMQP_VERSION_EXTRA "dev" -#define PHP_AMQP_VERSION "2.0.1dev" -#define PHP_AMQP_VERSION_ID 20001 +#define PHP_AMQP_VERSION_MINOR 1 +#define PHP_AMQP_VERSION_PATCH 0 +#define PHP_AMQP_VERSION_EXTRA "" +#define PHP_AMQP_VERSION "2.1.0" +#define PHP_AMQP_VERSION_ID 20100 From 0d76f106aebec05141ef2ff3cdbf95992fe8450b Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Thu, 7 Sep 2023 08:53:12 +0200 Subject: [PATCH 079/147] [RM] back to dev 2.2.0dev --- package.xml | 60 ++++++++++++++++++++++++++++++---------------- php_amqp_version.h | 8 +++---- 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/package.xml b/package.xml index 07159f8a..2508f2a8 100644 --- a/package.xml +++ b/package.xml @@ -23,34 +23,21 @@ yes 2023-09-07 - + - 2.1.0 - 2.1.0 + 2.2.0dev + 2.2.0dev - stable - stable + devel + devel PHP License - ) (https://github.com/php-amqp/php-amqp/issues/473) - - Implement AMQPQueue::recover() to provide the basic.recover method (fixes #478) (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/484) - - Fix double free when an error occurs in AMQPQueue::consume() (Jan Prachar ) (https://github.com/php-amqp/php-amqp/issues/482) - - Revamp error handling (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/485) - - Refactor AMQPQueue::consume error handling (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/483) - - Use RETURN_THROWS for parameter parsing errors (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/474) - - Fix auto-formatting (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/877b2f4) - - Remove appveyor badge (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/4971c80) - - Replace microtime() as a randomness source (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/4503e53) - - Fix version test for release builds (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/00a6715) - - Remove non-ASCII characters from package.xml to work around pecl.php.net issue (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/732f7e8) - - Bump actions/checkout from 3.5.3 to 3.6.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/475) - - Bump symplify/easy-coding-standard from 12.0.6 to 12.0.7 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/472) - - Bump actions/checkout from 3.5.3 to 3.6.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/471) - - Bump actions/checkout from 3.6.0 to 4.0.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/481) + +https://github.com/php-amqp/php-amqp/compare/v2.1.0...latest +]]> @@ -314,6 +301,37 @@ https://github.com/php-amqp/php-amqp/compare/v2.0.0...v2.1.0]]> + + 2023-09-07 + + + 2.1.0 + 2.1.0 + + + stable + stable + + PHP License + ) (https://github.com/php-amqp/php-amqp/issues/473) + - Implement AMQPQueue::recover() to provide the basic.recover method (fixes #478) (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/484) + - Fix double free when an error occurs in AMQPQueue::consume() (Jan Prachar ) (https://github.com/php-amqp/php-amqp/issues/482) + - Revamp error handling (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/485) + - Refactor AMQPQueue::consume error handling (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/483) + - Use RETURN_THROWS for parameter parsing errors (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/474) + - Fix auto-formatting (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/877b2f4) + - Remove appveyor badge (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/4971c80) + - Replace microtime() as a randomness source (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/4503e53) + - Fix version test for release builds (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/00a6715) + - Remove non-ASCII characters from package.xml to work around pecl.php.net issue (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/732f7e8) + - Bump actions/checkout from 3.5.3 to 3.6.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/475) + - Bump symplify/easy-coding-standard from 12.0.6 to 12.0.7 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/472) + - Bump actions/checkout from 3.5.3 to 3.6.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/471) + - Bump actions/checkout from 3.6.0 to 4.0.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/481) + +For a complete list of changes see: +https://github.com/php-amqp/php-amqp/compare/v2.0.0...v2.1.0]]> + 2023-08-20 diff --git a/php_amqp_version.h b/php_amqp_version.h index 64253f5d..61c2d46c 100644 --- a/php_amqp_version.h +++ b/php_amqp_version.h @@ -1,6 +1,6 @@ #define PHP_AMQP_VERSION_MAJOR 2 -#define PHP_AMQP_VERSION_MINOR 1 +#define PHP_AMQP_VERSION_MINOR 2 #define PHP_AMQP_VERSION_PATCH 0 -#define PHP_AMQP_VERSION_EXTRA "" -#define PHP_AMQP_VERSION "2.1.0" -#define PHP_AMQP_VERSION_ID 20100 +#define PHP_AMQP_VERSION_EXTRA "dev" +#define PHP_AMQP_VERSION "2.2.0dev" +#define PHP_AMQP_VERSION_ID 20200 From d5375425db9e57a805642e5e376536f116affb6e Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 7 Sep 2023 15:15:37 +0200 Subject: [PATCH 080/147] Remove assert on undefined variable (#486) --- amqp_connection_resource.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/amqp_connection_resource.c b/amqp_connection_resource.c index 4a894fe3..56194dab 100644 --- a/amqp_connection_resource.c +++ b/amqp_connection_resource.c @@ -236,8 +236,6 @@ static void php_amqp_close_channel_from_server( int php_amqp_connection_resource_error_advanced(amqp_rpc_reply_t reply, char **message, amqp_channel_object *channel) { - assert(resource != NULL); - amqp_frame_t frame; assert(AMQP_RESPONSE_LIBRARY_EXCEPTION == reply.reply_type); From 29e693f1737d8fe56e113b556bc8bf19ecf30667 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 8 Sep 2023 06:40:58 +0200 Subject: [PATCH 081/147] Bump phpstan/phpdoc-parser from 1.23.1 to 1.24.0 (#491) --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index ec98b948..4c679f62 100644 --- a/composer.lock +++ b/composer.lock @@ -87,16 +87,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.23.1", + "version": "1.24.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "846ae76eef31c6d7790fac9bc399ecee45160b26" + "reference": "3510b0a6274cc42f7219367cb3abfc123ffa09d6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/846ae76eef31c6d7790fac9bc399ecee45160b26", - "reference": "846ae76eef31c6d7790fac9bc399ecee45160b26", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/3510b0a6274cc42f7219367cb3abfc123ffa09d6", + "reference": "3510b0a6274cc42f7219367cb3abfc123ffa09d6", "shasum": "" }, "require": { @@ -128,9 +128,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.23.1" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.0" }, - "time": "2023-08-03T16:32:59+00:00" + "time": "2023-09-07T20:46:32+00:00" }, { "name": "slevomat/coding-standard", From 447a09609ec9893ef9dbc75cd02360e0d6ca0039 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 20 Sep 2023 15:12:56 +0200 Subject: [PATCH 082/147] Bump phpstan/phpdoc-parser from 1.24.0 to 1.24.1 (#495) --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 4c679f62..3441eefc 100644 --- a/composer.lock +++ b/composer.lock @@ -87,16 +87,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.24.0", + "version": "1.24.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "3510b0a6274cc42f7219367cb3abfc123ffa09d6" + "reference": "9f854d275c2dbf84915a5c0ec9a2d17d2cd86b01" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/3510b0a6274cc42f7219367cb3abfc123ffa09d6", - "reference": "3510b0a6274cc42f7219367cb3abfc123ffa09d6", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/9f854d275c2dbf84915a5c0ec9a2d17d2cd86b01", + "reference": "9f854d275c2dbf84915a5c0ec9a2d17d2cd86b01", "shasum": "" }, "require": { @@ -128,9 +128,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.1" }, - "time": "2023-09-07T20:46:32+00:00" + "time": "2023-09-18T12:18:02+00:00" }, { "name": "slevomat/coding-standard", From 4542968896bdc31a9043af5691d5b9a5b37b048c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 20 Sep 2023 15:13:05 +0200 Subject: [PATCH 083/147] Bump symplify/easy-coding-standard from 12.0.7 to 12.0.8 (#492) --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 3441eefc..d0ecb72c 100644 --- a/composer.lock +++ b/composer.lock @@ -256,16 +256,16 @@ }, { "name": "symplify/easy-coding-standard", - "version": "12.0.7", + "version": "12.0.8", "source": { "type": "git", "url": "https://github.com/easy-coding-standard/easy-coding-standard.git", - "reference": "79b5679f0dd758311770543969087b8dc46429ee" + "reference": "99d87d188acc712dd6655ee946569f823cfeff69" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/79b5679f0dd758311770543969087b8dc46429ee", - "reference": "79b5679f0dd758311770543969087b8dc46429ee", + "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/99d87d188acc712dd6655ee946569f823cfeff69", + "reference": "99d87d188acc712dd6655ee946569f823cfeff69", "shasum": "" }, "require": { @@ -298,7 +298,7 @@ ], "support": { "issues": "https://github.com/easy-coding-standard/easy-coding-standard/issues", - "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.0.7" + "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.0.8" }, "funding": [ { @@ -310,7 +310,7 @@ "type": "github" } ], - "time": "2023-08-24T21:43:33+00:00" + "time": "2023-09-08T10:17:14+00:00" } ], "aliases": [], From 550e3b5ad2abfef0c790cf43f97bb0978917c68f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 20 Sep 2023 15:13:15 +0200 Subject: [PATCH 084/147] Bump shivammathur/setup-php from 2.25.5 to 2.26.0 (#493) --- .github/workflows/test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 8c10b6d6..304af45b 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -79,7 +79,7 @@ jobs: packages: cmake valgrind - name: Setup PHP - uses: shivammathur/setup-php@2.25.5 + uses: shivammathur/setup-php@2.26.0 with: php-version: ${{ matrix.php-version }} extensions: json @@ -148,7 +148,7 @@ jobs: version: ${{ (matrix.librabbitmq-version == '0.10.0' || matrix.librabbitmq-version == '0.9.0' || matrix.librabbitmq-version == '0.8.0') && 'ubuntu-20.04' || 'ubuntu-22.04' }} - name: Setup PHP - uses: shivammathur/setup-php@2.25.5 + uses: shivammathur/setup-php@2.26.0 with: php-version: ${{ matrix.php-version }} coverage: none From 3b7bc337c0504e155d1b897c2294a53b1509747b Mon Sep 17 00:00:00 2001 From: Daniel Kozak Date: Tue, 10 Oct 2023 16:30:43 +0200 Subject: [PATCH 085/147] FIX: #494 Param "verify" always true (#497) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Kozák --- amqp_connection.c | 2 +- ...amqpconnection_construct_with_verify_false.phpt | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/amqpconnection_construct_with_verify_false.phpt diff --git a/amqp_connection.c b/amqp_connection.c index 6b0a3018..454dde5c 100644 --- a/amqp_connection.c +++ b/amqp_connection.c @@ -83,7 +83,7 @@ zend_object_handlers amqp_connection_object_handlers; #define PHP_AMQP_EXTRACT_CONNECTION_BOOL(name) \ zdata = NULL; \ - if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), (name), sizeof(name))) != NULL) { \ + if (ini_arr && (zdata = zend_hash_str_find(HASH_OF(ini_arr), ZEND_STRL(name))) != NULL) { \ SEPARATE_ZVAL(zdata); \ convert_to_long(zdata); \ } \ diff --git a/tests/amqpconnection_construct_with_verify_false.phpt b/tests/amqpconnection_construct_with_verify_false.phpt new file mode 100644 index 00000000..3193b7e0 --- /dev/null +++ b/tests/amqpconnection_construct_with_verify_false.phpt @@ -0,0 +1,14 @@ +--TEST-- +AMQPConnection constructor with verify parameter set to false in $params +--SKIPIF-- + +--FILE-- + false); +$cnn = new AMQPConnection($params); +var_dump($cnn->getVerify()); +?> +--EXPECT-- +bool(false) From 2ff076e4600724cc89439157223fc700634b2969 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 11 Oct 2023 22:09:47 +0200 Subject: [PATCH 086/147] Fixing debug mode errors (#502) Fixes all errors that occur in debug mode only. Additionally changes all Debian based development images to have debug mode enabled. --- DEVELOPMENT.md | 8 ++++---- amqp_channel.c | 6 ++++-- amqp_connection.c | 30 +++++++++++++++--------------- amqp_envelope.c | 7 ++++++- amqp_queue.c | 26 ++++++++++++-------------- amqp_type.c | 1 + docker-compose.yml | 18 +++++++++++++++++- infra/dev/Dockerfile | 19 +++++++++++++++++++ infra/tools/pamqp-dump-reflection | 6 +++++- php_amqp.h | 2 +- stubs/AMQPEnvelope.php | 4 ++-- 11 files changed, 86 insertions(+), 41 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 1a82e22d..1ef33564 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -25,10 +25,10 @@ all the logs, especially the RabbitMQ logs. Various development containers are provided: -- `debian-74`: PHP 7.4 on Debian 11 ("Bullseye") -- `debian-80`: PHP 8.0 on Debian 12 ("Bookworm") -- `debian-81`: PHP 8.1 on Debian 12 ("Bookworm") -- `debian-82`: PHP 8.2 on Debian 12 ("Bookworm") +- `debian-74`: PHP 7.4 on Debian 11 ("Bullseye") with debug build enabled +- `debian-80`: PHP 8.0 on Debian 12 ("Bookworm") with debug build enabled +- `debian-81`: PHP 8.1 on Debian 12 ("Bookworm") with debug build enabled +- `debian-82`: PHP 8.2 on Debian 12 ("Bookworm") with debug build enabled - `ubuntu-74`: PHP 7.4 on Ubuntu 20 ("Jammy") - `ubuntu-80`: PHP 8.0 on Ubuntu 22 ("Jammy") - `ubuntu-81`: PHP 8.1 on Ubuntu 22 ("Jammy") diff --git a/amqp_channel.c b/amqp_channel.c index 53eca3b1..253f6b41 100644 --- a/amqp_channel.c +++ b/amqp_channel.c @@ -1349,12 +1349,14 @@ PHP_METHOD(amqp_channel_class, waitForConfirm) } /* }}} */ -/* {{{ proto amqp::getConsumers() */ +/* {{{ proto AMQPChannel::getConsumers() */ static PHP_METHOD(amqp_channel_class, getConsumers) { zval rv; PHP_AMQP_NOPARAMS() - PHP_AMQP_RETURN_THIS_PROP("consumers"); + zval *tmp = zend_read_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("consumers"), 0, &rv); + // Return a proper copy, so that the internal consumer map can be safely modified + ZVAL_DUP(return_value, tmp); } /* }}} */ diff --git a/amqp_connection.c b/amqp_connection.c index 454dde5c..7f5573d3 100644 --- a/amqp_connection.c +++ b/amqp_connection.c @@ -648,7 +648,7 @@ static PHP_METHOD(amqp_connection_class, __construct) "Parameter 'rpc_timeout' must be greater than or equal to zero.", 0 ); - return; + RETURN_THROWS(); } zend_update_property_double( @@ -676,7 +676,7 @@ static PHP_METHOD(amqp_connection_class, __construct) "Parameter 'connect_timeout' must be greater than or equal to zero.", 0 ); - return; + RETURN_THROWS(); } zend_update_property_double( @@ -700,7 +700,7 @@ static PHP_METHOD(amqp_connection_class, __construct) if (!php_amqp_is_valid_channel_max(Z_LVAL_P(zdata))) { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'channel_max' is out of range.", 0); - return; + RETURN_THROWS(); } if (Z_LVAL_P(zdata) == 0) { @@ -732,7 +732,7 @@ static PHP_METHOD(amqp_connection_class, __construct) convert_to_long(zdata); if (!php_amqp_is_valid_frame_size_max(Z_LVAL_P(zdata))) { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'frame_max' is out of range.", 0); - return; + RETURN_THROWS(); } if (Z_LVAL_P(zdata) == 0) { @@ -764,7 +764,7 @@ static PHP_METHOD(amqp_connection_class, __construct) convert_to_long(zdata); if (!php_amqp_is_valid_heartbeat(Z_LVAL_P(zdata))) { zend_throw_exception(amqp_connection_exception_class_entry, "Parameter 'heartbeat' is out of range.", 0); - return; + RETURN_THROWS(); } zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("heartbeat"), Z_LVAL_P(zdata)); @@ -837,14 +837,14 @@ static PHP_METHOD(amqp_connection_class, connect) if (connection->connection_resource && connection->connection_resource->is_connected) { if (connection->connection_resource->is_persistent) { - php_error_docref( - NULL, - E_WARNING, - "Attempt to start transient connection while persistent transient one already established. Continue." + zend_throw_exception( + amqp_connection_exception_class_entry, + "Attempt to start transient connection while persistent one already established. Continue.", + 0 ); } - RETURN_TRUE; + return; } /* Actually connect this resource to the broker */ @@ -868,14 +868,14 @@ static PHP_METHOD(amqp_connection_class, pconnect) assert(connection->connection_resource != NULL); if (!connection->connection_resource->is_persistent) { - php_error_docref( - NULL, - E_WARNING, - "Attempt to start persistent connection while transient one already established. Continue." + zend_throw_exception( + amqp_connection_exception_class_entry, + "Attempt to start persistent connection while transient one already established. Continue.", + 0 ); } - RETURN_TRUE; + return; } /* Actually connect this resource to the broker or use stored connection */ diff --git a/amqp_envelope.c b/amqp_envelope.c index f1ca4c2c..827887ce 100644 --- a/amqp_envelope.c +++ b/amqp_envelope.c @@ -256,7 +256,12 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_envelope_class_isRedelivery, ZEND_SEND_BY_VAL, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_envelope_class_getHeader, ZEND_SEND_BY_VAL, 1, IS_STRING, 1) +#ifdef IS_MIXED +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_amqp_envelope_class_getHeader, ZEND_SEND_BY_VAL, 1, IS_MIXED, 1) +#else +/* PHP < 8.0 */ +ZEND_BEGIN_ARG_INFO_EX(arginfo_amqp_envelope_class_getHeader, 0, 0, 1) +#endif ZEND_ARG_TYPE_INFO(0, headerName, IS_STRING, 0) ZEND_END_ARG_INFO() diff --git a/amqp_queue.c b/amqp_queue.c index 09c684a9..67229a05 100644 --- a/amqp_queue.c +++ b/amqp_queue.c @@ -324,7 +324,9 @@ static PHP_METHOD(amqp_queue_class, removeArgument) RETURN_THROWS(); } - zend_hash_str_del_ind(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len); + if (zend_hash_str_exists_ind(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len)) { + zend_hash_str_del_ind(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, key_len); + } } /* }}} */ @@ -445,7 +447,7 @@ static PHP_METHOD(amqp_queue_class, bind) if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; + RETURN_THROWS(); } php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); @@ -583,7 +585,7 @@ static PHP_METHOD(amqp_queue_class, consume) "Invalid channel consumers, forgot to call channel constructor?", 0 ); - return; + RETURN_THROWS(); } amqp_channel_object *channel = PHP_AMQP_GET_CHANNEL(channel_zv); @@ -615,7 +617,7 @@ static PHP_METHOD(amqp_queue_class, consume) zend_throw_exception(amqp_queue_exception_class_entry, PHP_AMQP_G(error_message), PHP_AMQP_G(error_code)); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; + RETURN_THROWS(); } char *key; @@ -625,7 +627,7 @@ static PHP_METHOD(amqp_queue_class, consume) // This should never happen as AMQP server guarantees that consumer tag is unique within channel zend_throw_exception(amqp_exception_class_entry, "Duplicate consumer tag", 0); efree(key); - return; + RETURN_THROWS(); } zval tmp; @@ -647,7 +649,7 @@ static PHP_METHOD(amqp_queue_class, consume) } if (!ZEND_FCI_INITIALIZED(fci)) { - /* Callback not set, we have nothing to do - real consuming may happens later */ + /* Callback not set, we have nothing to do - real consuming may happen later */ return; } @@ -703,7 +705,7 @@ static PHP_METHOD(amqp_queue_class, consume) php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; + RETURN_THROWS(); } ZVAL_UNDEF(&message); @@ -799,10 +801,7 @@ static PHP_METHOD(amqp_queue_class, consume) fci.retval = &retval; - /* Call the function, and track the return value */ - if (zend_call_function(&fci, &fci_cache) == SUCCESS && fci.retval) { - RETVAL_ZVAL(&retval, 1, 1); - } + zend_call_function(&fci, &fci_cache); /* Clean up our mess */ zend_fcall_info_args_clear(&fci, 1); @@ -810,13 +809,12 @@ static PHP_METHOD(amqp_queue_class, consume) zval_ptr_dtor(&message); /* Check if user land function wants to bail */ - if (EG(exception) || Z_TYPE_P(return_value) == IS_FALSE) { + if (EG(exception) || Z_TYPE_P(&retval) == IS_FALSE) { break; } } php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - return; } /* }}} */ @@ -1038,7 +1036,7 @@ static PHP_METHOD(amqp_queue_class, cancel) "Invalid channel consumers, forgot to call channel constructor?", 0 ); - return; + RETURN_THROWS(); } channel_resource = PHP_AMQP_GET_CHANNEL_RESOURCE(channel_zv); diff --git a/amqp_type.c b/amqp_type.c index c43cb421..71abfb31 100644 --- a/amqp_type.c +++ b/amqp_type.c @@ -163,6 +163,7 @@ void php_amqp_type_zval_to_amqp_table_internal(zval *array, amqp_table_t *amqp_t if (!php_amqp_type_zval_to_amqp_value_internal(value_nested, &field, key, depth + 1)) { /* Reset entries counter back */ amqp_table->num_entries--; + efree(string_key); continue; } diff --git a/docker-compose.yml b/docker-compose.yml index dab8732f..ea82ecd6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -83,6 +83,14 @@ services: php_version: "8.2" working_dir: /src/build/centos-82 + centos-83: + <<: *centos-dev + build: + <<: *centos-dev-build + args: + php_version: "8.3" + working_dir: /src/build/centos-83 + ubuntu-74: &ubuntu-dev build: &ubuntu-dev-build context: infra/dev @@ -126,10 +134,18 @@ services: php_version: "8.2" working_dir: /src/build/ubuntu-82 + ubuntu-83: + <<: *ubuntu-dev + build: + <<: *ubuntu-dev-build + args: + php_version: "8.3" + working_dir: /src/build/ubuntu-83 + debian-74: &debian-dev build: &debian-dev-build context: infra/dev - target: debianish + target: debian-php additional_contexts: base: docker-image://php:7.4-zts-bullseye volumes: diff --git a/infra/dev/Dockerfile b/infra/dev/Dockerfile index b7e5e84e..ef2dac05 100644 --- a/infra/dev/Dockerfile +++ b/infra/dev/Dockerfile @@ -34,3 +34,22 @@ RUN sed -e "s:main:main main/debug:" -i /etc/apt/sources.list.d/ondrej-*.list RUN apt-get update -yqq ARG php_version RUN apt-get install -yqq php${php_version}-dev php${php_version}-common-dbgsym php${php_version}-cli-dbgsym + +FROM debianish AS debian-php +# Rebuild to enable debug build +RUN apt-get install -y --no-install-recommends \ + libargon2-dev \ + libcurl4-openssl-dev \ + libonig-dev \ + libreadline-dev \ + libsodium-dev \ + libsqlite3-dev \ + libssl-dev \ + libxml2-dev \ + zlib1g-dev \ + && \ + docker-php-source extract && \ + cd /usr/src/php && \ + ./configure $(php --info | grep "^Configure Command" | cut -d " " -f 7- | rev | cut -d " " -f 2- | rev | tr "'" " ") --enable-debug && \ + make -j $(nproc) && \ + make install \ diff --git a/infra/tools/pamqp-dump-reflection b/infra/tools/pamqp-dump-reflection index 7621ce5d..62efb642 100755 --- a/infra/tools/pamqp-dump-reflection +++ b/infra/tools/pamqp-dump-reflection @@ -18,7 +18,11 @@ function sortByName(array $array): array function getTypeMetadata(?ReflectionType $type): ?array { if ($type == null) { - return null; + return [ + 'name' => 'mixed', + 'nullable' => true, + 'builtin' => true, + ]; } if ($type instanceof ReflectionNamedType) { diff --git a/php_amqp.h b/php_amqp.h index 03337a68..4592aadd 100644 --- a/php_amqp.h +++ b/php_amqp.h @@ -279,7 +279,7 @@ struct _amqp_connection_object { #define PHP_AMQP_NOPARAMS() \ if (zend_parse_parameters_none() == FAILURE) { \ - return; \ + RETURN_THROWS(); \ } #define PHP_AMQP_RETURN_THIS_PROP(prop_name) \ diff --git a/stubs/AMQPEnvelope.php b/stubs/AMQPEnvelope.php index 76581c46..d72419a6 100644 --- a/stubs/AMQPEnvelope.php +++ b/stubs/AMQPEnvelope.php @@ -85,9 +85,9 @@ public function isRedelivery(): bool * * @param string $headerName Name of the header to get the value from. * - * @return string|null The contents of the specified header or null if not set. + * @return mixed The contents of the specified header or null if not set. */ - public function getHeader(string $headerName): ?string + public function getHeader(string $headerName) { } From cbe4466437ca05cd014e71ec7e0193e1e1d31e89 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Thu, 12 Oct 2023 11:38:52 +0200 Subject: [PATCH 087/147] Set custom PHP executable dynamically (#503) --- .env | 2 +- .github/workflows/test.yaml | 2 +- config.m4 | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.env b/.env index 98a8c9a6..39753f40 100644 --- a/.env +++ b/.env @@ -1,6 +1,6 @@ PHP_AMQP_HOST=rabbitmq PHP_AMQP_SSL_HOST=rabbitmq.example.org -MAKEFLAGS="-j16" +MAKEFLAGS="-j16 PHP_EXECUTABLE=/src/infra/tools/pamqp-php-cli-deterministic" CFLAGS="-g -O0 -fstack-protector-strong -Wall -Werror -D_GNU_SOURCE" TEST_PHP_ARGS="-j16 -q" CC=clang diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 304af45b..d077017c 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -8,7 +8,7 @@ on: env: TEST_TIMEOUT: 120 CFLAGS: -g -O0 -fstack-protector-strong -Wall -Werror -D_GNU_SOURCE - MAKEFLAGS: -j4 + MAKEFLAGS: -j4 PHP_EXECUTABLE=./infra/tools/pamqp-php-cli-deterministic jobs: prep: diff --git a/config.m4 b/config.m4 index 3e33d57d..94624fa4 100644 --- a/config.m4 +++ b/config.m4 @@ -7,7 +7,6 @@ PHP_ARG_WITH(librabbitmq-dir, for amqp, [ --with-librabbitmq-dir[=DIR] Set the path to librabbitmq install prefix.], yes) dnl Set test wrapper binary to ignore any local ini settings -PHP_EXECUTABLE="\$(top_srcdir)/infra/tools/pamqp-php-cli-deterministic" if test "$PHP_AMQP" != "no"; then AC_MSG_CHECKING([for supported PHP versions]) From c6f53e415cd47083b54a3e8d4a3fc85ec6ea82b9 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Thu, 12 Oct 2023 12:28:37 +0200 Subject: [PATCH 088/147] Refactor test skipping (#504) * Print the reason a test was skipped * Respect SKIP_SLOW_TESTS * Respect SKIP_ONLINE_TESTS that require network --- tests/003-channel-consumers.phpt | 4 ++-- tests/004-queue-consume-nested.phpt | 4 ++-- tests/004-queue-consume-orphaned.phpt | 4 ++-- tests/amqp_version.phpt | 2 +- tests/amqpbasicproperties.phpt | 2 +- tests/amqpchannel_basicRecover.phpt | 5 +++-- tests/amqpchannel_close.phpt | 4 ++-- tests/amqpchannel_confirmSelect.phpt | 4 ++-- tests/amqpchannel_construct_basic.phpt | 4 ++-- ...l_construct_ini_global_prefetch_count.phpt | 4 ++-- ...el_construct_ini_global_prefetch_size.phpt | 6 +++--- ...pchannel_construct_ini_prefetch_count.phpt | 4 ++-- ...qpchannel_construct_ini_prefetch_size.phpt | 6 +++--- tests/amqpchannel_getChannelId.phpt | 4 ++-- tests/amqpchannel_get_connection.phpt | 4 ++-- .../amqpchannel_multi_channel_connection.phpt | 4 ++-- ...amqpchannel_set_global_prefetch_count.phpt | 4 ++-- .../amqpchannel_set_global_prefetch_size.phpt | 6 +++--- ...et_prefetch_and_global_prefetch_count.phpt | 4 ++-- ...set_prefetch_and_global_prefetch_size.phpt | 6 +++--- tests/amqpchannel_set_prefetch_count.phpt | 4 ++-- tests/amqpchannel_set_prefetch_size.phpt | 6 +++--- tests/amqpchannel_slots_usage.phpt | 4 ++-- tests/amqpchannel_validation.phpt | 4 ++-- tests/amqpchannel_var_dump.phpt | 4 ++-- .../amqpconnection_connect_login_failure.phpt | 4 ++-- tests/amqpconnection_connection_getters.phpt | 4 ++-- tests/amqpconnection_construct_basic.phpt | 4 ++-- ...connection_construct_ini_read_timeout.phpt | 4 ++-- .../amqpconnection_construct_ini_timeout.phpt | 4 ++-- ...onstruct_ini_timeout_and_read_timeout.phpt | 4 ++-- ...nection_construct_ini_timeout_default.phpt | 4 ++-- ...pconnection_construct_params_by_value.phpt | 2 +- ...ection_construct_with_connect_timeout.phpt | 4 +++- ...ection_construct_with_connection_name.phpt | 2 +- .../amqpconnection_construct_with_limits.phpt | 4 ++-- ...connection_construct_with_rpc_timeout.phpt | 2 +- ...amqpconnection_construct_with_timeout.phpt | 2 +- ...nstruct_with_timeout_and_read_timeout.phpt | 2 +- ...onnection_construct_with_verify_false.phpt | 2 +- ...nnection_construct_with_write_timeout.phpt | 2 +- tests/amqpconnection_getUsedChannels.phpt | 4 ++-- tests/amqpconnection_heartbeat.phpt | 5 +++-- ...mqpconnection_heartbeat_with_consumer.phpt | 5 +++-- ...pconnection_heartbeat_with_persistent.phpt | 5 +++-- tests/amqpconnection_nullable_setters.phpt | 2 +- ...connection_persistent_construct_basic.phpt | 4 ++-- tests/amqpconnection_persistent_in_use.phpt | 4 ++-- tests/amqpconnection_persistent_reusable.phpt | 4 ++-- tests/amqpconnection_setConnectionName.phpt | 4 ++-- tests/amqpconnection_setHost.phpt | 2 +- tests/amqpconnection_setLogin.phpt | 4 ++-- tests/amqpconnection_setPassword.phpt | 4 ++-- tests/amqpconnection_setPort_int.phpt | 4 ++-- .../amqpconnection_setPort_out_of_range.phpt | 4 ++-- tests/amqpconnection_setPort_string.phpt | 4 ++-- .../amqpconnection_setReadTimeout_float.phpt | 4 ++-- tests/amqpconnection_setReadTimeout_int.phpt | 4 ++-- ...onnection_setReadTimeout_out_of_range.phpt | 2 +- .../amqpconnection_setReadTimeout_string.phpt | 4 ++-- tests/amqpconnection_setRpcTimeout_float.phpt | 4 ++-- tests/amqpconnection_setRpcTimeout_int.phpt | 4 ++-- ...connection_setRpcTimeout_out_of_range.phpt | 4 ++-- .../amqpconnection_setRpcTimeout_string.phpt | 4 ++-- tests/amqpconnection_setSaslMethod.phpt | 4 ++-- .../amqpconnection_setSaslMethod_invalid.phpt | 4 ++-- .../amqpconnection_setTimeout_deprecated.phpt | 2 +- tests/amqpconnection_setTimeout_float.phpt | 2 +- tests/amqpconnection_setTimeout_int.phpt | 2 +- ...mqpconnection_setTimeout_out_of_range.phpt | 2 +- tests/amqpconnection_setTimeout_string.phpt | 2 +- tests/amqpconnection_setVhost.phpt | 4 ++-- .../amqpconnection_setWriteTimeout_float.phpt | 4 ++-- tests/amqpconnection_setWriteTimeout_int.phpt | 4 ++-- ...nnection_setWriteTimeout_out_of_range.phpt | 4 ++-- ...amqpconnection_setWriteTimeout_string.phpt | 4 ++-- tests/amqpconnection_tls_basic.phpt | 6 +++--- tests/amqpconnection_tls_mtls.phpt | 10 +++++----- tests/amqpconnection_tls_sasl.phpt | 10 +++++----- tests/amqpconnection_toomanychannels.phpt | 4 ++-- tests/amqpconnection_validation.phpt | 2 +- tests/amqpconnection_var_dump.phpt | 4 ++-- tests/amqpdecimal.phpt | 2 +- tests/amqpenvelope_construct.phpt | 2 +- tests/amqpenvelope_get_accessors.phpt | 4 ++-- tests/amqpenvelope_var_dump.phpt | 4 ++-- tests/amqpexchange-declare-segfault.phpt | 4 ++-- tests/amqpexchange_attributes.phpt | 4 ++-- tests/amqpexchange_bind.phpt | 4 ++-- tests/amqpexchange_bind_with_arguments.phpt | 4 ++-- tests/amqpexchange_bind_without_key.phpt | 4 ++-- ...hange_bind_without_key_with_arguments.phpt | 4 ++-- tests/amqpexchange_channel_refcount.phpt | 4 ++-- tests/amqpexchange_construct_basic.phpt | 4 ++-- tests/amqpexchange_declare_basic.phpt | 4 ++-- tests/amqpexchange_declare_existent.phpt | 4 ++-- ...change_declare_with_stalled_reference.phpt | 2 +- tests/amqpexchange_declare_without_name.phpt | 4 ++-- tests/amqpexchange_declare_without_type.phpt | 4 ++-- .../amqpexchange_delete_default_exchange.phpt | 4 ++-- tests/amqpexchange_delete_null_name.phpt | 4 ++-- tests/amqpexchange_get_channel.phpt | 4 ++-- tests/amqpexchange_get_connection.phpt | 4 ++-- tests/amqpexchange_invalid_type.phpt | 4 ++-- tests/amqpexchange_name.phpt | 4 ++-- tests/amqpexchange_publish_basic.phpt | 4 ++-- tests/amqpexchange_publish_confirms.phpt | 5 +++-- ...amqpexchange_publish_confirms_consume.phpt | 5 +++-- ...mqpexchange_publish_empty_routing_key.phpt | 4 ++-- tests/amqpexchange_publish_mandatory.phpt | 5 +++-- ...mqpexchange_publish_mandatory_consume.phpt | 5 +++-- ...h_mandatory_multiple_channels_pitfall.phpt | 5 +++-- ...amqpexchange_publish_null_routing_key.phpt | 4 ++-- tests/amqpexchange_publish_timeout.disabled | 4 ++-- ...pexchange_publish_with_decimal_header.phpt | 4 ++-- tests/amqpexchange_publish_with_null.phpt | Bin 2122 -> 2201 bytes .../amqpexchange_publish_with_properties.phpt | 4 ++-- ...ish_with_properties_ignore_num_header.phpt | 4 ++-- ...ties_ignore_unsupported_header_values.phpt | 4 ++-- ...publish_with_properties_nested_header.phpt | 4 ++-- ...blish_with_properties_user_id_failure.phpt | 4 ++-- ...xchange_publish_with_timestamp_header.phpt | 4 ++-- tests/amqpexchange_publish_xdeath.phpt | 4 ++-- tests/amqpexchange_setArgument.phpt | 4 ++-- tests/amqpexchange_set_flag.phpt | 4 ++-- tests/amqpexchange_set_flags.phpt | 4 ++-- tests/amqpexchange_type.phpt | 4 ++-- tests/amqpexchange_unbind.phpt | 4 ++-- tests/amqpexchange_unbind_with_arguments.phpt | 4 ++-- tests/amqpexchange_unbind_without_key.phpt | 4 ++-- ...nge_unbind_without_key_with_arguments.phpt | 4 ++-- tests/amqpexchange_var_dump.phpt | 4 ++-- tests/amqpqueue-cancel-no-consumers.phpt | 4 ++-- tests/amqpqueue_attributes.phpt | 4 ++-- tests/amqpqueue_bind_basic.phpt | 4 ++-- ...mqpqueue_bind_basic_empty_routing_key.phpt | 4 ++-- ...mqpqueue_bind_basic_headers_arguments.phpt | 4 ++-- tests/amqpqueue_bind_null_routing_key.phpt | 4 ++-- tests/amqpqueue_cancel.phpt | 5 +++-- tests/amqpqueue_construct_basic.phpt | 4 ++-- tests/amqpqueue_consume_basic.phpt | 4 ++-- tests/amqpqueue_consume_multiple.phpt | 4 ++-- ...amqpqueue_consume_multiple_no_doubles.phpt | 4 ++-- tests/amqpqueue_consume_nonexistent.phpt | 4 ++-- .../amqpqueue_consume_null_consumer_key.phpt | 4 ++-- tests/amqpqueue_consume_timeout.phpt | 4 ++-- tests/amqpqueue_declare_basic.phpt | 4 ++-- tests/amqpqueue_declare_with_arguments.phpt | 4 ++-- ...pqueue_declare_with_stalled_reference.phpt | 2 +- tests/amqpqueue_delete_basic.phpt | 4 ++-- tests/amqpqueue_empty_name.phpt | 4 ++-- tests/amqpqueue_get_basic.phpt | 4 ++-- tests/amqpqueue_get_channel.phpt | 4 ++-- tests/amqpqueue_get_connection.phpt | 4 ++-- tests/amqpqueue_get_empty_body.phpt | 4 ++-- tests/amqpqueue_get_headers.phpt | 4 ++-- tests/amqpqueue_get_nonexistent.phpt | 4 ++-- tests/amqpqueue_headers_with_bool.phpt | 4 ++-- tests/amqpqueue_headers_with_float.phpt | 4 ++-- tests/amqpqueue_headers_with_null.phpt | 4 ++-- tests/amqpqueue_nack.phpt | 4 ++-- tests/amqpqueue_nested_arrays.phpt | 4 ++-- tests/amqpqueue_nested_headers.phpt | 4 ++-- tests/amqpqueue_purge_basic.phpt | 2 +- tests/amqpqueue_recover.phpt | 4 ++-- tests/amqpqueue_setArgument.phpt | 4 ++-- tests/amqpqueue_setFlags.phpt | 4 ++-- ...pqueue_unbind_basic_empty_routing_key.phpt | 4 ++-- ...pqueue_unbind_basic_headers_arguments.phpt | 4 ++-- tests/amqpqueue_var_dump.phpt | 4 ++-- tests/amqptimestamp.phpt | 2 +- tests/bug_17831.phpt | 4 ++-- tests/bug_19707.phpt | 4 ++-- tests/bug_19840.phpt | 2 +- tests/bug_351.phpt | 4 ++-- tests/bug_385.phpt | 4 ++-- tests/bug_61533.phpt | 4 ++-- tests/bug_62354.phpt | 2 +- tests/bug_gh147.phpt | 4 ++-- tests/bug_gh155_direct_reply_to.phpt | 4 ++-- tests/bug_gh50-1.phpt | 4 ++-- tests/bug_gh50-2.phpt | 4 ++-- tests/bug_gh50-3.phpt | 4 ++-- tests/bug_gh50-4.phpt | 4 ++-- tests/bug_gh53-2.phpt | 4 ++-- tests/bug_gh53.phpt | 4 ++-- tests/bug_gh72-1.phpt | 4 ++-- tests/bug_gh72-2.phpt | 4 ++-- tests/ini_validation_failure.phpt | 2 +- tests/package-version.phpt | 4 ++-- tests/serialize-custom-amqpvalue-errors.phpt | 4 ++-- tests/serialize-custom-amqpvalue.phpt | 4 ++-- tests/testtest.phpt | 2 +- 193 files changed, 379 insertions(+), 367 deletions(-) diff --git a/tests/003-channel-consumers.phpt b/tests/003-channel-consumers.phpt index faae6216..98fdb8fa 100644 --- a/tests/003-channel-consumers.phpt +++ b/tests/003-channel-consumers.phpt @@ -2,8 +2,8 @@ AMQPChannel - consumers --SKIPIF-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --INI-- amqp.global_prefetch_count=123 diff --git a/tests/amqpchannel_construct_ini_global_prefetch_size.phpt b/tests/amqpchannel_construct_ini_global_prefetch_size.phpt index 12a57f7e..b84e3f99 100644 --- a/tests/amqpchannel_construct_ini_global_prefetch_size.phpt +++ b/tests/amqpchannel_construct_ini_global_prefetch_size.phpt @@ -3,9 +3,9 @@ AMQPChannel - constructor with amqp.global_prefetch_size ini value set --SKIPIF-- setGlobalPrefetchSize(123); } catch (AMQPConnectionException $e) { if ($e->getCode() === 540 && strpos($e->getMessage(), "NOT_IMPLEMENTED") !== false) { - print "skip"; + print "skip prefetch size is not supported by the AMQP server"; } } } diff --git a/tests/amqpchannel_construct_ini_prefetch_count.phpt b/tests/amqpchannel_construct_ini_prefetch_count.phpt index 6f3a0d4b..1919362d 100644 --- a/tests/amqpchannel_construct_ini_prefetch_count.phpt +++ b/tests/amqpchannel_construct_ini_prefetch_count.phpt @@ -2,8 +2,8 @@ AMQPChannel - constructor with amqp.prefetch_count ini value set --SKIPIF-- --INI-- amqp.prefetch_count=123 diff --git a/tests/amqpchannel_construct_ini_prefetch_size.phpt b/tests/amqpchannel_construct_ini_prefetch_size.phpt index 41be13ee..6a1ad65a 100644 --- a/tests/amqpchannel_construct_ini_prefetch_size.phpt +++ b/tests/amqpchannel_construct_ini_prefetch_size.phpt @@ -3,9 +3,9 @@ AMQPChannel - constructor with amqp.prefetch_size ini value set --SKIPIF-- setPrefetchSize(123); } catch (AMQPConnectionException $e) { if ($e->getCode() === 540 && strpos($e->getMessage(), "NOT_IMPLEMENTED") !== false) { - print "skip"; + print "skip prefetch size is not supported by the AMQP server"; } } } diff --git a/tests/amqpchannel_getChannelId.phpt b/tests/amqpchannel_getChannelId.phpt index 26d2a08b..00e7da89 100644 --- a/tests/amqpchannel_getChannelId.phpt +++ b/tests/amqpchannel_getChannelId.phpt @@ -2,8 +2,8 @@ AMQPChannel::getChannelId --SKIPIF-- --FILE-- --FILE-- --FILE-- --FILE-- setGlobalPrefetchSize(123); } catch (AMQPConnectionException $e) { if ($e->getCode() === 540 && strpos($e->getMessage(), "NOT_IMPLEMENTED") !== false) { - print "skip"; + print "skip prefetch size is not supported by the AMQP server"; } } } diff --git a/tests/amqpchannel_set_prefetch_and_global_prefetch_count.phpt b/tests/amqpchannel_set_prefetch_and_global_prefetch_count.phpt index cd7e5247..30e956a9 100644 --- a/tests/amqpchannel_set_prefetch_and_global_prefetch_count.phpt +++ b/tests/amqpchannel_set_prefetch_and_global_prefetch_count.phpt @@ -2,8 +2,8 @@ AMQPChannel - Setting both consumer and channel wide prefetch counts. --SKIPIF-- --FILE-- setGlobalPrefetchSize(123); } catch (AMQPConnectionException $e) { if ($e->getCode() === 540 && strpos($e->getMessage(), "NOT_IMPLEMENTED") !== false) { - print "skip"; + print "skip prefetch size is not supported by the AMQP server"; } } } diff --git a/tests/amqpchannel_set_prefetch_count.phpt b/tests/amqpchannel_set_prefetch_count.phpt index 46716d97..2f4b3d1d 100644 --- a/tests/amqpchannel_set_prefetch_count.phpt +++ b/tests/amqpchannel_set_prefetch_count.phpt @@ -2,8 +2,8 @@ AMQPChannel::setPrefetchCount --SKIPIF-- --FILE-- setPrefetchSize(123); } catch (AMQPConnectionException $e) { if ($e->getCode() === 540 && strpos($e->getMessage(), "NOT_IMPLEMENTED") !== false) { - print "skip"; + print "skip prefetch size is not supported by the AMQP server"; } } } diff --git a/tests/amqpchannel_slots_usage.phpt b/tests/amqpchannel_slots_usage.phpt index 5186f633..5b09ff18 100644 --- a/tests/amqpchannel_slots_usage.phpt +++ b/tests/amqpchannel_slots_usage.phpt @@ -2,8 +2,8 @@ AMQPChannel slots usage --SKIPIF-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --INI-- amqp.read_timeout=202.202 diff --git a/tests/amqpconnection_construct_ini_timeout.phpt b/tests/amqpconnection_construct_ini_timeout.phpt index cb5b81a1..197da239 100644 --- a/tests/amqpconnection_construct_ini_timeout.phpt +++ b/tests/amqpconnection_construct_ini_timeout.phpt @@ -2,8 +2,8 @@ AMQPConnection constructor with amqp.timeout ini value set --SKIPIF-- --INI-- amqp.timeout=101.101 diff --git a/tests/amqpconnection_construct_ini_timeout_and_read_timeout.phpt b/tests/amqpconnection_construct_ini_timeout_and_read_timeout.phpt index 49047161..eef96ac2 100644 --- a/tests/amqpconnection_construct_ini_timeout_and_read_timeout.phpt +++ b/tests/amqpconnection_construct_ini_timeout_and_read_timeout.phpt @@ -2,8 +2,8 @@ AMQPConnection constructor with both amqp.timeout and amqp.read_timeout ini values set --SKIPIF-- --INI-- amqp.timeout = 101.101 diff --git a/tests/amqpconnection_construct_ini_timeout_default.phpt b/tests/amqpconnection_construct_ini_timeout_default.phpt index 761f82b8..aef63ac6 100644 --- a/tests/amqpconnection_construct_ini_timeout_default.phpt +++ b/tests/amqpconnection_construct_ini_timeout_default.phpt @@ -2,8 +2,8 @@ AMQPConnection constructor with amqp.timeout ini value set in code to it default value --SKIPIF-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- diff --git a/tests/amqpexchange_publish_confirms_consume.phpt b/tests/amqpexchange_publish_confirms_consume.phpt index f98008af..7900a34a 100644 --- a/tests/amqpexchange_publish_confirms_consume.phpt +++ b/tests/amqpexchange_publish_confirms_consume.phpt @@ -2,8 +2,9 @@ AMQPExchange::publish() - publish in conform mode and handle conforms with AMQPQueue::consume() method --SKIPIF-- --FILE-- --FILE-- --FILE-- diff --git a/tests/amqpexchange_publish_mandatory_consume.phpt b/tests/amqpexchange_publish_mandatory_consume.phpt index d1da3862..fe8fe4da 100644 --- a/tests/amqpexchange_publish_mandatory_consume.phpt +++ b/tests/amqpexchange_publish_mandatory_consume.phpt @@ -2,8 +2,9 @@ AMQPExchange::publish() - publish unroutable with mandatory flag and handle them with AMQPQueue::consume() method --SKIPIF-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- lFjH_sfr^5oZ(x8zYDGzEUU6oAoyt2%q{Jh-Myb^`7#G=f^q?}Zk-s04fjdRwq0|0VjBA);N delta 17 ZcmbO!cuHVG0ke`d*TgBB8(*(u2LLyW295v# diff --git a/tests/amqpexchange_publish_with_properties.phpt b/tests/amqpexchange_publish_with_properties.phpt index 4bc4bc72..cba3b0f8 100644 --- a/tests/amqpexchange_publish_with_properties.phpt +++ b/tests/amqpexchange_publish_with_properties.phpt @@ -2,8 +2,8 @@ AMQPExchange publish with properties --SKIPIF-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --FILE-- --INI-- amqp.host=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx diff --git a/tests/package-version.phpt b/tests/package-version.phpt index 0a53390b..5b12f21e 100644 --- a/tests/package-version.phpt +++ b/tests/package-version.phpt @@ -2,8 +2,8 @@ Compare version in package.xml and module --SKIPIF-- --FILE-- --FILE-- --FILE-- $skipCode] = $matches; - if (!preg_match('/if\s*\(!extension_loaded\("amqp"\)\)\s*\{?\s*print "skip";/', $skipCode)) { + if (!preg_match('/if\s*\(!extension_loaded\("amqp"\)\)\s*\{?\s*print "skip AMQP extension is not loaded";/', $skipCode)) { printf("%s --SKIP-- does not check for the extension being present\n", basename($test)); continue; } From 18469b4fa740d0928cbd5d7b7d6942a65c35a955 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 12 Oct 2023 12:29:19 +0200 Subject: [PATCH 089/147] Bump slevomat/coding-standard from 8.13.4 to 8.14.1 (#501) --- composer.lock | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/composer.lock b/composer.lock index d0ecb72c..194f2ca0 100644 --- a/composer.lock +++ b/composer.lock @@ -87,16 +87,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.24.1", + "version": "1.24.2", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "9f854d275c2dbf84915a5c0ec9a2d17d2cd86b01" + "reference": "bcad8d995980440892759db0c32acae7c8e79442" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/9f854d275c2dbf84915a5c0ec9a2d17d2cd86b01", - "reference": "9f854d275c2dbf84915a5c0ec9a2d17d2cd86b01", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/bcad8d995980440892759db0c32acae7c8e79442", + "reference": "bcad8d995980440892759db0c32acae7c8e79442", "shasum": "" }, "require": { @@ -128,38 +128,38 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.1" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.2" }, - "time": "2023-09-18T12:18:02+00:00" + "time": "2023-09-26T12:28:12+00:00" }, { "name": "slevomat/coding-standard", - "version": "8.13.4", + "version": "8.14.1", "source": { "type": "git", "url": "https://github.com/slevomat/coding-standard.git", - "reference": "4b2af2fb17773656d02fbfb5d18024ebd19fe322" + "reference": "fea1fd6f137cc84f9cba0ae30d549615dbc6a926" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/4b2af2fb17773656d02fbfb5d18024ebd19fe322", - "reference": "4b2af2fb17773656d02fbfb5d18024ebd19fe322", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/fea1fd6f137cc84f9cba0ae30d549615dbc6a926", + "reference": "fea1fd6f137cc84f9cba0ae30d549615dbc6a926", "shasum": "" }, "require": { "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7 || ^1.0", "php": "^7.2 || ^8.0", - "phpstan/phpdoc-parser": "^1.23.0", + "phpstan/phpdoc-parser": "^1.23.1", "squizlabs/php_codesniffer": "^3.7.1" }, "require-dev": { "phing/phing": "2.17.4", "php-parallel-lint/php-parallel-lint": "1.3.2", - "phpstan/phpstan": "1.10.26", - "phpstan/phpstan-deprecation-rules": "1.1.3", - "phpstan/phpstan-phpunit": "1.3.13", + "phpstan/phpstan": "1.10.37", + "phpstan/phpstan-deprecation-rules": "1.1.4", + "phpstan/phpstan-phpunit": "1.3.14", "phpstan/phpstan-strict-rules": "1.5.1", - "phpunit/phpunit": "7.5.20|8.5.21|9.6.8|10.2.6" + "phpunit/phpunit": "8.5.21|9.6.8|10.3.5" }, "type": "phpcodesniffer-standard", "extra": { @@ -183,7 +183,7 @@ ], "support": { "issues": "https://github.com/slevomat/coding-standard/issues", - "source": "https://github.com/slevomat/coding-standard/tree/8.13.4" + "source": "https://github.com/slevomat/coding-standard/tree/8.14.1" }, "funding": [ { @@ -195,7 +195,7 @@ "type": "tidelift" } ], - "time": "2023-07-25T10:28:55+00:00" + "time": "2023-10-08T07:28:08+00:00" }, { "name": "squizlabs/php_codesniffer", From 6539de511ec73a8eac175c56966014962c32cfa4 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Thu, 12 Oct 2023 12:53:19 +0200 Subject: [PATCH 090/147] Fixes in stub comments --- stubs/AMQPChannel.php | 4 ++-- stubs/AMQPConnection.php | 12 ++++++------ stubs/AMQPQueue.php | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/stubs/AMQPChannel.php b/stubs/AMQPChannel.php index 5ce11422..59bdc741 100644 --- a/stubs/AMQPChannel.php +++ b/stubs/AMQPChannel.php @@ -247,7 +247,7 @@ public function confirmSelect(): void * function ack_callback(int $delivery_tag, bool $multiple) : bool; * function nack_callback(int $delivery_tag, bool $multiple, bool $requeue) : bool; * - * and should return boolean false when wait loop should be canceled. + * and should return boolean FALSE when wait loop should be canceled. * * Note, basic.nack server method will only be delivered if an internal error occurs in the Erlang process * responsible for a queue (see https://www.rabbitmq.com/confirms.html for details). @@ -281,7 +281,7 @@ public function waitForConfirm(float $timeout = 0.0): void * AMQPBasicProperties $properties, * string $body) : bool; * - * and should return boolean false when wait loop should be canceled. + * and should return boolean FALSE when wait loop should be canceled. */ public function setReturnCallback(?callable $returnCallback): void { diff --git a/stubs/AMQPConnection.php b/stubs/AMQPConnection.php index e5440f7d..19c3a175 100644 --- a/stubs/AMQPConnection.php +++ b/stubs/AMQPConnection.php @@ -54,10 +54,10 @@ class AMQPConnection * 'vhost' => amqp.vhost The virtual host on the host. Note: Max 128 characters. * 'login' => amqp.login The login name to use. Note: Max 128 characters. * 'password' => amqp.password Password. Note: Max 128 characters. - * 'read_timeout' => Timeout in for income activity. Note: 0 or greater seconds. May be fractional. - * 'write_timeout' => Timeout in for outcome activity. Note: 0 or greater seconds. May be fractional. + * 'read_timeout' => Timeout in for consume. Note: 0 or greater seconds. May be fractional. + * 'write_timeout' => Timeout in for publish. Note: 0 or greater seconds. May be fractional. * 'connect_timeout' => Connection timeout. Note: 0 or greater seconds. May be fractional. - * 'rpc_timeout' => RPC timeout. Note: 0 or greater seconds. May be fractional. + * 'rpc_timeout' => Timeout for RPC-style AMQP methods. Note: 0 or greater seconds. May be fractional. * * Connection tuning options (see http://www.rabbitmq.com/amqp-0-9-1-reference.html#connection.tune for details): * 'channel_max' => Specifies highest channel number that the server permits. 0 means standard extension limit @@ -91,7 +91,7 @@ public function __construct(array $credentials = []) * Cannot reliably detect dropped connections or unusual socket errors, as it does not actively * engage the socket. * - * @return boolean True if connected, false otherwise. + * @return boolean TRUE if connected, FALSE otherwise. */ public function isConnected(): bool { @@ -100,10 +100,10 @@ public function isConnected(): bool /** * Whether connection persistent. * - * When no connection is established, it will always return false. The same disclaimer as for + * When no connection is established, it will always return FALSE. The same disclaimer as for * {@see AMQPConnection::isConnected()} applies. * - * @return boolean True if persistently connected, false otherwise. + * @return boolean TRUE if persistently connected, FALSE otherwise. */ public function isPersistent(): bool { diff --git a/stubs/AMQPQueue.php b/stubs/AMQPQueue.php index bf9225ca..18e95d25 100644 --- a/stubs/AMQPQueue.php +++ b/stubs/AMQPQueue.php @@ -178,7 +178,7 @@ public function delete(?int $flags = null): int * Retrieve the next message from the queue. * * Retrieve the next available message from the queue. If no messages are - * present in the queue, this function will return FALSE immediately. This + * present in the queue, this function will return NULL immediately. This * is a non blocking alternative to the AMQPQueue::consume() method. * Currently, the only supported flag for the flags parameter is * AMQP_AUTOACK. If this flag is passed in, then the message returned will @@ -265,11 +265,11 @@ public function reject(int $deliveryTag, ?int $flags = null): void * * Recover all the unacknowledged messages delivered to the current consumer. * If $requeue is true, the broker can redeliver the messages to different - * consumers. If $requeue is false, it can only redeliver it to the current + * consumers. If $requeue is FALSE, it can only redeliver it to the current * consumer. RabbitMQ does not implement $request = false. * This method exposes `basic.recover` from the AMQP spec. * - * @param bool $requeue If true, deliver to any consumer, if false, deliver to the current consumer only + * @param bool $requeue If TRUE, deliver to any consumer, if FALSE, deliver to the current consumer only * @throws AMQPConnectionException If the connection to the broker was lost. * @throws AMQPChannelException If the channel is not open. */ From fd5be1789a7c04cbeffd64ec8a6c0403f7a1f1db Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 12 Oct 2023 13:28:31 +0200 Subject: [PATCH 091/147] Bump actions/checkout from 4.0.0 to 4.1.0 (#499) --- .github/workflows/test.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index d077017c..6d9f06f9 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -30,7 +30,7 @@ jobs: concurrent_skipping: 'same_content_newer' - name: Checkout - uses: actions/checkout@v4.0.0 + uses: actions/checkout@v4.1.0 - name: Prepare matrix id: matrix @@ -53,7 +53,7 @@ jobs: install: clang-format-17 - name: Checkout - uses: actions/checkout@v4.0.0 + uses: actions/checkout@v4.1.0 - name: Check style run: ./infra/tools/pamqp-format-check @@ -71,7 +71,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v4.0.0 + uses: actions/checkout@v4.1.0 - name: Install packages uses: awalsh128/cache-apt-pkgs-action@v1.3.0 @@ -130,7 +130,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v4.0.0 + uses: actions/checkout@v4.1.0 - name: Configure hostnames run: sudo echo "127.0.0.1 ${{ env.PHP_AMQP_SSL_HOST }}" | sudo tee -a /etc/hosts From e5bd9096c06326f48e0a3fc185efca16fb8caeb9 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Thu, 12 Oct 2023 15:04:52 +0200 Subject: [PATCH 092/147] Semantically sort changelog --- infra/tools/functions.php | 40 +++++++++++++++++++++++++++++- infra/tools/pamqp-release-cut | 2 +- infra/tools/pamqp-release-finalize | 2 +- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/infra/tools/functions.php b/infra/tools/functions.php index 98ff884f..93c60358 100644 --- a/infra/tools/functions.php +++ b/infra/tools/functions.php @@ -1,6 +1,6 @@ $rightPriority; + } + + return $left <=> $right; +} + +function getChangelogPriority(string $line): int +{ + $lineWithoutDash = substr($line, 3); + + if (strStartsWithCaseInsensitive($lineWithoutDash, 'bump')) { + return 100; + } + + if (strStartsWithCaseInsensitive($lineWithoutDash, 'refactor')) { + return 50; + } + + if (strStartsWithCaseInsensitive($lineWithoutDash, 'fix')) { + return 30; + } + + return 0; +} + +function strStartsWithCaseInsensitive(string $haystack, string $needle): bool +{ + return strnatcasecmp(substr($haystack, 0, strlen($needle)), $needle) === 0; +} + function archiveRelease(): void { $dom = packageXml(); diff --git a/infra/tools/pamqp-release-cut b/infra/tools/pamqp-release-cut index 98944261..4e1c3218 100755 --- a/infra/tools/pamqp-release-cut +++ b/infra/tools/pamqp-release-cut @@ -1,7 +1,7 @@ #!/usr/bin/env php Date: Thu, 12 Oct 2023 15:06:44 +0200 Subject: [PATCH 093/147] [RM] releasing version 2.1.1 --- package.xml | 30 +++++++++++++++++++++--------- php_amqp_version.h | 10 +++++----- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/package.xml b/package.xml index 2508f2a8..6916dad5 100644 --- a/package.xml +++ b/package.xml @@ -22,22 +22,33 @@ pinepain@gmail.com yes - 2023-09-07 - + 2023-10-12 + - 2.2.0dev - 2.2.0dev + 2.1.1 + 2.1.1 - devel - devel + stable + stable PHP License - ) (https://github.com/php-amqp/php-amqp/issues/502) + - FIX: #494 Param "verify" always true (Daniel Kozak ) (https://github.com/php-amqp/php-amqp/issues/497) + - Remove assert on undefined variable (Remi Collet ) (https://github.com/php-amqp/php-amqp/issues/486) + - Semantically sort changelog (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/e5bd909) + - Set custom PHP executable dynamically (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/503) + - Fixes in stub comments (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/6539de5) + - Refactor test skipping (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/504) + - Bump actions/checkout from 4.0.0 to 4.1.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/499) + - Bump phpstan/phpdoc-parser from 1.23.1 to 1.24.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/491) + - Bump phpstan/phpdoc-parser from 1.24.0 to 1.24.1 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/495) + - Bump shivammathur/setup-php from 2.25.5 to 2.26.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/493) + - Bump slevomat/coding-standard from 8.13.4 to 8.14.1 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/501) + - Bump symplify/easy-coding-standard from 12.0.7 to 12.0.8 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/492) For a complete list of changes see: -https://github.com/php-amqp/php-amqp/compare/v2.1.0...latest -]]> +https://github.com/php-amqp/php-amqp/compare/v2.1.0...v2.1.1]]> @@ -114,6 +125,7 @@ https://github.com/php-amqp/php-amqp/compare/v2.1.0...latest + diff --git a/php_amqp_version.h b/php_amqp_version.h index 61c2d46c..1358f862 100644 --- a/php_amqp_version.h +++ b/php_amqp_version.h @@ -1,6 +1,6 @@ #define PHP_AMQP_VERSION_MAJOR 2 -#define PHP_AMQP_VERSION_MINOR 2 -#define PHP_AMQP_VERSION_PATCH 0 -#define PHP_AMQP_VERSION_EXTRA "dev" -#define PHP_AMQP_VERSION "2.2.0dev" -#define PHP_AMQP_VERSION_ID 20200 +#define PHP_AMQP_VERSION_MINOR 1 +#define PHP_AMQP_VERSION_PATCH 1 +#define PHP_AMQP_VERSION_EXTRA "" +#define PHP_AMQP_VERSION "2.1.1" +#define PHP_AMQP_VERSION_ID 20101 From fa97019eeffb4d2a98a2aebb8679a690a7f5b725 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 18 Oct 2023 16:50:46 +0200 Subject: [PATCH 094/147] Bump actions/checkout from 4.1.0 to 4.1.1 (#506) --- .github/workflows/test.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 6d9f06f9..8adbe588 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -30,7 +30,7 @@ jobs: concurrent_skipping: 'same_content_newer' - name: Checkout - uses: actions/checkout@v4.1.0 + uses: actions/checkout@v4.1.1 - name: Prepare matrix id: matrix @@ -53,7 +53,7 @@ jobs: install: clang-format-17 - name: Checkout - uses: actions/checkout@v4.1.0 + uses: actions/checkout@v4.1.1 - name: Check style run: ./infra/tools/pamqp-format-check @@ -71,7 +71,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v4.1.0 + uses: actions/checkout@v4.1.1 - name: Install packages uses: awalsh128/cache-apt-pkgs-action@v1.3.0 @@ -130,7 +130,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v4.1.0 + uses: actions/checkout@v4.1.1 - name: Configure hostnames run: sudo echo "127.0.0.1 ${{ env.PHP_AMQP_SSL_HOST }}" | sudo tee -a /etc/hosts From 82374fe0012deff3c9b3512b238223acc83c8438 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 24 Oct 2023 11:29:11 +0200 Subject: [PATCH 095/147] Bump fkirc/skip-duplicate-actions from 5.3.0 to 5.3.1 (#507) --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 8adbe588..b94c16fb 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -23,7 +23,7 @@ jobs: steps: - id: skip_check name: Prevent duplicate builds - uses: fkirc/skip-duplicate-actions@v5.3.0 + uses: fkirc/skip-duplicate-actions@v5.3.1 with: skip_after_successful_duplicate: 'true' cancel_others: 'true' From 062c539caf86db39d23d887e3ae61e39592de3b9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 31 Oct 2023 08:54:19 +0100 Subject: [PATCH 096/147] Bump awalsh128/cache-apt-pkgs-action from 1.3.0 to 1.3.1 (#509) --- .github/workflows/test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index b94c16fb..5c5a06d3 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -74,7 +74,7 @@ jobs: uses: actions/checkout@v4.1.1 - name: Install packages - uses: awalsh128/cache-apt-pkgs-action@v1.3.0 + uses: awalsh128/cache-apt-pkgs-action@v1.3.1 with: packages: cmake valgrind @@ -142,7 +142,7 @@ jobs: run: docker compose up -d rabbitmq - name: Install packages - uses: awalsh128/cache-apt-pkgs-action@v1.3.0 + uses: awalsh128/cache-apt-pkgs-action@v1.3.1 with: packages: cmake valgrind ${{ matrix.compiler }} version: ${{ (matrix.librabbitmq-version == '0.10.0' || matrix.librabbitmq-version == '0.9.0' || matrix.librabbitmq-version == '0.8.0') && 'ubuntu-20.04' || 'ubuntu-22.04' }} From dcb45f6c70fbc9ea66c5ef4d5b5a3f16a380238e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 2 Nov 2023 09:45:45 +0100 Subject: [PATCH 097/147] Bump shivammathur/setup-php from 2.26.0 to 2.27.0 (#510) --- .github/workflows/test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5c5a06d3..6471e7f8 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -79,7 +79,7 @@ jobs: packages: cmake valgrind - name: Setup PHP - uses: shivammathur/setup-php@2.26.0 + uses: shivammathur/setup-php@2.27.0 with: php-version: ${{ matrix.php-version }} extensions: json @@ -148,7 +148,7 @@ jobs: version: ${{ (matrix.librabbitmq-version == '0.10.0' || matrix.librabbitmq-version == '0.9.0' || matrix.librabbitmq-version == '0.8.0') && 'ubuntu-20.04' || 'ubuntu-22.04' }} - name: Setup PHP - uses: shivammathur/setup-php@2.26.0 + uses: shivammathur/setup-php@2.27.0 with: php-version: ${{ matrix.php-version }} coverage: none From 10b3da82f9ff202d794a92e2574873aa5774bf2e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 9 Nov 2023 12:25:19 +0700 Subject: [PATCH 098/147] Bump shivammathur/setup-php from 2.27.0 to 2.27.1 (#512) --- .github/workflows/test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 6471e7f8..6bfc1cff 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -79,7 +79,7 @@ jobs: packages: cmake valgrind - name: Setup PHP - uses: shivammathur/setup-php@2.27.0 + uses: shivammathur/setup-php@2.27.1 with: php-version: ${{ matrix.php-version }} extensions: json @@ -148,7 +148,7 @@ jobs: version: ${{ (matrix.librabbitmq-version == '0.10.0' || matrix.librabbitmq-version == '0.9.0' || matrix.librabbitmq-version == '0.8.0') && 'ubuntu-20.04' || 'ubuntu-22.04' }} - name: Setup PHP - uses: shivammathur/setup-php@2.27.0 + uses: shivammathur/setup-php@2.27.1 with: php-version: ${{ matrix.php-version }} coverage: none From 2f85cfc743310f90071681d49e2e5f7df5d442e1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 23 Nov 2023 13:12:38 +0100 Subject: [PATCH 099/147] Bump phpstan/phpdoc-parser from 1.24.2 to 1.24.3 (#513) --- composer.lock | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.lock b/composer.lock index 194f2ca0..35731238 100644 --- a/composer.lock +++ b/composer.lock @@ -87,16 +87,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.24.2", + "version": "1.24.3", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "bcad8d995980440892759db0c32acae7c8e79442" + "reference": "12f01d214f1c73b9c91fdb3b1c415e4c70652083" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/bcad8d995980440892759db0c32acae7c8e79442", - "reference": "bcad8d995980440892759db0c32acae7c8e79442", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/12f01d214f1c73b9c91fdb3b1c415e4c70652083", + "reference": "12f01d214f1c73b9c91fdb3b1c415e4c70652083", "shasum": "" }, "require": { @@ -128,9 +128,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.2" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.3" }, - "time": "2023-09-26T12:28:12+00:00" + "time": "2023-11-18T20:15:32+00:00" }, { "name": "slevomat/coding-standard", @@ -326,5 +326,5 @@ "ext-dom": "*", "ext-simplexml": "*" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } From 6113d102999957b6b69ea69ff7cea41046867d73 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 28 Nov 2023 08:55:47 +0100 Subject: [PATCH 100/147] Bump phpstan/phpdoc-parser from 1.24.3 to 1.24.4 (#516) Bumps [phpstan/phpdoc-parser](https://github.com/phpstan/phpdoc-parser) from 1.24.3 to 1.24.4. - [Release notes](https://github.com/phpstan/phpdoc-parser/releases) - [Commits](https://github.com/phpstan/phpdoc-parser/compare/1.24.3...1.24.4) --- updated-dependencies: - dependency-name: phpstan/phpdoc-parser dependency-type: indirect update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 35731238..6ee34430 100644 --- a/composer.lock +++ b/composer.lock @@ -87,16 +87,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.24.3", + "version": "1.24.4", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "12f01d214f1c73b9c91fdb3b1c415e4c70652083" + "reference": "6bd0c26f3786cd9b7c359675cb789e35a8e07496" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/12f01d214f1c73b9c91fdb3b1c415e4c70652083", - "reference": "12f01d214f1c73b9c91fdb3b1c415e4c70652083", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/6bd0c26f3786cd9b7c359675cb789e35a8e07496", + "reference": "6bd0c26f3786cd9b7c359675cb789e35a8e07496", "shasum": "" }, "require": { @@ -128,9 +128,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.3" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.4" }, - "time": "2023-11-18T20:15:32+00:00" + "time": "2023-11-26T18:29:22+00:00" }, { "name": "slevomat/coding-standard", From 2b5516cc1127601756445ddcdb23d1cfe2cd9485 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 28 Nov 2023 08:55:58 +0100 Subject: [PATCH 101/147] Bump shivammathur/setup-php from 2.27.1 to 2.28.0 (#515) --- .github/workflows/test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 6bfc1cff..82bed358 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -79,7 +79,7 @@ jobs: packages: cmake valgrind - name: Setup PHP - uses: shivammathur/setup-php@2.27.1 + uses: shivammathur/setup-php@2.28.0 with: php-version: ${{ matrix.php-version }} extensions: json @@ -148,7 +148,7 @@ jobs: version: ${{ (matrix.librabbitmq-version == '0.10.0' || matrix.librabbitmq-version == '0.9.0' || matrix.librabbitmq-version == '0.8.0') && 'ubuntu-20.04' || 'ubuntu-22.04' }} - name: Setup PHP - uses: shivammathur/setup-php@2.27.1 + uses: shivammathur/setup-php@2.28.0 with: php-version: ${{ matrix.php-version }} coverage: none From a37c5f19bb4f92ad48ae07925ceea8703044682b Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Fri, 1 Dec 2023 14:30:12 +0100 Subject: [PATCH 102/147] Only restart on failure --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index ea82ecd6..c0b9a1f4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -32,7 +32,7 @@ services: condition: service_completed_successfully extra_hosts: - "${PHP_AMQP_SSL_HOST}:127.0.0.1" - restart: always + restart: on-failure ca: build: From f992b308863f9352f5cc63cfa04c8d7d72b35931 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:15:32 +0100 Subject: [PATCH 103/147] Bump symplify/easy-coding-standard from 12.0.8 to 12.0.9 (#517) Bumps [symplify/easy-coding-standard](https://github.com/easy-coding-standard/easy-coding-standard) from 12.0.8 to 12.0.9. - [Release notes](https://github.com/easy-coding-standard/easy-coding-standard/releases) - [Commits](https://github.com/easy-coding-standard/easy-coding-standard/compare/12.0.8...12.0.9) --- updated-dependencies: - dependency-name: symplify/easy-coding-standard dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 6ee34430..52a48174 100644 --- a/composer.lock +++ b/composer.lock @@ -256,16 +256,16 @@ }, { "name": "symplify/easy-coding-standard", - "version": "12.0.8", + "version": "12.0.9", "source": { "type": "git", "url": "https://github.com/easy-coding-standard/easy-coding-standard.git", - "reference": "99d87d188acc712dd6655ee946569f823cfeff69" + "reference": "24b7b28c25d698e64496c4d19c798ccd01617c7d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/99d87d188acc712dd6655ee946569f823cfeff69", - "reference": "99d87d188acc712dd6655ee946569f823cfeff69", + "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/24b7b28c25d698e64496c4d19c798ccd01617c7d", + "reference": "24b7b28c25d698e64496c4d19c798ccd01617c7d", "shasum": "" }, "require": { @@ -298,7 +298,7 @@ ], "support": { "issues": "https://github.com/easy-coding-standard/easy-coding-standard/issues", - "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.0.8" + "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.0.9" }, "funding": [ { @@ -310,7 +310,7 @@ "type": "github" } ], - "time": "2023-09-08T10:17:14+00:00" + "time": "2023-11-29T09:35:09+00:00" } ], "aliases": [], From 5548760c9881085f7d967e0c77a7055c2f24bf74 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Fri, 1 Dec 2023 18:15:21 +0100 Subject: [PATCH 104/147] Ignore setfacl errors --- infra/tools/pamqp-certificates-generate | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infra/tools/pamqp-certificates-generate b/infra/tools/pamqp-certificates-generate index dd74a2aa..68fd78c9 100755 --- a/infra/tools/pamqp-certificates-generate +++ b/infra/tools/pamqp-certificates-generate @@ -6,7 +6,7 @@ set -o nounset cert_dir="${1:-}" if test -z "$cert_dir"; then - echo "`basename $0` " + echo "$(basename $0) " exit 1 fi @@ -36,4 +36,4 @@ mkdir -p $cert_dir/testca/private $cert_dir/server $cert_dir/sasl-client $cert_d # Set permissions for the different images consuming the certificates # - 100 is the UID of the rabbitmq user of the rabbitmq image that runs the rabbitmq process # - 1001 is the UID of the GitHub Action runner user that runs the tests -setfacl -R -m u:100:rX -m u:1001:rX $cert_dir +setfacl -R -m u:100:rX -m u:1001:rX $cert_dir || true From e596945abb3b9e078e3f3489ba9d1bb29bbf93a9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 5 Dec 2023 07:51:08 +0100 Subject: [PATCH 105/147] Bump symplify/easy-coding-standard from 12.0.9 to 12.0.11 (#518) --- composer.lock | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.lock b/composer.lock index 52a48174..791104d8 100644 --- a/composer.lock +++ b/composer.lock @@ -256,16 +256,16 @@ }, { "name": "symplify/easy-coding-standard", - "version": "12.0.9", + "version": "12.0.11", "source": { "type": "git", "url": "https://github.com/easy-coding-standard/easy-coding-standard.git", - "reference": "24b7b28c25d698e64496c4d19c798ccd01617c7d" + "reference": "5f34a99d035b4eef048857ec47d2035140871f50" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/24b7b28c25d698e64496c4d19c798ccd01617c7d", - "reference": "24b7b28c25d698e64496c4d19c798ccd01617c7d", + "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/5f34a99d035b4eef048857ec47d2035140871f50", + "reference": "5f34a99d035b4eef048857ec47d2035140871f50", "shasum": "" }, "require": { @@ -273,7 +273,7 @@ }, "conflict": { "friendsofphp/php-cs-fixer": "<3.0", - "squizlabs/php_codesniffer": "<3.6", + "phpcsstandards/php_codesniffer": "<3.6", "symplify/coding-standard": "<11.3" }, "bin": [ @@ -298,7 +298,7 @@ ], "support": { "issues": "https://github.com/easy-coding-standard/easy-coding-standard/issues", - "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.0.9" + "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.0.11" }, "funding": [ { @@ -310,7 +310,7 @@ "type": "github" } ], - "time": "2023-11-29T09:35:09+00:00" + "time": "2023-12-02T09:38:08+00:00" } ], "aliases": [], From 593862dbbb099bf7d9ae9762678ada38601e6ad2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 8 Dec 2023 07:23:43 +0100 Subject: [PATCH 106/147] Bump symplify/easy-coding-standard from 12.0.11 to 12.0.13 (#519) --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 791104d8..e446e2a1 100644 --- a/composer.lock +++ b/composer.lock @@ -256,16 +256,16 @@ }, { "name": "symplify/easy-coding-standard", - "version": "12.0.11", + "version": "12.0.13", "source": { "type": "git", "url": "https://github.com/easy-coding-standard/easy-coding-standard.git", - "reference": "5f34a99d035b4eef048857ec47d2035140871f50" + "reference": "d15707b14d50b7cb6d656f7a7a5e5b9a17099b3c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/5f34a99d035b4eef048857ec47d2035140871f50", - "reference": "5f34a99d035b4eef048857ec47d2035140871f50", + "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/d15707b14d50b7cb6d656f7a7a5e5b9a17099b3c", + "reference": "d15707b14d50b7cb6d656f7a7a5e5b9a17099b3c", "shasum": "" }, "require": { @@ -298,7 +298,7 @@ ], "support": { "issues": "https://github.com/easy-coding-standard/easy-coding-standard/issues", - "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.0.11" + "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.0.13" }, "funding": [ { @@ -310,7 +310,7 @@ "type": "github" } ], - "time": "2023-12-02T09:38:08+00:00" + "time": "2023-12-07T09:18:07+00:00" } ], "aliases": [], From 0ecabc407556438ca11683130516223d28113a57 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 9 Dec 2023 00:40:52 +0100 Subject: [PATCH 107/147] Bump squizlabs/php_codesniffer from 3.7.2 to 3.8.0 (#520) Bumps [squizlabs/php_codesniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer) from 3.7.2 to 3.8.0. - [Release notes](https://github.com/PHPCSStandards/PHP_CodeSniffer/releases) - [Changelog](https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/CHANGELOG.md) - [Commits](https://github.com/PHPCSStandards/PHP_CodeSniffer/compare/3.7.2...3.8.0) --- updated-dependencies: - dependency-name: squizlabs/php_codesniffer dependency-type: indirect update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.lock | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/composer.lock b/composer.lock index e446e2a1..2bea9463 100644 --- a/composer.lock +++ b/composer.lock @@ -199,16 +199,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.7.2", + "version": "3.8.0", "source": { "type": "git", - "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879" + "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", + "reference": "5805f7a4e4958dbb5e944ef1e6edae0a303765e7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ed8e00df0a83aa96acf703f8c2979ff33341f879", - "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/5805f7a4e4958dbb5e944ef1e6edae0a303765e7", + "reference": "5805f7a4e4958dbb5e944ef1e6edae0a303765e7", "shasum": "" }, "require": { @@ -218,7 +218,7 @@ "php": ">=5.4.0" }, "require-dev": { - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" }, "bin": [ "bin/phpcs", @@ -237,22 +237,45 @@ "authors": [ { "name": "Greg Sherwood", - "role": "lead" + "role": "Former lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "Current lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" } ], "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", - "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", "keywords": [ "phpcs", "standards", "static analysis" ], "support": { - "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", - "source": "https://github.com/squizlabs/PHP_CodeSniffer", - "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", + "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", + "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" }, - "time": "2023-02-22T23:07:41+00:00" + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2023-12-08T12:32:31+00:00" }, { "name": "symplify/easy-coding-standard", From 4a4194300e5c1519b4a23dd33d3b37b9d0d9e7b8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Dec 2023 10:29:38 +0100 Subject: [PATCH 108/147] Bump phpstan/phpdoc-parser from 1.24.4 to 1.24.5 (#521) Bumps [phpstan/phpdoc-parser](https://github.com/phpstan/phpdoc-parser) from 1.24.4 to 1.24.5. - [Release notes](https://github.com/phpstan/phpdoc-parser/releases) - [Commits](https://github.com/phpstan/phpdoc-parser/compare/1.24.4...1.24.5) --- updated-dependencies: - dependency-name: phpstan/phpdoc-parser dependency-type: indirect update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 2bea9463..c93e478a 100644 --- a/composer.lock +++ b/composer.lock @@ -87,16 +87,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.24.4", + "version": "1.24.5", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "6bd0c26f3786cd9b7c359675cb789e35a8e07496" + "reference": "fedf211ff14ec8381c9bf5714e33a7a552dd1acc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/6bd0c26f3786cd9b7c359675cb789e35a8e07496", - "reference": "6bd0c26f3786cd9b7c359675cb789e35a8e07496", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/fedf211ff14ec8381c9bf5714e33a7a552dd1acc", + "reference": "fedf211ff14ec8381c9bf5714e33a7a552dd1acc", "shasum": "" }, "require": { @@ -128,9 +128,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.4" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.5" }, - "time": "2023-11-26T18:29:22+00:00" + "time": "2023-12-16T09:33:33+00:00" }, { "name": "slevomat/coding-standard", From 29aa5f76521b94d1abc00b19d2f5bd9a356f3a8f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 8 Jan 2024 12:45:46 +0700 Subject: [PATCH 109/147] Bump phpstan/phpdoc-parser from 1.24.5 to 1.25.0 (#524) --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index c93e478a..75b68c6f 100644 --- a/composer.lock +++ b/composer.lock @@ -87,16 +87,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.24.5", + "version": "1.25.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "fedf211ff14ec8381c9bf5714e33a7a552dd1acc" + "reference": "bd84b629c8de41aa2ae82c067c955e06f1b00240" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/fedf211ff14ec8381c9bf5714e33a7a552dd1acc", - "reference": "fedf211ff14ec8381c9bf5714e33a7a552dd1acc", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/bd84b629c8de41aa2ae82c067c955e06f1b00240", + "reference": "bd84b629c8de41aa2ae82c067c955e06f1b00240", "shasum": "" }, "require": { @@ -128,9 +128,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.5" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.25.0" }, - "time": "2023-12-16T09:33:33+00:00" + "time": "2024-01-04T17:06:16+00:00" }, { "name": "slevomat/coding-standard", From e58ac221e317c840ee06f7731e0dc76c7d6a431a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 10 Jan 2024 08:59:44 +0100 Subject: [PATCH 110/147] Bump symplify/easy-coding-standard from 12.0.13 to 12.1.3 (#526) Bumps [symplify/easy-coding-standard](https://github.com/easy-coding-standard/easy-coding-standard) from 12.0.13 to 12.1.3. - [Release notes](https://github.com/easy-coding-standard/easy-coding-standard/releases) - [Commits](https://github.com/easy-coding-standard/easy-coding-standard/compare/12.0.13...12.1.3) --- updated-dependencies: - dependency-name: symplify/easy-coding-standard dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.lock | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/composer.lock b/composer.lock index 75b68c6f..eec87b10 100644 --- a/composer.lock +++ b/composer.lock @@ -279,25 +279,25 @@ }, { "name": "symplify/easy-coding-standard", - "version": "12.0.13", + "version": "12.1.3", "source": { "type": "git", "url": "https://github.com/easy-coding-standard/easy-coding-standard.git", - "reference": "d15707b14d50b7cb6d656f7a7a5e5b9a17099b3c" + "reference": "333771289a714037d9233e78b1e73334f94cd372" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/d15707b14d50b7cb6d656f7a7a5e5b9a17099b3c", - "reference": "d15707b14d50b7cb6d656f7a7a5e5b9a17099b3c", + "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/333771289a714037d9233e78b1e73334f94cd372", + "reference": "333771289a714037d9233e78b1e73334f94cd372", "shasum": "" }, "require": { "php": ">=7.2" }, "conflict": { - "friendsofphp/php-cs-fixer": "<3.0", - "phpcsstandards/php_codesniffer": "<3.6", - "symplify/coding-standard": "<11.3" + "friendsofphp/php-cs-fixer": "<3.46", + "phpcsstandards/php_codesniffer": "<3.8", + "symplify/coding-standard": "<12.1" }, "bin": [ "bin/ecs" @@ -321,7 +321,7 @@ ], "support": { "issues": "https://github.com/easy-coding-standard/easy-coding-standard/issues", - "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.0.13" + "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.1.3" }, "funding": [ { @@ -333,7 +333,7 @@ "type": "github" } ], - "time": "2023-12-07T09:18:07+00:00" + "time": "2024-01-07T21:36:48+00:00" } ], "aliases": [], From 2e014fcf2b5bcdffe991b516b45b670e92f54235 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 13 Jan 2024 11:43:27 +0100 Subject: [PATCH 111/147] Bump squizlabs/php_codesniffer from 3.8.0 to 3.8.1 (#527) Bumps [squizlabs/php_codesniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer) from 3.8.0 to 3.8.1. - [Release notes](https://github.com/PHPCSStandards/PHP_CodeSniffer/releases) - [Changelog](https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/CHANGELOG.md) - [Commits](https://github.com/PHPCSStandards/PHP_CodeSniffer/compare/3.8.0...3.8.1) --- updated-dependencies: - dependency-name: squizlabs/php_codesniffer dependency-type: indirect update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.lock b/composer.lock index eec87b10..ac89297e 100644 --- a/composer.lock +++ b/composer.lock @@ -199,16 +199,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.8.0", + "version": "3.8.1", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", - "reference": "5805f7a4e4958dbb5e944ef1e6edae0a303765e7" + "reference": "14f5fff1e64118595db5408e946f3a22c75807f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/5805f7a4e4958dbb5e944ef1e6edae0a303765e7", - "reference": "5805f7a4e4958dbb5e944ef1e6edae0a303765e7", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/14f5fff1e64118595db5408e946f3a22c75807f7", + "reference": "14f5fff1e64118595db5408e946f3a22c75807f7", "shasum": "" }, "require": { @@ -218,11 +218,11 @@ "php": ">=5.4.0" }, "require-dev": { - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" }, "bin": [ - "bin/phpcs", - "bin/phpcbf" + "bin/phpcbf", + "bin/phpcs" ], "type": "library", "extra": { @@ -275,7 +275,7 @@ "type": "open_collective" } ], - "time": "2023-12-08T12:32:31+00:00" + "time": "2024-01-11T20:47:48+00:00" }, { "name": "symplify/easy-coding-standard", From dd816ccfc3431689b9fb2840bb7c1bc90e7935ed Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 16 Jan 2024 12:00:47 +0100 Subject: [PATCH 112/147] Bump symplify/easy-coding-standard from 12.1.3 to 12.1.7 (#529) Bumps [symplify/easy-coding-standard](https://github.com/easy-coding-standard/easy-coding-standard) from 12.1.3 to 12.1.7. - [Release notes](https://github.com/easy-coding-standard/easy-coding-standard/releases) - [Commits](https://github.com/easy-coding-standard/easy-coding-standard/compare/12.1.3...12.1.7) --- updated-dependencies: - dependency-name: symplify/easy-coding-standard dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index ac89297e..b9d3703e 100644 --- a/composer.lock +++ b/composer.lock @@ -279,16 +279,16 @@ }, { "name": "symplify/easy-coding-standard", - "version": "12.1.3", + "version": "12.1.7", "source": { "type": "git", "url": "https://github.com/easy-coding-standard/easy-coding-standard.git", - "reference": "333771289a714037d9233e78b1e73334f94cd372" + "reference": "f23626aba4f103a09c7e33f74f6995d844d63bf3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/333771289a714037d9233e78b1e73334f94cd372", - "reference": "333771289a714037d9233e78b1e73334f94cd372", + "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/f23626aba4f103a09c7e33f74f6995d844d63bf3", + "reference": "f23626aba4f103a09c7e33f74f6995d844d63bf3", "shasum": "" }, "require": { @@ -321,7 +321,7 @@ ], "support": { "issues": "https://github.com/easy-coding-standard/easy-coding-standard/issues", - "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.1.3" + "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.1.7" }, "funding": [ { @@ -333,7 +333,7 @@ "type": "github" } ], - "time": "2024-01-07T21:36:48+00:00" + "time": "2024-01-14T17:55:27+00:00" } ], "aliases": [], From 4e26e595221194ff97f435733f3191e1a36ec95a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 16 Jan 2024 12:00:54 +0100 Subject: [PATCH 113/147] Bump shivammathur/setup-php from 2.28.0 to 2.29.0 (#528) Bumps [shivammathur/setup-php](https://github.com/shivammathur/setup-php) from 2.28.0 to 2.29.0. - [Release notes](https://github.com/shivammathur/setup-php/releases) - [Commits](https://github.com/shivammathur/setup-php/compare/2.28.0...2.29.0) --- updated-dependencies: - dependency-name: shivammathur/setup-php dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 82bed358..8a0ff383 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -79,7 +79,7 @@ jobs: packages: cmake valgrind - name: Setup PHP - uses: shivammathur/setup-php@2.28.0 + uses: shivammathur/setup-php@2.29.0 with: php-version: ${{ matrix.php-version }} extensions: json @@ -148,7 +148,7 @@ jobs: version: ${{ (matrix.librabbitmq-version == '0.10.0' || matrix.librabbitmq-version == '0.9.0' || matrix.librabbitmq-version == '0.8.0') && 'ubuntu-20.04' || 'ubuntu-22.04' }} - name: Setup PHP - uses: shivammathur/setup-php@2.28.0 + uses: shivammathur/setup-php@2.29.0 with: php-version: ${{ matrix.php-version }} coverage: none From 1b55799d9c6f19415632190ed4a7d02972feedf2 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 17 Jan 2024 19:01:50 +0100 Subject: [PATCH 114/147] Fix missing debug symbols for memory checks (#531) --- .github/workflows/test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 8a0ff383..33e5aea1 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -76,7 +76,7 @@ jobs: - name: Install packages uses: awalsh128/cache-apt-pkgs-action@v1.3.1 with: - packages: cmake valgrind + packages: cmake - name: Setup PHP uses: shivammathur/setup-php@2.29.0 @@ -144,7 +144,7 @@ jobs: - name: Install packages uses: awalsh128/cache-apt-pkgs-action@v1.3.1 with: - packages: cmake valgrind ${{ matrix.compiler }} + packages: cmake valgrind libc6-dbg gcc clang version: ${{ (matrix.librabbitmq-version == '0.10.0' || matrix.librabbitmq-version == '0.9.0' || matrix.librabbitmq-version == '0.8.0') && 'ubuntu-20.04' || 'ubuntu-22.04' }} - name: Setup PHP From f9763b06abdc8f0f790844b4427972e36d49d329 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 17 Jan 2024 19:02:07 +0100 Subject: [PATCH 115/147] Bump symplify/easy-coding-standard from 12.1.7 to 12.1.8 (#530) Bumps [symplify/easy-coding-standard](https://github.com/easy-coding-standard/easy-coding-standard) from 12.1.7 to 12.1.8. - [Release notes](https://github.com/easy-coding-standard/easy-coding-standard/releases) - [Commits](https://github.com/easy-coding-standard/easy-coding-standard/compare/12.1.7...12.1.8) --- updated-dependencies: - dependency-name: symplify/easy-coding-standard dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index b9d3703e..69d1cfd3 100644 --- a/composer.lock +++ b/composer.lock @@ -279,16 +279,16 @@ }, { "name": "symplify/easy-coding-standard", - "version": "12.1.7", + "version": "12.1.8", "source": { "type": "git", "url": "https://github.com/easy-coding-standard/easy-coding-standard.git", - "reference": "f23626aba4f103a09c7e33f74f6995d844d63bf3" + "reference": "7962c810a8eebc4174a38d7dff673f1999e61595" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/f23626aba4f103a09c7e33f74f6995d844d63bf3", - "reference": "f23626aba4f103a09c7e33f74f6995d844d63bf3", + "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/7962c810a8eebc4174a38d7dff673f1999e61595", + "reference": "7962c810a8eebc4174a38d7dff673f1999e61595", "shasum": "" }, "require": { @@ -321,7 +321,7 @@ ], "support": { "issues": "https://github.com/easy-coding-standard/easy-coding-standard/issues", - "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.1.7" + "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.1.8" }, "funding": [ { @@ -333,7 +333,7 @@ "type": "github" } ], - "time": "2024-01-14T17:55:27+00:00" + "time": "2024-01-16T22:56:06+00:00" } ], "aliases": [], From 55a9821e8a4dfb80ba538f77894cd5ca96a81c5b Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Mon, 22 Jan 2024 11:21:48 +0100 Subject: [PATCH 116/147] Fix nullability issue in AMQPBasicProperties (#532) --- amqp_basic_properties.c | 147 +++++++++++++-------- ecs.php | 4 +- infra/tools/pamqp-arguments-validate | 41 +++--- infra/tools/pamqp-dump-reflection | 7 +- tests/amqpbasicproperties.phpt | 44 +++--- tests/amqpbasicproperties_nullability.phpt | 97 ++++++++++++++ 6 files changed, 235 insertions(+), 105 deletions(-) create mode 100644 tests/amqpbasicproperties_nullability.phpt diff --git a/amqp_basic_properties.c b/amqp_basic_properties.c index 85cb77af..1edd6968 100644 --- a/amqp_basic_properties.c +++ b/amqp_basic_properties.c @@ -114,6 +114,7 @@ static PHP_METHOD(AMQPBasicProperties, __construct) size_t message_id_len = 0; zend_long timestamp = 0; + bool timestamp_is_null = 1; char *type = NULL; size_t type_len = 0; @@ -129,7 +130,7 @@ static PHP_METHOD(AMQPBasicProperties, __construct) if (zend_parse_parameters( ZEND_NUM_ARGS(), - "|ssallsssslssss", + "|s!s!alls!s!s!s!l!s!s!s!s!", /* s */ &content_type, &content_type_len, /* s */ &content_encoding, @@ -146,6 +147,7 @@ static PHP_METHOD(AMQPBasicProperties, __construct) /* s */ &message_id, &message_id_len, /* l */ ×tamp, + ×tamp_is_null, /* s */ &type, &type_len, /* s */ &user_id, @@ -157,20 +159,26 @@ static PHP_METHOD(AMQPBasicProperties, __construct) ) == FAILURE) { RETURN_THROWS(); } - zend_update_property_stringl( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("contentType"), - content_type, - content_type_len - ); - zend_update_property_stringl( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("contentEncoding"), - content_encoding, - content_encoding_len - ); + + if (content_type != NULL) { + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("contentType"), + content_type, + content_type_len + ); + } + + if (content_encoding != NULL) { + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("contentEncoding"), + content_encoding, + content_encoding_len + ); + } if (headers != NULL) { zend_update_property(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("headers"), headers); @@ -181,47 +189,78 @@ static PHP_METHOD(AMQPBasicProperties, __construct) zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("deliveryMode"), delivery_mode); zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("priority"), priority); - zend_update_property_stringl( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("correlationId"), - correlation_id, - correlation_id_len - ); - zend_update_property_stringl( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("replyTo"), - reply_to, - reply_to_len - ); - zend_update_property_stringl( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("expiration"), - expiration, - expiration_len - ); - zend_update_property_stringl( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("messageId"), - message_id, - message_id_len - ); + if (correlation_id != NULL) { + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("correlationId"), + correlation_id, + correlation_id_len + ); + } - zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("timestamp"), timestamp); + if (reply_to != NULL) { + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("replyTo"), + reply_to, + reply_to_len + ); + } - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("type"), type, type_len); - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("userId"), user_id, user_id_len); - zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("appId"), app_id, app_id_len); - zend_update_property_stringl( - this_ce, - PHP_AMQP_COMPAT_OBJ_P(getThis()), - ZEND_STRL("clusterId"), - cluster_id, - cluster_id_len - ); + if (expiration != NULL) { + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("expiration"), + expiration, + expiration_len + ); + } + + if (message_id != NULL) { + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("messageId"), + message_id, + message_id_len + ); + } + + if (!timestamp_is_null) { + zend_update_property_long(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("timestamp"), timestamp); + } + + + if (type != NULL) { + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("type"), type, type_len); + } + + if (user_id != NULL) { + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("userId"), + user_id, + user_id_len + ); + } + + if (app_id != NULL) { + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("appId"), app_id, app_id_len); + } + + if (cluster_id != NULL) { + zend_update_property_stringl( + this_ce, + PHP_AMQP_COMPAT_OBJ_P(getThis()), + ZEND_STRL("clusterId"), + cluster_id, + cluster_id_len + ); + } } /* }}} */ diff --git a/ecs.php b/ecs.php index 701e644a..2b93488a 100644 --- a/ecs.php +++ b/ecs.php @@ -39,8 +39,6 @@ use Symplify\EasyCodingStandard\ValueObject\Set\SetList; return static function (ECSConfig $ecsConfig): void { - $ecsConfig->paths([__DIR__ . '/stubs', __DIR__ . '/infra']); - // this way you add a single rule $ecsConfig->rules( [ @@ -114,4 +112,6 @@ $ecsConfig->ruleWithConfiguration(PhpdocAlignFixer::class, [ 'align' => 'left', ]); + + $ecsConfig->paths([...glob(__DIR__ . '/infra/tools/*'), __DIR__ . '/stubs', __DIR__ . '/infra']); }; \ No newline at end of file diff --git a/infra/tools/pamqp-arguments-validate b/infra/tools/pamqp-arguments-validate index d0857704..07eda958 100755 --- a/infra/tools/pamqp-arguments-validate +++ b/infra/tools/pamqp-arguments-validate @@ -1,28 +1,11 @@ #!/usr/bin/env php 0); + + $fileName = 'amqp_' . implode('_', array_map('strtolower', $parts)) . '.c'; $path = __DIR__ . '/../../' . $fileName; @@ -30,6 +13,10 @@ function getSource(string $class): ?string return file_get_contents($path); } + if (end($parts) === 'Exception') { + return file_get_contents(__DIR__ . '/../../amqp.c'); + } + return null; } @@ -44,7 +31,7 @@ function validate(string $class) $source = getSource($class); if ($source === null) { - // WARNING + error('Could not load source for "%s"', $class); return; } @@ -155,7 +142,7 @@ function parseParameterString(string $str): array $parameters = []; $requiredCount = null; $count = 0; - foreach (str_split($str) as $pos => $char) { + foreach (str_split($str) as $char) { if (isset($types[$char])) { if (isset($currentInfo)) { $parameters[] = $currentInfo; @@ -187,8 +174,12 @@ function parseParameterString(string $str): array return [$parameters, $requiredCount]; } -foreach (CLASSES as $class) { - validate($class); +function getAmqpClasses(): array +{ + $ext = new ReflectionExtension('amqp'); + return $ext->getClassNames(); } +array_map('validate', getAmqpClasses()); + exit((int) $isError); diff --git a/infra/tools/pamqp-dump-reflection b/infra/tools/pamqp-dump-reflection index 62efb642..252afbe3 100755 --- a/infra/tools/pamqp-dump-reflection +++ b/infra/tools/pamqp-dump-reflection @@ -53,7 +53,8 @@ function error(string $message, ...$args): void const MAGIC_METHODS = ['__construct', '__toString', '__wakeup', '__clone']; -function getParents(ReflectionClass $r): array { +function getParents(ReflectionClass $r): array +{ $parents = []; while ($r = $r->getParentClass()) { $parents[] = $r->getName(); @@ -74,7 +75,9 @@ function getClassMetadata(string $class): array 'abstract' => $refl->isAbstract(), 'interface' => $refl->isInterface(), 'implements' => $refl->getInterfaceNames(), - 'readonly' => method_exists($refl, 'isReadonly') ? $refl->isReadonly() || strpos($refl->getDocComment(), '@readonly') !== false : null, + 'readonly' => method_exists($refl, 'isReadonly') + ? $refl->isReadonly() || strpos($refl->getDocComment(), '@readonly') !== false + : null, 'extends' => getParents($refl), ]; diff --git a/tests/amqpbasicproperties.phpt b/tests/amqpbasicproperties.phpt index ac9bc385..35d4c128 100644 --- a/tests/amqpbasicproperties.phpt +++ b/tests/amqpbasicproperties.phpt @@ -38,9 +38,9 @@ dump_methods($props); --EXPECT-- object(AMQPBasicProperties)#1 (14) { ["contentType":"AMQPBasicProperties":private]=> - string(0) "" + NULL ["contentEncoding":"AMQPBasicProperties":private]=> - string(0) "" + NULL ["headers":"AMQPBasicProperties":private]=> array(0) { } @@ -49,29 +49,29 @@ object(AMQPBasicProperties)#1 (14) { ["priority":"AMQPBasicProperties":private]=> int(0) ["correlationId":"AMQPBasicProperties":private]=> - string(0) "" + NULL ["replyTo":"AMQPBasicProperties":private]=> - string(0) "" + NULL ["expiration":"AMQPBasicProperties":private]=> - string(0) "" + NULL ["messageId":"AMQPBasicProperties":private]=> - string(0) "" + NULL ["timestamp":"AMQPBasicProperties":private]=> - int(0) + NULL ["type":"AMQPBasicProperties":private]=> - string(0) "" + NULL ["userId":"AMQPBasicProperties":private]=> - string(0) "" + NULL ["appId":"AMQPBasicProperties":private]=> - string(0) "" + NULL ["clusterId":"AMQPBasicProperties":private]=> - string(0) "" + NULL } AMQPBasicProperties getContentType(): - string(0) "" + NULL getContentEncoding(): - string(0) "" + NULL getHeaders(): array(0) { } @@ -80,23 +80,23 @@ AMQPBasicProperties getPriority(): int(0) getCorrelationId(): - string(0) "" + NULL getReplyTo(): - string(0) "" + NULL getExpiration(): - string(0) "" + NULL getMessageId(): - string(0) "" + NULL getTimestamp(): - int(0) + NULL getType(): - string(0) "" + NULL getUserId(): - string(0) "" + NULL getAppId(): - string(0) "" + NULL getClusterId(): - string(0) "" + NULL object(AMQPBasicProperties)#2 (14) { ["contentType":"AMQPBasicProperties":private]=> diff --git a/tests/amqpbasicproperties_nullability.phpt b/tests/amqpbasicproperties_nullability.phpt new file mode 100644 index 00000000..8a172cab --- /dev/null +++ b/tests/amqpbasicproperties_nullability.phpt @@ -0,0 +1,97 @@ +--TEST-- +AMQPBasicProperties - explicit nullability +--SKIPIF-- + +--FILE-- + 'headers'), + 42, + 24, + null, + null, + null, + null, + null, + null, + null, + null, + null +); +var_dump($props); +dump_methods($props); + + +?> +--EXPECT-- +object(AMQPBasicProperties)#1 (14) { + ["contentType":"AMQPBasicProperties":private]=> + NULL + ["contentEncoding":"AMQPBasicProperties":private]=> + NULL + ["headers":"AMQPBasicProperties":private]=> + array(1) { + ["test"]=> + string(7) "headers" + } + ["deliveryMode":"AMQPBasicProperties":private]=> + int(42) + ["priority":"AMQPBasicProperties":private]=> + int(24) + ["correlationId":"AMQPBasicProperties":private]=> + NULL + ["replyTo":"AMQPBasicProperties":private]=> + NULL + ["expiration":"AMQPBasicProperties":private]=> + NULL + ["messageId":"AMQPBasicProperties":private]=> + NULL + ["timestamp":"AMQPBasicProperties":private]=> + NULL + ["type":"AMQPBasicProperties":private]=> + NULL + ["userId":"AMQPBasicProperties":private]=> + NULL + ["appId":"AMQPBasicProperties":private]=> + NULL + ["clusterId":"AMQPBasicProperties":private]=> + NULL +} +AMQPBasicProperties + getContentType(): + NULL + getContentEncoding(): + NULL + getHeaders(): + array(1) { + ["test"]=> + string(7) "headers" +} + getDeliveryMode(): + int(42) + getPriority(): + int(24) + getCorrelationId(): + NULL + getReplyTo(): + NULL + getExpiration(): + NULL + getMessageId(): + NULL + getTimestamp(): + NULL + getType(): + NULL + getUserId(): + NULL + getAppId(): + NULL + getClusterId(): + NULL From 82424ed50eb10cd97777e2aabf0f2a0887faf447 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Mon, 22 Jan 2024 11:49:15 +0100 Subject: [PATCH 117/147] [RM] releasing version 2.1.2 --- package.xml | 47 ++++++++++++++++++++++++++++------------------ php_amqp_version.h | 6 +++--- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/package.xml b/package.xml index 6916dad5..70cbd115 100644 --- a/package.xml +++ b/package.xml @@ -22,33 +22,43 @@ pinepain@gmail.com yes - 2023-10-12 - + 2024-01-22 + - 2.1.1 - 2.1.1 + 2.1.2 + 2.1.2 stable stable PHP License - ) (https://github.com/php-amqp/php-amqp/issues/502) - - FIX: #494 Param "verify" always true (Daniel Kozak ) (https://github.com/php-amqp/php-amqp/issues/497) - - Remove assert on undefined variable (Remi Collet ) (https://github.com/php-amqp/php-amqp/issues/486) - - Semantically sort changelog (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/e5bd909) - - Set custom PHP executable dynamically (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/503) - - Fixes in stub comments (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/6539de5) - - Refactor test skipping (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/504) - - Bump actions/checkout from 4.0.0 to 4.1.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/499) - - Bump phpstan/phpdoc-parser from 1.23.1 to 1.24.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/491) - - Bump phpstan/phpdoc-parser from 1.24.0 to 1.24.1 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/495) - - Bump shivammathur/setup-php from 2.25.5 to 2.26.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/493) - - Bump slevomat/coding-standard from 8.13.4 to 8.14.1 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/501) - - Bump symplify/easy-coding-standard from 12.0.7 to 12.0.8 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/492) + ) (https://github.com/php-amqp/php-amqp/issues/531) + - Fix nullability issue in AMQPBasicProperties (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/532) + - Ignore setfacl errors (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/5548760) + - Only restart on failure (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/a37c5f1) + - Bump actions/checkout from 4.1.0 to 4.1.1 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/506) + - Bump awalsh128/cache-apt-pkgs-action from 1.3.0 to 1.3.1 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/509) + - Bump fkirc/skip-duplicate-actions from 5.3.0 to 5.3.1 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/507) + - Bump phpstan/phpdoc-parser from 1.24.2 to 1.24.3 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/513) + - Bump phpstan/phpdoc-parser from 1.24.3 to 1.24.4 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/516) + - Bump phpstan/phpdoc-parser from 1.24.4 to 1.24.5 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/521) + - Bump phpstan/phpdoc-parser from 1.24.5 to 1.25.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/524) + - Bump shivammathur/setup-php from 2.26.0 to 2.27.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/510) + - Bump shivammathur/setup-php from 2.27.0 to 2.27.1 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/512) + - Bump shivammathur/setup-php from 2.27.1 to 2.28.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/515) + - Bump shivammathur/setup-php from 2.28.0 to 2.29.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/528) + - Bump squizlabs/php_codesniffer from 3.7.2 to 3.8.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/520) + - Bump squizlabs/php_codesniffer from 3.8.0 to 3.8.1 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/527) + - Bump symplify/easy-coding-standard from 12.0.11 to 12.0.13 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/519) + - Bump symplify/easy-coding-standard from 12.0.13 to 12.1.3 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/526) + - Bump symplify/easy-coding-standard from 12.0.8 to 12.0.9 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/517) + - Bump symplify/easy-coding-standard from 12.0.9 to 12.0.11 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/518) + - Bump symplify/easy-coding-standard from 12.1.3 to 12.1.7 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/529) + - Bump symplify/easy-coding-standard from 12.1.7 to 12.1.8 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/530) For a complete list of changes see: -https://github.com/php-amqp/php-amqp/compare/v2.1.0...v2.1.1]]> +https://github.com/php-amqp/php-amqp/compare/v2.1.1...v2.1.2]]> @@ -91,6 +101,7 @@ https://github.com/php-amqp/php-amqp/compare/v2.1.0...v2.1.1]]> + diff --git a/php_amqp_version.h b/php_amqp_version.h index 1358f862..249d4363 100644 --- a/php_amqp_version.h +++ b/php_amqp_version.h @@ -1,6 +1,6 @@ #define PHP_AMQP_VERSION_MAJOR 2 #define PHP_AMQP_VERSION_MINOR 1 -#define PHP_AMQP_VERSION_PATCH 1 +#define PHP_AMQP_VERSION_PATCH 2 #define PHP_AMQP_VERSION_EXTRA "" -#define PHP_AMQP_VERSION "2.1.1" -#define PHP_AMQP_VERSION_ID 20101 +#define PHP_AMQP_VERSION "2.1.2" +#define PHP_AMQP_VERSION_ID 20102 From 13a81e6140f13c5bdeef12665bdb44bcd93d4259 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Mon, 22 Jan 2024 11:52:16 +0100 Subject: [PATCH 118/147] [RM] back to dev 2.2.0dev --- package.xml | 76 ++++++++++++++++++++++++++++------------------ php_amqp_version.h | 10 +++--- 2 files changed, 52 insertions(+), 34 deletions(-) diff --git a/package.xml b/package.xml index 70cbd115..8b5ce17c 100644 --- a/package.xml +++ b/package.xml @@ -23,42 +23,21 @@ yes 2024-01-22 - + - 2.1.2 - 2.1.2 + 2.2.0dev + 2.2.0dev - stable - stable + devel + devel PHP License - ) (https://github.com/php-amqp/php-amqp/issues/531) - - Fix nullability issue in AMQPBasicProperties (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/532) - - Ignore setfacl errors (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/5548760) - - Only restart on failure (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/a37c5f1) - - Bump actions/checkout from 4.1.0 to 4.1.1 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/506) - - Bump awalsh128/cache-apt-pkgs-action from 1.3.0 to 1.3.1 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/509) - - Bump fkirc/skip-duplicate-actions from 5.3.0 to 5.3.1 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/507) - - Bump phpstan/phpdoc-parser from 1.24.2 to 1.24.3 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/513) - - Bump phpstan/phpdoc-parser from 1.24.3 to 1.24.4 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/516) - - Bump phpstan/phpdoc-parser from 1.24.4 to 1.24.5 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/521) - - Bump phpstan/phpdoc-parser from 1.24.5 to 1.25.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/524) - - Bump shivammathur/setup-php from 2.26.0 to 2.27.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/510) - - Bump shivammathur/setup-php from 2.27.0 to 2.27.1 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/512) - - Bump shivammathur/setup-php from 2.27.1 to 2.28.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/515) - - Bump shivammathur/setup-php from 2.28.0 to 2.29.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/528) - - Bump squizlabs/php_codesniffer from 3.7.2 to 3.8.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/520) - - Bump squizlabs/php_codesniffer from 3.8.0 to 3.8.1 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/527) - - Bump symplify/easy-coding-standard from 12.0.11 to 12.0.13 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/519) - - Bump symplify/easy-coding-standard from 12.0.13 to 12.1.3 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/526) - - Bump symplify/easy-coding-standard from 12.0.8 to 12.0.9 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/517) - - Bump symplify/easy-coding-standard from 12.0.9 to 12.0.11 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/518) - - Bump symplify/easy-coding-standard from 12.1.3 to 12.1.7 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/529) - - Bump symplify/easy-coding-standard from 12.1.7 to 12.1.8 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/530) + +https://github.com/php-amqp/php-amqp/compare/v2.1.2...latest +]]> @@ -324,6 +303,45 @@ https://github.com/php-amqp/php-amqp/compare/v2.1.1...v2.1.2]]> + + 2024-01-22 + + + 2.1.2 + 2.1.2 + + + stable + stable + + PHP License + ) (https://github.com/php-amqp/php-amqp/issues/531) + - Fix nullability issue in AMQPBasicProperties (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/532) + - Ignore setfacl errors (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/5548760) + - Only restart on failure (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/a37c5f1) + - Bump actions/checkout from 4.1.0 to 4.1.1 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/506) + - Bump awalsh128/cache-apt-pkgs-action from 1.3.0 to 1.3.1 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/509) + - Bump fkirc/skip-duplicate-actions from 5.3.0 to 5.3.1 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/507) + - Bump phpstan/phpdoc-parser from 1.24.2 to 1.24.3 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/513) + - Bump phpstan/phpdoc-parser from 1.24.3 to 1.24.4 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/516) + - Bump phpstan/phpdoc-parser from 1.24.4 to 1.24.5 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/521) + - Bump phpstan/phpdoc-parser from 1.24.5 to 1.25.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/524) + - Bump shivammathur/setup-php from 2.26.0 to 2.27.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/510) + - Bump shivammathur/setup-php from 2.27.0 to 2.27.1 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/512) + - Bump shivammathur/setup-php from 2.27.1 to 2.28.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/515) + - Bump shivammathur/setup-php from 2.28.0 to 2.29.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/528) + - Bump squizlabs/php_codesniffer from 3.7.2 to 3.8.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/520) + - Bump squizlabs/php_codesniffer from 3.8.0 to 3.8.1 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/527) + - Bump symplify/easy-coding-standard from 12.0.11 to 12.0.13 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/519) + - Bump symplify/easy-coding-standard from 12.0.13 to 12.1.3 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/526) + - Bump symplify/easy-coding-standard from 12.0.8 to 12.0.9 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/517) + - Bump symplify/easy-coding-standard from 12.0.9 to 12.0.11 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/518) + - Bump symplify/easy-coding-standard from 12.1.3 to 12.1.7 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/529) + - Bump symplify/easy-coding-standard from 12.1.7 to 12.1.8 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/530) + +For a complete list of changes see: +https://github.com/php-amqp/php-amqp/compare/v2.1.1...v2.1.2]]> + 2023-09-07 diff --git a/php_amqp_version.h b/php_amqp_version.h index 249d4363..61c2d46c 100644 --- a/php_amqp_version.h +++ b/php_amqp_version.h @@ -1,6 +1,6 @@ #define PHP_AMQP_VERSION_MAJOR 2 -#define PHP_AMQP_VERSION_MINOR 1 -#define PHP_AMQP_VERSION_PATCH 2 -#define PHP_AMQP_VERSION_EXTRA "" -#define PHP_AMQP_VERSION "2.1.2" -#define PHP_AMQP_VERSION_ID 20102 +#define PHP_AMQP_VERSION_MINOR 2 +#define PHP_AMQP_VERSION_PATCH 0 +#define PHP_AMQP_VERSION_EXTRA "dev" +#define PHP_AMQP_VERSION "2.2.0dev" +#define PHP_AMQP_VERSION_ID 20200 From 431cc5825af2a785811773bd6c546b4a106951cc Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Tue, 23 Jan 2024 17:51:37 +0100 Subject: [PATCH 119/147] Restore changelog for 2.1.1 (#533) --- package.xml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/package.xml b/package.xml index 8b5ce17c..2cc2a2cf 100644 --- a/package.xml +++ b/package.xml @@ -341,6 +341,35 @@ https://github.com/php-amqp/php-amqp/compare/v2.1.2...latest For a complete list of changes see: https://github.com/php-amqp/php-amqp/compare/v2.1.1...v2.1.2]]> + + + 2023-10-12 + + + 2.1.1 + 2.1.1 + + + stable + stable + + PHP License + ) (https://github.com/php-amqp/php-amqp/issues/502) + - FIX: #494 Param "verify" always true (Daniel Kozak ) (https://github.com/php-amqp/php-amqp/issues/497) + - Remove assert on undefined variable (Remi Collet ) (https://github.com/php-amqp/php-amqp/issues/486) + - Semantically sort changelog (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/e5bd909) + - Set custom PHP executable dynamically (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/503) + - Fixes in stub comments (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/6539de5) + - Refactor test skipping (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/504) + - Bump actions/checkout from 4.0.0 to 4.1.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/499) + - Bump phpstan/phpdoc-parser from 1.23.1 to 1.24.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/491) + - Bump phpstan/phpdoc-parser from 1.24.0 to 1.24.1 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/495) + - Bump shivammathur/setup-php from 2.25.5 to 2.26.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/493) + - Bump slevomat/coding-standard from 8.13.4 to 8.14.1 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/501) + - Bump symplify/easy-coding-standard from 12.0.7 to 12.0.8 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/492) + +For a complete list of changes see: +https://github.com/php-amqp/php-amqp/compare/v2.1.0...v2.1.1]]> 2023-09-07 From 3e327d42c32d4b9ce7e7e0f20a4468caaee87ad9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Feb 2024 10:56:50 +0100 Subject: [PATCH 120/147] Bump squizlabs/php_codesniffer from 3.8.1 to 3.9.0 (#539) Bumps [squizlabs/php_codesniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer) from 3.8.1 to 3.9.0. - [Release notes](https://github.com/PHPCSStandards/PHP_CodeSniffer/releases) - [Changelog](https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/CHANGELOG.md) - [Commits](https://github.com/PHPCSStandards/PHP_CodeSniffer/compare/3.8.1...3.9.0) --- updated-dependencies: - dependency-name: squizlabs/php_codesniffer dependency-type: indirect update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.lock b/composer.lock index 69d1cfd3..93afd2f1 100644 --- a/composer.lock +++ b/composer.lock @@ -199,16 +199,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.8.1", + "version": "3.9.0", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", - "reference": "14f5fff1e64118595db5408e946f3a22c75807f7" + "reference": "d63cee4890a8afaf86a22e51ad4d97c91dd4579b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/14f5fff1e64118595db5408e946f3a22c75807f7", - "reference": "14f5fff1e64118595db5408e946f3a22c75807f7", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/d63cee4890a8afaf86a22e51ad4d97c91dd4579b", + "reference": "d63cee4890a8afaf86a22e51ad4d97c91dd4579b", "shasum": "" }, "require": { @@ -275,7 +275,7 @@ "type": "open_collective" } ], - "time": "2024-01-11T20:47:48+00:00" + "time": "2024-02-16T15:06:51+00:00" }, { "name": "symplify/easy-coding-standard", From 9af3c459f091a8b7dc088ec6c981dc236af3503c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Feb 2024 10:57:36 +0100 Subject: [PATCH 121/147] Bump awalsh128/cache-apt-pkgs-action from 1.3.1 to 1.4.1 (#538) Bumps [awalsh128/cache-apt-pkgs-action](https://github.com/awalsh128/cache-apt-pkgs-action) from 1.3.1 to 1.4.1. - [Release notes](https://github.com/awalsh128/cache-apt-pkgs-action/releases) - [Commits](https://github.com/awalsh128/cache-apt-pkgs-action/compare/v1.3.1...v1.4.1) --- updated-dependencies: - dependency-name: awalsh128/cache-apt-pkgs-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 33e5aea1..f58cb9cd 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -74,7 +74,7 @@ jobs: uses: actions/checkout@v4.1.1 - name: Install packages - uses: awalsh128/cache-apt-pkgs-action@v1.3.1 + uses: awalsh128/cache-apt-pkgs-action@v1.4.1 with: packages: cmake @@ -142,7 +142,7 @@ jobs: run: docker compose up -d rabbitmq - name: Install packages - uses: awalsh128/cache-apt-pkgs-action@v1.3.1 + uses: awalsh128/cache-apt-pkgs-action@v1.4.1 with: packages: cmake valgrind libc6-dbg gcc clang version: ${{ (matrix.librabbitmq-version == '0.10.0' || matrix.librabbitmq-version == '0.9.0' || matrix.librabbitmq-version == '0.8.0') && 'ubuntu-20.04' || 'ubuntu-22.04' }} From a9cbd81ea401d4ba41b72381008b331f5516823c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Tue, 4 Jun 2024 16:51:59 +0200 Subject: [PATCH 122/147] fix: SIGPIPE handling (#550) Sets SA_ONSTACK and switches from signal to sigaction (see https://github.com/php/php-src/pull/9597) --- amqp_connection_resource.c | 19 +++++++++++++++---- amqp_exchange.c | 23 ++++++++++++++++------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/amqp_connection_resource.c b/amqp_connection_resource.c index 56194dab..8809a20b 100644 --- a/amqp_connection_resource.c +++ b/amqp_connection_resource.c @@ -39,6 +39,7 @@ #else #include #include + #include #endif #if HAVE_LIBRABBITMQ_NEW_LAYOUT @@ -689,15 +690,21 @@ static void connection_resource_destructor(amqp_connection_resource *resource, i assert(resource != NULL); #ifndef PHP_WIN32 - void *old_handler; - /* If we are trying to close the connection and the connection already closed, it will throw SIGPIPE, which is fine, so ignore all SIGPIPES */ + struct sigaction oldact; + struct sigaction act = { 0 }; + + act.sa_flags = SA_ONSTACK; + act.sa_handler = SIG_IGN; + /* Start ignoring SIGPIPE */ - old_handler = signal(SIGPIPE, SIG_IGN); + if (sigaction(SIGPIPE, &act, &oldact) == -1) { + perror("sigaction"); + } #endif if (resource->parent) { @@ -720,7 +727,11 @@ static void connection_resource_destructor(amqp_connection_resource *resource, i #ifndef PHP_WIN32 /* End ignoring of SIGPIPEs */ - signal(SIGPIPE, old_handler); + oldact.sa_flags |= SA_ONSTACK; + + if (sigaction(SIGPIPE, &oldact, NULL) == -1) { + perror("sigaction"); + } #endif pefree(resource, persistent); diff --git a/amqp_exchange.c b/amqp_exchange.c index 314a15dc..7d62f2c2 100644 --- a/amqp_exchange.c +++ b/amqp_exchange.c @@ -37,6 +37,7 @@ #else #include #include + #include #endif #if HAVE_LIBRABBITMQ_NEW_LAYOUT #include @@ -466,11 +467,6 @@ static PHP_METHOD(amqp_exchange_class, publish) zend_long flags = AMQP_NOPARAM; bool flags_is_null = 1; -#ifndef PHP_WIN32 - /* Storage for previous signal handler during SIGPIPE override */ - void *old_handler; -#endif - amqp_basic_properties_t props; if (zend_parse_parameters( @@ -625,7 +621,16 @@ static PHP_METHOD(amqp_exchange_class, publish) #ifndef PHP_WIN32 /* Start ignoring SIGPIPE */ - old_handler = signal(SIGPIPE, SIG_IGN); + struct sigaction oldact; + struct sigaction act = { 0 }; + + act.sa_flags = SA_ONSTACK; + act.sa_handler = SIG_IGN; + + /* Start ignoring SIGPIPE */ + if (sigaction(SIGPIPE, &act, &oldact) == -1) { + perror("sigaction"); + } #endif zval *exchange_name = PHP_AMQP_READ_THIS_PROP("name"); @@ -650,7 +655,11 @@ static PHP_METHOD(amqp_exchange_class, publish) #ifndef PHP_WIN32 /* End ignoring of SIGPIPEs */ - signal(SIGPIPE, old_handler); + oldact.sa_flags |= SA_ONSTACK; + + if (sigaction(SIGPIPE, &oldact, NULL) == -1) { + perror("sigaction"); + } #endif if (status != AMQP_STATUS_OK) { From 2ed7b6a469e37408288b4dc7c31d1253560fa23b Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 18 Dec 2024 14:07:41 +0100 Subject: [PATCH 123/147] Ignore codebase reformatting for blame --- .git-blame-ignore-revs | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .git-blame-ignore-revs diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 00000000..1d98aec4 --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,2 @@ +# Codebase reformatting +7b6a6443d6fea0dce155ab67cbd7640177a152ca From f6757c21634091b1d2baed18a37118f808f8f67f Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Wed, 18 Dec 2024 13:17:16 +0000 Subject: [PATCH 124/147] Enable support for PIE (#584) --- composer.json | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f6f76b2b..b8a946d5 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "php-amqp/php-amqp", - "type": "library", + "type": "php-ext", "description": "PHP AMQP Binding Library", "keywords": [ "rabbitmq", @@ -31,5 +31,19 @@ "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": false } + }, + "php-ext": { + "extension-name": "amqp", + "configure-options": [ + { + "name": "with-amqp", + "description": "Include amqp support" + }, + { + "name": "with-librabbitmq-dir", + "description": "Set the path to librabbitmq install prefix.", + "needs-value": true + } + ] } } From 3618db5f781aa3d371b630c666bc90845d7c77d4 Mon Sep 17 00:00:00 2001 From: Jeremy Smith Date: Fri, 21 Feb 2025 20:23:57 +1000 Subject: [PATCH 125/147] Adds connection_resource as parameter for PHP_AMQP_MAYBE_ERROR (#589) --- amqp_channel.c | 34 +++++++++++++++++----------------- amqp_exchange.c | 8 ++++---- amqp_queue.c | 8 ++++---- php_amqp.h | 4 ++-- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/amqp_channel.c b/amqp_channel.c index 253f6b41..860daad9 100644 --- a/amqp_channel.c +++ b/amqp_channel.c @@ -93,7 +93,7 @@ void php_amqp_close_channel(amqp_channel_resource *channel_resource, bool throw) amqp_rpc_reply_t close_res = amqp_channel_close(connection_resource->connection_state, channel_resource->channel_id, AMQP_REPLY_SUCCESS); - if (throw && PHP_AMQP_MAYBE_ERROR(close_res, channel_resource)) { + if (throw && PHP_AMQP_MAYBE_ERROR(close_res, channel_resource, connection_resource)) { php_amqp_zend_throw_exception_short(close_res, amqp_channel_exception_class_entry); goto err; } @@ -103,7 +103,7 @@ void php_amqp_close_channel(amqp_channel_resource *channel_resource, bool throw) } amqp_rpc_reply_t reply_res = amqp_get_rpc_reply(connection_resource->connection_state); - if (throw && PHP_AMQP_MAYBE_ERROR(reply_res, channel_resource)) { + if (throw && PHP_AMQP_MAYBE_ERROR(reply_res, channel_resource, connection_resource)) { php_amqp_zend_throw_exception_short(reply_res, amqp_channel_exception_class_entry); goto err; } @@ -422,7 +422,7 @@ static PHP_METHOD(amqp_channel_class, __construct) amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource, channel_resource->connection_resource)) { php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; @@ -445,7 +445,7 @@ static PHP_METHOD(amqp_channel_class, __construct) res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource, channel_resource->connection_resource)) { php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; @@ -544,7 +544,7 @@ static PHP_METHOD(amqp_channel_class, setPrefetchCount) amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource, channel_resource->connection_resource)) { php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; @@ -567,7 +567,7 @@ static PHP_METHOD(amqp_channel_class, setPrefetchCount) res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource, channel_resource->connection_resource)) { php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; @@ -631,7 +631,7 @@ static PHP_METHOD(amqp_channel_class, setPrefetchSize) amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource, channel_resource->connection_resource)) { php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; @@ -654,7 +654,7 @@ static PHP_METHOD(amqp_channel_class, setPrefetchSize) res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource, channel_resource->connection_resource)) { php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; @@ -717,7 +717,7 @@ static PHP_METHOD(amqp_channel_class, setGlobalPrefetchCount) amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource, channel_resource->connection_resource)) { php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; @@ -784,7 +784,7 @@ static PHP_METHOD(amqp_channel_class, setGlobalPrefetchSize) amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource, channel_resource->connection_resource)) { php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; @@ -869,7 +869,7 @@ static PHP_METHOD(amqp_channel_class, qos) amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource, channel_resource->connection_resource)) { php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; @@ -892,7 +892,7 @@ static PHP_METHOD(amqp_channel_class, qos) res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource, channel_resource->connection_resource)) { php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; @@ -922,7 +922,7 @@ static PHP_METHOD(amqp_channel_class, startTransaction) res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource, channel_resource->connection_resource)) { php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; @@ -950,7 +950,7 @@ static PHP_METHOD(amqp_channel_class, commitTransaction) res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource, channel_resource->connection_resource)) { php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; @@ -977,7 +977,7 @@ static PHP_METHOD(amqp_channel_class, rollbackTransaction) res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource, channel_resource->connection_resource)) { php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; @@ -1022,7 +1022,7 @@ static PHP_METHOD(amqp_channel_class, basicRecover) res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource, channel_resource->connection_resource)) { php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; @@ -1048,7 +1048,7 @@ PHP_METHOD(amqp_channel_class, confirmSelect) res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource, channel_resource->connection_resource)) { php_amqp_zend_throw_exception_short(res, amqp_channel_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); diff --git a/amqp_exchange.c b/amqp_exchange.c index 7d62f2c2..fd772716 100644 --- a/amqp_exchange.c +++ b/amqp_exchange.c @@ -395,7 +395,7 @@ static PHP_METHOD(amqp_exchange_class, declareExchange) php_amqp_type_free_amqp_table(arguments); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource, channel_resource->connection_resource)) { php_amqp_zend_throw_exception_short(res, amqp_exchange_exception_class_entry); return; } @@ -437,7 +437,7 @@ static PHP_METHOD(amqp_exchange_class, delete) amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource, channel_resource->connection_resource)) { php_amqp_zend_throw_exception_short(res, amqp_exchange_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; @@ -735,7 +735,7 @@ static PHP_METHOD(amqp_exchange_class, bind) amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource, channel_resource->connection_resource)) { php_amqp_zend_throw_exception_short(res, amqp_exchange_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; @@ -797,7 +797,7 @@ static PHP_METHOD(amqp_exchange_class, unbind) amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource, channel_resource->connection_resource)) { php_amqp_zend_throw_exception_short(res, amqp_exchange_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; diff --git a/amqp_queue.c b/amqp_queue.c index 67229a05..eeeec3df 100644 --- a/amqp_queue.c +++ b/amqp_queue.c @@ -444,7 +444,7 @@ static PHP_METHOD(amqp_queue_class, bind) amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource, channel_resource->connection_resource)) { php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); RETURN_THROWS(); @@ -484,7 +484,7 @@ static PHP_METHOD(amqp_queue_class, get) (AMQP_AUTOACK & flags) ? 1 : 0 ); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource, channel_resource->connection_resource)) { php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; @@ -518,7 +518,7 @@ static PHP_METHOD(amqp_queue_class, get) 0 ); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource, channel_resource->connection_resource)) { php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); amqp_destroy_envelope(&envelope); @@ -1175,7 +1175,7 @@ static PHP_METHOD(amqp_queue_class, unbind) amqp_rpc_reply_t res = amqp_get_rpc_reply(channel_resource->connection_resource->connection_state); - if (PHP_AMQP_MAYBE_ERROR(res, channel_resource)) { + if (PHP_AMQP_MAYBE_ERROR(res, channel_resource, channel_resource->connection_resource)) { php_amqp_zend_throw_exception_short(res, amqp_queue_exception_class_entry); php_amqp_maybe_release_buffers_on_channel(channel_resource->connection_resource, channel_resource); return; diff --git a/php_amqp.h b/php_amqp.h index 4592aadd..e73ac5bf 100644 --- a/php_amqp.h +++ b/php_amqp.h @@ -367,10 +367,10 @@ static inline amqp_channel_object *php_amqp_channel_object_fetch(zend_object *ob PHP_AMQP_VERIFY_CONNECTION_ERROR(error, "No connection available.") \ } -#define PHP_AMQP_MAYBE_ERROR(res, channel_resource) \ +#define PHP_AMQP_MAYBE_ERROR(res, channel_resource, connection_resource) \ ((AMQP_RESPONSE_NORMAL != (res).reply_type) && \ PHP_AMQP_RESOURCE_RESPONSE_OK != \ - php_amqp_error(res, &PHP_AMQP_G(error_message), (channel_resource)->connection_resource, (channel_resource))) + php_amqp_error(res, &PHP_AMQP_G(error_message), (connection_resource), (channel_resource))) #if ZEND_MODULE_API_NO >= 20100000 From b17516c2ed5c90410a35e6a7a415733d43e224c5 Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Fri, 19 Dec 2025 15:41:58 +0100 Subject: [PATCH 126/147] Add PHP 8.4 and 8.5 to CI matrix (#597) --- infra/tools/pamqp-matrix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/infra/tools/pamqp-matrix b/infra/tools/pamqp-matrix index b90dc3ac..7bf54f25 100755 --- a/infra/tools/pamqp-matrix +++ b/infra/tools/pamqp-matrix @@ -1,5 +1,5 @@ #!/usr/bin/env node -const PHP_VERSIONS = ["8.3", "8.2", "8.1", "8.0", "7.4"] +const PHP_VERSIONS = ["8.5", "8.4", "8.3", "8.2", "8.1", "8.0", "7.4"] const LIBRABBITMQ_VERSIONS = ["master", "0.13.0", "0.12.0", "0.11.0", "0.10.0", "0.9.0", "0.8.0"] const toOutput = (k, v) => console.log(`${k}=${JSON.stringify(v)}`) @@ -15,4 +15,4 @@ const memoryBuilds = PHP_VERSIONS.flatMap(php => [LIBRABBITMQ_VERSIONS[0], LIBRA toOutput('php_versions', PHP_VERSIONS) toOutput('librabbitmq_versions', LIBRABBITMQ_VERSIONS) -toOutput('memory_build_matrix', memoryBuilds) \ No newline at end of file +toOutput('memory_build_matrix', memoryBuilds) From 99acba795d39c3f413e7ff8e00b646ce6e2cd0be Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Fri, 19 Dec 2025 15:53:26 +0100 Subject: [PATCH 127/147] Upgrade GH actions --- .github/workflows/test.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f58cb9cd..e2600df9 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -74,12 +74,12 @@ jobs: uses: actions/checkout@v4.1.1 - name: Install packages - uses: awalsh128/cache-apt-pkgs-action@v1.4.1 + uses: awalsh128/cache-apt-pkgs-action@v1.6.0 with: packages: cmake - name: Setup PHP - uses: shivammathur/setup-php@2.29.0 + uses: shivammathur/setup-php@2.36.0 with: php-version: ${{ matrix.php-version }} extensions: json @@ -142,13 +142,13 @@ jobs: run: docker compose up -d rabbitmq - name: Install packages - uses: awalsh128/cache-apt-pkgs-action@v1.4.1 + uses: awalsh128/cache-apt-pkgs-action@v1.6.0 with: packages: cmake valgrind libc6-dbg gcc clang version: ${{ (matrix.librabbitmq-version == '0.10.0' || matrix.librabbitmq-version == '0.9.0' || matrix.librabbitmq-version == '0.8.0') && 'ubuntu-20.04' || 'ubuntu-22.04' }} - name: Setup PHP - uses: shivammathur/setup-php@2.29.0 + uses: shivammathur/setup-php@2.36.0 with: php-version: ${{ matrix.php-version }} coverage: none From 43209e0c2cb763bdfc84612b2ff4abad364118dc Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Fri, 19 Dec 2025 16:33:38 +0100 Subject: [PATCH 128/147] Fix non-deterministic tests --- docker-compose.yml | 2 -- tests/amqpexchange_invalid_type.phpt | 6 ++-- ...publish_with_properties_nested_header.phpt | 31 +++++++++++++------ tests/amqpqueue_headers_with_bool.phpt | 8 +++-- tests/amqpqueue_headers_with_float.phpt | 8 +++-- tests/amqpqueue_nested_arrays.phpt | 9 ++++-- 6 files changed, 41 insertions(+), 23 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index c0b9a1f4..efa14b1f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: "3.9" - services: rabbitmq: image: rabbitmq:3-management-alpine diff --git a/tests/amqpexchange_invalid_type.phpt b/tests/amqpexchange_invalid_type.phpt index 3cee7598..bff0e8cb 100644 --- a/tests/amqpexchange_invalid_type.phpt +++ b/tests/amqpexchange_invalid_type.phpt @@ -30,9 +30,9 @@ echo "Channel ", $ch->isConnected() ? 'connected' : 'disconnected', PHP_EOL; echo "Connection ", $cnn->isConnected() ? 'connected' : 'disconnected', PHP_EOL; ?> ---EXPECT-- +--EXPECTF-- Channel connected Connection connected -AMQPConnectionException(503): Server connection error: 503, message: COMMAND_INVALID - unknown exchange type 'invalid_exchange_type' +AMQPExchangeException(%d): %s - unknown exchange type 'invalid_exchange_type' Channel disconnected -Connection disconnected \ No newline at end of file +Connection connected diff --git a/tests/amqpexchange_publish_with_properties_nested_header.phpt b/tests/amqpexchange_publish_with_properties_nested_header.phpt index 89c98f9d..1cc008c5 100644 --- a/tests/amqpexchange_publish_with_properties_nested_header.phpt +++ b/tests/amqpexchange_publish_with_properties_nested_header.phpt @@ -43,9 +43,10 @@ echo $message->getHeaders() === $headers ? 'same' : 'differs'; echo PHP_EOL, PHP_EOL; -$headers = array( +$originalHeaders = array( 'x-death' => array( array ( + 'count' => 1, 'reason' => 'rejected', 'queue' => 'my_queue', 'time' => 1410527691, @@ -55,12 +56,16 @@ $headers = array( ) ); -$ex->publish('message', 'routing.key', AMQP_NOPARAM, array('headers' => $headers)); +$ex->publish('message', 'routing.key', AMQP_NOPARAM, array('headers' => $originalHeaders)); $message = $q->get(AMQP_AUTOACK); -var_dump($message->getHeaders()); -var_dump($headers); -echo $message->getHeaders() === $headers ? 'same' : 'differs'; +$messageHeaders = $message->getHeaders(); +ksort($messageHeaders); +var_dump($originalHeaders); +var_dump($messageHeaders); +echo $messageHeaders['x-death'][0]['time']->getTimestamp() === (float) $originalHeaders['x-death'][0]['time'] ? "timestamp matches\n" : "timestamp differs\n"; +unset($messageHeaders['x-death'][0]['time'], $originalHeaders['x-death'][0]['time']); +echo $messageHeaders === $originalHeaders ? "headers (except timestamp) identical\n" : "headers (except timestamp) also differ\n"; echo PHP_EOL, PHP_EOL; ?> @@ -103,7 +108,9 @@ array(1) { ["x-death"]=> array(1) { [0]=> - array(5) { + array(6) { + ["count"]=> + int(1) ["reason"]=> string(8) "rejected" ["queue"]=> @@ -124,13 +131,18 @@ array(1) { ["x-death"]=> array(1) { [0]=> - array(5) { + array(6) { + ["count"]=> + int(1) ["reason"]=> string(8) "rejected" ["queue"]=> string(8) "my_queue" ["time"]=> - int(1410527691) + object(AMQPTimestamp)#7 (1) { + ["timestamp":"AMQPTimestamp":private]=> + float(1410527691) + } ["exchange"]=> string(11) "my_exchange" ["routing-keys"]=> @@ -141,4 +153,5 @@ array(1) { } } } -same \ No newline at end of file +timestamp matches +headers (except timestamp) identical diff --git a/tests/amqpqueue_headers_with_bool.phpt b/tests/amqpqueue_headers_with_bool.phpt index c8b96590..e758ab78 100644 --- a/tests/amqpqueue_headers_with_bool.phpt +++ b/tests/amqpqueue_headers_with_bool.phpt @@ -37,7 +37,9 @@ $ex->publish( // Read from the queue $msg = $q->get(AMQP_AUTOACK); -var_dump($msg->getHeaders()); +$headers = $msg->getHeaders(); +ksort($headers); +var_dump($headers); echo $msg->getHeader('foo') . "\n"; var_dump($msg->hasHeader('true'), $msg->getHeader('true')); var_dump($msg->hasHeader('false'), $msg->getHeader('false')); @@ -47,12 +49,12 @@ $q->delete(); ?> --EXPECT-- array(3) { + ["false"]=> + bool(false) ["foo"]=> string(3) "bar" ["true"]=> bool(true) - ["false"]=> - bool(false) } bar bool(true) diff --git a/tests/amqpqueue_headers_with_float.phpt b/tests/amqpqueue_headers_with_float.phpt index 35ecc223..f5db8c36 100644 --- a/tests/amqpqueue_headers_with_float.phpt +++ b/tests/amqpqueue_headers_with_float.phpt @@ -39,7 +39,9 @@ $ex->publish( // Read from the queue $msg = $q->get(AMQP_AUTOACK); -var_dump($msg->getHeaders()); +$headers = $msg->getHeaders(); +ksort($headers); +var_dump($headers); echo $msg->getHeader('foo') . "\n"; var_dump($msg->hasHeader('positive'), $msg->getHeader('positive')); var_dump($msg->hasHeader('negative'), $msg->getHeader('negative')); @@ -53,10 +55,10 @@ $q->delete(); array(5) { ["foo"]=> string(3) "bar" - ["positive"]=> - float(2.3) ["negative"]=> float(-1022.123456789) + ["positive"]=> + float(2.3) ["scientific"]=> float(1000) ["scientific_big"]=> diff --git a/tests/amqpqueue_nested_arrays.phpt b/tests/amqpqueue_nested_arrays.phpt index 390470c0..d056e762 100644 --- a/tests/amqpqueue_nested_arrays.phpt +++ b/tests/amqpqueue_nested_arrays.phpt @@ -36,7 +36,10 @@ $ex->publish( // Read from the queue $msg = $q->get(AMQP_AUTOACK); -var_dump($msg->getHeaders()); +$headers = $msg->getHeaders(); +ksort($headers); + +var_dump($headers); echo $msg->getHeader('foo') . "\n"; var_dump($msg->getHeader('baz')); @@ -45,8 +48,6 @@ $q->delete(); ?> --EXPECT-- array(2) { - ["foo"]=> - string(3) "bar" ["baz"]=> array(3) { [0]=> @@ -56,6 +57,8 @@ array(2) { [2]=> string(3) "def" } + ["foo"]=> + string(3) "bar" } bar array(3) { From 8b76bad74a7954839d8808130d6cc9db435532ac Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Fri, 19 Dec 2025 16:47:32 +0100 Subject: [PATCH 129/147] Fix formatting --- .clang-format | 2 +- amqp_channel.c | 6 +++--- amqp_connection_resource.c | 2 +- amqp_exchange.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.clang-format b/.clang-format index adc0bce2..3a14f913 100644 --- a/.clang-format +++ b/.clang-format @@ -86,4 +86,4 @@ SortIncludes: Never IndentWrappedFunctionNames: true InsertNewlineAtEOF: true PenaltyReturnTypeOnItsOwnLine: 9999 -PenaltyExcessCharacter: 999 \ No newline at end of file +PenaltyExcessCharacter: 999 diff --git a/amqp_channel.c b/amqp_channel.c index 860daad9..2cd7414b 100644 --- a/amqp_channel.c +++ b/amqp_channel.c @@ -65,7 +65,7 @@ zend_class_entry *amqp_channel_class_entry; zend_object_handlers amqp_channel_object_handlers; -void php_amqp_close_channel(amqp_channel_resource *channel_resource, bool throw) +void php_amqp_close_channel(amqp_channel_resource *channel_resource, bool throw_exception) { assert(channel_resource != NULL); @@ -93,7 +93,7 @@ void php_amqp_close_channel(amqp_channel_resource *channel_resource, bool throw) amqp_rpc_reply_t close_res = amqp_channel_close(connection_resource->connection_state, channel_resource->channel_id, AMQP_REPLY_SUCCESS); - if (throw && PHP_AMQP_MAYBE_ERROR(close_res, channel_resource, connection_resource)) { + if (throw_exception && PHP_AMQP_MAYBE_ERROR(close_res, channel_resource, connection_resource)) { php_amqp_zend_throw_exception_short(close_res, amqp_channel_exception_class_entry); goto err; } @@ -103,7 +103,7 @@ void php_amqp_close_channel(amqp_channel_resource *channel_resource, bool throw) } amqp_rpc_reply_t reply_res = amqp_get_rpc_reply(connection_resource->connection_state); - if (throw && PHP_AMQP_MAYBE_ERROR(reply_res, channel_resource, connection_resource)) { + if (throw_exception && PHP_AMQP_MAYBE_ERROR(reply_res, channel_resource, connection_resource)) { php_amqp_zend_throw_exception_short(reply_res, amqp_channel_exception_class_entry); goto err; } diff --git a/amqp_connection_resource.c b/amqp_connection_resource.c index 8809a20b..49fb98fb 100644 --- a/amqp_connection_resource.c +++ b/amqp_connection_resource.c @@ -696,7 +696,7 @@ static void connection_resource_destructor(amqp_connection_resource *resource, i */ struct sigaction oldact; - struct sigaction act = { 0 }; + struct sigaction act = {0}; act.sa_flags = SA_ONSTACK; act.sa_handler = SIG_IGN; diff --git a/amqp_exchange.c b/amqp_exchange.c index fd772716..138759c3 100644 --- a/amqp_exchange.c +++ b/amqp_exchange.c @@ -622,7 +622,7 @@ static PHP_METHOD(amqp_exchange_class, publish) #ifndef PHP_WIN32 /* Start ignoring SIGPIPE */ struct sigaction oldact; - struct sigaction act = { 0 }; + struct sigaction act = {0}; act.sa_flags = SA_ONSTACK; act.sa_handler = SIG_IGN; From e12a99c373688993cda4434c280b948bae5f53fc Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Fri, 19 Dec 2025 18:18:28 +0100 Subject: [PATCH 130/147] Update runner images, no longer build against ancient librabbitmq versions --- .github/workflows/test.yaml | 11 +++++------ infra/tools/pamqp-matrix | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e2600df9..b52c8645 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -14,7 +14,7 @@ jobs: prep: name: Prepare continue-on-error: true - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 outputs: should_skip: ${{ steps.skip_check.outputs.should_skip }} php_versions: ${{ steps.matrix.outputs.php_versions }} @@ -39,7 +39,7 @@ jobs: checkstyle: name: Check C formatting - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 needs: prep if: needs.prep.outputs.should_skip != 'true' @@ -60,7 +60,7 @@ jobs: stubs: name: Check stubs php-${{ matrix.php-version }} - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 needs: prep if: needs.prep.outputs.should_skip != 'true' @@ -107,8 +107,7 @@ jobs: test: name: ${{ matrix.test-php-args == '-m' && 'Memtest' || 'Test' }} php-${{ matrix.php-version }}${{ matrix.php-thread-safe && '-ts' || '-nts' }} librabbitmq-${{ matrix.librabbitmq-version }} ${{ matrix.compiler }} - # librabbitmq < 0.11 needs older OpenSSL version which comes with Ubuntu 20.04 - runs-on: ${{ (matrix.librabbitmq-version == '0.10.0' || matrix.librabbitmq-version == '0.9.0' || matrix.librabbitmq-version == '0.8.0') && 'ubuntu-20.04' || 'ubuntu-22.04' }} + runs-on: ubuntu-24.04 needs: prep if: needs.prep.outputs.should_skip != 'true' @@ -145,7 +144,7 @@ jobs: uses: awalsh128/cache-apt-pkgs-action@v1.6.0 with: packages: cmake valgrind libc6-dbg gcc clang - version: ${{ (matrix.librabbitmq-version == '0.10.0' || matrix.librabbitmq-version == '0.9.0' || matrix.librabbitmq-version == '0.8.0') && 'ubuntu-20.04' || 'ubuntu-22.04' }} + version: ubuntu-24.04 - name: Setup PHP uses: shivammathur/setup-php@2.36.0 diff --git a/infra/tools/pamqp-matrix b/infra/tools/pamqp-matrix index 7bf54f25..9dbb53c6 100755 --- a/infra/tools/pamqp-matrix +++ b/infra/tools/pamqp-matrix @@ -1,6 +1,6 @@ #!/usr/bin/env node const PHP_VERSIONS = ["8.5", "8.4", "8.3", "8.2", "8.1", "8.0", "7.4"] -const LIBRABBITMQ_VERSIONS = ["master", "0.13.0", "0.12.0", "0.11.0", "0.10.0", "0.9.0", "0.8.0"] +const LIBRABBITMQ_VERSIONS = ["master", "0.15.0", "0.14.0", "0.13.0", "0.12.0", "0.11.0"] const toOutput = (k, v) => console.log(`${k}=${JSON.stringify(v)}`) const stringSum = (s) => ([...s].map(c => c.charCodeAt(0)).reduce((c, v) => c + v, 0)) From 6f1c675c0a6b12aebf10320101b9c7f5c9dfe414 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Fri, 4 Jul 2025 12:13:08 +0200 Subject: [PATCH 131/147] Use php_format_date instead of php_std_date - php_format_date exists in 7.4+ - php_std_date removed in 8.5 x --- amqp_connection_resource.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/amqp_connection_resource.c b/amqp_connection_resource.c index 49fb98fb..520f26ec 100644 --- a/amqp_connection_resource.c +++ b/amqp_connection_resource.c @@ -26,7 +26,7 @@ #endif #include "php.h" -#include "ext/standard/datetime.h" +#include "ext/date/php_date.h" #include "zend_exceptions.h" #ifdef PHP_WIN32 @@ -470,8 +470,8 @@ amqp_connection_resource *connection_resource_constructor(amqp_connection_params { struct timeval tv = {0}; struct timeval *tv_ptr = &tv; + zend_string *std_datetime; - char *std_datetime; amqp_table_entry_t client_properties_entries[4]; amqp_table_t client_properties_table; @@ -581,8 +581,6 @@ amqp_connection_resource *connection_resource_constructor(amqp_connection_params return NULL; } - std_datetime = php_std_date(time(NULL)); - client_properties_entries[0].key = amqp_cstring_bytes("type"); client_properties_entries[0].value.kind = AMQP_FIELD_KIND_UTF8; client_properties_entries[0].value.value.bytes = amqp_cstring_bytes("php-amqp extension"); @@ -597,7 +595,8 @@ amqp_connection_resource *connection_resource_constructor(amqp_connection_params client_properties_entries[3].key = amqp_cstring_bytes("connection started"); client_properties_entries[3].value.kind = AMQP_FIELD_KIND_UTF8; - client_properties_entries[3].value.value.bytes = amqp_cstring_bytes(std_datetime); + std_datetime = php_format_date("D, d M Y H:i:s \\G\\M\\T", sizeof("D, d M Y H:i:s \\G\\M\\T")-1, time(NULL), 0); + client_properties_entries[3].value.value.bytes = amqp_cstring_bytes(ZSTR_VAL(std_datetime)); client_properties_table.entries = client_properties_entries; client_properties_table.num_entries = sizeof(client_properties_entries) / sizeof(amqp_table_entry_t); @@ -632,7 +631,7 @@ amqp_connection_resource *connection_resource_constructor(amqp_connection_params params->password ); - efree(std_datetime); + zend_string_release(std_datetime); if (AMQP_RESPONSE_NORMAL != res.reply_type) { char *message = NULL, *long_message = NULL; From a7141b20e40c4370ce4555b089ec960cd61a56f6 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Tue, 15 Jul 2025 14:50:40 +0200 Subject: [PATCH 132/147] use zend_ce_exception --- amqp.c | 2 +- amqp_queue.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/amqp.c b/amqp.c index ef04488d..84a87b7b 100644 --- a/amqp.c +++ b/amqp.c @@ -276,7 +276,7 @@ static PHP_MINIT_FUNCTION(amqp) /* {{{ */ /* Exceptions */ INIT_CLASS_ENTRY(ce, "AMQPException", NULL); - amqp_exception_class_entry = zend_register_internal_class_ex(&ce, zend_exception_get_default()); + amqp_exception_class_entry = zend_register_internal_class_ex(&ce, zend_ce_exception); INIT_CLASS_ENTRY(ce, "AMQPConnectionException", NULL); amqp_connection_exception_class_entry = zend_register_internal_class_ex(&ce, amqp_exception_class_entry); diff --git a/amqp_queue.c b/amqp_queue.c index eeeec3df..48287fa1 100644 --- a/amqp_queue.c +++ b/amqp_queue.c @@ -754,7 +754,7 @@ static PHP_METHOD(amqp_queue_class, consume) ZVAL_UNDEF(&exception); object_init_ex(&exception, amqp_envelope_exception_class_entry); zend_update_property_string( - zend_exception_get_default(), + zend_ce_exception, PHP_AMQP_COMPAT_OBJ_P(&exception), ZEND_STRL("message"), "Orphaned envelope" From ae0ab5621126bc0c442a30c6c7e27ce5bc049846 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Fri, 19 Dec 2025 20:14:20 +0100 Subject: [PATCH 133/147] PHP 8.5 toolchain update (#604) --- .clang-format | 2 ++ .github/workflows/test.yaml | 4 +-- amqp_connection.c | 2 +- amqp_connection_resource.c | 2 +- docker-compose.yml | 48 ++++++++++++++++++++++++++++ infra/dev/Dockerfile | 9 +++--- infra/tools/pamqp-format | 2 +- tests/amqpconnection_validation.phpt | 6 ++-- 8 files changed, 62 insertions(+), 13 deletions(-) diff --git a/.clang-format b/.clang-format index 3a14f913..84b8b71a 100644 --- a/.clang-format +++ b/.clang-format @@ -33,6 +33,8 @@ Macros: - "PHP_AMQP_MAYBE_ERROR(a, b)=(a && b)" StatementMacros: - PHP_AMQP_NOPARAMS +WhitespaceSensitiveMacros: + - PHP_ME BraceWrapping: AfterCaseLabel: false AfterClass: false diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index b52c8645..7042da87 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -47,10 +47,10 @@ jobs: - name: Install clang-format uses: myci-actions/add-deb-repo@11 with: - repo: 'deb https://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main' + repo: 'deb https://apt.llvm.org/jammy/ llvm-toolchain-jammy-20 main' repo-name: llvm keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - install: clang-format-17 + install: clang-format-20 - name: Checkout uses: actions/checkout@v4.1.1 diff --git a/amqp_connection.c b/amqp_connection.c index 7f5573d3..1d245354 100644 --- a/amqp_connection.c +++ b/amqp_connection.c @@ -1925,7 +1925,7 @@ zend_function_entry amqp_connection_class_functions[] = { PHP_ME(amqp_connection_class, setWriteTimeout, arginfo_amqp_connection_class_setWriteTimeout, ZEND_ACC_PUBLIC) PHP_ME(amqp_connection_class, getConnectTimeout, arginfo_amqp_connection_class_getConnectTimeout, ZEND_ACC_PUBLIC) - /** setConnectTimeout intentionally left out */ + /** setConnectTimeout intentionally left out */ PHP_ME(amqp_connection_class, getRpcTimeout, arginfo_amqp_connection_class_getRpcTimeout, ZEND_ACC_PUBLIC) PHP_ME(amqp_connection_class, setRpcTimeout, arginfo_amqp_connection_class_setRpcTimeout, ZEND_ACC_PUBLIC) diff --git a/amqp_connection_resource.c b/amqp_connection_resource.c index 520f26ec..a070bd13 100644 --- a/amqp_connection_resource.c +++ b/amqp_connection_resource.c @@ -595,7 +595,7 @@ amqp_connection_resource *connection_resource_constructor(amqp_connection_params client_properties_entries[3].key = amqp_cstring_bytes("connection started"); client_properties_entries[3].value.kind = AMQP_FIELD_KIND_UTF8; - std_datetime = php_format_date("D, d M Y H:i:s \\G\\M\\T", sizeof("D, d M Y H:i:s \\G\\M\\T")-1, time(NULL), 0); + std_datetime = php_format_date("D, d M Y H:i:s \\G\\M\\T", sizeof("D, d M Y H:i:s \\G\\M\\T") - 1, time(NULL), 0); client_properties_entries[3].value.value.bytes = amqp_cstring_bytes(ZSTR_VAL(std_datetime)); client_properties_table.entries = client_properties_entries; diff --git a/docker-compose.yml b/docker-compose.yml index efa14b1f..d5dcdbb8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -89,6 +89,22 @@ services: php_version: "8.3" working_dir: /src/build/centos-83 + centos-84: + <<: *centos-dev + build: + <<: *centos-dev-build + args: + php_version: "8.4" + working_dir: /src/build/centos-84 + + centos-85: + <<: *centos-dev + build: + <<: *centos-dev-build + args: + php_version: "8.5" + working_dir: /src/build/centos-85 + ubuntu-74: &ubuntu-dev build: &ubuntu-dev-build context: infra/dev @@ -140,6 +156,22 @@ services: php_version: "8.3" working_dir: /src/build/ubuntu-83 + ubuntu-84: + <<: *ubuntu-dev + build: + <<: *ubuntu-dev-build + args: + php_version: "8.4" + working_dir: /src/build/ubuntu-84 + + ubuntu-85: + <<: *ubuntu-dev + build: + <<: *ubuntu-dev-build + args: + php_version: "8.5" + working_dir: /src/build/ubuntu-85 + debian-74: &debian-dev build: &debian-dev-build context: infra/dev @@ -188,3 +220,19 @@ services: additional_contexts: base: docker-image://php:8.3-rc-zts-bookworm working_dir: /src/build/debian-83 + + debian-84: + <<: *debian-dev + build: + <<: *debian-dev-build + additional_contexts: + base: docker-image://php:8.4-rc-zts-trixie + working_dir: /src/build/debian-84 + + debian-85: + <<: *debian-dev + build: + <<: *debian-dev-build + additional_contexts: + base: docker-image://php:8.5-rc-zts-trixie + working_dir: /src/build/debian-85 diff --git a/infra/dev/Dockerfile b/infra/dev/Dockerfile index ef2dac05..2cc35e97 100644 --- a/infra/dev/Dockerfile +++ b/infra/dev/Dockerfile @@ -8,7 +8,6 @@ FROM common AS redhatish RUN dnf install -y 'dnf-command(config-manager)' RUN dnf config-manager --set-enabled crb RUN dnf install -y gcc clang libtool pkg-config autoconf gdb valgrind git unzip librabbitmq-devel -# FIXME: clang-format 17.x not available yet RUN dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm ARG php_version RUN dnf module install -y php:remi-${php_version} @@ -18,13 +17,13 @@ RUN dnf install -y php-devel FROM common AS debianish ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update -yqq -RUN apt-get install -yqq software-properties-common curl +RUN apt-get install -yqq curl RUN . /etc/os-release && \ curl https://apt.llvm.org/llvm-snapshot.gpg.key > /etc/apt/trusted.gpg.d/llvm-snapshot.asc && \ - echo "deb https://apt.llvm.org/$VERSION_CODENAME llvm-toolchain-$VERSION_CODENAME-17 main" > /etc/apt/sources.list.d/llvm.list + echo "deb https://apt.llvm.org/$VERSION_CODENAME llvm-toolchain-$VERSION_CODENAME-20 main" > /etc/apt/sources.list.d/llvm.list RUN apt-get update -yqq RUN apt-get install -yqq gcc clang libtool pkg-config autoconf gdb valgrind librabbitmq-dev git unzip -RUN apt-get install -yqq clang-format-17 +RUN apt-get install -yqq clang-format-20 # Install PHP on Ubuntu FROM debianish AS ubuntu-php @@ -50,6 +49,6 @@ RUN apt-get install -y --no-install-recommends \ && \ docker-php-source extract && \ cd /usr/src/php && \ - ./configure $(php --info | grep "^Configure Command" | cut -d " " -f 7- | rev | cut -d " " -f 2- | rev | tr "'" " ") --enable-debug && \ + sh -c 'eval $(php --info | grep "^Configure Command" | cut -d " " -f 5-) --enable-debug' && \ make -j $(nproc) && \ make install \ diff --git a/infra/tools/pamqp-format b/infra/tools/pamqp-format index 04f50cda..506e0973 100755 --- a/infra/tools/pamqp-format +++ b/infra/tools/pamqp-format @@ -5,4 +5,4 @@ set -o nounset base_dir=`dirname $0`/../../ -clang-format-17 -i $base_dir/*.c $base_dir/*.h $@ \ No newline at end of file +clang-format-20 -i $base_dir/*.c $base_dir/*.h $@ diff --git a/tests/amqpconnection_validation.phpt b/tests/amqpconnection_validation.phpt index 9f67cf67..4ceb9986 100644 --- a/tests/amqpconnection_validation.phpt +++ b/tests/amqpconnection_validation.phpt @@ -99,14 +99,14 @@ AMQPConnectionException: Parameter 'rpc_timeout' must be greater than or equal t AMQPConnectionException: Parameter 'rpcTimeout' must be greater than or equal to zero. getRpcTimeout after constructor: 50 getRpcTimeout after setter: 50 -AMQPConnectionException: Parameter 'frame_max' is out of range. +AMQPConnectionException: Parameter 'frame_max' is out of range.%A AMQPConnectionException: Parameter 'frame_max' is out of range. getMaxFrameSize after constructor: 128 AMQPConnectionException: Parameter 'channel_max' is out of range. AMQPConnectionException: Parameter 'channel_max' is out of range. getMaxChannels after constructor: 128 -AMQPConnectionException: Parameter 'heartbeat' is out of range. +AMQPConnectionException: Parameter 'heartbeat' is out of range.%A AMQPConnectionException: Parameter 'heartbeat' is out of range. getHeartbeatInterval after constructor: 250 getHeartbeatInterval after constructor: 0 -==DONE== \ No newline at end of file +==DONE== From 3ea6d56733104730ed19f054b8bd64583532e708 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Sat, 20 Dec 2025 23:21:57 +0100 Subject: [PATCH 134/147] Fix segmentation fault in php_amqp_close_channel #598 (#606) Co-authored-by: Paul Johnston --- amqp_channel.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/amqp_channel.c b/amqp_channel.c index 2cd7414b..4b62d0fc 100644 --- a/amqp_channel.c +++ b/amqp_channel.c @@ -90,35 +90,40 @@ void php_amqp_close_channel(amqp_channel_resource *channel_resource, bool throw_ if (connection_resource && connection_resource->is_connected && channel_resource->channel_id > 0) { assert(connection_resource != NULL); + // assume below methods will fail and mark slot as used + // If PHP_AMQP_MAYBE_ERROR fails it may free the connection_resource by calling php_amqp_disconnect_force + // So we cannot increment the used slots after the error as some code paths result in `use after free` on + // the connection_resource. + // In other code paths (error but not free) the connection_resource object is still valid and only the channels + // slot should be marked as used. + connection_resource->used_slots++; + amqp_rpc_reply_t close_res = amqp_channel_close(connection_resource->connection_state, channel_resource->channel_id, AMQP_REPLY_SUCCESS); if (throw_exception && PHP_AMQP_MAYBE_ERROR(close_res, channel_resource, connection_resource)) { php_amqp_zend_throw_exception_short(close_res, amqp_channel_exception_class_entry); - goto err; + return; } if (close_res.reply_type != AMQP_RESPONSE_NORMAL) { - goto err; + return; } amqp_rpc_reply_t reply_res = amqp_get_rpc_reply(connection_resource->connection_state); if (throw_exception && PHP_AMQP_MAYBE_ERROR(reply_res, channel_resource, connection_resource)) { php_amqp_zend_throw_exception_short(reply_res, amqp_channel_exception_class_entry); - goto err; + return; } if (reply_res.reply_type != AMQP_RESPONSE_NORMAL) { - goto err; + return; } php_amqp_maybe_release_buffers_on_channel(connection_resource, channel_resource); - return; - - err: - // Mark failed slot as used - connection_resource->used_slots++; - return; + // was successful, let the slot be used again + // we know connection_resource is still valid at this point + connection_resource->used_slots--; } } From 96510ee93639aaae90c600a8722780e6ca580930 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Fri, 2 Jan 2026 13:02:16 +0100 Subject: [PATCH 135/147] Use ZEND_LONG_FMT and ZEND_ULONG_FMT to fix warnings on 32-bit (#607) Co-authored-by: Andy Postnikov --- amqp_basic_properties.c | 2 +- amqp_connection_resource.c | 8 ++++---- amqp_type.c | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/amqp_basic_properties.c b/amqp_basic_properties.c index 1edd6968..ac4056ed 100644 --- a/amqp_basic_properties.c +++ b/amqp_basic_properties.c @@ -607,7 +607,7 @@ bool php_amqp_basic_properties_value_to_zval_internal(amqp_field_value_t *value, zend_throw_exception_ex( amqp_exception_class_entry, 0, - "Maximum deserialization depth limit of %ld reached while deserializing value", + "Maximum deserialization depth limit of " ZEND_LONG_FMT " reached while deserializing value", PHP_AMQP_G(deserialization_depth) ); return 0; diff --git a/amqp_connection_resource.c b/amqp_connection_resource.c index a070bd13..0818475d 100644 --- a/amqp_connection_resource.c +++ b/amqp_connection_resource.c @@ -142,8 +142,8 @@ static void php_amqp_close_connection_from_server( spprintf( message, 0, - "Server connection error: %ld, message: %s", - (long) PHP_AMQP_G(error_code), + "Server connection error: " ZEND_LONG_FMT ", message: %s", + PHP_AMQP_G(error_code), "unexpected response" ); } else { @@ -198,8 +198,8 @@ static void php_amqp_close_channel_from_server( spprintf( message, 0, - "Server channel error: %ld, message: %s", - (long) PHP_AMQP_G(error_code), + "Server channel error: " ZEND_LONG_FMT ", message: %s", + PHP_AMQP_G(error_code), "unexpected response" ); } else { diff --git a/amqp_type.c b/amqp_type.c index 71abfb31..08da4b90 100644 --- a/amqp_type.c +++ b/amqp_type.c @@ -141,11 +141,11 @@ void php_amqp_type_zval_to_amqp_table_internal(zval *array, amqp_table_t *amqp_t /* Convert to strings non-string keys */ char str[32]; - key_len = snprintf(str, 32, "%lu", index); + key_len = snprintf(str, 32, ZEND_ULONG_FMT, index); key = str; } else { /* Skip things that are not strings */ - php_error_docref(NULL, E_WARNING, "Ignoring non-string header field '%lu'", index); + php_error_docref(NULL, E_WARNING, "Ignoring non-string header field '" ZEND_ULONG_FMT "'", index); continue; } @@ -209,7 +209,7 @@ bool php_amqp_type_zval_to_amqp_value_internal(zval *value, amqp_field_value_t * zend_throw_exception_ex( amqp_exception_class_entry, 0, - "Maximum serialization depth of %ld reached while serializing value", + "Maximum serialization depth of " ZEND_LONG_FMT " reached while serializing value", PHP_AMQP_G(serialization_depth) ); return 0; From f2df48496693f8aa2942fad3606838149deb82ea Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Fri, 2 Jan 2026 13:18:31 +0100 Subject: [PATCH 136/147] [RM] releasing version 2.2.0 --- package.xml | 33 ++++++++++++++++++++++++--------- php_amqp_version.h | 4 ++-- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/package.xml b/package.xml index 2cc2a2cf..8c15e8d6 100644 --- a/package.xml +++ b/package.xml @@ -22,22 +22,37 @@ pinepain@gmail.com yes - 2024-01-22 - + 2026-01-02 + - 2.2.0dev - 2.2.0dev + 2.2.0 + 2.2.0 - devel - devel + stable + stable PHP License - ) (https://github.com/php-amqp/php-amqp/issues/589) + - Enable support for PIE (James Titcumb ) (https://github.com/php-amqp/php-amqp/issues/584) + - Ignore codebase reformatting for blame (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/2ed7b6a) + - PHP 8.5 toolchain update (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/604) + - Restore changelog for 2.1.1 (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/533) + - Update runner images, no longer build against ancient librabbitmq versions (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/e12a99c) + - Upgrade GH actions (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/99acba7) + - Use ZEND_LONG_FMT and ZEND_ULONG_FMT to fix warnings on 32-bit (Andy Postnikov ) (https://github.com/php-amqp/php-amqp/issues/607) + - Use php_format_date instead of php_std_date (Remi Collet ) (https://github.com/php-amqp/php-amqp/commit/6f1c675) + - Use zend_ce_exception (Remi Collet ) (https://github.com/php-amqp/php-amqp/commit/a7141b2) + - Fix formatting (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/8b76bad) + - Fix non-deterministic tests (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/43209e0) + - Fix segmentation fault in php_amqp_close_channel #598 (Paul Johnston ) (https://github.com/php-amqp/php-amqp/issues/606) + - Fix: SIGPIPE handling (Kévin Dunglas ) (https://github.com/php-amqp/php-amqp/issues/550) + - Bump awalsh128/cache-apt-pkgs-action from 1.3.1 to 1.4.1 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/538) + - Bump squizlabs/php_codesniffer from 3.8.1 to 3.9.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/539) For a complete list of changes see: -https://github.com/php-amqp/php-amqp/compare/v2.1.2...latest -]]> +https://github.com/php-amqp/php-amqp/compare/v2.1.2...v2.2.0]]> diff --git a/php_amqp_version.h b/php_amqp_version.h index 61c2d46c..f82253dd 100644 --- a/php_amqp_version.h +++ b/php_amqp_version.h @@ -1,6 +1,6 @@ #define PHP_AMQP_VERSION_MAJOR 2 #define PHP_AMQP_VERSION_MINOR 2 #define PHP_AMQP_VERSION_PATCH 0 -#define PHP_AMQP_VERSION_EXTRA "dev" -#define PHP_AMQP_VERSION "2.2.0dev" +#define PHP_AMQP_VERSION_EXTRA "" +#define PHP_AMQP_VERSION "2.2.0" #define PHP_AMQP_VERSION_ID 20200 From 05e84490659887435c3ddde8fc76ddddfb35455f Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Fri, 2 Jan 2026 13:21:10 +0100 Subject: [PATCH 137/147] [RM] back to dev 2.2.1dev --- package.xml | 64 +++++++++++++++++++++++++++++----------------- php_amqp_version.h | 8 +++--- 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/package.xml b/package.xml index 8c15e8d6..4f08ada6 100644 --- a/package.xml +++ b/package.xml @@ -23,36 +23,21 @@ yes 2026-01-02 - + - 2.2.0 - 2.2.0 + 2.2.1dev + 2.2.1dev - stable - stable + devel + devel PHP License - ) (https://github.com/php-amqp/php-amqp/issues/589) - - Enable support for PIE (James Titcumb ) (https://github.com/php-amqp/php-amqp/issues/584) - - Ignore codebase reformatting for blame (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/2ed7b6a) - - PHP 8.5 toolchain update (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/604) - - Restore changelog for 2.1.1 (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/533) - - Update runner images, no longer build against ancient librabbitmq versions (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/e12a99c) - - Upgrade GH actions (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/99acba7) - - Use ZEND_LONG_FMT and ZEND_ULONG_FMT to fix warnings on 32-bit (Andy Postnikov ) (https://github.com/php-amqp/php-amqp/issues/607) - - Use php_format_date instead of php_std_date (Remi Collet ) (https://github.com/php-amqp/php-amqp/commit/6f1c675) - - Use zend_ce_exception (Remi Collet ) (https://github.com/php-amqp/php-amqp/commit/a7141b2) - - Fix formatting (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/8b76bad) - - Fix non-deterministic tests (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/43209e0) - - Fix segmentation fault in php_amqp_close_channel #598 (Paul Johnston ) (https://github.com/php-amqp/php-amqp/issues/606) - - Fix: SIGPIPE handling (Kévin Dunglas ) (https://github.com/php-amqp/php-amqp/issues/550) - - Bump awalsh128/cache-apt-pkgs-action from 1.3.1 to 1.4.1 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/538) - - Bump squizlabs/php_codesniffer from 3.8.1 to 3.9.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/539) + +https://github.com/php-amqp/php-amqp/compare/v2.2.0...latest +]]> @@ -318,6 +303,39 @@ https://github.com/php-amqp/php-amqp/compare/v2.1.2...v2.2.0]]> + + 2026-01-02 + + + 2.2.0 + 2.2.0 + + + stable + stable + + PHP License + ) (https://github.com/php-amqp/php-amqp/issues/589) + - Enable support for PIE (James Titcumb ) (https://github.com/php-amqp/php-amqp/issues/584) + - Ignore codebase reformatting for blame (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/2ed7b6a) + - PHP 8.5 toolchain update (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/604) + - Restore changelog for 2.1.1 (Lars Strojny ) (https://github.com/php-amqp/php-amqp/issues/533) + - Update runner images, no longer build against ancient librabbitmq versions (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/e12a99c) + - Upgrade GH actions (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/99acba7) + - Use ZEND_LONG_FMT and ZEND_ULONG_FMT to fix warnings on 32-bit (Andy Postnikov ) (https://github.com/php-amqp/php-amqp/issues/607) + - Use php_format_date instead of php_std_date (Remi Collet ) (https://github.com/php-amqp/php-amqp/commit/6f1c675) + - Use zend_ce_exception (Remi Collet ) (https://github.com/php-amqp/php-amqp/commit/a7141b2) + - Fix formatting (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/8b76bad) + - Fix non-deterministic tests (Lars Strojny ) (https://github.com/php-amqp/php-amqp/commit/43209e0) + - Fix segmentation fault in php_amqp_close_channel #598 (Paul Johnston ) (https://github.com/php-amqp/php-amqp/issues/606) + - Fix: SIGPIPE handling (Kévin Dunglas ) (https://github.com/php-amqp/php-amqp/issues/550) + - Bump awalsh128/cache-apt-pkgs-action from 1.3.1 to 1.4.1 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/538) + - Bump squizlabs/php_codesniffer from 3.8.1 to 3.9.0 (dependabot[bot]) (https://github.com/php-amqp/php-amqp/issues/539) + +For a complete list of changes see: +https://github.com/php-amqp/php-amqp/compare/v2.1.2...v2.2.0]]> + 2024-01-22 diff --git a/php_amqp_version.h b/php_amqp_version.h index f82253dd..740e6d07 100644 --- a/php_amqp_version.h +++ b/php_amqp_version.h @@ -1,6 +1,6 @@ #define PHP_AMQP_VERSION_MAJOR 2 #define PHP_AMQP_VERSION_MINOR 2 -#define PHP_AMQP_VERSION_PATCH 0 -#define PHP_AMQP_VERSION_EXTRA "" -#define PHP_AMQP_VERSION "2.2.0" -#define PHP_AMQP_VERSION_ID 20200 +#define PHP_AMQP_VERSION_PATCH 1 +#define PHP_AMQP_VERSION_EXTRA "dev" +#define PHP_AMQP_VERSION "2.2.1dev" +#define PHP_AMQP_VERSION_ID 20201 From fcc02262ef8146b90a3e24bafd162acca55c72e1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 2 Jan 2026 14:31:20 +0100 Subject: [PATCH 138/147] Bump actions/checkout from 4.1.1 to 4.1.7 (#569) Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.1 to 4.1.7. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v4.1.1...v4.1.7) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/test.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 7042da87..e52cb7b1 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -30,7 +30,7 @@ jobs: concurrent_skipping: 'same_content_newer' - name: Checkout - uses: actions/checkout@v4.1.1 + uses: actions/checkout@v6.0.1 - name: Prepare matrix id: matrix @@ -53,7 +53,7 @@ jobs: install: clang-format-20 - name: Checkout - uses: actions/checkout@v4.1.1 + uses: actions/checkout@v6.0.1 - name: Check style run: ./infra/tools/pamqp-format-check @@ -71,7 +71,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v4.1.1 + uses: actions/checkout@v6.0.1 - name: Install packages uses: awalsh128/cache-apt-pkgs-action@v1.6.0 @@ -129,7 +129,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v4.1.1 + uses: actions/checkout@v6.0.1 - name: Configure hostnames run: sudo echo "127.0.0.1 ${{ env.PHP_AMQP_SSL_HOST }}" | sudo tee -a /etc/hosts From 5afeaedf6e833b846800dbe4ffff6a8fe475f5e9 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Fri, 2 Jan 2026 14:31:51 +0100 Subject: [PATCH 139/147] Update stub formatters (#608) --- composer.lock | 146 +++++++++++++++------------ ecs.php | 6 +- infra/tools/pamqp-arguments-validate | 1 + infra/tools/pamqp-docker-setup | 1 + infra/tools/pamqp-dump-reflection | 1 + stubs/AMQP.php | 1 + stubs/AMQPBasicProperties.php | 13 --- stubs/AMQPValue.php | 1 + 8 files changed, 90 insertions(+), 80 deletions(-) diff --git a/composer.lock b/composer.lock index 93afd2f1..5c5420c9 100644 --- a/composer.lock +++ b/composer.lock @@ -9,29 +9,29 @@ "packages-dev": [ { "name": "dealerdirect/phpcodesniffer-composer-installer", - "version": "v1.0.0", + "version": "v1.2.0", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/composer-installer.git", - "reference": "4be43904336affa5c2f70744a348312336afd0da" + "reference": "845eb62303d2ca9b289ef216356568ccc075ffd1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/composer-installer/zipball/4be43904336affa5c2f70744a348312336afd0da", - "reference": "4be43904336affa5c2f70744a348312336afd0da", + "url": "https://api.github.com/repos/PHPCSStandards/composer-installer/zipball/845eb62303d2ca9b289ef216356568ccc075ffd1", + "reference": "845eb62303d2ca9b289ef216356568ccc075ffd1", "shasum": "" }, "require": { - "composer-plugin-api": "^1.0 || ^2.0", + "composer-plugin-api": "^2.2", "php": ">=5.4", - "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" + "squizlabs/php_codesniffer": "^3.1.0 || ^4.0" }, "require-dev": { - "composer/composer": "*", + "composer/composer": "^2.2", "ext-json": "*", "ext-zip": "*", - "php-parallel-lint/php-parallel-lint": "^1.3.1", - "phpcompatibility/php-compatibility": "^9.0", + "php-parallel-lint/php-parallel-lint": "^1.4.0", + "phpcompatibility/php-compatibility": "^9.0 || ^10.0.0@dev", "yoast/phpunit-polyfills": "^1.0" }, "type": "composer-plugin", @@ -50,9 +50,9 @@ "authors": [ { "name": "Franck Nijhof", - "email": "franck.nijhof@dealerdirect.com", - "homepage": "http://www.frenck.nl", - "role": "Developer / IT Manager" + "email": "opensource@frenck.dev", + "homepage": "https://frenck.dev", + "role": "Open source developer" }, { "name": "Contributors", @@ -60,7 +60,6 @@ } ], "description": "PHP_CodeSniffer Standards Composer Installer Plugin", - "homepage": "http://www.dealerdirect.com", "keywords": [ "PHPCodeSniffer", "PHP_CodeSniffer", @@ -81,36 +80,55 @@ ], "support": { "issues": "https://github.com/PHPCSStandards/composer-installer/issues", + "security": "https://github.com/PHPCSStandards/composer-installer/security/policy", "source": "https://github.com/PHPCSStandards/composer-installer" }, - "time": "2023-01-05T11:28:13+00:00" + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + }, + { + "url": "https://thanks.dev/u/gh/phpcsstandards", + "type": "thanks_dev" + } + ], + "time": "2025-11-11T04:32:07+00:00" }, { "name": "phpstan/phpdoc-parser", - "version": "1.25.0", + "version": "2.3.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "bd84b629c8de41aa2ae82c067c955e06f1b00240" + "reference": "1e0cd5370df5dd2e556a36b9c62f62e555870495" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/bd84b629c8de41aa2ae82c067c955e06f1b00240", - "reference": "bd84b629c8de41aa2ae82c067c955e06f1b00240", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/1e0cd5370df5dd2e556a36b9c62f62e555870495", + "reference": "1e0cd5370df5dd2e556a36b9c62f62e555870495", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0" + "php": "^7.4 || ^8.0" }, "require-dev": { "doctrine/annotations": "^2.0", - "nikic/php-parser": "^4.15", + "nikic/php-parser": "^5.3.0", "php-parallel-lint/php-parallel-lint": "^1.2", "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^1.5", - "phpstan/phpstan-phpunit": "^1.1", - "phpstan/phpstan-strict-rules": "^1.0", - "phpunit/phpunit": "^9.5", + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpstan/phpstan-strict-rules": "^2.0", + "phpunit/phpunit": "^9.6", "symfony/process": "^5.2" }, "type": "library", @@ -128,38 +146,38 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.25.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/2.3.0" }, - "time": "2024-01-04T17:06:16+00:00" + "time": "2025-08-30T15:50:23+00:00" }, { "name": "slevomat/coding-standard", - "version": "8.14.1", + "version": "8.26.0", "source": { "type": "git", "url": "https://github.com/slevomat/coding-standard.git", - "reference": "fea1fd6f137cc84f9cba0ae30d549615dbc6a926" + "reference": "d247cdc04b91956bdcfaa0b1313c01960b189d3c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/fea1fd6f137cc84f9cba0ae30d549615dbc6a926", - "reference": "fea1fd6f137cc84f9cba0ae30d549615dbc6a926", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/d247cdc04b91956bdcfaa0b1313c01960b189d3c", + "reference": "d247cdc04b91956bdcfaa0b1313c01960b189d3c", "shasum": "" }, "require": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7 || ^1.0", - "php": "^7.2 || ^8.0", - "phpstan/phpdoc-parser": "^1.23.1", - "squizlabs/php_codesniffer": "^3.7.1" + "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || ^1.2.0", + "php": "^7.4 || ^8.0", + "phpstan/phpdoc-parser": "^2.3.0", + "squizlabs/php_codesniffer": "^4.0.1" }, "require-dev": { - "phing/phing": "2.17.4", - "php-parallel-lint/php-parallel-lint": "1.3.2", - "phpstan/phpstan": "1.10.37", - "phpstan/phpstan-deprecation-rules": "1.1.4", - "phpstan/phpstan-phpunit": "1.3.14", - "phpstan/phpstan-strict-rules": "1.5.1", - "phpunit/phpunit": "8.5.21|9.6.8|10.3.5" + "phing/phing": "3.0.1|3.1.0", + "php-parallel-lint/php-parallel-lint": "1.4.0", + "phpstan/phpstan": "2.1.33", + "phpstan/phpstan-deprecation-rules": "2.0.3", + "phpstan/phpstan-phpunit": "2.0.11", + "phpstan/phpstan-strict-rules": "2.0.7", + "phpunit/phpunit": "9.6.31|10.5.60|11.4.4|11.5.46|12.5.4" }, "type": "phpcodesniffer-standard", "extra": { @@ -183,7 +201,7 @@ ], "support": { "issues": "https://github.com/slevomat/coding-standard/issues", - "source": "https://github.com/slevomat/coding-standard/tree/8.14.1" + "source": "https://github.com/slevomat/coding-standard/tree/8.26.0" }, "funding": [ { @@ -195,41 +213,36 @@ "type": "tidelift" } ], - "time": "2023-10-08T07:28:08+00:00" + "time": "2025-12-21T18:01:15+00:00" }, { "name": "squizlabs/php_codesniffer", - "version": "3.9.0", + "version": "4.0.1", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", - "reference": "d63cee4890a8afaf86a22e51ad4d97c91dd4579b" + "reference": "0525c73950de35ded110cffafb9892946d7771b5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/d63cee4890a8afaf86a22e51ad4d97c91dd4579b", - "reference": "d63cee4890a8afaf86a22e51ad4d97c91dd4579b", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/0525c73950de35ded110cffafb9892946d7771b5", + "reference": "0525c73950de35ded110cffafb9892946d7771b5", "shasum": "" }, "require": { "ext-simplexml": "*", "ext-tokenizer": "*", "ext-xmlwriter": "*", - "php": ">=5.4.0" + "php": ">=7.2.0" }, "require-dev": { - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" + "phpunit/phpunit": "^8.4.0 || ^9.3.4 || ^10.5.32 || 11.3.3 - 11.5.28 || ^11.5.31" }, "bin": [ "bin/phpcbf", "bin/phpcs" ], "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.x-dev" - } - }, "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" @@ -248,7 +261,7 @@ "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" } ], - "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "description": "PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.", "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", "keywords": [ "phpcs", @@ -273,22 +286,26 @@ { "url": "https://opencollective.com/php_codesniffer", "type": "open_collective" + }, + { + "url": "https://thanks.dev/u/gh/phpcsstandards", + "type": "thanks_dev" } ], - "time": "2024-02-16T15:06:51+00:00" + "time": "2025-11-10T16:43:36+00:00" }, { "name": "symplify/easy-coding-standard", - "version": "12.1.8", + "version": "13.0.0", "source": { "type": "git", "url": "https://github.com/easy-coding-standard/easy-coding-standard.git", - "reference": "7962c810a8eebc4174a38d7dff673f1999e61595" + "reference": "24708c6673871e342245c692e1bb304f119ffc58" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/7962c810a8eebc4174a38d7dff673f1999e61595", - "reference": "7962c810a8eebc4174a38d7dff673f1999e61595", + "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/24708c6673871e342245c692e1bb304f119ffc58", + "reference": "24708c6673871e342245c692e1bb304f119ffc58", "shasum": "" }, "require": { @@ -299,6 +316,9 @@ "phpcsstandards/php_codesniffer": "<3.8", "symplify/coding-standard": "<12.1" }, + "suggest": { + "ext-dom": "Needed to support checkstyle output format in class CheckstyleOutputFormatter" + }, "bin": [ "bin/ecs" ], @@ -321,7 +341,7 @@ ], "support": { "issues": "https://github.com/easy-coding-standard/easy-coding-standard/issues", - "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.1.8" + "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/13.0.0" }, "funding": [ { @@ -333,12 +353,12 @@ "type": "github" } ], - "time": "2024-01-16T22:56:06+00:00" + "time": "2025-11-06T14:47:06+00:00" } ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/ecs.php b/ecs.php index 2b93488a..e2756280 100644 --- a/ecs.php +++ b/ecs.php @@ -2,12 +2,10 @@ declare(strict_types=1); -use PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\LanguageConstructSpacingSniff; +use PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace\LanguageConstructSpacingSniff; use PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff; -use PhpCsFixer\Fixer\Basic\PsrAutoloadingFixer; use PhpCsFixer\Fixer\CastNotation\CastSpacesFixer; use PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer; -use PhpCsFixer\Fixer\ClassNotation\FinalClassFixer; use PhpCsFixer\Fixer\ClassNotation\NoBlankLinesAfterClassOpeningFixer; use PhpCsFixer\Fixer\ClassNotation\SingleTraitInsertPerStatementFixer; use PhpCsFixer\Fixer\FunctionNotation\FunctionTypehintSpaceFixer; @@ -114,4 +112,4 @@ ]); $ecsConfig->paths([...glob(__DIR__ . '/infra/tools/*'), __DIR__ . '/stubs', __DIR__ . '/infra']); -}; \ No newline at end of file +}; diff --git a/infra/tools/pamqp-arguments-validate b/infra/tools/pamqp-arguments-validate index 07eda958..671d7e67 100755 --- a/infra/tools/pamqp-arguments-validate +++ b/infra/tools/pamqp-arguments-validate @@ -1,5 +1,6 @@ #!/usr/bin/env php [], 'constants' => [], diff --git a/stubs/AMQP.php b/stubs/AMQP.php index 463c64d1..2eef3c8b 100644 --- a/stubs/AMQP.php +++ b/stubs/AMQP.php @@ -1,4 +1,5 @@ Date: Tue, 6 Jan 2026 23:14:34 +0100 Subject: [PATCH 140/147] Bump symplify/easy-coding-standard from 13.0.0 to 13.0.4 (#611) Bumps [symplify/easy-coding-standard](https://github.com/easy-coding-standard/easy-coding-standard) from 13.0.0 to 13.0.4. - [Release notes](https://github.com/easy-coding-standard/easy-coding-standard/releases) - [Commits](https://github.com/easy-coding-standard/easy-coding-standard/compare/13.0.0...13.0.4) --- updated-dependencies: - dependency-name: symplify/easy-coding-standard dependency-version: 13.0.4 dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.lock b/composer.lock index 5c5420c9..e5291f16 100644 --- a/composer.lock +++ b/composer.lock @@ -296,24 +296,24 @@ }, { "name": "symplify/easy-coding-standard", - "version": "13.0.0", + "version": "13.0.4", "source": { "type": "git", "url": "https://github.com/easy-coding-standard/easy-coding-standard.git", - "reference": "24708c6673871e342245c692e1bb304f119ffc58" + "reference": "5c7e7a07e5d6a98b9dd2e6fc0a9155efb7c166c8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/24708c6673871e342245c692e1bb304f119ffc58", - "reference": "24708c6673871e342245c692e1bb304f119ffc58", + "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/5c7e7a07e5d6a98b9dd2e6fc0a9155efb7c166c8", + "reference": "5c7e7a07e5d6a98b9dd2e6fc0a9155efb7c166c8", "shasum": "" }, "require": { "php": ">=7.2" }, "conflict": { - "friendsofphp/php-cs-fixer": "<3.46", - "phpcsstandards/php_codesniffer": "<3.8", + "friendsofphp/php-cs-fixer": "<3.92.4", + "phpcsstandards/php_codesniffer": "<4.0.1", "symplify/coding-standard": "<12.1" }, "suggest": { @@ -341,7 +341,7 @@ ], "support": { "issues": "https://github.com/easy-coding-standard/easy-coding-standard/issues", - "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/13.0.0" + "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/13.0.4" }, "funding": [ { @@ -353,7 +353,7 @@ "type": "github" } ], - "time": "2025-11-06T14:47:06+00:00" + "time": "2026-01-05T09:10:04+00:00" } ], "aliases": [], From f40b151b8c9f0431f47876f41d4675359a5fe525 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 15 Jan 2026 15:06:15 +0100 Subject: [PATCH 141/147] Bump phpstan/phpdoc-parser from 2.3.0 to 2.3.1 (#612) Bumps [phpstan/phpdoc-parser](https://github.com/phpstan/phpdoc-parser) from 2.3.0 to 2.3.1. - [Release notes](https://github.com/phpstan/phpdoc-parser/releases) - [Commits](https://github.com/phpstan/phpdoc-parser/compare/2.3.0...2.3.1) --- updated-dependencies: - dependency-name: phpstan/phpdoc-parser dependency-version: 2.3.1 dependency-type: indirect update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index e5291f16..692af885 100644 --- a/composer.lock +++ b/composer.lock @@ -105,16 +105,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "2.3.0", + "version": "2.3.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "1e0cd5370df5dd2e556a36b9c62f62e555870495" + "reference": "16dbf9937da8d4528ceb2145c9c7c0bd29e26374" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/1e0cd5370df5dd2e556a36b9c62f62e555870495", - "reference": "1e0cd5370df5dd2e556a36b9c62f62e555870495", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/16dbf9937da8d4528ceb2145c9c7c0bd29e26374", + "reference": "16dbf9937da8d4528ceb2145c9c7c0bd29e26374", "shasum": "" }, "require": { @@ -146,9 +146,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/2.3.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/2.3.1" }, - "time": "2025-08-30T15:50:23+00:00" + "time": "2026-01-12T11:33:04+00:00" }, { "name": "slevomat/coding-standard", From 2df7faef6c85f571b7bae5c2c8c9635c436a9178 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 23 Jan 2026 16:40:01 +0100 Subject: [PATCH 142/147] Bump actions/checkout from 6.0.1 to 6.0.2 (#613) Bumps [actions/checkout](https://github.com/actions/checkout) from 6.0.1 to 6.0.2. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v6.0.1...v6.0.2) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: 6.0.2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/test.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e52cb7b1..0161f983 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -30,7 +30,7 @@ jobs: concurrent_skipping: 'same_content_newer' - name: Checkout - uses: actions/checkout@v6.0.1 + uses: actions/checkout@v6.0.2 - name: Prepare matrix id: matrix @@ -53,7 +53,7 @@ jobs: install: clang-format-20 - name: Checkout - uses: actions/checkout@v6.0.1 + uses: actions/checkout@v6.0.2 - name: Check style run: ./infra/tools/pamqp-format-check @@ -71,7 +71,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v6.0.1 + uses: actions/checkout@v6.0.2 - name: Install packages uses: awalsh128/cache-apt-pkgs-action@v1.6.0 @@ -129,7 +129,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v6.0.1 + uses: actions/checkout@v6.0.2 - name: Configure hostnames run: sudo echo "127.0.0.1 ${{ env.PHP_AMQP_SSL_HOST }}" | sudo tee -a /etc/hosts From e413bfe44faa50035735a7367714055c56229f7c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 1 Feb 2026 23:26:24 +0700 Subject: [PATCH 143/147] Bump phpstan/phpdoc-parser from 2.3.1 to 2.3.2 (#615) Bumps [phpstan/phpdoc-parser](https://github.com/phpstan/phpdoc-parser) from 2.3.1 to 2.3.2. - [Release notes](https://github.com/phpstan/phpdoc-parser/releases) - [Commits](https://github.com/phpstan/phpdoc-parser/compare/2.3.1...2.3.2) --- updated-dependencies: - dependency-name: phpstan/phpdoc-parser dependency-version: 2.3.2 dependency-type: indirect update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 692af885..8d26b0f4 100644 --- a/composer.lock +++ b/composer.lock @@ -105,16 +105,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "2.3.1", + "version": "2.3.2", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "16dbf9937da8d4528ceb2145c9c7c0bd29e26374" + "reference": "a004701b11273a26cd7955a61d67a7f1e525a45a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/16dbf9937da8d4528ceb2145c9c7c0bd29e26374", - "reference": "16dbf9937da8d4528ceb2145c9c7c0bd29e26374", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/a004701b11273a26cd7955a61d67a7f1e525a45a", + "reference": "a004701b11273a26cd7955a61d67a7f1e525a45a", "shasum": "" }, "require": { @@ -146,9 +146,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/2.3.1" + "source": "https://github.com/phpstan/phpdoc-parser/tree/2.3.2" }, - "time": "2026-01-12T11:33:04+00:00" + "time": "2026-01-25T14:56:51+00:00" }, { "name": "slevomat/coding-standard", From 78c26268c29d12bab8b011a9b2bc66c125ec51b8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 1 Feb 2026 23:26:33 +0700 Subject: [PATCH 144/147] Bump slevomat/coding-standard from 8.26.0 to 8.27.1 (#614) Bumps [slevomat/coding-standard](https://github.com/slevomat/coding-standard) from 8.26.0 to 8.27.1. - [Release notes](https://github.com/slevomat/coding-standard/releases) - [Commits](https://github.com/slevomat/coding-standard/compare/8.26.0...8.27.1) --- updated-dependencies: - dependency-name: slevomat/coding-standard dependency-version: 8.27.1 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.lock | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/composer.lock b/composer.lock index 8d26b0f4..31703e30 100644 --- a/composer.lock +++ b/composer.lock @@ -152,32 +152,32 @@ }, { "name": "slevomat/coding-standard", - "version": "8.26.0", + "version": "8.27.1", "source": { "type": "git", "url": "https://github.com/slevomat/coding-standard.git", - "reference": "d247cdc04b91956bdcfaa0b1313c01960b189d3c" + "reference": "29bdaee8b65e7ed2b8e702b01852edba8bae1769" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/d247cdc04b91956bdcfaa0b1313c01960b189d3c", - "reference": "d247cdc04b91956bdcfaa0b1313c01960b189d3c", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/29bdaee8b65e7ed2b8e702b01852edba8bae1769", + "reference": "29bdaee8b65e7ed2b8e702b01852edba8bae1769", "shasum": "" }, "require": { "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || ^1.2.0", "php": "^7.4 || ^8.0", - "phpstan/phpdoc-parser": "^2.3.0", + "phpstan/phpdoc-parser": "^2.3.1", "squizlabs/php_codesniffer": "^4.0.1" }, "require-dev": { - "phing/phing": "3.0.1|3.1.0", + "phing/phing": "3.0.1|3.1.1", "php-parallel-lint/php-parallel-lint": "1.4.0", - "phpstan/phpstan": "2.1.33", + "phpstan/phpstan": "2.1.37", "phpstan/phpstan-deprecation-rules": "2.0.3", - "phpstan/phpstan-phpunit": "2.0.11", + "phpstan/phpstan-phpunit": "2.0.12", "phpstan/phpstan-strict-rules": "2.0.7", - "phpunit/phpunit": "9.6.31|10.5.60|11.4.4|11.5.46|12.5.4" + "phpunit/phpunit": "9.6.31|10.5.60|11.4.4|11.5.49|12.5.7" }, "type": "phpcodesniffer-standard", "extra": { @@ -201,7 +201,7 @@ ], "support": { "issues": "https://github.com/slevomat/coding-standard/issues", - "source": "https://github.com/slevomat/coding-standard/tree/8.26.0" + "source": "https://github.com/slevomat/coding-standard/tree/8.27.1" }, "funding": [ { @@ -213,7 +213,7 @@ "type": "tidelift" } ], - "time": "2025-12-21T18:01:15+00:00" + "time": "2026-01-25T15:57:07+00:00" }, { "name": "squizlabs/php_codesniffer", From 89bf8b959088ca1f667b14d8216c541e7f472a0c Mon Sep 17 00:00:00 2001 From: Thomas Unterreitmeier Date: Wed, 4 Feb 2026 04:12:46 +0100 Subject: [PATCH 145/147] feat(exchange): treat various SSL and TCP errors as a more specific `AMQPConnectionException` instead of just `AMQPException` (#571) As exceptions are covariant, this is not a BC break. --- amqp.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/amqp.c b/amqp.c index 84a87b7b..bd5df48c 100644 --- a/amqp.c +++ b/amqp.c @@ -491,12 +491,23 @@ void php_amqp_zend_throw_exception( break; case AMQP_RESPONSE_LIBRARY_EXCEPTION: switch (reply.library_error) { + case AMQP_STATUS_BROKER_UNSUPPORTED_SASL_METHOD: case AMQP_STATUS_CONNECTION_CLOSED: + case AMQP_STATUS_HOSTNAME_RESOLUTION_FAILED: case AMQP_STATUS_SOCKET_ERROR: case AMQP_STATUS_SOCKET_CLOSED: case AMQP_STATUS_SOCKET_INUSE: - case AMQP_STATUS_BROKER_UNSUPPORTED_SASL_METHOD: - case AMQP_STATUS_HOSTNAME_RESOLUTION_FAILED: + case AMQP_STATUS_SSL_CONNECTION_FAILED: + case AMQP_STATUS_SSL_ERROR: + case AMQP_STATUS_SSL_HOSTNAME_VERIFY_FAILED: + case AMQP_STATUS_SSL_PEER_VERIFY_FAILED: +#if AMQP_VERSION >= AMQP_VERSION_CODE(0, 11, 0, 1) + case AMQP_STATUS_SSL_SET_ENGINE_FAILED: +#endif +#if AMQP_VERSION >= AMQP_VERSION_CODE(0, 14, 0, 1) + case AMQP_STATUS_SSL_UNIMPLEMENTED: +#endif + case AMQP_STATUS_TCP_ERROR: exception_ce = amqp_connection_exception_class_entry; break; default: From 64fff28839ffb4218b1d80d590618010c0c7da2f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 25 Feb 2026 16:07:49 +0100 Subject: [PATCH 146/147] Bump slevomat/coding-standard from 8.27.1 to 8.28.0 (#616) Bumps [slevomat/coding-standard](https://github.com/slevomat/coding-standard) from 8.27.1 to 8.28.0. - [Release notes](https://github.com/slevomat/coding-standard/releases) - [Commits](https://github.com/slevomat/coding-standard/compare/8.27.1...8.28.0) --- updated-dependencies: - dependency-name: slevomat/coding-standard dependency-version: 8.28.0 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.lock | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/composer.lock b/composer.lock index 31703e30..a8707838 100644 --- a/composer.lock +++ b/composer.lock @@ -152,32 +152,32 @@ }, { "name": "slevomat/coding-standard", - "version": "8.27.1", + "version": "8.28.0", "source": { "type": "git", "url": "https://github.com/slevomat/coding-standard.git", - "reference": "29bdaee8b65e7ed2b8e702b01852edba8bae1769" + "reference": "0cd4b30cc1037eca54091c188d260d570e61770c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/29bdaee8b65e7ed2b8e702b01852edba8bae1769", - "reference": "29bdaee8b65e7ed2b8e702b01852edba8bae1769", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/0cd4b30cc1037eca54091c188d260d570e61770c", + "reference": "0cd4b30cc1037eca54091c188d260d570e61770c", "shasum": "" }, "require": { "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || ^1.2.0", "php": "^7.4 || ^8.0", - "phpstan/phpdoc-parser": "^2.3.1", + "phpstan/phpdoc-parser": "^2.3.2", "squizlabs/php_codesniffer": "^4.0.1" }, "require-dev": { - "phing/phing": "3.0.1|3.1.1", + "phing/phing": "3.0.1|3.1.2", "php-parallel-lint/php-parallel-lint": "1.4.0", - "phpstan/phpstan": "2.1.37", - "phpstan/phpstan-deprecation-rules": "2.0.3", - "phpstan/phpstan-phpunit": "2.0.12", - "phpstan/phpstan-strict-rules": "2.0.7", - "phpunit/phpunit": "9.6.31|10.5.60|11.4.4|11.5.49|12.5.7" + "phpstan/phpstan": "2.1.40", + "phpstan/phpstan-deprecation-rules": "2.0.4", + "phpstan/phpstan-phpunit": "2.0.16", + "phpstan/phpstan-strict-rules": "2.0.10", + "phpunit/phpunit": "9.6.34|10.5.63|11.4.4|11.5.50|12.5.14" }, "type": "phpcodesniffer-standard", "extra": { @@ -201,7 +201,7 @@ ], "support": { "issues": "https://github.com/slevomat/coding-standard/issues", - "source": "https://github.com/slevomat/coding-standard/tree/8.27.1" + "source": "https://github.com/slevomat/coding-standard/tree/8.28.0" }, "funding": [ { @@ -213,7 +213,7 @@ "type": "tidelift" } ], - "time": "2026-01-25T15:57:07+00:00" + "time": "2026-02-23T21:35:24+00:00" }, { "name": "squizlabs/php_codesniffer", From 88843fb5d10970c39499e8c668bb7dae6ed8d199 Mon Sep 17 00:00:00 2001 From: Max Yekhlakov Date: Mon, 16 Mar 2026 17:34:01 +0500 Subject: [PATCH 147/147] merge fixes --- amqp_connection.c | 18 +++++++++--------- amqp_connection_resource.c | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/amqp_connection.c b/amqp_connection.c index af81b289..c45b21f3 100644 --- a/amqp_connection.c +++ b/amqp_connection.c @@ -107,7 +107,7 @@ static size_t php_amqp_get_connection_hash(amqp_connection_params *params, char return spprintf( hash, 0, - "amqp_conn_res_h:%s_p:%d_v:%s_l:%s_p:%s_f:%d_c:%d_h:%d_cacert:%s_capath:s_cert:%s_key:%s_sasl_method:%d_connection_name:" + "amqp_conn_res_h:%s_p:%d_v:%s_l:%s_p:%s_f:%d_c:%d_h:%d_cacert:%s_capath:%s_cert:%s_key:%s_sasl_method:%d_connection_name:" "%s", params->host, params->port, @@ -1048,11 +1048,11 @@ static PHP_METHOD(amqp_connection_class, sendHeartbeat) if (connection->connection_resource && connection->connection_resource->is_connected) { if (AMQP_STATUS_OK != amqp_send_heartbeat(connection->connection_resource->connection_state)) { - zend_throw_exception(amqp_connection_exception_class_entry, "Library error: error while send heartbeat", 0 TSRMLS_CC); + zend_throw_exception(amqp_connection_exception_class_entry, "Library error: error while send heartbeat", 0); return; } } else { - zend_throw_exception(amqp_connection_exception_class_entry, "Error while try send heartbeat: not connected", 0 TSRMLS_CC); + zend_throw_exception(amqp_connection_exception_class_entry, "Error while try send heartbeat: not connected", 0); } RETURN_TRUE; @@ -1612,11 +1612,11 @@ static PHP_METHOD(amqp_connection_class, setCAPath) { char *str = NULL; PHP5to7_param_str_len_type_t str_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &str, &str_len) == FAILURE) { return; } - zend_update_property_stringl(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("capath"), str, str_len TSRMLS_CC); + zend_update_property_stringl(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("capath"), str, str_len); RETURN_TRUE; } @@ -1637,11 +1637,11 @@ static PHP_METHOD(amqp_connection_class, setUseDefaultCACert) { zend_bool use_default_cacert = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &use_default_cacert) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &use_default_cacert) == FAILURE) { return; } - zend_update_property_bool(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("use_default_cacert"), use_default_cacert TSRMLS_CC); + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("use_default_cacert"), use_default_cacert); RETURN_TRUE; } @@ -1662,11 +1662,11 @@ static PHP_METHOD(amqp_connection_class, setUseDefaultCAPath) { zend_bool use_default_capath = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &use_default_capath) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &use_default_capath) == FAILURE) { return; } - zend_update_property_bool(this_ce, PHP5to8_OBJ_PROP(getThis()), ZEND_STRL("use_default_capath"), use_default_capath TSRMLS_CC); + zend_update_property_bool(this_ce, PHP_AMQP_COMPAT_OBJ_P(getThis()), ZEND_STRL("use_default_capath"), use_default_capath); RETURN_TRUE; } diff --git a/amqp_connection_resource.c b/amqp_connection_resource.c index c92b4278..126df257 100644 --- a/amqp_connection_resource.c +++ b/amqp_connection_resource.c @@ -513,15 +513,15 @@ amqp_connection_resource *connection_resource_constructor(amqp_connection_params return NULL; } else if (params->capath && amqp_ssl_socket_set_capath(resource->socket, params->capath)) { - zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: could not set CA path.", 0 TSRMLS_CC); + zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: could not set CA path.", 0); return NULL; } else if (params->use_default_cacert && amqp_ssl_socket_set_default_cacert(resource->socket)) { - zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: could not set default CA certificate.", 0 TSRMLS_CC); + zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: could not set default CA certificate.", 0); return NULL; } else if (params->use_default_capath && amqp_ssl_socket_set_default_capath(resource->socket)) { - zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: could not set default CA path.", 0 TSRMLS_CC); + zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: could not set default CA path.", 0); return NULL; }