Hi Willy,

a small patch to fix a problem on Scientiamobile WURFL module's "Engine
Target" option

Thanks and regards
-Massimiliano
From 28badec3241c9b8d7c1b56aab5e5c4c5b76624c2 Mon Sep 17 00:00:00 2001
From: scientiamobile <[email protected]>
Date: Mon, 3 Jul 2017 13:34:33 +0200
Subject: [PATCH] BUG-MINOR WURFL engine target fix

---
 doc/WURFL-device-detection.txt | 24 ++++++++++++++++++------
 doc/configuration.txt          | 33 ++++++++++++++++++---------------
 examples/wurfl-example.cfg     |  6 +-----
 src/wurfl.c                    | 41 ++++++++++++++++++++++++++++++++++-------
 4 files changed, 71 insertions(+), 33 deletions(-)
 mode change 100644 => 100755 doc/WURFL-device-detection.txt
 mode change 100644 => 100755 doc/configuration.txt
 mode change 100644 => 100755 examples/wurfl-example.cfg

diff --git a/doc/WURFL-device-detection.txt b/doc/WURFL-device-detection.txt
old mode 100644
new mode 100755
index c968615..0c6ea63
--- a/doc/WURFL-device-detection.txt
+++ b/doc/WURFL-device-detection.txt
@@ -17,29 +17,41 @@ Compile haproxy as shown :
 
 Optionally WURFL_DEBUG=1 may be set to increase logs verbosity
 
+*************** IMPORTANT: Decommissioning of Engine Mode Options **************
+Prior to version 1.9 of the Scientiamobile InFuze C API, users could choose
+between Accuracy and Performance engine optimization options. These options
+had been introduced years ago to manage the behavior of certain web browsers
+and their tendency to present "always different" User-Agent strings that would
+baffle strategies to cache similar WURFL queries in memory. As the problem has
+been solved by browser vendors, the need to adopt this strategy has diminished
+and ultimately disappeared (i.e. there was no longer much to be gained with
+the Performance mode in most circumstances) and ScientiaMobile elected to
+"remove" this option to simplify configuration and go in the direction of
+uniform WURFL API behavior in different contexts.
+
+For this reason, since HAProxy versions greater than 1.7.7, in order to build
+WURFL Device Detection support, Scientiamobile InFuze C API version 1.9 or
+greater is required.
+********************************************************************************
+
 These are the supported WURFL directives (see doc/configuration.txt) :
 - wurfl-data-file <path to WURFL data file>
 - wurfl-information-list [<string>] (list of WURFL capabilities,
    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
diff --git a/doc/configuration.txt b/doc/configuration.txt
old mode 100644
new mode 100755
index b6e3c9a..2ff75a8
--- a/doc/configuration.txt
+++ b/doc/configuration.txt
@@ -57,7 +57,7 @@ Summary
 4.2.      Alphabetically sorted keywords reference
 
 5.    Bind and Server options
-5.1.      Bind options
+5.1.      Find options
 5.2.      Server and default-server options
 5.3.      Server DNS resolution
 5.3.1.      Global overview
@@ -1044,10 +1044,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.
 
@@ -1075,16 +1071,23 @@ 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-engine-mode
+  ************** IMPORTANT: Decommissioning of Engine Mode Options *************
+  Prior to version 1.9 of the Scientiamobile InFuze C API, users could choose
+  between Accuracy and Performance engine optimization options. These options
+  had been introduced years ago to manage the behavior of certain web browsers
+  and their tendency to present "always different" User-Agent strings that would
+  baffle strategies to cache similar WURFL queries in memory. As the problem has
+  been solved by browser vendors, the need to adopt this strategy has diminished
+  and ultimately disappeared (i.e. there was no longer much to be gained with
+  the Performance mode in most circumstances) and ScientiaMobile elected to
+  "remove" this option to simplify configuration and go in the direction of
+  uniform WURFL API behavior in different contexts.
+
+  For this reason, since HAProxy versions greater than 1.7.7, in order to build
+  WURFL Device Detection support, Scientiamobile InFuze C API version 1.9 or
+  greater is required.
+  ******************************************************************************
 
 wurfl-cache-size <U>[,<D>]
   Sets the WURFL caching strategy. Here <U> is the Useragent cache size, and
diff --git a/examples/wurfl-example.cfg b/examples/wurfl-example.cfg
old mode 100644
new mode 100755
index ad651a8..50e4efc
--- a/examples/wurfl-example.cfg
+++ b/examples/wurfl-example.cfg
@@ -7,15 +7,11 @@
 global
 
 	# The WURFL data file
-	wurfl-data-file		/usr/share/wurfl/wurfl-eval.xml
+	wurfl-data-file		/usr/share/wurfl/wurfl.zip
 
 	# 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
diff --git a/src/wurfl.c b/src/wurfl.c
index 18723a6..20fdc84 100644
--- a/src/wurfl.c
+++ b/src/wurfl.c
@@ -50,11 +50,13 @@ typedef struct {
 	struct ebmb_node nd;
 } wurfl_data_t;
 
-static const char HA_WURFL_MODULE_VERSION[] = "1.0";
+static const char HA_WURFL_MODULE_VERSION[] = "1.1";
 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_TARGET_FASTDESKTOPBROWSER[] = "fast_desktop_browser_match";
+static const char HA_WURFL_TARGET_DEFAULT[] = "default";
 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";
@@ -89,9 +91,9 @@ static const struct {
 	{"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_root_id", ha_wurfl_get_wurfl_root_id},
 	{"wurfl_useragent", ha_wurfl_get_wurfl_useragent},
 	{"wurfl_useragent_priority", ha_wurfl_get_wurfl_useragent_priority },
-	{"wurfl_root_id", ha_wurfl_get_wurfl_root_id},
 };
 static const int HA_WURFL_PROPERTIES_NBR = 10;
 
@@ -159,7 +161,17 @@ static int ha_wurfl_cfg_engine_mode(char **args, int section_type, struct proxy
 		return 0;
 	}
 
-	memprintf(err, "WURFL: %s valid values are %s or %s.\n", args[0], HA_WURFL_TARGET_PERFORMANCE, HA_WURFL_TARGET_ACCURACY);
+	if (!strcmp(args[1],HA_WURFL_TARGET_DEFAULT)) {
+		global.wurfl.engine_mode = WURFL_ENGINE_TARGET_DEFAULT;
+		return 0;
+	}
+
+	if (!strcmp(args[1],HA_WURFL_TARGET_FASTDESKTOPBROWSER)) {
+		global.wurfl.engine_mode = WURFL_ENGINE_TARGET_FAST_DESKTOP_BROWSER_MATCH;
+		return 0;
+	}
+
+	memprintf(err, "WURFL: %s valid values are %s or %s.\n", args[0], HA_WURFL_TARGET_DEFAULT, HA_WURFL_TARGET_FASTDESKTOPBROWSER);
 	return -1;
 }
 
@@ -447,7 +459,7 @@ int ha_wurfl_init(void)
 
 	}
 
-	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) );
+	send_log(NULL, LOG_NOTICE, "WURFL: Engine target set to [%s]\n", wurfl_get_engine_target_as_string(global.wurfl.handle));
 
 	// setting ua priority if specified in cfg, otherwise let engine choose
 	if (global.wurfl.useragent_priority != -1) {
@@ -520,8 +532,6 @@ static int ha_wurfl_get_all(const struct arg *args, struct sample *smp, const ch
 	chunk_reset(temp);
 
 	list_for_each_entry(wi, &global.wurfl.information_list, list) {
-		chunk_appendf(temp, "%c", global.wurfl.information_list_separator);
-
 		switch(wi->data.type) {
 		case HA_WURFL_DATA_TYPE_UNKNOWN :
 			ha_wurfl_log("WURFL: %s is of an %s type\n", wi->data.name, HA_WURFL_DATA_TYPE_UNKNOWN_STRING);
@@ -556,6 +566,15 @@ static int ha_wurfl_get_all(const struct arg *args, struct sample *smp, const ch
 			break;
 		}
 
+		// append separator
+		chunk_appendf(temp, "%c", global.wurfl.information_list_separator);
+
+	}
+
+	// remove trailing separator if needed
+	if (temp->len) {
+		--temp->len;
+		temp->str[temp->len] = '\0';
 	}
 
 	wurfl_device_destroy(dHandle);
@@ -586,7 +605,6 @@ static int ha_wurfl_get(const struct arg *args, struct sample *smp, const char *
 	chunk_reset(temp);
 
 	while (args[i].data.str.str) {
-		chunk_appendf(temp, "%c", global.wurfl.information_list_separator);
 		node = ebst_lookup(&global.wurfl.btree, args[i].data.str.str);
 		wn = container_of(node, wurfl_data_t, nd);
 
@@ -630,10 +648,19 @@ static int ha_wurfl_get(const struct arg *args, struct sample *smp, const char *
 			ha_wurfl_log("WURFL: %s not in wurfl-information-list \n", args[i].data.str.str);
 		}
 
+		// append separator
+		chunk_appendf(temp, "%c", global.wurfl.information_list_separator);
 		i++;
 	}
 
 	wurfl_device_destroy(dHandle);
+
+	// remove trailing separator if needed
+	if (temp->len) {
+		--temp->len;
+		temp->str[temp->len] = '\0';
+	}
+
 	smp->data.u.str.str = temp->str;
 	smp->data.u.str.len = temp->len;
 	return 1;
-- 
2.7.4

Reply via email to