Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnishevent
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
varnishevent
Commits
3424c5fe
Commit
3424c5fe
authored
Sep 21, 2015
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add the header trie code, not yet used
parent
312a0c45
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
635 additions
and
4 deletions
+635
-4
Makefile.am
src/Makefile.am
+3
-1
hdrtrie.c
src/hdrtrie.c
+147
-0
hdrtrie.h
src/hdrtrie.h
+43
-0
Makefile.am
src/test/Makefile.am
+12
-3
test_hdrtrie.c
src/test/test_hdrtrie.c
+430
-0
No files found.
src/Makefile.am
View file @
3424c5fe
...
...
@@ -33,7 +33,9 @@ varnishevent_SOURCES = \
flopen.c
\
vcs_version.h
\
vmb.h
\
vmb.c
vmb.c
\
hdrtrie.h
\
hdrtrie.c
varnishevent_LDADD
=
\
${
PTHREAD_LIBS
}
${
RT_LIBS
}
${
LIBM
}
@VARNISH_LIBS@
\
...
...
src/hdrtrie.c
0 → 100644
View file @
3424c5fe
/*-
* Copyright (c) 2015 UPLEX Nils Goroll Systemoptimierung
* Copyright (c) 2015 Otto Gmbh & Co KG
* All rights reserved.
* Use only with permission
*
* Author: Geoffrey Simmons <geoffrey.simmons@uplex.de>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "hdrtrie.h"
#include "vas.h"
#include "miniobj.h"
static
inline
int
hdr_next
(
const
char
c
)
{
int
n
=
toupper
(
c
)
-
32
;
if
(
c
==
'~'
)
n
=
':'
-
32
;
return
n
;
}
int
HDR_FindIdx
(
struct
hdrt_node
*
hdrt
,
const
char
*
hdr
)
{
const
char
*
h
=
hdr
;
char
*
s
;
int
n
;
if
(
hdrt
==
NULL
)
return
-
1
;
while
(
*
h
&&
isspace
(
*
h
))
h
++
;
if
(
*
h
==
'\0'
)
return
-
1
;
while
(
1
)
{
CHECK_OBJ
(
hdrt
,
HDRT_NODE_MAGIC
);
s
=
hdrt
->
str
;
while
(
*
h
&&
*
s
&&
(
toupper
(
*
h
)
==
toupper
(
*
s
)))
{
h
++
;
s
++
;
}
if
(
*
s
!=
'\0'
)
return
-
1
;
n
=
hdr_next
(
*
h
);
if
(
n
<
0
||
n
>=
64
)
return
-
1
;
if
(
hdrt
->
next
[
n
]
==
NULL
)
break
;
hdrt
=
hdrt
->
next
[
n
];
h
++
;
}
while
(
*
h
&&
isspace
(
*
h
))
h
++
;
if
(
*
h
!=
':'
||
*
h
==
'\0'
)
return
-
1
;
return
hdrt
->
idx
;
}
struct
hdrt_node
*
HDR_InsertIdx
(
struct
hdrt_node
*
hdrt
,
const
char
*
hdr
,
int
idx
)
{
const
char
*
h
=
hdr
;
char
*
s
;
int
n
;
if
(
hdrt
==
NULL
)
{
ALLOC_OBJ
(
hdrt
,
HDRT_NODE_MAGIC
);
AN
(
hdrt
);
hdrt
->
str
=
strdup
(
hdr
);
hdrt
->
idx
=
idx
;
return
hdrt
;
}
CHECK_OBJ
(
hdrt
,
HDRT_NODE_MAGIC
);
s
=
hdrt
->
str
;
while
(
*
h
&&
*
s
&&
(
toupper
(
*
h
)
==
toupper
(
*
s
)))
{
h
++
;
s
++
;
}
if
(
*
s
==
'\0'
&&
*
h
==
'\0'
)
assert
(
hdrt
->
idx
==
idx
);
else
if
(
*
s
==
'\0'
)
{
n
=
hdr_next
(
*
h
);
assert
(
n
>=
0
&&
n
<
64
);
hdrt
->
next
[
n
]
=
HDR_InsertIdx
(
hdrt
->
next
[
n
],
++
h
,
idx
);
}
else
if
(
*
h
==
'\0'
)
{
n
=
hdr_next
(
*
s
);
assert
(
n
>=
0
&&
n
<
64
);
*
s
=
'\0'
;
hdrt
->
next
[
n
]
=
HDR_InsertIdx
(
hdrt
->
next
[
n
],
++
s
,
hdrt
->
idx
);
hdrt
->
idx
=
idx
;
}
else
{
n
=
hdr_next
(
*
s
);
assert
(
n
>=
0
&&
n
<
64
);
*
s
=
'\0'
;
hdrt
->
next
[
n
]
=
HDR_InsertIdx
(
hdrt
->
next
[
n
],
++
s
,
hdrt
->
idx
);
n
=
hdr_next
(
*
h
);
assert
(
n
>=
0
&&
n
<
64
);
hdrt
->
next
[
n
]
=
HDR_InsertIdx
(
hdrt
->
next
[
n
],
++
h
,
idx
);
hdrt
->
idx
=
-
1
;
}
return
hdrt
;
}
void
HDR_Fini
(
struct
hdrt_node
*
hdrt
)
{
if
(
hdrt
==
NULL
)
return
;
free
(
hdrt
->
str
);
for
(
int
i
=
0
;
i
<
64
;
i
++
)
HDR_Fini
(
hdrt
->
next
[
i
]);
FREE_OBJ
(
hdrt
);
}
src/hdrtrie.h
0 → 100644
View file @
3424c5fe
/*-
* Copyright (c) 2015 UPLEX Nils Goroll Systemoptimierung
* Copyright (c) 2015 Otto Gmbh & Co KG
* All rights reserved.
* Use only with permission
*
* Author: Geoffrey Simmons <geoffrey.simmons@uplex.de>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
struct
hdrt_node
{
unsigned
magic
;
#define HDRT_NODE_MAGIC 0x970ec029
char
*
str
;
struct
hdrt_node
*
next
[
64
];
int
idx
;
};
int
HDR_FindIdx
(
struct
hdrt_node
*
hdrt
,
const
char
*
hdr
);
struct
hdrt_node
*
HDR_InsertIdx
(
struct
hdrt_node
*
hdrt
,
const
char
*
hdr
,
int
idx
);
void
HDR_Fini
(
struct
hdrt_node
*
hdrt
);
src/test/Makefile.am
View file @
3424c5fe
AM_CPPFLAGS
=
@VARNISH_CFLAGS@
-I
${
ac_varnish_pkgdataincludedir
}
TESTS
=
test_data test_strfTIM test_
format test_writer ncsa.sh vslarg
.sh
\
regress.sh
TESTS
=
test_data test_strfTIM test_
hdrtrie test_format test_writer ncsa
.sh
\
vslarg.sh
regress.sh
# artifactes of the regression test
CLEANFILES
=
test.log output.log
check_PROGRAMS
=
test_data test_strfTIM test_format test_writer
check_PROGRAMS
=
test_data test_strfTIM test_format test_writer
test_hdrtrie
test_data_SOURCES
=
\
minunit.h
\
...
...
@@ -57,3 +57,12 @@ test_strfTIM_SOURCES = \
test_strfTIM_LDADD
=
\
../strfTIM.
$(OBJEXT)
\
@VARNISH_LIBS@ @VARNISH_LIBVARNISH_LIB@
${
LIBM
}
-lvarnish
test_hdrtrie_SOURCES
=
\
minunit.h
\
../hdrtrie.h
\
test_hdrtrie.c
test_hdrtrie_LDADD
=
\
../hdrtrie.
$(OBJEXT)
\
@VARNISH_LIBS@ @VARNISH_LIBVARNISH_LIB@
${
LIBM
}
-lvarnish
src/test/test_hdrtrie.c
0 → 100644
View file @
3424c5fe
/*-
* Copyright (c) 2012 UPLEX Nils Goroll Systemoptimierung
* Copyright (c) 2012 Otto Gmbh & Co KG
* All rights reserved
* Use only with permission
*
* Author: Geoffrey Simmons <geoffrey.simmons@uplex.de>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#include <stdio.h>
#include <ctype.h>
#include "minunit.h"
#include "../hdrtrie.h"
int
tests_run
=
0
;
static
inline
int
next_idx
(
char
c
)
{
int
n
=
toupper
(
c
)
-
32
;
if
(
c
==
'~'
)
n
=
':'
-
32
;
return
n
;
}
static
char
*
test_HDR_FindIdx
(
void
)
{
#define NODES 10
struct
hdrt_node
hdrt
[
NODES
];
printf
(
"... testing HDR_FindIdx()
\n
"
);
for
(
int
i
=
0
;
i
<
NODES
;
i
++
)
hdrt
[
i
].
magic
=
HDRT_NODE_MAGIC
;
hdrt
[
0
].
str
=
strdup
(
"Foo"
);
memset
(
&
hdrt
[
0
].
next
,
0
,
64
*
sizeof
(
struct
hdrt_node
*
));
hdrt
[
0
].
idx
=
4711
;
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Foo:"
)
==
4711
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Foo: bar"
)
==
4711
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Foo:bar"
)
==
4711
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Foo: bar baz"
)
==
4711
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
" Foo : "
)
==
4711
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
" fOO : "
)
==
4711
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Bar:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
" Bar:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Fo:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Food:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Foo bar baz"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Foo"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
" Foo "
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
" "
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
""
)
==
-
1
);
hdrt
[
0
].
str
=
strdup
(
"Accept"
);
hdrt
[
0
].
next
[
next_idx
(
'-'
)]
=
&
hdrt
[
1
];
hdrt
[
1
].
str
=
strdup
(
""
);
memset
(
&
hdrt
[
1
].
next
,
0
,
64
*
sizeof
(
struct
hdrt_node
*
));
hdrt
[
1
].
next
[
next_idx
(
'C'
)]
=
&
hdrt
[
2
];
hdrt
[
1
].
next
[
next_idx
(
'E'
)]
=
&
hdrt
[
3
];
hdrt
[
1
].
next
[
next_idx
(
'L'
)]
=
&
hdrt
[
4
];
hdrt
[
1
].
next
[
next_idx
(
'D'
)]
=
&
hdrt
[
5
];
hdrt
[
1
].
idx
=
-
1
;
hdrt
[
2
].
str
=
strdup
(
"harset"
);
memset
(
&
hdrt
[
2
].
next
,
0
,
64
*
sizeof
(
struct
hdrt_node
*
));
hdrt
[
2
].
idx
=
1
;
hdrt
[
3
].
str
=
strdup
(
"ncoding"
);
memset
(
&
hdrt
[
3
].
next
,
0
,
64
*
sizeof
(
struct
hdrt_node
*
));
hdrt
[
3
].
idx
=
2
;
hdrt
[
4
].
str
=
strdup
(
"anguage"
);
memset
(
&
hdrt
[
4
].
next
,
0
,
64
*
sizeof
(
struct
hdrt_node
*
));
hdrt
[
4
].
idx
=
3
;
hdrt
[
5
].
str
=
strdup
(
"atetime"
);
memset
(
&
hdrt
[
5
].
next
,
0
,
64
*
sizeof
(
struct
hdrt_node
*
));
hdrt
[
5
].
idx
=
4
;
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Accept:"
)
==
4711
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Accept-Charset:"
)
==
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Accept-Encoding:"
)
==
2
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Accept-Language:"
)
==
3
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Accept-Datetime:"
)
==
4
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"accept:"
)
==
4711
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"accept-charset:"
)
==
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"accept-encoding:"
)
==
2
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"accept-language:"
)
==
3
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"accept-datetime:"
)
==
4
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Accept-:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Foo:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Accept-Foo:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Accept-CharsetFoo:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Accept-Charse:"
)
==
-
1
);
hdrt
[
0
].
str
=
strdup
(
"Content-"
);
memset
(
&
hdrt
[
0
].
next
,
0
,
64
*
sizeof
(
struct
hdrt_node
*
));
hdrt
[
0
].
next
[
next_idx
(
'D'
)]
=
&
hdrt
[
1
];
hdrt
[
0
].
next
[
next_idx
(
'E'
)]
=
&
hdrt
[
2
];
hdrt
[
0
].
next
[
next_idx
(
'L'
)]
=
&
hdrt
[
3
];
hdrt
[
0
].
next
[
next_idx
(
'M'
)]
=
&
hdrt
[
4
];
hdrt
[
0
].
next
[
next_idx
(
'R'
)]
=
&
hdrt
[
5
];
hdrt
[
0
].
next
[
next_idx
(
'T'
)]
=
&
hdrt
[
6
];
hdrt
[
0
].
idx
=
-
1
;
hdrt
[
1
].
str
=
strdup
(
"isposition"
);
memset
(
&
hdrt
[
1
].
next
,
0
,
64
*
sizeof
(
struct
hdrt_node
*
));
hdrt
[
1
].
idx
=
1
;
hdrt
[
2
].
str
=
strdup
(
"ncoding"
);
memset
(
&
hdrt
[
2
].
next
,
0
,
64
*
sizeof
(
struct
hdrt_node
*
));
hdrt
[
2
].
idx
=
2
;
hdrt
[
3
].
str
=
strdup
(
""
);
memset
(
&
hdrt
[
3
].
next
,
0
,
64
*
sizeof
(
struct
hdrt_node
*
));
hdrt
[
3
].
next
[
next_idx
(
'A'
)]
=
&
hdrt
[
7
];
hdrt
[
3
].
next
[
next_idx
(
'E'
)]
=
&
hdrt
[
8
];
hdrt
[
3
].
next
[
next_idx
(
'O'
)]
=
&
hdrt
[
9
];
hdrt
[
3
].
idx
=
-
1
;
hdrt
[
4
].
str
=
strdup
(
"D5"
);
memset
(
&
hdrt
[
4
].
next
,
0
,
64
*
sizeof
(
struct
hdrt_node
*
));
hdrt
[
4
].
idx
=
3
;
hdrt
[
5
].
str
=
strdup
(
"ange"
);
memset
(
&
hdrt
[
5
].
next
,
0
,
64
*
sizeof
(
struct
hdrt_node
*
));
hdrt
[
5
].
idx
=
4
;
hdrt
[
6
].
str
=
strdup
(
"ype"
);
memset
(
&
hdrt
[
6
].
next
,
0
,
64
*
sizeof
(
struct
hdrt_node
*
));
hdrt
[
6
].
idx
=
5
;
hdrt
[
7
].
str
=
strdup
(
"nguage"
);
memset
(
&
hdrt
[
7
].
next
,
0
,
64
*
sizeof
(
struct
hdrt_node
*
));
hdrt
[
7
].
idx
=
6
;
hdrt
[
8
].
str
=
strdup
(
"ngth"
);
memset
(
&
hdrt
[
8
].
next
,
0
,
64
*
sizeof
(
struct
hdrt_node
*
));
hdrt
[
8
].
idx
=
7
;
hdrt
[
9
].
str
=
strdup
(
"cation"
);
memset
(
&
hdrt
[
9
].
next
,
0
,
64
*
sizeof
(
struct
hdrt_node
*
));
hdrt
[
9
].
idx
=
8
;
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Content-Disposition:"
)
==
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Content-Encoding:"
)
==
2
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Content-Language:"
)
==
6
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Content-Length:"
)
==
7
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Content-Location:"
)
==
8
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Content-MD5:"
)
==
3
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Content-Range:"
)
==
4
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Content-Type:"
)
==
5
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Content-:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Content-L:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Content-La:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Content-Le:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Content-Lo:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Content:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"Content-Foo:"
)
==
-
1
);
hdrt
[
0
].
str
=
strdup
(
"X-"
);
memset
(
&
hdrt
[
0
].
next
,
0
,
64
*
sizeof
(
struct
hdrt_node
*
));
hdrt
[
0
].
next
[
next_idx
(
'C'
)]
=
&
hdrt
[
1
];
hdrt
[
0
].
next
[
next_idx
(
'F'
)]
=
&
hdrt
[
2
];
hdrt
[
0
].
idx
=
-
1
;
hdrt
[
1
].
str
=
strdup
(
"srf-Token"
);
memset
(
&
hdrt
[
1
].
next
,
0
,
64
*
sizeof
(
struct
hdrt_node
*
));
hdrt
[
1
].
idx
=
1
;
hdrt
[
2
].
str
=
strdup
(
"orwarded-"
);
memset
(
&
hdrt
[
2
].
next
,
0
,
64
*
sizeof
(
struct
hdrt_node
*
));
hdrt
[
2
].
next
[
next_idx
(
'F'
)]
=
&
hdrt
[
3
];
hdrt
[
2
].
next
[
next_idx
(
'H'
)]
=
&
hdrt
[
4
];
hdrt
[
2
].
next
[
next_idx
(
'P'
)]
=
&
hdrt
[
5
];
hdrt
[
2
].
idx
=
-
1
;
hdrt
[
3
].
str
=
strdup
(
"or"
);
memset
(
&
hdrt
[
3
].
next
,
0
,
64
*
sizeof
(
struct
hdrt_node
*
));
hdrt
[
3
].
idx
=
2
;
hdrt
[
4
].
str
=
strdup
(
"ost"
);
memset
(
&
hdrt
[
4
].
next
,
0
,
64
*
sizeof
(
struct
hdrt_node
*
));
hdrt
[
4
].
idx
=
3
;
hdrt
[
5
].
str
=
strdup
(
"roto"
);
memset
(
&
hdrt
[
5
].
next
,
0
,
64
*
sizeof
(
struct
hdrt_node
*
));
hdrt
[
5
].
idx
=
4
;
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"X-Csrf-Token:"
)
==
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"X-Forwarded-For:"
)
==
2
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"X-Forwarded-Host:"
)
==
3
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"X-Forwarded-Proto:"
)
==
4
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"X-:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"X-Forwarded-:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"X-Forwarded-F:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"X-Forwarded-H:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
&
hdrt
[
0
],
"X-Forwarded-P:"
)
==
-
1
);
return
NULL
;
}
static
char
*
test_HDR_InsertIdx
(
void
)
{
#define NODES 10
#define SIZEOF_NEXTTBL (64 * sizeof(struct hdrt_node *))
struct
hdrt_node
*
hdrt
,
*
hdrt2
,
*
next
;
printf
(
"... testing HDR_InsertIdx()
\n
"
);
next
=
calloc
(
64
,
sizeof
(
next
));
MAN
(
next
);
hdrt
=
HDR_InsertIdx
(
NULL
,
"Foo"
,
4711
);
MCHECK_OBJ_NOTNULL
(
hdrt
,
HDRT_NODE_MAGIC
);
MASSERT
(
strcmp
(
hdrt
->
str
,
"Foo"
)
==
0
);
MASSERT
(
hdrt
->
idx
==
4711
);
MASSERT
(
memcmp
(
hdrt
->
next
,
next
,
SIZEOF_NEXTTBL
)
==
0
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Foo:"
)
==
4711
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Foo: bar"
)
==
4711
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Foo:bar"
)
==
4711
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Foo: bar baz"
)
==
4711
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
" Foo : "
)
==
4711
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
" fOO : "
)
==
4711
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Bar:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
" Bar:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Fo:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Food:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Foo bar baz"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Foo"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
" Foo "
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
" "
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
""
)
==
-
1
);
hdrt
=
HDR_InsertIdx
(
hdrt
,
"Foo"
,
4711
);
MCHECK_OBJ_NOTNULL
(
hdrt
,
HDRT_NODE_MAGIC
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Foo:"
)
==
4711
);
hdrt
=
HDR_InsertIdx
(
hdrt
,
"Bar"
,
1147
);
MCHECK_OBJ_NOTNULL
(
hdrt
,
HDRT_NODE_MAGIC
);
MASSERT
(
*
hdrt
->
str
==
'\0'
);
MASSERT
(
hdrt
->
idx
==
-
1
);
for
(
int
i
=
0
;
i
<
64
;
i
++
)
if
(
i
!=
next_idx
(
'B'
)
&&
i
!=
next_idx
(
'F'
))
MAZ
(
hdrt
->
next
[
i
]);
hdrt2
=
hdrt
->
next
[
next_idx
(
'B'
)];
MCHECK_OBJ_NOTNULL
(
hdrt2
,
HDRT_NODE_MAGIC
);
MASSERT
(
strcmp
(
hdrt2
->
str
,
"ar"
)
==
0
);
MASSERT
(
hdrt2
->
idx
==
1147
);
MASSERT
(
memcmp
(
hdrt2
->
next
,
next
,
SIZEOF_NEXTTBL
)
==
0
);
hdrt2
=
hdrt
->
next
[
next_idx
(
'F'
)];
MCHECK_OBJ_NOTNULL
(
hdrt2
,
HDRT_NODE_MAGIC
);
MASSERT
(
strcmp
(
hdrt2
->
str
,
"oo"
)
==
0
);
MASSERT
(
hdrt2
->
idx
==
4711
);
MASSERT
(
memcmp
(
hdrt2
->
next
,
next
,
SIZEOF_NEXTTBL
)
==
0
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Foo:"
)
==
4711
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Bar:"
)
==
1147
);
hdrt
=
HDR_InsertIdx
(
NULL
,
"Accept"
,
1
);
MCHECK_OBJ_NOTNULL
(
hdrt
,
HDRT_NODE_MAGIC
);
hdrt
=
HDR_InsertIdx
(
hdrt
,
"Accept-Encoding"
,
2
);
MCHECK_OBJ_NOTNULL
(
hdrt
,
HDRT_NODE_MAGIC
);
MASSERT
(
strcmp
(
hdrt
->
str
,
"Accept"
)
==
0
);
MASSERT
(
hdrt
->
idx
==
1
);
for
(
int
i
=
0
;
i
<
64
;
i
++
)
if
(
i
!=
next_idx
(
'-'
))
MAZ
(
hdrt
->
next
[
i
]);
hdrt2
=
hdrt
->
next
[
next_idx
(
'-'
)];
MCHECK_OBJ_NOTNULL
(
hdrt2
,
HDRT_NODE_MAGIC
);
MASSERT
(
strcmp
(
hdrt2
->
str
,
"Encoding"
)
==
0
);
MASSERT
(
hdrt2
->
idx
==
2
);
MASSERT
(
memcmp
(
hdrt2
->
next
,
next
,
SIZEOF_NEXTTBL
)
==
0
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Accept:"
)
==
1
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Accept-Encoding:"
)
==
2
);
hdrt
=
HDR_InsertIdx
(
hdrt
,
"Accept-Charset"
,
3
);
MCHECK_OBJ_NOTNULL
(
hdrt
,
HDRT_NODE_MAGIC
);
hdrt
=
HDR_InsertIdx
(
hdrt
,
"Accept-Language"
,
4
);
MCHECK_OBJ_NOTNULL
(
hdrt
,
HDRT_NODE_MAGIC
);
hdrt
=
HDR_InsertIdx
(
hdrt
,
"Accept-Datetime"
,
5
);
MCHECK_OBJ_NOTNULL
(
hdrt
,
HDRT_NODE_MAGIC
);
MASSERT
(
strcmp
(
hdrt
->
str
,
"Accept"
)
==
0
);
MASSERT
(
hdrt
->
idx
==
1
);
for
(
int
i
=
0
;
i
<
64
;
i
++
)
if
(
i
!=
next_idx
(
'-'
))
MAZ
(
hdrt
->
next
[
i
]);
hdrt2
=
hdrt
->
next
[
next_idx
(
'-'
)];
MCHECK_OBJ_NOTNULL
(
hdrt2
,
HDRT_NODE_MAGIC
);
MASSERT
(
*
hdrt2
->
str
==
'\0'
);
MASSERT
(
hdrt2
->
idx
==
-
1
);
for
(
int
i
=
0
;
i
<
64
;
i
++
)
if
(
i
!=
next_idx
(
'C'
)
&&
i
!=
next_idx
(
'D'
)
&&
i
!=
next_idx
(
'E'
)
&&
i
!=
next_idx
(
'L'
))
MAZ
(
hdrt2
->
next
[
i
]);
MCHECK_OBJ_NOTNULL
(
hdrt2
->
next
[
next_idx
(
'C'
)],
HDRT_NODE_MAGIC
);
MCHECK_OBJ_NOTNULL
(
hdrt2
->
next
[
next_idx
(
'D'
)],
HDRT_NODE_MAGIC
);
MCHECK_OBJ_NOTNULL
(
hdrt2
->
next
[
next_idx
(
'E'
)],
HDRT_NODE_MAGIC
);
MCHECK_OBJ_NOTNULL
(
hdrt2
->
next
[
next_idx
(
'L'
)],
HDRT_NODE_MAGIC
);
MASSERT
(
strcmp
(
hdrt2
->
next
[
next_idx
(
'C'
)]
->
str
,
"harset"
)
==
0
);
MASSERT
(
hdrt2
->
next
[
next_idx
(
'C'
)]
->
idx
==
3
);
MASSERT
(
strcmp
(
hdrt2
->
next
[
next_idx
(
'D'
)]
->
str
,
"atetime"
)
==
0
);
MASSERT
(
hdrt2
->
next
[
next_idx
(
'D'
)]
->
idx
==
5
);
MASSERT
(
strcmp
(
hdrt2
->
next
[
next_idx
(
'E'
)]
->
str
,
"ncoding"
)
==
0
);
MASSERT
(
hdrt2
->
next
[
next_idx
(
'E'
)]
->
idx
==
2
);
MASSERT
(
strcmp
(
hdrt2
->
next
[
next_idx
(
'L'
)]
->
str
,
"anguage"
)
==
0
);
MASSERT
(
hdrt2
->
next
[
next_idx
(
'L'
)]
->
idx
==
4
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Accept:"
)
==
1
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Accept-Charset:"
)
==
3
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Accept-Encoding:"
)
==
2
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Accept-Language:"
)
==
4
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Accept-Datetime:"
)
==
5
);
hdrt
=
HDR_InsertIdx
(
NULL
,
"Accept-Encoding"
,
4711
);
hdrt
=
HDR_InsertIdx
(
hdrt
,
"Accept"
,
1147
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Accept:"
)
==
1147
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Accept-Charset:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Accept-Encoding:"
)
==
4711
);
hdrt
=
HDR_InsertIdx
(
NULL
,
"Content-Disposition"
,
1
);
hdrt
=
HDR_InsertIdx
(
hdrt
,
"Content-Encoding"
,
2
);
hdrt
=
HDR_InsertIdx
(
hdrt
,
"Content-Language"
,
3
);
hdrt
=
HDR_InsertIdx
(
hdrt
,
"Content-Length"
,
4
);
hdrt
=
HDR_InsertIdx
(
hdrt
,
"Content-Location"
,
5
);
hdrt
=
HDR_InsertIdx
(
hdrt
,
"Content-MD5"
,
6
);
hdrt
=
HDR_InsertIdx
(
hdrt
,
"Content-Range"
,
7
);
hdrt
=
HDR_InsertIdx
(
hdrt
,
"Content-Type"
,
8
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Content-Disposition:"
)
==
1
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Content-Encoding:"
)
==
2
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Content-Language:"
)
==
3
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Content-Length:"
)
==
4
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Content-Location:"
)
==
5
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Content-MD5:"
)
==
6
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Content-Range:"
)
==
7
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Content-Type:"
)
==
8
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Content-:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Content-L:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Content-La:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Content-Le:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Content-Lo:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Content:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"Content-Foo:"
)
==
-
1
);
hdrt
=
HDR_InsertIdx
(
NULL
,
"X-Csrf-Token"
,
11
);
hdrt
=
HDR_InsertIdx
(
hdrt
,
"X-Forwarded-For"
,
12
);
hdrt
=
HDR_InsertIdx
(
hdrt
,
"X-Forwarded-Host"
,
13
);
hdrt
=
HDR_InsertIdx
(
hdrt
,
"X-Forwarded-Proto"
,
14
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"X-Csrf-Token:"
)
==
11
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"X-Forwarded-For:"
)
==
12
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"X-Forwarded-Host:"
)
==
13
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"X-Forwarded-Proto:"
)
==
14
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"X-:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"X-Forwarded-:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"X-Forwarded-F:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"X-Forwarded-H:"
)
==
-
1
);
MASSERT
(
HDR_FindIdx
(
hdrt
,
"X-Forwarded-P:"
)
==
-
1
);
return
NULL
;
}
static
char
*
test_HDR_Fini
(
void
)
{
struct
hdrt_node
*
hdrt
;
printf
(
"... testing HDR_Fini()
\n
"
);
hdrt
=
HDR_InsertIdx
(
NULL
,
"Content-Disposition"
,
1
);
hdrt
=
HDR_InsertIdx
(
hdrt
,
"Content-Encoding"
,
2
);
hdrt
=
HDR_InsertIdx
(
hdrt
,
"Content-Language"
,
3
);
hdrt
=
HDR_InsertIdx
(
hdrt
,
"Content-Length"
,
4
);
hdrt
=
HDR_InsertIdx
(
hdrt
,
"Content-Location"
,
5
);
hdrt
=
HDR_InsertIdx
(
hdrt
,
"Content-MD5"
,
6
);
hdrt
=
HDR_InsertIdx
(
hdrt
,
"Content-Range"
,
7
);
hdrt
=
HDR_InsertIdx
(
hdrt
,
"Content-Type"
,
8
);
MCHECK_OBJ_NOTNULL
(
hdrt
,
HDRT_NODE_MAGIC
);
HDR_Fini
(
hdrt
);
MASSERT
(
hdrt
==
NULL
||
hdrt
->
magic
!=
HDRT_NODE_MAGIC
);
return
NULL
;
}
static
const
char
*
all_tests
(
void
)
{
mu_run_test
(
test_HDR_FindIdx
);
mu_run_test
(
test_HDR_InsertIdx
);
mu_run_test
(
test_HDR_Fini
);
return
NULL
;
}
TEST_RUNNER
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment