Skip to content

Commit

Permalink
Add mosquitto_client_id_hashv broker helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
ralight committed Feb 3, 2025
1 parent aa89eb3 commit 843872a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 1 deletion.
8 changes: 8 additions & 0 deletions include/mosquitto/broker.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
1 change: 1 addition & 0 deletions lib/mosquitto_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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;
}
}
1 change: 1 addition & 0 deletions src/linker-macosx.syms
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/linker.syms
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/plugin_public.c
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down

0 comments on commit 843872a

Please sign in to comment.