Support new GWeb format.
---
tools/web-test.c | 29 +++++++++++++++++++++++++++--
1 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/tools/web-test.c b/tools/web-test.c
index 253948f..b953b0a 100644
--- a/tools/web-test.c
+++ b/tools/web-test.c
@@ -34,6 +34,8 @@ static GTimer *timer;
static GMainLoop *main_loop;
+static GString *content;
+
static void web_debug(const char *str, void *data)
{
g_print("%s: %s\n", (const char *) data, str);
@@ -50,6 +52,7 @@ static void web_result(uint16_t status, gpointer user_data)
elapsed = g_timer_elapsed(timer, NULL);
+ g_print("%s", content->str);
g_print("elapse: %f seconds\n", elapsed);
g_print("status: %03u\n", status);
@@ -57,14 +60,25 @@ static void web_result(uint16_t status, gpointer user_data)
g_main_loop_quit(main_loop);
}
+static gboolean received_data(const unsigned char *str, int len,
+ GWebDataType data_type,
+ gpointer user_data)
+{
+ g_string_append_len(content, (gchar *)str, len);
+ return TRUE;
+}
+
static gboolean option_debug = FALSE;
static gchar *option_nameserver = NULL;
+static gchar *option_proxy = NULL;
static GOptionEntry options[] = {
{ "debug", 'd', 0, G_OPTION_ARG_NONE, &option_debug,
"Enable debug output" },
{ "nameserver", 'n', 0, G_OPTION_ARG_STRING, &option_nameserver,
"Specify nameserver", "ADDRESS" },
+ { "proxy", 'p', 0, G_OPTION_ARG_STRING, &option_proxy,
+ "Specify proxy", "ADDRESS" },
{ NULL },
};
@@ -95,7 +109,16 @@ int main(int argc, char *argv[])
return 1;
}
- web = g_web_new(index);
+ content = g_string_sized_new(1024);
+ if (content == NULL) {
+ printf("failed to allocate buf\n");
+ return 1;
+ }
+
+ web = g_web_new(index, option_proxy);
+ if (option_proxy != NULL)
+ g_free(option_proxy);
+
if (web == NULL) {
printf("failed to web service\n");
return 1;
@@ -114,7 +137,7 @@ int main(int argc, char *argv[])
timer = g_timer_new();
if (g_web_request(web, G_WEB_METHOD_GET, argv[1],
- web_result, NULL) == 0) {
+ received_data, web_result, NULL) == 0) {
printf("failed to start request\n");
return 1;
}
@@ -130,6 +153,8 @@ int main(int argc, char *argv[])
g_web_unref(web);
+ g_string_free(content, TRUE);
+
g_main_loop_unref(main_loop);
return 0;
--
1.7.2.3
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman