mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-02-10 08:46:58 +08:00
Replace header_check() mess with a gperf table
This commit is contained in:
@@ -9,7 +9,7 @@ AM_CPPFLAGS = -I$(srcdir)/../gl/ -I$(builddir)/../gl/ \
|
||||
|
||||
BUILT_SOURCES = ocpasswd-args.c ocpasswd-args.h \
|
||||
ocserv-args.c ocserv-args.h ipc.pb-c.c ipc.pb-c.h \
|
||||
ctl.pb-c.c ctl.pb-c.h
|
||||
ctl.pb-c.c ctl.pb-c.h http-heads.h
|
||||
|
||||
#AM_CPPFLAGS += -DDEBUG_LEAKS
|
||||
|
||||
@@ -29,7 +29,7 @@ endif
|
||||
|
||||
EXTRA_DIST = ccan/licenses/BSD-MIT version.inc.in \
|
||||
ccan/licenses/CC0 ccan/licenses/LGPL-2.1 version.inc \
|
||||
occtl-args.def ipc.proto ctl.proto
|
||||
occtl-args.def ipc.proto ctl.proto http-heads.gperf
|
||||
|
||||
bin_PROGRAMS = ocpasswd occtl
|
||||
|
||||
@@ -138,3 +138,6 @@ ctl.pb-c.c: ctl.proto
|
||||
protoc-c --c_out=. --proto_path=$(srcdir) $<
|
||||
|
||||
ctl.pb-c.h: ctl.pb-c.c
|
||||
|
||||
http-heads.h: $(srcdir)/http-heads.gperf
|
||||
-gperf --global-table -t $^ > $@-tmp && mv $@-tmp $@
|
||||
|
||||
19
src/http-heads.gperf
Normal file
19
src/http-heads.gperf
Normal file
@@ -0,0 +1,19 @@
|
||||
%{
|
||||
#include "vpn.h"
|
||||
%}
|
||||
%language=ANSI-C
|
||||
%readonly-tables
|
||||
struct http_headers_st { const char *name; unsigned id; };
|
||||
%%
|
||||
Cookie, HEADER_COOKIE
|
||||
User-Agent, HEADER_USER_AGENT
|
||||
X-CSTP-Accept-Encoding, HEADER_CSTP_ENCODING
|
||||
X-DTLS-Accept-Encoding, HEADER_DTLS_ENCODING
|
||||
Connection, HEADER_CONNECTION
|
||||
X-DTLS-Master-Secret, HEADER_MASTER_SECRET
|
||||
X-DTLS-CipherSuite, HEADER_DTLS_CIPHERSUITE
|
||||
X-CSTP-Base-MTU, HEADER_CSTP_BASE_MTU
|
||||
X-CSTP-Address-Type, HEADER_CSTP_ATYPE
|
||||
X-CSTP-Hostname, HEADER_HOSTNAME
|
||||
X-CSTP-Full-IPv6-Capability, HEADER_FULL_IPV6
|
||||
X-AnyConnect-Identifier-DeviceType, HEADER_DEVICE_TYPE
|
||||
@@ -469,60 +469,19 @@ int http_header_field_cb(http_parser * parser, const char *at, size_t length)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* include hash table of headers */
|
||||
#include "http-heads.h"
|
||||
|
||||
static void header_check(struct http_req_st *req)
|
||||
{
|
||||
/* FIXME: move this mess to a table */
|
||||
if (req->header.length == sizeof(STR_HDR_COOKIE) - 1 &&
|
||||
strncmp((char *)req->header.data, STR_HDR_COOKIE,
|
||||
req->header.length) == 0) {
|
||||
req->next_header = HEADER_COOKIE;
|
||||
} else if (req->header.length == sizeof(STR_HDR_MS) - 1 &&
|
||||
strncmp((char *)req->header.data, STR_HDR_MS,
|
||||
req->header.length) == 0) {
|
||||
req->next_header = HEADER_MASTER_SECRET;
|
||||
} else if (req->header.length == sizeof(STR_HDR_CMTU) - 1 &&
|
||||
strncmp((char *)req->header.data, STR_HDR_CMTU,
|
||||
req->header.length) == 0) {
|
||||
req->next_header = HEADER_CSTP_BASE_MTU;
|
||||
} else if (req->header.length == sizeof(STR_HDR_HOST) - 1 &&
|
||||
strncmp((char *)req->header.data, STR_HDR_HOST,
|
||||
req->header.length) == 0) {
|
||||
req->next_header = HEADER_HOSTNAME;
|
||||
} else if (req->header.length == sizeof(STR_HDR_CS) - 1 &&
|
||||
strncmp((char *)req->header.data, STR_HDR_CS,
|
||||
req->header.length) == 0) {
|
||||
req->next_header = HEADER_DTLS_CIPHERSUITE;
|
||||
} else if (req->header.length == sizeof(STR_HDR_DEVICE_TYPE) - 1 &&
|
||||
strncmp((char *)req->header.data, STR_HDR_DEVICE_TYPE,
|
||||
req->header.length) == 0) {
|
||||
req->next_header = HEADER_DEVICE_TYPE;
|
||||
} else if (req->header.length == sizeof(STR_HDR_ATYPE) - 1 &&
|
||||
strncmp((char *)req->header.data, STR_HDR_ATYPE,
|
||||
req->header.length) == 0) {
|
||||
req->next_header = HEADER_CSTP_ATYPE;
|
||||
} else if (req->header.length == sizeof(STR_HDR_CONNECTION) - 1 &&
|
||||
strncmp((char *)req->header.data, STR_HDR_CONNECTION,
|
||||
req->header.length) == 0) {
|
||||
req->next_header = HEADER_CONNECTION;
|
||||
} else if (req->header.length == sizeof(STR_HDR_USER_AGENT) - 1 &&
|
||||
strncmp((char *)req->header.data, STR_HDR_USER_AGENT,
|
||||
req->header.length) == 0) {
|
||||
req->next_header = HEADER_USER_AGENT;
|
||||
} else if (req->header.length == sizeof(STR_HDR_CSTP_ENCODING) - 1 &&
|
||||
strncmp((char *)req->header.data, STR_HDR_CSTP_ENCODING,
|
||||
req->header.length) == 0) {
|
||||
req->next_header = HEADER_CSTP_ENCODING;
|
||||
} else if (req->header.length == sizeof(STR_HDR_DTLS_ENCODING) - 1 &&
|
||||
strncmp((char *)req->header.data, STR_HDR_DTLS_ENCODING,
|
||||
req->header.length) == 0) {
|
||||
req->next_header = HEADER_DTLS_ENCODING;
|
||||
} else if (req->header.length == sizeof(STR_HDR_FULL_IPV6) - 1 &&
|
||||
strncmp((char *)req->header.data, STR_HDR_FULL_IPV6,
|
||||
req->header.length) == 0) {
|
||||
req->next_header = HEADER_FULL_IPV6;
|
||||
} else {
|
||||
req->next_header = 0;
|
||||
const struct http_headers_st *p;
|
||||
|
||||
p = in_word_set((char *)req->header.data, req->header.length);
|
||||
if (p != NULL) {
|
||||
req->next_header = p->id;
|
||||
return;
|
||||
}
|
||||
req->next_header = 0;
|
||||
}
|
||||
|
||||
int http_header_value_cb(http_parser * parser, const char *at, size_t length)
|
||||
|
||||
14
src/worker.h
14
src/worker.h
@@ -25,6 +25,7 @@
|
||||
#include <syslog.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <net/if.h>
|
||||
#include <vpn.h>
|
||||
@@ -45,19 +46,6 @@ typedef enum {
|
||||
UP_ACTIVE
|
||||
} udp_port_state_t;
|
||||
|
||||
#define STR_HDR_COOKIE "Cookie"
|
||||
#define STR_HDR_USER_AGENT "User-Agent"
|
||||
#define STR_HDR_CSTP_ENCODING "X-CSTP-Accept-Encoding"
|
||||
#define STR_HDR_DTLS_ENCODING "X-DTLS-Accept-Encoding"
|
||||
#define STR_HDR_CONNECTION "Connection"
|
||||
#define STR_HDR_MS "X-DTLS-Master-Secret"
|
||||
#define STR_HDR_CS "X-DTLS-CipherSuite"
|
||||
#define STR_HDR_CMTU "X-CSTP-Base-MTU"
|
||||
#define STR_HDR_ATYPE "X-CSTP-Address-Type"
|
||||
#define STR_HDR_HOST "X-CSTP-Hostname"
|
||||
#define STR_HDR_FULL_IPV6 "X-CSTP-Full-IPv6-Capability"
|
||||
#define STR_HDR_DEVICE_TYPE "X-AnyConnect-Identifier-DeviceType"
|
||||
|
||||
enum {
|
||||
HEADER_COOKIE = 1,
|
||||
HEADER_MASTER_SECRET,
|
||||
|
||||
Reference in New Issue
Block a user