Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dcs_classifier
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
dcs_classifier
Commits
87034056
Commit
87034056
authored
Apr 13, 2014
by
Nils Goroll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dcs_varnish_classify must return entry IDs, not type ids
add NB_E_SPECIAL_* enums and skip these in dcs_test
parent
68534490
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
70 additions
and
34 deletions
+70
-34
dcs_test.c
src/dcs_test.c
+1
-3
dcs_varnish.c
src/dcs_varnish.c
+2
-2
gen_dcs_classifier.pl
src/gen_dcs_classifier.pl
+48
-25
dcs01.vtc
src/tests/dcs01.vtc
+19
-4
No files found.
src/dcs_test.c
View file @
87034056
...
...
@@ -103,9 +103,7 @@ test (const char *fixup_remove_name, const char *fixup_reorder_name) {
}
}
for
(
i
=
0
;
i
<
DCS_ENTRY_COUNT
;
i
++
)
{
if
(
dcs_entry
[
i
].
active
==
0
)
continue
;
for
(
i
=
NB_E_SPECIAL_LIMIT
;
i
<
DCS_ENTRY_COUNT
;
i
++
)
{
if
(
dcs_matchstate_init
.
matchmask
[
i
]
==
0
)
{
r
=
dcs_match
(
dcs_entry
[
i
].
key
);
if
(
i
!=
r
)
{
...
...
src/dcs_varnish.c
View file @
87034056
...
...
@@ -67,10 +67,10 @@ dcs_varnish_classify(const struct sess *sp) {
char
uabuf
[
space
];
if
((
!
ua
)
||
(
!
*
ua
))
return
NB_
T
_UNIDENTIFIED
;
return
NB_
E_SPECIAL
_UNIDENTIFIED
;
if
(
VRT_GetHdr
(
sp
,
HDR_REQ
,
"
\016
x-wap-profile:"
))
return
NB_
T_MOBILE_PHONE
;
return
NB_
E_SPECIAL_GENERIC_WAP
;
/* we need to copy to downcase the string for matching */
w
=
uabuf
;
...
...
src/gen_dcs_classifier.pl
View file @
87034056
...
...
@@ -384,6 +384,15 @@ sub load_classifier_db($$) {
return
wantarray
?
(
\
$decrypt
,
$h_file
)
:
\
$decrypt
;
}
sub
enum_name
($$)
{
my
(
$prefix
,
$s
)
=
@_
;
my
$e
=
$prefix
.
uc
(
$s
);
$e
=~
s:
[
-\
s
]:
_:g
;
$e
=~
s:
[
^
_A
-
Z0
-
9
]
::
g
;
return
$e
}
my
%
nbtype2typeenum
;
my
%
typeenum2nbtype
;
# convert a NB type string to an enum
...
...
@@ -394,9 +403,7 @@ sub type_enum($) {
return
$nbtype2typeenum
{
$s
};
}
my
$e
=
'NB_T_'
.
uc
(
$s
);
$e
=~
s:
[
-\
s
]:
_:g
;
$e
=~
s:
[
^
_A
-
Z0
-
9
]
::
g
;
my
$e
=
enum_name
(
'NB_T_'
,
$s
);
if
(
exists
(
$typeenum2nbtype
{
$e
}))
{
die
'name clash '
.
$e
.
' '
.
$typeenum2nbtype
{
$e
}
.
' vs '
.
$s
;
...
...
@@ -529,29 +536,41 @@ my %types;
my
$line
=
0
;
my
$subkey_id
=
0
;
# init the special entry 0
{
my
@e
;
my
$s
=
"unidentified"
;
$e
[
ENTRY_ACTIVE
]
=
1
;
$e
[
ENTRY_ID
]
=
0
;
$e
[
ENTRY_ORDER
]
=
0
;
$e
[
ENTRY_COMMON_MATCHMASK
]
=
0xffffffff
;
$e
[
ENTRY_MATCHMASK
]
=
0xffffffff
;
$e
[
ENTRY_INITMASK
]
=
0
;
$e
[
ENTRY_TYPE
]
=
type_enum
(
$s
);
$e
[
ENTRY_KEY
]
=
\
$s
;
$e
[
ENTRY_SUBKEYS
]
=
[]
;
$entries
[
$line
++
]
=
\
@e
;
my
%
special_entries
;
my
@n
;
$n
[
SUBKEY_ID
]
=
$subkey_id
;
$n
[
SUBKEY_COMMON_MATCHMASK
]
=
0
;
$n
[
SUBKEY_STRING
]
=
\
$s
;
$n
[
SUBKEY_ENTRIES
]
=
[[
0
,
0
]];
assert
(
!
defined
(
$subkeys_byid
[
$subkey_id
]));
$subkeys_byid
[
$subkey_id
]
=
\
@n
;
$subkey_id
++
;
# init the special entries
{
{
my
@e
;
my
$s
=
"unidentified"
;
$special_entries
{
enum_name
(
'NB_E_SPECIAL_'
,
$s
)}
=
$line
;
$e
[
ENTRY_ACTIVE
]
=
1
;
$e
[
ENTRY_ID
]
=
$line
;
$e
[
ENTRY_ORDER
]
=
$line
;
$e
[
ENTRY_COMMON_MATCHMASK
]
=
0xffffffff
;
$e
[
ENTRY_MATCHMASK
]
=
0xffffffff
;
$e
[
ENTRY_INITMASK
]
=
0
;
$e
[
ENTRY_TYPE
]
=
type_enum
(
$s
);
$e
[
ENTRY_KEY
]
=
\
$s
;
$e
[
ENTRY_SUBKEYS
]
=
[]
;
$entries
[
$line
++
]
=
\
@e
;
}
{
my
@e
;
my
$s
=
"generic wap"
;
$special_entries
{
enum_name
(
'NB_E_SPECIAL_'
,
$s
)}
=
$line
;
$e
[
ENTRY_ACTIVE
]
=
1
;
$e
[
ENTRY_ID
]
=
$line
;
$e
[
ENTRY_ORDER
]
=
$line
;
$e
[
ENTRY_COMMON_MATCHMASK
]
=
0xffffffff
;
$e
[
ENTRY_MATCHMASK
]
=
0xffffffff
;
$e
[
ENTRY_INITMASK
]
=
0
;
$e
[
ENTRY_TYPE
]
=
type_enum
(
"Mobile Phone"
);
$e
[
ENTRY_KEY
]
=
\
$s
;
$e
[
ENTRY_SUBKEYS
]
=
[]
;
$entries
[
$line
++
]
=
\
@e
;
}
$special_entries
{
enum_name
(
'NB_E_SPECIAL_'
,
'LIMIT'
)}
=
$line
;
}
## pre-process the db to generate statistics, filter and
...
...
@@ -786,6 +805,10 @@ _VCL (F_CLASSIFIER_H, VCL_TOP,
join
(
",\n\t"
,
'NB_T_UNIDENTIFIED = 0'
,
sort
grep
{
$_
ne
'NB_T_UNIDENTIFIED'
}
keys
%
typeenum2nbtype
)
.
"\n};\n"
.
"enum dcs_special_entry {\n\t"
.
join
(
",\n\t"
,
map { $_.' = '.$special_entries{$_} } sort keys %special
_entries
)
.
"\n};\n"
);
# /* 4emacs c-mode " */
...
...
src/tests/dcs01.vtc
View file @
87034056
...
...
@@ -17,14 +17,23 @@ varnish v1 -vcl+backend {
# once or use inline-C to save the return value of
# classify (int)
set req.http.x-nb-classified = dcs.type_name(dcs.classify());
set req.http.x-variant = dcs.type_mtd(dcs.classify());
# exotic use cases
set req.http.xx-entry-key = dcs.entry_key(dcs.classify());
set req.http.xx-type-id = dcs.type_id(dcs.classify());
# common use cases
set req.http.x-nb-classified = dcs.type_name(dcs.classify());
set req.http.x-variant = dcs.type_mtd(dcs.classify());
error 200;
}
sub vcl_error {
set obj.http.x-nb-classified = req.http.x-nb-classified;
set obj.http.x-variant = req.http.x-variant;
set obj.http.xx-entry-key = req.http.xx-entry-key;
set obj.http.xx-type-id = req.http.xx-type-id;
set obj.http.x-nb-classified = req.http.x-nb-classified;
set obj.http.x-variant = req.http.x-variant;
synthetic {"classified ad here
"};
return (deliver);
...
...
@@ -37,6 +46,8 @@ client c1 {
txreq -url "/"
rxresp
expect resp.status == 200
expect resp.http.xx-entry-key == "unidentified"
expect resp.http.xx-type-id == "0"
expect resp.http.x-nb-classified == "unidentified"
expect resp.http.x-variant == "dsk"
} -run
...
...
@@ -45,6 +56,8 @@ client c1 {
txreq -hdr "user-agent: willgetignored" -hdr "x-wap-profile: anything"
rxresp
expect resp.status == 200
expect resp.http.xx-entry-key == "generic wap"
expect resp.http.xx-type-id == "11"
expect resp.http.x-nb-classified == "Mobile Phone"
expect resp.http.x-variant == "mob"
} -run
...
...
@@ -54,6 +67,8 @@ client c1 {
-hdr "X-OperaMini-Phone-UA: Mozilla/5.0 (Linux; U; Android 4.3; de-de; ME302C Build/JSS15Q) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30"
rxresp
expect resp.status == 200
expect resp.http.xx-entry-key == "android*android*opera mini/"
expect resp.http.xx-type-id == "11"
expect resp.http.x-nb-classified == "Mobile Phone"
expect resp.http.x-variant == "mob"
} -run
...
...
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