summaryrefslogtreecommitdiffstats
path: root/gatchat/gatresult.c
diff options
context:
space:
mode:
authorAndrzej Zaborowski <andrew.zaborowski@intel.com>2009-05-22 13:58:49 +0200
committerDenis Kenzior <denkenz@gmail.com>2009-05-26 18:15:53 -0500
commit41afb58bd74a1f949fbe4d3001939f0663db7bfd (patch)
tree4a38b5004832484cbb93f694691a50868a595973 /gatchat/gatresult.c
parent70fce6b5512a42f97fc6fb725c0d1e8465db4ad1 (diff)
downloadofono-41afb58bd74a1f949fbe4d3001939f0663db7bfd.tar.bz2
Add hex-encoded character string getter to AtChat
Diffstat (limited to 'gatchat/gatresult.c')
-rw-r--r--gatchat/gatresult.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/gatchat/gatresult.c b/gatchat/gatresult.c
index 87457f1c..8da88211 100644
--- a/gatchat/gatresult.c
+++ b/gatchat/gatresult.c
@@ -24,6 +24,7 @@
#endif
#include <string.h>
+#include <stdio.h>
#include <glib.h>
@@ -148,6 +149,58 @@ out:
return TRUE;
}
+gboolean g_at_result_iter_next_hexstring(GAtResultIter *iter,
+ const guint8 **str, gint *length)
+{
+ unsigned int pos;
+ unsigned int end;
+ unsigned int len;
+ char *line;
+ char *bufpos;
+
+ if (!iter)
+ return FALSE;
+
+ if (!iter->l)
+ return FALSE;
+
+ line = iter->l->data;
+ len = strlen(line);
+
+ pos = iter->line_pos;
+
+ /* Omitted string */
+ if (line[pos] == ',') {
+ end = pos;
+ memset(iter->buf, 0, sizeof(iter->buf));
+ goto out;
+ }
+
+ end = pos;
+
+ while (end < len && g_ascii_isxdigit(line[end]))
+ end += 1;
+
+ if ((end - pos) & 1)
+ return FALSE;
+
+ if ((end - pos) / 2 >= sizeof(iter->buf))
+ return FALSE;
+ *length = (end - pos) / 2;
+
+ for (bufpos = iter->buf; pos < end; pos += 2)
+ sscanf(line + pos, "%02hhx", bufpos++);
+ memset(bufpos, 0, sizeof(iter->buf) - (bufpos - iter->buf));
+
+out:
+ iter->line_pos = skip_to_next_field(line, end, len);
+
+ if (str)
+ *str = (guint8 *) iter->buf;
+
+ return TRUE;
+}
+
gboolean g_at_result_iter_next_number(GAtResultIter *iter, gint *number)
{
int pos;