[Pkg-mozext-commits] [wot] 83/226: Added parsing of categories and blacklists from API response
David Prévot
taffit at moszumanska.debian.org
Fri May 1 00:35:37 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository wot.
commit c73573a4e9621ca967723bb12a9b53feede0107e
Author: Sergey Andryukhin <sorgoz at yandex.com>
Date: Mon Jul 22 15:06:47 2013 +0300
Added parsing of categories and blacklists from API response
---
content/cache.js | 282 ++++++++++++++++++++++++++++++++++--------------------
content/config.js | 38 +++++---
2 files changed, 206 insertions(+), 114 deletions(-)
diff --git a/content/cache.js b/content/cache.js
index bb57e90..00e037d 100644
--- a/content/cache.js
+++ b/content/cache.js
@@ -1,6 +1,6 @@
/*
cache.js
- Copyright © 2005-2011 WOT Services Oy <info at mywot.com>
+ Copyright © 2005 - 2013 WOT Services Oy <info at mywot.com>
This file is part of WOT.
@@ -29,7 +29,7 @@ var wot_hashtable =
this.bag = Components.classes["@mozilla.org/hash-property-bag;1"].
getService(Components.interfaces.nsIWritablePropertyBag);
} catch (e) {
- dump("wot_hashtable.init: failed with: " + e + "\n");
+ wdump("wot_hashtable.init: failed with: " + e);
}
},
@@ -169,7 +169,8 @@ var wot_cache =
return;
}
- wot_hashtable.set(pn, value);
+// wdump(name + ", " + property + ", " + value);
+ wot_hashtable.set(pn, value);
},
remove: function(name, property)
@@ -254,8 +255,12 @@ var wot_cache =
this.set(name, "inprogress", false);
this.set(name, "status", WOT_QUERY_RETRY);
this.set(name, "time", Date.now());
+ this.set(name, "normalized", "");
+ this.set(name, "categories", 0);
+ this.set(name, "blacklists", 0);
- for (var i = 0; i < WOT_APPLICATIONS; ++i) {
+ // FIXME: don't create redundant apps. Use only 0 and 4
+ for (var i = 0; i < WOT_APPLICATIONS; ++i) {
this.set(name, "reputation_" + i, -1);
this.set(name, "confidence_" + i, -1);
@@ -284,6 +289,9 @@ var wot_cache =
this.remove(name, "inprogress");
this.remove(name, "status");
this.remove(name, "time");
+ this.remove(name, "normalized");
+ this.remove(name, "categories");
+ this.remove(name, "blacklists");
for (var i = 0; i < WOT_APPLICATIONS; ++i) {
this.remove(name, "reputation_" + i);
@@ -300,8 +308,7 @@ var wot_cache =
add_target: function(nonce, target, islink)
{
try {
- var index = target.attributes.getNamedItem(
- WOT_SERVICE_XML_QUERY_TARGET_INDEX);
+ var index = target.attributes.getNamedItem(WOT_SERVICE_XML_QUERY_TARGET_INDEX);
if (index && index.value != null) {
nonce += "-" + index.value;
@@ -310,7 +317,7 @@ var wot_cache =
var name = this.resolve_nonce(nonce);
if (!name) {
- dump("wot_cache.add_target: unknown nonce: " + nonce + "\n");
+ wdump("wot_cache.add_target: unknown nonce: " + nonce);
return;
}
@@ -320,13 +327,14 @@ var wot_cache =
this.create(name);
}
+ var normalized_attr = target.attributes.getNamedItem(WOT_SERVICE_XML_QUERY_TARGET_NORMAL);
+ this.set(name, "normalized", normalized_attr ? normalized_attr.value : "");
+
var child = target.firstChild;
- var a, r, c, t, i, l, x;
if (islink) {
if (this.get(name, "status") == WOT_QUERY_OK) {
- dump("wot_cache.add_target: not overwriting on link for " +
- name + "\n");
+ wdump("wot_cache.add_target: not overwriting on link for " + name);
return;
}
this.set(name, "status", WOT_QUERY_LINK);
@@ -334,116 +342,184 @@ var wot_cache =
this.set(name, "status", WOT_QUERY_OK);
}
+ var categories_number = 0,
+ blacklists_number = 0;
+
while (child) {
- if (child.localName == WOT_SERVICE_XML_QUERY_APPLICATION) {
- a = child.attributes.getNamedItem(
- WOT_SERVICE_XML_QUERY_APPLICATION_NAME);
- r = child.attributes.getNamedItem(
- WOT_SERVICE_XML_QUERY_APPLICATION_R);
- c = child.attributes.getNamedItem(
- WOT_SERVICE_XML_QUERY_APPLICATION_C);
- i = child.attributes.getNamedItem(
- WOT_SERVICE_XML_QUERY_APPLICATION_I);
- l = child.attributes.getNamedItem(
- WOT_SERVICE_XML_QUERY_APPLICATION_L);
- x = child.attributes.getNamedItem(
- WOT_SERVICE_XML_QUERY_APPLICATION_E);
- t = child.attributes.getNamedItem(
- WOT_SERVICE_XML_QUERY_APPLICATION_T);
-
- if (a && a.value) {
- if (r && r.value && c && c.value) {
- this.set(name, "reputation_" + a.value,
- Number(r.value));
- this.set(name, "confidence_" + a.value,
- Number(c.value));
- }
- if (i && i.value) {
- this.set(name, "inherited_" + a.value,
- Number(i.value));
- }
- if (l && l.value) {
- this.set(name, "lowered_" + a.value,
- Number(l.value));
- }
- if (x && x.value) {
- this.set(name, "excluded_" + a.value,
- Number(x.value));
- }
- if (t && t.value) {
- this.set(name, "testimony_" + a.value,
- Number(t.value));
- }
- } else {
- dump("wot_cache.add_target: application name missing\n");
- }
+ switch (child.localName) {
+ case WOT_SERVICE_XML_QUERY_APPLICATION:
+ this.add_application(name, child);
+ break;
+
+ case WOT_SERVICE_XML_QUERY_QUESTION:
+ // just skip it. Questions are processed later (out of the cycle)
+ break;
+
+ case WOT_SERVICE_XML_QUERY_CATEGORY:
+ categories_number += this.add_category(name, child, categories_number);
+ break;
+
+ case WOT_SERVICE_XML_QUERY_BLACKLIST:
+ blacklists_number += this.add_blacklist(name, child, blacklists_number);
+ break;
+
+ default:
+ // unknown node found inside TARGET tag
+ wdump("Unknown tag " + child.localName + " inside the TARGET");
}
+ child = child.nextSibling;
+ }
- // process Feedback Question
- this.add_question(name, child);
+ this.set(name, "categories", categories_number);
+ this.set(name, "blacklists", blacklists_number);
- child = child.nextSibling;
- }
- } catch (e) {
- dump("wot_cache.add_target: failed with " + e + "\n");
+ // process GFeedbackLoop Question
+ this.add_question(name, target.firstChild);
+
+ } catch (e) {
+ wdump("ERROR: wot_cache.add_target: failed with " + e);
}
},
+ add_application: function (hostname, app_node) {
+ try {
+ var a, r, c, t, i, l, x;
+ a = app_node.attributes.getNamedItem(WOT_SERVICE_XML_QUERY_APPLICATION_NAME);
+ r = app_node.attributes.getNamedItem(WOT_SERVICE_XML_QUERY_APPLICATION_R);
+ c = app_node.attributes.getNamedItem(WOT_SERVICE_XML_QUERY_APPLICATION_C);
+ i = app_node.attributes.getNamedItem(WOT_SERVICE_XML_QUERY_APPLICATION_I);
+ l = app_node.attributes.getNamedItem(WOT_SERVICE_XML_QUERY_APPLICATION_L);
+ x = app_node.attributes.getNamedItem(WOT_SERVICE_XML_QUERY_APPLICATION_E);
+ t = app_node.attributes.getNamedItem(WOT_SERVICE_XML_QUERY_APPLICATION_T);
+
+ if (a && a.value) {
+ if (r && r.value !== null && c && c.value !== null) {
+ this.set(hostname, "reputation_" + a.value, Number(r.value));
+ this.set(hostname, "confidence_" + a.value, Number(c.value));
+ }
+ if (i && i.value) {
+ this.set(hostname, "inherited_" + a.value, Number(i.value));
+ }
+ if (l && l.value) {
+ this.set(hostname, "lowered_" + a.value, Number(l.value));
+ }
+ if (x && x.value) {
+ this.set(hostname, "excluded_" + a.value, Number(x.value));
+ }
+ if (t && t.value) {
+ this.set(hostname, "testimony_" + a.value, Number(t.value));
+ }
+ }
+ } catch (e) {
+ wdump("ERROR: wot_cache.add_application: failed with " + e);
+ }
+
+ },
+
+ process_attributes: function (attrs_list, hostname, node, slot_name, slot_index) {
+ for (var i = 0; i < attrs_list.length; i++) {
+ var attr = attrs_list[i],
+ attr_node = node.attributes.getNamedItem(attr),
+ val = null;
+ if (attr_node && attr_node.value !== null) {
+ if (isNaN(attr_node.value)) {
+ val = String(attr_node.value);
+ } else {
+ val = Number(attr_node.value);
+ }
+ this.set(hostname, slot_name + "_" + slot_index + "_" + attr, val);
+ }
+ }
+ },
+
+ add_category: function (hostname, node, index) {
+ try {
+ var attrs_list = [
+ WOT_SERVICE_XML_QUERY_CATEGORY_NAME,
+ WOT_SERVICE_XML_QUERY_CATEGORY_GROUP,
+ WOT_SERVICE_XML_QUERY_CATEGORY_C,
+ WOT_SERVICE_XML_QUERY_CATEGORY_I,
+ WOT_SERVICE_XML_QUERY_CATEGORY_VOTE
+ ];
+
+ this.process_attributes(attrs_list, hostname, node, "category", index);
+
+ } catch (e) {
+ wdump("ERROR: wot_cache.add_category: failed with " + e);
+ return 0;
+ }
+
+ return 1;
+ },
+
+ add_blacklist: function (hostname, node, index) {
+ try {
+ var attrs_list = [
+ WOT_SERVICE_XML_QUERY_BLACKLIST_TYPE,
+ WOT_SERVICE_XML_QUERY_BLACKLIST_TIME
+ ];
+
+ this.process_attributes(attrs_list, hostname, node, "blacklist", index);
+
+ } catch (e) {
+ wdump("ERROR: wot_cache.add_category: failed with " + e);
+ return 0;
+ }
+
+ return 1;
+ },
+
add_question: function (hostname, target_node)
{
- if (target_node.localName == WOT_SERVICE_XML_QUERY_QUESTION) {
-
- try {
- var doc = target_node.ownerDocument;
- var id_node = doc.getElementsByTagName(WOT_SERVICE_XML_QUERY_QUESTION_ID).item(0),
- text_node = doc.getElementsByTagName(WOT_SERVICE_XML_QUERY_QUESTION_TEXT).item(0),
- dismiss_node = doc.getElementsByTagName(WOT_SERVICE_XML_QUERY_DISMISS_TEXT).item(0),
- choices_nodes = doc.getElementsByTagName(WOT_SERVICE_XML_QUERY_CHOICE_TEXT);
-
- if (id_node && id_node.firstChild && text_node && text_node.firstChild) {
- var id = String(id_node.firstChild.nodeValue),
- text = String(text_node.firstChild.nodeValue),
- dismiss_text = "";
-
- if (dismiss_node && dismiss_node.firstChild) {
- dismiss_text = String(dismiss_node.firstChild.nodeValue);
- }
+ try {
+ var doc = target_node.ownerDocument;
+ var id_node = doc.getElementsByTagName(WOT_SERVICE_XML_QUERY_QUESTION_ID).item(0),
+ text_node = doc.getElementsByTagName(WOT_SERVICE_XML_QUERY_QUESTION_TEXT).item(0),
+ dismiss_node = doc.getElementsByTagName(WOT_SERVICE_XML_QUERY_DISMISS_TEXT).item(0),
+ choices_nodes = doc.getElementsByTagName(WOT_SERVICE_XML_QUERY_CHOICE_TEXT);
+ if (id_node && id_node.firstChild && text_node && text_node.firstChild) {
+ var id = String(id_node.firstChild.nodeValue),
+ text = String(text_node.firstChild.nodeValue),
+ dismiss_text = "";
- if (id && text) {
+ if (dismiss_node && dismiss_node.firstChild) {
+ dismiss_text = String(dismiss_node.firstChild.nodeValue);
+ }
- var choice = choices_nodes.item(0),
- choices = [];
+ if (id && text) {
- while(choice) {
+ var choice = choices_nodes.item(0),
+ choices = [];
- var choice_text = choice.firstChild.nodeValue;
- var choice_value = choice.attributes.getNamedItem("value").value;
+ while(choice) {
- if (choice_text && choice_value) {
- choices.push({ value: choice_value, text: choice_text });
- }
+ var choice_text = choice.firstChild.nodeValue;
+ var choice_value = choice.attributes.getNamedItem("value").value;
- choice = choice.nextSibling;
- }
+ if (choice_text && choice_value) {
+ choices.push({ value: choice_value, text: choice_text });
+ }
- // now store question data to global WOT cache (if there are any choices)
- if (choices.length) {
- this.set(hostname, "question_id", id);
- this.set(hostname, "question_text", text);
- this.set(hostname, "dismiss_text", dismiss_text);
- this.set(hostname, "choices_number", Number(choices.length));
- for(var j=0; j < choices.length; j++) {
- this.set(hostname, "choice_value_" + String(j), choices[j]['value']);
- this.set(hostname, "choice_text_" + String(j), choices[j]['text']);
- }
- }
- }
- }
- } catch(e) {
- dump("Failed to extract Question data from XML\n");
- }
- }
+ choice = choice.nextSibling;
+ }
+
+ // now store question data to global WOT cache (if there are any choices)
+ if (choices.length) {
+ this.set(hostname, "question_id", id);
+ this.set(hostname, "question_text", text);
+ this.set(hostname, "dismiss_text", dismiss_text);
+ this.set(hostname, "choices_number", Number(choices.length));
+ for(var j=0; j < choices.length; j++) {
+ this.set(hostname, "choice_value_" + String(j), choices[j]['value']);
+ this.set(hostname, "choice_text_" + String(j), choices[j]['text']);
+ }
+ }
+ }
+ }
+ } catch(e) {
+ wdump("Failed to extract Question data from XML");
+ }
},
add_query: function(queries, targets, islink)
diff --git a/content/config.js b/content/config.js
index 58a9f70..85e0e01 100644
--- a/content/config.js
+++ b/content/config.js
@@ -19,7 +19,7 @@
*/
const WOT_PLATFORM = "firefox";
-const WOT_VERSION = "20130515";
+const WOT_VERSION = "20130722";
/*
* Constants
@@ -52,7 +52,7 @@ const WOT_TESTIMONY_ROUND = 1; /* Testimony steps */
const WOT_MIN_COMMENT_DIFF = 35;
/* Applications */
-const WOT_APPLICATIONS = 6;
+const WOT_APPLICATIONS = 5;
/* Search */
const WOT_SAFESEARCH_OSD_URL = "https://search.mywot.com/osd/en-US.xml";
@@ -78,6 +78,7 @@ const WOT_SERVICE_XML_QUERY = "query";
const WOT_SERVICE_XML_QUERY_NONCE = "nonce";
const WOT_SERVICE_XML_QUERY_TARGET = "target";
const WOT_SERVICE_XML_QUERY_TARGET_INDEX = "index";
+const WOT_SERVICE_XML_QUERY_TARGET_NORMAL = "normalized";
const WOT_SERVICE_XML_QUERY_APPLICATION = "application";
const WOT_SERVICE_XML_QUERY_APPLICATION_NAME = "name";
const WOT_SERVICE_XML_QUERY_APPLICATION_R = "r";
@@ -86,6 +87,15 @@ const WOT_SERVICE_XML_QUERY_APPLICATION_I = "inherited";
const WOT_SERVICE_XML_QUERY_APPLICATION_L = "lowered";
const WOT_SERVICE_XML_QUERY_APPLICATION_E = "excluded";
const WOT_SERVICE_XML_QUERY_APPLICATION_T = "t";
+const WOT_SERVICE_XML_QUERY_CATEGORY = "category";
+const WOT_SERVICE_XML_QUERY_CATEGORY_NAME = "name";
+const WOT_SERVICE_XML_QUERY_CATEGORY_GROUP = "group";
+const WOT_SERVICE_XML_QUERY_CATEGORY_C = "c";
+const WOT_SERVICE_XML_QUERY_CATEGORY_I = "inherited";
+const WOT_SERVICE_XML_QUERY_CATEGORY_VOTE = "vote";
+const WOT_SERVICE_XML_QUERY_BLACKLIST = "bl";
+const WOT_SERVICE_XML_QUERY_BLACKLIST_TYPE = "type";
+const WOT_SERVICE_XML_QUERY_BLACKLIST_TIME = "time";
const WOT_SERVICE_XML_QUERY_QUESTION = "question";
const WOT_SERVICE_XML_QUERY_QUESTION_ID = "questionId";
const WOT_SERVICE_XML_QUERY_QUESTION_TEXT = "questionText";
@@ -129,7 +139,8 @@ const WOT_SERVICE_XML_UPDATE_SHARED_DOMAINS = "domains";
const WOT_SERVICE_XML_UPDATE_SHARED_LEVEL = "level";
/* My */
-const WOT_MY_URL = "http://www.mywot.com/";
+//const WOT_MY_URL = "http://www.mywot.com/";
+const WOT_MY_URL = "http://beta.mywot.com/";
const WOT_MY_COOKIE_DOMAIN = ".mywot.com";
const WOT_MY_TRIGGER = /^(.+\.)?mywot.com$/;
const WOT_MY_SESSION_LENGTH = 86340 * 1000; /* < 1d */
@@ -184,8 +195,8 @@ const WOT_BLOCK_BLOCKED = "chrome://wot/locale/blocked.html";
const WOT_PREF_PATH = "settings/";
const WOT_PREF_FORWARD_TAB_MATCH = 7;
-const WOT_PREF_FORWARD = /^http(s)?\:\/\/(www\.)?mywot\.com\/([^\/]{2}(-[^\/]+)?\/)?(settings|update)(\/([^\/]+))?\/?$/;
-const WOT_PREF_TRIGGER = /^http(s)?\:\/\/(www\.)?mywot\.com\/([^\/]{2}(-[^\/]+)?\/)?(settings|update)\/.+/;
+const WOT_PREF_FORWARD = /^http(s)?\:\/\/(www\.|beta\.)?mywot\.com\/([^\/]{2}(-[^\/]+)?\/)?(settings|update)(\/([^\/]+))?\/?$/;
+const WOT_PREF_TRIGGER = /^http(s)?\:\/\/(www\.|beta\.)?mywot\.com\/([^\/]{2}(-[^\/]+)?\/)?(settings|update)\/.+/;
const WOT_PREF = "weboftrust.";
@@ -222,11 +233,11 @@ const wot_prefs_bool = [
[ "search_ignore_4", true ],
[ "search_scripts", true ],
[ "show_application_0", true ],
- [ "show_application_1", true ],
- [ "show_application_2", true ],
+ [ "show_application_1", false ],
+ [ "show_application_2", false ],
[ "show_application_3", false ],
[ "show_application_4", true ],
- [ "show_application_5", false ],
+// [ "show_application_5", false ],
[ "show_search_popup", true ],
[ "use_search_level", false ],
[ "ninja_donuts", false ],
@@ -235,7 +246,7 @@ const wot_prefs_bool = [
[ "warning_unknown_2", false ],
[ "warning_unknown_3", false ],
[ "warning_unknown_4", false ],
- [ "warning_unknown_5", false ],
+// [ "warning_unknown_5", false ],
[ "feedback_enabled", true ],
[ "feedback_optedout", false ]
];
@@ -269,13 +280,13 @@ const wot_prefs_int = [
[ "warning_level_2", WOT_DEFAULT_WARNING_LEVEL ],
[ "warning_level_3", WOT_DEFAULT_WARNING_LEVEL ],
[ "warning_level_4", 0 ],
- [ "warning_level_5", WOT_DEFAULT_WARNING_LEVEL ],
+// [ "warning_level_5", WOT_DEFAULT_WARNING_LEVEL ],
[ "warning_type_0", WOT_WARNING_DOM ],
[ "warning_type_1", WOT_WARNING_DOM ],
[ "warning_type_2", WOT_WARNING_DOM ],
[ "warning_type_3", WOT_WARNING_NONE ],
[ "warning_type_4", WOT_WARNING_NONE ],
- [ "warning_type_5", WOT_WARNING_NONE ]
+// [ "warning_type_5", WOT_WARNING_NONE ]
];
/* Search rules */
@@ -323,3 +334,8 @@ const WOT_URL_BTN = "button";
const WOT_URL_CTX = "contextmenu";
var wot_modules = [];
+
+// Dirty hack. This function should be moved to other place
+function wdump (str) {
+ dump(str + "\n");
+}
\ No newline at end of file
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/wot.git
More information about the Pkg-mozext-commits
mailing list