Skip to content
This repository has been archived by the owner on Nov 15, 2020. It is now read-only.

Commit

Permalink
Merge pull request #54 from elricho/master
Browse files Browse the repository at this point in the history
Bugfix for test_detectionOnEmptyArchiveStillNotSolved() & cleanups.
  • Loading branch information
elricho authored Dec 22, 2016
2 parents 3c95459 + 4d91bc7 commit 65aa18e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
25 changes: 12 additions & 13 deletions src/HDBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,34 +534,33 @@ function hasBiKeys($headers) {
* The heart of the detection process
*
* @param string $header The type of header we're matching against - user-agent type headers use a sieve matching, all others are hash matching.
* @param string $newvalue The http header's value (could be a user-agent or some other x- header value)
* @param string $treetag The branch name eg : user-agent0, user-agent1, user-agentplatform, user-agentbrowser
* @param string $value The http header's sanitised value (could be a user-agent or some other x- header value)
* @param string $subtree The 0 or 1 for devices (isGeneric), category name for extras ('platform', 'browser', 'app')
* @param string $actualHeader Unused (optimized away)
* @param string $category : One of 'device', 'platform', 'browser' or 'app'
* @return int node (which is an id) on success, false otherwise
*/
function getMatch($header, $value, $subtree="0", $actualHeader='', $class='device') {
function getMatch($header, $value, $subtree="0", $actualHeader='', $category='device') {
$f = 0;
$r = 0;
if ($class == 'device') {
$value = $this->cleanStr($value);
if ($category == 'device') {
//$value = $this->cleanStr($value);
$treetag = $header.$subtree;
} else {
$value = $this->extraCleanStr($value);
//$value = $this->extraCleanStr($value);
$treetag = $header.$subtree;
}

if ($value == "") {
// Fetch branch before validating params to confirm local files are installed correctly.
$branch = $this->getBranch($treetag);
if (empty($branch)) {
return false;
}

if (strlen($value) < 4) {
return false;
}

$branch = $this->getBranch($treetag);
if (empty($branch)) {
return false;
}

if ($header == 'user-agent') {
// Sieve matching strategy
foreach((array) $branch as $order => $filters) {
Expand All @@ -571,7 +570,7 @@ function getMatch($header, $value, $subtree="0", $actualHeader='', $class='devic
foreach((array) $matches as $match => $node) {
++$r;
if (strpos($value, (string) $match) !== false) {
$this->detectedRuleKey[$class] = $this->cleanStr(@$header).':'.$this->cleanStr(@$filter).':'.$this->cleanStr(@$match);
$this->detectedRuleKey[$category] = $this->cleanStr(@$header).':'.$this->cleanStr(@$filter).':'.$this->cleanStr(@$match);
return $node;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/HDDevice.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ function v4MatchBIHelper($buildInfo, $category='device') {
if (empty($confBIKeys) || empty($buildInfo))
return null;

$hints = array();
foreach($confBIKeys as $platform => $set) {
foreach($set as $tuple) {
$checking = true;
Expand All @@ -526,8 +525,8 @@ function v4MatchBIHelper($buildInfo, $category='device') {
}
if ($checking) {
$value = trim($value, "| \t\n\r\0\x0B");
$hints[] = $value;
$subtree = ($category == 'device') ? DETECTIONV4_STANDARD : $category;
$value = ($category == 'device') ? $value = $this->cleanStr($value) : $this->extraCleanStr($value);
$_id = $this->getMatch('buildinfo', $value, $subtree, 'buildinfo', $category);
if (! empty($_id)) {
return ($category == 'device') ? $this->findById($_id) : $this->Extra->findById($_id);
Expand All @@ -542,6 +541,7 @@ function v4MatchBIHelper($buildInfo, $category='device') {
$try = array("generic|{$platform}", "{$platform}|generic");
foreach($try as $value) {
$subtree = ($category == 'device') ? DETECTIONV4_GENERIC : $category;
$value = ($category == 'device') ? $value = $this->cleanStr($value) : $this->extraCleanStr($value);
$_id = $this->getMatch('buildinfo', $value, $subtree, 'buildinfo', $category);
if (! empty($_id)) {
return ($category == 'device') ? $this->findById($_id) : $this->Extra->findById($_id);
Expand Down

0 comments on commit 65aa18e

Please sign in to comment.