From 64e9586ae2953162b3b7ae1c0e11e4df4b0ed787 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Mon, 1 Nov 2010 02:05:45 +0100 Subject: [PATCH] The HTTP status code can be retrieved from result object --- gweb/gweb.c | 15 +++++++++------ gweb/gweb.h | 3 +-- tools/web-test.c | 5 ++++- tools/wispr.c | 3 ++- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/gweb/gweb.c b/gweb/gweb.c index 94da3d1..eb31ae9 100644 --- a/gweb/gweb.c +++ b/gweb/gweb.c @@ -41,7 +41,7 @@ #define SESSION_FLAG_USE_TLS (1 << 0) struct _GWebResult { - guint status; + guint16 status; const guint8 *buffer; gsize length; }; @@ -297,12 +297,15 @@ gboolean g_web_get_close_connection(GWeb *web) return web->close_connection; } -static inline void call_result_func(struct web_session *session, guint status) +static inline void call_result_func(struct web_session *session, guint16 status) { if (session->result_func == NULL) return; - session->result_func(status, &session->result, session->result_data); + if (status != 0) + session->result.status = status; + + session->result_func(&session->result, session->result_data); } static gboolean received_data(GIOChannel *channel, GIOCondition cond, @@ -331,7 +334,7 @@ static gboolean received_data(GIOChannel *channel, GIOCondition cond, session->transport_watch = 0; session->result.buffer = NULL; session->result.length = 0; - call_result_func(session, 200); + call_result_func(session, 0); return FALSE; } @@ -340,7 +343,7 @@ static gboolean received_data(GIOChannel *channel, GIOCondition cond, if (session->header_done == TRUE) { session->result.buffer = session->receive_buffer; session->result.length = bytes_read; - call_result_func(session, 100); + call_result_func(session, 0); return TRUE; } @@ -373,7 +376,7 @@ static gboolean received_data(GIOChannel *channel, GIOCondition cond, session->header_done = TRUE; session->result.buffer = pos + 1; session->result.length = bytes_read; - call_result_func(session, 100); + call_result_func(session, 0); break; } diff --git a/gweb/gweb.h b/gweb/gweb.h index cc2324c..c07e00d 100644 --- a/gweb/gweb.h +++ b/gweb/gweb.h @@ -42,8 +42,7 @@ typedef enum { G_WEB_METHOD_GET, } GWebMethod; -typedef void (*GWebResultFunc)(guint16 status, GWebResult *result, - gpointer user_data); +typedef void (*GWebResultFunc)(GWebResult *result, gpointer user_data); typedef void (*GWebDebugFunc)(const char *str, gpointer user_data); diff --git a/tools/web-test.c b/tools/web-test.c index 823e158..c148c91 100644 --- a/tools/web-test.c +++ b/tools/web-test.c @@ -43,10 +43,13 @@ static void sig_term(int sig) g_main_loop_quit(main_loop); } -static void web_result(guint16 status, GWebResult *result, gpointer user_data) +static void web_result(GWebResult *result, gpointer user_data) { + guint16 status; gdouble elapsed; + status = g_web_result_get_status(result); + elapsed = g_timer_elapsed(timer, NULL); g_print("elapse: %f seconds\n", elapsed); diff --git a/tools/wispr.c b/tools/wispr.c index 279d5c1..1492e6b 100644 --- a/tools/wispr.c +++ b/tools/wispr.c @@ -240,10 +240,11 @@ static void parser_callback(const char *str, gpointer user_data) static guint request_id; static GWebParser *request_parser; -static void web_result(guint16 status, GWebResult *result, gpointer user_data) +static void web_result(GWebResult *result, gpointer user_data) { const guint8 *chunk; gsize length; + guint16 status; gdouble elapsed; status = g_web_result_get_status(result); -- 2.7.4