Add a utility routine to do ITU V.250 quoting of strings for AT commands.

BUG=chromium-os:27096,chromium-os:27063
TEST=None
Change-Id: Ic1d24a9e4b7421db7f8d16c52535bd6d2780423e
This commit is contained in:
Nathan Williams
2012-03-23 14:05:40 -04:00
committed by Aleksander Morgado
parent 67698b43c4
commit 00cb8a26a8
2 changed files with 32 additions and 0 deletions

View File

@@ -49,6 +49,32 @@ typedef struct {
/*****************************************************************************/
gchar *
mm_at_serial_port_quote_string (const char *string)
{
int len, i;
gchar *quoted, *pos;
if (string == NULL)
len = 0;
else
len = strlen (string);
quoted = g_malloc (3 + 3 * len); /* worst case */
pos = quoted;
*pos++ = '"';
for (i = 0 ; i < len; i++) {
if (string[i] < 0x20 || string[i] == '"' || string[i] == '\\')
pos += sprintf (pos, "\\%02X", string[i]);
else
*pos++ = string[i];
}
*pos++ = '"';
*pos++ = '\0';
return quoted;
}
void
mm_at_serial_port_set_response_parser (MMAtSerialPort *self,
MMAtSerialResponseParserFn fn,

View File

@@ -104,6 +104,12 @@ void mm_at_serial_port_queue_command_cached (MMAtSerialPort *self,
MMAtSerialResponseFn callback,
gpointer user_data);
/*
* Convert a string into a quoted and escaped string. Returns a new
* allocated string. Follows ITU V.250 5.4.2.2 "String constants".
*/
gchar *mm_at_serial_port_quote_string (const char *string);
/* Just for unit tests */
void mm_at_serial_port_remove_echo (GByteArray *response);