Implement 1.1 in CONNECT and SUBSCRIBE

v1.1
Pierrick Charron 2014-12-09 19:46:38 -05:00
parent 8b0bbd4db2
commit d0bc504615
3 changed files with 47 additions and 6 deletions

View File

@ -527,7 +527,6 @@ PHP_FUNCTION(stomp_connect)
stomp->options.connect_timeout_usec = STOMP_G(connection_timeout_usec);
stomp->status = stomp_connect(stomp, url_parts->host, url_parts->port ? url_parts->port : 61613 TSRMLS_CC);
php_url_free(url_parts);
if (stomp->status) {
stomp_frame_t *res;
@ -542,13 +541,20 @@ PHP_FUNCTION(stomp_connect)
password = STOMP_G(default_password);
password_len = strlen(password);
}
zend_hash_add(frame.headers, "login", sizeof("login"), username, username_len + 1, NULL);
zend_hash_add(frame.headers, "passcode", sizeof("passcode"), password, password_len + 1, NULL);
if (username_len) {
zend_hash_add(frame.headers, "login", sizeof("login"), username, username_len+1, NULL);
}
if (password_len) {
zend_hash_add(frame.headers, "passcode", sizeof("passcode"), password, password_len+1, NULL);
}
if (NULL != headers) {
FRAME_HEADER_FROM_HASHTABLE(frame.headers, Z_ARRVAL_P(headers));
}
zend_hash_add(frame.headers, "accept-version", sizeof("accept-version"), "1.0,1.1", sizeof("1.0,1.1"), NULL);
zend_hash_add(frame.headers, "host", sizeof("host"), url_parts->host, strlen(url_parts->host)+1, NULL);
stomp_send(stomp, &frame TSRMLS_CC);
CLEAR_FRAME(frame);
@ -581,6 +587,11 @@ PHP_FUNCTION(stomp_connect)
}
stomp->session = estrdup(key);
}
if (zend_hash_find(res->headers, "version", sizeof("version"), (void **)&key) == SUCCESS) {
if (!strncmp(key, "1.1", sizeof("1.1"))) {
stomp->version = STOMP_1_1;
}
}
stomp_free_frame(res);
@ -593,6 +604,7 @@ PHP_FUNCTION(stomp_connect)
stomp_close(i_obj->stomp);
}
i_obj->stomp = stomp;
php_url_free(url_parts);
RETURN_TRUE;
}
}
@ -601,6 +613,7 @@ PHP_FUNCTION(stomp_connect)
}
stomp_close(stomp);
php_url_free(url_parts);
RETURN_FALSE;
}
/* }}} */
@ -760,6 +773,7 @@ PHP_FUNCTION(stomp_subscribe)
zval *headers = NULL;
stomp_frame_t frame = {0};
int success = 0;
char *id = NULL;
if (stomp_object) {
stomp_object_t *i_obj = NULL;
@ -791,14 +805,26 @@ PHP_FUNCTION(stomp_subscribe)
/* Add the destination */
zend_hash_add(frame.headers, "ack", sizeof("ack"), "client", sizeof("client"), NULL);
zend_hash_add(frame.headers, "destination", sizeof("destination"), destination, destination_length + 1, NULL);
zend_hash_add(frame.headers, "activemq.prefetchSize", sizeof("activemq.prefetchSize"), "1", sizeof("1"), NULL);
zend_hash_add(frame.headers, "activemq.prefetchSize", sizeof("activemq.prefetchSize"), "1", sizeof("1"), NULL);
if (stomp->version >= STOMP_1_1) {
zend_hash_add(frame.headers, "id", sizeof("id"), "0", sizeof("0"), NULL);
}
if (stomp_send(stomp, &frame TSRMLS_CC) > 0) {
success = stomp_valid_receipt(stomp, &frame);
}
if (zend_hash_find(frame.headers, "id", sizeof("id"), (void **)&id) == SUCCESS) {
id = estrdup(id);
}
CLEAR_FRAME(frame);
RETURN_BOOL(success);
if (id) {
RETURN_STRING(id, 0);
} else {
RETURN_BOOL(success);
}
}
/* }}} */

View File

@ -79,6 +79,7 @@ stomp_t *stomp_init()
stomp->error_details = NULL;
stomp->errnum = 0;
stomp->session = NULL;
stomp->version = STOMP_1_0;
stomp->options.connect_timeout_sec = 2;
stomp->options.connect_timeout_usec = 0;
stomp->options.read_timeout_sec = 2;
@ -377,6 +378,9 @@ int stomp_send(stomp_t *stomp, stomp_frame_t *frame TSRMLS_DC)
smart_str_free(&buf);
#if PHP_DEBUG
print_stomp_frame(frame TSRMLS_CC);
#endif
return 1;
}
/* }}} */
@ -668,6 +672,11 @@ stomp_frame_t *stomp_read_frame_ex(stomp_t *stomp, int use_stack)
f->body_length = stomp_read_buffer(stomp, &f->body);
}
#if PHP_DEBUG
TSRMLS_FETCH();
print_stomp_frame(f TSRMLS_CC);
#endif
return f;
}
/* }}} */

View File

@ -35,6 +35,11 @@
ALLOC_HASHTABLE(f->headers); \
zend_hash_init(f->headers, 0, NULL, NULL, 0);
typedef enum {
STOMP_1_0 = 0x0100,
STOMP_1_1 = 0x0101,
} stomp_version;
typedef struct _stomp_options {
long connect_timeout_sec;
long connect_timeout_usec;
@ -68,6 +73,7 @@ typedef struct _stomp {
char *error;
int errnum;
char *error_details;
stomp_version version;
char *session;
#if HAVE_STOMP_SSL
SSL *ssl_handle;