From: Andrzej Zaborowski Date: Fri, 22 May 2009 11:58:49 +0000 (+0200) Subject: Add hex-encoded character string getter to AtChat X-Git-Tag: maemo-0.19~8 X-Git-Url: https://vcs.maemo.org/git/?p=connman;a=commitdiff_plain;h=930cfd8ec8a0d0e0d4a24af709a884804799c58e Add hex-encoded character string getter to AtChat --- diff --git a/gatchat/gatresult.c b/gatchat/gatresult.c index 87457f1..8da8821 100644 --- a/gatchat/gatresult.c +++ b/gatchat/gatresult.c @@ -24,6 +24,7 @@ #endif #include +#include #include @@ -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; diff --git a/gatchat/gatresult.h b/gatchat/gatresult.h index 8259e7c..cbe6d05 100644 --- a/gatchat/gatresult.h +++ b/gatchat/gatresult.h @@ -54,6 +54,8 @@ gboolean g_at_result_iter_skip_next(GAtResultIter *iter); gboolean g_at_result_iter_next_range(GAtResultIter *iter, gint *min, gint *max); gboolean g_at_result_iter_next_string(GAtResultIter *iter, const char **str); gboolean g_at_result_iter_next_number(GAtResultIter *iter, gint *number); +gboolean g_at_result_iter_next_hexstring(GAtResultIter *iter, + const guint8 **str, gint *length); const char *g_at_result_iter_raw_line(GAtResultIter *iter);