diff --git a/src/adc/message.c b/src/adc/message.c index cfabb3f..ad4cb80 100644 --- a/src/adc/message.c +++ b/src/adc/message.c @@ -787,6 +787,13 @@ int adc_msg_add_argument(struct adc_message* cmd, const char* string) return 0; } +int adc_msg_add_argument_string(struct adc_message* cmd, const char* string) +{ + char* escaped = adc_msg_escape(string); + int ret = adc_msg_add_argument(cmd, escaped); + hub_free(escaped); + return ret; +} char* adc_msg_get_argument(struct adc_message* cmd, int offset) { @@ -866,8 +873,6 @@ int adc_msg_get_argument_index(struct adc_message* cmd, const char prefix[2]) return -1; } - - int adc_msg_escape_length(const char* str) { int add = 0; diff --git a/src/adc/message.h b/src/adc/message.h index 31b4e7f..a493314 100644 --- a/src/adc/message.h +++ b/src/adc/message.h @@ -171,6 +171,12 @@ extern int adc_msg_replace_named_argument(struct adc_message* cmd, const char pr */ extern int adc_msg_add_argument(struct adc_message* cmd, const char* string); +/** + * Add an argument string, the string will be automatcally escaped. + * @return 0 if successful, or -1 if an error occured (out of memory). + */ +extern int adc_msg_add_argument_string(struct adc_message* cmd, const char* string); + /** * Append a named argument * @@ -209,6 +215,13 @@ extern char* adc_msg_unescape(const char* string); */ extern int adc_msg_unescape_to_target(const char* string, char* target, size_t target_size); +/** + * Returns the length of the string once escaped with + * adc_msg_escape(). + * + * The string must be NULL terminated. + */ +extern int adc_msg_escape_length(const char* str); /** * Convert a string to a ADC command escaped string. @@ -234,4 +247,5 @@ void adc_msg_unterminate(struct adc_message* cmd); */ int adc_msg_get_arg_offset(struct adc_message* msg); + #endif /* HAVE_UHUB_COMMAND_H */