Index: .bzrignore
===================================================================
--- .bzrignore	(revision 41e871f7e9f10623b34845b191718605cbd70730)
+++ .bzrignore	(revision d7b7f5e312adb3acb6e7c2044551454dfd1e4019)
@@ -273,2 +273,4 @@
 uspace/app/df/df
 uspace/dist/app/df
+uspace/app/download/download
+uspace/dist/app/download
Index: boot/Makefile.common
===================================================================
--- boot/Makefile.common	(revision 41e871f7e9f10623b34845b191718605cbd70730)
+++ boot/Makefile.common	(revision d7b7f5e312adb3acb6e7c2044551454dfd1e4019)
@@ -174,4 +174,5 @@
 	$(USPACE_PATH)/app/dnscfg/dnscfg \
 	$(USPACE_PATH)/app/dnsres/dnsres \
+	$(USPACE_PATH)/app/download/download \
 	$(USPACE_PATH)/app/edit/edit \
 	$(USPACE_PATH)/app/inet/inet \
Index: uspace/Makefile
===================================================================
--- uspace/Makefile	(revision 41e871f7e9f10623b34845b191718605cbd70730)
+++ uspace/Makefile	(revision d7b7f5e312adb3acb6e7c2044551454dfd1e4019)
@@ -42,4 +42,5 @@
 	app/dnscfg \
 	app/dnsres \
+	app/download \
 	app/edit \
 	app/getterm \
@@ -234,4 +235,5 @@
 	lib/gui \
 	lib/hound \
+	lib/http \
 	lib/softrend \
 	lib/draw \
@@ -239,4 +241,5 @@
 	lib/nic \
 	lib/ext4 \
+	lib/uri \
 	lib/usb \
 	lib/usbhost \
Index: uspace/Makefile.common
===================================================================
--- uspace/Makefile.common	(revision 41e871f7e9f10623b34845b191718605cbd70730)
+++ uspace/Makefile.common	(revision d7b7f5e312adb3acb6e7c2044551454dfd1e4019)
@@ -141,4 +141,7 @@
 LIBBITHENGE_PREFIX = $(LIB_PREFIX)/bithenge
 
+LIBHTTP_PREFIX = $(LIB_PREFIX)/http
+LIBURI_PREFIX = $(LIB_PREFIX)/uri
+
 ifeq ($(STATIC_NEEDED),y)
 	STATIC_BUILD = y
Index: uspace/app/download/Makefile
===================================================================
--- uspace/app/download/Makefile	(revision d7b7f5e312adb3acb6e7c2044551454dfd1e4019)
+++ uspace/app/download/Makefile	(revision d7b7f5e312adb3acb6e7c2044551454dfd1e4019)
@@ -0,0 +1,38 @@
+#
+# Copyright (c) 2013 Martin Sucha
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+USPACE_PREFIX = ../..
+LIBS = $(LIBHTTP_PREFIX)/libhttp.a $(LIBURI_PREFIX)/liburi.a
+EXTRA_CFLAGS = -I$(LIBHTTP_PREFIX) -I$(LIBURI_PREFIX)
+DEFS = -DRELEASE=$(RELEASE)
+BINARY = download
+
+SOURCES = \
+	main.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/app/download/main.c
===================================================================
--- uspace/app/download/main.c	(revision d7b7f5e312adb3acb6e7c2044551454dfd1e4019)
+++ uspace/app/download/main.c	(revision d7b7f5e312adb3acb6e7c2044551454dfd1e4019)
@@ -0,0 +1,219 @@
+/*
+ * Copyright (c) 2013 Martin Sucha
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup download
+ * @{
+ */
+
+/** @file
+ * Download a file from a HTTP server
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <str.h>
+#include <str_error.h>
+#include <task.h>
+#include <macros.h>
+
+#include <net/in.h>
+#include <net/inet.h>
+#include <net/socket.h>
+
+#include <http.h>
+#include <uri.h>
+
+#define NAME "download"
+#ifdef TIMESTAMP_UNIX
+#define VERSION STRING(RELEASE) "-" STRING(TIMESTAMP_UNIX)
+#else
+#define VERSION STRING(RELEASE)
+#endif
+#define USER_AGENT "HelenOS-" NAME "/" VERSION
+
+static void syntax_print(void)
+{
+	fprintf(stderr, "Usage: download <url>\n");
+	fprintf(stderr, "  This will write the data to stdout, so you may want\n");
+	fprintf(stderr, "  to redirect the output, e.g.\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "    download http://helenos.org/ | to helenos.html\n\n");
+}
+
+int main(int argc, char *argv[])
+{
+	if (argc != 2) {
+		syntax_print();
+		return 2;
+	}
+	
+	uri_t *uri = uri_parse(argv[1]);
+	if (uri == NULL) {
+		fprintf(stderr, "Failed parsing URI\n");
+		return 2;
+	}
+	
+	if (!uri_validate(uri)) {
+		fprintf(stderr, "The URI is invalid\n");
+		return 2;
+	}
+	
+	/* TODO uri_normalize(uri) */
+	
+	if (str_cmp(uri->scheme, "http") != 0) {
+		fprintf(stderr, "Only http scheme is supported at the moment\n");
+		return 2;
+	}
+	
+	if (uri->host == NULL) {
+		fprintf(stderr, "host not set\n");
+		return 2;
+	}
+	
+	uint16_t port = 80;
+	if (uri->port != NULL) {
+		int rc = str_uint16_t(uri->port, NULL, 10, true, &port);
+		if (rc != EOK) {
+			fprintf(stderr, "Invalid port number: %s\n", uri->port);
+			return 2;
+		}
+	}
+	
+	const char *path = uri->path;
+	if (path == NULL || *path == 0)
+		path = "/";
+	char *server_path = NULL;
+	if (uri->query == NULL) {
+		server_path = str_dup(path);
+		if (server_path == NULL) {
+			fprintf(stderr, "Failed allocating path\n");
+			uri_destroy(uri);
+			return 3;
+		}
+	}
+	else {
+		int rc = asprintf(&server_path, "%s?%s", path, uri->query);
+		if (rc < 0) {
+			fprintf(stderr, "Failed allocating path\n");
+			uri_destroy(uri);
+			return 3;
+		}
+	}
+	
+	http_request_t *req = http_request_create("GET", server_path);
+	free(server_path);
+	if (req == NULL) {
+		fprintf(stderr, "Failed creating request\n");
+		uri_destroy(uri);
+		free(server_path);
+		return 3;
+	}
+	
+	http_header_t *header_host = http_header_create("Host", uri->host);
+	if (header_host == NULL) {
+		fprintf(stderr, "Failed creating Host header\n");
+		uri_destroy(uri);
+		free(server_path);
+		return 3;
+	}
+	list_append(&header_host->link, &req->headers);
+	
+	http_header_t *header_ua = http_header_create("User-Agent", USER_AGENT);
+	if (header_ua == NULL) {
+		fprintf(stderr, "Failed creating User-Agent header\n");
+		uri_destroy(uri);
+		free(server_path);
+		return 3;
+	}
+	list_append(&header_ua->link, &req->headers);
+	
+	http_t *http = http_create(uri->host, port);
+	if (http == NULL) {
+		uri_destroy(uri);
+		free(server_path);
+		fprintf(stderr, "Failed creating HTTP object\n");
+		return 3;
+	}
+	
+	int rc = http_connect(http);
+	if (rc != EOK) {
+		fprintf(stderr, "Failed connecting: %s\n", str_error(rc));
+		uri_destroy(uri);
+		free(server_path);
+		return rc;
+	}
+	
+	rc = http_send_request(http, req);
+	if (rc != EOK) {
+		fprintf(stderr, "Failed sending request: %s\n", str_error(rc));
+		uri_destroy(uri);
+		free(server_path);
+		return rc;
+	}
+	
+	http_response_t *response = NULL;
+	rc = http_receive_response(http, &response);
+	if (rc != EOK) {
+		fprintf(stderr, "Failed receiving response: %s\n", str_error(rc));
+		uri_destroy(uri);
+		free(server_path);
+		return rc;
+	}
+	
+	if (response->status != 200) {
+		fprintf(stderr, "Server returned status %d %s\n", response->status,
+		    response->message);
+	}
+	else {
+		size_t buf_size = 4096;
+		void *buf = malloc(buf_size);
+		if (buf == NULL) {
+			fprintf(stderr, "Failed allocating buffer\n)");
+			uri_destroy(uri);
+			free(server_path);
+			return ENOMEM;
+		}
+		
+		int body_size;
+		while ((body_size = http_receive_body(http, buf, buf_size)) > 0) {
+			fwrite(buf, 1, body_size, stdout);
+		}
+		
+		if (body_size != 0) {
+			fprintf(stderr, "Failed receiving body: %s", str_error(body_size));
+		}
+	}
+	
+	uri_destroy(uri);
+	free(server_path);
+	return EOK;
+}
+
+/** @}
+ */
Index: uspace/lib/http/Makefile
===================================================================
--- uspace/lib/http/Makefile	(revision d7b7f5e312adb3acb6e7c2044551454dfd1e4019)
+++ uspace/lib/http/Makefile	(revision d7b7f5e312adb3acb6e7c2044551454dfd1e4019)
@@ -0,0 +1,38 @@
+#
+# Copyright (c) 2013 Martin Sucha
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+USPACE_PREFIX = ../..
+LIBRARY = libhttp
+SLIBRARY = libhttp.so.0.0
+LSONAME = libhttp.so0
+#EXTRA_CFLAGS += 
+
+SOURCES = \
+	http.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/lib/http/http.c
===================================================================
--- uspace/lib/http/http.c	(revision d7b7f5e312adb3acb6e7c2044551454dfd1e4019)
+++ uspace/lib/http/http.c	(revision d7b7f5e312adb3acb6e7c2044551454dfd1e4019)
@@ -0,0 +1,530 @@
+/*
+ * Copyright (c) 2013 Martin Sucha
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup http
+ * @{
+ */
+/**
+ * @file
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <str.h>
+#include <macros.h>
+
+#include <net/socket.h>
+#include <inet/dnsr.h>
+
+#include "http.h"
+
+#define HTTP_METHOD_LINE "%s %s HTTP/1.1\r\n"
+#define HTTP_HEADER_LINE "%s: %s\r\n"
+#define HTTP_REQUEST_LINE "\r\n"
+
+static char *cut_str(const char *start, const char *end)
+{
+	size_t size = end - start;
+	return str_ndup(start, size);
+}
+
+static void recv_reset(http_t *http)
+{
+	http->recv_buffer_in = 0;
+	http->recv_buffer_out = 0;
+}
+
+/** Receive one character (with buffering) */
+static int recv_char(http_t *http, char *c, bool consume)
+{
+	if (http->recv_buffer_out == http->recv_buffer_in) {
+		recv_reset(http);
+		
+		ssize_t rc = recv(http->conn_sd, http->recv_buffer, http->buffer_size, 0);
+		if (rc <= 0)
+			return rc;
+		
+		http->recv_buffer_in = rc;
+	}
+	
+	*c = http->recv_buffer[http->recv_buffer_out];
+	if (consume)
+		http->recv_buffer_out++;
+	return EOK;
+}
+
+static ssize_t recv_buffer(http_t *http, char *buf, size_t buf_size)
+{
+	/* Flush any buffered data*/
+	if (http->recv_buffer_out != http->recv_buffer_in) {
+		size_t size = min(http->recv_buffer_in - http->recv_buffer_out, buf_size);
+		memcpy(buf, http->recv_buffer + http->recv_buffer_out, size);
+		http->recv_buffer_out += size;
+		return size;
+	}
+	
+	return recv(http->conn_sd, buf, buf_size, 0);
+}
+
+/** Receive a character and if it is c, discard it from input buffer */
+static int recv_discard(http_t *http, char discard)
+{
+	char c = 0;
+	int rc = recv_char(http, &c, false);
+	if (rc != EOK)
+		return rc;
+	if (c != discard)
+		return EOK;
+	return recv_char(http, &c, true);
+}
+
+/* Receive a single line */
+static ssize_t recv_line(http_t *http, char *line, size_t size)
+{
+	size_t written = 0;
+	
+	while (written < size) {
+		char c = 0;
+		int rc = recv_char(http, &c, true);
+		if (rc != EOK)
+			return rc;
+		if (c == '\n') {
+			recv_discard(http, '\r');
+			line[written++] = 0;
+			return written;
+		}
+		else if (c == '\r') {
+			recv_discard(http, '\n');
+			line[written++] = 0;
+			return written;
+		}
+		line[written++] = c;
+	}
+	
+	return ELIMIT;
+}
+
+http_t *http_create(const char *host, uint16_t port)
+{
+	http_t *http = malloc(sizeof(http_t));
+	if (http == NULL)
+		return NULL;
+	
+	http->host = str_dup(host);
+	if (http->host == NULL) {
+		free(http);
+		return NULL;
+	}
+	http->port = port;
+	
+	http->buffer_size = 4096;
+	http->recv_buffer = malloc(http->buffer_size);
+	if (http->recv_buffer == NULL) {
+		free(http->host);
+		free(http);
+		return NULL;
+	}
+	
+	return http;
+}
+
+int http_connect(http_t *http)
+{
+	if (http->connected)
+		return EBUSY;
+	
+	/* Interpret as address */
+	int rc = inet_addr_parse(http->host, &http->addr);
+	
+	if (rc != EOK) {
+		/* Interpret as a host name */
+		dnsr_hostinfo_t *hinfo = NULL;
+		rc = dnsr_name2host(http->host, &hinfo, AF_NONE);
+		
+		if (rc != EOK)
+			return rc;
+		
+		http->addr = hinfo->addr;
+		dnsr_hostinfo_destroy(hinfo);
+	}
+	
+	struct sockaddr_in addr;
+	struct sockaddr_in6 addr6;
+	uint16_t af = inet_addr_sockaddr_in(&http->addr, &addr, &addr6);
+	
+	http->conn_sd = socket(PF_INET, SOCK_STREAM, 0);
+	if (http->conn_sd < 0)
+		return http->conn_sd;
+	
+	switch (af) {
+	case AF_INET:
+		addr.sin_port = htons(http->port);
+		rc = connect(http->conn_sd, (struct sockaddr *) &addr, sizeof(addr));
+		break;
+	case AF_INET6:
+		addr6.sin6_port = htons(http->port);
+		rc = connect(http->conn_sd, (struct sockaddr *) &addr6, sizeof(addr6));
+		break;
+	default:
+		return ENOTSUP;
+	}
+	
+	return rc;
+}
+
+http_header_t *http_header_create(const char *name, const char *value)
+{
+	char *dname = str_dup(name);
+	if (dname == NULL)
+		return NULL;
+	
+	char *dvalue = str_dup(value);
+	if (dvalue == NULL) {
+		free(dname);
+		return NULL;
+	}
+
+	return http_header_create_no_copy(dname, dvalue);
+}
+
+http_header_t *http_header_create_no_copy(char *name, char *value)
+{
+	http_header_t *header = malloc(sizeof(http_header_t));
+	if (header == NULL)
+		return NULL;
+	
+	link_initialize(&header->link);
+	header->name = name;
+	header->value = value;
+	
+	return header;
+}
+
+void http_header_destroy(http_header_t *header)
+{
+	free(header->name);
+	free(header->value);
+	free(header);
+}
+
+http_request_t *http_request_create(const char *method, const char *path)
+{
+	http_request_t *req = malloc(sizeof(http_request_t));
+	if (req == NULL)
+		return NULL;
+	
+	req->method = str_dup(method);
+	if (req->method == NULL) {
+		free(req);
+		return NULL;
+	}
+	
+	req->path = str_dup(path);
+	if (req->path == NULL) {
+		free(req->method);
+		free(req);
+		return NULL;
+	}
+	
+	list_initialize(&req->headers);
+	
+	return req;
+}
+
+void http_request_destroy(http_request_t *req)
+{
+	free(req->method);
+	free(req->path);
+	link_t *link = req->headers.head.next;
+	while (link != &req->headers.head) {
+		link_t *next = link->next;
+		http_header_t *header = list_get_instance(link, http_header_t, link);
+		http_header_destroy(header);
+		link = next;
+	}
+	free(req);
+}
+
+static ssize_t http_encode_method(char *buf, size_t buf_size,
+    const char *method, const char *path)
+{
+	if (buf == NULL) {
+		return printf_size(HTTP_METHOD_LINE, method, path);
+	}
+	else {
+		return snprintf(buf, buf_size, HTTP_METHOD_LINE, method, path);
+	}
+}
+
+static ssize_t http_encode_header(char *buf, size_t buf_size,
+    http_header_t *header)
+{
+	/* TODO properly split long header values */
+	if (buf == NULL) {
+		return printf_size(HTTP_HEADER_LINE, header->name, header->value);
+	}
+	else {
+		return snprintf(buf, buf_size,
+		    HTTP_HEADER_LINE, header->name, header->value);
+	}
+}
+
+int http_request_format(http_request_t *req, char **out_buf,
+    size_t *out_buf_size)
+{
+	/* Compute the size of the request */
+	ssize_t meth_size = http_encode_method(NULL, 0, req->method, req->path);
+	if (meth_size < 0)
+		return meth_size;
+	size_t size = meth_size;
+	
+	list_foreach(req->headers, link, http_header_t, header) {
+		ssize_t header_size = http_encode_header(NULL, 0, header);
+		if (header_size < 0)
+			return header_size;
+		size += header_size;
+	}
+	size += str_length(HTTP_REQUEST_LINE);
+	
+	char *buf = malloc(size);
+	if (buf == NULL)
+		return ENOMEM;
+	
+	char *pos = buf;
+	size_t pos_size = size;
+	ssize_t written = http_encode_method(pos, pos_size, req->method, req->path);
+	if (written < 0) {
+		free(buf);
+		return written;
+	}
+	pos += written;
+	pos_size -= written;
+	
+	list_foreach(req->headers, link, http_header_t, header) {
+		written = http_encode_header(pos, pos_size, header);
+		if (written < 0) {
+			free(buf);
+			return written;
+		}
+		pos += written;
+		pos_size -= written;
+	}
+	
+	size_t rlsize = str_size(HTTP_REQUEST_LINE);
+	memcpy(pos, HTTP_REQUEST_LINE, rlsize);
+	pos_size -= rlsize;
+	assert(pos_size == 0);
+	
+	*out_buf = buf;
+	*out_buf_size = size;
+	return EOK;
+}
+
+int http_send_request(http_t *http, http_request_t *req)
+{
+	char *buf;
+	size_t buf_size;
+	
+	int rc = http_request_format(req, &buf, &buf_size);
+	if (rc != EOK)
+		return rc;
+	
+	rc = send(http->conn_sd, buf, buf_size, 0);
+	free(buf);
+	
+	return rc;
+}
+
+int http_parse_status(const char *line, http_version_t *out_version,
+    uint16_t *out_status, char **out_message)
+{
+	http_version_t version;
+	uint16_t status;
+	char *message = NULL;
+	
+	if (!str_test_prefix(line, "HTTP/"))
+		return EINVAL;
+	
+	const char *pos_version = line + 5;
+	const char *pos = pos_version;
+	
+	int rc = str_uint8_t(pos_version, &pos, 10, false, &version.major);
+	if (rc != EOK)
+		return rc;
+	if (*pos != '.')
+		return EINVAL;
+	pos++;
+	
+	pos_version = pos;
+	rc = str_uint8_t(pos_version, &pos, 10, false, &version.minor);
+	if (rc != EOK)
+		return rc;
+	if (*pos != ' ')
+		return EINVAL;
+	pos++;
+	
+	const char *pos_status = pos;
+	rc = str_uint16_t(pos_status, &pos, 10, false, &status);
+	if (rc != EOK)
+		return rc;
+	if (*pos != ' ')
+		return EINVAL;
+	pos++;
+	
+	if (out_message) {
+		message = str_dup(pos);
+		if (message == NULL)
+			return ENOMEM;
+	}
+	
+	if (out_version)
+		*out_version = version;
+	if (out_status)
+		*out_status = status;
+	if (out_message)
+		*out_message = message;
+	return EOK;
+}
+
+int http_parse_header(const char *line, char **out_name, char **out_value)
+{
+	const char *pos = line;
+	while (*pos != 0 && *pos != ':') pos++;
+	if (*pos != ':')
+		return EINVAL;
+	
+	char *name = cut_str(line, pos);
+	if (name == NULL)
+		return ENOMEM;
+	
+	pos++;
+	
+	while (*pos == ' ') pos++;
+	
+	char *value = str_dup(pos);
+	if (value == NULL) {
+		free(name);
+		return ENOMEM;
+	}
+	
+	*out_name = name;
+	*out_value = value;
+	
+	return EOK;
+}
+
+int http_receive_response(http_t *http, http_response_t **out_response)
+{
+	http_response_t *resp = malloc(sizeof(http_response_t));
+	if (resp == NULL)
+		return ENOMEM;
+	memset(resp, 0, sizeof(http_response_t));
+	list_initialize(&resp->headers);
+	
+	char *line = malloc(http->buffer_size);
+	if (line == NULL) {
+		free(resp);
+		return ENOMEM;
+	}
+	
+	int rc = recv_line(http, line, http->buffer_size);
+	if (rc < 0)
+		goto error;
+	
+	rc = http_parse_status(line, &resp->version, &resp->status,
+	    &resp->message);
+	if (rc != EOK)
+		goto error;
+	
+	while (true) {
+		rc = recv_line(http, line, http->buffer_size);
+		if (rc < 0)
+			goto error;
+		if (*line == 0)
+			break;
+		
+		char *name = NULL;
+		char *value = NULL;
+		rc = http_parse_header(line, &name, &value);
+		if (rc != EOK)
+			goto error;
+		
+		http_header_t *header = http_header_create_no_copy(name, value);
+		if (header == NULL) {
+			free(name);
+			free(value);
+			rc = ENOMEM;
+			goto error;
+		}
+		
+		list_append(&header->link, &resp->headers);
+	}
+	
+	*out_response = resp;
+	
+	return EOK;
+error:
+	free(line);
+	http_response_destroy(resp);
+	return rc;
+}
+
+int http_receive_body(http_t *http, void *buf, size_t buf_size)
+{
+	return recv_buffer(http, buf, buf_size);
+}
+
+void http_response_destroy(http_response_t *resp)
+{
+	free(resp->message);
+	link_t *link = resp->headers.head.next;
+	while (link != &resp->headers.head) {
+		link_t *next = link->next;
+		http_header_t *header = list_get_instance(link, http_header_t, link);
+		http_header_destroy(header);
+		link = next;
+	}
+	free(resp);
+}
+
+int http_close(http_t *http)
+{
+	if (!http->connected)
+		return EINVAL;
+	
+	return closesocket(http->conn_sd);
+}
+
+void http_destroy(http_t *http)
+{
+	free(http->recv_buffer);
+	free(http);
+}
+
+/** @}
+ */
Index: uspace/lib/http/http.h
===================================================================
--- uspace/lib/http/http.h	(revision d7b7f5e312adb3acb6e7c2044551454dfd1e4019)
+++ uspace/lib/http/http.h	(revision d7b7f5e312adb3acb6e7c2044551454dfd1e4019)
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2013 Martin Sucha
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup http
+ * @{
+ */
+/**
+ * @file
+ */
+
+#ifndef HTTP_HTTP_H_
+#define HTTP_HTTP_H_
+
+#include <net/socket.h>
+#include <adt/list.h>
+#include <inet/addr.h>
+
+typedef struct {
+	char *host;
+	uint16_t port;
+	inet_addr_t addr;
+
+	bool connected;
+	int conn_sd;
+	
+	size_t buffer_size;
+	char *recv_buffer;
+	size_t recv_buffer_in;
+	size_t recv_buffer_out;
+} http_t;
+
+typedef struct {
+	uint8_t minor;
+	uint8_t major;
+} http_version_t;
+
+typedef struct {
+	link_t link;
+	char *name;
+	char *value;
+} http_header_t;
+
+typedef struct {
+	char *method;
+	char *path;
+	list_t headers;
+} http_request_t;
+
+typedef struct {
+	http_version_t version;
+	uint16_t status;
+	char *message;
+	list_t headers;
+} http_response_t;
+
+extern http_t *http_create(const char *, uint16_t);
+extern int http_connect(http_t *);
+extern http_header_t *http_header_create(const char *, const char *);
+extern http_header_t *http_header_create_no_copy(char *, char *);
+extern void http_header_destroy(http_header_t *);
+extern http_request_t *http_request_create(const char *, const char *);
+extern void http_request_destroy(http_request_t *);
+extern int http_request_format(http_request_t *, char **, size_t *);
+extern int http_send_request(http_t *, http_request_t *);
+extern int http_parse_status(const char *, http_version_t *, uint16_t *,
+    char **);
+extern int http_parse_header(const char *, char **, char **);
+extern int http_receive_response(http_t *, http_response_t **);
+extern int http_receive_body(http_t *, void *, size_t);
+extern void http_response_destroy(http_response_t *);
+extern int http_close(http_t *);
+extern void http_destroy(http_t *);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/uri/Makefile
===================================================================
--- uspace/lib/uri/Makefile	(revision d7b7f5e312adb3acb6e7c2044551454dfd1e4019)
+++ uspace/lib/uri/Makefile	(revision d7b7f5e312adb3acb6e7c2044551454dfd1e4019)
@@ -0,0 +1,38 @@
+#
+# Copyright (c) 2013 Martin Sucha
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+USPACE_PREFIX = ../..
+LIBRARY = liburi
+SLIBRARY = liburi.so.0.0
+LSONAME = liburi.so0
+#EXTRA_CFLAGS += 
+
+SOURCES = \
+	uri.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/lib/uri/ctype.h
===================================================================
--- uspace/lib/uri/ctype.h	(revision d7b7f5e312adb3acb6e7c2044551454dfd1e4019)
+++ uspace/lib/uri/ctype.h	(revision d7b7f5e312adb3acb6e7c2044551454dfd1e4019)
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2013 Martin Sucha
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup uri
+ * @{
+ */
+/**
+ * @file
+ */
+
+#ifndef URI_CTYPE_H_
+#define URI_CTYPE_H_
+
+static inline bool is_unreserved(char c)
+{
+	return isalpha(c) || isdigit(c) ||
+	    c == '-' || c == '.' || c == '_' || c == '~';
+}
+
+static inline bool is_hexdig(char c)
+{
+	return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') ||
+	    (c >= 'A' && c <= 'F');
+}
+
+static inline bool is_subdelim(char c)
+{
+	switch (c) {
+	case '!':
+	case '$':
+	case '&':
+	case '\'':
+	case '(':
+	case ')':
+	case '*':
+	case '+':
+	case ',':
+	case ';':
+	case '=':
+		return true;
+	default:
+		return false;
+	}
+}
+
+static inline bool is_gendelim(char c)
+{
+	switch (c) {
+	case ':':
+	case '/':
+	case '?':
+	case '#':
+	case '[':
+	case ']':
+	case '@':
+		return true;
+	default:
+		return false;
+	}
+}
+
+static inline bool is_reserved(char c)
+{
+	return is_gendelim(c) || is_subdelim(c);
+}
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/uri/uri.c
===================================================================
--- uspace/lib/uri/uri.c	(revision d7b7f5e312adb3acb6e7c2044551454dfd1e4019)
+++ uspace/lib/uri/uri.c	(revision d7b7f5e312adb3acb6e7c2044551454dfd1e4019)
@@ -0,0 +1,271 @@
+/*
+ * Copyright (c) 2013 Martin Sucha
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup uri
+ * @{
+ */
+/**
+ * @file
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+#include <str.h>
+#include <ctype.h>
+#include <errno.h>
+
+#include "uri.h"
+#include "ctype.h"
+
+static char *cut_str(const char *start, const char *end)
+{
+	size_t size = end - start;
+	return str_ndup(start, size);
+}
+
+uri_t *uri_parse(const char *str)
+{
+	uri_t *uri = malloc(sizeof(uri_t));
+	if (uri == NULL)
+		return NULL;
+	memset(uri, 0, sizeof(uri_t));
+	
+	/* scheme ":" */
+	const char *scheme = str;
+	while (*str != 0 && *str != ':') str++;
+	if (*str == 0) {
+		uri_destroy(uri);
+		return NULL;
+	}
+	uri->scheme = cut_str(scheme, str);
+	
+	/* skip the colon */
+	str++;
+	
+	if (*str == '/' && str[1] == '/') {
+		/* "//" [user-info [":" user-credential] "@"] host [":" port] */
+		str++;
+		str++;
+		const char *authority_start = str;
+	
+		char *host_or_user_info = NULL;
+		char *port_or_user_credential = NULL;
+	
+		while (*str != 0 && *str != '?' && *str != '#' && *str != '@'
+			&& *str != ':' && *str != '/')
+			str++;
+	
+		host_or_user_info = cut_str(authority_start, str);
+		if (*str == ':') {
+			str++;
+			const char *second_part = str;
+			while (*str != 0 && *str != '?' && *str != '#' &&
+				*str != '@' && *str != '/') str++;
+			port_or_user_credential = cut_str(second_part, str);
+		}
+	
+		if (*str == '@') {
+			uri->user_info = host_or_user_info;
+			uri->user_credential = port_or_user_credential;
+		
+			str++;
+			const char *host_start = str;
+			while (*str != 0 && *str != '?' && *str != '#'
+				&& *str != ':' && *str != '/') str++;
+			uri->host = cut_str(host_start, str);
+		
+			if (*str == ':') {
+				str++;
+				const char *port_start = str;
+				while (*str != 0 && *str != '?' && *str != '#' && *str != '/')
+					str++;
+				uri->port = cut_str(port_start, str);
+			}
+		}
+		else {
+			uri->host = host_or_user_info;
+			uri->port = port_or_user_credential;
+		}
+	}
+	
+	const char *path_start = str;
+	while (*str != 0 && *str != '?' && *str != '#') str++;
+	uri->path = cut_str(path_start, str);
+	
+	if (*str == '?') {
+		str++;
+		const char *query_start = str;
+		while (*str != 0 && *str != '#') str++;
+		uri->query = cut_str(query_start, str);
+	}
+	
+	if (*str == '#') {
+		str++;
+		const char *fragment_start = str;
+		while (*str != 0) str++;
+		uri->fragment = cut_str(fragment_start, str);
+	}
+	
+	assert(*str == 0);
+	return uri;
+}
+
+/** Parse the URI scheme
+ *
+ * @param endptr The position of the first character after the scheme
+ *               is stored there.
+ * @return EOK on success
+ */
+int uri_scheme_parse(const char *str, const char **endptr)
+{
+	if (*str == 0) {
+		*endptr = str;
+		return ELIMIT;
+	}
+	
+	if (!isalpha(*str)) {
+		*endptr = str;
+		return EINVAL;
+	}
+	
+	while (isalpha(*str) || isdigit(*str) ||
+	    *str == '+' || *str == '-' || *str == '.') {
+		str++;
+	}
+	
+	*endptr = str;
+	return EOK;
+}
+
+/** Determine if the URI scheme is valid
+ *
+ */
+bool uri_scheme_validate(const char *str)
+{
+	const char *endptr = NULL;
+	if (uri_scheme_parse(str, &endptr) != EOK)
+		return false;
+	return *endptr == 0;
+}
+
+int uri_percent_parse(const char *str, const char **endptr,
+    uint8_t *decoded)
+{
+	*endptr = str;
+	if (str[0] == 0 || str[1] == 0 || str[2] == 0)
+		return ELIMIT;
+	
+	if (str[0] != '%' || !is_hexdig(str[1]) || !is_hexdig(str[2]))
+		return EINVAL;
+	
+	if (decoded != NULL) {
+		int rc = str_uint8_t(str + 1, NULL, 16, true, decoded);
+		if (rc != EOK)
+			return rc;
+	}
+	
+	*endptr = str + 3;
+	return EOK;
+}
+
+int uri_user_info_parse(const char *str, const char **endptr)
+{
+	while (*str != 0) {
+		while (is_unreserved(*str) || is_subdelim(*str) || *str == ':') str++;
+		if (*str == 0)
+			break;
+		int rc = uri_percent_parse(str, &str, NULL);
+		if (rc != EOK) {
+			*endptr = str;
+			return rc;
+		}
+	}
+	
+	*endptr = str;
+	return EOK;
+}
+
+bool uri_user_info_validate(const char *str)
+{
+	const char *endptr = NULL;
+	if (uri_user_info_parse(str, &endptr) != EOK)
+		return false;
+	return *endptr == 0;
+}
+
+int uri_port_parse(const char *str, const char **endptr)
+{
+	if (*str == 0)
+		return ELIMIT;
+	if (!isdigit(*str))
+		return EINVAL;
+	while (isdigit(*str)) str++;
+	*endptr = str;
+	return EOK;
+}
+
+bool uri_port_validate(const char *str)
+{
+	const char *endptr = NULL;
+	if (uri_port_parse(str, &endptr) != EOK)
+		return false;
+	return *endptr == 0;
+}
+
+bool uri_validate(uri_t *uri)
+{
+	if (uri->scheme && !uri_scheme_validate(uri->scheme))
+		return false;
+	
+	if (uri->user_info && !uri_user_info_validate(uri->user_info))
+		return false;
+	
+	if (uri->user_credential && !uri_user_info_validate(uri->user_credential))
+		return false;
+	
+	if (uri->port && !uri_port_validate(uri->port))
+		return false;
+	
+	return true;
+}
+
+void uri_destroy(uri_t *uri)
+{
+	free(uri->scheme);
+	free(uri->user_info);
+	free(uri->user_credential);
+	free(uri->host);
+	free(uri->port);
+	free(uri->path);
+	free(uri->query);
+	free(uri->fragment);
+	free(uri);
+}
+
+/** @}
+ */
Index: uspace/lib/uri/uri.h
===================================================================
--- uspace/lib/uri/uri.h	(revision d7b7f5e312adb3acb6e7c2044551454dfd1e4019)
+++ uspace/lib/uri/uri.h	(revision d7b7f5e312adb3acb6e7c2044551454dfd1e4019)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2013 Martin Sucha
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup uri
+ * @{
+ */
+/**
+ * @file
+ */
+
+#ifndef URI_URI_H_
+#define URI_URI_H_
+
+typedef struct {
+	char *scheme;
+	char *user_info;
+	char *user_credential;
+	char *host;
+	char *port;
+	char *path;
+	char *query;
+	char *fragment;
+} uri_t;
+
+extern uri_t *uri_parse(const char *);
+extern int uri_scheme_parse(const char *, const char **);
+extern bool uri_scheme_validate(const char *);
+extern int uri_percent_parse(const char *, const char **, uint8_t *);
+extern int uri_user_info_parse(const char *, const char **);
+extern bool uri_user_info_validate(const char *);
+extern int uri_port_parse(const char *, const char **);
+extern bool uri_port_validate(const char *);
+extern bool uri_validate(uri_t *);
+extern void uri_destroy(uri_t *);
+
+#endif
+
+/** @}
+ */
