Hi, in attach patch for : - build fix for 1.9/2.0 code base (0001) - removed deprecated methods (0001) - enabled multithreading mode (0001) - added point of contact in MAINTAINERS file (0004)
Module is now tested in MT mode internally. Thanks -Paul -- Paul Stephen Borile Director, WURFL InFuze Product Development - Italy Scientiamobile Inc - paul.bor...@scientiamobile.com +39 348 7108474 Milano Office : +39 02 620227260 skype: paulstephenborile "Reducing complexity and size must be the goal in every step." Niklaus Wirth
From 1951335fe4782a778caa8d504dcc55aaa40db653 Mon Sep 17 00:00:00 2001 From: paulborile <paul.bor...@gmail.com> Date: Thu, 7 Mar 2019 14:47:46 +0100 Subject: [PATCH 1/4] wurfl module porting to 1.9 --- doc/WURFL-device-detection.txt | 10 +-- doc/configuration.txt | 36 +------- examples/wurfl-example.cfg | 11 +-- src/wurfl.c | 157 ++++++++------------------------- 4 files changed, 44 insertions(+), 170 deletions(-) diff --git a/doc/WURFL-device-detection.txt b/doc/WURFL-device-detection.txt index c968615..908fb66 100644 --- a/doc/WURFL-device-detection.txt +++ b/doc/WURFL-device-detection.txt @@ -23,26 +23,18 @@ These are the supported WURFL directives (see doc/configuration.txt) : virtual capabilities, property names we plan to use in injected headers) - wurfl-information-list-separator <char> (character that will be used to separate values in a response header, ',' by default). -- wurfl-engine-mode <string> (Sets the WURFL engine target. You can choose - between "accuracy" and "performance","performance" by default) - wurfl-cache-size <string> (Sets the WURFL caching strategy) - wurfl-patch-file [<file path>] (Sets the paths to custom WURFL patch files) Sample configuration : global - wurfl-data-file /usr/share/wurfl/wurfl-eval.xml + wurfl-data-file /usr/share/wurfl/wurfl.zip wurfl-information-list wurfl_id model_name #wurfl-information-list-separator | - wurfl-engine-mode performance - #wurfl-engine-mode accuracy - - ## double LRU cache - wurfl-cache-size 100000,30000 - ## single LRU cache #wurfl-cache-size 100000 ## no cache #wurfl-cache-size 0 diff --git a/doc/configuration.txt b/doc/configuration.txt index 8a23c0a..7c75483 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -599,9 +599,7 @@ The following keywords are supported in the "global" section : - wurfl-data-file - wurfl-information-list - wurfl-information-list-separator - - wurfl-engine-mode - wurfl-cache-size - - wurfl-useragent-priority * Performance tuning - max-spread-checks @@ -1236,10 +1234,6 @@ wurfl-information-list [<capability>]* - wurfl_api_version Contains a string representing the currently used Libwurfl API version. - - wurfl_engine_target Contains a string representing the currently - set WURFL Engine Target. Possible values are - "HIGH_ACCURACY", "HIGH_PERFORMANCE", "INVALID". - - wurfl_info A string containing information on the parsed wurfl.xml and its full path. @@ -1248,7 +1242,6 @@ wurfl-information-list [<capability>]* - wurfl_normalized_useragent The normalized useragent. - - wurfl_useragent_priority The user agent priority used by WURFL. Please note that this option is only available when haproxy has been compiled with USE_WURFL=1. @@ -1267,36 +1260,15 @@ wurfl-patch-file [<file path>] Please note that this option is only available when haproxy has been compiled with USE_WURFL=1. -wurfl-engine-mode { accuracy | performance } - Sets the WURFL engine target. You can choose between 'accuracy' or - 'performance' targets. In performance mode, desktop web browser detection is - done programmatically without referencing the WURFL data. As a result, most - desktop web browsers are returned as generic_web_browser WURFL ID for - performance. If either performance or accuracy are not defined, performance - mode is enabled by default. - - Please note that this option is only available when haproxy has been compiled - with USE_WURFL=1. - -wurfl-cache-size <U>[,<D>] - Sets the WURFL caching strategy. Here <U> is the Useragent cache size, and - <D> is the internal device cache size. There are three possibilities here : +wurfl-cache-size <U> + Sets the WURFL Useragent cache size. For faster lookups, already processed user + agents are kept in a LRU cache : - "0" : no cache is used. - - <U> : the Single LRU cache is used, the size is expressed in elements. - - <U>,<D> : the Double LRU cache is used, both sizes are in elements. This is - the highest performing option. + - <size> : size of lru cache in elements. Please note that this option is only available when haproxy has been compiled with USE_WURFL=1. -wurfl-useragent-priority { plain | sideloaded_browser } - Tells WURFL if it should prioritize use of the plain user agent ('plain') - over the default sideloaded browser user agent ('sideloaded_browser'). - - Please note that this option is only available when haproxy has been compiled - with USE_WURFL=1. - - 3.2. Performance tuning ----------------------- diff --git a/examples/wurfl-example.cfg b/examples/wurfl-example.cfg index ad651a8..d8e35a2 100644 --- a/examples/wurfl-example.cfg +++ b/examples/wurfl-example.cfg @@ -6,20 +6,15 @@ global + nbproc 1 + nbthread 4 + # The WURFL data file wurfl-data-file /usr/share/wurfl/wurfl-eval.xml # WURFL patches definition (as much as needed, patches will be applied in the same order as specified in this conf file) #wurfl-patch-file /path/to/patch1.xml; - # WURFL engine target: one of the following (default is performance) - wurfl-engine-mode performance - #wurfl-engine-mode accuracy - - # WURFL cache: one of the following - ## double LRU cache - wurfl-cache-size 100000,30000 - ## single LRU cache #wurfl-cache-size 100000 ## no cache #wurfl-cache-size 0 diff --git a/src/wurfl.c b/src/wurfl.c index 75dcf00..44e246e 100644 --- a/src/wurfl.c +++ b/src/wurfl.c @@ -19,8 +19,6 @@ static struct { char *data_file; /* the WURFL data file */ char *cache_size; /* the WURFL cache parameters */ - int engine_mode; /* the WURFL engine mode */ - int useragent_priority; /* the WURFL ua priority */ struct list patch_file_list; /* the list of WURFL patch file to use */ char information_list_separator; /* the separator used in request to separate values */ struct list information_list; /* the list of WURFL data to return into request */ @@ -29,8 +27,6 @@ static struct { } global_wurfl = { .data_file = NULL, .cache_size = NULL, - .engine_mode = -1, - .useragent_priority = -1, .information_list_separator = ',', .information_list = LIST_HEAD_INIT(global_wurfl.information_list), .patch_file_list = LIST_HEAD_INIT(global_wurfl.patch_file_list), @@ -75,11 +71,6 @@ typedef struct { static const char HA_WURFL_MODULE_VERSION[] = "1.0"; static const char HA_WURFL_ISDEVROOT_FALSE[] = "FALSE"; static const char HA_WURFL_ISDEVROOT_TRUE[] = "TRUE"; -static const char HA_WURFL_TARGET_ACCURACY[] = "accuracy"; -static const char HA_WURFL_TARGET_PERFORMANCE[] = "performance"; -static const char HA_WURFL_PRIORITY_PLAIN[] = "plain"; -static const char HA_WURFL_PRIORITY_SIDELOADED_BROWSER[] = "sideloaded_browser"; -static const char HA_WURFL_MIN_ENGINE_VERSION_MANDATORY[] = "1.8.0.0"; static const char HA_WURFL_DATA_TYPE_UNKNOWN_STRING[] = "unknown"; static const char HA_WURFL_DATA_TYPE_CAP_STRING[] = "capability"; @@ -105,14 +96,14 @@ static const struct { const char *(*func)(wurfl_handle wHandle, wurfl_device_handle dHandle); } wurfl_properties_function_map [] = { {"wurfl_api_version", ha_wurfl_get_wurfl_api_version}, - {"wurfl_engine_target", ha_wurfl_get_wurfl_engine_target}, + {"wurfl_engine_target", ha_wurfl_get_wurfl_engine_target}, // kept for backward conf file compat {"wurfl_id", ha_wurfl_get_wurfl_id }, {"wurfl_info", ha_wurfl_get_wurfl_info }, {"wurfl_isdevroot", ha_wurfl_get_wurfl_isdevroot}, {"wurfl_last_load_time", ha_wurfl_get_wurfl_last_load_time}, {"wurfl_normalized_useragent", ha_wurfl_get_wurfl_normalized_useragent}, {"wurfl_useragent", ha_wurfl_get_wurfl_useragent}, - {"wurfl_useragent_priority", ha_wurfl_get_wurfl_useragent_priority }, + {"wurfl_useragent_priority", ha_wurfl_get_wurfl_useragent_priority }, // kept for backward conf file compat {"wurfl_root_id", ha_wurfl_get_wurfl_root_id}, }; static const int HA_WURFL_PROPERTIES_NBR = 10; @@ -166,28 +157,13 @@ static int ha_wurfl_cfg_engine_mode(char **args, int section_type, struct proxy struct proxy *defpx, const char *file, int line, char **err) { - if (*(args[1]) == 0) { - memprintf(err, "WURFL: %s expects a value.\n", args[0]); - return -1; - } - - if (!strcmp(args[1],HA_WURFL_TARGET_ACCURACY)) { - global_wurfl.engine_mode = WURFL_ENGINE_TARGET_HIGH_ACCURACY; - return 0; - } - - if (!strcmp(args[1],HA_WURFL_TARGET_PERFORMANCE)) { - global_wurfl.engine_mode = WURFL_ENGINE_TARGET_HIGH_PERFORMANCE; - return 0; - } - - memprintf(err, "WURFL: %s valid values are %s or %s.\n", args[0], HA_WURFL_TARGET_PERFORMANCE, HA_WURFL_TARGET_ACCURACY); - return -1; + // there is no engine target anymore since wurfl 1.9 + return 0; } static int ha_wurfl_cfg_information_list_separator(char **args, int section_type, struct proxy *curpx, - struct proxy *defpx, const char *file, int line, - char **err) + struct proxy *defpx, const char *file, int line, + char **err) { if (*(args[1]) == 0) { memprintf(err, "WURFL: %s expects a single character.\n", args[0]); @@ -204,8 +180,8 @@ static int ha_wurfl_cfg_information_list_separator(char **args, int section_type } static int ha_wurfl_cfg_information_list(char **args, int section_type, struct proxy *curpx, - struct proxy *defpx, const char *file, int line, - char **err) + struct proxy *defpx, const char *file, int line, + char **err) { int argIdx = 1; wurfl_information_t *wi; @@ -262,26 +238,12 @@ static int ha_wurfl_cfg_patch_file_list(char **args, int section_type, struct pr } static int ha_wurfl_cfg_useragent_priority(char **args, int section_type, struct proxy *curpx, - struct proxy *defpx, const char *file, int line, - char **err) + struct proxy *defpx, const char *file, int line, + char **err) { - if (*(args[1]) == 0) { - memprintf(err, "WURFL: %s expects a value.\n", args[0]); - return -1; - } - - if (!strcmp(args[1],HA_WURFL_PRIORITY_PLAIN)) { - global_wurfl.useragent_priority = WURFL_USERAGENT_PRIORITY_USE_PLAIN_USERAGENT; - return 0; - } - - if (!strcmp(args[1],HA_WURFL_PRIORITY_SIDELOADED_BROWSER)) { - global_wurfl.useragent_priority = WURFL_USERAGENT_PRIORITY_OVERRIDE_SIDELOADED_BROWSER_USERAGENT; - return 0; - } - - memprintf(err, "WURFL: %s valid values are %s or %s.\n", args[0], HA_WURFL_PRIORITY_PLAIN, HA_WURFL_PRIORITY_SIDELOADED_BROWSER); - return -1; + // this feature is deprecated, keeping only not to break compatibility + // with old configuration files. + return 0; } /* @@ -315,11 +277,6 @@ static int ha_wurfl_init(void) return ERR_WARN; } - if (global.nbthread > 1) { - ha_alert("WURFL: multithreading is not supported for now.\n"); - return (ERR_FATAL | ERR_ALERT); - } - if (wurfl_set_root(global_wurfl.handle, global_wurfl.data_file) != WURFL_OK) { ha_warning("WURFL: Engine setting root file failed - %s\n", wurfl_get_error_message(global_wurfl.handle)); send_log(NULL, LOG_WARNING, "WURFL: Engine setting root file failed - %s\n", wurfl_get_error_message(global_wurfl.handle)); @@ -335,7 +292,8 @@ static int ha_wurfl_init(void) ha_warning("WURFL: missing wurfl-information-list parameter in global configuration\n"); send_log(NULL, LOG_WARNING, "WURFL: missing wurfl-information-list parameter in global configuration\n"); return ERR_WARN; - } else { + } + else { // ebtree initialization global_wurfl.btree = EB_ROOT; @@ -346,10 +304,12 @@ static int ha_wurfl_init(void) if ((wi->data.func_callback = (PROP_CALLBACK_FUNC) ha_wurfl_get_property_callback(wi->data.name)) != NULL) { wi->data.type = HA_WURFL_DATA_TYPE_PROPERTY; ha_wurfl_log("WURFL: [%s] is a valid wurfl data [property]\n",wi->data.name); - } else if (wurfl_has_virtual_capability(global_wurfl.handle, wi->data.name)) { + } + else if (wurfl_has_virtual_capability(global_wurfl.handle, wi->data.name)) { wi->data.type = HA_WURFL_DATA_TYPE_VCAP; ha_wurfl_log("WURFL: [%s] is a valid wurfl data [virtual capability]\n",wi->data.name); - } else { + } + else { // by default a cap type is assumed to be and we control it on engine load wi->data.type = HA_WURFL_DATA_TYPE_CAP; @@ -385,39 +345,13 @@ static int ha_wurfl_init(void) return ERR_WARN; } - } else { - ha_wurfl_log("WURFL: [%s] already loaded\n",wi->data.name); } - - } - - } - - // filtering mandatory capabilities if engine version < 1.8.0.0 - if (strcmp(wurfl_get_api_version(), HA_WURFL_MIN_ENGINE_VERSION_MANDATORY) < 0) { - wurfl_capability_enumerator_handle hmandatorycapabilityenumerator; - ha_wurfl_log("WURFL: Engine version %s < %s - Filtering mandatory capabilities\n", wurfl_get_api_version(), HA_WURFL_MIN_ENGINE_VERSION_MANDATORY); - hmandatorycapabilityenumerator = wurfl_get_mandatory_capability_enumerator(global_wurfl.handle); - - while (wurfl_capability_enumerator_is_valid(hmandatorycapabilityenumerator)) { - char *name = (char *)wurfl_capability_enumerator_get_name(hmandatorycapabilityenumerator); - - if (ebst_lookup(&global_wurfl.btree, name) == NULL) { - if (wurfl_add_requested_capability(global_wurfl.handle, name) != WURFL_OK) { - ha_warning("WURFL: Engine adding mandatory capability [%s] failed - %s\n", name, wurfl_get_error_message(global_wurfl.handle)); - send_log(NULL, LOG_WARNING, "WURFL: Adding mandatory capability [%s] failed - %s\n", name, wurfl_get_error_message(global_wurfl.handle)); - return ERR_WARN; - } - - ha_wurfl_log("WURFL: Mandatory capability [%s] added\n", name); - } else { - ha_wurfl_log("WURFL: Mandatory capability [%s] already filtered\n", name); + else { + ha_wurfl_log("WURFL: [%s] already loaded\n",wi->data.name); } - wurfl_capability_enumerator_move_next(hmandatorycapabilityenumerator); } - wurfl_capability_enumerator_destroy(hmandatorycapabilityenumerator); } // adding WURFL patches if needed @@ -436,16 +370,19 @@ static int ha_wurfl_init(void) } // setting cache provider if specified in cfg, otherwise let engine choose + // this code is maintained for backward comp : there is only 1 type of case (SINGLE LRU) + // and libwurfl will always default any confguration to single lru if (global_wurfl.cache_size != NULL) { - if (strpbrk(global_wurfl.cache_size, ",") != NULL) { + if (strchr(global_wurfl.cache_size, ',') != NULL) { wurfl_result_code = wurfl_set_cache_provider(global_wurfl.handle, WURFL_CACHE_PROVIDER_DOUBLE_LRU, global_wurfl.cache_size) ; - } else { + } + else { if (strcmp(global_wurfl.cache_size, "0")) { wurfl_result_code = wurfl_set_cache_provider(global_wurfl.handle, WURFL_CACHE_PROVIDER_LRU, global_wurfl.cache_size) ; - } else { + } + else { wurfl_result_code = wurfl_set_cache_provider(global_wurfl.handle, WURFL_CACHE_PROVIDER_NONE, 0); } - } if (wurfl_result_code != WURFL_OK) { @@ -453,33 +390,9 @@ static int ha_wurfl_init(void) send_log(NULL, LOG_WARNING, "WURFL: Setting cache to [%s] failed - %s\n", global_wurfl.cache_size, wurfl_get_error_message(global_wurfl.handle)); return ERR_WARN; } - send_log(NULL, LOG_NOTICE, "WURFL: Cache set to [%s]\n", global_wurfl.cache_size); } - // setting engine mode if specified in cfg, otherwise let engine choose - if (global_wurfl.engine_mode != -1) { - if (wurfl_set_engine_target(global_wurfl.handle, global_wurfl.engine_mode) != WURFL_OK ) { - ha_warning("WURFL: Setting engine target failed - %s\n", wurfl_get_error_message(global_wurfl.handle)); - send_log(NULL, LOG_WARNING, "WURFL: Setting engine target failed - %s\n", wurfl_get_error_message(global_wurfl.handle)); - return ERR_WARN; - } - - } - - send_log(NULL, LOG_NOTICE, "WURFL: Engine target set to [%s]\n", (global_wurfl.engine_mode == WURFL_ENGINE_TARGET_HIGH_PERFORMANCE) ? (HA_WURFL_TARGET_PERFORMANCE) : (HA_WURFL_TARGET_ACCURACY) ); - - // setting ua priority if specified in cfg, otherwise let engine choose - if (global_wurfl.useragent_priority != -1) { - if (wurfl_set_useragent_priority(global_wurfl.handle, global_wurfl.useragent_priority) != WURFL_OK ) { - ha_warning("WURFL: Setting engine useragent priority failed - %s\n", wurfl_get_error_message(global_wurfl.handle)); - send_log(NULL, LOG_WARNING, "WURFL: Setting engine useragent priority failed - %s\n", wurfl_get_error_message(global_wurfl.handle)); - return ERR_WARN; - } - - } - - send_log(NULL, LOG_NOTICE, "WURFL: Engine useragent priority set to [%s]\n", (global_wurfl.useragent_priority == WURFL_USERAGENT_PRIORITY_USE_PLAIN_USERAGENT) ? (HA_WURFL_PRIORITY_PLAIN) : (HA_WURFL_PRIORITY_SIDELOADED_BROWSER) ); // loading WURFL engine if (wurfl_load(global_wurfl.handle) != WURFL_OK) { @@ -645,9 +558,10 @@ static int ha_wurfl_get(const struct arg *args, struct sample *smp, const char * break; } - } else { + } + else { ha_wurfl_log("WURFL: %s not in wurfl-information-list \n", - args[i].data.str.area); + args[i].data.str.area); } i++; @@ -722,7 +636,7 @@ static const char *ha_wurfl_get_wurfl_api_version (wurfl_handle wHandle, wurfl_d static const char *ha_wurfl_get_wurfl_engine_target (wurfl_handle wHandle, wurfl_device_handle dHandle) { - return wurfl_get_engine_target_as_string(wHandle); + return "default"; } static const char *ha_wurfl_get_wurfl_info (wurfl_handle wHandle, wurfl_device_handle dHandle) @@ -742,7 +656,7 @@ static const char *ha_wurfl_get_wurfl_normalized_useragent (wurfl_handle wHandle static const char *ha_wurfl_get_wurfl_useragent_priority (wurfl_handle wHandle, wurfl_device_handle dHandle) { - return wurfl_get_useragent_priority_as_string(wHandle); + return "default"; } // call function for WURFL properties @@ -759,7 +673,8 @@ static const char *(*ha_wurfl_get_property_callback(char *name)) (wurfl_handle w if((cond = strcmp(wurfl_properties_function_map[position].name, name)) == 0) { ha_wurfl_log("WURFL: ha_wurfl_get_property_callback match %s\n", wurfl_properties_function_map[position].name ); return wurfl_properties_function_map[position].func; - } else if(cond < 0) + } + else if(cond < 0) begin = position + 1; else end = position - 1; @@ -783,7 +698,7 @@ static const char *ha_wurfl_retrieve_header(const char *header_name, const void msg = &smp->strm->txn->req; ctx.idx = 0; - if (http_find_full_header2(header_name, strlen(header_name), msg->chn->buf->p, idx, &ctx) == 0) + if (http_find_full_header2(header_name, strlen(header_name), ci_head(msg->chn), idx, &ctx) == 0) return 0; if (header_len > ctx.vlen) -- 2.17.1
From a169161d97478a94eadda2f9713cae92105e6a20 Mon Sep 17 00:00:00 2001 From: paulborile <paul.bor...@gmail.com> Date: Mon, 11 Mar 2019 12:29:20 +0100 Subject: [PATCH 4/4] added Scientiamobile point of contact --- MAINTAINERS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index df7cc33..e006de4 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -62,6 +62,10 @@ Files: src/da.c, include/*/da.h Maintainer: Ben Shillito <b...@51degrees.com> Files: src/51d.c +ScientiaMobile WURFL Device Detection +Maintainer: Paul Borile, Massimiliano Bellomi <wurfl-haproxy-supp...@scientiamobile.com> +Files: src/wurfl.c + Cache Maintainer: William Lallemand <wlallem...@haproxy.com> Files: src/cache.c, include/*/cache.h -- 2.17.1