Skip to content

Commit

Permalink
Add tokenizeTopic
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Maclean committed Dec 5, 2013
1 parent 7d0eac7 commit 7c95367
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions mosquitto_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ ZEND_BEGIN_ARG_INFO(Mosquitto_Message_topicMatchesSub_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, subscription)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO(Mosquitto_Message_tokenizeTopic_args, ZEND_SEND_BY_VAL)
ZEND_ARG_INFO(0, topic)
ZEND_END_ARG_INFO()

/* }}} */

PHP_METHOD(Mosquitto_Message, __construct)
Expand Down Expand Up @@ -57,6 +61,34 @@ PHP_METHOD(Mosquitto_Message, topicMatchesSub)
}
/* }}} */

/* {{{ Mosquitto\Message::tokenizeTopic() */
PHP_METHOD(Mosquitto_Message, tokenizeTopic)
{
char *topic = NULL, **topics = NULL;
int topic_len = 0, retval = 0, count = 0, i = 0;

PHP_MOSQUITTO_ERROR_HANDLING();
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &topic, &topic_len) == FAILURE) {
PHP_MOSQUITTO_RESTORE_ERRORS();
return;
}

retval = mosquitto_sub_topic_tokenize(topic, &topics, &count);

if (retval == MOSQ_ERR_NOMEM) {
zend_throw_exception_ex(mosquitto_ce_exception, 0 TSRMLS_CC, "Failed to tokenize topic");
return;
}

array_init(return_value);
for (i = 0; i < count; i++) {
add_next_index_string(return_value, topics[i], 1);
}

mosquitto_sub_topic_tokens_free(&topics, count);
}
/* }}} */

PHP_MOSQUITTO_MESSAGE_LONG_PROPERTY_READER_FUNCTION(mid);
PHP_MOSQUITTO_MESSAGE_LONG_PROPERTY_READER_FUNCTION(qos);

Expand Down Expand Up @@ -357,6 +389,7 @@ static zend_object_value mosquitto_message_object_new(zend_class_entry *ce TSRML
const zend_function_entry mosquitto_message_methods[] = {
PHP_ME(Mosquitto_Message, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(Mosquitto_Message, topicMatchesSub, Mosquitto_Message_topicMatchesSub_args, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Mosquitto_Message, tokenizeTopic, Mosquitto_Message_tokenizeTopic_args, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_FE_END
};

Expand Down

0 comments on commit 7c95367

Please sign in to comment.