mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-09-20 23:03:55 +08:00
Add mosquitto_string_to_command.
This commit is contained in:
+2
-1
@@ -94,7 +94,8 @@ MOSQ_1.5 {
|
||||
|
||||
MOSQ_1.6 {
|
||||
global:
|
||||
mosquitto_subscribe_multiple;
|
||||
mosquitto_property_free_all;
|
||||
mosquitto_property_command_check;
|
||||
mosquitto_string_to_command;
|
||||
mosquitto_subscribe_multiple;
|
||||
} MOSQ_1.5;
|
||||
|
||||
@@ -493,6 +493,40 @@ const char *mosquitto_reason_string(int reason_code)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int mosquitto_string_to_command(const char *str, int *cmd)
|
||||
{
|
||||
if(!strcasecmp(str, "connect")){
|
||||
*cmd = CMD_CONNECT;
|
||||
}else if(!strcasecmp(str, "connack")){
|
||||
*cmd = CMD_CONNACK;
|
||||
}else if(!strcasecmp(str, "publish")){
|
||||
*cmd = CMD_PUBLISH;
|
||||
}else if(!strcasecmp(str, "puback")){
|
||||
*cmd = CMD_PUBACK;
|
||||
}else if(!strcasecmp(str, "pubrec")){
|
||||
*cmd = CMD_PUBREC;
|
||||
}else if(!strcasecmp(str, "pubrel")){
|
||||
*cmd = CMD_PUBREL;
|
||||
}else if(!strcasecmp(str, "pubcomp")){
|
||||
*cmd = CMD_PUBCOMP;
|
||||
}else if(!strcasecmp(str, "subscribe")){
|
||||
*cmd = CMD_SUBSCRIBE;
|
||||
}else if(!strcasecmp(str, "unsubscribe")){
|
||||
*cmd = CMD_UNSUBSCRIBE;
|
||||
}else if(!strcasecmp(str, "disconnect")){
|
||||
*cmd = CMD_DISCONNECT;
|
||||
}else if(!strcasecmp(str, "auth")){
|
||||
*cmd = CMD_AUTH;
|
||||
}else if(!strcasecmp(str, "will")){
|
||||
*cmd = CMD_WILL;
|
||||
}else{
|
||||
return MOSQ_ERR_INVAL;
|
||||
}
|
||||
return MOSQ_ERR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int mosquitto_sub_topic_tokenise(const char *subtopic, char ***topics, int *count)
|
||||
{
|
||||
int len;
|
||||
|
||||
@@ -1568,6 +1568,25 @@ libmosq_EXPORT const char *mosquitto_strerror(int mosq_errno);
|
||||
*/
|
||||
libmosq_EXPORT const char *mosquitto_connack_string(int connack_code);
|
||||
|
||||
/* Function: mosquitto_string_to_command
|
||||
*
|
||||
* Take a string input representing an MQTT command and convert it to the
|
||||
* libmosquitto integer representation.
|
||||
*
|
||||
* Parameters:
|
||||
* str - the string to parse.
|
||||
* cmd - pointer to an int, for the result.
|
||||
*
|
||||
* Returns:
|
||||
* MOSQ_ERR_SUCCESS - on success
|
||||
* MOSQ_ERR_INVAL - on an invalid input.
|
||||
*
|
||||
* Example:
|
||||
* mosquitto_string_to_command("CONNECT", &cmd);
|
||||
* // cmd == CMD_CONNECT
|
||||
*/
|
||||
libmosq_EXPORT int mosquitto_string_to_command(const char *str, int *cmd);
|
||||
|
||||
/*
|
||||
* Function: mosquitto_sub_topic_tokenise
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user