Better function names.

pull/211/merge
Roger A. Light 11 years ago
parent e221b37658
commit aca67a2170

@ -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(strlen(topic) == 0) return MOSQ_ERR_INVAL;
if(payloadlen < 0 || payloadlen > MQTT_MAX_PAYLOAD) return MOSQ_ERR_PAYLOAD_SIZE; 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; 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) return MOSQ_ERR_INVAL;
if(mosq->sock == INVALID_SOCKET) return MOSQ_ERR_NO_CONN; 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); 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) return MOSQ_ERR_INVAL;
if(mosq->sock == INVALID_SOCKET) return MOSQ_ERR_NO_CONN; 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); return _mosquitto_send_unsubscribe(mosq, mid, false, sub);
} }

@ -151,11 +151,12 @@ uint16_t _mosquitto_mid_generate(struct mosquitto *mosq)
return mosq->last_mid; 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. * Also returns MOSQ_ERR_INVAL if the topic string is too long.
* Returns MOSQ_ERR_SUCCESS if everything is fine. * 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; int len = 0;
while(str && str[0]){ while(str && str[0]){
@ -170,12 +171,14 @@ int _mosquitto_topic_wildcard_len_check(const char *str)
return MOSQ_ERR_SUCCESS; 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. * Return MOSQ_ERR_INVAL if invalid position found.
* Also returns MOSQ_ERR_INVAL if the topic string is too long. * Also returns MOSQ_ERR_INVAL if the topic string is too long.
* Returns MOSQ_ERR_SUCCESS if everything is fine. * 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'; char c = '\0';
int len = 0; int len = 0;

@ -24,8 +24,8 @@ Contributors:
int _mosquitto_packet_alloc(struct _mosquitto_packet *packet); int _mosquitto_packet_alloc(struct _mosquitto_packet *packet);
void _mosquitto_check_keepalive(struct mosquitto *mosq); void _mosquitto_check_keepalive(struct mosquitto *mosq);
uint16_t _mosquitto_mid_generate(struct mosquitto *mosq); uint16_t _mosquitto_mid_generate(struct mosquitto *mosq);
int _mosquitto_topic_wildcard_len_check(const char *str); int _mosquitto_pub_topic_check(const char *str);
int _mosquitto_topic_wildcard_pos_check(const char *str); int _mosquitto_sub_topic_check(const char *str);
FILE *_mosquitto_fopen(const char *path, const char *mode); FILE *_mosquitto_fopen(const char *path, const char *mode);
#ifdef REAL_WITH_TLS_PSK #ifdef REAL_WITH_TLS_PSK

@ -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 || payloadlen > MQTT_MAX_PAYLOAD) return MOSQ_ERR_PAYLOAD_SIZE;
if(payloadlen > 0 && !payload) return MOSQ_ERR_INVAL; 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){
if(mosq->will->topic){ if(mosq->will->topic){

@ -1313,7 +1313,7 @@ int _config_read_file_core(struct mqtt3_config *config, bool reload, const char
return MOSQ_ERR_INVAL; return MOSQ_ERR_INVAL;
} }
if(_conf_parse_string(&token, "mount_point", &cur_listener->mount_point, saveptr)) 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, _mosquitto_log_printf(NULL, MOSQ_LOG_ERR,
"Error: Invalid mount_point '%s'. Does it contain a wildcard character?", "Error: Invalid mount_point '%s'. Does it contain a wildcard character?",
cur_listener->mount_point); cur_listener->mount_point);
@ -1628,7 +1628,7 @@ int _config_read_file_core(struct mqtt3_config *config, bool reload, const char
if(!strcmp(token, "\"\"")){ if(!strcmp(token, "\"\"")){
cur_topic->local_prefix = NULL; cur_topic->local_prefix = NULL;
}else{ }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); _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Invalid bridge topic local prefix '%s'.", token);
return MOSQ_ERR_INVAL; return MOSQ_ERR_INVAL;
} }
@ -1644,7 +1644,7 @@ int _config_read_file_core(struct mqtt3_config *config, bool reload, const char
if(!strcmp(token, "\"\"")){ if(!strcmp(token, "\"\"")){
cur_topic->remote_prefix = NULL; cur_topic->remote_prefix = NULL;
}else{ }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); _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Invalid bridge topic remote prefix '%s'.", token);
return MOSQ_ERR_INVAL; return MOSQ_ERR_INVAL;
} }

@ -157,7 +157,7 @@ int mqtt3_handle_publish(struct mosquitto_db *db, struct mosquitto *context)
} }
} }
#endif #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. */ /* Invalid publish topic, just swallow it. */
_mosquitto_free(topic); _mosquitto_free(topic);
return 1; return 1;

@ -203,7 +203,7 @@ int mqtt3_handle_connect(struct mosquitto_db *db, struct mosquitto *context)
rc = 1; rc = 1;
goto handle_connect_error; goto handle_connect_error;
} }
if(_mosquitto_topic_wildcard_pos_check(will_topic)){ if(_mosquitto_pub_topic_check(will_topic)){
mqtt3_context_disconnect(db, context); mqtt3_context_disconnect(db, context);
rc = 1; rc = 1;
goto handle_connect_error; goto handle_connect_error;
@ -563,7 +563,7 @@ int mqtt3_handle_subscribe(struct mosquitto_db *db, struct mosquitto *context)
if(payload) _mosquitto_free(payload); if(payload) _mosquitto_free(payload);
return 1; 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.", _mosquitto_log_printf(NULL, MOSQ_LOG_INFO, "Invalid subscription string from %s, disconnecting.",
context->address); context->address);
_mosquitto_free(sub); _mosquitto_free(sub);
@ -673,7 +673,7 @@ int mqtt3_handle_unsubscribe(struct mosquitto_db *db, struct mosquitto *context)
_mosquitto_free(sub); _mosquitto_free(sub);
return 1; 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.", _mosquitto_log_printf(NULL, MOSQ_LOG_INFO, "Invalid unsubscription string from %s, disconnecting.",
context->id); context->id);
_mosquitto_free(sub); _mosquitto_free(sub);

Loading…
Cancel
Save