Skip to content

Commit

Permalink
Add support for wills
Browse files Browse the repository at this point in the history
  • Loading branch information
mgdm committed Oct 4, 2013
1 parent 4ee6bbb commit a5aa811
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions mosquitto.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,50 @@ PHP_METHOD(Mosquitto_Client, setCredentials)
}
/* }}} */

/* {{{ */
PHP_METHOD(Mosquitto_Client, setWill)
{
mosquitto_client_object *object;
int topic_len, payload_len, retval;
long qos;
zend_bool retain;
char *topic, *payload;

PHP_MOSQUITTO_ERROR_HANDLING();
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sslb",
&topic, &topic_len, &payload, &payload_len, &qos, &retain) == FAILURE) {
PHP_MOSQUITTO_RESTORE_ERRORS();
return;
}
PHP_MOSQUITTO_RESTORE_ERRORS();

object = (mosquitto_client_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
retval = mosquitto_will_set(object->client, topic, payload_len, (void *) payload, qos, retain);

php_mosquitto_handle_errno(retval, errno);
}
/* }}} */

/* {{{ */
PHP_METHOD(Mosquitto_Client, clearWill)
{
mosquitto_client_object *object;
int retval;

PHP_MOSQUITTO_ERROR_HANDLING();
if (zend_parse_parameters_none() == FAILURE) {
PHP_MOSQUITTO_RESTORE_ERRORS();
return;
}
PHP_MOSQUITTO_RESTORE_ERRORS();

object = (mosquitto_client_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
retval = mosquitto_will_clear(object->client);

php_mosquitto_handle_errno(retval, errno);
}
/* }}} */

/* {{{ */
PHP_METHOD(Mosquitto_Client, connect)
{
Expand Down Expand Up @@ -598,6 +642,8 @@ const zend_function_entry mosquitto_client_methods[] = {
PHP_ME(Mosquitto_Client, onSubscribe, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Mosquitto_Client, onMessage, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Mosquitto_Client, setCredentials, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Mosquitto_Client, setWill, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Mosquitto_Client, clearWill, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Mosquitto_Client, connect, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Mosquitto_Client, disconnect, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Mosquitto_Client, publish, NULL, ZEND_ACC_PUBLIC)
Expand Down

0 comments on commit a5aa811

Please sign in to comment.