Add property helper functions.

mosquitto_property_identifier()
mosquitto_property_identifier_to_string()
mosquitto_property_next()
pull/1480/head
Roger Light 6 years ago
parent a65aef9232
commit 2f8573b456

@ -9,6 +9,12 @@ Client library:
now expected to be generated on the broker. This matches the behaviour for
v5 clients. Closes #291.
- Add support for connecting to brokers through Unix domain sockets.
- Add `mosquitto_property_identifier()`, for retrieving the identifier integer
for a property.
- Add `mosquitto_property_identifier_to_string()` for converting a property
identifier integer to the corresponding property name string.
- Add `mosquitto_property_next()` to retrieve the next property in a list, for
iterating over property lists.
Clients:
- Add timeout return code (27) for `mosquitto_sub -W <secs>` and

@ -132,3 +132,10 @@ MOSQ_1.6 {
mosquitto_void_option;
mosquitto_will_set_v5;
} MOSQ_1.5;
MOSQ_1.7 {
global:
mosquitto_property_identifier;
mosquitto_property_identifier_to_string;
mosquitto_property_next;
} MOSQ_1.6;

@ -2695,6 +2695,44 @@ libmosq_EXPORT int mosquitto_property_add_string(mosquitto_property **proplist,
*/
libmosq_EXPORT int mosquitto_property_add_string_pair(mosquitto_property **proplist, int identifier, const char *name, const char *value);
/*
* Function: mosquitto_property_identifier
*
* Return the property identifier for a single property.
*
* Parameters:
* property - pointer to a valid mosquitto_property pointer.
*
* Returns:
* A valid property identifier on success
* 0 - on error
*/
libmosq_EXPORT int mosquitto_property_identifier(const mosquitto_property *property);
/*
* Function: mosquitto_property_next
*
* Return the next property in a property list. Use to iterate over a property
* list, e.g.:
*
* for(prop = proplist; prop != NULL; prop = mosquitto_property_next(prop)){
* if(mosquitto_property_identifier(prop) == MQTT_PROP_CONTENT_TYPE){
* ...
* }
* }
*
* Parameters:
* proplist - pointer to mosquitto_property pointer, the list of properties
*
* Returns:
* Pointer to the next item in the list
* NULL, if proplist is NULL, or if there are no more items in the list.
*/
libmosq_EXPORT const mosquitto_property *mosquitto_property_next(const mosquitto_property *proplist);
/*
* Function: mosquitto_property_read_byte
*
@ -2965,6 +3003,23 @@ libmosq_EXPORT int mosquitto_property_check_command(int command, int identifier)
*/
libmosq_EXPORT int mosquitto_property_check_all(int command, const mosquitto_property *properties);
/*
* Function: mosquitto_property_identifier_to_string
*
* Return the property name as a string for a property identifier.
* The property name is as defined in the MQTT specification, with - as a
* separator, for example: payload-format-indicator.
*
* Parameters:
* identifier - valid MQTT property identifier integer
*
* Returns:
* A const string to the property name on success
* NULL on failure
*/
libmosq_EXPORT const char *mosquitto_property_identifier_to_string(int identifier);
/* Function: mosquitto_string_to_property_info
*
* Parse a property name string and convert to a property identifier and data type.

@ -534,6 +534,69 @@ int mosquitto_property_check_command(int command, int identifier)
}
const char *mosquitto_property_identifier_to_string(int identifier)
{
switch(identifier){
case MQTT_PROP_PAYLOAD_FORMAT_INDICATOR:
return "payload-format-indicator";
case MQTT_PROP_MESSAGE_EXPIRY_INTERVAL:
return "message-expiry-interval";
case MQTT_PROP_CONTENT_TYPE:
return "content-type";
case MQTT_PROP_RESPONSE_TOPIC:
return "response-topic";
case MQTT_PROP_CORRELATION_DATA:
return "correlation-data";
case MQTT_PROP_SUBSCRIPTION_IDENTIFIER:
return "subscription-identifier";
case MQTT_PROP_SESSION_EXPIRY_INTERVAL:
return "session-expiry-interval";
case MQTT_PROP_ASSIGNED_CLIENT_IDENTIFIER:
return "assigned-client-identifier";
case MQTT_PROP_SERVER_KEEP_ALIVE:
return "server-keep-alive";
case MQTT_PROP_AUTHENTICATION_METHOD:
return "authentication-method";
case MQTT_PROP_AUTHENTICATION_DATA:
return "authentication-data";
case MQTT_PROP_REQUEST_PROBLEM_INFORMATION:
return "request-problem-information";
case MQTT_PROP_WILL_DELAY_INTERVAL:
return "will-delay-interval";
case MQTT_PROP_REQUEST_RESPONSE_INFORMATION:
return "request-response-information";
case MQTT_PROP_RESPONSE_INFORMATION:
return "response-information";
case MQTT_PROP_SERVER_REFERENCE:
return "server-reference";
case MQTT_PROP_REASON_STRING:
return "reason-string";
case MQTT_PROP_RECEIVE_MAXIMUM:
return "receive-maximum";
case MQTT_PROP_TOPIC_ALIAS_MAXIMUM:
return "topic-alias-maximum";
case MQTT_PROP_TOPIC_ALIAS:
return "topic-alias";
case MQTT_PROP_MAXIMUM_QOS:
return "maximum-qos";
case MQTT_PROP_RETAIN_AVAILABLE:
return "retain-available";
case MQTT_PROP_USER_PROPERTY:
return "user-property";
case MQTT_PROP_MAXIMUM_PACKET_SIZE:
return "maximum-packet-size";
case MQTT_PROP_WILDCARD_SUB_AVAILABLE:
return "wildcard-subscription-available";
case MQTT_PROP_SUBSCRIPTION_ID_AVAILABLE:
return "subscription-identifier-available";
case MQTT_PROP_SHARED_SUB_AVAILABLE:
return "shared-subscription-available";
default:
return NULL;
}
}
int mosquitto_string_to_property_info(const char *propname, int *identifier, int *type)
{
if(!propname) return MOSQ_ERR_INVAL;
@ -926,6 +989,22 @@ const mosquitto_property *property__get_property(const mosquitto_property *propl
}
int mosquitto_property_identifier(const mosquitto_property *property)
{
if(property == NULL) return 0;
return property->identifier;
}
const mosquitto_property *mosquitto_property_next(const mosquitto_property *proplist)
{
if(proplist == NULL) return NULL;
return proplist->next;
}
const mosquitto_property *mosquitto_property_read_byte(const mosquitto_property *proplist, int identifier, uint8_t *value, bool skip_first)
{
const mosquitto_property *p;

Loading…
Cancel
Save