diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2010-11-01 02:05:45 +0100 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2010-11-01 02:05:45 +0100 |
commit | 64e9586ae2953162b3b7ae1c0e11e4df4b0ed787 (patch) | |
tree | 0f704d3ffd81e511f35a8d189491db68e3ad96bc | |
parent | 0b011d307d9f87927fe9db8d0490a31a6a879ce4 (diff) | |
download | connman-64e9586ae2953162b3b7ae1c0e11e4df4b0ed787.tar.gz connman-64e9586ae2953162b3b7ae1c0e11e4df4b0ed787.tar.bz2 connman-64e9586ae2953162b3b7ae1c0e11e4df4b0ed787.zip |
The HTTP status code can be retrieved from result object
-rw-r--r-- | gweb/gweb.c | 15 | ||||
-rw-r--r-- | gweb/gweb.h | 3 | ||||
-rw-r--r-- | tools/web-test.c | 5 | ||||
-rw-r--r-- | tools/wispr.c | 3 |
4 files changed, 16 insertions, 10 deletions
diff --git a/gweb/gweb.c b/gweb/gweb.c index 94da3d1a..eb31ae94 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 cc2324c9..c07e00d6 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 823e1589..c148c912 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 279d5c1c..1492e6b9 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); |