diff options
author | Andrzej Zaborowski <andrew.zaborowski@intel.com> | 2009-05-22 13:58:49 +0200 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2009-05-26 18:15:53 -0500 |
commit | 41afb58bd74a1f949fbe4d3001939f0663db7bfd (patch) | |
tree | 4a38b5004832484cbb93f694691a50868a595973 /gatchat/gatresult.c | |
parent | 70fce6b5512a42f97fc6fb725c0d1e8465db4ad1 (diff) | |
download | ofono-41afb58bd74a1f949fbe4d3001939f0663db7bfd.tar.bz2 |
Add hex-encoded character string getter to AtChat
Diffstat (limited to 'gatchat/gatresult.c')
-rw-r--r-- | gatchat/gatresult.c | 53 |
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; |