mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-03-24 17:32:41 +08:00
Add mosquitto_set_clientid function for security plugins.
Signed-off-by: Tobias Assarsson <tobias.assarsson@gmail.com>
This commit is contained in:
@@ -462,6 +462,21 @@ mosq_EXPORT const char *mosquitto_client_username(const struct mosquitto *client
|
||||
*/
|
||||
mosq_EXPORT int mosquitto_set_username(struct mosquitto *client, const char *username);
|
||||
|
||||
/* Function: mosquitto_set_clientid
|
||||
*
|
||||
* Set the client id for a client.
|
||||
*
|
||||
* This effectively forces the client onto another message queue.
|
||||
* Can be used to scope client ids by prefixing the client id with some user-specific data.
|
||||
* eg. "client1" could become "user1-client1".
|
||||
*
|
||||
* Returns:
|
||||
* MOSQ_ERR_SUCCESS - on success
|
||||
* MOSQ_ERR_INVAL - if client is NULL, or if clientid is not a valid utf-8 string
|
||||
* MOSQ_ERR_NOMEM - on out of memory
|
||||
*/
|
||||
mosq_EXPORT int mosquitto_set_clientid(struct mosquitto *client, const char *clientid);
|
||||
|
||||
|
||||
/* =========================================================================
|
||||
*
|
||||
|
||||
@@ -29,6 +29,7 @@ _mosquitto_property_free_all
|
||||
_mosquitto_pub_topic_check
|
||||
_mosquitto_realloc
|
||||
_mosquitto_set_username
|
||||
_mosquitto_set_clientid
|
||||
_mosquitto_strdup
|
||||
_mosquitto_sub_matches_acl
|
||||
_mosquitto_sub_matches_acl_with_pattern
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
mosquitto_pub_topic_check;
|
||||
mosquitto_realloc;
|
||||
mosquitto_set_username;
|
||||
mosquitto_set_clientid;
|
||||
mosquitto_strdup;
|
||||
mosquitto_sub_matches_acl;
|
||||
mosquitto_sub_matches_acl_with_pattern;
|
||||
|
||||
@@ -268,6 +268,28 @@ int mosquitto_set_username(struct mosquitto *client, const char *username)
|
||||
}
|
||||
}
|
||||
|
||||
int mosquitto_set_clientid(struct mosquitto *client, const char *clientid)
|
||||
{
|
||||
char *u_dup;
|
||||
char *old;
|
||||
|
||||
if(!client) return MOSQ_ERR_INVAL;
|
||||
|
||||
int clientid_len = (int)strlen(clientid);
|
||||
if(mosquitto_validate_utf8(clientid, clientid_len)){
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
|
||||
u_dup = mosquitto__strdup(clientid);
|
||||
if(!u_dup) return MOSQ_ERR_NOMEM;
|
||||
|
||||
|
||||
old = client->id;
|
||||
client->id = u_dup;
|
||||
|
||||
mosquitto__free(old);
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
}
|
||||
|
||||
static void disconnect_client(struct mosquitto *context, bool with_will)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user