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:

committed by
Aleksander Morgado

parent
67698b43c4
commit
00cb8a26a8
@@ -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,
|
||||
|
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user