From aca67a2170f2acde6826f8b2515b052645a02143 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sun, 8 Jun 2014 22:51:36 +0100 Subject: [PATCH] Better function names. --- lib/mosquitto.c | 6 +++--- lib/util_mosq.c | 11 +++++++---- lib/util_mosq.h | 4 ++-- lib/will_mosq.c | 2 +- src/conf.c | 6 +++--- src/read_handle.c | 2 +- src/read_handle_server.c | 6 +++--- 7 files changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/mosquitto.c b/lib/mosquitto.c index 728c2eba..6ccece93 100644 --- a/lib/mosquitto.c +++ b/lib/mosquitto.c @@ -526,7 +526,7 @@ int mosquitto_publish(struct mosquitto *mosq, int *mid, const char *topic, int p if(strlen(topic) == 0) return MOSQ_ERR_INVAL; if(payloadlen < 0 || payloadlen > MQTT_MAX_PAYLOAD) return MOSQ_ERR_PAYLOAD_SIZE; - if(_mosquitto_topic_wildcard_len_check(topic) != MOSQ_ERR_SUCCESS){ + if(_mosquitto_pub_topic_check(topic) != MOSQ_ERR_SUCCESS){ return MOSQ_ERR_INVAL; } @@ -589,7 +589,7 @@ int mosquitto_subscribe(struct mosquitto *mosq, int *mid, const char *sub, int q if(!mosq) return MOSQ_ERR_INVAL; if(mosq->sock == INVALID_SOCKET) return MOSQ_ERR_NO_CONN; - if(_mosquitto_topic_wildcard_pos_check(sub)) return MOSQ_ERR_INVAL; + if(_mosquitto_sub_topic_check(sub)) return MOSQ_ERR_INVAL; return _mosquitto_send_subscribe(mosq, mid, false, sub, qos); } @@ -599,7 +599,7 @@ int mosquitto_unsubscribe(struct mosquitto *mosq, int *mid, const char *sub) if(!mosq) return MOSQ_ERR_INVAL; if(mosq->sock == INVALID_SOCKET) return MOSQ_ERR_NO_CONN; - if(_mosquitto_topic_wildcard_pos_check(sub)) return MOSQ_ERR_INVAL; + if(_mosquitto_sub_topic_check(sub)) return MOSQ_ERR_INVAL; return _mosquitto_send_unsubscribe(mosq, mid, false, sub); } diff --git a/lib/util_mosq.c b/lib/util_mosq.c index 088d1d87..91e3646b 100644 --- a/lib/util_mosq.c +++ b/lib/util_mosq.c @@ -151,11 +151,12 @@ uint16_t _mosquitto_mid_generate(struct mosquitto *mosq) return mosq->last_mid; } -/* Search for + or # in a topic. Return MOSQ_ERR_INVAL if found. +/* Check that a topic used for publishing is valid. + * Search for + or # in a topic. Return MOSQ_ERR_INVAL if found. * Also returns MOSQ_ERR_INVAL if the topic string is too long. * Returns MOSQ_ERR_SUCCESS if everything is fine. */ -int _mosquitto_topic_wildcard_len_check(const char *str) +int _mosquitto_pub_topic_check(const char *str) { int len = 0; while(str && str[0]){ @@ -170,12 +171,14 @@ int _mosquitto_topic_wildcard_len_check(const char *str) return MOSQ_ERR_SUCCESS; } -/* Search for + or # in a topic, check they aren't in invalid positions such as foo/#/bar, foo/+bar or foo/bar#. +/* Check that a topic used for subscriptions is valid. + * Search for + or # in a topic, check they aren't in invalid positions such as + * foo/#/bar, foo/+bar or foo/bar#. * Return MOSQ_ERR_INVAL if invalid position found. * Also returns MOSQ_ERR_INVAL if the topic string is too long. * Returns MOSQ_ERR_SUCCESS if everything is fine. */ -int _mosquitto_topic_wildcard_pos_check(const char *str) +int _mosquitto_sub_topic_check(const char *str) { char c = '\0'; int len = 0; diff --git a/lib/util_mosq.h b/lib/util_mosq.h index e99e462a..fc23093e 100644 --- a/lib/util_mosq.h +++ b/lib/util_mosq.h @@ -24,8 +24,8 @@ Contributors: int _mosquitto_packet_alloc(struct _mosquitto_packet *packet); void _mosquitto_check_keepalive(struct mosquitto *mosq); uint16_t _mosquitto_mid_generate(struct mosquitto *mosq); -int _mosquitto_topic_wildcard_len_check(const char *str); -int _mosquitto_topic_wildcard_pos_check(const char *str); +int _mosquitto_pub_topic_check(const char *str); +int _mosquitto_sub_topic_check(const char *str); FILE *_mosquitto_fopen(const char *path, const char *mode); #ifdef REAL_WITH_TLS_PSK diff --git a/lib/will_mosq.c b/lib/will_mosq.c index e78faa89..60f519d3 100644 --- a/lib/will_mosq.c +++ b/lib/will_mosq.c @@ -45,7 +45,7 @@ int _mosquitto_will_set(struct mosquitto *mosq, const char *topic, int payloadle if(payloadlen < 0 || payloadlen > MQTT_MAX_PAYLOAD) return MOSQ_ERR_PAYLOAD_SIZE; if(payloadlen > 0 && !payload) return MOSQ_ERR_INVAL; - if(_mosquitto_topic_wildcard_pos_check(topic)) return MOSQ_ERR_INVAL; + if(_mosquitto_pub_topic_check(topic)) return MOSQ_ERR_INVAL; if(mosq->will){ if(mosq->will->topic){ diff --git a/src/conf.c b/src/conf.c index 3bfe2fe6..7a1db2fb 100644 --- a/src/conf.c +++ b/src/conf.c @@ -1313,7 +1313,7 @@ int _config_read_file_core(struct mqtt3_config *config, bool reload, const char return MOSQ_ERR_INVAL; } if(_conf_parse_string(&token, "mount_point", &cur_listener->mount_point, saveptr)) return MOSQ_ERR_INVAL; - if(_mosquitto_topic_wildcard_len_check(cur_listener->mount_point) != MOSQ_ERR_SUCCESS){ + if(_mosquitto_pub_topic_check(cur_listener->mount_point) != MOSQ_ERR_SUCCESS){ _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Invalid mount_point '%s'. Does it contain a wildcard character?", cur_listener->mount_point); @@ -1628,7 +1628,7 @@ int _config_read_file_core(struct mqtt3_config *config, bool reload, const char if(!strcmp(token, "\"\"")){ cur_topic->local_prefix = NULL; }else{ - if(_mosquitto_topic_wildcard_len_check(token) != MOSQ_ERR_SUCCESS){ + if(_mosquitto_pub_topic_check(token) != MOSQ_ERR_SUCCESS){ _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Invalid bridge topic local prefix '%s'.", token); return MOSQ_ERR_INVAL; } @@ -1644,7 +1644,7 @@ int _config_read_file_core(struct mqtt3_config *config, bool reload, const char if(!strcmp(token, "\"\"")){ cur_topic->remote_prefix = NULL; }else{ - if(_mosquitto_topic_wildcard_len_check(token) != MOSQ_ERR_SUCCESS){ + if(_mosquitto_pub_topic_check(token) != MOSQ_ERR_SUCCESS){ _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Invalid bridge topic remote prefix '%s'.", token); return MOSQ_ERR_INVAL; } diff --git a/src/read_handle.c b/src/read_handle.c index f7b21942..16af8cae 100644 --- a/src/read_handle.c +++ b/src/read_handle.c @@ -157,7 +157,7 @@ int mqtt3_handle_publish(struct mosquitto_db *db, struct mosquitto *context) } } #endif - if(_mosquitto_topic_wildcard_len_check(topic) != MOSQ_ERR_SUCCESS){ + if(_mosquitto_pub_topic_check(topic) != MOSQ_ERR_SUCCESS){ /* Invalid publish topic, just swallow it. */ _mosquitto_free(topic); return 1; diff --git a/src/read_handle_server.c b/src/read_handle_server.c index 4d320a20..9fd215f2 100644 --- a/src/read_handle_server.c +++ b/src/read_handle_server.c @@ -203,7 +203,7 @@ int mqtt3_handle_connect(struct mosquitto_db *db, struct mosquitto *context) rc = 1; goto handle_connect_error; } - if(_mosquitto_topic_wildcard_pos_check(will_topic)){ + if(_mosquitto_pub_topic_check(will_topic)){ mqtt3_context_disconnect(db, context); rc = 1; goto handle_connect_error; @@ -563,7 +563,7 @@ int mqtt3_handle_subscribe(struct mosquitto_db *db, struct mosquitto *context) if(payload) _mosquitto_free(payload); return 1; } - if(_mosquitto_topic_wildcard_pos_check(sub)){ + if(_mosquitto_sub_topic_check(sub)){ _mosquitto_log_printf(NULL, MOSQ_LOG_INFO, "Invalid subscription string from %s, disconnecting.", context->address); _mosquitto_free(sub); @@ -673,7 +673,7 @@ int mqtt3_handle_unsubscribe(struct mosquitto_db *db, struct mosquitto *context) _mosquitto_free(sub); return 1; } - if(_mosquitto_topic_wildcard_pos_check(sub)){ + if(_mosquitto_sub_topic_check(sub)){ _mosquitto_log_printf(NULL, MOSQ_LOG_INFO, "Invalid unsubscription string from %s, disconnecting.", context->id); _mosquitto_free(sub);