Commit 87034056 authored by Nils Goroll's avatar Nils Goroll

dcs_varnish_classify must return entry IDs, not type ids

add NB_E_SPECIAL_* enums and skip these in dcs_test
parent 68534490
......@@ -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) {
......
......@@ -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, "\016x-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;
......
......@@ -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 " */
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment