Tag 1.0.3 and bump trunk version

release_1_0_3
Pierrick Charron 2010-10-13 03:28:20 +00:00
commit a3cfb3c06d
32 changed files with 3182 additions and 0 deletions

2
CREDITS Normal file
View File

@ -0,0 +1,2 @@
stomp
Pierrick Charron

29
config.m4 Normal file
View File

@ -0,0 +1,29 @@
dnl $Id: config.m4 292170 2009-12-15 14:19:32Z pierrick $
dnl config.m4 for extension stomp
PHP_ARG_ENABLE(stomp, whether to enable stomp support,
Make sure that the comment is aligned:
[ --enable-stomp Enable stomp support])
PHP_ARG_WITH(openssl-dir,OpenSSL dir for stomp,
[ --with-openssl-dir[=DIR] stomp: openssl install prefix], no, no)
if test "$PHP_STOMP" != "no"; then
PHP_NEW_EXTENSION(stomp, stomp.c php_stomp.c, $ext_shared)
test -z "$PHP_OPENSSL" && PHP_OPENSSL=no
if test "$PHP_OPENSSL" != "no" || test "$PHP_OPENSSL_DIR" != "no"; then
PHP_SETUP_OPENSSL(STOMP_SHARED_LIBADD,
[
AC_DEFINE(HAVE_STOMP_SSL,1,[ ])
], [
AC_MSG_ERROR([OpenSSL libraries not found.
Check the path given to --with-openssl-dir and output in config.log)
])
])
PHP_SUBST(STOMP_SHARED_LIBADD)
fi
fi

13
config.w32 Normal file
View File

@ -0,0 +1,13 @@
// $Id: config.w32 292170 2009-12-15 14:19:32Z pierrick $
// vim:ft=javascript
ARG_ENABLE("stomp", "enable stomp support", "no");
if (PHP_STOMP != "no") {
if (CHECK_LIB("ssleay32.lib", "stomp", PHP_STOMP) && CHECK_LIB("libeay32.lib", "stomp", PHP_STOMP)) {
ADD_FLAG("CFLAGS_STOMP", "/DHAVE_STOMP_SSL=1");
}
EXTENSION("stomp", "stomp.c php_stomp.c");
}

166
doc/classes.php Normal file
View File

@ -0,0 +1,166 @@
<?php
class Stomp {
/**
* Connect to server
*
* @param string $broker Broker URI
* @param string $username The username
* @param string $password The password
*/
public function __construct($broker = null, $username = null, $password = null) {
}
/**
* Get the current stomp session ID
*
* @return string stomp session ID if it exists, or FALSE otherwise
*/
public function getSessionId() {
}
/**
* Close stomp connection
*
* @return boolean TRUE on success, or FALSE on failure
*/
public function disconnect() {
}
/**
* Sends a message to a destination in the messaging system
*
* @param string $destination indicates where to send the message
* @param string|StompFrame $msg message to be sent
* @param array $properties extra properties (example: receipt, transaction)
* @return boolean TRUE on success, or FALSE on failure
*/
public function send($destination, $msg, array $properties = array()) {
}
/**
* Register to listen to a given destination
*
* @param string $destination indicates which destination to subscribe to
* @param array $properties extra properties (example: receipt, transaction, id)
* @return boolean TRUE on success, or FALSE on failure
*/
public function subscribe($destination, array $properties = array()) {
}
/**
* Remove an existing subscription
*
* @param string $destination indicates which subscription to remove
* @param array $properties extra properties (example: receipt, transaction, id)
* @return boolean TRUE on success, or FALSE on failure
*/
public function unsubscribe($destination, array $properties = array()) {
}
/**
* Indicate whether or not there is a frame ready to read
*
* @return boolean TRUE if there is one, or FALSE otherwise
*/
public function hasFrame() {
}
/**
* Read the next frame
*
* @param string $className name of the class to instantiate.
* @return object on success, or FALSE on failure
*/
public function readFrame($className = 'stompFrame') {
}
/**
* Start a transaction
*
* @param string $transaction_id transaction id
* @return boolean TRUE on success, or FALSE on failure
*/
public function begin($transaction_id) {
}
/**
* Commit a transaction in progress
*
* @param string $transaction_id transaction id
* @return boolean TRUE on success, or FALSE on failure
*/
public function commit($transaction_id) {
}
/**
* Roll back a transaction in progress
*
* @param string $transaction_id transaction id
* @return boolean TRUE on success, or FALSE on failure
*/
public function abort($transaction_id) {
}
/**
* Acknowledge consumption of a message from a subscription using client acknowledgment
*
* @param string|StompFrame $msg message/messageId to be acknowledged
* @param array $properties extra properties (example: receipt, transaction)
* @return boolean TRUE on success, or FALSE on failure
*/
public function ack($msg, array $properties = array()) {
}
/**
* Get the last stomp error
*
* @return string Error message, or FALSE if no error
*/
public function error() {
}
/**
* Set timeout
*
* @param int $seconds the seconds part of the timeout to be set
* @param int $microseconds the microseconds part of the timeout to be set
* @return void
*/
public function setTimeout($seconds, $microseconds = 0) {
}
/**
* Get timeout
*
* @return array Array with timeout informations
*/
public function getTimeout() {
}
}
class StompFrame {
/**
* Frame Command
* @var String
*/
public $command;
/**
* Frame headers
* @var Array
*/
public $headers;
/**
* Frame body
* @var String
*/
public $body;
}
class StompException extends Exception {
}

160
doc/functions.php Normal file
View File

@ -0,0 +1,160 @@
<?php
/**
* Get the current version of the stomp extension
*
* @return string version
*/
function stomp_version() {
}
/**
* Connect to server
*
* @param string $broker broker URI
* @param string $username The username
* @param string $password The password
* @return Ressource stomp connection identifier on success, or FALSE on failure
*/
function stomp_connect($broker = null, $username = null, $password = null) {
}
/**
* Get the current stomp session ID
*
* @param ressource $link identifier returned by stomp_connect
* @return string stomp session ID if it exists, or FALSE otherwise
*/
function stomp_get_session_id($link) {
}
/**
* Close stomp connection
*
* @param ressource $link identifier returned by stomp_connect
* @return boolean TRUE on success, or FALSE on failure
*/
function stomp_close($link) {
}
/**
* Sends a message to a destination in the messaging system
*
* @param ressource $link identifier returned by stomp_connect
* @param string $destination indicates where to send the message
* @param string|StompFrame $msg message to be sent
* @param array $properties extra properties (example: receipt, transaction)
* @return boolean TRUE on success, or FALSE on failure
*/
function stomp_send($link, $destination, $msg, array $properties = array()) {
}
/**
* Register to listen to a given destination
*
* @param ressource $link identifier returned by stomp_connect
* @param string $destination indicates which destination to subscribe to
* @param array $properties extra properties (example: receipt, transaction, id)
* @return boolean TRUE on success, or FALSE on failure
*/
function stomp_subscribe($link, $destination, array $properties = array()) {
}
/**
* Remove an existing subscription
*
* @param ressource $link identifier returned by stomp_connect
* @param string $destination indicates which subscription to remove
* @param array $properties extra properties (example: receipt, transaction, id)
* @return boolean TRUE on success, or FALSE on failure
*/
function stomp_unsubscribe($link, $destination, array $properties = array()) {
}
/**
* Indicate whether or not there is a frame ready to read
*
* @param ressource $link identifier returned by stomp_connect
* @return boolean TRUE if there is one, or FALSE otherwise
*/
function stomp_has_frame($link) {
}
/**
* Read the next frame
*
* @param ressource $link identifier returned by stomp_connect
* @return array on success, or FALSE on failure
*/
function stomp_read_frame($link) {
}
/**
* Start a transaction
*
* @param ressource $link identifier returned by stomp_connect
* @param string $transaction_id transaction id
* @return boolean TRUE on success, or FALSE on failure
*/
function stomp_begin($link, $transaction_id) {
}
/**
* Commit a transaction in progress
*
* @param ressource $link identifier returned by stomp_connect
* @param string $transaction_id transaction id
* @return boolean TRUE on success, or FALSE on failure
*/
function stomp_commit($link, $transaction_id) {
}
/**
* Roll back a transaction in progress
*
* @param ressource $link identifier returned by stomp_connect
* @param string $transaction_id transaction id
* @return boolean TRUE on success, or FALSE on failure
*/
function stomp_abort($link, $transaction_id) {
}
/**
* Acknowledge consumption of a message from a subscription using client acknowledgment
*
* @param ressource $link identifier returned by stomp_connect
* @param string|StompFrame $msg message/messageId to be acknowledged
* @param array $properties extra properties (example: receipt, transaction)
* @return boolean TRUE on success, or FALSE on failure
*/
function stomp_ack($link, $msg, array $properties = array()) {
}
/**
* Get the last stomp error
*
* @param ressource $link identifier returned by stomp_connect
* @return string Error message, or FALSE if no error
*/
function stomp_error($link) {
}
/**
* Set timeout
*
* @param ressource $link identifier returned by stomp_connect
* @param int $seconds the seconds part of the timeout to be set
* @param int $microseconds the microseconds part of the timeout to be set
* @return void
*/
function stomp_set_timeout($link, $seconds, $microseconds = 0) {
}
/**
* Get timeout
*
* @param ressource $link identifier returned by stomp_connect
* @return array Array with timeout informations
*/
function stomp_get_timeout($link) {
}

24
examples/oop.php Normal file
View File

@ -0,0 +1,24 @@
<?php
$broker = 'tcp://localhost:61613';
$queue = '/queue/foo';
$msg = 'bar';
try {
$stomp = new Stomp($broker);
$stomp->send($queue, $msg);
$stomp->subscribe($queue);
$frame = $stomp->readFrame();
if ($frame->body === $msg) {
echo "Worked\n";
$stomp->ack($frame, array('receipt' => 'message-12345'));
} else {
echo "Failed\n";
}
$stomp->disconnect();
} catch(StompException $e) {
echo $e->getMessage();
}

24
examples/procedural.php Normal file
View File

@ -0,0 +1,24 @@
<?php
$broker = 'tcp://localhost:61613';
$queue = '/queue/foo';
$msg = 'bar';
if($stomp = stomp_connect($broker)) {
stomp_begin($stomp, 't1');
stomp_send($stomp, $queue, $msg, array('transaction' => 't1'));
stomp_commit($stomp, 't1');
stomp_subscribe($stomp, $queue);
$frame = stomp_read_frame($stomp);
if ($frame['body'] === $msg) {
echo "Worked\n";
stomp_ack($stomp, $frame['headers']['message-id']);
} else {
echo "Failed\n";
}
stomp_close($stomp);
}

184
package.xml Normal file
View File

@ -0,0 +1,184 @@
<?xml version="1.0" encoding="UTF-8" ?>
<package xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" packagerversion="1.4.7" version="2.0" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
<name>stomp</name>
<channel>pecl.php.net</channel>
<summary>Stomp client extension</summary>
<description>
This extension allows php applications to communicate with any Stomp compliant Message Brokers through easy object oriented and procedural interfaces.
</description>
<lead>
<name>Pierrick Charron</name>
<user>pierrick</user>
<email>pierrick@php.net</email>
<active>yes</active>
</lead>
<date>2010-10-12</date>
<version><release>1.0.3</release><api>1.0.3</api></version>
<stability><release>stable</release><api>stable</api></stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- Fixed bug #18772 (setTimeout usecs not honored)
</notes>
<contents>
<dir name="/">
<file role="doc" name="CREDITS" />
<file role="src" name="config.m4" />
<file role="src" name="config.w32" />
<file role="src" name="php_stomp.c" />
<file role="src" name="php_stomp.h" />
<file role="src" name="stomp.c" />
<file role="src" name="stomp.h" />
<file role="test" name="tests/001-stomp.phpt" />
<file role="test" name="tests/002-version.phpt" />
<file role="test" name="tests/003-connect/001.phpt" />
<file role="test" name="tests/003-connect/002.phpt" />
<file role="test" name="tests/004-getSessionId/001.phpt" />
<file role="test" name="tests/005-close/001.phpt" />
<file role="test" name="tests/005-close/002.phpt" />
<file role="test" name="tests/006-send/001.phpt" />
<file role="test" name="tests/006-send/002.phpt" />
<file role="test" name="tests/007-subscribe/001.phpt" />
<file role="test" name="tests/008-unsubscribe/001.phpt" />
<file role="test" name="tests/009-readFrame/001.phpt" />
<file role="test" name="tests/009-readFrame/002.phpt" />
<file role="test" name="tests/009-readFrame/003.phpt" />
<file role="test" name="tests/010-timeout/001.phpt" />
<file role="test" name="tests/010-timeout/002.phpt" />
<file role="test" name="tests/011-commit/001.phpt" />
<file role="doc" name="doc/classes.php" />
<file role="doc" name="doc/functions.php" />
<file role="doc" name="examples/oop.php" />
<file role="doc" name="examples/procedural.php" />
</dir>
</contents>
<dependencies>
<required>
<php>
<min>5.2.2</min>
</php>
<pearinstaller>
<min>1.4.0</min>
</pearinstaller>
</required>
<optional>
<extension>
<name>openssl</name>
</extension>
</optional>
</dependencies>
<providesextension>stomp</providesextension>
<extsrcrelease>
<configureoption default="/usr" name="with-openssl-dir" prompt="OpenSSL install prefix (no to disable SSL support)" />
</extsrcrelease>
<changelog>
<release>
<version><release>1.0.2</release><api>1.0.2</api></version>
<stability><release>stable</release><api>stable</api></stability>
<license uri="http://www.php.net/license">PHP License</license>
<date>2010-08-13</date>
<notes>
- Fixed SSL connection bug introduced in 1.0.1
</notes>
</release>
<release>
<version><release>1.0.1</release><api>1.0.1</api></version>
<stability><release>stable</release><api>stable</api></stability>
<license uri="http://www.php.net/license">PHP License</license>
<date>2010-08-03</date>
<notes>
- Add new parameter to the constructor to allow client to send extra informations
- Add zend engine runtime cache support (introduced into trunk)
- Add new details property in the StompException class
- Add new StompException::getDetails() method
- Add the frame body content in the Stomp::Error() method
- Fixed bug #17262 (Server is not responding on win32)
</notes>
</release>
<release>
<version><release>1.0.0</release><api>1.0.0</api></version>
<stability><release>stable</release><api>stable</api></stability>
<license uri="http://www.php.net/license">PHP License</license>
<date>2010-02-11</date>
<notes>
- Bump to stable
</notes>
</release>
<release>
<version><release>0.4.1</release><api>0.4.1</api></version>
<stability><release>beta</release><api>beta</api></stability>
<license uri="http://www.php.net/license">PHP License</license>
<date>2010-01-19</date>
<notes>
- Fix compilation issue on PHP5.2 branch
</notes>
</release>
<release>
<version><release>0.4.0</release><api>0.4.0</api></version>
<stability><release>beta</release><api>beta</api></stability>
<license uri="http://www.php.net/license">PHP License</license>
<date>2010-01-17</date>
<notes>
- Adds the ability to specify an alternative class for readFrame
</notes>
</release>
<release>
<version><release>0.3.2</release><api>0.3.2</api></version>
<stability><release>beta</release><api>beta</api></stability>
<license uri="http://www.php.net/license">PHP License</license>
<date>2009-11-22</date>
<notes>
- Adds alt class
- Fixed bug #16936 (Module segfaults on readFrame if Frame > STOMP_BUFSIZE)
- Fixed bug #16933 (readFrame does not notice when server shuts down)
- Fixed bug #16930 (readFrame reports error-frames as "timeout")
</notes>
</release>
<release>
<version><release>0.3.1</release><api>0.3.1</api></version>
<stability><release>beta</release><api>beta</api></stability>
<license uri="http://www.php.net/license">PHP License</license>
<date>2009-11-08</date>
<notes>
- Fix memory leak in stomp_send and in stomp_ack
- Reduced minimum php version to 5.2.2
</notes>
</release>
<release>
<version><release>0.3.0</release><api>0.3.0</api></version>
<stability><release>beta</release><api>beta</api></stability>
<license uri="http://www.php.net/license">PHP License</license>
<date>2009-11-06</date>
<notes>
- new stomp_connect_error() function (pierrick)
- stomp_begin, stomp_abort and stomp_commit now accept additional headers (pierrick)
- new connection timeout and read timeout ini configuration (pierrick)
- Fix a memory leak in stomp_read_line (pierrick)
- Better set of test (Pierrick and Anis)
</notes>
</release>
<release>
<version><release>0.2.0</release><api>0.2.0</api></version>
<stability><release>beta</release><api>beta</api></stability>
<license uri="http://www.php.net/license">PHP License</license>
<date>2009-11-01</date>
<notes>
- Windows build fix (kalle)
- Add SSL support (pierrick)
</notes>
</release>
<release>
<version><release>0.1.0</release><api>0.1.0</api></version>
<stability><release>alpha</release><api>alpha</api></stability>
<license uri="http://www.php.net/license">PHP License</license>
<date>2009-10-30</date>
<notes>
- Initial PECL release. (pierrick)
</notes>
</release>
</changelog>
</package>

1242
php_stomp.c Executable file

File diff suppressed because it is too large Load Diff

122
php_stomp.h Normal file
View File

@ -0,0 +1,122 @@
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2010 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: Pierrick Charron <pierrick@php.net> |
+----------------------------------------------------------------------+
*/
/* $Id: php_stomp.h 302189 2010-08-13 14:06:56Z pierrick $ */
#ifndef PHP_STOMP_H
#define PHP_STOMP_H
#include "stomp.h"
typedef struct _stomp_object {
zend_object std;
stomp_t *stomp;
} stomp_object_t;
#define PHP_STOMP_EXTNAME "Stomp"
#define PHP_STOMP_MAJOR_VERSION "1"
#define PHP_STOMP_MINOR_VERSION "0"
#define PHP_STOMP_PATCH_VERSION "3"
#define PHP_STOMP_VERSION_STATUS ""
#define PHP_STOMP_VERSION PHP_STOMP_MAJOR_VERSION "." PHP_STOMP_MINOR_VERSION "." PHP_STOMP_PATCH_VERSION PHP_STOMP_VERSION_STATUS
#define PHP_STOMP_RES_NAME "stomp connection"
#define PHP_STOMP_CLASSNAME "Stomp"
#define PHP_STOMP_FRAME_CLASSNAME "StompFrame"
#define PHP_STOMP_EXCEPTION_CLASSNAME "StompException"
#define PHP_STOMP_ERR_UNKNOWN "Stomp unknown error"
#define PHP_STOMP_ERR_INVALID_BROKER_URI "Invalid Broker URI"
#define PHP_STOMP_ERR_INVALID_BROKER_URI_SCHEME "Invalid Broker URI scheme"
#define PHP_STOMP_ERR_SERVER_NOT_RESPONDING "Server is not responding"
#define PHP_STOMP_ERR_EMPTY_DESTINATION "Destination can not be empty"
#define PHP_STOMP_ERR_NO_CTR "Stomp constructor was not called"
extern zend_module_entry stomp_module_entry;
#define phpext_stomp_ptr &stomp_module_entry
#ifdef PHP_WIN32
#define PHP_STOMP_API __declspec(dllexport)
#else
#define PHP_STOMP_API
#endif
#ifdef ZTS
#include "TSRM.h"
#endif
PHP_MINIT_FUNCTION(stomp);
PHP_MSHUTDOWN_FUNCTION(stomp);
PHP_RINIT_FUNCTION(stomp);
PHP_RSHUTDOWN_FUNCTION(stomp);
PHP_MINFO_FUNCTION(stomp);
/* Methods declarations */
PHP_FUNCTION(stomp_version);
PHP_FUNCTION(stomp_connect);
PHP_FUNCTION(stomp_connect_error);
PHP_FUNCTION(stomp_get_session_id);
PHP_FUNCTION(stomp_close);
PHP_FUNCTION(stomp_send);
PHP_FUNCTION(stomp_subscribe);
PHP_FUNCTION(stomp_has_frame);
PHP_FUNCTION(stomp_read_frame);
PHP_FUNCTION(stomp_unsubscribe);
PHP_FUNCTION(stomp_begin);
PHP_FUNCTION(stomp_commit);
PHP_FUNCTION(stomp_abort);
PHP_FUNCTION(stomp_ack);
PHP_FUNCTION(stomp_error);
PHP_FUNCTION(stomp_set_read_timeout);
PHP_FUNCTION(stomp_get_read_timeout);
PHP_METHOD(stompframe, __construct);
PHP_METHOD(stompexception, getDetails);
ZEND_BEGIN_MODULE_GLOBALS(stomp)
/* INI */
char *default_broker;
long read_timeout_sec;
long read_timeout_usec;
long connection_timeout_sec;
long connection_timeout_usec;
/* Others */
long error_no;
char *error_msg;
ZEND_END_MODULE_GLOBALS(stomp)
#ifdef ZTS
#define STOMP_G(v) TSRMG(stomp_globals_id, zend_stomp_globals *, v)
#else
#define STOMP_G(v) (stomp_globals.v)
#endif
#endif /* PHP_STOMP_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
*/

589
stomp.c Normal file
View File

@ -0,0 +1,589 @@
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2010 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: Pierrick Charron <pierrick@php.net> |
+----------------------------------------------------------------------+
*/
/* $Id: stomp.c 304355 2010-10-13 03:13:56Z pierrick $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "zend_exceptions.h"
#include "ext/standard/php_smart_str.h"
#include "stomp.h"
#include "php_stomp.h"
#define RETURN_READ_FRAME_FAIL { stomp_free_frame(f); return NULL; }
ZEND_EXTERN_MODULE_GLOBALS(stomp);
extern zend_class_entry *stomp_ce_exception;
/* {{{ stomp_init
*/
stomp_t *stomp_init()
{
/* Memory allocation */
stomp_t *stomp = (stomp_t *) emalloc(sizeof(stomp_t));
memset(stomp, 0, sizeof(*stomp));
/* Define all values */
stomp->host = NULL;
stomp->port = 0;
stomp->status = 0;
stomp->error = NULL;
stomp->error_details = NULL;
stomp->errnum = 0;
stomp->session = NULL;
stomp->options.connect_timeout_sec = 2;
stomp->options.connect_timeout_usec = 0;
stomp->options.read_timeout_sec = 2;
stomp->options.read_timeout_usec = 0;
#if HAVE_STOMP_SSL
stomp->options.use_ssl = 0;
stomp->ssl_handle = NULL;
#endif
return stomp;
}
/* }}} */
/* {{{ stomp_set_error
*/
void stomp_set_error(stomp_t *stomp, const char *error, int errnum, const char *details)
{
if (stomp->error != NULL) {
efree(stomp->error);
stomp->error = NULL;
}
if (stomp->error_details != NULL) {
efree(stomp->error_details);
stomp->error_details = NULL;
}
stomp->errnum = errnum;
if (error != NULL) {
stomp->error = estrdup(error);
}
if (details != NULL) {
stomp->error_details = estrdup(details);
}
}
/* }}} */
/* {{{ stomp_writeable
*/
int stomp_writeable(stomp_t *stomp)
{
int n;
n = php_pollfd_for_ms(stomp->fd, POLLOUT, 1000);
if (n < 1) {
#ifndef PHP_WIN32
if (n == 0) {
errno = ETIMEDOUT;
}
#endif
return 0;
}
return 1;
}
/* }}} */
/* {{{ stomp_connect
*/
int stomp_connect(stomp_t *stomp, const char *host, unsigned short port TSRMLS_DC)
{
char error[1024];
socklen_t size;
struct timeval tv;
if (stomp->host != NULL)
{
efree(stomp->host);
}
stomp->host = (char *) emalloc(strlen(host) + 1);
memcpy(stomp->host, host, strlen(host));
stomp->host[strlen(host)] = '\0';
stomp->port = port;
tv.tv_sec = stomp->options.connect_timeout_sec;
tv.tv_usec = stomp->options.connect_timeout_usec;
stomp->fd = php_network_connect_socket_to_host(stomp->host, stomp->port, SOCK_STREAM, 0, &tv, NULL, NULL, NULL, 0 TSRMLS_CC);
if (stomp->fd == -1) {
snprintf(error, sizeof(error), "Unable to connect to %s:%ld", stomp->host, stomp->port);
stomp_set_error(stomp, error, errno, NULL);
return 0;
}
size = sizeof(stomp->localaddr);
memset(&stomp->localaddr, 0, size);
if (getsockname(stomp->fd, (struct sockaddr*) &stomp->localaddr, &size) == -1) {
snprintf(error, sizeof(error), "getsockname failed: %s (%d)", strerror(errno), errno);
stomp_set_error(stomp, error, errno, NULL);
return 0;
}
if (stomp_writeable(stomp)) {
#if HAVE_STOMP_SSL
if (stomp->options.use_ssl) {
SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
if (NULL == ctx) {
stomp_set_error(stomp, "failed to create the SSL context", 0, NULL);
return 0;
}
SSL_CTX_set_options(ctx, SSL_OP_ALL);
stomp->ssl_handle = SSL_new(ctx);
if (stomp->ssl_handle == NULL) {
stomp_set_error(stomp, "failed to create the SSL handle", 0, NULL);
SSL_CTX_free(ctx);
return 0;
}
SSL_set_fd(stomp->ssl_handle, stomp->fd);
if (SSL_connect(stomp->ssl_handle) <= 0) {
stomp_set_error(stomp, "SSL/TLS handshake failed", 0, NULL);
SSL_shutdown(stomp->ssl_handle);
return 0;
}
}
#endif
return 1;
} else {
snprintf(error, sizeof(error), "Unable to connect to %s:%ld", stomp->host, stomp->port);
stomp_set_error(stomp, error, errno, NULL);
return 0;
}
}
/* }}} */
/* {{{ stomp_close
*/
void stomp_close(stomp_t *stomp)
{
if (NULL == stomp) {
return;
}
if (stomp->fd != -1) {
#if HAVE_STOMP_SSL
if(stomp->ssl_handle) {
SSL_shutdown(stomp->ssl_handle);
}
#endif
closesocket(stomp->fd);
}
if (stomp->host) {
efree(stomp->host);
}
if (stomp->session) {
efree(stomp->session);
}
if (stomp->error) {
efree(stomp->error);
}
if (stomp->error_details) {
efree(stomp->error_details);
}
efree(stomp);
}
/* }}} */
/* {{{ stomp_send
*/
int stomp_send(stomp_t *stomp, stomp_frame_t *frame TSRMLS_DC)
{
smart_str buf = {0};
/* Command */
smart_str_appends(&buf, frame->command);
smart_str_appendc(&buf, '\n');
/* Headers */
if (frame->headers) {
char *key;
ulong pos;
zend_hash_internal_pointer_reset(frame->headers);
while (zend_hash_get_current_key(frame->headers, &key, &pos, 0) == HASH_KEY_IS_STRING) {
char *value = NULL;
smart_str_appends(&buf, key);
smart_str_appendc(&buf, ':');
if (zend_hash_get_current_data(frame->headers, (void **)&value) == SUCCESS) {
smart_str_appends(&buf, value);
}
smart_str_appendc(&buf, '\n');
zend_hash_move_forward(frame->headers);
}
}
if (frame->body_length > 0) {
smart_str_appends(&buf, "content-length: ");
smart_str_append_long(&buf, frame->body_length);
smart_str_appendc(&buf, '\n');
}
smart_str_appendc(&buf, '\n');
if (frame->body > 0) {
smart_str_appends(&buf, frame->body);
}
if (!stomp_writeable(stomp)) {
char error[1024];
snprintf(error, sizeof(error), "Unable to send data");
stomp_set_error(stomp, error, errno, NULL);
return 0;
}
#ifdef HAVE_STOMP_SSL
if (stomp->options.use_ssl) {
if (-1 == SSL_write(stomp->ssl_handle, buf.c, buf.len) || -1 == SSL_write(stomp->ssl_handle, "\0\n", 2)) {
char error[1024];
snprintf(error, sizeof(error), "Unable to send data");
stomp_set_error(stomp, error, errno, NULL);
smart_str_free(&buf);
return 0;
}
} else {
#endif
if (-1 == send(stomp->fd, buf.c, buf.len, 0) || -1 == send(stomp->fd, "\0\n", 2, 0)) {
char error[1024];
snprintf(error, sizeof(error), "Unable to send data");
stomp_set_error(stomp, error, errno, NULL);
smart_str_free(&buf);
return 0;
}
#ifdef HAVE_STOMP_SSL
}
#endif
smart_str_free(&buf);
return 1;
}
/* }}} */
/* {{{ stomp_recv
*/
int stomp_recv(stomp_t *stomp, char *msg, size_t length)
{
int len;
#if HAVE_STOMP_SSL
if(stomp->options.use_ssl) {
len = SSL_read(stomp->ssl_handle, msg, length);
} else {
#endif
len = recv(stomp->fd, msg, length, 0);
#if HAVE_STOMP_SSL
}
#endif
if (len == 0) {
TSRMLS_FETCH();
zend_throw_exception_ex(stomp_ce_exception, errno TSRMLS_CC, "Unexpected EOF while reading from socket");
stomp->status = -1;
}
return len;
}
/* }}} */
/* {{{ stomp_read_buffer
*/
static int stomp_read_buffer(stomp_t *stomp, char **data)
{
int rc = 0;
size_t i = 0;
size_t bufsize = STOMP_BUFSIZE + 1;
char *buffer = (char *) emalloc(STOMP_BUFSIZE + 1);
while (1) {
size_t length = 1;
rc = stomp_recv(stomp, buffer + i, length);
if (rc < 1) {
efree(buffer);
return -1;
}
if (1 == length) {
i++;
if (buffer[i-1] == 0) {
char endline[1];
if (1 != stomp_recv(stomp, endline, 1) && '\n' != endline[0]) {
efree(buffer);
return 0;
}
break;
}
if (i >= bufsize) {
buffer = (char *) erealloc(buffer, bufsize + STOMP_BUFSIZE);
bufsize += STOMP_BUFSIZE;
}
}
}
if (i > 1) {
*data = (char *) emalloc(i);
if (NULL == *data) {
efree(buffer);
return -1;
}
memcpy(*data, buffer, i);
}
efree(buffer);
return i-1;
}
/* }}} */
/* {{{ stomp_read_line
*/
static int stomp_read_line(stomp_t *stomp, char **data)
{
int rc = 0;
size_t i = 0;
size_t bufsize = STOMP_BUFSIZE + 1;
char *buffer = (char *) emalloc(STOMP_BUFSIZE + 1);
while (1) {
size_t length = 1;
rc = stomp_recv(stomp, buffer + i, length);
if (rc < 1) {
efree(buffer);
return -1;
}
if (1 == length) {
i++;
if (buffer[i-1] == '\n') {
buffer[i-1] = 0;
break;
} else if (buffer[i-1] == 0) {
efree(buffer);
return 0;
}
if (i >= bufsize) {
buffer = (char *) erealloc(buffer, bufsize + STOMP_BUFSIZE);
bufsize += STOMP_BUFSIZE;
}
}
}
if (i > 1) {
*data = (char *) emalloc(i);
if (NULL == *data) {
efree(buffer);
return -1;
}
memcpy(*data, buffer, i);
}
efree(buffer);
return i-1;
}
/* }}} */
/* {{{ stomp_free_frame
*/
void stomp_free_frame(stomp_frame_t *frame)
{
if (frame) {
if (frame->command) {
efree(frame->command);
}
if (frame->body) {
efree(frame->body);
}
if (frame->headers) {
zend_hash_destroy(frame->headers);
efree(frame->headers);
}
efree(frame);
}
}
/* }}} */
/* {{{ stomp_read_frame
*/
stomp_frame_t *stomp_read_frame(stomp_t *stomp)
{
stomp_frame_t *f = NULL;
char *cmd = NULL, *length_str = NULL;
int length = 0;
if (!stomp_select(stomp)) {
return NULL;
}
INIT_STOMP_FRAME(f);
if (NULL == f) {
return NULL;
}
/* Parse the command */
length = stomp_read_line(stomp, &cmd);
if (length < 1) {
RETURN_READ_FRAME_FAIL;
}
f->command = cmd;
f->command_length = length;
/* Parse the header */
while (1) {
char *p = NULL;
length = stomp_read_line(stomp, &p);
if (length < 0) {
RETURN_READ_FRAME_FAIL;
}
if (0 == length) {
break;
} else {
char *p2 = NULL;
char *key;
char *value;
p2 = strstr(p,":");
if (p2 == NULL) {
efree(p);
RETURN_READ_FRAME_FAIL;
}
/* Null terminate the key */
*p2=0;
key = p;
/* The rest is the value. */
value = p2+1;
/* Insert key/value into hash table. */
zend_hash_add(f->headers, key, strlen(key) + 1, value, strlen(value) + 1, NULL);
efree(p);
}
}
/* Check for the content length */
if (zend_hash_find(f->headers, "content-length", strlen("content-length"), (void **)&length_str) == SUCCESS) {
char endbuffer[2];
length = 2;
f->body_length = atoi(length_str);
f->body = (char *) emalloc(f->body_length);
if (-1 == stomp_recv(stomp, f->body, f->body_length)) {
RETURN_READ_FRAME_FAIL;
}
if (length != stomp_recv(stomp, endbuffer, length) || endbuffer[0] != '\0' || endbuffer[1] != '\n') {
RETURN_READ_FRAME_FAIL;
}
} else {
f->body_length = stomp_read_buffer(stomp, &f->body);
}
return f;
}
/* }}} */
/* {{{ stomp_valid_receipt
*/
int stomp_valid_receipt(stomp_t *stomp, stomp_frame_t *frame) {
int success = 1;
char error[1024];
char *receipt = NULL;
if (zend_hash_find(frame->headers, "receipt", sizeof("receipt"), (void **)&receipt) == SUCCESS) {
stomp_frame_t *res = stomp_read_frame(stomp);
success = 0;
if (res) {
if (0 == strncmp("RECEIPT", res->command, sizeof("RECEIPT") - 1)) {
char *receipt_id = NULL;
if (zend_hash_find(res->headers, "receipt-id", sizeof("receipt-id"), (void **)&receipt_id) == SUCCESS
&& strlen(receipt) == strlen(receipt_id)
&& !strcmp(receipt, receipt_id)) {
success = 1;
} else {
snprintf(error, sizeof(error), "Unexpected receipt id : %s", receipt_id);
stomp_set_error(stomp, error, 0, NULL);
}
} 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, res->body);
}
} else {
snprintf(error, sizeof(error), "Receipt not received, unexpected command : %s", res->command);
stomp_set_error(stomp, error, 0, NULL);
}
stomp_free_frame(res);
}
}
return success;
}
/* }}} */
/* {{{ stomp_select
*/
int stomp_select(stomp_t *stomp)
{
int n;
struct timeval tv;
tv.tv_sec = stomp->options.read_timeout_sec;
tv.tv_usec = stomp->options.read_timeout_usec;
n = php_pollfd_for(stomp->fd, PHP_POLLREADABLE, &tv);
if (n < 1) {
#if !defined(PHP_WIN32) && !(defined(NETWARE) && defined(USE_WINSOCK))
if (n == 0) {
errno = ETIMEDOUT;
}
#endif
return 0;
}
return 1;
}
/* }}} */

91
stomp.h Executable file
View File

@ -0,0 +1,91 @@
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2010 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: Pierrick Charron <pierrick@php.net> |
+----------------------------------------------------------------------+
*/
/* $Id: stomp.h 301597 2010-07-27 05:48:59Z pierrick $ */
#ifndef _STOMP_H_
#define _STOMP_H_
#include "php_network.h"
#if HAVE_STOMP_SSL
#include <openssl/ssl.h>
#endif
#define STOMP_BUFSIZE 4096
#define INIT_STOMP_FRAME(f) \
f = (stomp_frame_t *) emalloc(sizeof(stomp_frame_t)); \
f->command = NULL; f->body = NULL; \
ALLOC_HASHTABLE(f->headers); \
zend_hash_init(f->headers, 0, NULL, NULL, 0);
typedef struct _stomp_options {
long connect_timeout_sec;
long connect_timeout_usec;
long read_timeout_sec;
long read_timeout_usec;
#if HAVE_STOMP_SSL
int use_ssl;
#endif
} stomp_options_t;
typedef struct _stomp {
php_socket_t fd;
php_sockaddr_storage localaddr;
stomp_options_t options;
char *host;
unsigned short port;
int status;
char *error;
int errnum;
char *error_details;
char *session;
#if HAVE_STOMP_SSL
SSL *ssl_handle;
#endif
} stomp_t;
typedef struct _stomp_frame {
char *command;
int command_length;
HashTable *headers;
char *body;
int body_length;
} stomp_frame_t;
stomp_t *stomp_init();
int stomp_connect(stomp_t *stomp, const char *host, unsigned short port TSRMLS_DC);
void stomp_close(stomp_t *stomp);
int stomp_send(stomp_t *connection, stomp_frame_t *frame TSRMLS_DC);
stomp_frame_t *stomp_read_frame(stomp_t *connection);
int stomp_valid_receipt(stomp_t *connection, stomp_frame_t *frame);
int stomp_select(stomp_t *connection);
void stomp_set_error(stomp_t *stomp, const char *error, int errnum, const char *details);
void stomp_free_frame(stomp_frame_t *frame);
#endif /* _STOMP_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
*/

10
tests/001-stomp.phpt Normal file
View File

@ -0,0 +1,10 @@
--TEST--
Check for stomp presence
--SKIPIF--
<?php if (!extension_loaded("stomp")) print "skip"; ?>
--FILE--
<?php
echo "stomp extension is available";
?>
--EXPECT--
stomp extension is available

10
tests/002-version.phpt Normal file
View File

@ -0,0 +1,10 @@
--TEST--
Test stomp_version()
--SKIPIF--
<?php if (!extension_loaded("stomp")) print "skip"; ?>
--FILE--
<?php
echo stomp_version();
?>
--EXPECTF--
%d.%d.%d

View File

@ -0,0 +1,20 @@
--TEST--
Test stomp_connect() - URI validation
--SKIPIF--
<?php if (!extension_loaded("stomp")) print "skip"; ?>
--FILE--
<?php
var_dump(stomp_connect(''), stomp_connect_error());
var_dump(stomp_connect(1), stomp_connect_error());
var_dump(stomp_connect('foo'), stomp_connect_error());
var_dump(stomp_connect('foo://bar'), stomp_connect_error());
?>
--EXPECT--
NULL
string(18) "Invalid Broker URI"
NULL
string(18) "Invalid Broker URI"
NULL
string(18) "Invalid Broker URI"
NULL
string(25) "Invalid Broker URI scheme"

View File

@ -0,0 +1,12 @@
--TEST--
Test stomp_connect() - Test connection
--SKIPIF--
<?php if (!extension_loaded("stomp")) print "skip"; ?>
--FILE--
<?php
var_dump(stomp_connect());
var_dump(stomp_connect_error());
?>
--EXPECTF--
resource(%d) of type (stomp connection)
NULL

View File

@ -0,0 +1,14 @@
--TEST--
Test stomp_get_session_id()
--SKIPIF--
<?php
if (!extension_loaded("stomp")) print "skip";
if (!stomp_connect()) print "skip";
?>
--FILE--
<?php
$link = stomp_connect();
var_dump(stomp_get_session_id($link));
?>
--EXPECTF--
string(%d) "%s"

12
tests/005-close/001.phpt Normal file
View File

@ -0,0 +1,12 @@
--TEST--
Test stomp_close() - tests parameters
--SKIPIF--
<?php
if (!extension_loaded("stomp")) print "skip";
?>
--FILE--
<?php
stomp_close(null);
?>
--EXPECTF--
Warning: stomp_close() expects parameter 1 to be resource, null given in %s on line %d

16
tests/005-close/002.phpt Normal file
View File

@ -0,0 +1,16 @@
--TEST--
Test stomp_close()
--SKIPIF--
<?php
if (!extension_loaded("stomp")) print "skip";
if (!stomp_connect()) print "skip";
?>
--FILE--
<?php
$link = stomp_connect();
if($link) echo "success" . PHP_EOL;
if(stomp_close($link)) echo "closed";
?>
--EXPECT--
success
closed

29
tests/006-send/001.phpt Normal file
View File

@ -0,0 +1,29 @@
--TEST--
Test stomp_send() - tests parameters
--SKIPIF--
<?php
if (!extension_loaded("stomp")) print "skip";
if (!stomp_connect()) print "skip";
?>
--FILE--
<?php
$link = stomp_connect();
stomp_send($link, '', array());
stomp_send($link, '/queue/test-06', array());
var_dump(stomp_send($link, '/queue/test-06', ''));
var_dump(stomp_send($link, '/queue/test-06', 'A realMessage'));
var_dump(stomp_send($link, '/queue/test-06', 'بياريك شارون'));
var_dump(stomp_send($link, 'بياريك شارون', 'بياريك شارون', array('receipt' => 'message-123')));
echo gettype(stomp_error($link));
?>
--EXPECTF--
Warning: stomp_send(): Destination can not be empty in %s on line %d
Warning: stomp_send(): Expects parameter %d to be a string or a StompFrame object. in %s on line %d
bool(true)
bool(true)
bool(true)
bool(false)
string

29
tests/006-send/002.phpt Normal file
View File

@ -0,0 +1,29 @@
--TEST--
Test stomp::send() - tests parameters
--SKIPIF--
<?php
if (!extension_loaded("stomp")) print "skip";
if (!stomp_connect()) print "skip";
?>
--FILE--
<?php
$s = new Stomp();
$s->send('', array());
$s->send('/queue/test-06', array());
var_dump($s->send('/queue/test-06', ''));
var_dump($s->send('/queue/test-06', 'A realMessage'));
var_dump($s->send('/queue/test-06', 'بياريك شارون'));
var_dump($s->send('بياريك شارون', 'بياريك شارون', array('receipt' => 'message-123')));
echo gettype($s->error());
?>
--EXPECTF--
Warning: Stomp::send(): Destination can not be empty in %s on line %d
Warning: Stomp::send(): Expects parameter %d to be a string or a StompFrame object. in %s on line %d
bool(true)
bool(true)
bool(true)
bool(false)
string

View File

@ -0,0 +1,17 @@
--TEST--
Test Stomp::subscribe()
--SKIPIF--
<?php
if (!extension_loaded("stomp")) print "skip";
if (!stomp_connect()) print "skip";
?>
--FILE--
<?php
$s = new Stomp();
$s->subscribe('', array());
$s->subscribe('/queue/test', 'string');
?>
--EXPECTF--
Warning: Stomp::subscribe(): Destination can not be empty in %s on line %d
Catchable fatal error: Argument 2 passed to Stomp::subscribe() must be %s array, string given in %s on line %d

View File

@ -0,0 +1,17 @@
--TEST--
Test Stomp::unsubscribe()
--SKIPIF--
<?php
if (!extension_loaded("stomp")) print "skip";
if (!stomp_connect()) print "skip";
?>
--FILE--
<?php
$s = new Stomp();
$s->unsubscribe('', array());
$s->unsubscribe('/queue/test', 'string');
?>
--EXPECTF--
Warning: Stomp::unsubscribe(): Destination can not be empty in %s on line %d
Catchable fatal error: Argument 2 passed to Stomp::unsubscribe() must be %s array, string given in %s on line %d

View File

@ -0,0 +1,19 @@
--TEST--
Test stomp::readFrame() - tests functionnality and parameters
--SKIPIF--
<?php
if (!extension_loaded("stomp")) print "skip";
if (!stomp_connect()) print "skip";
?>
--FILE--
<?php
$s = new Stomp();
$s->send('/queue/test-09', 'A test Message');
$s->subscribe('/queue/test-09');
var_dump($s->readFrame()->body);
var_dump($s->readFrame());
?>
--EXPECTF--
string(14) "A test Message"
bool(false)

View File

@ -0,0 +1,20 @@
--TEST--
Test stomp_read_frame() - test functionnality and parameters
--SKIPIF--
<?php
if (!extension_loaded("stomp")) print "skip";
if (!stomp_connect()) print "skip";
?>
--FILE--
<?php
$link = stomp_connect();
stomp_send($link, '/queue/test-09', 'A test Message');
stomp_subscribe($link, '/queue/test-09');
$result = stomp_read_frame($link);
var_dump($result['body']);
var_dump(stomp_read_frame($link));
?>
--EXPECTF--
string(14) "A test Message"
bool(false)

View File

@ -0,0 +1,27 @@
--TEST--
Test stomp::readFrame() - custom frame class
--SKIPIF--
<?php
if (!extension_loaded("stomp")) print "skip";
if (!stomp_connect()) print "skip";
?>
--FILE--
<?php
class customFrame extends stompFrame
{
public function __construct($cmd, $headers, $body)
{
parent::__construct($cmd, $headers, $body);
}
}
$s = new Stomp();
$s->send('/queue/test-09', 'A test Message');
$s->subscribe('/queue/test-09');
$frame = $s->readFrame('customFrame');
var_dump(get_class($frame), $frame->body);
?>
--EXPECT--
string(11) "customFrame"
string(14) "A test Message"

View File

@ -0,0 +1,91 @@
--TEST--
Test Stomp::getReadTimout() and Stomp::setReadTimeout() - tests functionnality and parameters
--INI--
stomp.default_read_timeout_sec=5
stomp.default_read_timeout_usec=5
--SKIPIF--
<?php
if (!extension_loaded("stomp")) print "skip";
if (!stomp_connect()) print "skip";
?>
--FILE--
<?php
$s = new Stomp();
// First test, read from ini variables, expected to return 5.5
var_dump($s->getReadTimeout());
// Set read timout with an integer as seconds
var_dump($s->setReadTimeout(10));
// Second test, read supposed to return 10.0
var_dump($s->getReadTimeout());
// Set read timout with an integer as seconds
var_dump($s->setReadTimeout(10, 5));
// Third test, read supposed to return 10.5
var_dump($s->getReadTimeout());
// Set read timout with the first param as a string, supposed to trigger a warning
var_dump($s->setReadTimeout(''));
// Fourth test, read supposed to get the last value set : 10.5
var_dump($s->getReadTimeout());
// Set read timout with the second param as a string, supposed to trigger a warning
var_dump($s->setReadTimeout(10, ''));
// Fourth test, read supposed to get the last value set : 10.5
var_dump($s->getReadTimeout());
// Set read timout with the params as null
var_dump($s->setReadTimeout(null, null));
// Fifth test, read supposed to get the last value set : 0.0
var_dump($s->getReadTimeout());
unset($s);
?>
--EXPECTF--
array(2) {
["sec"]=>
int(5)
["usec"]=>
int(5)
}
NULL
array(2) {
["sec"]=>
int(10)
["usec"]=>
int(0)
}
NULL
array(2) {
["sec"]=>
int(10)
["usec"]=>
int(5)
}
Warning: Stomp::setReadTimeout() expects parameter 1 to be long, string given in %s on line %d
NULL
array(2) {
["sec"]=>
int(10)
["usec"]=>
int(5)
}
Warning: Stomp::setReadTimeout() expects parameter 2 to be long, string given in %s on line %d
NULL
array(2) {
["sec"]=>
int(10)
["usec"]=>
int(5)
}
NULL
array(2) {
["sec"]=>
int(0)
["usec"]=>
int(0)
}

View File

@ -0,0 +1,4 @@
<?php
if (!extension_loaded("stomp")) print "skip";
if (!stomp_connect()) print "skip";
?>

View File

@ -0,0 +1,92 @@
--TEST--
Test stomp_get_read_timout() and stomp_set_read_timeout() - tests functionnality and parameters
--INI--
stomp.default_read_timeout_sec=5
stomp.default_read_timeout_usec=5
--SKIPIF--
<?php
if (!extension_loaded("stomp")) print "skip";
if (!stomp_connect()) print "skip";
?>
--FILE--
<?php
$link = stomp_connect();
// First test, read from ini variables, expected to return 5.5
var_dump(stomp_get_read_timeout($link));
// Set read timout with an integer as seconds
var_dump(stomp_set_read_timeout($link, 10));
// Second test, read supposed to return 10.0
var_dump(stomp_get_read_timeout($link));
// Set read timout with an integer as seconds
var_dump(stomp_set_read_timeout($link, 10, 5));
// Third test, read supposed to return 10.5
var_dump(stomp_get_read_timeout($link));
// Set read timout with the first param as a string, supposed to trigger a warning
var_dump(stomp_set_read_timeout($link, ''));
// Fourth test, read supposed to get the last value set : 10.5
var_dump(stomp_get_read_timeout($link));
// Set read timout with the second param as a string, supposed to trigger a warning
var_dump(stomp_set_read_timeout($link, 10, ''));
// Fourth test, read supposed to get the last value set : 10.5
var_dump(stomp_get_read_timeout($link));
// Set read timout with the params as null
var_dump(stomp_set_read_timeout($link, null, null));
// Fifth test, read supposed to get the last value set : 0.0
var_dump(stomp_get_read_timeout($link));
unset($s);
?>
--EXPECTF--
array(2) {
["sec"]=>
int(5)
["usec"]=>
int(5)
}
NULL
array(2) {
["sec"]=>
int(10)
["usec"]=>
int(0)
}
NULL
array(2) {
["sec"]=>
int(10)
["usec"]=>
int(5)
}
Warning: stomp_set_read_timeout() expects parameter 2 to be long, string given in %s on line %d
NULL
array(2) {
["sec"]=>
int(10)
["usec"]=>
int(5)
}
Warning: stomp_set_read_timeout() expects parameter 3 to be long, string given in %s on line %d
NULL
array(2) {
["sec"]=>
int(10)
["usec"]=>
int(5)
}
NULL
array(2) {
["sec"]=>
int(0)
["usec"]=>
int(0)
}

42
tests/011-commit/001.phpt Normal file
View File

@ -0,0 +1,42 @@
--TEST--
Test Stomp::commit() - tests functionnality and parameters
--SKIPIF--
<?php
if (!extension_loaded("stomp")) print "skip";
if (!stomp_connect()) print "skip";
?>
--FILE--
<?php
$s = new Stomp();
/* begin a transaction */
var_dump($s->begin('t1'));
// sends a message to the queue and specifies a good transaction
var_dump($s->send('/queue/test-011-commit', 'bar', array('transaction' => 't1')));
// sends a message to the queue and asks for a receipt
$s->send('/queue/test-011-commit', 'bar', array('transaction' => 't2', 'receipt' => 'tptp'));
echo gettype($s->error()) . PHP_EOL;
// commits a valid transaction
var_dump($s->commit('t1'));
// commits non valid transaction (null as a parameter) and asks for a receipt
var_dump($s->commit(null, array('receipt' => 'commit-key')));
var_dump($s->commit(null));
// commits a non valid transaction (a transaction id that does not exist) and asks for a receipt
$s->commit('t2', array('receipt' => 'commit-key'));
echo gettype($s->error());
unset($s);
?>
--EXPECTF--
bool(true)
bool(true)
string
bool(true)
bool(false)
bool(true)
string

17
tests/bug_16930.phpt Normal file
View File

@ -0,0 +1,17 @@
--TEST--
Bug #16930 - readFrame reports error-frames as "timeout"
--SKIPIF--
<?php if (!extension_loaded("stomp")) print "skip"; ?>
--FILE--
<?php
$s = new Stomp();
$s->abort('t2');
try {
var_dump($s->readFrame());
} catch(StompException $e) {
var_dump($e->getMessage());
}
?>
--EXPECTF--
string(%d) "%s"

38
tests/bug_16936.phpt Normal file
View File

@ -0,0 +1,38 @@
--TEST--
Bug #16936 - Module segfaults on readFrame if Frame > STOMP_BUFSIZE
--SKIPIF--
<?php if (!extension_loaded("stomp")) print "skip"; ?>
--FILE--
<?php
$queue = '/queue/foo';
$msg = str_repeat('bar', 3000);
/* connection */
try {
$stomp = new Stomp();
} catch(StompException $e) {
die('Connection failed: ' . $e->getMessage());
}
/* send a message to the queue 'foo' */
$stomp->send($queue, $msg);
/* subscribe to messages from the queue 'foo' */
$stomp->subscribe($queue);
/* read a frame */
$frame = $stomp->readFrame();
if ($frame->body === $msg) {
var_dump($frame->body);
/* acknowledge that the frame was received */
$stomp->ack($frame);
}
/* close connection */
unset($stomp);
?>
--EXPECTF--
string(%d) "%s"