Skip to content

Commit

Permalink
Add setCredentials function
Browse files Browse the repository at this point in the history
  • Loading branch information
mgdm committed Oct 4, 2013
1 parent 4753145 commit 67aee03
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
21 changes: 21 additions & 0 deletions mosquitto.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ PHP_METHOD(Mosquitto_Client, __construct)
}
/* }}} */

/* {{{ */
PHP_METHOD(Mosquitto_Client, setCredentials)
{
mosquitto_client_object *object;
char *username = NULL, *password = NULL;
int username_len, password_len, retval;

PHP_MOSQUITTO_ERROR_HANDLING();
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &username, &username_len, &password, &password_len) == FAILURE) {
PHP_MOSQUITTO_RESTORE_ERRORS();
return;
}
PHP_MOSQUITTO_RESTORE_ERRORS();

object = (mosquitto_client_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
retval = mosquitto_username_pw_set(object->client, username, password);
php_mosquitto_handle_errno(retval, errno);
}
/* }}} */

/* {{{ */
PHP_METHOD(Mosquitto_Client, connect)
{
Expand Down Expand Up @@ -546,6 +566,7 @@ PHP_MOSQUITTO_API void php_mosquitto_subscribe_callback(struct mosquitto *mosq,
/* {{{ mosquitto_client_methods */
const zend_function_entry mosquitto_client_methods[] = {
PHP_ME(Mosquitto_Client, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(Mosquitto_Client, setCredentials, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Mosquitto_Client, connect, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Mosquitto_Client, onConnect, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Mosquitto_Client, onDisconnect, NULL, ZEND_ACC_PUBLIC)
Expand Down
1 change: 0 additions & 1 deletion php_mosquitto.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ PHP_MOSQUITTO_API void php_mosquitto_disconnect_callback(struct mosquitto *mosq,
PHP_MOSQUITTO_API void php_mosquitto_message_callback(struct mosquitto *mosq, void *client_obj, const struct mosquitto_message *message);
PHP_MOSQUITTO_API void php_mosquitto_subscribe_callback(struct mosquitto *mosq, void *client_obj, int mid, int qos_count, const int *granted_qos);


char *php_mosquitto_strerror_wrapper(int err);
void php_mosquitto_handle_errno(int retval, int err);

Expand Down

0 comments on commit 67aee03

Please sign in to comment.