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 5b864d7
Show file tree
Hide file tree
Showing 4 changed files with 22 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;
}
}
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 5b864d7

Please sign in to comment.