Add support for parsing HTTP status code response
authorMarcel Holtmann <marcel@holtmann.org>
Sat, 30 Oct 2010 22:59:38 +0000 (00:59 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Sat, 30 Oct 2010 22:59:38 +0000 (00:59 +0200)
gweb/gweb.c
gweb/gweb.h

index 1add710..bfeecc8 100644 (file)
@@ -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)
 {
index daeb262..24c84a0 100644 (file)
@@ -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);