mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-09-26 03:43:47 +08:00
client_id -> clientid rename.
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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){
|
||||
|
||||
@@ -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++;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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){
|
||||
|
||||
Reference in New Issue
Block a user