summaryrefslogtreecommitdiff
path: root/gweb
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2010-10-31 00:59:38 +0200
committerMarcel Holtmann <marcel@holtmann.org>2010-10-31 00:59:38 +0200
commit3b9a4a65e4850a01713324634fa7ccd064322508 (patch)
treee4eec8a97b229ad106266789db40e39b8d020bfd /gweb
parent000a60dfed237e3d00584f0c3b475aa777be1ae0 (diff)
downloadconnman-3b9a4a65e4850a01713324634fa7ccd064322508.tar.gz
connman-3b9a4a65e4850a01713324634fa7ccd064322508.tar.bz2
connman-3b9a4a65e4850a01713324634fa7ccd064322508.zip
Add support for parsing HTTP status code response
Diffstat (limited to 'gweb')
-rw-r--r--gweb/gweb.c15
-rw-r--r--gweb/gweb.h2
2 files changed, 17 insertions, 0 deletions
diff --git a/gweb/gweb.c b/gweb/gweb.c
index 1add7106..bfeecc87 100644
--- a/gweb/gweb.c
+++ b/gweb/gweb.c
@@ -41,6 +41,7 @@
#define SESSION_FLAG_USE_TLS (1 << 0)
struct _GWebResult {
+ guint status;
const guint8 *buffer;
gsize length;
};
@@ -340,6 +341,7 @@ static gboolean received_data(GIOChannel *channel, GIOCondition cond,
while (str != NULL) {
char *start = session->current_line;
+ unsigned int code;
*str = '\0';
count = strlen(start);
@@ -362,6 +364,11 @@ static gboolean received_data(GIOChannel *channel, GIOCondition cond,
//printf("[ %s ]\n", start);
+ if (session->result.status == 0) {
+ if (sscanf(start, "HTTP/%*s %u %*s", &code) == 1)
+ session->result.status = code;
+ }
+
str = memchr(session->current_line, '\n',
bytes_read - consumed);
}
@@ -628,6 +635,14 @@ guint g_web_request(GWeb *web, GWebMethod method, const char *url,
return web->next_query_id++;
}
+guint16 g_web_result_get_status(GWebResult *result)
+{
+ if (result == NULL)
+ return 0;
+
+ return result->status;
+}
+
gboolean g_web_result_get_chunk(GWebResult *result,
const guint8 **chunk, gsize *length)
{
diff --git a/gweb/gweb.h b/gweb/gweb.h
index daeb262d..24c84a03 100644
--- a/gweb/gweb.h
+++ b/gweb/gweb.h
@@ -67,6 +67,8 @@ guint g_web_request(GWeb *web, GWebMethod method, const char *url,
gboolean g_web_cancel(GWeb *web, guint id);
+guint16 g_web_result_get_status(GWebResult *result);
+
gboolean g_web_result_get_chunk(GWebResult *result,
const guint8 **chunk, gsize *length);