dovecot-2.2: lib-http: Implemented functions for cloning and cop...
dovecot at dovecot.org
dovecot at dovecot.org
Sat Oct 12 11:14:58 EEST 2013
details: http://hg.dovecot.org/dovecot-2.2/rev/9709839d2be7
changeset: 16853:9709839d2be7
user: Stephan Bosch <stephan at rename-it.nl>
date: Sat Oct 12 10:58:04 2013 +0300
description:
lib-http: Implemented functions for cloning and copying HTTP URLs and for constructing partial URLs.
diffstat:
src/lib-http/http-url.c | 109 +++++++++++++++++++++++++++++++++++++++--------
src/lib-http/http-url.h | 12 +++++
2 files changed, 102 insertions(+), 19 deletions(-)
diffs (163 lines):
diff -r a8fe88d2286d -r 9709839d2be7 src/lib-http/http-url.c
--- a/src/lib-http/http-url.c Sat Oct 12 10:57:05 2013 +0300
+++ b/src/lib-http/http-url.c Sat Oct 12 10:58:04 2013 +0300
@@ -418,10 +418,78 @@
}
/*
+ * HTTP URL manipulation
+ */
+
+void http_url_copy_authority(pool_t pool, struct http_url *dest,
+ const struct http_url *src)
+{
+ dest->host_name = p_strdup(pool, src->host_name);
+ if (src->have_host_ip) {
+ dest->host_ip = src->host_ip;
+ dest->have_host_ip = TRUE;
+ }
+ if (src->have_port) {
+ dest->port = src->port;
+ dest->have_port = TRUE;
+ }
+ dest->have_ssl = src->have_ssl;
+}
+
+void http_url_copy(pool_t pool, struct http_url *dest,
+ const struct http_url *src)
+{
+ http_url_copy_authority(pool, dest, src);
+ dest->path = p_strdup(pool, src->path);
+ dest->enc_query = p_strdup(pool, src->enc_query);
+ dest->enc_fragment = p_strdup(pool, src->enc_fragment);
+}
+
+struct http_url *http_url_clone(pool_t pool,const struct http_url *src)
+{
+ struct http_url *new_url;
+
+ new_url = p_new(pool, struct http_url, 1);
+ http_url_copy(pool, new_url, src);
+
+ return new_url;
+}
+
+/*
* HTTP URL construction
*/
-static void http_url_add_target(string_t *urlstr, const struct http_url *url)
+static void
+http_url_add_scheme(string_t *urlstr, const struct http_url *url)
+{
+ /* scheme */
+ if (!url->have_ssl)
+ uri_append_scheme(urlstr, "http");
+ else
+ uri_append_scheme(urlstr, "https");
+ str_append(urlstr, "//");
+}
+
+static void
+http_url_add_authority(string_t *urlstr, const struct http_url *url)
+{
+ /* host:port */
+ if (url->host_name != NULL) {
+ /* assume IPv6 literal if starts with '['; avoid encoding */
+ if (*url->host_name == '[')
+ str_append(urlstr, url->host_name);
+ else
+ uri_append_host_name(urlstr, url->host_name);
+ } else if (url->have_host_ip) {
+ uri_append_host_ip(urlstr, &url->host_ip);
+ } else
+ i_unreached();
+ if (url->have_port)
+ uri_append_port(urlstr, url->port);
+}
+
+static void
+http_url_add_target(string_t *urlstr, const struct http_url *url)
{
if (url->path == NULL || *url->path == '\0') {
/* Older syntax of RFC 2616 requires this slash at all times for an
@@ -443,24 +511,8 @@
{
string_t *urlstr = t_str_new(512);
- /* scheme */
- uri_append_scheme(urlstr, "http");
- str_append(urlstr, "//");
-
- /* host:port */
- if (url->host_name != NULL) {
- /* assume IPv6 literal if starts with '['; avoid encoding */
- if (*url->host_name == '[')
- str_append(urlstr, url->host_name);
- else
- uri_append_host_name(urlstr, url->host_name);
- } else if (url->have_host_ip) {
- uri_append_host_ip(urlstr, &url->host_ip);
- } else
- i_unreached();
- if (url->have_port)
- uri_append_port(urlstr, url->port);
-
+ http_url_add_scheme(urlstr, url);
+ http_url_add_authority(urlstr, url);
http_url_add_target(urlstr, url);
/* fragment */
@@ -472,6 +524,25 @@
return str_c(urlstr);
}
+const char *http_url_create_host(const struct http_url *url)
+{
+ string_t *urlstr = t_str_new(512);
+
+ http_url_add_scheme(urlstr, url);
+ http_url_add_authority(urlstr, url);
+
+ return str_c(urlstr);
+}
+
+const char *http_url_create_authority(const struct http_url *url)
+{
+ string_t *urlstr = t_str_new(256);
+
+ http_url_add_authority(urlstr, url);
+
+ return str_c(urlstr);
+}
+
const char *http_url_create_target(const struct http_url *url)
{
string_t *urlstr = t_str_new(256);
diff -r a8fe88d2286d -r 9709839d2be7 src/lib-http/http-url.h
--- a/src/lib-http/http-url.h Sat Oct 12 10:57:05 2013 +0300
+++ b/src/lib-http/http-url.h Sat Oct 12 10:58:04 2013 +0300
@@ -52,11 +52,23 @@
struct http_request_target *target, const char **error_r);
/*
+ * HTTP URL manipulation
+ */
+
+void http_url_copy_authority(pool_t pool, struct http_url *dest,
+ const struct http_url *src);
+void http_url_copy(pool_t pool, struct http_url *dest,
+ const struct http_url *src);
+struct http_url *http_url_clone(pool_t pool,const struct http_url *src);
+
+/*
* HTTP URL construction
*/
const char *http_url_create(const struct http_url *url);
+const char *http_url_create_host(const struct http_url *url);
+const char *http_url_create_authority(const struct http_url *url);
const char *http_url_create_target(const struct http_url *url);
void http_url_escape_param(string_t *out, const char *data);
More information about the dovecot-cvs
mailing list