From 883fdb2ad28e60a1c907f5a32e8d773662eb176c Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 16 Sep 2025 23:19:44 +0100 Subject: [PATCH] Formatting: Double indent continuation --- apps/mosquitto_ctrl/client.c | 4 +- apps/mosquitto_ctrl/ctrl_shell.c | 8 +- client/client_shared.c | 4 +- lib/http_client.c | 16 +- lib/net_mosq_ocsp.c | 4 +- lib/util_mosq.c | 4 +- libcommon/cjson_common.c | 6 +- libcommon/file_common.c | 8 +- libcommon/password_common.c | 5 +- plugins/dynamic-security/config_init.c | 24 +-- plugins/dynamic-security/default_acl.c | 2 +- .../add-properties/mosquitto_add_properties.c | 24 +-- plugins/persist-sqlite/clients.c | 8 +- plugins/persist-sqlite/init.c | 171 +++++++++--------- plugins/persist-sqlite/restore.c | 10 +- plugins/persist-sqlite/retain_msgs.c | 2 +- plugins/persist-sqlite/subscriptions.c | 12 +- plugins/persist-sqlite/will.c | 14 +- src/bridge.c | 24 ++- src/context.c | 16 +- src/database.c | 8 +- src/handle_auth.c | 2 +- src/handle_connack.c | 10 +- src/handle_connect.c | 25 +-- src/handle_publish.c | 6 +- src/handle_subscribe.c | 2 +- src/net.c | 10 +- src/persist_write_v5.c | 5 +- src/plugin_basic_auth.c | 4 +- src/plugin_callbacks.c | 2 +- src/plugin_message.c | 4 +- src/plugin_persist.c | 4 +- src/plugin_tick.c | 2 +- src/service.c | 2 +- src/sys_tree.c | 2 +- src/websockets.c | 22 +-- test/broker/c/auth_plugin_delayed.c | 2 +- test/unit/lib/property_read.c | 49 +++-- test/unit/libcommon/strings_test.c | 14 +- 39 files changed, 284 insertions(+), 257 deletions(-) diff --git a/apps/mosquitto_ctrl/client.c b/apps/mosquitto_ctrl/client.c index 2e857693..45c0757b 100644 --- a/apps/mosquitto_ctrl/client.c +++ b/apps/mosquitto_ctrl/client.c @@ -130,9 +130,9 @@ int client_request_response(struct mosq_ctrl *ctrl) if(ctrl->cfg.cafile == NULL && ctrl->cfg.capath == NULL && !ctrl->cfg.tls_use_os_certs && ctrl->cfg.port != 8883 # ifdef FINAL_WITH_TLS_PSK - && !ctrl->cfg.psk + && !ctrl->cfg.psk # endif - ){ + ){ fprintf(stderr, "Warning: You are running mosquitto_ctrl without encryption.\nThis means all of the configuration changes you are making are visible on the network, including passwords.\n\n"); } diff --git a/apps/mosquitto_ctrl/ctrl_shell.c b/apps/mosquitto_ctrl/ctrl_shell.c index 99b19a13..d8eedc4e 100644 --- a/apps/mosquitto_ctrl/ctrl_shell.c +++ b/apps/mosquitto_ctrl/ctrl_shell.c @@ -62,8 +62,8 @@ const char ANSI_MODULE_dark[] = "\001\e[38;5;214m\002"; const char ANSI_INPUT_dark[] = "\001\e[38;5;80m\002"; const char ANSI_ERROR_dark[] = "\001\e[38;5;198m\002"; const char *ANSI_LABEL_dark[] = { - "\001\e[38;5;207m\002", - "\001\e[38;5;219m\002", + "\001\e[38;5;207m\002", + "\001\e[38;5;219m\002", }; const char ANSI_TOPIC_dark[] = "\001\e[93m\002"; const char ANSI_POSITIVE_dark[] = "\001\e[92m\002"; @@ -74,8 +74,8 @@ const char ANSI_MODULE_light[] = "\001\e[38;5;130m\002"; const char ANSI_INPUT_light[] = "\001\e[38;5;27m\002"; const char ANSI_ERROR_light[] = "\001\e[38;5;196m\002"; const char *ANSI_LABEL_light[] = { - "\001\e[38;5;165m\002", - "\001\e[38;5;171m\002", + "\001\e[38;5;165m\002", + "\001\e[38;5;171m\002", }; const char ANSI_TOPIC_light[] = "\001\e[33m\002"; const char ANSI_POSITIVE_light[] = "\001\e[32m\002"; diff --git a/client/client_shared.c b/client/client_shared.c index 651ffe1d..0252ebc5 100644 --- a/client/client_shared.c +++ b/client/client_shared.c @@ -1424,8 +1424,8 @@ int client_opts_set(struct mosquitto *mosq, struct mosq_config *cfg) mosquitto_int_option(mosq, MOSQ_OPT_TRANSPORT, cfg->transport); if(cfg->will_topic && mosquitto_will_set_v5(mosq, cfg->will_topic, - cfg->will_payloadlen, cfg->will_payload, cfg->will_qos, - cfg->will_retain, cfg->will_props)){ + cfg->will_payloadlen, cfg->will_payload, cfg->will_qos, + cfg->will_retain, cfg->will_props)){ err_printf(cfg, "Error: Problem setting will.\n"); return 1; diff --git a/lib/http_client.c b/lib/http_client.c index bd79953c..583dac1b 100644 --- a/lib/http_client.c +++ b/lib/http_client.c @@ -68,14 +68,14 @@ int http_c__context_init(struct mosquitto *context) path = context->wsd.http_path?context->wsd.http_path:"/mqtt"; packet->packet_length = (uint32_t )snprintf((char *)&packet->payload[WS_PACKET_OFFSET], 1024, - "GET %s HTTP/1.1\r\n" - "Host: %s\r\n" - "Upgrade: websocket\r\n" - "Connection: Upgrade\r\n" - "Sec-WebSocket-Key: %s\r\n" - "Sec-WebSocket-Protocol: mqtt\r\n" - "Sec-WebSocket-Version: 13\r\n" - "\r\n", path, context->host, key); + "GET %s HTTP/1.1\r\n" + "Host: %s\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n" + "Sec-WebSocket-Key: %s\r\n" + "Sec-WebSocket-Protocol: mqtt\r\n" + "Sec-WebSocket-Version: 13\r\n" + "\r\n", path, context->host, key); mosquitto_FREE(key); packet->packet_length += WS_PACKET_OFFSET; packet->to_process = packet->packet_length; diff --git a/lib/net_mosq_ocsp.c b/lib/net_mosq_ocsp.c index b83ba44d..9f87d381 100644 --- a/lib/net_mosq_ocsp.c +++ b/lib/net_mosq_ocsp.c @@ -90,7 +90,7 @@ int mosquitto__verify_ocsp_status_cb(SSL *ssl, void *arg) ocsp_status = OCSP_response_status(rsp); if(ocsp_status != OCSP_RESPONSE_STATUS_SUCCESSFUL){ log__printf(mosq, MOSQ_LOG_DEBUG, "OCSP: invalid status: %s (%d)", - OCSP_response_status_str(ocsp_status), ocsp_status); + OCSP_response_status_str(ocsp_status), ocsp_status); goto end; } @@ -144,7 +144,7 @@ int mosquitto__verify_ocsp_status_cb(SSL *ssl, void *arg) case V_OCSP_CERTSTATUS_REVOKED: log__printf(mosq, MOSQ_LOG_DEBUG, "OCSP: SSL certificate revocation reason: %s (%d)", - OCSP_crl_reason_str(crl_reason), crl_reason); + OCSP_crl_reason_str(crl_reason), crl_reason); goto end; case V_OCSP_CERTSTATUS_UNKNOWN: diff --git a/lib/util_mosq.c b/lib/util_mosq.c index 356a8844..6c974a71 100644 --- a/lib/util_mosq.c +++ b/lib/util_mosq.c @@ -80,8 +80,8 @@ int mosquitto__check_keepalive(struct mosquitto *mosq) #if defined(WITH_BROKER) && defined(WITH_BRIDGE) /* Check if a lazy bridge should be timed out due to idle. */ if(mosq->bridge && mosq->bridge->start_type == bst_lazy - && net__is_connected(mosq) - && now - mosq->next_msg_out - mosq->keepalive >= mosq->bridge->idle_timeout){ + && net__is_connected(mosq) + && now - mosq->next_msg_out - mosq->keepalive >= mosq->bridge->idle_timeout){ log__printf(mosq, MOSQ_LOG_NOTICE, "Bridge connection %s has exceeded idle timeout, disconnecting.", mosq->id); net__socket_close(mosq); diff --git a/libcommon/cjson_common.c b/libcommon/cjson_common.c index 737d139a..c45cb59a 100644 --- a/libcommon/cjson_common.c +++ b/libcommon/cjson_common.c @@ -53,9 +53,9 @@ cJSON *mosquitto_properties_to_json(const mosquitto_property *properties) cJSON_AddItemToArray(array, obj); /* identifier, (key), value */ if(cJSON_AddStringToObject(obj, - "identifier", - mosquitto_property_identifier_to_string(propid)) == NULL - ){ + "identifier", + mosquitto_property_identifier_to_string(propid)) == NULL + ){ cJSON_Delete(array); return NULL; } diff --git a/libcommon/file_common.c b/libcommon/file_common.c index 720de9d8..3ed19df6 100644 --- a/libcommon/file_common.c +++ b/libcommon/file_common.c @@ -112,10 +112,10 @@ FILE *mosquitto_fopen(const char *path, const char *mode, bool restrict_read) sec.lpSecurityDescriptor = &sd; hfile = CreateFileA(buf, dwShareMode, FILE_SHARE_READ, - &sec, - dwCreationDisposition, - FILE_ATTRIBUTE_NORMAL, - NULL); + &sec, + dwCreationDisposition, + FILE_ATTRIBUTE_NORMAL, + NULL); LocalFree(pacl); diff --git a/libcommon/password_common.c b/libcommon/password_common.c index 970b7ddf..6e77fcf8 100644 --- a/libcommon/password_common.c +++ b/libcommon/password_common.c @@ -132,6 +132,7 @@ static int pw__create_argon2id(struct mosquitto_pw *pw, const char *password) #endif } + static int pw__verify_argon2id(struct mosquitto_pw *pw, const char *password) { #ifdef WITH_ARGON2 @@ -188,8 +189,8 @@ static int pw__hash_sha512_pbkdf2(const char *password, struct mosquitto_pw *pw, } PKCS5_PBKDF2_HMAC(password, (int)strlen(password), - pw->params.sha512.salt, (int)pw->params.sha512.salt_len, iterations, - digest, (int)hash_len, password_hash); + pw->params.sha512.salt, (int)pw->params.sha512.salt_len, iterations, + digest, (int)hash_len, password_hash); return MOSQ_ERR_SUCCESS; } diff --git a/plugins/dynamic-security/config_init.c b/plugins/dynamic-security/config_init.c index 6d331a29..1d67d573 100644 --- a/plugins/dynamic-security/config_init.c +++ b/plugins/dynamic-security/config_init.c @@ -371,15 +371,15 @@ static int add_role_with_full_permission(cJSON *j_roles, const char *role_name, cJSON_AddItemToArray(j_roles, j_role); if(cJSON_AddStringToObject(j_role, "rolename", role_name) == NULL - || cJSON_AddStringToObject(j_role, "textdescription", text_description) == NULL - || (j_acls = cJSON_AddArrayToObject(j_role, "acls")) == NULL){ + || cJSON_AddStringToObject(j_role, "textdescription", text_description) == NULL + || (j_acls = cJSON_AddArrayToObject(j_role, "acls")) == NULL){ return MOSQ_ERR_NOMEM; } if(acl_add(j_acls, "publishClientSend", topic_pattern, 0, true) - || acl_add(j_acls, "publishClientReceive", topic_pattern, 0, true) - || acl_add(j_acls, "subscribePattern", topic_pattern, 0, true) - || acl_add(j_acls, "unsubscribePattern", topic_pattern, 0, true)){ + || acl_add(j_acls, "publishClientReceive", topic_pattern, 0, true) + || acl_add(j_acls, "subscribePattern", topic_pattern, 0, true) + || acl_add(j_acls, "unsubscribePattern", topic_pattern, 0, true)){ return MOSQ_ERR_NOMEM; } return MOSQ_ERR_SUCCESS; @@ -398,7 +398,7 @@ static int role_add_sys_notify(cJSON *j_roles) if(cJSON_AddStringToObject(j_role, "rolename", "sys-notify") == NULL || cJSON_AddStringToObject(j_role, "textdescription", - "Allow bridges to publish connection state messages.") == NULL + "Allow bridges to publish connection state messages.") == NULL || (j_acls = cJSON_AddArrayToObject(j_role, "acls")) == NULL ){ @@ -426,7 +426,7 @@ static int role_add_sys_observe(cJSON *j_roles) if(cJSON_AddStringToObject(j_role, "rolename", "sys-observe") == NULL || cJSON_AddStringToObject(j_role, "textdescription", - "Observe the $SYS topic hierarchy.") == NULL + "Observe the $SYS topic hierarchy.") == NULL || (j_acls = cJSON_AddArrayToObject(j_role, "acls")) == NULL ){ @@ -455,7 +455,7 @@ static int role_add_topic_observe(cJSON *j_roles) if(cJSON_AddStringToObject(j_role, "rolename", "topic-observe") == NULL || cJSON_AddStringToObject(j_role, "textdescription", - "Read only access to the full application topic hierarchy.") == NULL + "Read only access to the full application topic hierarchy.") == NULL || (j_acls = cJSON_AddArrayToObject(j_role, "acls")) == NULL ){ @@ -483,10 +483,10 @@ static int add_roles(cJSON *j_tree) } if(add_role_with_full_permission(j_roles, "client", "Read/write access to the full application topic hierarchy.", "#") - || add_role_with_full_permission(j_roles, "broker-admin", "Grants access to administer general broker configuration.", "$CONTROL/broker/#") - || add_role_with_full_permission(j_roles, "dynsec-admin", "Grants access to administer clients/groups/roles.", "$CONTROL/dynamic-security/#") - || add_role_with_full_permission(j_roles, "super-admin", "Grants access to administer all kind of broker controls", "$CONTROL/#") - || role_add_sys_notify(j_roles) || role_add_sys_observe(j_roles) || role_add_topic_observe(j_roles)){ + || add_role_with_full_permission(j_roles, "broker-admin", "Grants access to administer general broker configuration.", "$CONTROL/broker/#") + || add_role_with_full_permission(j_roles, "dynsec-admin", "Grants access to administer clients/groups/roles.", "$CONTROL/dynamic-security/#") + || add_role_with_full_permission(j_roles, "super-admin", "Grants access to administer all kind of broker controls", "$CONTROL/#") + || role_add_sys_notify(j_roles) || role_add_sys_observe(j_roles) || role_add_topic_observe(j_roles)){ return MOSQ_ERR_NOMEM; } diff --git a/plugins/dynamic-security/default_acl.c b/plugins/dynamic-security/default_acl.c index 3843f299..f5ed1ee8 100644 --- a/plugins/dynamic-security/default_acl.c +++ b/plugins/dynamic-security/default_acl.c @@ -86,7 +86,7 @@ int dynsec__process_get_default_acl_access(struct dynsec__data *data, struct mos admin_clientid, admin_username); if(cJSON_AddStringToObject(tree, "command", "getDefaultACLAccess") == NULL - || ((j_data = cJSON_AddObjectToObject(tree, "data")) == NULL) + || ((j_data = cJSON_AddObjectToObject(tree, "data")) == NULL) ){ goto internal_error; diff --git a/plugins/examples/add-properties/mosquitto_add_properties.c b/plugins/examples/add-properties/mosquitto_add_properties.c index 25d0cbca..69074a76 100644 --- a/plugins/examples/add-properties/mosquitto_add_properties.c +++ b/plugins/examples/add-properties/mosquitto_add_properties.c @@ -63,26 +63,26 @@ static int callback_message_in(int event, void *event_data, void *userdata) snprintf(ts_buf, TS_BUF_LEN, "%li%03lu", ts.tv_sec, ts.tv_nsec / 1000 / 1000); result = mosquitto_property_add_string_pair( - &ed->properties, - MQTT_PROP_USER_PROPERTY, - "$timestamp", - ts_buf); + &ed->properties, + MQTT_PROP_USER_PROPERTY, + "$timestamp", + ts_buf); if(result != MOSQ_ERR_SUCCESS) return result; // Add client id result = mosquitto_property_add_string_pair( - &ed->properties, - MQTT_PROP_USER_PROPERTY, - "$clientid", - mosquitto_client_id(ed->client)); + &ed->properties, + MQTT_PROP_USER_PROPERTY, + "$clientid", + mosquitto_client_id(ed->client)); if(result != MOSQ_ERR_SUCCESS) return result; // Add client username result = mosquitto_property_add_string_pair( - &ed->properties, - MQTT_PROP_USER_PROPERTY, - "$client_username", - mosquitto_client_username(ed->client)); + &ed->properties, + MQTT_PROP_USER_PROPERTY, + "$client_username", + mosquitto_client_username(ed->client)); if(result != MOSQ_ERR_SUCCESS) return result; // If no return occurred up to this point, we were successful diff --git a/plugins/persist-sqlite/clients.c b/plugins/persist-sqlite/clients.c index 04b83b19..88043737 100644 --- a/plugins/persist-sqlite/clients.c +++ b/plugins/persist-sqlite/clients.c @@ -35,7 +35,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.clientid, (int)strlen(ed->data.clientid), 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, @@ -81,7 +81,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.clientid, (int)strlen(ed->data.clientid), 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); @@ -98,7 +98,7 @@ int persist_sqlite__client_remove_cb(int event, void *event_data, void *userdata persist_sqlite__client_msg_clear(ms, ed->data.clientid); if(sqlite3_bind_text(ms->client_remove_stmt, 1, - ed->data.clientid, (int)strlen(ed->data.clientid), 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); @@ -125,7 +125,7 @@ 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.clientid, - (int)strlen(ed->data.clientid), SQLITE_STATIC) == SQLITE_OK + (int)strlen(ed->data.clientid), SQLITE_STATIC) == SQLITE_OK ){ ms->event_count++; diff --git a/plugins/persist-sqlite/init.c b/plugins/persist-sqlite/init.c index 6e832b72..9f33edc3 100644 --- a/plugins/persist-sqlite/init.c +++ b/plugins/persist-sqlite/init.c @@ -56,27 +56,32 @@ static int create_tables_1_1(struct mosquitto_sqlite *ms) rc = sqlite3_exec(ms->db, "CREATE TABLE IF NOT EXISTS wills " "(" - "client_id TEXT PRIMARY KEY," - "payload BLOB," - "topic STRING NOT NULL," - "payloadlen INTEGER," - "qos INTEGER," - "retain INTEGER," - "properties STRING" + "client_id TEXT PRIMARY KEY," + "payload BLOB," + "topic STRING NOT NULL," + "payloadlen INTEGER," + "qos INTEGER," + "retain INTEGER," + "properties STRING" ");", NULL, NULL, NULL); - if (rc) { return rc; } + if(rc){ + return rc; + } rc = sqlite3_exec((*ms).db, - "UPDATE version_info" - " SET major = 1, minor = 1, patch = 0" - " WHERE component = 'database_schema';", + "UPDATE version_info" + " SET major = 1, minor = 1, patch = 0" + " WHERE component = 'database_schema';", NULL, NULL, NULL); - if (rc) { return rc; } + if(rc){ + return rc; + } return 0; } + static int create_tables(struct mosquitto_sqlite *ms) { int rc; @@ -85,18 +90,18 @@ static int create_tables(struct mosquitto_sqlite *ms) rc = sqlite3_exec(ms->db, "CREATE TABLE IF NOT EXISTS base_msgs " "(" - "store_id INT64 PRIMARY KEY," - "expiry_time INT64," - "topic STRING NOT NULL," - "payload BLOB," - "source_id STRING," - "source_username STRING," - "payloadlen INTEGER," - "source_mid INTEGER," - "source_port INTEGER," - "qos INTEGER," - "retain INTEGER," - "properties STRING" + "store_id INT64 PRIMARY KEY," + "expiry_time INT64," + "topic STRING NOT NULL," + "payload BLOB," + "source_id STRING," + "source_username STRING," + "payloadlen INTEGER," + "source_mid INTEGER," + "source_port INTEGER," + "qos INTEGER," + "retain INTEGER," + "properties STRING" ");", NULL, NULL, NULL); if(rc) goto fail; @@ -104,10 +109,10 @@ static int create_tables(struct mosquitto_sqlite *ms) rc = sqlite3_exec(ms->db, "CREATE TABLE IF NOT EXISTS retains " "(" - "topic STRING PRIMARY KEY," - "store_id INT64" - //"FOREIGN KEY (store_id) REFERENCES msg_store(store_id) " - //"ON DELETE CASCADE" + "topic STRING PRIMARY KEY," + "store_id INT64" + //"FOREIGN KEY (store_id) REFERENCES msg_store(store_id) " + //"ON DELETE CASCADE" ");", NULL, NULL, NULL); if(rc) goto fail; @@ -115,17 +120,17 @@ static int create_tables(struct mosquitto_sqlite *ms) rc = sqlite3_exec(ms->db, "CREATE TABLE IF NOT EXISTS clients " "(" - "client_id TEXT PRIMARY KEY," - "username TEXT," - "connection_time INT64," - "will_delay_time INT64," - "session_expiry_time INT64," - "listener_port INT," - "max_packet_size INT," - "max_qos INT," - "retain_available INT," - "session_expiry_interval INT," - "will_delay_interval INT" + "client_id TEXT PRIMARY KEY," + "username TEXT," + "connection_time INT64," + "will_delay_time INT64," + "session_expiry_time INT64," + "listener_port INT," + "max_packet_size INT," + "max_qos INT," + "retain_available INT," + "session_expiry_interval INT," + "will_delay_interval INT" ");", NULL, NULL, NULL); if(rc) goto fail; @@ -133,11 +138,11 @@ static int create_tables(struct mosquitto_sqlite *ms) rc = sqlite3_exec(ms->db, "CREATE TABLE IF NOT EXISTS subscriptions " "(" - "client_id TEXT NOT NULL," - "topic TEXT NOT NULL," - "subscription_options INTEGER," - "subscription_identifier INTEGER," - "PRIMARY KEY (client_id, topic) " + "client_id TEXT NOT NULL," + "topic TEXT NOT NULL," + "subscription_options INTEGER," + "subscription_identifier INTEGER," + "PRIMARY KEY (client_id, topic) " ");", NULL, NULL, NULL); if(rc) goto fail; @@ -145,21 +150,21 @@ static int create_tables(struct mosquitto_sqlite *ms) rc = sqlite3_exec(ms->db, "CREATE TABLE IF NOT EXISTS client_msgs " "(" - "client_id TEXT NOT NULL," - "cmsg_id INT64," - "store_id INT64," - "dup INTEGER," - "direction INTEGER," - "mid INTEGER," - "qos INTEGER," - "retain INTEGER," - "state INTEGER," - "subscription_identifier INTEGER" - //"state INTEGER," - //"FOREIGN KEY (client_id) REFERENCES clients(client_id) " - //"ON DELETE CASCADE," - //"FOREIGN KEY (store_id) REFERENCES msg_store(store_id) " - //"ON DELETE CASCADE" + "client_id TEXT NOT NULL," + "cmsg_id INT64," + "store_id INT64," + "dup INTEGER," + "direction INTEGER," + "mid INTEGER," + "qos INTEGER," + "retain INTEGER," + "state INTEGER," + "subscription_identifier INTEGER" + //"state INTEGER," + //"FOREIGN KEY (client_id) REFERENCES clients(client_id) " + //"ON DELETE CASCADE," + //"FOREIGN KEY (store_id) REFERENCES msg_store(store_id) " + //"ON DELETE CASCADE" ");", NULL, NULL, NULL); if(rc) goto fail; @@ -190,10 +195,10 @@ static int create_tables(struct mosquitto_sqlite *ms) rc = sqlite3_exec(ms->db, "CREATE TABLE IF NOT EXISTS version_info " "(" - "component TEXT NOT NULL," - "major INTEGER NOT NULL," - "minor INTEGER NOT NULL," - "patch INTEGER NOT NULL" + "component TEXT NOT NULL," + "major INTEGER NOT NULL," + "minor INTEGER NOT NULL," + "patch INTEGER NOT NULL" ");", NULL, NULL, NULL); if(rc) goto fail; @@ -207,9 +212,9 @@ static int create_tables(struct mosquitto_sqlite *ms) if(db_schema_version[0] == 0){ rc = sqlite3_exec((*ms).db, - "INSERT INTO version_info(component,major,minor,patch) " - "VALUES ('database_schema','1','0','0');", - NULL, NULL, NULL); + "INSERT INTO version_info(component,major,minor,patch) " + "VALUES ('database_schema','1','0','0');", + NULL, NULL, NULL); if(rc) goto fail; memcpy(db_schema_version, (int[3]){1, 0, 0}, sizeof(db_schema_version)); } @@ -217,7 +222,9 @@ static int create_tables(struct mosquitto_sqlite *ms) /* 1.0.x needs to be upgraded to 1.1 */ if(db_schema_version[1] == 0){ rc = create_tables_1_1(ms); - if (rc) { goto fail; } + if(rc){ + goto fail; + } memcpy(db_schema_version, (int[3]){1, 1, 0}, sizeof(db_schema_version)); } /* 1.1.x is the current DB-Schema version */ @@ -226,7 +233,7 @@ static int create_tables(struct mosquitto_sqlite *ms) } } mosquitto_log_printf(MOSQ_LOG_ERR, "Sqlite persistence: Unknown database_schema version %d.%d.%d", - db_schema_version[0], db_schema_version[1], db_schema_version[2]); + db_schema_version[0], db_schema_version[1], db_schema_version[2]); rc = MOSQ_ERR_INVAL; goto close_db; @@ -246,8 +253,8 @@ static int prepare_statements(struct mosquitto_sqlite *ms) /* Subscriptions */ rc = sqlite3_prepare_v3(ms->db, "INSERT OR REPLACE INTO subscriptions " - "(client_id, topic, subscription_options, subscription_identifier) " - "VALUES (?,?,?,?)", + "(client_id, topic, subscription_options, subscription_identifier) " + "VALUES (?,?,?,?)", -1, SQLITE_PREPARE_PERSISTENT, &ms->subscription_add_stmt, NULL); if(rc) goto fail; @@ -268,10 +275,10 @@ static int prepare_statements(struct mosquitto_sqlite *ms) /* Clients */ rc = sqlite3_prepare_v3(ms->db, "INSERT OR REPLACE INTO clients " - "(client_id, username, connection_time, will_delay_time, session_expiry_time, " - "listener_port, max_packet_size, max_qos, retain_available, " - "session_expiry_interval, will_delay_interval) " - "VALUES(?,?,?,?,?,?,?,?,?,?,?)", + "(client_id, username, connection_time, will_delay_time, session_expiry_time, " + "listener_port, max_packet_size, max_qos, retain_available, " + "session_expiry_interval, will_delay_interval) " + "VALUES(?,?,?,?,?,?,?,?,?,?,?)", -1, SQLITE_PREPARE_PERSISTENT, &ms->client_add_stmt, NULL); if(rc) goto fail; @@ -292,8 +299,8 @@ static int prepare_statements(struct mosquitto_sqlite *ms) /* Client messages */ rc = sqlite3_prepare_v3(ms->db, "INSERT INTO client_msgs " - "(client_id,cmsg_id,store_id,dup,direction,mid,qos,retain,state,subscription_identifier) " - "VALUES(?,?,?,?,?,?,?,?,?,?)", + "(client_id,cmsg_id,store_id,dup,direction,mid,qos,retain,state,subscription_identifier) " + "VALUES(?,?,?,?,?,?,?,?,?,?)", -1, SQLITE_PREPARE_PERSISTENT, &ms->client_msg_add_stmt, NULL); if(rc) goto fail; @@ -340,12 +347,12 @@ static int prepare_statements(struct mosquitto_sqlite *ms) if(rc) goto fail; rc = sqlite3_prepare_v3(ms->db, - "DELETE FROM base_msgs AS bm " - "WHERE bm.store_id IN " - "( SELECT cm.store_id FROM client_msgs AS cm" - " LEFT OUTER JOIN client_msgs AS oc ON oc.store_id = cm.store_id AND oc.client_id != cm.client_id" - " LEFT OUTER JOIN retains AS rm ON rm.store_id = cm.store_id" - " WHERE cm.client_id = ? AND oc.store_id IS NULL AND rm.store_id IS NULL)", + "DELETE FROM base_msgs AS bm " + "WHERE bm.store_id IN " + "( SELECT cm.store_id FROM client_msgs AS cm" + " LEFT OUTER JOIN client_msgs AS oc ON oc.store_id = cm.store_id AND oc.client_id != cm.client_id" + " LEFT OUTER JOIN retains AS rm ON rm.store_id = cm.store_id" + " WHERE cm.client_id = ? AND oc.store_id IS NULL AND rm.store_id IS NULL)", -1, SQLITE_PREPARE_PERSISTENT, &ms->base_msg_remove_for_clientid_stmt, NULL); if(rc) goto fail; diff --git a/plugins/persist-sqlite/restore.c b/plugins/persist-sqlite/restore.c index 0f024094..38ce58cf 100644 --- a/plugins/persist-sqlite/restore.c +++ b/plugins/persist-sqlite/restore.c @@ -468,11 +468,11 @@ static int will_restore(struct mosquitto_sqlite *ms) int payloadlen, qos, retain; rc = sqlite3_prepare_v2(ms->db, - "SELECT w.client_id,w.topic,w.payload,w.payloadlen,w.qos,w.retain,w.properties," - " c.session_expiry_time,c.will_delay_interval" - " FROM wills w" - " LEFT OUTER JOIN clients c ON c.client_id = w.client_id", - -1, &stmt, NULL); + "SELECT w.client_id,w.topic,w.payload,w.payloadlen,w.qos,w.retain,w.properties," + " c.session_expiry_time,c.will_delay_interval" + " FROM wills w" + " LEFT OUTER JOIN clients c ON c.client_id = w.client_id", + -1, &stmt, NULL); if(rc != SQLITE_OK){ mosquitto_log_printf(MOSQ_LOG_ERR, "sqlite: Error restoring will messages: %s", sqlite3_errstr(rc)); diff --git a/plugins/persist-sqlite/retain_msgs.c b/plugins/persist-sqlite/retain_msgs.c index 906a9367..59e03f08 100644 --- a/plugins/persist-sqlite/retain_msgs.c +++ b/plugins/persist-sqlite/retain_msgs.c @@ -59,7 +59,7 @@ int persist_sqlite__retain_msg_remove_cb(int event, void *event_data, void *user UNUSED(event); if(sqlite3_bind_text(ms->retain_msg_remove_stmt, 1, - ed->topic, (int)strlen(ed->topic), SQLITE_STATIC) == SQLITE_OK){ + ed->topic, (int)strlen(ed->topic), SQLITE_STATIC) == SQLITE_OK){ ms->event_count++; rc = sqlite3_step(ms->retain_msg_remove_stmt); diff --git a/plugins/persist-sqlite/subscriptions.c b/plugins/persist-sqlite/subscriptions.c index fcea9536..3a7d0304 100644 --- a/plugins/persist-sqlite/subscriptions.c +++ b/plugins/persist-sqlite/subscriptions.c @@ -33,16 +33,16 @@ 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.clientid, (int)strlen(ed->data.clientid), 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){ + ed->data.topic_filter, (int)strlen(ed->data.topic_filter), SQLITE_STATIC) == SQLITE_OK){ if(sqlite3_bind_int(ms->subscription_add_stmt, 3, - ed->data.options) == SQLITE_OK){ + ed->data.options) == SQLITE_OK){ if(sqlite3_bind_int(ms->subscription_add_stmt, 4, - (int)ed->data.identifier) == SQLITE_OK){ + (int)ed->data.identifier) == SQLITE_OK){ ms->event_count++; rc = sqlite3_step(ms->subscription_add_stmt); @@ -70,10 +70,10 @@ 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.clientid, (int)strlen(ed->data.clientid), 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){ + ed->data.topic_filter, (int)strlen(ed->data.topic_filter), SQLITE_STATIC) == SQLITE_OK){ ms->event_count++; rc = sqlite3_step(ms->subscription_remove_stmt); diff --git a/plugins/persist-sqlite/will.c b/plugins/persist-sqlite/will.c index 6d205d89..1057d3c0 100644 --- a/plugins/persist-sqlite/will.c +++ b/plugins/persist-sqlite/will.c @@ -41,13 +41,13 @@ int persist_sqlite__will_add_cb(int event, void *event_data, void *userdata) } } - if(sqlite3_bind_text_from_c_str( ms->will_add_stmt, 1, ed->data.clientid) != SQLITE_OK - || sqlite3_bind_blob_optional(ms->will_add_stmt, 2, ed->data.payload, (int)ed->data.payloadlen) != SQLITE_OK - || sqlite3_bind_text_from_c_str(ms->will_add_stmt, 3, ed->data.topic) != SQLITE_OK - || sqlite3_bind_int64(ms->will_add_stmt, 4, (int64_t)ed->data.payloadlen) != SQLITE_OK - || sqlite3_bind_int(ms->will_add_stmt, 5, ed->data.qos) != SQLITE_OK - || sqlite3_bind_int(ms->will_add_stmt, 6, ed->data.retain) != SQLITE_OK - || sqlite3_bind_text_from_optional_c_str( ms->will_add_stmt, 7, propties_json_str) != SQLITE_OK) { + if(sqlite3_bind_text_from_c_str(ms->will_add_stmt, 1, ed->data.clientid) != SQLITE_OK + || sqlite3_bind_blob_optional(ms->will_add_stmt, 2, ed->data.payload, (int)ed->data.payloadlen) != SQLITE_OK + || sqlite3_bind_text_from_c_str(ms->will_add_stmt, 3, ed->data.topic) != SQLITE_OK + || sqlite3_bind_int64(ms->will_add_stmt, 4, (int64_t)ed->data.payloadlen) != SQLITE_OK + || sqlite3_bind_int(ms->will_add_stmt, 5, ed->data.qos) != SQLITE_OK + || sqlite3_bind_int(ms->will_add_stmt, 6, ed->data.retain) != SQLITE_OK + || sqlite3_bind_text_from_optional_c_str(ms->will_add_stmt, 7, propties_json_str) != SQLITE_OK){ rc = MOSQ_ERR_UNKNOWN; } rc = sqlite3_single_step_stmt(rc, ms, ms->will_add_stmt); diff --git a/src/bridge.c b/src/bridge.c index ce6a0e5c..a1b28af8 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -198,19 +198,17 @@ static int bridge__set_tcp_keepalive(struct mosquitto *context) if(idle == 0 || interval == 0 || counter == 0) return MOSQ_ERR_SUCCESS; #ifdef WIN32 - ret = - setsockopt(context->sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&enabled, sizeof(enabled)) || - setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPIDLE, (char *)&idle, sizeof(idle)) || - setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPINTVL, (char *)&interval, sizeof(interval)) || - setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPCNT, (char *)&counter, sizeof(counter)); + ret = setsockopt(context->sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&enabled, sizeof(enabled)) || + setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPIDLE, (char *)&idle, sizeof(idle)) || + setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPINTVL, (char *)&interval, sizeof(interval)) || + setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPCNT, (char *)&counter, sizeof(counter)); #else - ret = - setsockopt(context->sock, SOL_SOCKET, SO_KEEPALIVE, (const void *)&enabled, sizeof(enabled)) || + ret = setsockopt(context->sock, SOL_SOCKET, SO_KEEPALIVE, (const void *)&enabled, sizeof(enabled)) || #ifndef __APPLE__ - setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPIDLE, (const void *)&idle, sizeof(idle)) || + setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPIDLE, (const void *)&idle, sizeof(idle)) || #endif - setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPINTVL, (const void *)&interval, sizeof(interval)) || - setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPCNT, (const void *)&counter, sizeof(counter)); + setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPINTVL, (const void *)&interval, sizeof(interval)) || + setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPCNT, (const void *)&counter, sizeof(counter)); #endif if(ret) return MOSQ_ERR_UNKNOWN; @@ -690,9 +688,9 @@ int bridge__on_connect(struct mosquitto *context) } if(context->bridge->protocol_version == mosq_p_mqtt5){ sub_opts = sub_opts - | MQTT_SUB_OPT_NO_LOCAL - | MQTT_SUB_OPT_RETAIN_AS_PUBLISHED - | MQTT_SUB_OPT_SEND_RETAIN_ALWAYS; + | MQTT_SUB_OPT_NO_LOCAL + | MQTT_SUB_OPT_RETAIN_AS_PUBLISHED + | MQTT_SUB_OPT_SEND_RETAIN_ALWAYS; } if(send__subscribe(context, NULL, 1, &cur_topic->remote_topic, sub_opts, NULL)){ return 1; diff --git a/src/context.c b/src/context.c index 74d5cb90..a3fa584d 100644 --- a/src/context.c +++ b/src/context.c @@ -43,8 +43,8 @@ int context__init_sock(struct mosquitto *context, mosq_sock_t sock, bool get_add char address[1024]; if(!net__socket_get_address(context->sock, - address, sizeof(address), - &context->remote_port)){ + address, sizeof(address), + &context->remote_port)){ context->address = mosquitto_strdup(address); } @@ -216,12 +216,12 @@ void context__send_will(struct mosquitto *ctxt) } if(mosquitto_acl_check(ctxt, - ctxt->will->msg.topic, - (uint32_t)ctxt->will->msg.payloadlen, - ctxt->will->msg.payload, - (uint8_t)ctxt->will->msg.qos, - ctxt->will->msg.retain, - MOSQ_ACL_WRITE) == MOSQ_ERR_SUCCESS){ + ctxt->will->msg.topic, + (uint32_t)ctxt->will->msg.payloadlen, + ctxt->will->msg.payload, + (uint8_t)ctxt->will->msg.qos, + ctxt->will->msg.retain, + MOSQ_ACL_WRITE) == MOSQ_ERR_SUCCESS){ /* Unexpected disconnect, queue the client will. */ db__messages_easy_queue(ctxt, diff --git a/src/database.c b/src/database.c index dd8467de..ceab9879 100644 --- a/src/database.c +++ b/src/database.c @@ -1274,8 +1274,8 @@ static void db__client_messages_check_acl(struct mosquitto *context, struct mosq access = MOSQ_ACL_WRITE; } if(mosquitto_acl_check(context, base_msg->data.topic, - base_msg->data.payloadlen, base_msg->data.payload, - base_msg->data.qos, base_msg->data.retain, access) != MOSQ_ERR_SUCCESS){ + base_msg->data.payloadlen, base_msg->data.payload, + base_msg->data.qos, base_msg->data.retain, access) != MOSQ_ERR_SUCCESS){ DL_DELETE((*head), client_msg); decrement_stats_fn(msg_data, client_msg); @@ -1436,8 +1436,8 @@ int db__message_write_inflight_out_latest(struct mosquitto *context) client_msg = context->msgs_out.inflight->prev; while(client_msg != context->msgs_out.inflight && (client_msg->data.state == mosq_ms_publish_qos0 - || client_msg->data.state == mosq_ms_publish_qos1 - || client_msg->data.state == mosq_ms_publish_qos2)){ + || client_msg->data.state == mosq_ms_publish_qos1 + || client_msg->data.state == mosq_ms_publish_qos2)){ client_msg = client_msg->prev; } diff --git a/src/handle_auth.c b/src/handle_auth.c index 4631ff08..537f25d7 100644 --- a/src/handle_auth.c +++ b/src/handle_auth.c @@ -61,7 +61,7 @@ int handle__auth(struct mosquitto *context) if((reason_code == MQTT_RC_REAUTHENTICATE && context->state != mosq_cs_active) || (reason_code == MQTT_RC_CONTINUE_AUTHENTICATION - && context->state != mosq_cs_authenticating && context->state != mosq_cs_reauthenticating)){ + && context->state != mosq_cs_authenticating && context->state != mosq_cs_reauthenticating)){ send__disconnect(context, MQTT_RC_PROTOCOL_ERROR, NULL); return MOSQ_ERR_PROTOCOL; diff --git a/src/handle_connack.c b/src/handle_connack.c index e02d4b58..0fc11228 100644 --- a/src/handle_connack.c +++ b/src/handle_connack.c @@ -44,14 +44,14 @@ static int handle__connack_properties(struct mosquitto *context) /* maximum-qos */ mosquitto_property_read_byte(properties, MQTT_PROP_MAXIMUM_QOS, - &max_qos, false); + &max_qos, false); if(max_qos != 255){ context->max_qos = max_qos; } /* maximum-packet-size */ if(mosquitto_property_read_int32(properties, MQTT_PROP_MAXIMUM_PACKET_SIZE, - &maximum_packet_size, false)){ + &maximum_packet_size, false)){ if(context->maximum_packet_size == 0 || context->maximum_packet_size > maximum_packet_size){ context->maximum_packet_size = maximum_packet_size; @@ -68,7 +68,7 @@ static int handle__connack_properties(struct mosquitto *context) /* retain-available */ if(mosquitto_property_read_byte(properties, MQTT_PROP_RETAIN_AVAILABLE, - &retain_available, false)){ + &retain_available, false)){ /* Only use broker provided value if the local config is set to available==true */ if(context->retain_available){ @@ -78,14 +78,14 @@ static int handle__connack_properties(struct mosquitto *context) /* server-keepalive */ if(mosquitto_property_read_int16(properties, MQTT_PROP_SERVER_KEEP_ALIVE, - &server_keepalive, false)){ + &server_keepalive, false)){ context->keepalive = server_keepalive; } /* topic-alias-maximum */ if(mosquitto_property_read_int16(properties, MQTT_PROP_TOPIC_ALIAS_MAXIMUM, - &max_topic_alias, false)){ + &max_topic_alias, false)){ if(max_topic_alias < context->bridge->max_topic_alias){ context->alias_max_l2r = max_topic_alias; diff --git a/src/handle_connect.c b/src/handle_connect.c index 87630c08..e2a61d2d 100644 --- a/src/handle_connect.c +++ b/src/handle_connect.c @@ -216,14 +216,14 @@ int connect__on_authorised(struct mosquitto *context, void *auth_data_out, uint1 } } - if(context->will) { + if(context->will){ log__printf(NULL, MOSQ_LOG_DEBUG, "Will message specified (%ld bytes) (r%d, q%d).", (long)context->will->msg.payloadlen, context->will->msg.retain, context->will->msg.qos); log__printf(NULL, MOSQ_LOG_DEBUG, "\t%s", context->will->msg.topic); - } else { + }else{ log__printf(NULL, MOSQ_LOG_DEBUG, "No will message specified."); } } @@ -476,7 +476,7 @@ static int read_protocol_name(struct mosquitto *context, char protocol_name[7]) static int read_and_verify_protocol_version(struct mosquitto *context, const char *protocol_name, - uint8_t *protocol_version) + uint8_t *protocol_version) { uint8_t tmp_protocol_version = 0; if(packet__read_byte(&context->in_packet, &tmp_protocol_version)){ @@ -637,7 +637,7 @@ static int verify_will_options(struct mosquitto *context, uint8_t will, uint8_t static int handle_zero_length_clientid(struct mosquitto *context, char **clientid, bool *allow_zero_length_clientid, - uint8_t clean_start) + uint8_t clean_start) { if(context->protocol == mosq_p_mqtt31){ send__connack(context, 0, CONNACK_REFUSED_IDENTIFIER_REJECTED, NULL); @@ -659,7 +659,7 @@ static int handle_zero_length_clientid(struct mosquitto *context, char **clienti } *clientid = clientid_gen(&(uint16_t){0}, context->listener->security_options->auto_id_prefix, - context->listener->security_options->auto_id_prefix_len); + context->listener->security_options->auto_id_prefix_len); if(*clientid == NULL){ return MOSQ_ERR_NOMEM; } @@ -680,8 +680,9 @@ static int check_clientid_prefixes(struct mosquitto *context, const char *client return MOSQ_ERR_SUCCESS; } -static int read_and_verify_clientid_from_packet(struct mosquitto *context, char** clientid, - bool *allow_zero_length_clientid, uint8_t clean_start) + +static int read_and_verify_clientid_from_packet(struct mosquitto *context, char **clientid, + bool *allow_zero_length_clientid, uint8_t clean_start) { int rc; uint16_t slen; @@ -755,9 +756,9 @@ static int set_password_from_packet(struct mosquitto *context, char **password) static int read_and_verify_client_credentials_from_packet(struct mosquitto *context, - char **username, uint8_t username_flag, - char **password, uint8_t password_flag, - const char* clientid) + char **username, uint8_t username_flag, + char **password, uint8_t password_flag, + const char *clientid) { int rc; @@ -827,7 +828,7 @@ inline static int free_x509_and_send_connack_error(struct mosquitto *context, X5 inline static int free_x509_and_BIO_and_send_connack_error(struct mosquitto *context, X509 *client_cert, - BIO *subject_name, int rc) + BIO *subject_name, int rc) { BIO_free(subject_name); return free_x509_and_send_connack_error(context, client_cert, rc); @@ -1031,7 +1032,7 @@ int handle__connect(struct mosquitto *context) if(context->in_packet.command == 0x16 && context->listener->ssl_ctx == NULL){ /* 0x16 is TLS handshake client hello */ log__printf(NULL, MOSQ_LOG_NOTICE, "Client from %s:%d appears to be using TLS to connect to a non-TLS listener.", - context->address, context->remote_port); + context->address, context->remote_port); rc = MOSQ_ERR_PROTOCOL; goto handle_connect_error; } diff --git a/src/handle_publish.c b/src/handle_publish.c index ca3c95d7..eb855f15 100644 --- a/src/handle_publish.c +++ b/src/handle_publish.c @@ -253,9 +253,9 @@ int handle__publish(struct mosquitto *context) if(cmsg_stored && base_msg->data.source_mid != 0 && (cmsg_stored->base_msg->data.qos != base_msg->data.qos - || cmsg_stored->base_msg->data.payloadlen != base_msg->data.payloadlen - || strcmp(cmsg_stored->base_msg->data.topic, base_msg->data.topic) - || memcmp(cmsg_stored->base_msg->data.payload, base_msg->data.payload, base_msg->data.payloadlen) )){ + || cmsg_stored->base_msg->data.payloadlen != base_msg->data.payloadlen + || strcmp(cmsg_stored->base_msg->data.topic, base_msg->data.topic) + || memcmp(cmsg_stored->base_msg->data.payload, base_msg->data.payload, base_msg->data.payloadlen))){ log__printf(NULL, MOSQ_LOG_WARNING, "Reused message ID %u from %s detected. Clearing from storage.", base_msg->data.source_mid, context->id); db__message_remove_incoming(context, base_msg->data.source_mid); diff --git a/src/handle_subscribe.c b/src/handle_subscribe.c index c3028dfa..fac8ba6e 100644 --- a/src/handle_subscribe.c +++ b/src/handle_subscribe.c @@ -77,7 +77,7 @@ int handle__subscribe(struct mosquitto *context) } if(mosquitto_property_read_varint(properties, MQTT_PROP_SUBSCRIPTION_IDENTIFIER, - &subscription_identifier, false)){ + &subscription_identifier, false)){ /* If the identifier was force set to 0, this is an error */ if(subscription_identifier == 0){ diff --git a/src/net.c b/src/net.c index ef8f649e..2f259bec 100644 --- a/src/net.c +++ b/src/net.c @@ -702,8 +702,8 @@ static int net__bind_interface(struct mosquitto__listener *listener, struct addr if(rp->ai_addr->sa_family == AF_INET){ if(listener->host && memcmp(&((struct sockaddr_in *)rp->ai_addr)->sin_addr, - &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr, - sizeof(struct in_addr))){ + &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr, + sizeof(struct in_addr))){ log__printf(NULL, MOSQ_LOG_ERR, "Error: Interface address for %s does not match specified listener address (%s).", listener->bind_interface, listener->host); @@ -719,8 +719,8 @@ static int net__bind_interface(struct mosquitto__listener *listener, struct addr }else if(rp->ai_addr->sa_family == AF_INET6){ if(listener->host && memcmp(&((struct sockaddr_in6 *)rp->ai_addr)->sin6_addr, - &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr, - sizeof(struct in6_addr))){ + &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr, + sizeof(struct in6_addr))){ log__printf(NULL, MOSQ_LOG_ERR, "Error: Interface address for %s does not match specified listener address (%s).", listener->bind_interface, listener->host); @@ -742,7 +742,7 @@ static int net__bind_interface(struct mosquitto__listener *listener, struct addr freeifaddrs(ifaddr); if(have_interface){ log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Interface %s does not support %s configuration.", - listener->bind_interface, rp->ai_addr->sa_family == AF_INET ? "IPv4" : "IPv6"); + listener->bind_interface, rp->ai_addr->sa_family == AF_INET ? "IPv4" : "IPv6"); return MOSQ_ERR_NOT_SUPPORTED; }else{ log__printf(NULL, MOSQ_LOG_ERR, "Error: Interface %s does not exist.", listener->bind_interface); diff --git a/src/persist_write_v5.c b/src/persist_write_v5.c index aee501d5..399783be 100644 --- a/src/persist_write_v5.c +++ b/src/persist_write_v5.c @@ -92,8 +92,9 @@ int persist__chunk_client_msg_write_v6(FILE *db_fptr, struct P_client_msg *chunk uint16_t id_len = chunk->F.id_len; uint32_t proplen = 0; int rc; - mosquitto_property subscription_id_prop = - {.next = NULL, .identifier = MQTT_PROP_SUBSCRIPTION_IDENTIFIER, .client_generated = true, .property_type = MQTT_PROP_TYPE_VARINT}; + mosquitto_property subscription_id_prop = { + .next = NULL, .identifier = MQTT_PROP_SUBSCRIPTION_IDENTIFIER, .client_generated = true, .property_type = MQTT_PROP_TYPE_VARINT + }; if(chunk->subscription_identifier){ subscription_id_prop.value.varint = chunk->subscription_identifier; diff --git a/src/plugin_basic_auth.c b/src/plugin_basic_auth.c index 8b08827d..dfc0a57d 100644 --- a/src/plugin_basic_auth.c +++ b/src/plugin_basic_auth.c @@ -89,7 +89,7 @@ int mosquitto_basic_auth(struct mosquitto *context) if(plugin_used == false){ if((context->listener && context->listener->security_options->allow_anonymous == true) || (!db.config->per_listener_settings && db.config->security_options.allow_anonymous == true - && context->listener && context->listener->security_options->allow_anonymous != false)){ + && context->listener && context->listener->security_options->allow_anonymous != false)){ return MOSQ_ERR_SUCCESS; }else{ @@ -101,7 +101,7 @@ int mosquitto_basic_auth(struct mosquitto *context) if(context->username == NULL && ((context->listener && context->listener->security_options->allow_anonymous == true) || (!db.config->per_listener_settings && db.config->security_options.allow_anonymous == true - && context->listener && context->listener->security_options->allow_anonymous != false))){ + && context->listener && context->listener->security_options->allow_anonymous != false))){ return MOSQ_ERR_SUCCESS; }else{ diff --git a/src/plugin_callbacks.c b/src/plugin_callbacks.c index 4333b415..bf333e02 100644 --- a/src/plugin_callbacks.c +++ b/src/plugin_callbacks.c @@ -226,7 +226,7 @@ BROKER_EXPORT int mosquitto_callback_register( own_callback->cb_func = cb_func; DL_APPEND(identifier->own_callbacks, own_callback); - if(identifier->config.security_option_count == 0) { + if(identifier->config.security_option_count == 0){ log__printf(NULL, MOSQ_LOG_WARNING, "Plugin could not register callback '%s'", get_event_name(event)); return MOSQ_ERR_INVAL; diff --git a/src/plugin_message.c b/src/plugin_message.c index d39d570e..f0efada4 100644 --- a/src/plugin_message.c +++ b/src/plugin_message.c @@ -90,7 +90,7 @@ int plugin__handle_message_out(struct mosquitto *context, struct mosquitto_base_ if(db.config->per_listener_settings && context->listener){ rc = plugin__handle_message_single(context->listener->security_options->plugin_callbacks.message_out, - MOSQ_EVT_MESSAGE_OUT, &to_free, context, stored); + MOSQ_EVT_MESSAGE_OUT, &to_free, context, stored); } return rc; @@ -109,7 +109,7 @@ int plugin__handle_message_in(struct mosquitto *context, struct mosquitto_base_m if(db.config->per_listener_settings && context->listener){ rc = plugin__handle_message_single(context->listener->security_options->plugin_callbacks.message_in, - MOSQ_EVT_MESSAGE_IN, &to_free, context, stored); + MOSQ_EVT_MESSAGE_IN, &to_free, context, stored); } return rc; diff --git a/src/plugin_persist.c b/src/plugin_persist.c index 85f84dba..2c8682a1 100644 --- a/src/plugin_persist.c +++ b/src/plugin_persist.c @@ -131,8 +131,8 @@ void plugin_persist__handle_client_delete(struct mosquitto *context) struct mosquitto__security_options *opts; if(context->id == NULL - || context->state == mosq_cs_duplicate - || db.shutdown){ + || context->state == mosq_cs_duplicate + || db.shutdown){ return; } diff --git a/src/plugin_tick.c b/src/plugin_tick.c index 6a09d445..aacc1565 100644 --- a/src/plugin_tick.c +++ b/src/plugin_tick.c @@ -37,7 +37,7 @@ static void plugin__handle_tick_single(struct mosquitto__security_options *opts) mosquitto_time_ns(&event_data.now_s, &event_data.now_ns); if(mosquitto_time_cmp(event_data.now_s, event_data.now_ns, - cb_base->data.next_tick.tv_sec, cb_base->data.next_tick.tv_nsec) > 0){ + cb_base->data.next_tick.tv_sec, cb_base->data.next_tick.tv_nsec) > 0){ event_data.next_s = 0; event_data.next_ms = 0; diff --git a/src/service.c b/src/service.c index ecec06fd..149ef26a 100644 --- a/src/service.c +++ b/src/service.c @@ -50,7 +50,7 @@ static void print_error(void) char *buf = NULL; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, GetLastError(), LANG_NEUTRAL, (LPTSTR)&buf, 0, NULL); + NULL, GetLastError(), LANG_NEUTRAL, (LPTSTR)&buf, 0, NULL); fprintf(stderr, "Error: %s\n", buf); LocalFree(buf); diff --git a/src/sys_tree.c b/src/sys_tree.c index 12e0edaa..32a3482b 100644 --- a/src/sys_tree.c +++ b/src/sys_tree.c @@ -268,7 +268,7 @@ void sys_tree__update(bool force) for(int i=0; i metrics[i].current) || - (!metrics[i].is_max && metrics[i].next != metrics[i].current)){ + (!metrics[i].is_max && metrics[i].next != metrics[i].current)){ metrics[i].current = metrics[i].next; len = (uint32_t)snprintf(buf, BUFLEN, "%lu", metrics[i].current); diff --git a/src/websockets.c b/src/websockets.c index aa3eef5e..a3ff19c6 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -53,16 +53,16 @@ static int callback_mqtt( size_t len); static int callback_http( - struct lws *wsi, - enum lws_callback_reasons reason, - void *user, - void *in, - size_t len); + struct lws *wsi, + enum lws_callback_reasons reason, + void *user, + void *in, + size_t len); enum mosq_ws_protocols { PROTOCOL_HTTP = 0, PROTOCOL_MQTT, - DEMO_PROTOCOL_COUNT + DEMO_PROTOCOL_COUNT, }; struct libws_http_data { @@ -493,8 +493,8 @@ static int callback_http( /* FIXME - use header functions from lws 2.x */ buflen = (size_t)snprintf((char *)buf, 4096, "HTTP/1.0 302 OK\r\n" - "Location: %s/\r\n\r\n", - (char *)in); + "Location: %s/\r\n\r\n", + (char *)in); return lws_write(wsi, buf, buflen, LWS_WRITE_HTTP); } @@ -510,9 +510,9 @@ static int callback_http( SAFE_FREE(filename_canonical); /* FIXME - use header functions from lws 2.x */ buflen = (size_t)snprintf((char *)buf, 4096, "HTTP/1.0 200 OK\r\n" - "Server: mosquitto\r\n" - "Content-Length: %u\r\n\r\n", - (unsigned int)filestat.st_size); + "Server: mosquitto\r\n" + "Content-Length: %u\r\n\r\n", + (unsigned int)filestat.st_size); if(lws_write(wsi, buf, buflen, LWS_WRITE_HTTP) < 0){ fclose(u->fptr); u->fptr = NULL; diff --git a/test/broker/c/auth_plugin_delayed.c b/test/broker/c/auth_plugin_delayed.c index 19b1e094..9e8c05e3 100644 --- a/test/broker/c/auth_plugin_delayed.c +++ b/test/broker/c/auth_plugin_delayed.c @@ -62,7 +62,7 @@ static int tick_callback(int event, void *event_data, void *user_data) if(auth_delay == 0){ if(clientid && username && password - && !strcmp(username, "delayed-username") && !strcmp(password, "good")){ + && !strcmp(username, "delayed-username") && !strcmp(password, "good")){ mosquitto_complete_basic_auth(clientid, MOSQ_ERR_SUCCESS); }else{ diff --git a/test/unit/lib/property_read.c b/test/unit/lib/property_read.c index d6b64a3c..b942602d 100644 --- a/test/unit/lib/property_read.c +++ b/test/unit/lib/property_read.c @@ -352,11 +352,14 @@ static void varint_prop_read_helper( CU_ASSERT_PTR_NULL(properties); } + static void packet_helper_reason_string_user_property(int command) { - uint8_t payload[24] = {23, + uint8_t payload[24] = { + 23, MQTT_PROP_REASON_STRING, 0, 6, 'r', 'e', 'a', 's', 'o', 'n', - MQTT_PROP_USER_PROPERTY, 0, 4, 'n', 'a', 'm', 'e', 0, 5, 'v', 'a', 'l', 'u', 'e'}; + MQTT_PROP_USER_PROPERTY, 0, 4, 'n', 'a', 'm', 'e', 0, 5, 'v', 'a', 'l', 'u', 'e' + }; struct mosquitto__packet_in packet; mosquitto_property *properties, *p; @@ -1303,7 +1306,8 @@ static void TEST_bad_subscription_identifier(void) static void TEST_packet_connect(void) { - uint8_t payload[] = {0, + uint8_t payload[] = { + 0, MQTT_PROP_SESSION_EXPIRY_INTERVAL, 0x12, 0x45, 0x00, 0x00, MQTT_PROP_RECEIVE_MAXIMUM, 0x00, 0x05, MQTT_PROP_MAXIMUM_PACKET_SIZE, 0x12, 0x45, 0x00, 0x00, @@ -1312,7 +1316,8 @@ static void TEST_packet_connect(void) MQTT_PROP_REQUEST_RESPONSE_INFORMATION, 1, MQTT_PROP_USER_PROPERTY, 0, 4, 'n', 'a', 'm', 'e', 0, 5, 'v', 'a', 'l', 'u', 'e', MQTT_PROP_AUTHENTICATION_METHOD, 0x00, 0x04, 'n', 'o', 'n', 'e', - MQTT_PROP_AUTHENTICATION_DATA, 0x00, 0x02, 1, 2}; + MQTT_PROP_AUTHENTICATION_DATA, 0x00, 0x02, 1, 2 + }; struct mosquitto__packet_in packet; mosquitto_property *properties, *p; @@ -1410,7 +1415,8 @@ static void TEST_packet_connect(void) static void TEST_packet_connack(void) { - uint8_t payload[] = {0, + uint8_t payload[] = { + 0, MQTT_PROP_SESSION_EXPIRY_INTERVAL, 0x12, 0x45, 0x00, 0x00, MQTT_PROP_RECEIVE_MAXIMUM, 0x00, 0x05, MQTT_PROP_MAXIMUM_QOS, 1, @@ -1427,7 +1433,8 @@ static void TEST_packet_connack(void) MQTT_PROP_RESPONSE_INFORMATION, 0x00, 0x03, 'r', 's', 'p', MQTT_PROP_SERVER_REFERENCE, 0x00, 0x04, 's', 'e', 'r', 'v', MQTT_PROP_AUTHENTICATION_METHOD, 0x00, 0x04, 'n', 'o', 'n', 'e', - MQTT_PROP_AUTHENTICATION_DATA, 0x00, 0x02, 1, 2}; + MQTT_PROP_AUTHENTICATION_DATA, 0x00, 0x02, 1, 2 + }; struct mosquitto__packet_in packet; mosquitto_property *properties, *p; @@ -1594,7 +1601,8 @@ static void TEST_packet_connack(void) static void TEST_packet_publish(void) { - uint8_t payload[] = {0, + uint8_t payload[] = { + 0, MQTT_PROP_PAYLOAD_FORMAT_INDICATOR, 1, MQTT_PROP_MESSAGE_EXPIRY_INTERVAL, 0x12, 0x45, 0x00, 0x00, MQTT_PROP_TOPIC_ALIAS, 0x00, 0x02, @@ -1602,7 +1610,8 @@ static void TEST_packet_publish(void) MQTT_PROP_CORRELATION_DATA, 0x00, 0x02, 1, 2, MQTT_PROP_USER_PROPERTY, 0, 4, 'n', 'a', 'm', 'e', 0, 5, 'v', 'a', 'l', 'u', 'e', MQTT_PROP_SUBSCRIPTION_IDENTIFIER, 0x04, - MQTT_PROP_CONTENT_TYPE, 0, 5, 'e', 'm', 'p', 't', 'y'}; + MQTT_PROP_CONTENT_TYPE, 0, 5, 'e', 'm', 'p', 't', 'y' + }; struct mosquitto__packet_in packet; mosquitto_property *properties, *p; @@ -1718,9 +1727,11 @@ static void TEST_packet_pubcomp(void) static void TEST_packet_subscribe(void) { - uint8_t payload[] = {0, + uint8_t payload[] = { + 0, MQTT_PROP_USER_PROPERTY, 0, 4, 'n', 'a', 'm', 'e', 0, 5, 'v', 'a', 'l', 'u', 'e', - MQTT_PROP_SUBSCRIPTION_IDENTIFIER, 0x04}; + MQTT_PROP_SUBSCRIPTION_IDENTIFIER, 0x04 + }; struct mosquitto__packet_in packet; mosquitto_property *properties, *p; @@ -1766,8 +1777,10 @@ static void TEST_packet_suback(void) static void TEST_packet_unsubscribe(void) { - uint8_t payload[] = {0, - MQTT_PROP_USER_PROPERTY, 0, 4, 'n', 'a', 'm', 'e', 0, 5, 'v', 'a', 'l', 'u', 'e'}; + uint8_t payload[] = { + 0, + MQTT_PROP_USER_PROPERTY, 0, 4, 'n', 'a', 'm', 'e', 0, 5, 'v', 'a', 'l', 'u', 'e' + }; struct mosquitto__packet_in packet; mosquitto_property *properties, *p; @@ -1805,10 +1818,12 @@ static void TEST_packet_unsuback(void) static void TEST_packet_disconnect(void) { - uint8_t payload[] = {0, + uint8_t payload[] = { + 0, MQTT_PROP_SESSION_EXPIRY_INTERVAL, 0x12, 0x45, 0x00, 0x00, MQTT_PROP_REASON_STRING, 0, 6, 'r', 'e', 'a', 's', 'o', 'n', - MQTT_PROP_USER_PROPERTY, 0, 4, 'n', 'a', 'm', 'e', 0, 5, 'v', 'a', 'l', 'u', 'e'}; + MQTT_PROP_USER_PROPERTY, 0, 4, 'n', 'a', 'm', 'e', 0, 5, 'v', 'a', 'l', 'u', 'e' + }; struct mosquitto__packet_in packet; mosquitto_property *properties, *p; @@ -1857,11 +1872,13 @@ static void TEST_packet_disconnect(void) static void TEST_packet_auth(void) { - uint8_t payload[] = {0, + uint8_t payload[] = { + 0, MQTT_PROP_AUTHENTICATION_METHOD, 0x00, 0x04, 'n', 'o', 'n', 'e', MQTT_PROP_AUTHENTICATION_DATA, 0x00, 0x02, 1, 2, MQTT_PROP_REASON_STRING, 0, 6, 'r', 'e', 'a', 's', 'o', 'n', - MQTT_PROP_USER_PROPERTY, 0, 4, 'n', 'a', 'm', 'e', 0, 5, 'v', 'a', 'l', 'u', 'e'}; + MQTT_PROP_USER_PROPERTY, 0, 4, 'n', 'a', 'm', 'e', 0, 5, 'v', 'a', 'l', 'u', 'e' + }; struct mosquitto__packet_in packet; mosquitto_property *properties, *p; diff --git a/test/unit/libcommon/strings_test.c b/test/unit/libcommon/strings_test.c index d06921f1..b94b36f0 100644 --- a/test/unit/libcommon/strings_test.c +++ b/test/unit/libcommon/strings_test.c @@ -83,12 +83,14 @@ static void TEST_string_to_property_info(void) static void TEST_mosquitto_strerror(void) { const char *str; - int used[] = {-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + int used[] = { + -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, /* 13, */ 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 31, 32, 33, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, - 158, 159, 160, 161, 162}; + 158, 159, 160, 161, 162 + }; /* Iterate over all possible errors, checking we have a place holder for all * unused errors, and that all used errors do not have place holder text. */ @@ -162,10 +164,12 @@ static void TEST_mosquitto_connack_string(void) static void TEST_mosquitto_reason_string(void) { const char *str; - uint8_t used[] = {0, 1, 2, 4, 16, 17, 24, 25, 128, 129, 130, 131, 132, 133, + uint8_t used[] = { + 0, 1, 2, 4, 16, 17, 24, 25, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, - 162}; + 162 + }; /* Iterate over all possible codes, checking we have a place holder for all * unused codes, and that all used codes do not have place holder text. */ @@ -291,5 +295,3 @@ int init_strings_tests(void) return 0; } - -