Commit 3d0b141f authored by Nils Goroll's avatar Nils Goroll

Rename: x-variant -> X-DeviceClass, type_mtd -> type_class, change return values

dcs.type_class will now return one of

	new value	old value
	---------	---------
	desktop		dsk
	smartphone	mob
	tablet		tab
parent fa8a0a66
...@@ -34,7 +34,7 @@ VCL: ...@@ -34,7 +34,7 @@ VCL:
sub vcl_recv { sub vcl_recv {
set req.http.x-nb-classified = dcs.type_name(dcs.classify()); set req.http.x-nb-classified = dcs.type_name(dcs.classify());
# - or- # - or-
set req.http.x-variant = dcs.type_mtd(dcs.classify()); set req.http.X-DeviceClass = dcs.type_class(dcs.classify());
# ... # ...
} }
...@@ -332,22 +332,22 @@ Example: ...@@ -332,22 +332,22 @@ Example:
might set `x-nb-classified` to "Mobile Phone" might set `x-nb-classified` to "Mobile Phone"
.. _func_type_mtd: .. _func_type_class:
STRING type_mtd(INT) STRING type_class(INT)
-------------------- ----------------------
Returns one of three meta type names "mob" (for mobile), "tab" (for Returns one of three meta type names "smartphone" (for mobile
tablet) or "dsk" (for desktop) for the dcs db entry whose index is given devices), "tablet" or "desktop" for the dcs db entry whose index is
as the integer argument. given as the integer argument.
Example: Example:
:: ::
set req.http.x-variant = dcs.type_mtd(dcs.classify()); set req.http.X-DeviceClass = dcs.type_class(dcs.classify());
might set `x-variant` to "mob" might set `X-DeviceClass` to "smartphone"
COMMAND LINE USAGE COMMAND LINE USAGE
...@@ -364,7 +364,7 @@ following format: ...@@ -364,7 +364,7 @@ following format:
-- --
<input-line lowercase> <input-line lowercase>
entry id <entry-id> type <type_id> - <type_mdt> - <type_name> entry id <entry-id> type <type_id> - <type_class> - <type_name>
VARNISH 2 USAGE VARNISH 2 USAGE
...@@ -432,8 +432,8 @@ call to `dcs_varnish2_classify_hdrs`: ...@@ -432,8 +432,8 @@ call to `dcs_varnish2_classify_hdrs`:
* `req.http.x-nb-classified` * `req.http.x-nb-classified`
same as :ref:`func_type_name` e.g. "Mobile Phone" same as :ref:`func_type_name` e.g. "Mobile Phone"
* `req.http.x-variant` * `req.http.X-DeviceClass`
same as :ref:`func_type_mtd` e.g. "mob" same as :ref:`func_type_class` e.g. "desktop"
NOTES NOTES
......
...@@ -46,7 +46,7 @@ main (void) { ...@@ -46,7 +46,7 @@ main (void) {
e = dcs_match(line); e = dcs_match(line);
t = dcs_match_type_id(e); t = dcs_match_type_id(e);
printf("--\n%sentry id %d type %d - %s - %s\n", line, printf("--\n%sentry id %d type %d - %s - %s\n", line,
dcs_match_id(e), t, dcs_type_mtd(t), dcs_type_name(t)); dcs_match_id(e), t, dcs_type_class(t), dcs_type_name(t));
} }
return 0; return 0;
} }
...@@ -53,42 +53,46 @@ dcs_type_name(int type_id /* enum dcs_type */) { ...@@ -53,42 +53,46 @@ dcs_type_name(int type_id /* enum dcs_type */) {
* useful meta-classification to just three string constants: * useful meta-classification to just three string constants:
* *
*/ */
enum dcs_type_mtd { enum dcs_type_class {
T_MTD_MISSING = 0, T_CLASS_MISSING = 0,
T_MTD_MOB, T_CLASS_MOB,
T_MTD_TAB, T_CLASS_TAB,
T_MTD_DSK T_CLASS_DSK,
#define T_MTD_MAX T_MTD_DSK _T_CLASS_LIMIT
}; };
const char * const dsc_type_mtd_str[T_MTD_MAX + 1] = { /*
[T_MTD_MISSING] = "dsk", * the class string "smartphone" might not be optimal,
[T_MTD_MOB] = "mob", * - read this as "mobile device".
[T_MTD_TAB] = "tab", */
[T_MTD_DSK] = "dsk" const char * const dcs_type_class_str[_T_CLASS_LIMIT] = {
[T_CLASS_MISSING] = "desktop",
[T_CLASS_MOB] = "smartphone",
[T_CLASS_TAB] = "tablet",
[T_CLASS_DSK] = "desktop"
}; };
enum dcs_type dcs_type2mtd[DCS_TYPE_COUNT] = { enum dcs_type dcs_type2class[DCS_TYPE_COUNT] = {
[NB_T_UNIDENTIFIED] = T_MTD_DSK, [NB_T_UNIDENTIFIED] = T_CLASS_DSK,
[NB_T_BOT] = T_MTD_DSK, [NB_T_BOT] = T_CLASS_DSK,
[NB_T_CAMERA] = T_MTD_MOB, [NB_T_CAMERA] = T_CLASS_MOB,
[NB_T_CE_DEVICE] = T_MTD_MOB, // android 1.5; en-us; nimble [NB_T_CE_DEVICE] = T_CLASS_MOB, // android 1.5; en-us; nimble
[NB_T_COMPUTER] = T_MTD_DSK, // macintosh*intel*mac os [NB_T_COMPUTER] = T_CLASS_DSK, // macintosh*intel*mac os
[NB_T_DESKTOP_BROWSER] = T_MTD_DSK, [NB_T_DESKTOP_BROWSER] = T_CLASS_DSK,
[NB_T_DEVTOOL] = T_MTD_DSK, [NB_T_DEVTOOL] = T_CLASS_DSK,
[NB_T_EREADER] = T_MTD_TAB, [NB_T_EREADER] = T_CLASS_TAB,
[NB_T_MEDIAPLAYER] = T_MTD_MOB, [NB_T_MEDIAPLAYER] = T_CLASS_MOB, // ipod, ms zune, yp-gb1
[NB_T_MOBILECONSOLE] = T_MTD_MOB, [NB_T_MOBILECONSOLE] = T_CLASS_MOB,
[NB_T_MOBILE_BROWSER] = T_MTD_MOB, [NB_T_MOBILE_BROWSER] = T_CLASS_MOB,
[NB_T_MOBILE_PHONE] = T_MTD_MOB, [NB_T_MOBILE_PHONE] = T_CLASS_MOB,
[NB_T_OPERATINGSYSTEM] = T_MTD_MOB, // ios 4.2 [NB_T_OPERATINGSYSTEM] = T_CLASS_MOB, // ios 4.2
[NB_T_SETTOP_BOX_TV] = T_MTD_DSK, [NB_T_SETTOP_BOX_TV] = T_CLASS_DSK,
[NB_T_TABLET] = T_MTD_TAB, [NB_T_TABLET] = T_CLASS_TAB,
[NB_T_WEARABLE_COMPUTER] = T_MTD_MOB // android 4.0*glass [NB_T_WEARABLE_COMPUTER] = T_CLASS_MOB // android 4.0*glass
}; };
const char * const char *
dcs_type_mtd(int type_id /* enum dcs_type */) { dcs_type_class(int type_id /* enum dcs_type */) {
check_type_id(type_id, 0); check_type_id(type_id, 0);
return (dsc_type_mtd_str[dcs_type2mtd[type_id]]); return (dcs_type_class_str[dcs_type2class[type_id]]);
} }
...@@ -31,5 +31,5 @@ ...@@ -31,5 +31,5 @@
#ifndef DCS_TYPE_H #ifndef DCS_TYPE_H
#define DCS_TYPE_H 1 #define DCS_TYPE_H 1
const char * dcs_type_name(int type_id /* enum dcs_type */); const char * dcs_type_name(int type_id /* enum dcs_type */);
const char * dcs_type_mtd(int type_id /* enum dcs_type */); const char * dcs_type_class(int type_id /* enum dcs_type */);
#endif #endif
...@@ -38,5 +38,5 @@ dcs_varnish2_classify_hdrs(const struct sess *sp) { ...@@ -38,5 +38,5 @@ dcs_varnish2_classify_hdrs(const struct sess *sp) {
const int t = dcs_match_type_id(e); const int t = dcs_match_type_id(e);
VRT_SetHdr(sp, HDR_REQ, "\020x-nb-classified:", dcs_type_name(t), vrt_magic_string_end); VRT_SetHdr(sp, HDR_REQ, "\020x-nb-classified:", dcs_type_name(t), vrt_magic_string_end);
VRT_SetHdr(sp, HDR_REQ, "\012x-variant:", dcs_type_mtd(t), vrt_magic_string_end); VRT_SetHdr(sp, HDR_REQ, "\012X-DeviceClass:", dcs_type_class(t), vrt_magic_string_end);
} }
...@@ -23,7 +23,7 @@ varnish v1 -vcl+backend { ...@@ -23,7 +23,7 @@ varnish v1 -vcl+backend {
# common use cases # common use cases
set req.http.x-nb-classified = dcs.type_name(dcs.classify()); set req.http.x-nb-classified = dcs.type_name(dcs.classify());
set req.http.x-variant = dcs.type_mtd(dcs.classify()); set req.http.X-DeviceClass = dcs.type_class(dcs.classify());
error 200; error 200;
} }
...@@ -33,7 +33,7 @@ varnish v1 -vcl+backend { ...@@ -33,7 +33,7 @@ varnish v1 -vcl+backend {
set obj.http.xx-type-id = req.http.xx-type-id; 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-nb-classified = req.http.x-nb-classified;
set obj.http.x-variant = req.http.x-variant; set obj.http.X-DeviceClass = req.http.X-DeviceClass;
synthetic {"classified ad here synthetic {"classified ad here
"}; "};
return (deliver); return (deliver);
...@@ -49,7 +49,7 @@ client c1 { ...@@ -49,7 +49,7 @@ client c1 {
expect resp.http.xx-entry-key == "unidentified" expect resp.http.xx-entry-key == "unidentified"
expect resp.http.xx-type-id == "0" expect resp.http.xx-type-id == "0"
expect resp.http.x-nb-classified == "unidentified" expect resp.http.x-nb-classified == "unidentified"
expect resp.http.x-variant == "dsk" expect resp.http.X-DeviceClass == "desktop"
} -run } -run
client c1 { client c1 {
...@@ -59,7 +59,7 @@ client c1 { ...@@ -59,7 +59,7 @@ client c1 {
expect resp.http.xx-entry-key == "generic wap" expect resp.http.xx-entry-key == "generic wap"
expect resp.http.xx-type-id == "11" expect resp.http.xx-type-id == "11"
expect resp.http.x-nb-classified == "Mobile Phone" expect resp.http.x-nb-classified == "Mobile Phone"
expect resp.http.x-variant == "mob" expect resp.http.X-DeviceClass == "smartphone"
} -run } -run
client c1 { client c1 {
...@@ -70,6 +70,6 @@ client c1 { ...@@ -70,6 +70,6 @@ client c1 {
expect resp.http.xx-entry-key == "android*android*opera mini/" expect resp.http.xx-entry-key == "android*android*opera mini/"
expect resp.http.xx-type-id == "11" expect resp.http.xx-type-id == "11"
expect resp.http.x-nb-classified == "Mobile Phone" expect resp.http.x-nb-classified == "Mobile Phone"
expect resp.http.x-variant == "mob" expect resp.http.X-DeviceClass == "smartphone"
} -run } -run
...@@ -69,9 +69,9 @@ vmod_type_name(struct sess *sp, int e) { ...@@ -69,9 +69,9 @@ vmod_type_name(struct sess *sp, int e) {
} }
const char * const char *
vmod_type_mtd(struct sess *sp, int e) { vmod_type_class(struct sess *sp, int e) {
const int t = dcs_match_type_id(e); const int t = dcs_match_type_id(e);
(void) sp; (void) sp;
return dcs_type_mtd(t > 0 ? t : 0); return dcs_type_class(t > 0 ? t : 0);
} }
...@@ -8,4 +8,4 @@ Function INT classify() ...@@ -8,4 +8,4 @@ Function INT classify()
Function STRING entry_key(INT) Function STRING entry_key(INT)
Function INT type_id(INT) Function INT type_id(INT)
Function STRING type_name(INT) Function STRING type_name(INT)
Function STRING type_mtd(INT) Function STRING type_class(INT)
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