From 87b67a302d33979c4467e93736dd7a0c8b9aadda Mon Sep 17 00:00:00 2001 From: Pierrick Charron Date: Sat, 14 Nov 2009 22:05:01 +0000 Subject: [PATCH] Fix bug #16930 --- php_stomp.c | 10 ++++++++++ stomp.c | 16 ++++++---------- tests/bug_16930.phpt | 17 +++++++++++++++++ 3 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 tests/bug_16930.phpt diff --git a/php_stomp.c b/php_stomp.c index df63191..fa2c9c0 100755 --- a/php_stomp.c +++ b/php_stomp.c @@ -810,6 +810,16 @@ PHP_FUNCTION(stomp_read_frame) if (stomp_select(stomp) > 0 && (res = stomp_read_frame(stomp))) { zval *headers = NULL; + + if (0 == strncmp("ERROR", res->command, sizeof("ERROR") - 1)) { + char *error_msg = NULL; + if (zend_hash_find(res->headers, "message", sizeof("message"), (void **)&error_msg) == SUCCESS) { + STOMP_ERROR(0, error_msg) + frame_destroy(res); + RETURN_FALSE; + } + } + MAKE_STD_ZVAL(headers); array_init(headers); if (res->headers) { diff --git a/stomp.c b/stomp.c index 10f2419..f888195 100644 --- a/stomp.c +++ b/stomp.c @@ -462,15 +462,6 @@ stomp_frame_t *stomp_read_frame(stomp_t *stomp) f->body_length = stomp_read_buffer(stomp, &f->body); } - if (0 == strncmp("ERROR", f->command, sizeof("ERROR") - 1)) { - char *error_msg = NULL; - if (zend_hash_find(f->headers, "message", sizeof("message"), (void **)&error_msg) == SUCCESS) { - stomp_set_error(stomp, error_msg, 0); - } - frame_destroy(f); - return NULL; - } - return f; } /* }}} */ @@ -491,7 +482,12 @@ int stomp_valid_receipt(stomp_t *stomp, stomp_frame_t *frame) { && !strcmp(receipt, receipt_id)) { success = 1; } - } + } else if (0 == strncmp("ERROR", res->command, sizeof("ERROR") - 1)) { + char *error_msg = NULL; + if (zend_hash_find(res->headers, "message", sizeof("message"), (void **)&error_msg) == SUCCESS) { + stomp_set_error(stomp, error_msg, 0); + } + } frame_destroy(res); } } diff --git a/tests/bug_16930.phpt b/tests/bug_16930.phpt new file mode 100644 index 0000000..395a09e --- /dev/null +++ b/tests/bug_16930.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #16930 - readFrame reports error-frames as "timeout" +--SKIPIF-- + +--FILE-- +abort('t2'); +try { + var_dump($s->readFrame()); +} catch(StompException $e) { + var_dump($e->getMessage()); +} + +?> +--EXPECTF-- +string(%d) "%s"