summaryrefslogtreecommitdiff
path: root/gweb
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2011-01-01 22:32:07 -0800
committerMarcel Holtmann <marcel@holtmann.org>2011-01-01 22:32:07 -0800
commitacdc215b11a42566027a3272c48d9ccf2f99c09b (patch)
tree2c34c537847327ed0d8354139cc9b3b6f73863ce /gweb
parent6b05f1c07e2d43c6c60fe950e3b62897ce133976 (diff)
downloadconnman-acdc215b11a42566027a3272c48d9ccf2f99c09b.tar.gz
connman-acdc215b11a42566027a3272c48d9ccf2f99c09b.tar.bz2
connman-acdc215b11a42566027a3272c48d9ccf2f99c09b.zip
gweb: Add support for handling proxy information
Diffstat (limited to 'gweb')
-rw-r--r--gweb/gweb.c59
1 files changed, 54 insertions, 5 deletions
diff --git a/gweb/gweb.c b/gweb/gweb.c
index 9d746c82..229989ef 100644
--- a/gweb/gweb.c
+++ b/gweb/gweb.c
@@ -921,7 +921,8 @@ static int create_transport(struct web_session *session)
return 0;
}
-static int parse_url(struct web_session *session, const char *url)
+static int parse_url(struct web_session *session,
+ const char *url, const char *proxy)
{
char *scheme, *host, *port, *path;
@@ -952,7 +953,52 @@ static int parse_url(struct web_session *session, const char *url)
if (path != NULL)
*(path++) = '\0';
- session->request = g_strdup_printf("/%s", path ? path : "");
+ if (proxy == NULL)
+ session->request = g_strdup_printf("/%s", path ? path : "");
+ else
+ session->request = g_strdup(url);
+
+ port = strrchr(host, ':');
+ if (port != NULL) {
+ char *end;
+ int tmp = strtol(port + 1, &end, 10);
+
+ if (*end == '\0') {
+ *port = '\0';
+ session->port = tmp;
+ }
+
+ if (proxy == NULL)
+ session->host = g_strdup(host);
+ else
+ session->host = g_strdup_printf("%s:%u", host, tmp);
+ } else
+ session->host = g_strdup(host);
+
+ g_free(scheme);
+
+ if (proxy == NULL)
+ return 0;
+
+ scheme = g_strdup(proxy);
+ if (scheme == NULL)
+ return -EINVAL;
+
+ host = strstr(proxy, "://");
+ if (host != NULL) {
+ *host = '\0';
+ host += 3;
+
+ if (strcasecmp(scheme, "http") != 0) {
+ g_free(scheme);
+ return -EINVAL;
+ }
+ } else
+ host = scheme;
+
+ path = strchr(host, '/');
+ if (path != NULL)
+ *(path++) = '\0';
port = strrchr(host, ':');
if (port != NULL) {
@@ -965,7 +1011,7 @@ static int parse_url(struct web_session *session, const char *url)
}
}
- session->host = g_strdup(host);
+ session->address = g_strdup(host);
g_free(scheme);
@@ -1012,13 +1058,16 @@ static guint do_request(GWeb *web, const char *url,
if (session == NULL)
return 0;
- if (parse_url(session, url) < 0) {
+ if (parse_url(session, url, web->proxy) < 0) {
free_session(session);
return 0;
}
- debug(web, "host %s:%u", session->host, session->port);
+ debug(web, "address %s", session->address);
+ debug(web, "port %u", session->port);
+ debug(web, "host %s", session->host);
debug(web, "flags %lu", session->flags);
+ debug(web, "request %s", session->request);
if (type != NULL) {
session->content_type = g_strdup(type);