diff --git a/apps/db_dump/db_dump.c b/apps/db_dump/db_dump.c index deac5285..499660ab 100644 --- a/apps/db_dump/db_dump.c +++ b/apps/db_dump/db_dump.c @@ -177,7 +177,7 @@ static int dump__client_chunk_process(FILE *db_fd, uint32_t length) if(do_json){ json_add_client(&chunk); } - if(do_print) { + if(do_print){ print__client(&chunk, length); } free__client(&chunk); @@ -222,7 +222,7 @@ static int dump__client_msg_chunk_process(FILE *db_fd, uint32_t length) if(do_json){ json_add_client_msg(&chunk); } - if(do_print) { + if(do_print){ print__client_msg(&chunk, length); } free__client_msg(&chunk); @@ -381,7 +381,7 @@ static int dump__sub_chunk_process(FILE *db_fd, uint32_t length) if(do_json){ json_add_subscription(&chunk); } - if(do_print) { + if(do_print){ print__sub(&chunk, length); } free__sub(&chunk); diff --git a/apps/mosquitto_ctrl/ctrl_shell_broker.c b/apps/mosquitto_ctrl/ctrl_shell_broker.c index cfa2805d..4be3501c 100644 --- a/apps/mosquitto_ctrl/ctrl_shell_broker.c +++ b/apps/mosquitto_ctrl/ctrl_shell_broker.c @@ -30,6 +30,7 @@ Contributors: static struct completion_tree_root *commands_broker = NULL; + static void command_tree_create(void) { struct completion_tree_cmd *cmd; diff --git a/apps/mosquitto_ctrl/ctrl_shell_client.c b/apps/mosquitto_ctrl/ctrl_shell_client.c index 978f1640..56a562c4 100644 --- a/apps/mosquitto_ctrl/ctrl_shell_client.c +++ b/apps/mosquitto_ctrl/ctrl_shell_client.c @@ -72,6 +72,7 @@ int ctrl_shell__connect(void) return 0; } + void ctrl_shell__disconnect(void) { if(!data.mosq) return; diff --git a/apps/mosquitto_ctrl/ctrl_shell_completion_tree.c b/apps/mosquitto_ctrl/ctrl_shell_completion_tree.c index 6d21ab1b..056e0aad 100644 --- a/apps/mosquitto_ctrl/ctrl_shell_completion_tree.c +++ b/apps/mosquitto_ctrl/ctrl_shell_completion_tree.c @@ -26,6 +26,7 @@ Contributors: #define UNUSED(A) (void)(A) + void completion_tree_arg_list_args_free(struct completion_tree_arg_list *arg_list) { struct completion_tree_arg *arg, *next; @@ -101,6 +102,7 @@ struct completion_tree_arg_list *completion_tree_cmd_new_arg_list(void) return calloc(1, sizeof(struct completion_tree_arg_list)); } + void completion_tree_cmd_append_arg_list(struct completion_tree_cmd *cmd, struct completion_tree_arg_list *new_list) { struct completion_tree_arg_list **arg_list; @@ -127,6 +129,7 @@ struct completion_tree_arg_list *completion_tree_cmd_add_arg_list(struct complet return new_list; } + void completion_tree_arg_list_add_arg(struct completion_tree_arg_list *arg_list, const char *name) { if(!arg_list || !name) return; diff --git a/apps/mosquitto_ctrl/ctrl_shell_dynsec.c b/apps/mosquitto_ctrl/ctrl_shell_dynsec.c index 12d0932f..e6ed702a 100644 --- a/apps/mosquitto_ctrl/ctrl_shell_dynsec.c +++ b/apps/mosquitto_ctrl/ctrl_shell_dynsec.c @@ -773,7 +773,7 @@ static void print_json_array(cJSON *j_list, const char *label, const char *eleme ctrl_shell_print_value(1, "%s", stmp); if(optional_element_name){ ctrl_shell_print_value(0, " (%s: ", optional_element_name); - print_json_value(cJSON_GetObjectItem(j_elem,optional_element_name),optional_element_null_value); + print_json_value(cJSON_GetObjectItem(j_elem, optional_element_name), optional_element_null_value); ctrl_shell_print_value(0, ")"); } }else if(cJSON_IsString(j_elem) && j_elem->valuestring){ diff --git a/apps/mosquitto_ctrl/ctrl_shell_pre_connect.c b/apps/mosquitto_ctrl/ctrl_shell_pre_connect.c index 624dd317..3c296620 100644 --- a/apps/mosquitto_ctrl/ctrl_shell_pre_connect.c +++ b/apps/mosquitto_ctrl/ctrl_shell_pre_connect.c @@ -137,11 +137,11 @@ static void line_callback(char *line) }else if(!strcasecmp(command, "connect")){ char *url = strtok_r(NULL, " ", &saveptr); if(url){ - if(!strncasecmp(url, "mqtt://", 7)) { + if(!strncasecmp(url, "mqtt://", 7)){ url += 7; data.port = 1883; data.url_scheme = "mqtt"; - } else if(!strncasecmp(url, "mqtts://", 8)) { + }else if(!strncasecmp(url, "mqtts://", 8)){ #ifdef WITH_TLS url += 8; data.port = 8883; @@ -151,12 +151,12 @@ static void line_callback(char *line) free(line); return; #endif - } else if(!strncasecmp(url, "ws://", 5)) { + }else if(!strncasecmp(url, "ws://", 5)){ url += 5; data.port = 1883; data.transport = MOSQ_T_WEBSOCKETS; data.url_scheme = "ws"; - } else if(!strncasecmp(url, "wss://", 6)) { + }else if(!strncasecmp(url, "wss://", 6)){ #ifdef WITH_TLS url += 6; data.port = 8883; diff --git a/apps/mosquitto_ctrl/dynsec.c b/apps/mosquitto_ctrl/dynsec.c index a752a645..aa70b386 100644 --- a/apps/mosquitto_ctrl/dynsec.c +++ b/apps/mosquitto_ctrl/dynsec.c @@ -146,7 +146,7 @@ static void print_json_value(cJSON *value, const char *null_value) printf("%s", buffer); } }else if(null_value){ - printf("%s",null_value); + printf("%s", null_value); } } @@ -166,7 +166,7 @@ static void print_json_array(cJSON *j_list, int slen, const char *label, const c printf("%-*s %s", (int)slen, label, stmp); if(optional_element_name){ printf(" (%s: ", optional_element_name); - print_json_value(cJSON_GetObjectItem(j_elem,optional_element_name),optional_element_null_value); + print_json_value(cJSON_GetObjectItem(j_elem, optional_element_name), optional_element_null_value); printf(")"); } }else if(cJSON_IsString(j_elem) && j_elem->valuestring){ @@ -184,7 +184,7 @@ static void print_json_array(cJSON *j_list, int slen, const char *label, const c static void print_client(cJSON *j_response) { cJSON *j_data, *j_client, *jtmp; - const int label_width = strlen( "Connections:"); + const int label_width = strlen("Connections:"); j_data = cJSON_GetObjectItem(j_response, "data"); if(j_data == NULL || !cJSON_IsObject(j_data)){ @@ -514,6 +514,7 @@ static int dynsec__get_default_acl_access(int argc, char *argv[], cJSON *j_comma * # * ################################################################ */ + static cJSON *init_add_acl_to_role(cJSON *j_acls, const char *type, const char *topic) { cJSON *j_acl; diff --git a/apps/mosquitto_ctrl/options.c b/apps/mosquitto_ctrl/options.c index 818ddb93..dd90791e 100644 --- a/apps/mosquitto_ctrl/options.c +++ b/apps/mosquitto_ctrl/options.c @@ -248,19 +248,19 @@ static int client_config_line_proc(struct mosq_config *cfg, int *argc, char **ar if((*argc) == 1){ fprintf(stderr, "Error: -L argument given but no URL specified.\n\n"); return 1; - } else { + }else{ char *url = argv[1]; char *topic; char *tmp; - if(!strncasecmp(url, "mqtt://", 7)) { + if(!strncasecmp(url, "mqtt://", 7)){ url += 7; cfg->port = 1883; - } else if(!strncasecmp(url, "mqtts://", 8)) { + }else if(!strncasecmp(url, "mqtts://", 8)){ url += 8; cfg->port = 8883; cfg->tls_use_os_certs = true; - } else { + }else{ fprintf(stderr, "Error: Unsupported URL scheme.\n\n"); return 1; } @@ -272,10 +272,10 @@ static int client_config_line_proc(struct mosq_config *cfg, int *argc, char **ar *topic++ = 0; tmp = strchr(url, '@'); - if(tmp) { + if(tmp){ *tmp++ = 0; char *colon = strchr(url, ':'); - if(colon) { + if(colon){ *colon = 0; cfg->password = strdup(colon + 1); } @@ -289,7 +289,7 @@ static int client_config_line_proc(struct mosq_config *cfg, int *argc, char **ar cfg->host = url; tmp = strchr(url, ':'); - if(tmp) { + if(tmp){ *tmp++ = 0; if(strlen(tmp) == 0){ cfg->host = NULL; /* Prevent free of non-heap memory later */ @@ -474,7 +474,7 @@ static int client_config_line_proc(struct mosq_config *cfg, int *argc, char **ar return MOSQ_ERR_SUCCESS; unknown_option: - fprintf(stderr, "Error: Unknown option '%s'.\n",argv[0]); + fprintf(stderr, "Error: Unknown option '%s'.\n", argv[0]); return 1; } @@ -631,7 +631,7 @@ int client_opts_set(struct mosquitto *mosq, struct mosq_config *cfg) return 1; } # ifdef FINAL_WITH_TLS_PSK - }else if (cfg->psk){ + }else if(cfg->psk){ if(mosquitto_tls_psk_set(mosq, cfg->psk, cfg->psk_identity, NULL)){ fprintf(stderr, "Error: Problem setting TLS-PSK options.\n"); mosquitto_lib_cleanup(); diff --git a/client/client_shared.c b/client/client_shared.c index 4c4d949b..651ffe1d 100644 --- a/client/client_shared.c +++ b/client/client_shared.c @@ -757,15 +757,15 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c if(i==argc-1){ fprintf(stderr, "Error: -L argument given but no URL specified.\n\n"); return 1; - } else { + }else{ char *url = argv[i+1]; char *topic; char *tmp; - if(!strncasecmp(url, "mqtt://", 7)) { + if(!strncasecmp(url, "mqtt://", 7)){ url += 7; cfg->port = 1883; - } else if(!strncasecmp(url, "mqtts://", 8)) { + }else if(!strncasecmp(url, "mqtts://", 8)){ #ifdef WITH_TLS url += 8; cfg->port = 8883; @@ -774,11 +774,11 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c fprintf(stderr, "Error: TLS support not available.\n\n"); return 1; #endif - } else if(!strncasecmp(url, "ws://", 5)) { + }else if(!strncasecmp(url, "ws://", 5)){ url += 5; cfg->port = 1883; cfg->transport = MOSQ_T_WEBSOCKETS; - } else if(!strncasecmp(url, "wss://", 6)) { + }else if(!strncasecmp(url, "wss://", 6)){ #ifdef WITH_TLS url += 6; cfg->port = 8883; @@ -788,7 +788,7 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c fprintf(stderr, "Error: TLS support not available.\n\n"); return 1; #endif - } else { + }else{ fprintf(stderr, "Error: Unsupported URL scheme.\n\n"); return 1; } @@ -803,11 +803,11 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c return 1; tmp = strchr(url, '@'); - if(tmp) { + if(tmp){ char *colon; *tmp++ = 0; colon = strchr(url, ':'); - if(colon) { + if(colon){ *colon = 0; cfg->password = strdup(colon + 1); } @@ -817,7 +817,7 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c cfg->host = url; tmp = strchr(url, ':'); - if(tmp) { + if(tmp){ *tmp++ = 0; cfg->port = atoi(tmp); } @@ -1052,11 +1052,11 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c fprintf(stderr, "Error: --retain-handling argument given but no option specified.\n\n"); return 1; }else{ - if(!strcmp(argv[i+1],"always")){ + if(!strcmp(argv[i+1], "always")){ MQTT_SUB_OPT_SET_RETAIN_HANDLING(cfg->sub_opts, MQTT_SUB_OPT_SEND_RETAIN_ALWAYS); - }else if(!strcmp(argv[i+1],"new")){ + }else if(!strcmp(argv[i+1], "new")){ MQTT_SUB_OPT_SET_RETAIN_HANDLING(cfg->sub_opts, MQTT_SUB_OPT_SEND_RETAIN_NEW); - }else if(!strcmp(argv[i+1],"never")){ + }else if(!strcmp(argv[i+1], "never")){ MQTT_SUB_OPT_SET_RETAIN_HANDLING(cfg->sub_opts, MQTT_SUB_OPT_SEND_RETAIN_NEVER); }else{ fprintf(stderr, "Error: Unknown value '%s' for --retain-handling.\n\n", argv[i+1]); @@ -1330,7 +1330,7 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c return MOSQ_ERR_SUCCESS; unknown_option: - fprintf(stderr, "Error: Unknown option '%s'.\n",argv[i]); + fprintf(stderr, "Error: Unknown option '%s'.\n", argv[i]); return 1; } @@ -1769,6 +1769,7 @@ cleanup: } #endif + void err_printf(const struct mosq_config *cfg, const char *fmt, ...) { va_list va; diff --git a/client/sub_client.c b/client/sub_client.c index 724c7705..4d3c1953 100644 --- a/client/sub_client.c +++ b/client/sub_client.c @@ -51,16 +51,17 @@ static HANDLE timeout_h = NULL; #endif #ifdef WIN32 + + void CALLBACK timeout_cb(PVOID lpParameter, BOOLEAN TimerOrWaitFired) { UNUSED(lpParameter); UNUSED(TimerOrWaitFired); - if (connack_received) { + if(connack_received){ process_messages = false; mosquitto_disconnect_v5(g_mosq, MQTT_RC_DISCONNECT_WITH_WILL_MSG, cfg.disconnect_props); - } - else { + }else{ exit(-1); } @@ -464,7 +465,7 @@ int main(int argc, char *argv[]) #ifdef WIN32 Sleep(1000); #else - struct timespec ts = {1,0}; + struct timespec ts = {1, 0}; nanosleep(&ts, NULL); #endif int message_count = message_rate_msg_count; diff --git a/client/sub_client_output.c b/client/sub_client_output.c index a26fba5b..5c5885e7 100644 --- a/client/sub_client_output.c +++ b/client/sub_client_output.c @@ -734,7 +734,7 @@ static void formatted_print(const struct mosq_config *lcfg, const struct mosquit } } - char strf[3] = {0, 0 ,0}; + char strf[3] = {0, 0, 0}; strf[0] = '%'; strf[1] = lcfg->format[i]; strf[2] = 0; diff --git a/lib/actions_unsubscribe.c b/lib/actions_unsubscribe.c index 0c5d7d72..613cfacb 100644 --- a/lib/actions_unsubscribe.c +++ b/lib/actions_unsubscribe.c @@ -34,11 +34,13 @@ int mosquitto_unsubscribe(struct mosquitto *mosq, int *mid, const char *sub) return mosquitto_unsubscribe_multiple(mosq, mid, 1, (char *const *const)&sub, NULL); } + int mosquitto_unsubscribe_v5(struct mosquitto *mosq, int *mid, const char *sub, const mosquitto_property *properties) { return mosquitto_unsubscribe_multiple(mosq, mid, 1, (char *const *const)&sub, properties); } + int mosquitto_unsubscribe_multiple(struct mosquitto *mosq, int *mid, int sub_count, char *const *const sub, const mosquitto_property *properties) { const mosquitto_property *outgoing_properties = NULL; diff --git a/lib/libmosquitto.c b/lib/libmosquitto.c index 5af67b27..c721f207 100644 --- a/lib/libmosquitto.c +++ b/lib/libmosquitto.c @@ -43,6 +43,7 @@ static unsigned int init_refcount = 0; void mosquitto__destroy(struct mosquitto *mosq); + int mosquitto_lib_version(int *major, int *minor, int *revision) { if(major) *major = LIBMOSQUITTO_MAJOR; @@ -51,18 +52,19 @@ int mosquitto_lib_version(int *major, int *minor, int *revision) return LIBMOSQUITTO_VERSION_NUMBER; } + int mosquitto_lib_init(void) { int rc; - if (init_refcount == 0) { + if(init_refcount == 0){ mosquitto_time_init(); #ifdef WIN32 srand((unsigned int)GetTickCount64()); #elif _POSIX_TIMERS>0 && defined(_POSIX_MONOTONIC_CLOCK) struct timespec tp; #ifdef CLOCK_BOOTTIME - if (clock_gettime(CLOCK_BOOTTIME, &tp) != 0) + if(clock_gettime(CLOCK_BOOTTIME, &tp) != 0) #endif clock_gettime(CLOCK_MONOTONIC, &tp); srand((unsigned int)tp.tv_nsec); @@ -79,7 +81,7 @@ int mosquitto_lib_init(void) #endif rc = net__init(); - if (rc != MOSQ_ERR_SUCCESS) { + if(rc != MOSQ_ERR_SUCCESS){ return rc; } } @@ -91,11 +93,11 @@ int mosquitto_lib_init(void) int mosquitto_lib_cleanup(void) { - if (init_refcount == 1) { + if(init_refcount == 1){ net__cleanup(); } - if (init_refcount > 0) { + if(init_refcount > 0){ --init_refcount; } diff --git a/lib/messages_mosq.c b/lib/messages_mosq.c index 13126921..d383807c 100644 --- a/lib/messages_mosq.c +++ b/lib/messages_mosq.c @@ -29,6 +29,7 @@ Contributors: #include "send_mosq.h" #include "util_mosq.h" + void message__cleanup(struct mosquitto_message_all **message) { struct mosquitto_message_all *msg; @@ -172,7 +173,7 @@ void message__reconnect_reset(struct mosquitto *mosq, bool update_quota_only) if(mosq->msgs_out.inflight_quota != 0){ util__decrement_send_quota(mosq); - if (update_quota_only == false){ + if(update_quota_only == false){ if(message->msg.qos == 1){ message->state = mosq_ms_publish_qos1; }else if(message->msg.qos == 2){ diff --git a/lib/net_mosq.c b/lib/net_mosq.c index 5cdbb4f5..81a7e28d 100644 --- a/lib/net_mosq.c +++ b/lib/net_mosq.c @@ -142,7 +142,7 @@ int net__init(void) { #ifdef WIN32 WSADATA wsaData; - if(WSAStartup(MAKEWORD(2,2), &wsaData) != 0){ + if(WSAStartup(MAKEWORD(2, 2), &wsaData) != 0){ return MOSQ_ERR_UNKNOWN; } #endif @@ -233,8 +233,7 @@ int net__socket_close(struct mosquitto *mosq) #endif #if defined(WITH_BROKER) && defined(WITH_WEBSOCKETS) && WITH_WEBSOCKETS == WS_IS_LWS - if(mosq->wsi) - { + if(mosq->wsi){ if(mosq->state != mosq_cs_disconnecting){ mosquitto__set_state(mosq, mosq_cs_disconnect_ws); } @@ -301,7 +300,7 @@ static unsigned int psk_client_callback(SSL *ssl, const char *hint, snprintf(identity, max_identity_len, "%s", mosq->tls_psk_identity); len = mosquitto__hex2bin(mosq->tls_psk, psk, (int)max_psk_len); - if (len < 0) return 0; + if(len < 0) return 0; return (unsigned int)len; } #endif @@ -586,17 +585,17 @@ int net__socket_connect_tls(struct mosquitto *mosq) long res; ERR_clear_error(); - if (mosq->tls_ocsp_required) { + if(mosq->tls_ocsp_required){ /* Note: OCSP is available in all currently supported OpenSSL versions. */ - if ((res=SSL_set_tlsext_status_type(mosq->ssl, TLSEXT_STATUSTYPE_ocsp)) != 1) { + if((res=SSL_set_tlsext_status_type(mosq->ssl, TLSEXT_STATUSTYPE_ocsp)) != 1){ log__printf(mosq, MOSQ_LOG_ERR, "Could not activate OCSP (error: %ld)", res); return MOSQ_ERR_OCSP; } - if ((res=SSL_CTX_set_tlsext_status_cb(mosq->ssl_ctx, mosquitto__verify_ocsp_status_cb)) != 1) { + if((res=SSL_CTX_set_tlsext_status_cb(mosq->ssl_ctx, mosquitto__verify_ocsp_status_cb)) != 1){ log__printf(mosq, MOSQ_LOG_ERR, "Could not activate OCSP (error: %ld)", res); return MOSQ_ERR_OCSP; } - if ((res=SSL_CTX_set_tlsext_status_arg(mosq->ssl_ctx, mosq)) != 1) { + if((res=SSL_CTX_set_tlsext_status_arg(mosq->ssl_ctx, mosq)) != 1){ log__printf(mosq, MOSQ_LOG_ERR, "Could not activate OCSP (error: %ld)", res); return MOSQ_ERR_OCSP; } @@ -733,8 +732,8 @@ static int net__init_ssl_ctx(struct mosquitto *mosq) SSL_CTX_set_options(mosq->ssl_ctx, SSL_OP_NO_COMPRESSION); /* Set ALPN */ - if(mosq->tls_alpn) { - tls_alpn_len = (uint8_t) strnlen(mosq->tls_alpn, 254); + if(mosq->tls_alpn){ + tls_alpn_len = (uint8_t)strnlen(mosq->tls_alpn, 254); tls_alpn_wire[0] = tls_alpn_len; /* first byte is length of string */ memcpy(tls_alpn_wire + 1, mosq->tls_alpn, tls_alpn_len); SSL_CTX_set_alpn_protos(mosq->ssl_ctx, tls_alpn_wire, tls_alpn_len + 1U); @@ -924,7 +923,7 @@ int net__socket_connect_step3(struct mosquitto *mosq, const char *host) /* * required for the SNI resolving */ - if(SSL_set_tlsext_host_name(mosq->ssl, host) != 1) { + if(SSL_set_tlsext_host_name(mosq->ssl, host) != 1){ net__socket_close(mosq); return MOSQ_ERR_TLS; } @@ -958,7 +957,7 @@ int net__socket_connect(struct mosquitto *mosq, const char *host, uint16_t port, if(mosq->tcp_nodelay && port){ int flag = 1; - if(setsockopt(mosq->sock, IPPROTO_TCP, TCP_NODELAY, (const void*)&flag, sizeof(int)) != 0){ + if(setsockopt(mosq->sock, IPPROTO_TCP, TCP_NODELAY, (const void *)&flag, sizeof(int)) != 0){ log__printf(mosq, MOSQ_LOG_WARNING, "Warning: Unable to set TCP_NODELAY."); } } @@ -983,10 +982,9 @@ static void net__handle_ssl(struct mosquitto *mosq, int ret) int err; err = SSL_get_error(mosq->ssl, ret); - if (err == SSL_ERROR_WANT_READ) { + if(err == SSL_ERROR_WANT_READ){ errno = EAGAIN; - } - else if (err == SSL_ERROR_WANT_WRITE) { + }else if(err == SSL_ERROR_WANT_WRITE){ #ifdef WITH_BROKER mux__add_out(mosq); #else diff --git a/lib/net_mosq_ocsp.c b/lib/net_mosq_ocsp.c index dc835ee4..b83ba44d 100644 --- a/lib/net_mosq_ocsp.c +++ b/lib/net_mosq_ocsp.c @@ -75,33 +75,33 @@ int mosquitto__verify_ocsp_status_cb(SSL *ssl, void *arg) /* the following functions expect a const pointer */ cp = (const unsigned char *)p; - if (!cp || len <= 0) { + if(!cp || len <= 0){ log__printf(mosq, MOSQ_LOG_DEBUG, "OCSP: no response"); goto end; } rsp = d2i_OCSP_RESPONSE(NULL, &cp, len); - if (rsp==NULL) { + if(rsp==NULL){ log__printf(mosq, MOSQ_LOG_DEBUG, "OCSP: invalid response"); goto end; } ocsp_status = OCSP_response_status(rsp); - if(ocsp_status != OCSP_RESPONSE_STATUS_SUCCESSFUL) { + 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); goto end; } br = OCSP_response_get1_basic(rsp); - if (!br) { + if(!br){ log__printf(mosq, MOSQ_LOG_DEBUG, "OCSP: invalid response"); goto end; } ch = SSL_get_peer_cert_chain(mosq->ssl); - if (sk_X509_num(ch) <= 0) { + if(sk_X509_num(ch) <= 0){ log__printf(mosq, MOSQ_LOG_ERR, "OCSP: we did not receive certificates of the server (num: %d)", sk_X509_num(ch)); goto end; } @@ -113,12 +113,12 @@ int mosquitto__verify_ocsp_status_cb(SSL *ssl, void *arg) * For all currently supported versions of the OpenSSL project, this is not needed anymore. */ - if ((result2=OCSP_basic_verify(br, ch, st, 0)) <= 0) { + if((result2=OCSP_basic_verify(br, ch, st, 0)) <= 0){ log__printf(mosq, MOSQ_LOG_DEBUG, "OCSP: response verification failed (error: %d)", result2); goto end; } - for(i = 0; i < OCSP_resp_count(br); i++) { + for(i = 0; i < OCSP_resp_count(br); i++){ int cert_status, crl_reason; OCSP_SINGLERESP *single = NULL; @@ -133,10 +133,10 @@ int mosquitto__verify_ocsp_status_cb(SSL *ssl, void *arg) log__printf(mosq, MOSQ_LOG_DEBUG, "OCSP: SSL certificate status: %s (%d)", OCSP_cert_status_str(cert_status), cert_status); - switch(cert_status) { + switch(cert_status){ case V_OCSP_CERTSTATUS_GOOD: /* Note: A OCSP stapling result will be accepted up to 5 minutes after it expired! */ - if(!OCSP_check_validity(thisupd, nextupd, 300L, -1L)) { + if(!OCSP_check_validity(thisupd, nextupd, 300L, -1L)){ log__printf(mosq, MOSQ_LOG_DEBUG, "OCSP: OCSP response has expired"); goto end; } @@ -156,13 +156,13 @@ int mosquitto__verify_ocsp_status_cb(SSL *ssl, void *arg) } } - if (br!=NULL) OCSP_BASICRESP_free(br); - if (rsp!=NULL) OCSP_RESPONSE_free(rsp); + if(br!=NULL) OCSP_BASICRESP_free(br); + if(rsp!=NULL) OCSP_RESPONSE_free(rsp); return 1; /* OK */ end: - if (br!=NULL) OCSP_BASICRESP_free(br); - if (rsp!=NULL) OCSP_RESPONSE_free(rsp); + if(br!=NULL) OCSP_BASICRESP_free(br); + if(rsp!=NULL) OCSP_RESPONSE_free(rsp); return 0; /* Not OK */ } #endif diff --git a/lib/options.c b/lib/options.c index b1b220da..3b502923 100644 --- a/lib/options.c +++ b/lib/options.c @@ -314,7 +314,7 @@ int mosquitto_string_option(struct mosquitto *mosq, enum mosq_opt_t option, cons if(!value) return MOSQ_ERR_INVAL; if(!strcasecmp(value, "pem")){ mosq->tls_keyform = mosq_k_pem; - }else if (!strcasecmp(value, "engine")){ + }else if(!strcasecmp(value, "engine")){ mosq->tls_keyform = mosq_k_engine; }else{ return MOSQ_ERR_INVAL; @@ -329,7 +329,7 @@ int mosquitto_string_option(struct mosquitto *mosq, enum mosq_opt_t option, cons case MOSQ_OPT_TLS_ENGINE_KPASS_SHA1: #if defined(WITH_TLS) && !defined(OPENSSL_NO_ENGINE) && OPENSSL_API_LEVEL < 30000 mosquitto_FREE(mosq->tls_engine_kpass_sha1); - if(mosquitto__hex2bin_sha1(value, (unsigned char**)&str) != MOSQ_ERR_SUCCESS){ + if(mosquitto__hex2bin_sha1(value, (unsigned char **)&str) != MOSQ_ERR_SUCCESS){ return MOSQ_ERR_INVAL; } mosq->tls_engine_kpass_sha1 = str; diff --git a/lib/packet_mosq.c b/lib/packet_mosq.c index dd517f2c..4427d990 100644 --- a/lib/packet_mosq.c +++ b/lib/packet_mosq.c @@ -343,7 +343,7 @@ int packet__write(struct mosquitto *mosq) #endif } #ifdef WITH_BROKER - if (mosq->out_packet == NULL) { + if(mosq->out_packet == NULL){ mux__remove_out(mosq); } #endif diff --git a/lib/send_publish.c b/lib/send_publish.c index b9a212a6..ddc4b08c 100644 --- a/lib/send_publish.c +++ b/lib/send_publish.c @@ -64,12 +64,12 @@ int send__publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint3 { struct mosquitto_base_msg tmp_msg; - tmp_msg.topic = (char *) topic; + tmp_msg.topic = (char *)topic; tmp_msg.payloadlen = payloadlen; - tmp_msg.payload = (void *) payload; + tmp_msg.payload = (void *)payload; tmp_msg.qos = qos; tmp_msg.retain = retain; - tmp_msg.properties = (mosquitto_property *) store_props; + tmp_msg.properties = (mosquitto_property *)store_props; rc = plugin__handle_message_out(mosq, &tmp_msg); @@ -95,9 +95,9 @@ int send__publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint3 "Rejected PUBLISH to %s, quota exceeded.", mosq->id); } - if(payload_changed) mosquitto_free((void *) payload); - if(topic_changed) mosquitto_free((char *) topic); - if(properties_changed) mosquitto_property_free_all((mosquitto_property **) &store_props); + if(payload_changed) mosquitto_free((void *)payload); + if(topic_changed) mosquitto_free((char *)topic); + if(properties_changed) mosquitto_property_free_all((mosquitto_property **)&store_props); return MOSQ_ERR_SUCCESS; } @@ -175,9 +175,9 @@ int send__publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint3 #ifdef WITH_BROKER rc = send__real_publish(mosq, mid, topic, payloadlen, payload, qos, retain, dup, subscription_identifier, store_props, expiry_interval); - if(payload_changed) mosquitto_free((void *) payload); - if(topic_changed) mosquitto_free((char *) topic); - if(properties_changed) mosquitto_property_free_all((mosquitto_property **) &store_props); + if(payload_changed) mosquitto_free((void *)payload); + if(topic_changed) mosquitto_free((char *)topic); + if(properties_changed) mosquitto_property_free_all((mosquitto_property **)&store_props); return rc; #else return send__real_publish(mosq, mid, topic, payloadlen, payload, qos, retain, dup, subscription_identifier, store_props, expiry_interval); diff --git a/lib/socks_mosq.c b/lib/socks_mosq.c index f1e3fe61..939d08cd 100644 --- a/lib/socks_mosq.c +++ b/lib/socks_mosq.c @@ -230,7 +230,7 @@ int socks5__send(struct mosquitto *mosq) if(!packet) return MOSQ_ERR_NOMEM; packet->payload[3 + WS_PACKET_OFFSET] = SOCKS_ATYPE_IP_V4; - memcpy(&(packet->payload[4 + WS_PACKET_OFFSET]), (const void*)&addr_ipv4, 4); + memcpy(&(packet->payload[4 + WS_PACKET_OFFSET]), (const void *)&addr_ipv4, 4); packet->payload[4+4 + WS_PACKET_OFFSET] = MOSQ_MSB(mosq->port); packet->payload[4+4+1 + WS_PACKET_OFFSET] = MOSQ_LSB(mosq->port); }else if(ipv6_pton_result == 1){ @@ -240,7 +240,7 @@ int socks5__send(struct mosquitto *mosq) if(!packet) return MOSQ_ERR_NOMEM; packet->payload[3 + WS_PACKET_OFFSET] = SOCKS_ATYPE_IP_V6; - memcpy(&(packet->payload[4 + WS_PACKET_OFFSET]), (const void*)&addr_ipv6, 16); + memcpy(&(packet->payload[4 + WS_PACKET_OFFSET]), (const void *)&addr_ipv6, 16); packet->payload[4+16 + WS_PACKET_OFFSET] = MOSQ_MSB(mosq->port); packet->payload[4+16+1 + WS_PACKET_OFFSET] = MOSQ_LSB(mosq->port); }else{ diff --git a/lib/util_mosq.c b/lib/util_mosq.c index 67e34ddc..356a8844 100644 --- a/lib/util_mosq.c +++ b/lib/util_mosq.c @@ -180,8 +180,8 @@ int mosquitto__hex2bin(const char *hex, unsigned char *bin, int bin_max_len) size_t i = 0; /* Count the number of leading zero */ - for(i=0; i= bin_max_len){ return 0; } diff --git a/libcommon/file_common.c b/libcommon/file_common.c index 588d20c0..0807ec73 100644 --- a/libcommon/file_common.c +++ b/libcommon/file_common.c @@ -134,7 +134,7 @@ FILE *mosquitto_fopen(const char *path, const char *mode, bool restrict_read) } return fptr; - }else { + }else{ return fopen(buf, mode); } } @@ -304,7 +304,7 @@ char *mosquitto_fgets(char **buf, int *buflen, FILE *stream) } \ }while (0) -int mosquitto_write_file(const char* target_path, bool restrict_read, int (*write_fn)(FILE* fptr, void* user_data), void* user_data, void (*log_fn)(const char* msg)) +int mosquitto_write_file(const char *target_path, bool restrict_read, int (*write_fn)(FILE *fptr, void *user_data), void *user_data, void (*log_fn)(const char *msg)) { int rc = 0; FILE *fptr = NULL; diff --git a/libcommon/password_common.c b/libcommon/password_common.c index 0458da6d..970b7ddf 100644 --- a/libcommon/password_common.c +++ b/libcommon/password_common.c @@ -634,11 +634,13 @@ int mosquitto_pw_decode(struct mosquitto_pw *pw, const char *password) } } + const char *mosquitto_pw_get_encoded(struct mosquitto_pw *pw) { return pw?pw->encoded_password:NULL; } + int mosquitto_pw_set_param(struct mosquitto_pw *pw, int param, int value) { if(!pw) return MOSQ_ERR_INVAL; diff --git a/libcommon/property_common.c b/libcommon/property_common.c index b6d41c52..4b3674e3 100644 --- a/libcommon/property_common.c +++ b/libcommon/property_common.c @@ -982,7 +982,7 @@ BROKER_EXPORT int mosquitto_property_copy_all(mosquitto_property **dest, const m case MQTT_PROP_TYPE_STRING: pnew->value.s.len = src->value.s.len; - pnew->value.s.v = src->value.s.v ? mosquitto_strdup(src->value.s.v) : (char*)mosquitto_calloc(1,1); + pnew->value.s.v = src->value.s.v ? mosquitto_strdup(src->value.s.v) : (char *)mosquitto_calloc(1, 1); if(!pnew->value.s.v){ mosquitto_property_free_all(dest); return MOSQ_ERR_NOMEM; @@ -1003,14 +1003,14 @@ BROKER_EXPORT int mosquitto_property_copy_all(mosquitto_property **dest, const m case MQTT_PROP_TYPE_STRING_PAIR: pnew->value.s.len = src->value.s.len; - pnew->value.s.v = src->value.s.v ? mosquitto_strdup(src->value.s.v) : (char*)mosquitto_calloc(1,1); + pnew->value.s.v = src->value.s.v ? mosquitto_strdup(src->value.s.v) : (char *)mosquitto_calloc(1, 1); if(!pnew->value.s.v){ mosquitto_property_free_all(dest); return MOSQ_ERR_NOMEM; } pnew->name.len = src->name.len; - pnew->name.v = src->name.v ? mosquitto_strdup(src->name.v) : (char*)mosquitto_calloc(1,1); + pnew->name.v = src->name.v ? mosquitto_strdup(src->name.v) : (char *)mosquitto_calloc(1, 1); if(!pnew->name.v){ mosquitto_property_free_all(dest); return MOSQ_ERR_NOMEM; diff --git a/libcommon/strings_common.c b/libcommon/strings_common.c index b9581044..d562d50f 100644 --- a/libcommon/strings_common.c +++ b/libcommon/strings_common.c @@ -28,6 +28,7 @@ Contributors: #include "mosquitto.h" #include "mosquitto/mqtt_protocol.h" + const char *mosquitto_strerror(int mosq_errno) { switch(mosq_errno){ @@ -135,16 +136,17 @@ const char *mosquitto_strerror(int mosq_errno) case MOSQ_ERR_CONNECTION_RATE_EXCEEDED: return "Connection rate exceeded"; default: - if(mosq_errno >= 128) { + if(mosq_errno >= 128){ // If mosq_errno is greater than 127, // a mqtt5_return_code error was used return mosquitto_reason_string(mosq_errno); - } else { + }else{ return "Unknown error"; } } } + const char *mosquitto_connack_string(int connack_code) { switch(connack_code){ @@ -165,6 +167,7 @@ const char *mosquitto_connack_string(int connack_code) } } + const char *mosquitto_reason_string(int reason_code) { switch(reason_code){ diff --git a/libcommon/time_common.c b/libcommon/time_common.c index 33a32924..ae7d7322 100644 --- a/libcommon/time_common.c +++ b/libcommon/time_common.c @@ -47,9 +47,9 @@ void mosquitto_time_init(void) struct timespec tp; #ifdef CLOCK_BOOTTIME - if (clock_gettime(CLOCK_BOOTTIME, &tp) == 0) { + if(clock_gettime(CLOCK_BOOTTIME, &tp) == 0){ time_clock = CLOCK_BOOTTIME; - } else { + }else{ time_clock = CLOCK_MONOTONIC; } #else @@ -66,10 +66,10 @@ time_t mosquitto_time(void) #elif _POSIX_TIMERS>0 && defined(_POSIX_MONOTONIC_CLOCK) struct timespec tp; - if (clock_gettime(time_clock, &tp) == 0) + if(clock_gettime(time_clock, &tp) == 0) return tp.tv_sec; - return (time_t) -1; + return (time_t)-1; #elif defined(__APPLE__) static mach_timebase_info_data_t tb; uint64_t ticks; diff --git a/libcommon/topic_common.c b/libcommon/topic_common.c index e5940340..8f1583fa 100644 --- a/libcommon/topic_common.c +++ b/libcommon/topic_common.c @@ -153,6 +153,7 @@ BROKER_EXPORT int mosquitto_sub_topic_check2(const char *str, size_t len) return MOSQ_ERR_SUCCESS; } + static int topic_matches_sub(const char *sub, const char *topic, const char *clientid, const char *username, bool match_patterns, bool *result) { size_t spos; diff --git a/plugins/dynamic-security/clients.c b/plugins/dynamic-security/clients.c index 991698df..36aa4d56 100644 --- a/plugins/dynamic-security/clients.c +++ b/plugins/dynamic-security/clients.c @@ -893,7 +893,7 @@ static int dynsec__remove_client_from_all_groups(struct dynsec__data *data, cons static int dynsec__add_client_address(const struct mosquitto *client, void *context_ptr) { - struct connection_array_context *functor_context = (struct connection_array_context*)context_ptr; + struct connection_array_context *functor_context = (struct connection_array_context *)context_ptr; const char *username = mosquitto_client_username(client); if((username == NULL && functor_context->username == NULL) diff --git a/plugins/dynamic-security/config.c b/plugins/dynamic-security/config.c index ce7f26c3..84a1f377 100644 --- a/plugins/dynamic-security/config.c +++ b/plugins/dynamic-security/config.c @@ -196,7 +196,7 @@ int dynsec__write_json_config(FILE *fptr, void *user_data) } json_str_len = strlen(json_str); - if (fwrite(json_str, 1, json_str_len, fptr) != json_str_len){ + if(fwrite(json_str, 1, json_str_len, fptr) != json_str_len){ mosquitto_log_printf(MOSQ_LOG_ERR, "Error saving Dynamic security plugin config: Cannot write whole config (%ld) bytes to file %s", json_str_len, data->config_file); rc = MOSQ_ERR_UNKNOWN; } diff --git a/plugins/examples/auth-by-env/mosquitto_auth_by_env.c b/plugins/examples/auth-by-env/mosquitto_auth_by_env.c index afe7f8f7..72687c1b 100644 --- a/plugins/examples/auth-by-env/mosquitto_auth_by_env.c +++ b/plugins/examples/auth-by-env/mosquitto_auth_by_env.c @@ -52,8 +52,7 @@ static int basic_auth_callback(int event, void *event_data, void *userdata) if(!strcmp(ed->password, environment_password)){ /* Password matched MOSQUITTO_PASSWORD */ return MOSQ_ERR_SUCCESS; - } - else{ + }else{ return MOSQ_ERR_PLUGIN_DEFER; } } diff --git a/plugins/persist-sqlite/common.c b/plugins/persist-sqlite/common.c index e6e0c3bd..589f0b06 100644 --- a/plugins/persist-sqlite/common.c +++ b/plugins/persist-sqlite/common.c @@ -23,7 +23,7 @@ Contributors: #include "persist_sqlite.h" -int persist_sqlite__client_msg_remove(struct mosquitto_sqlite *ms, const char* clientid, int64_t store_id, int direction) +int persist_sqlite__client_msg_remove(struct mosquitto_sqlite *ms, const char *clientid, int64_t store_id, int direction) { int rc = 1; diff --git a/plugins/persist-sqlite/init.c b/plugins/persist-sqlite/init.c index 5a62b4a5..955f7bfd 100644 --- a/plugins/persist-sqlite/init.c +++ b/plugins/persist-sqlite/init.c @@ -26,31 +26,30 @@ Contributors: #include "mosquitto/broker.h" -static int extract_version_numbers(void *data_ptr, int num_columns, char** values, char** column_names) +static int extract_version_numbers(void *data_ptr, int num_columns, char **values, char **column_names) { unsigned int found = 0; - int *version_array = (int*)data_ptr; + int *version_array = (int *)data_ptr; - for (int i = 0; i < num_columns; ++i) { - if (!sqlite3_stricmp(column_names[i], "MAJOR")){ + for(int i = 0; i < num_columns; ++i){ + if(!sqlite3_stricmp(column_names[i], "MAJOR")){ version_array[0] = values[i] ? atoi(values[i]) : 0; found |= 0x4; - } - else if (!sqlite3_stricmp(column_names[i], "MINOR")){ + }else if(!sqlite3_stricmp(column_names[i], "MINOR")){ version_array[1] = values[i] ? atoi(values[i]) : 0; found |= 0x2; - } - else if (!sqlite3_stricmp(column_names[i], "PATCH")){ + }else if(!sqlite3_stricmp(column_names[i], "PATCH")){ version_array[2] = values[i] ? atoi(values[i]) : 0; found |= 0x1; } } - if (found != 0x7){ + if(found != 0x7){ return SQLITE_MISMATCH; } return SQLITE_OK; } + static int create_tables_1_1(struct mosquitto_sqlite *ms) { int rc; @@ -206,7 +205,7 @@ static int create_tables(struct mosquitto_sqlite *ms) &extract_version_numbers, db_schema_version, NULL); if(rc) goto fail; - if (db_schema_version[0] == 0){ + 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');", @@ -214,7 +213,7 @@ static int create_tables(struct mosquitto_sqlite *ms) if(rc) goto fail; memcpy(db_schema_version, (int[3]){1, 0, 0}, sizeof(db_schema_version)); } - if (db_schema_version[0] == 1){ + if(db_schema_version[0] == 1){ /* 1.0.x needs to be upgraded to 1.1 */ if (db_schema_version[1] == 0){ rc = create_tables_1_1(ms); @@ -438,7 +437,7 @@ void persist_sqlite__cleanup(struct mosquitto_sqlite *ms) { if(ms->db){ int rc = sqlite3_exec(ms->db, "END;", NULL, NULL, NULL); - if (rc != SQLITE_OK){ + if(rc != SQLITE_OK){ mosquitto_log_printf(MOSQ_LOG_ERR, "Error: Sqlite persistence: Closing final transaction %s", sqlite3_errstr(rc)); } } @@ -464,12 +463,12 @@ void persist_sqlite__cleanup(struct mosquitto_sqlite *ms) sqlite3_finalize(ms->will_remove_stmt); if(ms->db){ - int rc = sqlite3_wal_checkpoint_v2(ms->db,NULL,SQLITE_CHECKPOINT_TRUNCATE,NULL,NULL); - if (rc != SQLITE_OK){ + int rc = sqlite3_wal_checkpoint_v2(ms->db, NULL, SQLITE_CHECKPOINT_TRUNCATE, NULL, NULL); + if(rc != SQLITE_OK){ mosquitto_log_printf(MOSQ_LOG_WARNING, "Warning: Sqlite persistence: Final wal_checkpoint %s", sqlite3_errstr(rc)); } rc = sqlite3_close(ms->db); - if (rc != SQLITE_OK){ + if(rc != SQLITE_OK){ mosquitto_log_printf(MOSQ_LOG_WARNING, "Warning: Sqlite persistence: Error closing database: %s", sqlite3_errstr(rc)); } ms->db = NULL; diff --git a/plugins/persist-sqlite/plugin.c b/plugins/persist-sqlite/plugin.c index a0d9ca8c..98283304 100644 --- a/plugins/persist-sqlite/plugin.c +++ b/plugins/persist-sqlite/plugin.c @@ -105,7 +105,7 @@ int mosquitto_plugin_init(mosquitto_plugin_id_t *identifier, void **user_data, s UNUSED(user_data); - memset(&plg_data, 0,sizeof(struct mosquitto_sqlite)); + memset(&plg_data, 0, sizeof(struct mosquitto_sqlite)); set_defaults(); if(get_db_file(options, option_count)){ diff --git a/plugins/persist-sqlite/restore.c b/plugins/persist-sqlite/restore.c index 8a5fd04f..0f024094 100644 --- a/plugins/persist-sqlite/restore.c +++ b/plugins/persist-sqlite/restore.c @@ -435,33 +435,35 @@ static int retain_restore(struct mosquitto_sqlite *ms) return MOSQ_ERR_SUCCESS; } + static int publish_will_msg(const char *topic, int payloadlen, const void *payload, int qos, bool retain, mosquitto_property *properties) { void *payload_mosq = NULL; int rc; - if (payloadlen){ + if(payloadlen){ payload_mosq = mosquitto_malloc((size_t)payloadlen); - if (!payload_mosq){ + if(!payload_mosq){ return MOSQ_ERR_NOMEM; } memcpy(payload_mosq, payload, (size_t)payloadlen); } rc = mosquitto_broker_publish(NULL, topic, payloadlen, payload_mosq, qos, retain, properties); - if (rc != MOSQ_ERR_SUCCESS){ + if(rc != MOSQ_ERR_SUCCESS){ mosquitto_free(payload_mosq); } return rc; } + static int will_restore(struct mosquitto_sqlite *ms) { sqlite3_stmt *stmt; int rc; long count = 0, failed = 0; const char *clientid, *topic; - const void* payload; + const void *payload; mosquitto_property *properties; int payloadlen, qos, retain; @@ -487,10 +489,10 @@ static int will_restore(struct mosquitto_sqlite *ms) properties = json_to_properties((const char *)sqlite3_column_text(stmt, 6)); rc = mosquitto_client_will_set(clientid, topic, payloadlen, payload, qos, retain, properties); - if (rc == MOSQ_ERR_NOT_FOUND){ + if(rc == MOSQ_ERR_NOT_FOUND){ /* If the client does not exist this is the will message of a non-persistent client. */ rc = publish_will_msg(topic, payloadlen, payload, qos, retain, properties); - } else if (rc == MOSQ_ERR_SUCCESS && (sqlite3_column_int64(stmt, 7) == 0 && sqlite3_column_int64(stmt, 8) == 0)) { + }else if(rc == MOSQ_ERR_SUCCESS && (sqlite3_column_int64(stmt, 7) == 0 && sqlite3_column_int64(stmt, 8) == 0)){ /* If the client is a persistent client and was connected at the moment of a crash and has no will delay we publish it's will message now, but need a new copy of the properties. */ properties = json_to_properties((const char *)sqlite3_column_text(stmt, 6)); diff --git a/plugins/persist-sqlite/will.c b/plugins/persist-sqlite/will.c index 17846c99..6d205d89 100644 --- a/plugins/persist-sqlite/will.c +++ b/plugins/persist-sqlite/will.c @@ -30,13 +30,13 @@ int persist_sqlite__will_add_cb(int event, void *event_data, void *userdata) char *propties_json_str = NULL; UNUSED(event); - if (!ed->data.clientid || !ed->data.topic){ + if(!ed->data.clientid || !ed->data.topic){ return MOSQ_ERR_INVAL; } - + if(ed->data.properties){ propties_json_str = properties_to_json_str(ed->data.properties); - if (!propties_json_str){ + if(!propties_json_str){ return MOSQ_ERR_NOMEM; } } @@ -53,10 +53,11 @@ int persist_sqlite__will_add_cb(int event, void *event_data, void *userdata) rc = sqlite3_single_step_stmt(rc, ms, ms->will_add_stmt); sqlite3_reset(ms->will_add_stmt); mosquitto_free(propties_json_str); - + return rc; } + int persist_sqlite__will_remove_cb(int event, void *event_data, void *userdata) { struct mosquitto_evt_persist_will_msg *ed = event_data; @@ -64,11 +65,11 @@ int persist_sqlite__will_remove_cb(int event, void *event_data, void *userdata) int rc = MOSQ_ERR_SUCCESS; UNUSED(event); - if(sqlite3_bind_text_from_c_str( ms->will_remove_stmt, 1, ed->data.clientid) != SQLITE_OK){ + if(sqlite3_bind_text_from_c_str(ms->will_remove_stmt, 1, ed->data.clientid) != SQLITE_OK){ rc = MOSQ_ERR_UNKNOWN; } rc = sqlite3_single_step_stmt(rc, ms, ms->will_remove_stmt); sqlite3_reset(ms->will_remove_stmt); - + return rc; } diff --git a/src/acl_file.c b/src/acl_file.c index 80a351f9..8815394e 100644 --- a/src/acl_file.c +++ b/src/acl_file.c @@ -69,6 +69,7 @@ int broker_acl_file__init(void) return MOSQ_ERR_SUCCESS; } + void broker_acl_file__cleanup(void) { if(db.config->per_listener_settings){ diff --git a/src/bridge.c b/src/bridge.c index 971378f0..ce6a0e5c 100644 --- a/src/bridge.c +++ b/src/bridge.c @@ -205,12 +205,12 @@ static int bridge__set_tcp_keepalive(struct mosquitto *context) 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)) || + 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; @@ -224,8 +224,8 @@ static int bridge__set_tcp_keepalive(struct mosquitto *context) static int bridge__set_tcp_user_timeout(struct mosquitto *context) { int timeout = context->bridge->tcp_user_timeout; - if(timeout >= 0) { - if(setsockopt(context->sock, IPPROTO_TCP, TCP_USER_TIMEOUT, (char *)&timeout, sizeof(timeout))) { + if(timeout >= 0){ + if(setsockopt(context->sock, IPPROTO_TCP, TCP_USER_TIMEOUT, (char *)&timeout, sizeof(timeout))){ return MOSQ_ERR_UNKNOWN; } } @@ -329,7 +329,7 @@ static int bridge__connect_step1(struct mosquitto *context) log__printf(NULL, MOSQ_LOG_NOTICE, "Connecting bridge (step 1) %s (%s:%d)", context->bridge->name, context->bridge->addresses[context->bridge->cur_address].address, context->bridge->addresses[context->bridge->cur_address].port); rc = net__try_connect_step1(context, context->bridge->addresses[context->bridge->cur_address].address); - if(rc > 0 ){ + if(rc > 0){ if(rc == MOSQ_ERR_TLS){ mux__delete(context); net__socket_close(context); @@ -582,7 +582,7 @@ int bridge__connect(struct mosquitto *context) HASH_ADD(hh_sock, db.contexts_by_sock, sock, sizeof(context->sock), context); - if (bridge__set_tcp_keepalive(context) != MOSQ_ERR_SUCCESS) return MOSQ_ERR_UNKNOWN; + if(bridge__set_tcp_keepalive(context) != MOSQ_ERR_SUCCESS) return MOSQ_ERR_UNKNOWN; #ifdef WITH_TCP_USER_TIMEOUT if(bridge__set_tcp_user_timeout(context)) return MOSQ_ERR_UNKNOWN; #endif @@ -819,7 +819,7 @@ void bridge__cleanup(struct mosquitto *context) if(db.bridge_count == 0){ mosquitto_FREE(db.bridges); }else{ - db.bridges = mosquitto_realloc(db.bridges, (unsigned) db.bridge_count * sizeof(db.bridges[0])); + db.bridges = mosquitto_realloc(db.bridges, (unsigned)db.bridge_count * sizeof(db.bridges[0])); } mosquitto_FREE(context->bridge->name); @@ -915,10 +915,10 @@ static void bridge__update_backoff(struct mosquitto__bridge *bridge) if(!bridge) return; if(!bridge->backoff_cap) return; /* skip if not using jitter */ - if (bridge->connected_at && db.now_s - bridge->connected_at >= bridge->stable_connection_period) { + if(bridge->connected_at && db.now_s - bridge->connected_at >= bridge->stable_connection_period){ log__printf(NULL, MOSQ_LOG_INFO, "Bridge %s connection was stable enough, resetting backoff", bridge->name); bridge__backoff_reset(bridge); - } else { + }else{ bridge__backoff_step(bridge); } diff --git a/src/conf.c b/src/conf.c index f6be5f67..4eaf6f4f 100644 --- a/src/conf.c +++ b/src/conf.c @@ -221,6 +221,7 @@ static int config__create_default_listener(struct mosquitto__config *config, con return MOSQ_ERR_SUCCESS; } + static void conf__set_cur_security_options(struct mosquitto__config *config, struct mosquitto__listener **cur_listener, struct mosquitto__security_options **security_options, const char *option_name) { if(config->per_listener_settings){ @@ -628,7 +629,7 @@ int config__parse_args(struct mosquitto__config *config, int argc, char *argv[]) }else if(!strcmp(argv[i], "--test-config")){ config->test_configuration = true; }else{ - fprintf(stderr, "Error: Unknown option '%s'.\n",argv[i]); + fprintf(stderr, "Error: Unknown option '%s'.\n", argv[i]); print_usage(); return MOSQ_ERR_INVAL; } @@ -1036,7 +1037,7 @@ static int config__read_file_core(struct mosquitto__config *config, bool reload, return MOSQ_ERR_INVAL; } while((token = strtok_r(NULL, " ", &saveptr))){ - if (token[0] == '#'){ + if(token[0] == '#'){ break; } struct bridge_address *new_addresses = mosquitto_realloc(cur_bridge->addresses, sizeof(struct bridge_address)*(size_t)(cur_bridge->address_count+1)); @@ -1429,21 +1430,21 @@ static int config__read_file_core(struct mosquitto__config *config, bool reload, REQUIRE_BRIDGE(token); if(conf__parse_int(&token, "bridge_tcp_keepalive_idle", &tmp_int, &saveptr)) return MOSQ_ERR_INVAL; - if(tmp_int <= 0) { + if(tmp_int <= 0){ log__printf(NULL, MOSQ_LOG_ERR, "Error: invalid TCP keepalive idle value."); return MOSQ_ERR_INVAL; } cur_bridge->tcp_keepalive_idle = (unsigned int)tmp_int; if(conf__parse_int(&token, "bridge_tcp_keepalive_interval", &tmp_int, &saveptr)) return MOSQ_ERR_INVAL; - if(tmp_int <= 0) { + if(tmp_int <= 0){ log__printf(NULL, MOSQ_LOG_ERR, "Error: invalid TCP keepalive interval value."); return MOSQ_ERR_INVAL; } cur_bridge->tcp_keepalive_interval = (unsigned int)tmp_int; if(conf__parse_int(&token, "bridge_tcp_keepalive_counter", &tmp_int, &saveptr)) return MOSQ_ERR_INVAL; - if(tmp_int <= 0) { + if(tmp_int <= 0){ log__printf(NULL, MOSQ_LOG_ERR, "Error: invalid TCP keepalive counter value."); return MOSQ_ERR_INVAL; } @@ -1456,7 +1457,7 @@ static int config__read_file_core(struct mosquitto__config *config, bool reload, REQUIRE_BRIDGE(token); #ifdef WITH_TCP_USER_TIMEOUT if(conf__parse_int(&token, "bridge_tcp_user_timeout", &tmp_int, &saveptr)) return MOSQ_ERR_INVAL; - if(tmp_int < 0) { + if(tmp_int < 0){ log__printf(NULL, MOSQ_LOG_ERR, "Error: invalid TCP user timeout value."); return MOSQ_ERR_INVAL; } @@ -1548,7 +1549,7 @@ static int config__read_file_core(struct mosquitto__config *config, bool reload, }else if(!strcmp(token, "local_cleansession")){ #ifdef WITH_BRIDGE REQUIRE_BRIDGE(token); - if(conf__parse_bool(&token, "local_cleansession", (bool *) &cur_bridge->clean_start_local, &saveptr)) return MOSQ_ERR_INVAL; + if(conf__parse_bool(&token, "local_cleansession", (bool *)&cur_bridge->clean_start_local, &saveptr)) return MOSQ_ERR_INVAL; #else log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Bridge support not available."); #endif @@ -1759,7 +1760,7 @@ static int config__read_file_core(struct mosquitto__config *config, bool reload, /* Look for bind address / unix socket path */ token = strtok_r(NULL, " ", &saveptr); - if (token != NULL && token[0] == '#'){ + if(token != NULL && token[0] == '#'){ token = NULL; } @@ -2372,7 +2373,7 @@ static int config__read_file_core(struct mosquitto__config *config, bool reload, char *kpass_sha = NULL, *kpass_sha_bin = NULL; REQUIRE_LISTENER_OR_DEFAULT_LISTENER(token); if(conf__parse_string(&token, "tls_engine_kpass_sha1", &kpass_sha, &saveptr)) return MOSQ_ERR_INVAL; - if(mosquitto__hex2bin_sha1(kpass_sha, (unsigned char**)&kpass_sha_bin) != MOSQ_ERR_SUCCESS){ + if(mosquitto__hex2bin_sha1(kpass_sha, (unsigned char **)&kpass_sha_bin) != MOSQ_ERR_SUCCESS){ mosquitto_FREE(kpass_sha); return MOSQ_ERR_INVAL; } @@ -2418,7 +2419,7 @@ static int config__read_file_core(struct mosquitto__config *config, bool reload, // Check if the topic is quoted (e.g. for spaces within topic names), but not the // special case of "" if(token[0] == '"' && token [1] != '"'){ - if (strchr(saveptr, '"') == NULL) { + if(strchr(saveptr, '"') == NULL){ log__printf(NULL, MOSQ_LOG_ERR, "Error: Missing closing quote in topic value (%s).", saveptr); return MOSQ_ERR_INVAL; } @@ -2430,7 +2431,7 @@ static int config__read_file_core(struct mosquitto__config *config, bool reload, } topic = mosquitto_malloc(strlen(token) + slen + 1); - if (!topic) { + if(!topic){ log__printf(NULL, MOSQ_LOG_ERR, "Error: Out of memory."); return MOSQ_ERR_NOMEM; } @@ -2442,7 +2443,7 @@ static int config__read_file_core(struct mosquitto__config *config, bool reload, } }else{ topic = mosquitto_strdup(token); - if (!topic) { + if(!topic){ log__printf(NULL, MOSQ_LOG_ERR, "Error: Out of memory."); return MOSQ_ERR_NOMEM; } @@ -2463,7 +2464,7 @@ static int config__read_file_core(struct mosquitto__config *config, bool reload, } token = strtok_r(NULL, " ", &saveptr); if(token){ - if (token[0] == '#'){ + if(token[0] == '#'){ (void)strtok_r(NULL, "", &saveptr); } qos = (uint8_t)atoi(token); @@ -2477,7 +2478,7 @@ static int config__read_file_core(struct mosquitto__config *config, bool reload, if(token){ if(!strcmp(token, "\"\"") || token[0] == '#'){ local_prefix = NULL; - if (token[0] == '#'){ + if(token[0] == '#'){ (void)strtok_r(NULL, "", &saveptr); } }else{ diff --git a/src/context.c b/src/context.c index d1066411..74d5cb90 100644 --- a/src/context.c +++ b/src/context.c @@ -234,7 +234,7 @@ void context__send_will(struct mosquitto *ctxt) &ctxt->will->properties); } } - + will__clear(ctxt); } @@ -249,7 +249,8 @@ void context__disconnect(struct mosquitto *context, int reason) if(context->transport == mosq_t_ws){ uint8_t buf[4] = {0x88, 0x02, 0x03, context->wsd.disconnect_reason}; /* Send the disconnect reason, but don't care if it fails */ - if(send(context->sock, buf, 4, 0)){}; + if(send(context->sock, buf, 4, 0)){ + } } #endif diff --git a/src/database.c b/src/database.c index 7baec515..dd8467de 100644 --- a/src/database.c +++ b/src/database.c @@ -614,7 +614,7 @@ int db__message_insert_outgoing(struct mosquitto *context, uint64_t cmsg_id, uin return 2; } }else{ - if (db__ready_for_queue(context, qos, msg_data)){ + if(db__ready_for_queue(context, qos, msg_data)){ state = mosq_ms_queued; }else{ metrics__int_inc(mosq_counter_mqtt_publish_dropped, 1); @@ -735,12 +735,13 @@ static inline int db__message_update_outgoing_state(struct mosquitto *context, s return MOSQ_ERR_NOT_FOUND; } + int db__message_update_outgoing(struct mosquitto *context, uint16_t mid, enum mosquitto_msg_state state, int qos, bool persist) { int rc; rc = db__message_update_outgoing_state(context, context->msgs_out.inflight, mid, state, qos, persist); - if (!persist && rc == MOSQ_ERR_NOT_FOUND){ + if(!persist && rc == MOSQ_ERR_NOT_FOUND){ rc = db__message_update_outgoing_state(context, context->msgs_out.queued, mid, state, qos, persist); } return rc; @@ -1145,14 +1146,14 @@ int db__message_reconnect_reset(struct mosquitto *context) } -int db__message_remove_incoming(struct mosquitto* context, uint16_t mid) +int db__message_remove_incoming(struct mosquitto *context, uint16_t mid) { struct mosquitto__client_msg *client_msg, *tmp; if(!context) return MOSQ_ERR_INVAL; DL_FOREACH_SAFE(context->msgs_in.inflight, client_msg, tmp){ - if(client_msg->data.mid == mid) { + if(client_msg->data.mid == mid){ if(client_msg->base_msg->data.qos != 2){ return MOSQ_ERR_PROTOCOL; } diff --git a/src/handle_connect.c b/src/handle_connect.c index c82dbf11..87630c08 100644 --- a/src/handle_connect.c +++ b/src/handle_connect.c @@ -313,7 +313,7 @@ int connect__on_authorised(struct mosquitto *context, void *auth_data_out, uint1 if(context->session_expiry_interval != 0){ plugin_persist__handle_client_add(context); - }else if (context->will){ + }else if(context->will){ plugin_persist__handle_will_add(context); } } @@ -597,7 +597,7 @@ static int read_and_verify_v5_connect_properties(struct mosquitto *context, mosq }else if(rc == MOSQ_ERR_MALFORMED_PACKET){ send__connack(context, 0, MQTT_RC_MALFORMED_PACKET, NULL); } - if(rc) { + if(rc){ return rc; } } @@ -698,13 +698,13 @@ static int read_and_verify_clientid_from_packet(struct mosquitto *context, char* if(slen == 0){ rc = handle_zero_length_clientid(context, clientid, allow_zero_length_clientid, clean_start); - if (rc != MOSQ_ERR_SUCCESS) { + if(rc != MOSQ_ERR_SUCCESS){ return rc; } } rc = check_clientid_prefixes(context, *clientid); - if (rc != MOSQ_ERR_SUCCESS) { + if(rc != MOSQ_ERR_SUCCESS){ return rc; } @@ -763,7 +763,7 @@ static int read_and_verify_client_credentials_from_packet(struct mosquitto *cont if(username_flag){ rc = set_username_from_packet(context, username); - if (rc != MOSQ_ERR_SUCCESS) { + if(rc != MOSQ_ERR_SUCCESS){ return rc; } }else{ @@ -777,7 +777,7 @@ static int read_and_verify_client_credentials_from_packet(struct mosquitto *cont } if(password_flag){ rc = set_password_from_packet(context, password); - if (rc != MOSQ_ERR_SUCCESS) { + if(rc != MOSQ_ERR_SUCCESS){ return rc; } } @@ -839,7 +839,7 @@ static int set_username_from_cert_identity(struct mosquitto *context) X509 *client_cert = NULL; X509_NAME *name = NULL; - if(get_client_cert_and_subject_name(context, &client_cert, &name)) { + if(get_client_cert_and_subject_name(context, &client_cert, &name)){ return MOSQ_ERR_AUTH; } @@ -857,11 +857,11 @@ static int set_username_from_cert_identity(struct mosquitto *context) ASN1_STRING *name_asn1 = NULL; name_asn1 = X509_NAME_ENTRY_get_data(name_entry); - if (name_asn1 == NULL) { + if(name_asn1 == NULL){ return free_x509_and_send_connack_error(context, client_cert, MOSQ_ERR_AUTH); } const char *cert_identity = NULL; - cert_identity = (char *) ASN1_STRING_get0_data(name_asn1); + cert_identity = (char *)ASN1_STRING_get0_data(name_asn1); if(mosquitto_validate_utf8(cert_identity, (int)strlen(cert_identity))){ return free_x509_and_send_connack_error(context, client_cert, MOSQ_ERR_AUTH); } @@ -871,7 +871,7 @@ static int set_username_from_cert_identity(struct mosquitto *context) return free_x509_and_send_connack_error(context, client_cert, MOSQ_ERR_NOMEM); } /* Make sure there isn't an embedded NUL character in the CN */ - if ((size_t)ASN1_STRING_length(name_asn1) != strlen(context->username)) { + if((size_t)ASN1_STRING_length(name_asn1) != strlen(context->username)){ return free_x509_and_send_connack_error(context, client_cert, MOSQ_ERR_AUTH); } @@ -887,7 +887,7 @@ static int set_username_from_cert_subject_name(struct mosquitto *context) X509 *client_cert = NULL; X509_NAME *name = NULL; - if(get_client_cert_and_subject_name(context, &client_cert, &name)) { + if(get_client_cert_and_subject_name(context, &client_cert, &name)){ return MOSQ_ERR_AUTH; } @@ -947,12 +947,12 @@ static int handle_username_from_cert_options(struct mosquitto *context, char **u }else #endif /* FINAL_WITH_TLS_PSK */ { - if (context->listener->use_identity_as_username) { + if(context->listener->use_identity_as_username){ rc = set_username_from_cert_identity(context); - } else { /* use_subject_as_username */ + }else{ /* use_subject_as_username */ rc = set_username_from_cert_subject_name(context); } - if(rc) { + if(rc){ return rc; } } @@ -1037,20 +1037,20 @@ int handle__connect(struct mosquitto *context) } rc = read_protocol_name(context, protocol_name); - if (rc != MOSQ_ERR_SUCCESS) { + if(rc != MOSQ_ERR_SUCCESS){ goto handle_connect_error; } rc = read_and_verify_protocol_version(context, protocol_name, &protocol_version); - if (rc != MOSQ_ERR_SUCCESS) { - if (rc == MOSQ_ERR_MALFORMED_PACKET) { + if(rc != MOSQ_ERR_SUCCESS){ + if(rc == MOSQ_ERR_MALFORMED_PACKET){ return rc; } goto handle_connect_error; } rc = read_and_verify_connect_flags(context, &connect_flags); - if (rc != MOSQ_ERR_SUCCESS) { + if(rc != MOSQ_ERR_SUCCESS){ goto handle_connect_error; } @@ -1058,12 +1058,12 @@ int handle__connect(struct mosquitto *context) set_session_expiry_interval(context, clean_start, protocol_version); rc = read_and_reset_keepalive(context); - if (rc != MOSQ_ERR_SUCCESS) { + if(rc != MOSQ_ERR_SUCCESS){ goto handle_connect_error; } rc = read_and_verify_v5_connect_properties(context, &properties, protocol_version); - if (rc != MOSQ_ERR_SUCCESS) { + if(rc != MOSQ_ERR_SUCCESS){ goto handle_connect_error; } @@ -1071,7 +1071,7 @@ int handle__connect(struct mosquitto *context) will_qos = (connect_flags & 0x18) >> 3; will_retain = ((connect_flags & 0x20) == 0x20); rc = verify_will_options(context, will, will_qos, will_retain, protocol_version); - if (rc != MOSQ_ERR_SUCCESS) { + if(rc != MOSQ_ERR_SUCCESS){ goto handle_connect_error; } @@ -1086,7 +1086,7 @@ int handle__connect(struct mosquitto *context) } rc = read_and_verify_clientid_from_packet(context, &clientid, &allow_zero_length_clientid, clean_start); - if (rc != MOSQ_ERR_SUCCESS) { + if(rc != MOSQ_ERR_SUCCESS){ goto handle_connect_error; } @@ -1115,12 +1115,12 @@ int handle__connect(struct mosquitto *context) password_flag = connect_flags & 0x40; username_flag = connect_flags & 0x80; rc = read_and_verify_client_credentials_from_packet(context, &username, username_flag, &password, password_flag, clientid); - if (rc != MOSQ_ERR_SUCCESS) { + if(rc != MOSQ_ERR_SUCCESS){ goto handle_connect_error; } rc = check_additional_trailing_data(context, protocol_version); - if (rc != MOSQ_ERR_SUCCESS) { + if(rc != MOSQ_ERR_SUCCESS){ goto handle_connect_error; } @@ -1132,14 +1132,14 @@ int handle__connect(struct mosquitto *context) /* use_identity_as_username or use_subject_as_username */ rc = handle_username_from_cert_options(context, &username, &password); - if (rc != MOSQ_ERR_SUCCESS) { + if(rc != MOSQ_ERR_SUCCESS){ goto handle_connect_error; } /* use_username_as_clientid */ if(context->listener->use_username_as_clientid){ rc = handle_username_as_clientid_option(context); - if (rc != MOSQ_ERR_SUCCESS) { + if(rc != MOSQ_ERR_SUCCESS){ goto handle_connect_error; } } diff --git a/src/http_api.c b/src/http_api.c index fe5ecf58..f4b2a033 100644 --- a/src/http_api.c +++ b/src/http_api.c @@ -299,7 +299,7 @@ static enum MHD_Result http_api__process_file(struct mosquitto__listener *listen if(!S_ISREG(statbuf.st_mode)){ fclose(fptr); http_api__send_error_response(connection, "Not found.\n", 404); - return MHD_YES; + return MHD_YES; } uint64_t flen = (uint64_t )statbuf.st_size; diff --git a/src/logging.c b/src/logging.c index 5e51b4d2..6dc19044 100644 --- a/src/logging.c +++ b/src/logging.c @@ -46,7 +46,7 @@ HANDLE syslog_h; #ifdef ANDROID #include -static const char* LOG_TAG = "mosquitto"; +static const char *LOG_TAG = "mosquitto"; #endif static char log_fptr_buffer[BUFSIZ]; @@ -144,7 +144,7 @@ int log__init(struct mosquitto__config *config) if(log_destinations & MQTT3_LOG_DLT){ dlt_fifo_check(); if(dlt_allowed){ - DLT_REGISTER_APP("MQTT","mosquitto log"); + DLT_REGISTER_APP("MQTT", "mosquitto log"); dlt_register_context(&dltContext, "MQTT", "mosquitto DLT context"); } } @@ -184,7 +184,7 @@ int log__close(struct mosquitto__config *config) DltLogLevelType get_dlt_level(unsigned int priority) { - switch (priority) { + switch(priority){ case MOSQ_LOG_ERR: return DLT_LOG_ERROR; case MOSQ_LOG_WARNING: @@ -208,7 +208,7 @@ DltLogLevelType get_dlt_level(unsigned int priority) android_LogPriority get_android_level(unsigned int priority) { - switch (priority) { + switch(priority){ case MOSQ_LOG_ERR: return ANDROID_LOG_ERROR; case MOSQ_LOG_WARNING: diff --git a/src/loop.c b/src/loop.c index 49cc912d..662e6d2e 100644 --- a/src/loop.c +++ b/src/loop.c @@ -65,6 +65,7 @@ void lws__sul_callback(struct lws_sorted_usec_list *l) static struct lws_sorted_usec_list sul; #endif + static int single_publish(struct mosquitto *context, struct mosquitto__message_v5 *pub_msg, uint32_t message_expiry) { struct mosquitto__base_msg *base_msg; diff --git a/src/mux_epoll.c b/src/mux_epoll.c index fa23620f..8d2b9bcb 100644 --- a/src/mux_epoll.c +++ b/src/mux_epoll.c @@ -48,7 +48,7 @@ int mux_epoll__init(void) memset(&ep_events, 0, sizeof(struct epoll_event)*MAX_EVENTS); db.epollfd = 0; - if ((db.epollfd = epoll_create(MAX_EVENTS)) == -1) { + if((db.epollfd = epoll_create(MAX_EVENTS)) == -1){ log__printf(NULL, MOSQ_LOG_ERR, "Error in epoll creating: %s", strerror(errno)); return MOSQ_ERR_UNKNOWN; } @@ -65,7 +65,7 @@ int mux_epoll__add_listeners(struct mosquitto__listener_sock *listensock, int li memset(&ev, 0, sizeof(struct epoll_event)); ev.data.ptr = &listensock[i]; ev.events = EPOLLIN; - if (epoll_ctl(db.epollfd, EPOLL_CTL_ADD, listensock[i].sock, &ev) == -1) { + if(epoll_ctl(db.epollfd, EPOLL_CTL_ADD, listensock[i].sock, &ev) == -1){ log__printf(NULL, MOSQ_LOG_ERR, "Error in epoll initial registering: %s", strerror(errno)); return MOSQ_ERR_UNKNOWN; } @@ -78,7 +78,7 @@ int mux_epoll__add_listeners(struct mosquitto__listener_sock *listensock, int li int mux_epoll__delete_listeners(struct mosquitto__listener_sock *listensock, int listensock_count) { for(int i=0; ievents & EPOLLOUT)) { + if(!(context->events & EPOLLOUT)){ struct epoll_event ev; memset(&ev, 0, sizeof(struct epoll_event)); ev.data.ptr = context; ev.events = EPOLLIN | EPOLLOUT; - if(epoll_ctl(db.epollfd, EPOLL_CTL_MOD, context->sock, &ev) == -1) { - if((errno != ENOENT)||(epoll_ctl(db.epollfd, EPOLL_CTL_ADD, context->sock, &ev) == -1)) { + if(epoll_ctl(db.epollfd, EPOLL_CTL_MOD, context->sock, &ev) == -1){ + if((errno != ENOENT)||(epoll_ctl(db.epollfd, EPOLL_CTL_ADD, context->sock, &ev) == -1)){ log__printf(NULL, MOSQ_LOG_DEBUG, "Error in epoll re-registering to EPOLLOUT: %s", strerror(errno)); } } @@ -108,14 +108,14 @@ int mux_epoll__add_out(struct mosquitto *context) int mux_epoll__remove_out(struct mosquitto *context) { - if(context->events & EPOLLOUT) { + if(context->events & EPOLLOUT){ struct epoll_event ev; memset(&ev, 0, sizeof(struct epoll_event)); ev.data.ptr = context; ev.events = EPOLLIN; - if(epoll_ctl(db.epollfd, EPOLL_CTL_MOD, context->sock, &ev) == -1) { - if((errno != ENOENT)||(epoll_ctl(db.epollfd, EPOLL_CTL_ADD, context->sock, &ev) == -1)) { + if(epoll_ctl(db.epollfd, EPOLL_CTL_MOD, context->sock, &ev) == -1){ + if((errno != ENOENT)||(epoll_ctl(db.epollfd, EPOLL_CTL_ADD, context->sock, &ev) == -1)){ log__printf(NULL, MOSQ_LOG_DEBUG, "Error in epoll re-registering to EPOLLIN: %s", strerror(errno)); } } @@ -132,7 +132,7 @@ int mux_epoll__new(struct mosquitto *context) memset(&ev, 0, sizeof(struct epoll_event)); ev.events = EPOLLIN; ev.data.ptr = context; - if (epoll_ctl(db.epollfd, EPOLL_CTL_ADD, context->sock, &ev) == -1) { + if(epoll_ctl(db.epollfd, EPOLL_CTL_ADD, context->sock, &ev) == -1){ if(errno != EEXIST){ log__printf(NULL, MOSQ_LOG_ERR, "Error in epoll accepting: %s", strerror(errno)); } diff --git a/src/mux_kqueue.c b/src/mux_kqueue.c index acc48742..6cc7db79 100644 --- a/src/mux_kqueue.c +++ b/src/mux_kqueue.c @@ -40,7 +40,7 @@ int mux_kqueue__init(void) memset(&event_list, 0, sizeof(struct kevent)*MAX_EVENTS); db.kqueuefd = 0; - if ((db.kqueuefd = kqueue()) == -1) { + if((db.kqueuefd = kqueue()) == -1){ log__printf(NULL, MOSQ_LOG_ERR, "Error in kqueue creating: %s", strerror(errno)); return MOSQ_ERR_UNKNOWN; } diff --git a/src/mux_poll.c b/src/mux_poll.c index 012d4fad..6041dd1d 100644 --- a/src/mux_poll.c +++ b/src/mux_poll.c @@ -74,7 +74,7 @@ int mux_poll__init(void) return MOSQ_ERR_NOMEM; } memset(pollfds, 0, sizeof(struct pollfd)*pollfd_max); - for(size_t i=0; ievents == evt){ return MOSQ_ERR_SUCCESS; @@ -128,7 +128,7 @@ static int mux_poll__add(struct mosquitto* context, uint16_t evt) pollfds[context->pollfd_index].events = (short int)evt; pollfds[context->pollfd_index].revents = 0; }else{ - for(size_t i=0; isock; pollfds[i].events = POLLIN; @@ -155,7 +155,7 @@ int mux_poll__add_out(struct mosquitto *context) int mux_poll__remove_out(struct mosquitto *context) { - if(context->events & POLLOUT) { + if(context->events & POLLOUT){ return mux_poll__new(context); }else{ return MOSQ_ERR_SUCCESS; diff --git a/src/net.c b/src/net.c index f75624e0..ef8f649e 100644 --- a/src/net.c +++ b/src/net.c @@ -176,7 +176,7 @@ struct mosquitto *net__socket_accept(struct mosquitto__listener_sock *listensock if(db.config->set_tcp_nodelay && listensock->listener->port){ int flag = 1; #ifdef WIN32 - if (setsockopt(new_sock, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)) != 0) { + if(setsockopt(new_sock, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)) != 0){ #else if(setsockopt(new_sock, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(int)) != 0){ #endif @@ -330,7 +330,7 @@ static unsigned int psk_server_callback(SSL *ssl, const char *identity, unsigned } len = mosquitto__hex2bin(psk_key, psk, (int)max_psk_len); - if (len < 0){ + if(len < 0){ mosquitto_FREE(psk_key); return 0; } @@ -777,7 +777,7 @@ static int net__socket_listen_tcp(struct mosquitto__listener *listener) hints.ai_socktype = SOCK_STREAM; rc = getaddrinfo(listener->host, service, &hints, &ainfo); - if (rc){ + if(rc){ log__printf(NULL, MOSQ_LOG_ERR, "Error creating listener: %s.", gai_strerror(rc)); return INVALID_SOCKET; } diff --git a/src/password_file.c b/src/password_file.c index c1b2671d..ab6a9092 100644 --- a/src/password_file.c +++ b/src/password_file.c @@ -64,6 +64,7 @@ int broker_password_file__init(void) return MOSQ_ERR_SUCCESS; } + void broker_password_file__cleanup(void) { if(db.config->per_listener_settings){ diff --git a/src/persist_read.c b/src/persist_read.c index e21a2666..62f7f34b 100644 --- a/src/persist_read.c +++ b/src/persist_read.c @@ -38,7 +38,7 @@ Contributors: uint32_t db_version; -const unsigned char magic[15] = {0x00, 0xB5, 0x00, 'm','o','s','q','u','i','t','t','o',' ','d','b'}; +const unsigned char magic[15] = {0x00, 0xB5, 0x00, 'm', 'o', 's', 'q', 'u', 'i', 't', 't', 'o', ' ', 'd', 'b'}; static long base_msg_count = 0; static long retained_count = 0; static long client_count = 0; diff --git a/src/persist_write.c b/src/persist_write.c index 554020be..d48614ae 100644 --- a/src/persist_write.c +++ b/src/persist_write.c @@ -316,9 +316,10 @@ static int persist__retain_save_all(FILE *db_fptr) return MOSQ_ERR_SUCCESS; } -static int persist__write_data(FILE* db_fptr, void* user_data); +static int persist__write_data(FILE *db_fptr, void *user_data); -static void persist__log_write_error(const char* msg) + +static void persist__log_write_error(const char *msg) { log__printf(NULL, MOSQ_LOG_ERR, "Error saving in-memory database, %s", msg); } @@ -338,10 +339,10 @@ int persist__backup(bool shutdown) static int persist__write_data(FILE *db_fptr, void *user_data) { - bool shutdown = *(bool*)(user_data); + bool shutdown = *(bool *)(user_data); uint32_t db_version_w = htonl(MOSQ_DB_VERSION); uint32_t crc = 0; - const char* err; + const char *err; struct PF_cfg cfg_chunk; int rc = MOSQ_ERR_UNKNOWN; @@ -362,7 +363,7 @@ static int persist__write_data(FILE *db_fptr, void *user_data) goto error; } - if (persist__client_save(db_fptr) + if(persist__client_save(db_fptr) || persist__subs_save_all(db_fptr) || persist__retain_save_all(db_fptr)){ goto error; diff --git a/src/plugin_acl_check.c b/src/plugin_acl_check.c index 41a48034..c651b453 100644 --- a/src/plugin_acl_check.c +++ b/src/plugin_acl_check.c @@ -100,7 +100,7 @@ static int acl__check_dollar(const char *topic, int access) } -static int plugin__acl_check(struct mosquitto__security_options *opts, struct mosquitto *context, const char *topic, uint32_t payloadlen, void* payload, uint8_t qos, bool retain, int access) +static int plugin__acl_check(struct mosquitto__security_options *opts, struct mosquitto *context, const char *topic, uint32_t payloadlen, void *payload, uint8_t qos, bool retain, int access) { int rc = MOSQ_ERR_PLUGIN_DEFER; struct mosquitto_acl_msg msg; @@ -135,7 +135,8 @@ static int plugin__acl_check(struct mosquitto__security_options *opts, struct mo return rc; } -int mosquitto_acl_check(struct mosquitto *context, const char *topic, uint32_t payloadlen, void* payload, uint8_t qos, bool retain, int access) + +int mosquitto_acl_check(struct mosquitto *context, const char *topic, uint32_t payloadlen, void *payload, uint8_t qos, bool retain, int access) { int rc; int rc_final; diff --git a/src/plugin_init.c b/src/plugin_init.c index 7d03ba80..793a4014 100644 --- a/src/plugin_init.c +++ b/src/plugin_init.c @@ -48,7 +48,7 @@ void LIB_ERROR(void) static int plugin__load_single(mosquitto_plugin_id_t *plugin) { void *lib; - int (*plugin_version)(int, const int*) = NULL; + int (*plugin_version)(int, const int *) = NULL; int (*plugin_auth_version)(void) = NULL; int version; int rc; diff --git a/src/plugin_persist.c b/src/plugin_persist.c index 60f45af6..1032032b 100644 --- a/src/plugin_persist.c +++ b/src/plugin_persist.c @@ -75,7 +75,7 @@ void plugin_persist__handle_client_add(struct mosquitto *context) cb_base->cb(MOSQ_EVT_PERSIST_CLIENT_ADD, &event_data, cb_base->userdata); } - if (context->will){ + if(context->will){ plugin_persist__handle_will_add(context); } @@ -116,7 +116,7 @@ void plugin_persist__handle_client_update(struct mosquitto *context) cb_base->cb(MOSQ_EVT_PERSIST_CLIENT_UPDATE, &event_data, cb_base->userdata); } - if (context->will){ + if(context->will){ plugin_persist__handle_will_add(context); }else{ plugin_persist__handle_will_delete(context); diff --git a/src/plugin_public.c b/src/plugin_public.c index 4fc621c6..30c55304 100644 --- a/src/plugin_public.c +++ b/src/plugin_public.c @@ -524,7 +524,7 @@ BROKER_EXPORT int mosquitto_persist_client_add(struct mosquitto_client *client) } context__add_to_by_id(context); - session_expiry__add_from_persistence(context,context->session_expiry_time); + session_expiry__add_from_persistence(context, context->session_expiry_time); return MOSQ_ERR_SUCCESS; error: @@ -871,20 +871,21 @@ BROKER_EXPORT int mosquitto_broker_node_id_set(uint16_t id) } } + BROKER_EXPORT const char *mosquitto_persistence_location(void) { return db.config->persistence_location; } -BROKER_EXPORT int mosquitto_client_will_set(const char* clientid, const char *topic, int payloadlen, const void *payload, int qos, bool retain, mosquitto_property *properties) +BROKER_EXPORT int mosquitto_client_will_set(const char *clientid, const char *topic, int payloadlen, const void *payload, int qos, bool retain, mosquitto_property *properties) { - struct mosquitto* mosq = mosquitto_client(clientid); - if (!mosq){ + struct mosquitto *mosq = mosquitto_client(clientid); + if(!mosq){ return MOSQ_ERR_NOT_FOUND; } - if (properties && mosq->protocol != mosq_p_mqtt5){ - if (net__is_connected(mosq)) { + if(properties && mosq->protocol != mosq_p_mqtt5){ + if(net__is_connected(mosq)){ return MOSQ_ERR_NOT_SUPPORTED; } mosq->protocol = mosq_p_mqtt5; diff --git a/src/proxy_v2.c b/src/proxy_v2.c index f0676538..3c69b63d 100644 --- a/src/proxy_v2.c +++ b/src/proxy_v2.c @@ -198,7 +198,7 @@ int proxy_v2__read(struct mosquitto *context) context->proxy.len = ntohs(hdr.len); if(context->proxy.len > 0){ /* PROXY_PACKET_LIMIT=500 bytes, arbitrary upper limit */ - switch (context->proxy.fam){ + switch(context->proxy.fam){ case PROXY_TCP_IPV4: if(context->proxy.len < 12 || context->proxy.len > PROXY_PACKET_LIMIT){ return MOSQ_ERR_INVAL; diff --git a/src/psk_file.c b/src/psk_file.c index 93ef905e..c968e244 100644 --- a/src/psk_file.c +++ b/src/psk_file.c @@ -70,6 +70,7 @@ int psk_file__init(void) return MOSQ_ERR_SUCCESS; } + int psk_file__cleanup(void) { int rc; diff --git a/src/retain.c b/src/retain.c index 8a4dbf1e..6c04f3d8 100644 --- a/src/retain.c +++ b/src/retain.c @@ -249,9 +249,9 @@ static int retain__process(struct mosquitto__retainhier *branch, struct mosquitt } sub_qos = sub->options & 0x03; - if (db.config->upgrade_outgoing_qos){ + if(db.config->upgrade_outgoing_qos){ qos = sub_qos; - } else { + }else{ qos = retained->data.qos; if(qos > sub_qos) qos = sub_qos; } diff --git a/src/security_default.c b/src/security_default.c index bc53f433..80699f01 100644 --- a/src/security_default.c +++ b/src/security_default.c @@ -207,7 +207,7 @@ int mosquitto_security_apply_default(void) security__disconnect_auth(context); continue; } - if (context->listener->use_identity_as_username) { /* use_identity_as_username */ + if(context->listener->use_identity_as_username){ /* use_identity_as_username */ int i = X509_NAME_get_index_by_NID(name, NID_commonName, -1); if(i == -1){ X509_free(client_cert); @@ -217,25 +217,25 @@ int mosquitto_security_apply_default(void) name_entry = X509_NAME_get_entry(name, i); if(name_entry){ name_asn1 = X509_NAME_ENTRY_get_data(name_entry); - if (name_asn1 == NULL) { + if(name_asn1 == NULL){ X509_free(client_cert); security__disconnect_auth(context); continue; } - context->username = mosquitto_strdup((char *) ASN1_STRING_get0_data(name_asn1)); + context->username = mosquitto_strdup((char *)ASN1_STRING_get0_data(name_asn1)); if(!context->username){ X509_free(client_cert); security__disconnect_auth(context); continue; } /* Make sure there isn't an embedded NUL character in the CN */ - if ((size_t)ASN1_STRING_length(name_asn1) != strlen(context->username)) { + if((size_t)ASN1_STRING_length(name_asn1) != strlen(context->username)){ X509_free(client_cert); security__disconnect_auth(context); continue; } } - } else { /* use_subject_as_username */ + }else{ /* use_subject_as_username */ subject_bio = BIO_new(BIO_s_mem()); X509_NAME_print_ex(subject_bio, X509_get_subject_name(client_cert), 0, XN_FLAG_RFC2253); data_start = NULL; diff --git a/src/service.c b/src/service.c index 5d67e90a..ecec06fd 100644 --- a/src/service.c +++ b/src/service.c @@ -28,11 +28,12 @@ SERVICE_STATUS_HANDLE service_handle = 0; static SERVICE_STATUS service_status; int main(int argc, char *argv[]); -static char* fix_name(char* name) + +static char *fix_name(char *name) { size_t len; - if (strrchr(name, '\\')) { + if(strrchr(name, '\\')){ name = strrchr(name, '\\') + 1; } len = strlen(name); @@ -92,8 +93,8 @@ void __stdcall service_main(DWORD dwArgc, LPTSTR *lpszArgv) name = fix_name(lpszArgv[0]); snprintf(env_name, sizeof(env_name), "%s_DIR", name); - for(int i=0; i='A' && env_name[i]<='Z') { + for(int i=0; i='A' && env_name[i]<='Z'){ /* Keep upper case letter */ }else if(env_name[i]>='0' && env_name[i]<='9'){ /* Keep number */ @@ -137,7 +138,8 @@ void __stdcall service_main(DWORD dwArgc, LPTSTR *lpszArgv) } } -void service_install(char* name) + +void service_install(char *name) { SC_HANDLE sc_manager, svc_handle; char service_string[MAX_PATH + 20]; @@ -156,7 +158,7 @@ void service_install(char* name) sc_manager = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE); if(sc_manager){ - if (!strcmp(name, "mosquitto")) { + if(!strcmp(name, "mosquitto")){ snprintf(display_name, sizeof(display_name), "Mosquitto Broker"); }else{ snprintf(display_name, sizeof(display_name), "Mosquitto Broker (%s.exe)", name); @@ -176,7 +178,7 @@ void service_install(char* name) print_error(); } CloseServiceHandle(sc_manager); - } else { + }else{ print_error(); } } diff --git a/src/signals.c b/src/signals.c index 2580f467..ddaa6ff0 100644 --- a/src/signals.c +++ b/src/signals.c @@ -185,9 +185,9 @@ DWORD WINAPI SigThreadProc(void *data) evt[i] = CreateEvent(NULL, TRUE, FALSE, evt_name); } - while (g_run) { + while(g_run){ int wr = WaitForMultipleObjects(MOSQ_MAX_EVTS, evt, FALSE, INFINITE); - switch (wr) { + switch(wr){ case WAIT_OBJECT_0 + 0: handle_signal(SIGINT); break; diff --git a/src/websockets.c b/src/websockets.c index 26c38a44..aa3eef5e 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -139,7 +139,7 @@ static int callback_mqtt( uint8_t byte; char ip_addr_buff[1024]; - switch (reason) { + switch(reason){ case LWS_CALLBACK_ESTABLISHED: mosq = context__init(); if(mosq){ @@ -223,7 +223,7 @@ static int callback_mqtt( packet = mosq->out_packet; count = lws_write(wsi, &packet->payload[packet->pos], packet->to_process, LWS_WRITE_BINARY); if(count < 0){ - if (mosq->state == mosq_cs_disconnect_ws + if(mosq->state == mosq_cs_disconnect_ws || mosq->state == mosq_cs_disconnecting || mosq->state == mosq_cs_disused){ @@ -238,7 +238,7 @@ static int callback_mqtt( packet->to_process -= ucount; packet->pos += ucount; if(packet->to_process > 0){ - if (mosq->state == mosq_cs_disconnect_ws + if(mosq->state == mosq_cs_disconnect_ws || mosq->state == mosq_cs_disconnecting || mosq->state == mosq_cs_disused){ @@ -259,7 +259,7 @@ static int callback_mqtt( mosq->next_msg_out = db.now_s + mosq->keepalive; } - if (mosq->state == mosq_cs_disconnect_ws + if(mosq->state == mosq_cs_disconnect_ws || mosq->state == mosq_cs_disconnecting || mosq->state == mosq_cs_disused){ @@ -342,12 +342,12 @@ static int callback_mqtt( keepalive__update(mosq); - if(rc && mosq->out_packet) { + if(rc && mosq->out_packet){ if(mosq->state != mosq_cs_disconnecting){ mosquitto__set_state(mosq, mosq_cs_disconnect_ws); } lws_callback_on_writable(mosq->wsi); - } else if (rc) { + }else if(rc){ do_disconnect(mosq, MOSQ_ERR_CONN_LOST); return -1; } @@ -445,7 +445,7 @@ static int callback_http( /* FIXME - ssl cert verification is done here. */ - switch (reason) { + switch(reason){ case LWS_CALLBACK_HTTP: if(!u){ return -1; @@ -638,7 +638,7 @@ static int callback_http( #ifdef WITH_TLS case LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION: - if(!len || (SSL_get_verify_result((SSL*)in) != X509_V_OK)){ + if(!len || (SSL_get_verify_result((SSL *)in) != X509_V_OK)){ return 1; } break; @@ -694,8 +694,7 @@ void mosq_websockets_init(struct mosquitto__listener *listener, const struct mos #ifdef WITH_TLS if(listener->cafile){ info.ssl_ca_filepath = listener->cafile; - } - else if(listener->capath){ + }else if(listener->capath){ log__printf(NULL, MOSQ_LOG_WARNING, "Warning: CA path option is not supported for websockets"); } info.ssl_cert_filepath = listener->certfile; diff --git a/test/broker/c/auth_plugin_acl.c b/test/broker/c/auth_plugin_acl.c index c0d5e08e..11ff0eef 100644 --- a/test/broker/c/auth_plugin_acl.c +++ b/test/broker/c/auth_plugin_acl.c @@ -61,7 +61,7 @@ int mosquitto_auth_acl_check(void *user_data, int access, struct mosquitto *clie if(username && !strcmp(username, "readonly") && access == MOSQ_ACL_READ){ return MOSQ_ERR_SUCCESS; - }else if(username && !strcmp(username, "readonly") && access == MOSQ_ACL_SUBSCRIBE &&!strchr(msg->topic, '#') && !strchr(msg->topic, '+')) { + }else if(username && !strcmp(username, "readonly") && access == MOSQ_ACL_SUBSCRIBE &&!strchr(msg->topic, '#') && !strchr(msg->topic, '+')){ return MOSQ_ERR_SUCCESS; }else{ return MOSQ_ERR_ACL_DENIED; diff --git a/test/broker/c/auth_plugin_v3.c b/test/broker/c/auth_plugin_v3.c index bcc71b85..cab1c2ef 100644 --- a/test/broker/c/auth_plugin_v3.c +++ b/test/broker/c/auth_plugin_v3.c @@ -61,7 +61,7 @@ int mosquitto_auth_acl_check(void *user_data, int access, struct mosquitto *clie if(username && !strcmp(username, "readonly") && access == MOSQ_ACL_READ){ return MOSQ_ERR_SUCCESS; - }else if(username && !strcmp(username, "readonly") && access == MOSQ_ACL_SUBSCRIBE &&!strchr(msg->topic, '#') && !strchr(msg->topic, '+')) { + }else if(username && !strcmp(username, "readonly") && access == MOSQ_ACL_SUBSCRIBE &&!strchr(msg->topic, '#') && !strchr(msg->topic, '+')){ return MOSQ_ERR_SUCCESS; }else if(username && !strcmp(username, "readwrite")){ if((!strcmp(msg->topic, "readonly") && access == MOSQ_ACL_READ) diff --git a/test/broker/c/auth_plugin_v4.c b/test/broker/c/auth_plugin_v4.c index 5c4e5cda..3dc195f7 100644 --- a/test/broker/c/auth_plugin_v4.c +++ b/test/broker/c/auth_plugin_v4.c @@ -61,7 +61,7 @@ int mosquitto_auth_acl_check(void *user_data, int access, struct mosquitto *clie if(username && !strcmp(username, "readonly") && access == MOSQ_ACL_READ){ return MOSQ_ERR_SUCCESS; - }else if(username && !strcmp(username, "readonly") && access == MOSQ_ACL_SUBSCRIBE &&!strchr(msg->topic, '#') && !strchr(msg->topic, '+')) { + }else if(username && !strcmp(username, "readonly") && access == MOSQ_ACL_SUBSCRIBE &&!strchr(msg->topic, '#') && !strchr(msg->topic, '+')){ return MOSQ_ERR_SUCCESS; }else if(username && !strcmp(username, "readwrite")){ if((!strcmp(msg->topic, "readonly") && access == MOSQ_ACL_READ) diff --git a/test/broker/c/auth_plugin_v5.c b/test/broker/c/auth_plugin_v5.c index 2f24a6d6..914ed822 100644 --- a/test/broker/c/auth_plugin_v5.c +++ b/test/broker/c/auth_plugin_v5.c @@ -54,7 +54,7 @@ int mosquitto_auth_acl_check_v5(int event, void *event_data, void *user_data) if(username && !strcmp(username, "readonly") && ed->access == MOSQ_ACL_READ){ return MOSQ_ERR_SUCCESS; - }else if(username && !strcmp(username, "readonly") && ed->access == MOSQ_ACL_SUBSCRIBE &&!strchr(ed->topic, '#') && !strchr(ed->topic, '+')) { + }else if(username && !strcmp(username, "readonly") && ed->access == MOSQ_ACL_SUBSCRIBE &&!strchr(ed->topic, '#') && !strchr(ed->topic, '+')){ return MOSQ_ERR_SUCCESS; }else if(username && !strcmp(username, "readwrite")){ if((!strcmp(ed->topic, "readonly") && ed->access == MOSQ_ACL_READ) diff --git a/test/broker/c/bad_v3_1.c b/test/broker/c/bad_v3_1.c index be66f3c7..c947c356 100644 --- a/test/broker/c/bad_v3_1.c +++ b/test/broker/c/bad_v3_1.c @@ -61,7 +61,7 @@ int mosquitto_auth_acl_check(void *user_data, int access, struct mosquitto *clie if(username && !strcmp(username, "readonly") && access == MOSQ_ACL_READ){ return MOSQ_ERR_SUCCESS; - }else if(username && !strcmp(username, "readonly") && access == MOSQ_ACL_SUBSCRIBE &&!strchr(msg->topic, '#') && !strchr(msg->topic, '+')) { + }else if(username && !strcmp(username, "readonly") && access == MOSQ_ACL_SUBSCRIBE &&!strchr(msg->topic, '#') && !strchr(msg->topic, '+')){ return MOSQ_ERR_SUCCESS; }else if(username && !strcmp(username, "readwrite")){ if((!strcmp(msg->topic, "readonly") && access == MOSQ_ACL_READ) diff --git a/test/broker/c/bad_v3_2.c b/test/broker/c/bad_v3_2.c index fff8cb38..bf7dd361 100644 --- a/test/broker/c/bad_v3_2.c +++ b/test/broker/c/bad_v3_2.c @@ -61,7 +61,7 @@ int mosquitto_auth_acl_check(void *user_data, int access, struct mosquitto *clie if(username && !strcmp(username, "readonly") && access == MOSQ_ACL_READ){ return MOSQ_ERR_SUCCESS; - }else if(username && !strcmp(username, "readonly") && access == MOSQ_ACL_SUBSCRIBE &&!strchr(msg->topic, '#') && !strchr(msg->topic, '+')) { + }else if(username && !strcmp(username, "readonly") && access == MOSQ_ACL_SUBSCRIBE &&!strchr(msg->topic, '#') && !strchr(msg->topic, '+')){ return MOSQ_ERR_SUCCESS; }else if(username && !strcmp(username, "readwrite")){ if((!strcmp(msg->topic, "readonly") && access == MOSQ_ACL_READ) diff --git a/test/lib/c/02-subscribe-qos1-async2.c b/test/lib/c/02-subscribe-qos1-async2.c index df6372a3..ece8638b 100644 --- a/test/lib/c/02-subscribe-qos1-async2.c +++ b/test/lib/c/02-subscribe-qos1-async2.c @@ -46,9 +46,9 @@ static void on_subscribe(struct mosquitto *mosq, void *obj, int mid, int qos_cou } -static const char* loglevel_as_str(int level) +static const char *loglevel_as_str(int level) { - switch (level){ + switch(level){ case MOSQ_LOG_INFO: return "INFO"; case MOSQ_LOG_NOTICE: diff --git a/test/lib/c/02-unsubscribe-multiple-v5.c b/test/lib/c/02-unsubscribe-multiple-v5.c index 5f3ea6d2..89b85093 100644 --- a/test/lib/c/02-unsubscribe-multiple-v5.c +++ b/test/lib/c/02-unsubscribe-multiple-v5.c @@ -19,6 +19,7 @@ static void on_connect(struct mosquitto *mosq, void *obj, int rc) } } + static void on_subscribe(struct mosquitto *mosq, void *obj, int mid, int sub_count, const int *subs) { char *const unsubs[] = {"unsubscribe/test", "no-sub"}; diff --git a/test/lib/c/08-ssl-connect-cert-auth-enc.c b/test/lib/c/08-ssl-connect-cert-auth-enc.c index a5dcf221..7fd9b6d1 100644 --- a/test/lib/c/08-ssl-connect-cert-auth-enc.c +++ b/test/lib/c/08-ssl-connect-cert-auth-enc.c @@ -30,7 +30,8 @@ static void on_disconnect(struct mosquitto *mosq, void *obj, int rc) run = rc; } -static int password_callback(char* buf, int size, int rwflag, void* userdata) + +static int password_callback(char *buf, int size, int rwflag, void *userdata) { (void)rwflag; (void)userdata; diff --git a/test/lib/c/fuzzish.c b/test/lib/c/fuzzish.c index 1bc5dea4..da9e6261 100644 --- a/test/lib/c/fuzzish.c +++ b/test/lib/c/fuzzish.c @@ -361,7 +361,7 @@ static void on_log(struct mosquitto *mosq, void *obj, int level, const char *str exit(1); } size_t i = strlen(str); - if (i == SIZE_MAX){ + if(i == SIZE_MAX){ printf("too large on_log\n"); exit(1); } @@ -373,7 +373,7 @@ static void setup_signal_handler(void) struct sigaction act = { 0 }; act.sa_handler = &signal_handler; - if(sigaction(SIGTERM, &act, NULL) < 0) { + if(sigaction(SIGTERM, &act, NULL) < 0){ exit(1); } } diff --git a/test/unit/lib/property_read.c b/test/unit/lib/property_read.c index 0d204913..d6b64a3c 100644 --- a/test/unit/lib/property_read.c +++ b/test/unit/lib/property_read.c @@ -1295,10 +1295,12 @@ static void TEST_bad_subscription_identifier(void) varint_prop_read_helper(payload, 7, MOSQ_ERR_MALFORMED_PACKET, MQTT_PROP_SUBSCRIPTION_IDENTIFIER, 0); } + /* ======================================================================== * CONTROL PACKET TESTS * ======================================================================== */ + static void TEST_packet_connect(void) { uint8_t payload[] = {0, @@ -1405,6 +1407,7 @@ static void TEST_packet_connect(void) mosquitto_property_free_all(&properties); } + static void TEST_packet_connack(void) { uint8_t payload[] = {0, @@ -1588,6 +1591,7 @@ static void TEST_packet_connack(void) mosquitto_property_free_all(&properties); } + static void TEST_packet_publish(void) { uint8_t payload[] = {0,