diff --git a/apps/db_dump/db_dump.c b/apps/db_dump/db_dump.c index 08871ee2..072b9ad9 100644 --- a/apps/db_dump/db_dump.c +++ b/apps/db_dump/db_dump.c @@ -80,20 +80,20 @@ struct base_msg_chunk *msgs_by_id = NULL; static void free__sub(struct P_sub *chunk) { - free(chunk->client_id); + free(chunk->clientid); free(chunk->topic); } static void free__client(struct P_client *chunk) { free(chunk->username); - free(chunk->client_id); + free(chunk->clientid); } static void free__client_msg(struct P_client_msg *chunk) { - free(chunk->client_id); + free(chunk->clientid); } @@ -166,10 +166,10 @@ static int dump__client_chunk_process(FILE *db_fd, uint32_t length) if(!cc){ fprintf(stderr, "Error: Out of memory.\n"); fclose(db_fd); - free(chunk.client_id); + free(chunk.clientid); return 1; } - cc->id = strdup(chunk.client_id); + cc->id = strdup(chunk.clientid); HASH_ADD_KEYPTR(hh_id, clients_by_id, cc->id, strlen(cc->id), cc); } @@ -204,7 +204,7 @@ static int dump__client_msg_chunk_process(FILE *db_fd, uint32_t length) } if(client_stats){ - HASH_FIND(hh_id, clients_by_id, chunk.client_id, strlen(chunk.client_id), cc); + HASH_FIND(hh_id, clients_by_id, chunk.clientid, strlen(chunk.clientid), cc); if(cc){ cc->messages++; cc->message_size += length; @@ -360,7 +360,7 @@ static int dump__sub_chunk_process(FILE *db_fd, uint32_t length) } if(client_stats){ - HASH_FIND(hh_id, clients_by_id, chunk.client_id, strlen(chunk.client_id), cc); + HASH_FIND(hh_id, clients_by_id, chunk.clientid, strlen(chunk.clientid), cc); if(cc){ cc->subscriptions++; cc->subscription_size += length; diff --git a/apps/db_dump/print.c b/apps/db_dump/print.c index ab19f54f..f124b7ff 100644 --- a/apps/db_dump/print.c +++ b/apps/db_dump/print.c @@ -76,7 +76,7 @@ void print__client(struct P_client *chunk, uint32_t length) { printf("DB_CHUNK_CLIENT:\n"); printf("\tLength: %d\n", length); - printf("\tClient ID: %s\n", chunk->client_id); + printf("\tClient ID: %s\n", chunk->clientid); if(chunk->username){ printf("\tUsername: %s\n", chunk->username); } @@ -93,7 +93,7 @@ void print__client_msg(struct P_client_msg *chunk, uint32_t length) { printf("DB_CHUNK_CLIENT_MSG:\n"); printf("\tLength: %d\n", length); - printf("\tClient ID: %s\n", chunk->client_id); + printf("\tClient ID: %s\n", chunk->clientid); printf("\tStore ID: %" PRIu64 "\n", chunk->F.store_id); printf("\tMID: %d\n", chunk->F.mid); printf("\tQoS: %d\n", chunk->F.qos); @@ -139,7 +139,7 @@ void print__sub(struct P_sub *chunk, uint32_t length) { printf("DB_CHUNK_SUB:\n"); printf("\tLength: %u\n", length); - printf("\tClient ID: %s\n", chunk->client_id); + printf("\tClient ID: %s\n", chunk->clientid); printf("\tTopic: %s\n", chunk->topic); printf("\tQoS: %d\n", chunk->F.qos); printf("\tSubscription ID: %d\n", chunk->F.identifier); diff --git a/client/client_shared.c b/client/client_shared.c index 20ccf4cf..037e9ee6 100644 --- a/client/client_shared.c +++ b/client/client_shared.c @@ -1426,7 +1426,7 @@ int client_opts_set(struct mosquitto *mosq, struct mosq_config *cfg) return MOSQ_ERR_SUCCESS; } -int client_id_generate(struct mosq_config *cfg) +int clientid_generate(struct mosq_config *cfg) { if(cfg->id_prefix){ cfg->id = malloc(strlen(cfg->id_prefix)+10); diff --git a/client/client_shared.h b/client/client_shared.h index 51cd022a..41f8265b 100644 --- a/client/client_shared.h +++ b/client/client_shared.h @@ -141,7 +141,7 @@ struct mosq_config { int client_config_load(struct mosq_config *config, int pub_or_sub, int argc, char *argv[]); void client_config_cleanup(struct mosq_config *cfg); int client_opts_set(struct mosquitto *mosq, struct mosq_config *cfg); -int client_id_generate(struct mosq_config *cfg); +int clientid_generate(struct mosq_config *cfg); int client_connect(struct mosquitto *mosq, struct mosq_config *cfg); int cfg_parse_property(struct mosq_config *cfg, int argc, char *argv[], int *idx); diff --git a/client/pub_client.c b/client/pub_client.c index d8125d68..a0806046 100644 --- a/client/pub_client.c +++ b/client/pub_client.c @@ -569,7 +569,7 @@ int main(int argc, char *argv[]) } - if(client_id_generate(&cfg)){ + if(clientid_generate(&cfg)){ goto cleanup; } diff --git a/client/rr_client.c b/client/rr_client.c index 7e8bf216..480dff62 100644 --- a/client/rr_client.c +++ b/client/rr_client.c @@ -356,7 +356,7 @@ int main(int argc, char *argv[]) } output_init(&cfg); - if(client_id_generate(&cfg)){ + if(clientid_generate(&cfg)){ goto cleanup; } diff --git a/client/sub_client.c b/client/sub_client.c index ad0b3ee9..cd4be9da 100644 --- a/client/sub_client.c +++ b/client/sub_client.c @@ -373,7 +373,7 @@ int main(int argc, char *argv[]) goto cleanup; } - if(client_id_generate(&cfg)){ + if(clientid_generate(&cfg)){ goto cleanup; } diff --git a/include/mosquitto.h b/include/mosquitto.h index 54d1cabf..1d161667 100644 --- a/include/mosquitto.h +++ b/include/mosquitto.h @@ -2839,7 +2839,7 @@ struct libmosquitto_tls { * qos - the qos to use for the subscription. * host - the broker to connect to. * port - the network port the broker is listening on. - * client_id - the client id to use, or NULL if a random client id should be + * clientid - the client id to use, or NULL if a random client id should be * generated. * keepalive - the MQTT keepalive value. * clean_session - the MQTT clean session flag. @@ -2863,7 +2863,7 @@ libmosq_EXPORT int mosquitto_subscribe_simple( int qos, const char *host, int port, - const char *client_id, + const char *clientid, int keepalive, bool clean_session, const char *username, @@ -2892,7 +2892,7 @@ libmosq_EXPORT int mosquitto_subscribe_simple( * qos - the qos to use for the subscription. * host - the broker to connect to. * port - the network port the broker is listening on. - * client_id - the client id to use, or NULL if a random client id should be + * clientid - the client id to use, or NULL if a random client id should be * generated. * keepalive - the MQTT keepalive value. * clean_session - the MQTT clean session flag. @@ -2915,7 +2915,7 @@ libmosq_EXPORT int mosquitto_subscribe_callback( int qos, const char *host, int port, - const char *client_id, + const char *clientid, int keepalive, bool clean_session, const char *username, diff --git a/include/mosquitto_broker.h b/include/mosquitto_broker.h index 2b7adcea..4b2f5573 100644 --- a/include/mosquitto_broker.h +++ b/include/mosquitto_broker.h @@ -66,7 +66,7 @@ enum mosquitto_broker_msg_direction { * ========================================================================= */ struct mosquitto_client { - char *client_id; + char *clientid; char *username; char *auth_method; struct mosquitto_message_v5 *will; @@ -83,7 +83,7 @@ struct mosquitto_client { }; struct mosquitto_subscription { - char *client_id; + char *clientid; char *topic_filter; mosquitto_property *properties; uint32_t identifier; @@ -110,7 +110,7 @@ struct mosquitto_base_msg { }; struct mosquitto_client_msg { - const char *client_id; + const char *clientid; uint64_t cmsg_id; uint64_t store_id; uint32_t subscription_identifier; @@ -547,7 +547,7 @@ mosq_EXPORT void mosquitto_log_printf(int level, const char *fmt, ...); * * Retrieve the struct mosquitto for a client id, or NULL if the client is not connected. */ -mosq_EXPORT struct mosquitto *mosquitto_client(const char *client_id); +mosq_EXPORT struct mosquitto *mosquitto_client(const char *clientid); /* @@ -843,7 +843,7 @@ mosq_EXPORT int mosquitto_broker_publish_copy( * the call to `mosquitto_complete_basic_auth()` must happen in the main * mosquitto thread. Using the MOSQ_EVT_TICK event for this is suggested. */ -mosq_EXPORT void mosquitto_complete_basic_auth(const char* client_id, int result); +mosq_EXPORT void mosquitto_complete_basic_auth(const char* clientid, int result); /* Function: mosquitto_broker_node_id_set @@ -876,7 +876,7 @@ mosq_EXPORT int mosquitto_broker_node_id_set(uint16_t id); * the broker. * * Parameters: - * client->plugin_client_id - the client id of the client to add + * client->plugin_clientid - the client id of the client to add * This must be allocated on the heap and becomes the property of the * broker immediately this call is made. Must not be NULL. * client->plugin_username - the username for the client session, or NULL. Must @@ -902,7 +902,7 @@ mosq_EXPORT int mosquitto_broker_node_id_set(uint16_t id); * * Returns: * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if client or client->plugin_client_id is NULL, or if a + * MOSQ_ERR_INVAL - if client or client->plugin_clientid is NULL, or if a * client with the same ID already exists. * MOSQ_ERR_NOMEM - on out of memory */ @@ -914,7 +914,7 @@ mosq_EXPORT int mosquitto_persist_client_add(struct mosquitto_client *client); * Use to update client session parameters * * Parameters: - * client->plugin_client_id - the client id of the client to update + * client->plugin_clientid - the client id of the client to update * The broker will *not* modify this string and it remains the * property of the plugin. * client->username - the new username for the client session, or NULL. Must @@ -937,7 +937,7 @@ mosq_EXPORT int mosquitto_persist_client_add(struct mosquitto_client *client); * * Returns: * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if client or client->plugin_client_id is NULL + * MOSQ_ERR_INVAL - if client or client->plugin_clientid is NULL * MOSQ_ERR_NOT_FOUND - the client is not found */ mosq_EXPORT int mosquitto_persist_client_update(struct mosquitto_client *client); @@ -948,14 +948,14 @@ mosq_EXPORT int mosquitto_persist_client_update(struct mosquitto_client *client) * Use to delete client session for a client from the broker * * Parameters: - * client_id - the client id of the client to delete + * clientid - the client id of the client to delete * * Returns: * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if client_id is NULL + * MOSQ_ERR_INVAL - if clientid is NULL * MOSQ_ERR_NOT_FOUND - the referenced client is not found */ -mosq_EXPORT int mosquitto_persist_client_delete(const char *client_id); +mosq_EXPORT int mosquitto_persist_client_delete(const char *clientid); /* Function: mosquitto_persist_client_msg_add @@ -963,7 +963,7 @@ mosq_EXPORT int mosquitto_persist_client_delete(const char *client_id); * Use to add a client message for a particular client. * * Parameters: - * client_msg->client_id - the client id of the client that the + * client_msg->clientid - the client id of the client that the * message belongs to. * client_msg->store_id - the ID of the base message that this client * message references. @@ -980,7 +980,7 @@ mosq_EXPORT int mosquitto_persist_client_delete(const char *client_id); * * Returns: * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if client_msg or client_msg->plugin_client_id is NULL + * MOSQ_ERR_INVAL - if client_msg or client_msg->plugin_clientid is NULL * MOSQ_ERR_NOT_FOUND - the client or base message is not found */ mosq_EXPORT int mosquitto_persist_client_msg_add(struct mosquitto_client_msg *client_msg); @@ -991,7 +991,7 @@ mosq_EXPORT int mosquitto_persist_client_msg_add(struct mosquitto_client_msg *cl * Use to delete a client message for a particular client. * * Parameters: - * client_msg->client_id - the client id of the client that the + * client_msg->clientid - the client id of the client that the * message belongs to. * client_msg->cmsg_id - the client message id of the affected message * client_msg->mid - the MQTT message id of the affected message @@ -1003,7 +1003,7 @@ mosq_EXPORT int mosquitto_persist_client_msg_add(struct mosquitto_client_msg *cl * * Returns: * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if client_msg or client_msg->plugin_client_id is NULL + * MOSQ_ERR_INVAL - if client_msg or client_msg->plugin_clientid is NULL * MOSQ_ERR_NOT_FOUND - the client is not found */ mosq_EXPORT int mosquitto_persist_client_msg_delete(struct mosquitto_client_msg *client_msg); @@ -1014,7 +1014,7 @@ mosq_EXPORT int mosquitto_persist_client_msg_delete(struct mosquitto_client_msg * Use to update the state of a client message for a particular client. * * Parameters: - * client_msg->client_id - the client id of the client that the + * client_msg->clientid - the client id of the client that the * message belongs to. * client_msg->cmsg_id - the client message id of the affected message * client_msg->mid - the MQTT message id of the affected message @@ -1027,7 +1027,7 @@ mosq_EXPORT int mosquitto_persist_client_msg_delete(struct mosquitto_client_msg * * Returns: * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if client_msg or client_msg->plugin_client_id is NULL + * MOSQ_ERR_INVAL - if client_msg or client_msg->plugin_clientid is NULL * MOSQ_ERR_NOT_FOUND - the client is not found */ mosq_EXPORT int mosquitto_persist_client_msg_update(struct mosquitto_client_msg *client_msg); @@ -1038,7 +1038,7 @@ mosq_EXPORT int mosquitto_persist_client_msg_update(struct mosquitto_client_msg * Clear all messages for the listed client and direction. * * Parameters: - * client_msg->client_id - the client id of the client that the + * client_msg->clientid - the client id of the client that the * message belongs to. * client_msg->direction - the direction of the messages to be cleared, from * the perspective of the broker (mosq_bmd_in / mosq_bmd_out / mosq_bmd_all) @@ -1048,7 +1048,7 @@ mosq_EXPORT int mosquitto_persist_client_msg_update(struct mosquitto_client_msg * * Returns: * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if client_msg or client_msg->plugin_client_id is NULL + * MOSQ_ERR_INVAL - if client_msg or client_msg->plugin_clientid is NULL * MOSQ_ERR_NOT_FOUND - the client is not found */ mosq_EXPORT int mosquitto_persist_client_msg_clear(struct mosquitto_client_msg *client_msg); @@ -1109,14 +1109,14 @@ mosq_EXPORT int mosquitto_persist_base_msg_delete(uint64_t store_id); * Use to add a new subscription for a client * * Parameters: - * sub->client_id - the client id of the client the new subscription is for + * sub->clientid - the client id of the client the new subscription is for * sub->topic - the topic filter for the subscription * sub->subscription_options - the QoS and other flags for this subscription * sub->subscription_identifier - the MQTT v5 subscription id, or 0 * * Returns: * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if sub, client_id, or topic are NULL, or are zero length + * MOSQ_ERR_INVAL - if sub, clientid, or topic are NULL, or are zero length * MOSQ_ERR_NOT_FOUND - the referenced client was not found * MOSQ_ERR_NOMEM - on out of memory */ @@ -1128,16 +1128,16 @@ mosq_EXPORT int mosquitto_subscription_add(const struct mosquitto_subscription * * Use to delete a subscription for a client * * Parameters: - * client_id - the client id of the client the new subscription is for + * clientid - the client id of the client the new subscription is for * topic - the topic filter for the subscription * * Returns: * MOSQ_ERR_SUCCESS - on success - * MOSQ_ERR_INVAL - if client_id or topic are NULL, or are zero length + * MOSQ_ERR_INVAL - if clientid or topic are NULL, or are zero length * MOSQ_ERR_NOT_FOUND - the referenced client was not found * MOSQ_ERR_NOMEM - on out of memory */ -mosq_EXPORT int mosquitto_subscription_delete(const char *client_id, const char *topic); +mosq_EXPORT int mosquitto_subscription_delete(const char *clientid, const char *topic); /* Function: mosquitto_persist_retain_msg_set diff --git a/include/mosquittopp.h b/include/mosquittopp.h index a1c32ad8..a71db242 100644 --- a/include/mosquittopp.h +++ b/include/mosquittopp.h @@ -55,7 +55,7 @@ mosqpp_EXPORT int subscribe_simple( int qos=0, const char *host="localhost", int port=1883, - const char *client_id=NULL, + const char *clientid=NULL, int keepalive=60, bool clean_session=true, const char *username=NULL, @@ -70,7 +70,7 @@ mosqpp_EXPORT int subscribe_callback( int qos=0, const char *host="localhost", int port=1883, - const char *client_id=NULL, + const char *clientid=NULL, int keepalive=60, bool clean_session=true, const char *username=NULL, diff --git a/lib/cpp/mosquittopp.cpp b/lib/cpp/mosquittopp.cpp index 350b38e6..cd4d0428 100644 --- a/lib/cpp/mosquittopp.cpp +++ b/lib/cpp/mosquittopp.cpp @@ -218,7 +218,7 @@ int subscribe_simple( int qos, const char *host, int port, - const char *client_id, + const char *clientid, int keepalive, bool clean_session, const char *username, @@ -229,7 +229,7 @@ int subscribe_simple( return mosquitto_subscribe_simple( messages, msg_count, retained, topic, qos, - host, port, client_id, keepalive, clean_session, + host, port, clientid, keepalive, clean_session, username, password, will, tls); } @@ -241,7 +241,7 @@ mosqpp_EXPORT int subscribe_callback( int qos, const char *host, int port, - const char *client_id, + const char *clientid, int keepalive, bool clean_session, const char *username, @@ -252,7 +252,7 @@ mosqpp_EXPORT int subscribe_callback( return mosquitto_subscribe_callback( callback, userdata, topic, qos, - host, port, client_id, keepalive, clean_session, + host, port, clientid, keepalive, clean_session, username, password, will, tls); } diff --git a/lib/helpers.c b/lib/helpers.c index c62a8049..0584a8a1 100644 --- a/lib/helpers.c +++ b/lib/helpers.c @@ -97,7 +97,7 @@ libmosq_EXPORT int mosquitto_subscribe_simple( int qos, const char *host, int port, - const char *client_id, + const char *clientid, int keepalive, bool clean_session, const char *username, @@ -127,7 +127,7 @@ libmosq_EXPORT int mosquitto_subscribe_simple( on_message_simple, &userdata, topic, qos, host, port, - client_id, keepalive, clean_session, + clientid, keepalive, clean_session, username, password, will, tls); @@ -151,7 +151,7 @@ libmosq_EXPORT int mosquitto_subscribe_callback( int qos, const char *host, int port, - const char *client_id, + const char *clientid, int keepalive, bool clean_session, const char *username, @@ -172,7 +172,7 @@ libmosq_EXPORT int mosquitto_subscribe_callback( cb_userdata.userdata = userdata; cb_userdata.callback = callback; - mosq = mosquitto_new(client_id, clean_session, &cb_userdata); + mosq = mosquitto_new(clientid, clean_session, &cb_userdata); if(!mosq){ return MOSQ_ERR_NOMEM; } diff --git a/plugins/examples/add-properties/mosquitto_add_properties.c b/plugins/examples/add-properties/mosquitto_add_properties.c index 026113f1..6a1032ed 100644 --- a/plugins/examples/add-properties/mosquitto_add_properties.c +++ b/plugins/examples/add-properties/mosquitto_add_properties.c @@ -20,7 +20,7 @@ Contributors: /* * Adds MQTT v5 user-properties to incoming messages: * - $timestamp: unix epoch in milliseconds - * - $client_id: client id of the publishing client + * - $clientid: client id of the publishing client * - $client_username: username that the publishing client used to authenticate * * Compile with: @@ -75,7 +75,7 @@ static int callback_message_in(int event, void *event_data, void *userdata) result = mosquitto_property_add_string_pair( &ed->properties, MQTT_PROP_USER_PROPERTY, - "$client_id", + "$clientid", mosquitto_client_id(ed->client)); if (result != MOSQ_ERR_SUCCESS) return result; diff --git a/plugins/examples/connection-state/mosquitto_connection_state.c b/plugins/examples/connection-state/mosquitto_connection_state.c index 0778977e..0a00943a 100644 --- a/plugins/examples/connection-state/mosquitto_connection_state.c +++ b/plugins/examples/connection-state/mosquitto_connection_state.c @@ -52,15 +52,15 @@ static mosquitto_plugin_id_t *mosq_pid = NULL; static int connect_callback(int event, void *event_data, void *userdata) { struct mosquitto_evt_connect *ed = event_data; - const char *client_id; + const char *clientid; char topic[1024]; int len; UNUSED(event); UNUSED(userdata); - client_id = mosquitto_client_id(ed->client); - len = snprintf(topic, sizeof(topic), "$SYS/broker/connection/client/%s/state", client_id); + clientid = mosquitto_client_id(ed->client); + len = snprintf(topic, sizeof(topic), "$SYS/broker/connection/client/%s/state", clientid); if(len < (int)sizeof(topic)){ mosquitto_broker_publish_copy(NULL, topic, 1, "1", 0, true, NULL); }else{ @@ -73,7 +73,7 @@ static int connect_callback(int event, void *event_data, void *userdata) static int disconnect_callback(int event, void *event_data, void *userdata) { struct mosquitto_evt_disconnect *ed = event_data; - const char *client_id; + const char *clientid; char topic[1024]; int len; mosquitto_property *proplist = NULL; @@ -82,8 +82,8 @@ static int disconnect_callback(int event, void *event_data, void *userdata) UNUSED(event); UNUSED(userdata); - client_id = mosquitto_client_id(ed->client); - len = snprintf(topic, sizeof(topic), "$SYS/broker/connection/client/%s/state", client_id); + clientid = mosquitto_client_id(ed->client); + len = snprintf(topic, sizeof(topic), "$SYS/broker/connection/client/%s/state", clientid); if(len < (int)sizeof(topic)){ /* Expire our "disconnected" message after a day. */ rc = mosquitto_property_add_int32(&proplist, MQTT_PROP_MESSAGE_EXPIRY_INTERVAL, 86400); diff --git a/plugins/examples/topic-jail/mosquitto_topic_jail.c b/plugins/examples/topic-jail/mosquitto_topic_jail.c index 295b4c14..0b2928c5 100644 --- a/plugins/examples/topic-jail/mosquitto_topic_jail.c +++ b/plugins/examples/topic-jail/mosquitto_topic_jail.c @@ -78,17 +78,17 @@ static int callback_message_in(int event, void *event_data, void *userdata) UNUSED(event); UNUSED(userdata); - const char *client_id = mosquitto_client_id(ed->client); + const char *clientid = mosquitto_client_id(ed->client); - if(!is_jailed(client_id)){ + if(!is_jailed(clientid)){ /* will only modify the topic of jailed clients */ return MOSQ_ERR_SUCCESS; } - /* put the client_id on front of the topic */ + /* put the clientid on front of the topic */ /* calculate the length of the new payload */ - new_topic_len = strlen(client_id) + sizeof('/') + strlen(ed->topic) + 1; + new_topic_len = strlen(clientid) + sizeof('/') + strlen(ed->topic) + 1; /* Allocate some memory - use * mosquitto_calloc/mosquitto_malloc/mosquitto_strdup when allocating, to @@ -98,8 +98,8 @@ static int callback_message_in(int event, void *event_data, void *userdata) return MOSQ_ERR_NOMEM; } - /* prepend the client_id to the topic */ - snprintf(new_topic, new_topic_len, "%s/%s", client_id, ed->topic); + /* prepend the clientid to the topic */ + snprintf(new_topic, new_topic_len, "%s/%s", clientid, ed->topic); /* Assign the new topic to the event data structure. You * must *not* free the original topic, it will be handled by the @@ -112,34 +112,34 @@ static int callback_message_in(int event, void *event_data, void *userdata) static int callback_message_out(int event, void *event_data, void *userdata) { struct mosquitto_evt_message *ed = event_data; - size_t client_id_len; + size_t clientid_len; UNUSED(event); UNUSED(userdata); - const char *client_id = mosquitto_client_id(ed->client); + const char *clientid = mosquitto_client_id(ed->client); - if(!is_jailed(client_id)){ + if(!is_jailed(clientid)){ /* will only modify the topic of jailed clients */ return MOSQ_ERR_SUCCESS; } - /* remove the client_id from the front of the topic */ - client_id_len = strlen(client_id); + /* remove the clientid from the front of the topic */ + clientid_len = strlen(clientid); - if(strlen(ed->topic) <= client_id_len + 1){ + if(strlen(ed->topic) <= clientid_len + 1){ /* the topic is not long enough to contain the - * client_id + '/' */ + * clientid + '/' */ return MOSQ_ERR_SUCCESS; } - if(!strncmp(client_id, ed->topic, client_id_len) && ed->topic[client_id_len] == '/'){ + if(!strncmp(clientid, ed->topic, clientid_len) && ed->topic[clientid_len] == '/'){ /* Allocate some memory - use * mosquitto_calloc/mosquitto_malloc/mosquitto_strdup when allocating, to * allow the broker to track memory usage */ - /* skip the client_id + '/' */ - char *new_topic = mosquitto_strdup(ed->topic + client_id_len + 1); + /* skip the clientid + '/' */ + char *new_topic = mosquitto_strdup(ed->topic + clientid_len + 1); if(new_topic == NULL){ return MOSQ_ERR_NOMEM; @@ -163,17 +163,17 @@ static int callback_subscribe(int event, void *event_data, void *userdata) UNUSED(event); UNUSED(userdata); - const char *client_id = mosquitto_client_id(ed->client); + const char *clientid = mosquitto_client_id(ed->client); - if(!is_jailed(client_id)){ + if(!is_jailed(clientid)){ /* will only modify the topic of jailed clients */ return MOSQ_ERR_SUCCESS; } - /* put the client_id on front of the topic */ + /* put the clientid on front of the topic */ /* calculate the length of the new payload */ - new_sub_len = strlen(client_id) + sizeof('/') + strlen(ed->data.topic_filter) + 1; + new_sub_len = strlen(clientid) + sizeof('/') + strlen(ed->data.topic_filter) + 1; /* Allocate some memory - use * mosquitto_calloc/mosquitto_malloc/mosquitto_strdup when allocating, to @@ -183,8 +183,8 @@ static int callback_subscribe(int event, void *event_data, void *userdata) return MOSQ_ERR_NOMEM; } - /* prepend the client_id to the subscription */ - snprintf(new_sub, new_sub_len, "%s/%s", client_id, ed->data.topic_filter); + /* prepend the clientid to the subscription */ + snprintf(new_sub, new_sub_len, "%s/%s", clientid, ed->data.topic_filter); /* Assign the new topic to the event data structure. You * must *not* free the original topic, it will be handled by the @@ -203,17 +203,17 @@ static int callback_unsubscribe(int event, void *event_data, void *userdata) UNUSED(event); UNUSED(userdata); - const char *client_id = mosquitto_client_id(ed->client); + const char *clientid = mosquitto_client_id(ed->client); - if(!is_jailed(client_id)){ + if(!is_jailed(clientid)){ /* will only modify the topic of jailed clients */ return MOSQ_ERR_SUCCESS; } - /* put the client_id on front of the topic */ + /* put the clientid on front of the topic */ /* calculate the length of the new payload */ - new_sub_len = strlen(client_id) + sizeof('/') + strlen(ed->data.topic_filter) + 1; + new_sub_len = strlen(clientid) + sizeof('/') + strlen(ed->data.topic_filter) + 1; /* Allocate some memory - use * mosquitto_calloc/mosquitto_malloc/mosquitto_strdup when allocating, to @@ -223,8 +223,8 @@ static int callback_unsubscribe(int event, void *event_data, void *userdata) return MOSQ_ERR_NOMEM; } - /* prepend the client_id to the subscription */ - snprintf(new_sub, new_sub_len, "%s/%s", client_id, ed->data.topic_filter); + /* prepend the clientid to the subscription */ + snprintf(new_sub, new_sub_len, "%s/%s", clientid, ed->data.topic_filter); /* Assign the new topic to the event data structure. You * must *not* free the original topic, it will be handled by the diff --git a/plugins/persist-sqlite/client_msgs.c b/plugins/persist-sqlite/client_msgs.c index 08f55d3a..26cbd394 100644 --- a/plugins/persist-sqlite/client_msgs.c +++ b/plugins/persist-sqlite/client_msgs.c @@ -32,7 +32,7 @@ int persist_sqlite__client_msg_add_cb(int event, void *event_data, void *userdat UNUSED(event); - if(sqlite3_bind_text(ms->client_msg_add_stmt, 1, ed->data.client_id, (int)strlen(ed->data.client_id), SQLITE_STATIC) == SQLITE_OK + if(sqlite3_bind_text(ms->client_msg_add_stmt, 1, ed->data.clientid, (int)strlen(ed->data.clientid), SQLITE_STATIC) == SQLITE_OK && sqlite3_bind_int64(ms->client_msg_add_stmt, 2, (int64_t)ed->data.cmsg_id) == SQLITE_OK && sqlite3_bind_int64(ms->client_msg_add_stmt, 3, (int64_t)ed->data.store_id) == SQLITE_OK && sqlite3_bind_int(ms->client_msg_add_stmt, 4, ed->data.dup) == SQLITE_OK @@ -67,7 +67,7 @@ int persist_sqlite__client_msg_remove_cb(int event, void *event_data, void *user UNUSED(event); - if(sqlite3_bind_text(ms->client_msg_remove_stmt, 1, ed->data.client_id, (int)strlen(ed->data.client_id), SQLITE_STATIC) == SQLITE_OK + if(sqlite3_bind_text(ms->client_msg_remove_stmt, 1, ed->data.clientid, (int)strlen(ed->data.clientid), SQLITE_STATIC) == SQLITE_OK && sqlite3_bind_int64(ms->client_msg_remove_stmt, 2, (int64_t)ed->data.store_id) == SQLITE_OK && sqlite3_bind_int(ms->client_msg_remove_stmt, 3, ed->data.direction) == SQLITE_OK ){ @@ -96,7 +96,7 @@ int persist_sqlite__client_msg_update_cb(int event, void *event_data, void *user if(sqlite3_bind_int(ms->client_msg_update_stmt, 1, ed->data.state) == SQLITE_OK && sqlite3_bind_int(ms->client_msg_update_stmt, 2, ed->data.dup) == SQLITE_OK - && sqlite3_bind_text(ms->client_msg_update_stmt, 3, ed->data.client_id, (int)strlen(ed->data.client_id), SQLITE_STATIC) == SQLITE_OK + && sqlite3_bind_text(ms->client_msg_update_stmt, 3, ed->data.clientid, (int)strlen(ed->data.clientid), SQLITE_STATIC) == SQLITE_OK && sqlite3_bind_int64(ms->client_msg_update_stmt, 4, (int64_t)ed->data.store_id) == SQLITE_OK ){ @@ -114,11 +114,11 @@ int persist_sqlite__client_msg_update_cb(int event, void *event_data, void *user } -int persist_sqlite__client_msg_clear(struct mosquitto_sqlite *ms, const char *client_id) +int persist_sqlite__client_msg_clear(struct mosquitto_sqlite *ms, const char *clientid) { int rc = MOSQ_ERR_UNKNOWN; - if(sqlite3_bind_text(ms->client_msg_clear_all_stmt, 1, client_id, (int)strlen(client_id), SQLITE_STATIC) == SQLITE_OK){ + if(sqlite3_bind_text(ms->client_msg_clear_all_stmt, 1, clientid, (int)strlen(clientid), SQLITE_STATIC) == SQLITE_OK){ ms->event_count++; rc = sqlite3_step(ms->client_msg_clear_all_stmt); if(rc == SQLITE_DONE){ diff --git a/plugins/persist-sqlite/clients.c b/plugins/persist-sqlite/clients.c index c463a32b..4cd11baf 100644 --- a/plugins/persist-sqlite/clients.c +++ b/plugins/persist-sqlite/clients.c @@ -33,7 +33,7 @@ int persist_sqlite__client_add_cb(int event, void *event_data, void *userdata) UNUSED(event); if(sqlite3_bind_text(ms->client_add_stmt, 1, - ed->data.client_id, (int)strlen(ed->data.client_id), SQLITE_STATIC) == SQLITE_OK){ + ed->data.clientid, (int)strlen(ed->data.clientid), SQLITE_STATIC) == SQLITE_OK){ if(ed->data.username){ sqlite3_bind_text(ms->client_add_stmt, 2, @@ -78,7 +78,7 @@ int persist_sqlite__client_remove_cb(int event, void *event_data, void *userdata UNUSED(event); if(sqlite3_bind_text(ms->subscription_clear_stmt, 1, - ed->data.client_id, (int)strlen(ed->data.client_id), SQLITE_STATIC) == SQLITE_OK){ + ed->data.clientid, (int)strlen(ed->data.clientid), SQLITE_STATIC) == SQLITE_OK){ ms->event_count++; rc = sqlite3_step(ms->subscription_clear_stmt); @@ -90,7 +90,7 @@ int persist_sqlite__client_remove_cb(int event, void *event_data, void *userdata } } if(sqlite3_bind_text(ms->client_remove_stmt, 1, - ed->data.client_id, (int)strlen(ed->data.client_id), SQLITE_STATIC) == SQLITE_OK){ + ed->data.clientid, (int)strlen(ed->data.clientid), SQLITE_STATIC) == SQLITE_OK){ ms->event_count++; rc = sqlite3_step(ms->client_remove_stmt); @@ -101,7 +101,7 @@ int persist_sqlite__client_remove_cb(int event, void *event_data, void *userdata rc = MOSQ_ERR_UNKNOWN; } } - persist_sqlite__client_msg_clear(ms, ed->data.client_id); + persist_sqlite__client_msg_clear(ms, ed->data.clientid); return rc; } @@ -117,8 +117,8 @@ int persist_sqlite__client_update_cb(int event, void *event_data, void *userdata if(sqlite3_bind_int64(ms->client_update_stmt, 1, ed->data.session_expiry_time) == SQLITE_OK && sqlite3_bind_int64(ms->client_update_stmt, 2, ed->data.will_delay_time) == SQLITE_OK - && sqlite3_bind_text(ms->client_update_stmt, 3, ed->data.client_id, - (int)strlen(ed->data.client_id), SQLITE_STATIC) == SQLITE_OK + && sqlite3_bind_text(ms->client_update_stmt, 3, ed->data.clientid, + (int)strlen(ed->data.clientid), SQLITE_STATIC) == SQLITE_OK ){ ms->event_count++; diff --git a/plugins/persist-sqlite/persist_sqlite.h b/plugins/persist-sqlite/persist_sqlite.h index 35b88808..8c34ada1 100644 --- a/plugins/persist-sqlite/persist_sqlite.h +++ b/plugins/persist-sqlite/persist_sqlite.h @@ -61,7 +61,7 @@ int persist_sqlite__client_add_cb(int event, void *event_data, void *userdata); int persist_sqlite__client_update_cb(int event, void *event_data, void *userdata); int persist_sqlite__client_remove_cb(int event, void *event_data, void *userdata); int persist_sqlite__client_msg_add_cb(int event, void *event_data, void *userdata); -int persist_sqlite__client_msg_clear(struct mosquitto_sqlite *ms, const char *client_id); +int persist_sqlite__client_msg_clear(struct mosquitto_sqlite *ms, const char *clientid); int persist_sqlite__client_msg_remove_cb(int event, void *event_data, void *userdata); int persist_sqlite__client_msg_update_cb(int event, void *event_data, void *userdata); int persist_sqlite__base_msg_add_cb(int event, void *event_data, void *userdata); diff --git a/plugins/persist-sqlite/restore.c b/plugins/persist-sqlite/restore.c index 746cdae7..49ea80f7 100644 --- a/plugins/persist-sqlite/restore.c +++ b/plugins/persist-sqlite/restore.c @@ -201,7 +201,7 @@ static int client_restore(struct mosquitto_sqlite *ms) while(sqlite3_step(stmt) == SQLITE_ROW){ str = (const char *)sqlite3_column_text(stmt, 0); if(str){ - client.client_id = strdup(str); + client.clientid = strdup(str); } str = (const char *)sqlite3_column_text(stmt, 1); if(str){ @@ -250,7 +250,7 @@ static int subscription_restore(struct mosquitto_sqlite *ms) while(sqlite3_step(stmt) == SQLITE_ROW){ memset(&sub, 0, sizeof(sub)); - sub.client_id = (char *)sqlite3_column_text(stmt, 0); + sub.clientid = (char *)sqlite3_column_text(stmt, 0); sub.topic_filter = (char *)sqlite3_column_text(stmt, 1); sub.options = (uint8_t)sqlite3_column_int(stmt, 2); sub.identifier = (uint32_t)sqlite3_column_int(stmt, 3); @@ -355,7 +355,7 @@ static int client_msg_restore(struct mosquitto_sqlite *ms) memset(&client_msg, 0, sizeof(client_msg)); while(sqlite3_step(stmt) == SQLITE_ROW){ - client_msg.client_id = (const char *)sqlite3_column_text(stmt, 0); + client_msg.clientid = (const char *)sqlite3_column_text(stmt, 0); client_msg.cmsg_id = (uint64_t)sqlite3_column_int64(stmt, 1); client_msg.store_id = (uint64_t)sqlite3_column_int64(stmt, 2); client_msg.dup = sqlite3_column_int(stmt, 3); diff --git a/plugins/persist-sqlite/subscriptions.c b/plugins/persist-sqlite/subscriptions.c index f45f4af8..200d0686 100644 --- a/plugins/persist-sqlite/subscriptions.c +++ b/plugins/persist-sqlite/subscriptions.c @@ -32,7 +32,7 @@ int persist_sqlite__subscription_add_cb(int event, void *event_data, void *userd UNUSED(event); if(sqlite3_bind_text(ms->subscription_add_stmt, 1, - ed->data.client_id, (int)strlen(ed->data.client_id), SQLITE_STATIC) == SQLITE_OK){ + ed->data.clientid, (int)strlen(ed->data.clientid), SQLITE_STATIC) == SQLITE_OK){ if(sqlite3_bind_text(ms->subscription_add_stmt, 2, ed->data.topic_filter, (int)strlen(ed->data.topic_filter), SQLITE_STATIC) == SQLITE_OK){ @@ -68,7 +68,7 @@ int persist_sqlite__subscription_remove_cb(int event, void *event_data, void *us UNUSED(event); if(sqlite3_bind_text(ms->subscription_remove_stmt, 1, - ed->data.client_id, (int)strlen(ed->data.client_id), SQLITE_STATIC) == SQLITE_OK){ + ed->data.clientid, (int)strlen(ed->data.clientid), SQLITE_STATIC) == SQLITE_OK){ if(sqlite3_bind_text(ms->subscription_remove_stmt, 2, ed->data.topic_filter, (int)strlen(ed->data.topic_filter), SQLITE_STATIC) == SQLITE_OK){ diff --git a/src/handle_connect.c b/src/handle_connect.c index 4d37408f..49530472 100644 --- a/src/handle_connect.c +++ b/src/handle_connect.c @@ -48,9 +48,9 @@ static char nibble_to_hex(uint8_t value) } } -static char *client_id_gen(uint16_t *idlen, const char *auto_id_prefix, uint16_t auto_id_prefix_len) +static char *clientid_gen(uint16_t *idlen, const char *auto_id_prefix, uint16_t auto_id_prefix_len) { - char *client_id; + char *clientid; uint8_t rnd[16]; int i; int pos; @@ -59,26 +59,26 @@ static char *client_id_gen(uint16_t *idlen, const char *auto_id_prefix, uint16_t *idlen = (uint16_t)(auto_id_prefix_len + 36); - client_id = (char *)mosquitto__calloc((size_t)(*idlen) + 1, sizeof(char)); - if(!client_id){ + clientid = (char *)mosquitto__calloc((size_t)(*idlen) + 1, sizeof(char)); + if(!clientid){ return NULL; } if(auto_id_prefix){ - memcpy(client_id, auto_id_prefix, auto_id_prefix_len); + memcpy(clientid, auto_id_prefix, auto_id_prefix_len); } pos = 0; for(i=0; i<16; i++){ - client_id[auto_id_prefix_len + pos + 0] = nibble_to_hex(rnd[i] & 0x0F); - client_id[auto_id_prefix_len + pos + 1] = nibble_to_hex((rnd[i] >> 4) & 0x0F); + clientid[auto_id_prefix_len + pos + 0] = nibble_to_hex(rnd[i] & 0x0F); + clientid[auto_id_prefix_len + pos + 1] = nibble_to_hex((rnd[i] >> 4) & 0x0F); pos += 2; if(pos == 8 || pos == 13 || pos == 18 || pos == 23){ - client_id[auto_id_prefix_len + pos] = '-'; + clientid[auto_id_prefix_len + pos] = '-'; pos++; } } - return client_id; + return clientid; } /* Remove any queued messages that are no longer allowed through ACL, @@ -358,7 +358,7 @@ error: } -static int will__read(struct mosquitto *context, const char *client_id, struct mosquitto_message_all **will, uint8_t will_qos, int will_retain) +static int will__read(struct mosquitto *context, const char *clientid, struct mosquitto_message_all **will, uint8_t will_qos, int will_retain) { int rc = MOSQ_ERR_SUCCESS; size_t slen; @@ -412,7 +412,7 @@ static int will__read(struct mosquitto *context, const char *client_id, struct m will_struct->msg.payloadlen = payloadlen; if(will_struct->msg.payloadlen > 0){ if(db.config->message_size_limit && will_struct->msg.payloadlen > (int)db.config->message_size_limit){ - log__printf(NULL, MOSQ_LOG_DEBUG, "Client %s connected with too large Will payload", client_id); + log__printf(NULL, MOSQ_LOG_DEBUG, "Client %s connected with too large Will payload", clientid); if(context->protocol == mosq_p_mqtt5){ send__connack(context, 0, MQTT_RC_PACKET_TOO_LARGE, NULL); }else{ @@ -578,7 +578,7 @@ int handle__connect(struct mosquitto *context) char protocol_name[7]; uint8_t protocol_version; uint8_t connect_flags; - char *client_id = NULL; + char *clientid = NULL; struct mosquitto *found_context; struct mosquitto_message_all *will_struct = NULL; uint8_t will, will_retain, will_qos, clean_start; @@ -770,7 +770,7 @@ int handle__connect(struct mosquitto *context) } - if(packet__read_string(&context->in_packet, &client_id, &slen)){ + if(packet__read_string(&context->in_packet, &clientid, &slen)){ rc = MOSQ_ERR_PROTOCOL; goto handle_connect_error; } @@ -781,7 +781,7 @@ int handle__connect(struct mosquitto *context) rc = MOSQ_ERR_PROTOCOL; goto handle_connect_error; }else{ /* mqtt311/mqtt5 */ - mosquitto__FREE(client_id); + mosquitto__FREE(clientid); if(db.config->per_listener_settings){ allow_zero_length_clientid = context->listener->security_options->allow_zero_length_clientid; @@ -798,11 +798,11 @@ int handle__connect(struct mosquitto *context) goto handle_connect_error; }else{ if(db.config->per_listener_settings){ - client_id = client_id_gen(&slen, context->listener->security_options->auto_id_prefix, context->listener->security_options->auto_id_prefix_len); + clientid = clientid_gen(&slen, context->listener->security_options->auto_id_prefix, context->listener->security_options->auto_id_prefix_len); }else{ - client_id = client_id_gen(&slen, db.config->security_options.auto_id_prefix, db.config->security_options.auto_id_prefix_len); + clientid = clientid_gen(&slen, db.config->security_options.auto_id_prefix, db.config->security_options.auto_id_prefix_len); } - if(!client_id){ + if(!clientid){ rc = MOSQ_ERR_NOMEM; goto handle_connect_error; } @@ -813,7 +813,7 @@ int handle__connect(struct mosquitto *context) /* clientid_prefixes check */ if(db.config->clientid_prefixes){ - if(strncmp(db.config->clientid_prefixes, client_id, strlen(db.config->clientid_prefixes))){ + if(strncmp(db.config->clientid_prefixes, clientid, strlen(db.config->clientid_prefixes))){ if(context->protocol == mosq_p_mqtt5){ send__connack(context, 0, MQTT_RC_NOT_AUTHORIZED, NULL); }else{ @@ -825,14 +825,14 @@ int handle__connect(struct mosquitto *context) } /* Check for an existing delayed auth check, reject if present */ - HASH_FIND(hh_id, db.contexts_by_id_delayed_auth, client_id, strlen(client_id), found_context); + HASH_FIND(hh_id, db.contexts_by_id_delayed_auth, clientid, strlen(clientid), found_context); if(found_context){ rc = MOSQ_ERR_UNKNOWN; goto handle_connect_error; } if(will){ - rc = will__read(context, client_id, &will_struct, will_qos, will_retain); + rc = will__read(context, clientid, &will_struct, will_qos, will_retain); if(rc){ if(context->protocol == mosq_p_mqtt5){ if(rc == MOSQ_ERR_DUPLICATE_PROPERTY || rc == MOSQ_ERR_PROTOCOL){ @@ -870,7 +870,7 @@ int handle__connect(struct mosquitto *context) if(context->protocol == mosq_p_mqtt311 || context->protocol == mosq_p_mqtt31){ if(password_flag){ /* username_flag == 0 && password_flag == 1 is forbidden */ - log__printf(NULL, MOSQ_LOG_ERR, "Protocol error from %s: password without username, closing connection.", client_id); + log__printf(NULL, MOSQ_LOG_ERR, "Protocol error from %s: password without username, closing connection.", clientid); rc = MOSQ_ERR_PROTOCOL; goto handle_connect_error; } @@ -903,8 +903,8 @@ int handle__connect(struct mosquitto *context) /* Once context->id is set, if we return from this function with an error * we must make sure that context->id is freed and set to NULL, so that the * client isn't erroneously removed from the by_id hash table. */ - context->id = client_id; - client_id = NULL; + context->id = clientid; + clientid = NULL; #ifdef WITH_TLS if(context->listener->ssl_ctx && (context->listener->use_identity_as_username || context->listener->use_subject_as_username)){ @@ -943,7 +943,7 @@ int handle__connect(struct mosquitto *context) }else #endif /* WITH_TLS */ { - /* FIXME - these ensure the mosquitto_client_id() and + /* FIXME - these ensure the mosquitto_clientid() and * mosquitto_client_username() functions work, but is hacky */ context->username = username; context->password = password; @@ -1052,7 +1052,7 @@ int handle__connect(struct mosquitto *context) handle_connect_error: mosquitto__FREE(auth_data); - mosquitto__FREE(client_id); + mosquitto__FREE(clientid); mosquitto__FREE(username); mosquitto__FREE(password); if(will_struct){ diff --git a/src/persist.h b/src/persist.h index 3f00cdc0..f77dfce9 100644 --- a/src/persist.h +++ b/src/persist.h @@ -81,7 +81,7 @@ struct PF_client{ }; struct P_client{ struct PF_client F; - char *client_id; + char *clientid; char *username; }; @@ -97,7 +97,7 @@ struct PF_client_msg{ }; struct P_client_msg{ struct PF_client_msg F; - char *client_id; + char *clientid; uint32_t subscription_identifier; }; @@ -132,7 +132,7 @@ struct PF_sub{ }; struct P_sub{ struct PF_sub F; - char *client_id; + char *clientid; char *topic; }; diff --git a/src/persist_read.c b/src/persist_read.c index 668f1db1..e3c0e581 100644 --- a/src/persist_read.c +++ b/src/persist_read.c @@ -50,18 +50,18 @@ static long client_msg_count = 0; static int persist__restore_sub(const struct mosquitto_subscription *sub); -static struct mosquitto *persist__find_or_add_context(const char *client_id, uint16_t last_mid) +static struct mosquitto *persist__find_or_add_context(const char *clientid, uint16_t last_mid) { struct mosquitto *context; - if(!client_id) return NULL; + if(!clientid) return NULL; context = NULL; - HASH_FIND(hh_id, db.contexts_by_id, client_id, strlen(client_id), context); + HASH_FIND(hh_id, db.contexts_by_id, clientid, strlen(clientid), context); if(!context){ context = context__init(); if(!context) return NULL; - context->id = mosquitto__strdup(client_id); + context->id = mosquitto__strdup(clientid); if(!context->id){ mosquitto__FREE(context); return NULL; @@ -127,7 +127,7 @@ static int persist__client_msg_restore(struct P_client_msg *chunk) return MOSQ_ERR_SUCCESS; } - context = persist__find_or_add_context(chunk->client_id, 0); + context = persist__find_or_add_context(chunk->clientid, 0); if(!context){ log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Persistence file contains client message with no matching client. File may be corrupt."); return 0; @@ -195,7 +195,7 @@ static int persist__client_chunk_restore(FILE *db_fptr) return MOSQ_ERR_SUCCESS; } - context = persist__find_or_add_context(chunk.client_id, chunk.F.last_mid); + context = persist__find_or_add_context(chunk.clientid, chunk.F.last_mid); if(context){ context->session_expiry_time = chunk.F.session_expiry_time; context->session_expiry_interval = chunk.F.session_expiry_interval; @@ -218,7 +218,7 @@ static int persist__client_chunk_restore(FILE *db_fptr) rc = 1; } - mosquitto__FREE(chunk.client_id); + mosquitto__FREE(chunk.clientid); mosquitto__FREE(chunk.username); if(rc == 0) client_count++; return rc; @@ -242,7 +242,7 @@ static int persist__client_msg_chunk_restore(FILE *db_fptr, uint32_t length) } rc = persist__client_msg_restore(&chunk); - mosquitto__FREE(chunk.client_id); + mosquitto__FREE(chunk.clientid); if(rc == 0) client_msg_count++; return rc; @@ -375,13 +375,13 @@ static int persist__sub_chunk_restore(FILE *db_fptr) return rc; } - sub.client_id = chunk.client_id; + sub.clientid = chunk.clientid; sub.topic_filter = chunk.topic; sub.options = chunk.F.qos | chunk.F.options; sub.identifier = chunk.F.identifier; rc = persist__restore_sub(&sub); - mosquitto__FREE(chunk.client_id); + mosquitto__FREE(chunk.clientid); mosquitto__FREE(chunk.topic); if(rc == 0) subscription_count++; @@ -547,10 +547,10 @@ static int persist__restore_sub(const struct mosquitto_subscription *sub) struct mosquitto *context; assert(sub); - assert(sub->client_id); + assert(sub->clientid); assert(sub->topic_filter); - context = persist__find_or_add_context(sub->client_id, 0); + context = persist__find_or_add_context(sub->clientid, 0); if(!context) return 1; return sub__add(context, sub); } diff --git a/src/persist_read_v234.c b/src/persist_read_v234.c index 217f1a43..82b7acb9 100644 --- a/src/persist_read_v234.c +++ b/src/persist_read_v234.c @@ -76,7 +76,7 @@ int persist__chunk_client_read_v234(FILE *db_fptr, struct P_client *chunk, uint3 int rc; time_t temp; - rc = persist__read_string(db_fptr, &chunk->client_id); + rc = persist__read_string(db_fptr, &chunk->clientid); if(rc){ return rc; } @@ -90,7 +90,7 @@ int persist__chunk_client_read_v234(FILE *db_fptr, struct P_client *chunk, uint3 return MOSQ_ERR_SUCCESS; error: log__printf(NULL, MOSQ_LOG_ERR, "Error: %s.", strerror(errno)); - mosquitto__FREE(chunk->client_id); + mosquitto__FREE(chunk->clientid); return 1; } @@ -101,7 +101,7 @@ int persist__chunk_client_msg_read_v234(FILE *db_fptr, struct P_client_msg *chun int rc; uint8_t retain, dup; - rc = persist__read_string(db_fptr, &chunk->client_id); + rc = persist__read_string(db_fptr, &chunk->clientid); if(rc){ return rc; } @@ -122,7 +122,7 @@ int persist__chunk_client_msg_read_v234(FILE *db_fptr, struct P_client_msg *chun return MOSQ_ERR_SUCCESS; error: log__printf(NULL, MOSQ_LOG_ERR, "Error: %s.", strerror(errno)); - mosquitto__FREE(chunk->client_id); + mosquitto__FREE(chunk->clientid); return 1; } @@ -198,7 +198,7 @@ int persist__chunk_sub_read_v234(FILE *db_fptr, struct P_sub *chunk) { int rc; - rc = persist__read_string(db_fptr, &chunk->client_id); + rc = persist__read_string(db_fptr, &chunk->clientid); if(rc) goto error; rc = persist__read_string(db_fptr, &chunk->topic); @@ -208,7 +208,7 @@ int persist__chunk_sub_read_v234(FILE *db_fptr, struct P_sub *chunk) return MOSQ_ERR_SUCCESS; error: - mosquitto__FREE(chunk->client_id); + mosquitto__FREE(chunk->clientid); mosquitto__FREE(chunk->topic); return rc; } diff --git a/src/persist_read_v5.c b/src/persist_read_v5.c index 4f724384..4e3e3f8e 100644 --- a/src/persist_read_v5.c +++ b/src/persist_read_v5.c @@ -85,17 +85,17 @@ int persist__chunk_client_read_v56(FILE *db_fptr, struct P_client *chunk, uint32 chunk->F.id_len = ntohs(chunk->F.id_len); - rc = persist__read_string_len(db_fptr, &chunk->client_id, chunk->F.id_len); + rc = persist__read_string_len(db_fptr, &chunk->clientid, chunk->F.id_len); if(rc){ return 1; - }else if(chunk->client_id == NULL){ + }else if(chunk->clientid == NULL){ return -1; } if(chunk->F.username_len > 0){ rc = persist__read_string_len(db_fptr, &chunk->username, chunk->F.username_len); if(rc || !chunk->username){ - mosquitto__FREE(chunk->client_id); + mosquitto__FREE(chunk->clientid); return 1; } } @@ -119,7 +119,7 @@ int persist__chunk_client_msg_read_v56(FILE *db_fptr, struct P_client_msg *chunk length -= (uint32_t)(sizeof(struct PF_client_msg) + chunk->F.id_len); - rc = persist__read_string_len(db_fptr, &chunk->client_id, chunk->F.id_len); + rc = persist__read_string_len(db_fptr, &chunk->clientid, chunk->F.id_len); if(rc) return rc; if(length > 0){ @@ -241,7 +241,7 @@ int persist__chunk_sub_read_v56(FILE *db_fptr, struct P_sub *chunk) chunk->F.id_len = ntohs(chunk->F.id_len); chunk->F.topic_len = ntohs(chunk->F.topic_len); - rc = persist__read_string_len(db_fptr, &chunk->client_id, chunk->F.id_len); + rc = persist__read_string_len(db_fptr, &chunk->clientid, chunk->F.id_len); if(rc) goto error; rc = persist__read_string_len(db_fptr, &chunk->topic, chunk->F.topic_len); @@ -249,7 +249,7 @@ int persist__chunk_sub_read_v56(FILE *db_fptr, struct P_sub *chunk) return MOSQ_ERR_SUCCESS; error: - mosquitto__FREE(chunk->client_id); + mosquitto__FREE(chunk->clientid); return rc; } diff --git a/src/persist_write.c b/src/persist_write.c index a4c29089..5773dfab 100644 --- a/src/persist_write.c +++ b/src/persist_write.c @@ -68,7 +68,7 @@ static int persist__client_messages_save(FILE *db_fptr, struct mosquitto *contex chunk.F.retain_dup = (uint8_t)((cmsg->data.retain&0x0F)<<4 | (cmsg->data.dup&0x0F)); chunk.F.direction = (uint8_t)cmsg->data.direction; chunk.F.state = (uint8_t)cmsg->data.state; - chunk.client_id = context->id; + chunk.clientid = context->id; chunk.subscription_identifier = cmsg->data.subscription_identifier; rc = persist__chunk_client_msg_write_v6(db_fptr, &chunk); @@ -178,7 +178,7 @@ static int persist__client_save(FILE *db_fptr) chunk.F.session_expiry_interval = context->session_expiry_interval; chunk.F.last_mid = context->last_mid; chunk.F.id_len = (uint16_t)strlen(context->id); - chunk.client_id = context->id; + chunk.clientid = context->id; if(context->username){ chunk.F.username_len = (uint16_t)strlen(context->username); chunk.username = context->username; @@ -237,7 +237,7 @@ static int persist__subs_save(FILE *db_fptr, struct mosquitto__subhier *node, co sub_chunk.F.topic_len = (uint16_t)strlen(thistopic); sub_chunk.F.qos = MQTT_SUB_OPT_GET_QOS(sub->subscription_options); sub_chunk.F.options = sub->subscription_options & 0xFC; - sub_chunk.client_id = sub->context->id; + sub_chunk.clientid = sub->context->id; sub_chunk.topic = thistopic; rc = persist__chunk_sub_write_v6(db_fptr, &sub_chunk); diff --git a/src/persist_write_v5.c b/src/persist_write_v5.c index b459553d..a7f68e15 100644 --- a/src/persist_write_v5.c +++ b/src/persist_write_v5.c @@ -74,7 +74,7 @@ int persist__chunk_client_write_v6(FILE *db_fptr, struct P_client *chunk) write_e(db_fptr, &header, sizeof(struct PF_header)); write_e(db_fptr, &chunk->F, sizeof(struct PF_client)); - write_e(db_fptr, chunk->client_id, id_len); + write_e(db_fptr, chunk->clientid, id_len); if(username_len > 0){ write_e(db_fptr, chunk->username, username_len); } @@ -113,7 +113,7 @@ int persist__chunk_client_msg_write_v6(FILE *db_fptr, struct P_client_msg *chunk write_e(db_fptr, &header, sizeof(struct PF_header)); write_e(db_fptr, &chunk->F, sizeof(struct PF_client_msg)); - write_e(db_fptr, chunk->client_id, id_len); + write_e(db_fptr, chunk->clientid, id_len); if(chunk->subscription_identifier){ if(proplen > 0){ prop_packet = calloc(1, sizeof(struct mosquitto__packet)+proplen); @@ -241,7 +241,7 @@ int persist__chunk_sub_write_v6(FILE *db_fptr, struct P_sub *chunk) write_e(db_fptr, &header, sizeof(struct PF_header)); write_e(db_fptr, &chunk->F, sizeof(struct PF_sub)); - write_e(db_fptr, chunk->client_id, id_len); + write_e(db_fptr, chunk->clientid, id_len); write_e(db_fptr, chunk->topic, topic_len); return MOSQ_ERR_SUCCESS; diff --git a/src/plugin_persist.c b/src/plugin_persist.c index 382e5fa3..53ab5bcf 100644 --- a/src/plugin_persist.c +++ b/src/plugin_persist.c @@ -59,7 +59,7 @@ void plugin_persist__handle_client_add(struct mosquitto *context) opts = &db.config->security_options; memset(&event_data, 0, sizeof(event_data)); - event_data.data.client_id = context->id; + event_data.data.clientid = context->id; event_data.data.username = context->username; event_data.data.auth_method = context->auth_method; event_data.data.will_delay_time = context->will_delay_time; @@ -95,7 +95,7 @@ void plugin_persist__handle_client_update(struct mosquitto *context) opts = &db.config->security_options; memset(&event_data, 0, sizeof(event_data)); - event_data.data.client_id = context->id; + event_data.data.clientid = context->id; event_data.data.username = context->username; event_data.data.auth_method = context->auth_method; event_data.data.will_delay_time = context->will_delay_time; @@ -133,7 +133,7 @@ void plugin_persist__handle_client_delete(struct mosquitto *context) } opts = &db.config->security_options; memset(&event_data, 0, sizeof(event_data)); - event_data.data.client_id = context->id; + event_data.data.clientid = context->id; DL_FOREACH(opts->plugin_callbacks.persist_client_delete, cb_base){ cb_base->cb(MOSQ_EVT_PERSIST_CLIENT_DELETE, &event_data, cb_base->userdata); @@ -152,7 +152,7 @@ void plugin_persist__handle_subscription_add(struct mosquitto *context, const st opts = &db.config->security_options; memset(&event_data, 0, sizeof(event_data)); - event_data.data.client_id = context->id; + event_data.data.clientid = context->id; event_data.data.topic_filter = sub->topic_filter; event_data.data.identifier = sub->identifier; event_data.data.options = sub->options; @@ -174,7 +174,7 @@ void plugin_persist__handle_subscription_delete(struct mosquitto *context, char opts = &db.config->security_options; memset(&event_data, 0, sizeof(event_data)); - event_data.data.client_id = context->id; + event_data.data.clientid = context->id; event_data.data.topic_filter = sub; DL_FOREACH(opts->plugin_callbacks.persist_subscription_delete, cb_base){ @@ -199,7 +199,7 @@ void plugin_persist__handle_client_msg_add(struct mosquitto *context, const stru opts = &db.config->security_options; memset(&event_data, 0, sizeof(event_data)); - event_data.data.client_id = context->id; + event_data.data.clientid = context->id; event_data.data.cmsg_id = client_msg->data.cmsg_id; event_data.data.store_id = client_msg->base_msg->data.store_id; event_data.data.mid = client_msg->data.mid; @@ -231,7 +231,7 @@ void plugin_persist__handle_client_msg_delete(struct mosquitto *context, const s opts = &db.config->security_options; memset(&event_data, 0, sizeof(event_data)); - event_data.data.client_id = context->id; + event_data.data.clientid = context->id; event_data.data.cmsg_id = client_msg->data.cmsg_id; event_data.data.mid = client_msg->data.mid; event_data.data.state = (uint8_t)client_msg->data.state; @@ -261,7 +261,7 @@ void plugin_persist__handle_client_msg_update(struct mosquitto *context, const s opts = &db.config->security_options; memset(&event_data, 0, sizeof(event_data)); - event_data.data.client_id = context->id; + event_data.data.clientid = context->id; event_data.data.cmsg_id = client_msg->data.cmsg_id; event_data.data.mid = client_msg->data.mid; event_data.data.store_id = client_msg->base_msg->data.store_id; diff --git a/src/plugin_public.c b/src/plugin_public.c index 6eb110f2..726933ba 100644 --- a/src/plugin_public.c +++ b/src/plugin_public.c @@ -60,16 +60,16 @@ BROKER_EXPORT const char *mosquitto_client_address(const struct mosquitto *clien } -BROKER_EXPORT struct mosquitto *mosquitto_client(const char *client_id) +BROKER_EXPORT struct mosquitto *mosquitto_client(const char *clientid) { size_t len; struct mosquitto *context; - if(!client_id) return NULL; - len = strlen(client_id); + if(!clientid) return NULL; + len = strlen(clientid); if(len == 0) return NULL; - HASH_FIND(hh_id, db.contexts_by_id, client_id, strlen(client_id), context); + HASH_FIND(hh_id, db.contexts_by_id, clientid, strlen(clientid), context); return context; } @@ -470,13 +470,13 @@ BROKER_EXPORT int mosquitto_persist_client_add(struct mosquitto_client *client) if(client == NULL){ return MOSQ_ERR_INVAL; } - if(client->client_id == NULL){ + if(client->clientid == NULL){ rc = MOSQ_ERR_INVAL; goto error; } context = NULL; - HASH_FIND(hh_id, db.contexts_by_id, client->client_id, strlen(client->client_id), context); + HASH_FIND(hh_id, db.contexts_by_id, client->clientid, strlen(client->clientid), context); if(context){ rc = MOSQ_ERR_INVAL; goto error; @@ -488,8 +488,8 @@ BROKER_EXPORT int mosquitto_persist_client_add(struct mosquitto_client *client) goto error; } - context->id = client->client_id; - client->client_id = NULL; + context->id = client->clientid; + client->clientid = NULL; context->username = client->username; client->username = NULL; context->auth_method = client->auth_method; @@ -519,7 +519,7 @@ BROKER_EXPORT int mosquitto_persist_client_add(struct mosquitto_client *client) return MOSQ_ERR_SUCCESS; error: - SAFE_FREE(client->client_id); + SAFE_FREE(client->clientid); SAFE_FREE(client->username); SAFE_FREE(client->auth_method); return rc; @@ -535,13 +535,13 @@ BROKER_EXPORT int mosquitto_persist_client_update(struct mosquitto_client *clien if(client == NULL){ return MOSQ_ERR_INVAL; } - if(client->client_id == NULL){ + if(client->clientid == NULL){ rc = MOSQ_ERR_INVAL; goto error; } context = NULL; - HASH_FIND(hh_id, db.contexts_by_id, client->client_id, strlen(client->client_id), context); + HASH_FIND(hh_id, db.contexts_by_id, client->clientid, strlen(client->clientid), context); if(context == NULL){ rc = MOSQ_ERR_NOT_FOUND; goto error; @@ -577,14 +577,14 @@ error: } -BROKER_EXPORT int mosquitto_persist_client_delete(const char *client_id) +BROKER_EXPORT int mosquitto_persist_client_delete(const char *clientid) { struct mosquitto *context; - if(client_id == NULL) return MOSQ_ERR_INVAL; + if(clientid == NULL) return MOSQ_ERR_INVAL; context = NULL; - HASH_FIND(hh_id, db.contexts_by_id, client_id, strlen(client_id), context); + HASH_FIND(hh_id, db.contexts_by_id, clientid, strlen(clientid), context); if(context == NULL){ return MOSQ_ERR_SUCCESS; } @@ -616,11 +616,11 @@ BROKER_EXPORT int mosquitto_persist_client_msg_add(struct mosquitto_client_msg * struct mosquitto *context; struct mosquitto__base_msg *base_msg; - if(client_msg == NULL || client_msg->client_id == NULL){ + if(client_msg == NULL || client_msg->clientid == NULL){ return MOSQ_ERR_INVAL; } - HASH_FIND(hh_id, db.contexts_by_id, client_msg->client_id, strlen(client_msg->client_id), context); + HASH_FIND(hh_id, db.contexts_by_id, client_msg->clientid, strlen(client_msg->clientid), context); if(context == NULL){ return MOSQ_ERR_NOT_FOUND; } @@ -649,9 +649,9 @@ BROKER_EXPORT int mosquitto_persist_client_msg_delete(struct mosquitto_client_ms { struct mosquitto *context; - if(client_msg == NULL || client_msg->client_id == NULL) return MOSQ_ERR_INVAL; + if(client_msg == NULL || client_msg->clientid == NULL) return MOSQ_ERR_INVAL; - HASH_FIND(hh_id, db.contexts_by_id, client_msg->client_id, strlen(client_msg->client_id), context); + HASH_FIND(hh_id, db.contexts_by_id, client_msg->clientid, strlen(client_msg->clientid), context); if(context == NULL){ return MOSQ_ERR_NOT_FOUND; } @@ -671,9 +671,9 @@ BROKER_EXPORT int mosquitto_persist_client_msg_update(struct mosquitto_client_ms { struct mosquitto *context; - if(client_msg == NULL || client_msg->client_id == NULL) return MOSQ_ERR_INVAL; + if(client_msg == NULL || client_msg->clientid == NULL) return MOSQ_ERR_INVAL; - HASH_FIND(hh_id, db.contexts_by_id, client_msg->client_id, strlen(client_msg->client_id), context); + HASH_FIND(hh_id, db.contexts_by_id, client_msg->clientid, strlen(client_msg->clientid), context); if(context == NULL){ return MOSQ_ERR_NOT_FOUND; } @@ -693,9 +693,9 @@ BROKER_EXPORT int mosquitto_persist_client_msg_clear(struct mosquitto_client_msg { struct mosquitto *context; - if(client_msg == NULL || client_msg->client_id == NULL) return MOSQ_ERR_INVAL; + if(client_msg == NULL || client_msg->clientid == NULL) return MOSQ_ERR_INVAL; - HASH_FIND(hh_id, db.contexts_by_id, client_msg->client_id, strlen(client_msg->client_id), context); + HASH_FIND(hh_id, db.contexts_by_id, client_msg->clientid, strlen(client_msg->clientid), context); if(context == NULL){ return MOSQ_ERR_NOT_FOUND; } @@ -713,11 +713,11 @@ BROKER_EXPORT int mosquitto_subscription_add(const struct mosquitto_subscription { struct mosquitto *context; - if(sub == NULL || sub->client_id == NULL || sub->topic_filter == NULL || sub->client_id[0] == '\0' || sub->topic_filter[0] == '\0'){ + if(sub == NULL || sub->clientid == NULL || sub->topic_filter == NULL || sub->clientid[0] == '\0' || sub->topic_filter[0] == '\0'){ return MOSQ_ERR_INVAL; } - HASH_FIND(hh_id, db.contexts_by_id, sub->client_id, strlen(sub->client_id), context); + HASH_FIND(hh_id, db.contexts_by_id, sub->clientid, strlen(sub->clientid), context); if(context){ return sub__add(context, sub); @@ -727,16 +727,16 @@ BROKER_EXPORT int mosquitto_subscription_add(const struct mosquitto_subscription } -BROKER_EXPORT int mosquitto_subscription_delete(const char *client_id, const char *topic) +BROKER_EXPORT int mosquitto_subscription_delete(const char *clientid, const char *topic) { struct mosquitto *context; uint8_t reason; - if(client_id == NULL || topic == NULL || client_id[0] == '\0' || topic[0] == '\0'){ + if(clientid == NULL || topic == NULL || clientid[0] == '\0' || topic[0] == '\0'){ return MOSQ_ERR_INVAL; } - HASH_FIND(hh_id, db.contexts_by_id, client_id, strlen(client_id), context); + HASH_FIND(hh_id, db.contexts_by_id, clientid, strlen(clientid), context); if(context){ return sub__remove(context, topic, &reason); @@ -836,13 +836,13 @@ BROKER_EXPORT int mosquitto_persist_base_msg_delete(uint64_t store_id) } -BROKER_EXPORT void mosquitto_complete_basic_auth(const char *client_id, int result) +BROKER_EXPORT void mosquitto_complete_basic_auth(const char *clientid, int result) { struct mosquitto *context; - if(client_id == NULL) return; + if(clientid == NULL) return; - HASH_FIND(hh_id, db.contexts_by_id_delayed_auth, client_id, strlen(client_id), context); + HASH_FIND(hh_id, db.contexts_by_id_delayed_auth, clientid, strlen(clientid), context); if(context){ HASH_DELETE(hh_id, db.contexts_by_id_delayed_auth, context); if(result == MOSQ_ERR_SUCCESS){ diff --git a/test/broker/c/auth_plugin_context_params.c b/test/broker/c/auth_plugin_context_params.c index 5c415d76..611e3f05 100644 --- a/test/broker/c/auth_plugin_context_params.c +++ b/test/broker/c/auth_plugin_context_params.c @@ -78,7 +78,7 @@ int mosquitto_auth_unpwd_check(void *user_data, struct mosquitto *client, const tmp = mosquitto_client_id(client); if(!tmp || strcmp(tmp, "client-params-test")){ - fprintf(stderr, "mosquitto_auth_unpwd_check client_id error: %s\n", tmp); + fprintf(stderr, "mosquitto_auth_unpwd_check clientid error: %s\n", tmp); return MOSQ_ERR_AUTH; } diff --git a/test/broker/c/auth_plugin_delayed.c b/test/broker/c/auth_plugin_delayed.c index 5b68f207..76f07580 100644 --- a/test/broker/c/auth_plugin_delayed.c +++ b/test/broker/c/auth_plugin_delayed.c @@ -12,7 +12,7 @@ static mosquitto_plugin_id_t *plg_id; static char *username = NULL; static char *password = NULL; -static char *client_id = NULL; +static char *clientid = NULL; static int auth_delay = -1; MOSQUITTO_PLUGIN_DECLARE_VERSION(5); @@ -39,7 +39,7 @@ int mosquitto_plugin_cleanup(void *user_data, struct mosquitto_opt *auth_opts, i free(username); free(password); - free(client_id); + free(clientid); mosquitto_callback_unregister(plg_id, MOSQ_EVT_BASIC_AUTH, unpwd_check_callback, NULL); mosquitto_callback_unregister(plg_id, MOSQ_EVT_TICK, tick_callback, NULL); @@ -58,19 +58,19 @@ static int tick_callback(int event, void *event_data, void *user_data) } if(auth_delay == 0){ - if(client_id && username && password + if(clientid && username && password && !strcmp(username, "delayed-username") && !strcmp(password, "good")){ - mosquitto_complete_basic_auth(client_id, MOSQ_ERR_SUCCESS); + mosquitto_complete_basic_auth(clientid, MOSQ_ERR_SUCCESS); }else{ - mosquitto_complete_basic_auth(client_id, MOSQ_ERR_AUTH); + mosquitto_complete_basic_auth(clientid, MOSQ_ERR_AUTH); } free(username); free(password); - free(client_id); + free(clientid); username = NULL; password = NULL; - client_id = NULL; + clientid = NULL; }else if(auth_delay > 0){ auth_delay--; } @@ -90,7 +90,7 @@ static int unpwd_check_callback(int event, void *event_data, void *user_data) free(username); free(password); - free(client_id); + free(clientid); if(ed->username){ username = strdup(ed->username); @@ -98,7 +98,7 @@ static int unpwd_check_callback(int event, void *event_data, void *user_data) if(ed->password){ password = strdup(ed->password); } - client_id = strdup(mosquitto_client_id(ed->client)); + clientid = strdup(mosquitto_client_id(ed->client)); /* Delay for arbitrary 10 ticks */ auth_delay = 10;