From 01ec22db277fbaf9cc12d0ec33ee94f7ef3bd600 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Thu, 12 Feb 2015 17:15:08 +0100 Subject: [PATCH] Allow setting content-type urlfw, and allow tcp --- doc/sample.config | 3 ++- src/config.c | 20 +++++++++++++++----- src/vpn.h | 1 + src/worker-urlfw.c | 8 ++++++++ 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/doc/sample.config b/doc/sample.config index df9fdf1a..85cca7f2 100644 --- a/doc/sample.config +++ b/doc/sample.config @@ -404,7 +404,8 @@ no-route = 192.168.5.0/255.255.255.0 # This option allows you to specify a URL location where a client can # post, and the message will be forwarded to the provided server. Any # reply will be provided as body into POST reply. -#url-fw = /kerberos udp@127.0.0.1:8888 +#url-fw = /kerberos udp@127.0.0.1:88 application/kerberos +#url-fw = /kerberos1 tcp@127.0.0.1:88 application/kerberos # # The following options are for (experimental) AnyConnect client diff --git a/src/config.c b/src/config.c index 9581e016..97838f61 100644 --- a/src/config.c +++ b/src/config.c @@ -526,7 +526,7 @@ static void figure_auth_funcs(struct cfg_st *config, char **auth, unsigned auth_ static void parse_urlfw(struct cfg_st *config, char **urlfw, unsigned urlfw_size) { unsigned i; - char *p, *p2, *p3; + char *p, *p2, *p3, *cont_type; struct addrinfo hints, *res; int ret; @@ -546,12 +546,24 @@ static void parse_urlfw(struct cfg_st *config, char **urlfw, unsigned urlfw_size *p2 = 0; p2++; - if (strncmp(p2, "udp@", 4) != 0) { + memset(&hints, 0, sizeof(hints)); + if (strncmp(p2, "udp@", 4) == 0) { + hints.ai_socktype = SOCK_DGRAM; + } else if (strncmp(p2, "tcp@", 4) == 0) { + hints.ai_socktype = SOCK_STREAM; + } else { fprintf(stderr, "cannot handle protocol %s\n", p2); exit(1); } p2 += 4; + cont_type = strchr(p2, ' '); + if (cont_type != NULL) { + *cont_type = 0; + cont_type++; + config->urlfw[i].content_type = talloc_strdup(config->urlfw, cont_type); + } + p3 = strchr(p2, ':'); if (p3 == NULL) { fprintf(stderr, "No server port specified in: %s\n", p2); @@ -560,8 +572,6 @@ static void parse_urlfw(struct cfg_st *config, char **urlfw, unsigned urlfw_size *p3 = 0; p3++; - memset(&hints, 0, sizeof(hints)); - hints.ai_socktype = SOCK_DGRAM; ret = getaddrinfo(p2, p3, &hints, &res); if (ret != 0) { fprintf(stderr, "getaddrinfo(%s) failed: %s\n", p2, @@ -575,7 +585,7 @@ static void parse_urlfw(struct cfg_st *config, char **urlfw, unsigned urlfw_size config->urlfw[i].ai_socktype = res->ai_socktype; config->urlfw[i].ai_protocol = res->ai_protocol; - config->urlfw[i].url = talloc_strdup(config, p); + config->urlfw[i].url = talloc_strdup(config->urlfw, p); freeaddrinfo(res); } diff --git a/src/vpn.h b/src/vpn.h index 7a85f9cc..0e98afb9 100644 --- a/src/vpn.h +++ b/src/vpn.h @@ -219,6 +219,7 @@ typedef struct auth_struct_st { typedef struct urlfw_st { char *url; + char *content_type; /* Content-Type */ struct sockaddr_storage addr; socklen_t addr_len; int ai_family; diff --git a/src/worker-urlfw.c b/src/worker-urlfw.c index ccfadbd0..88169d9b 100644 --- a/src/worker-urlfw.c +++ b/src/worker-urlfw.c @@ -98,6 +98,14 @@ int post_urlfw_handler(worker_st *ws, unsigned http_ver) goto fail; } + if (handler->content_type) { + ret = + cstp_printf(ws, "Content-Type: %s\r\n", handler->content_type); + if (ret < 0) { + goto fail; + } + } + ret = cstp_printf(ws, "Content-Length: %u\r\n", (unsigned int)length);