Skip to content

Commit

Permalink
Clean up compression type handling
Browse files Browse the repository at this point in the history
This makes it slightly easier to add new compression types.

[dwmw2: Split out from "Added support for LZ4" patch and tweaked a little.]

Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
nmav authored and David Woodhouse committed Jan 15, 2015
1 parent 6123188 commit 3f0f078
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
37 changes: 22 additions & 15 deletions cstp.c
Expand Up @@ -150,6 +150,23 @@ void cstp_free_splits(struct openconnect_info *vpninfo)
# define DEFAULT_CIPHER_LIST "AES256-SHA:AES128-SHA:DES-CBC3-SHA:DES-CBC-SHA"
#endif

static void append_compr_types(struct oc_text_buf *buf, const char *proto, int avail)
{
if (avail) {
char sep = ' ';
buf_append(buf, "X-%s-Accept-Encoding:", proto);
if (avail & COMPR_LZS) {
buf_append(buf, "%clzs", sep);
sep = ',';
}
if (avail & COMPR_DEFLATE) {
buf_append(buf, "%cdeflate", sep);
sep = ',';
}
buf_append(buf, "\r\n");
}
}

static int start_cstp_connection(struct openconnect_info *vpninfo)
{
struct oc_text_buf *reqbuf;
Expand Down Expand Up @@ -188,19 +205,9 @@ static int start_cstp_connection(struct openconnect_info *vpninfo)
buf_append(reqbuf, "Cookie: webvpn=%s\r\n", vpninfo->cookie);
buf_append(reqbuf, "X-CSTP-Version: 1\r\n");
buf_append(reqbuf, "X-CSTP-Hostname: %s\r\n", vpninfo->localname);
if (vpninfo->req_compr) {
char sep = ' ';
buf_append(reqbuf, "X-CSTP-Accept-Encoding:");
if (vpninfo->req_compr & COMPR_LZS) {
buf_append(reqbuf, "%clzs", sep);
sep = ',';
}
if (vpninfo->req_compr & COMPR_DEFLATE) {
buf_append(reqbuf, "%cdeflate", sep);
sep = ',';
}
buf_append(reqbuf, "\r\n");
}

append_compr_types(reqbuf, "CSTP", vpninfo->req_compr & ~COMPR_DEFLATE);

if (base_mtu)
buf_append(reqbuf, "X-CSTP-Base-MTU: %d\r\n", base_mtu);
buf_append(reqbuf, "X-CSTP-MTU: %d\r\n", mtu);
Expand All @@ -220,8 +227,8 @@ static int start_cstp_connection(struct openconnect_info *vpninfo)
}
buf_append(reqbuf, "\r\nX-DTLS-CipherSuite: %s\r\n",
vpninfo->dtls_ciphers ? : DEFAULT_CIPHER_LIST);
if (vpninfo->req_compr & COMPR_LZS)
buf_append(reqbuf, "X-DTLS-Accept-Encoding: lzs\r\n");

append_compr_types(reqbuf, "DTLS", vpninfo->req_compr);
buf_append(reqbuf, "\r\n");

if (buf_error(reqbuf)) {
Expand Down
21 changes: 16 additions & 5 deletions main.c
Expand Up @@ -931,6 +931,7 @@ int main(int argc, char **argv)
{
struct openconnect_info *vpninfo;
char *urlpath = NULL;
const char *compr = "";
char *proxy = getenv("https_proxy");
char *vpnc_script = NULL, *ifname = NULL;
const struct oc_ip_info *ip_info;
Expand Down Expand Up @@ -1423,15 +1424,25 @@ int main(int argc, char **argv)
fprintf(stderr, _("Set up DTLS failed; using SSL instead\n"));

openconnect_get_ip_info(vpninfo, &ip_info, NULL, NULL);

if (vpninfo->dtls_state != DTLS_CONNECTED) {
if (vpninfo->cstp_compr == COMPR_DEFLATE)
compr = " + deflate";
else if (vpninfo->cstp_compr == COMPR_LZS)
compr = " + lzs";
} else {
if (vpninfo->dtls_compr == COMPR_DEFLATE)
compr = " + deflate";
else if (vpninfo->dtls_compr == COMPR_LZS)
compr = " + lzs";
}
vpn_progress(vpninfo, PRG_INFO,
_("Connected %s as %s%s%s, using %s\n"), openconnect_get_ifname(vpninfo),
_("Connected %s as %s%s%s, using %s%s\n"), openconnect_get_ifname(vpninfo),
ip_info->addr?:"",
(ip_info->netmask6 && ip_info->addr) ? " + " : "",
ip_info->netmask6 ? : "",
(vpninfo->dtls_state != DTLS_CONNECTED) ?
(vpninfo->cstp_compr == COMPR_DEFLATE) ? "SSL + deflate" :
(vpninfo->cstp_compr == COMPR_LZS) ? "SSL + lzs" : "SSL"
: "DTLS");
(vpninfo->dtls_state != DTLS_CONNECTED) ? "SSL"
: "DTLS", compr);

if (!vpninfo->vpnc_script) {
vpn_progress(vpninfo, PRG_INFO,
Expand Down

0 comments on commit 3f0f078

Please sign in to comment.