aboutsummaryrefslogtreecommitdiff
path: root/src/mm-at-serial-port.c
diff options
context:
space:
mode:
authorNathan Williams <njw@chromium.org>2012-03-23 14:05:40 -0400
committerAleksander Morgado <aleksander@lanedo.com>2012-05-02 21:05:06 +0200
commit00cb8a26a829bd26ea7f1d953ebdbe657e85f83c (patch)
tree9e5237e78a096f8cd1f8d555a585509a12daf23a /src/mm-at-serial-port.c
parent67698b43c4c088fbd319de6f14914e958a0888d8 (diff)
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
Diffstat (limited to 'src/mm-at-serial-port.c')
-rw-r--r--src/mm-at-serial-port.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/mm-at-serial-port.c b/src/mm-at-serial-port.c
index 4a5afa4b..c16e8786 100644
--- a/src/mm-at-serial-port.c
+++ b/src/mm-at-serial-port.c
@@ -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,