mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-09-21 23:47:52 +08:00
Add mosquitto_client_id_hashv broker helper function
This commit is contained in:
@@ -616,6 +616,14 @@ mosq_EXPORT bool mosquitto_client_clean_session(const struct mosquitto *client);
|
||||
mosq_EXPORT const char *mosquitto_client_id(const struct mosquitto *client);
|
||||
|
||||
|
||||
/*
|
||||
* Function: mosquitto_client_id_hashv
|
||||
*
|
||||
* Retrieve the hash value associated with a client id.
|
||||
*/
|
||||
mosq_EXPORT unsigned mosquitto_client_id_hashv(const struct mosquitto *client);
|
||||
|
||||
|
||||
/*
|
||||
* Function: mosquitto_client_keepalive
|
||||
*
|
||||
|
||||
@@ -302,6 +302,7 @@ struct mosquitto {
|
||||
char *id;
|
||||
char *username;
|
||||
char *password;
|
||||
unsigned id_hashv;
|
||||
uint16_t keepalive;
|
||||
uint16_t last_mid;
|
||||
enum mosquitto_client_state state;
|
||||
|
||||
+3
-1
@@ -329,7 +329,8 @@ void context__add_to_by_id(struct mosquitto *context)
|
||||
{
|
||||
if(context->in_by_id == false){
|
||||
context->in_by_id = true;
|
||||
HASH_ADD_KEYPTR(hh_id, db.contexts_by_id, context->id, strlen(context->id), context);
|
||||
HASH_VALUE(context->id, strlen(context->id), context->id_hashv);
|
||||
HASH_ADD_KEYPTR_BYHASHVALUE(hh_id, db.contexts_by_id, context->id, strlen(context->id), context->id_hashv, context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,6 +349,7 @@ void context__remove_from_by_id(struct mosquitto *context)
|
||||
if(context_found){
|
||||
HASH_DELETE(hh_id, db.contexts_by_id, context_found);
|
||||
}
|
||||
context->id_hashv = 0;
|
||||
context->in_by_id = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ _mosquitto_client_address
|
||||
_mosquitto_client_certificate
|
||||
_mosquitto_client_clean_session
|
||||
_mosquitto_client_id
|
||||
_mosquitto_client_id_hashv
|
||||
_mosquitto_client_keepalive
|
||||
_mosquitto_client_port
|
||||
_mosquitto_client_protocol
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
mosquitto_client_certificate;
|
||||
mosquitto_client_clean_session;
|
||||
mosquitto_client_id;
|
||||
mosquitto_client_id_hashv;
|
||||
mosquitto_client_keepalive;
|
||||
mosquitto_client_port;
|
||||
mosquitto_client_protocol;
|
||||
|
||||
@@ -104,6 +104,16 @@ BROKER_EXPORT const char *mosquitto_client_id(const struct mosquitto *client)
|
||||
}
|
||||
|
||||
|
||||
BROKER_EXPORT unsigned mosquitto_client_id_hashv(const struct mosquitto *client)
|
||||
{
|
||||
if(client){
|
||||
return client->id_hashv;
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BROKER_EXPORT int mosquitto_client_keepalive(const struct mosquitto *client)
|
||||
{
|
||||
if(client){
|
||||
|
||||
Reference in New Issue
Block a user