Add mosquitto_string_to_property_info.

This commit is contained in:
Roger A. Light 2018-10-30 11:54:36 +00:00
parent c19b3598c0
commit 446ad6290a
4 changed files with 123 additions and 0 deletions

View File

@ -97,5 +97,6 @@ MOSQ_1.6 {
mosquitto_property_free_all;
mosquitto_property_command_check;
mosquitto_string_to_command;
mosquitto_string_to_property_info;
mosquitto_subscribe_multiple;
} MOSQ_1.5;

View File

@ -1931,6 +1931,29 @@ libmosq_EXPORT void mosquitto_property_free_all(mosquitto_property **properties)
*/
int mosquitto_property_command_check(int command, int identifier);
/* Function: mosquitto_string_to_property_info
*
* Parse a property name string and convert to a property identifier and data type.
* The property name is as defined in the MQTT specification, with - as a
* separator, for example: payload-format-indicator.
*
* Parameters:
* propname - the string to parse
* identifier - pointer to an int to receive the property identifier
* type - pointer to an int to receive the property type
*
* Returns:
* MOSQ_ERR_SUCCESS - on success
* MOSQ_ERR_INVAL - if the string does not match a property
*
* Example:
* mosquitto_string_to_property_info("response-topic", &id, &type);
* // id == MQTT_PROP_RESPONSE_TOPIC
* // type == MQTT_PROP_TYPE_STRING
*/
int mosquitto_string_to_property_info(const char *propname, int *identifier, int *type);
#ifdef __cplusplus
}
#endif

View File

@ -135,6 +135,16 @@ enum mqtt5_property {
MQTT_PROP_SHARED_SUB_AVAILABLE = 42, /* Byte : CONNACK */
};
enum mqtt5_property_type {
MQTT_PROP_TYPE_BYTE = 1,
MQTT_PROP_TYPE_INT16 = 2,
MQTT_PROP_TYPE_INT32 = 3,
MQTT_PROP_TYPE_VARINT = 4,
MQTT_PROP_TYPE_BINARY = 5,
MQTT_PROP_TYPE_STRING = 6,
MQTT_PROP_TYPE_STRING_PAIR = 7
};
#define MQTT_MAX_PAYLOAD 268435455
#endif

View File

@ -559,3 +559,92 @@ static int property__command_check(int command, struct mqtt5__property *properti
return MOSQ_ERR_SUCCESS;
}
int mosquitto_string_to_property_info(const char *propname, int *identifier, int *type)
{
if(!strcasecmp(propname, "payload-format-indicator")){
*identifier = MQTT_PROP_PAYLOAD_FORMAT_INDICATOR;
*type = MQTT_PROP_TYPE_BYTE;
}else if(!strcasecmp(propname, "message-expiry-interval")){
*identifier = MQTT_PROP_MESSAGE_EXPIRY_INTERVAL;
*type = MQTT_PROP_TYPE_INT32;
}else if(!strcasecmp(propname, "content-type")){
*identifier = MQTT_PROP_CONTENT_TYPE;
*type = MQTT_PROP_TYPE_STRING;
}else if(!strcasecmp(propname, "response-topic")){
*identifier = MQTT_PROP_RESPONSE_TOPIC;
*type = MQTT_PROP_TYPE_STRING;
}else if(!strcasecmp(propname, "correlation-data")){
*identifier = MQTT_PROP_CORRELATION_DATA;
*type = MQTT_PROP_TYPE_BINARY;
}else if(!strcasecmp(propname, "subscription-identifier")){
*identifier = MQTT_PROP_SUBSCRIPTION_IDENTIFIER;
*type = MQTT_PROP_TYPE_VARINT;
}else if(!strcasecmp(propname, "session-expiry-interval")){
*identifier = MQTT_PROP_SESSION_EXPIRY_INTERVAL;
*type = MQTT_PROP_TYPE_INT32;
}else if(!strcasecmp(propname, "assigned-client-identifier")){
*identifier = MQTT_PROP_ASSIGNED_CLIENT_IDENTIFIER;
*type = MQTT_PROP_TYPE_STRING;
}else if(!strcasecmp(propname, "server-keep-alive")){
*identifier = MQTT_PROP_SERVER_KEEP_ALIVE;
*type = MQTT_PROP_TYPE_INT16;
}else if(!strcasecmp(propname, "authentication-method")){
*identifier = MQTT_PROP_AUTHENTICATION_METHOD;
*type = MQTT_PROP_TYPE_STRING;
}else if(!strcasecmp(propname, "authentication-data")){
*identifier = MQTT_PROP_AUTHENTICATION_DATA;
*type = MQTT_PROP_TYPE_BINARY;
}else if(!strcasecmp(propname, "request-problem-information")){
*identifier = MQTT_PROP_REQUEST_PROBLEM_INFORMATION;
*type = MQTT_PROP_TYPE_BYTE;
}else if(!strcasecmp(propname, "will-delay-interval")){
*identifier = MQTT_PROP_WILL_DELAY_INTERVAL;
*type = MQTT_PROP_TYPE_INT32;
}else if(!strcasecmp(propname, "request-response-information")){
*identifier = MQTT_PROP_REQUEST_RESPONSE_INFORMATION;
*type = MQTT_PROP_TYPE_BYTE;
}else if(!strcasecmp(propname, "response-information")){
*identifier = MQTT_PROP_RESPONSE_INFORMATION;
*type = MQTT_PROP_TYPE_STRING;
}else if(!strcasecmp(propname, "server-reference")){
*identifier = MQTT_PROP_SERVER_REFERENCE;
*type = MQTT_PROP_TYPE_STRING;
}else if(!strcasecmp(propname, "reason-string")){
*identifier = MQTT_PROP_REASON_STRING;
*type = MQTT_PROP_TYPE_STRING;
}else if(!strcasecmp(propname, "receive-maximum")){
*identifier = MQTT_PROP_RECEIVE_MAXIMUM;
*type = MQTT_PROP_TYPE_INT16;
}else if(!strcasecmp(propname, "topic-alias-maximum")){
*identifier = MQTT_PROP_TOPIC_ALIAS_MAXIMUM;
*type = MQTT_PROP_TYPE_INT16;
}else if(!strcasecmp(propname, "topic-alias")){
*identifier = MQTT_PROP_TOPIC_ALIAS;
*type = MQTT_PROP_TYPE_INT16;
}else if(!strcasecmp(propname, "maximum-qos")){
*identifier = MQTT_PROP_MAXIMUM_QOS;
*type = MQTT_PROP_TYPE_BYTE;
}else if(!strcasecmp(propname, "retain-available")){
*identifier = MQTT_PROP_RETAIN_AVAILABLE;
*type = MQTT_PROP_TYPE_BYTE;
}else if(!strcasecmp(propname, "user-property")){
*identifier = MQTT_PROP_USER_PROPERTY;
*type = MQTT_PROP_TYPE_STRING_PAIR;
}else if(!strcasecmp(propname, "maximum-packet-size")){
*identifier = MQTT_PROP_MAXIMUM_PACKET_SIZE;
*type = MQTT_PROP_TYPE_INT32;
}else if(!strcasecmp(propname, "wildcard-subscription-available")){
*identifier = MQTT_PROP_WILDCARD_SUB_AVAILABLE;
*type = MQTT_PROP_TYPE_BYTE;
}else if(!strcasecmp(propname, "subscription-identifier-available")){
*identifier = MQTT_PROP_SUBSCRIPTION_ID_AVAILABLE;
*type = MQTT_PROP_TYPE_BYTE;
}else if(!strcasecmp(propname, "shared-subscription-available")){
*identifier = MQTT_PROP_SHARED_SUB_AVAILABLE;
*type = MQTT_PROP_TYPE_BYTE;
}else{
return MOSQ_ERR_INVAL;
}
return MOSQ_ERR_SUCCESS;
}