summaryrefslogtreecommitdiff
path: root/usr.sbin/relayd/relayd.c
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2019-05-08 23:22:20 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2019-05-08 23:22:20 +0000
commitcc1037c514e36abc8abb09bd484a68786d96567b (patch)
treeb211209b55794fc4bc00ea863b01b323a76c0258 /usr.sbin/relayd/relayd.c
parent8cb9985dfed2bc225590478d19e767611cd53b48 (diff)
Fix and tweak websocket upgrade handling.
- Don't expect the Connection header to equal Upgrade, it may include Upgrade - Reshuffle the code to check the Upgrade/Connection headers in one place Reported and tested by Rivo Nurges OK and input from benno@ Cvs: ----------------------------------------------------------------------
Diffstat (limited to 'usr.sbin/relayd/relayd.c')
-rw-r--r--usr.sbin/relayd/relayd.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/usr.sbin/relayd/relayd.c b/usr.sbin/relayd/relayd.c
index 9e80bed2d09..6cbb734757f 100644
--- a/usr.sbin/relayd/relayd.c
+++ b/usr.sbin/relayd/relayd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: relayd.c,v 1.175 2019/04/24 19:13:49 mestre Exp $ */
+/* $OpenBSD: relayd.c,v 1.176 2019/05/08 23:22:19 reyk Exp $ */
/*
* Copyright (c) 2007 - 2016 Reyk Floeter <reyk@openbsd.org>
@@ -812,6 +812,48 @@ kv_find(struct kvtree *keys, struct kv *kv)
return (match);
}
+struct kv *
+kv_find_value(struct kvtree *keys, char *key, const char *value,
+ const char *delim)
+{
+ struct kv *match, kv;
+ char *val = NULL, *next, *ptr;
+ size_t len;
+
+ kv.kv_key = key;
+ if ((match = RB_FIND(kvtree, keys, &kv)) == NULL)
+ return (NULL);
+
+ if (match->kv_value == NULL)
+ return (NULL);
+
+ if (delim == NULL) {
+ if (strcasecmp(match->kv_value, value) == 0)
+ goto done;
+ } else {
+ if ((val = strdup(match->kv_value)) == NULL)
+ return (NULL);
+ for (next = ptr = val; ptr != NULL;
+ ptr = strsep(&next, delim)) {
+ /* strip whitespace */
+ ptr += strspn(ptr, " \t");
+ len = strcspn(ptr, " \t");
+ if (strncasecmp(ptr, value, len) == 0)
+ goto done;
+ }
+ }
+
+ /* not matched */
+ match = NULL;
+ done:
+#ifdef DEBUG
+ if (match != NULL)
+ DPRINTF("%s: matched %s: %s", __func__, key, value);
+#endif
+ free(val);
+ return (match);
+}
+
int
kv_cmp(struct kv *a, struct kv *b)
{