Added methods for adding a string to be escaped automatically.

Previously only existed for named parameters.
This commit is contained in:
Jan Vidar Krey 2013-02-13 21:11:05 +01:00
parent 51a8e785c0
commit 5c31f47bea
2 changed files with 21 additions and 2 deletions

View File

@ -787,6 +787,13 @@ int adc_msg_add_argument(struct adc_message* cmd, const char* string)
return 0; 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) 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; return -1;
} }
int adc_msg_escape_length(const char* str) int adc_msg_escape_length(const char* str)
{ {
int add = 0; int add = 0;

View File

@ -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); 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 * 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); 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. * 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); int adc_msg_get_arg_offset(struct adc_message* msg);
#endif /* HAVE_UHUB_COMMAND_H */ #endif /* HAVE_UHUB_COMMAND_H */