-/**
+/*
* http_client - HTTP client
* Copyright (c) 2009, Jouni Malinen <j@w1.fi>
*
#include "http_client.h"
-#define HTTP_CLIENT_TIMEOUT 30
+#define HTTP_CLIENT_TIMEOUT_SEC 30
struct http_client {
c->req = NULL;
c->hread = httpread_create(c->sd, http_client_got_response, c,
- c->max_response, HTTP_CLIENT_TIMEOUT);
+ c->max_response, HTTP_CLIENT_TIMEOUT_SEC);
if (c->hread == NULL) {
c->cb(c->cb_ctx, c, HTTP_CLIENT_FAILED);
return;
return NULL;
}
- if (eloop_register_timeout(HTTP_CLIENT_TIMEOUT, 0, http_client_timeout,
- c, NULL)) {
+ if (eloop_register_timeout(HTTP_CLIENT_TIMEOUT_SEC, 0,
+ http_client_timeout, c, NULL)) {
http_client_free(c);
return NULL;
}
}
-struct http_client * http_client_url(const char *url,
- struct wpabuf *req, size_t max_response,
- void (*cb)(void *ctx,
- struct http_client *c,
- enum http_client_event event),
- void *cb_ctx)
+char * http_client_url_parse(const char *url, struct sockaddr_in *dst,
+ char **ret_path)
{
- struct sockaddr_in dst;
- struct http_client *c;
char *u, *addr, *port, *path;
- struct wpabuf *req_buf = NULL;
- if (os_strncmp(url, "http://", 7) != 0)
- return NULL;
u = os_strdup(url);
if (u == NULL)
return NULL;
- os_memset(&dst, 0, sizeof(dst));
- dst.sin_family = AF_INET;
+
+ os_memset(dst, 0, sizeof(*dst));
+ dst->sin_family = AF_INET;
addr = u + 7;
path = os_strchr(addr, '/');
port = os_strchr(addr, ':');
if (port)
*port++ = '\0';
- if (inet_aton(addr, &dst.sin_addr) == 0) {
+ if (inet_aton(addr, &dst->sin_addr) == 0) {
/* TODO: name lookup */
wpa_printf(MSG_DEBUG, "HTTP: Unsupported address in URL '%s' "
"(addr='%s' port='%s')",
}
if (port)
- dst.sin_port = htons(atoi(port));
+ dst->sin_port = htons(atoi(port));
else
- dst.sin_port = htons(80);
+ dst->sin_port = htons(80);
if (*path == '\0') {
/* remove temporary nul termination for address */
*path = '/';
}
+ *ret_path = path;
+
+ return u;
+}
+
+
+struct http_client * http_client_url(const char *url,
+ struct wpabuf *req, size_t max_response,
+ void (*cb)(void *ctx,
+ struct http_client *c,
+ enum http_client_event event),
+ void *cb_ctx)
+{
+ struct sockaddr_in dst;
+ struct http_client *c;
+ char *u, *path;
+ struct wpabuf *req_buf = NULL;
+
+ if (os_strncmp(url, "http://", 7) != 0)
+ return NULL;
+ u = http_client_url_parse(url, &dst, &path);
+ if (u == NULL)
+ return NULL;
+
if (req == NULL) {
req_buf = wpabuf_alloc(os_strlen(url) + 1000);
if (req_buf == NULL) {
}
+char * http_client_get_hdr_line(struct http_client *c, const char *tag)
+{
+ if (c->hread == NULL)
+ return NULL;
+ return httpread_hdr_line_get(c->hread, tag);
+}
+
+
char * http_link_update(char *url, const char *base)
{
char *n;
os_snprintf(n, len, "%s%s", base, url);
} else {
os_memcpy(n, base, pos - base);
- os_memcpy(n + (pos - base), url, os_strlen(url));
+ os_memcpy(n + (pos - base), url, os_strlen(url) + 1);
}
} else {
pos = os_strrchr(base + 7, '/');
os_snprintf(n, len, "%s/%s", base, url);
} else {
os_memcpy(n, base, pos - base + 1);
- os_memcpy(n + (pos - base) + 1, url, os_strlen(url));
+ os_memcpy(n + (pos - base) + 1, url, os_strlen(url) +
+ 1);
}
}