Added config option (IGNORE_XML_NAMESPACES) to make XML traversal using element local names only as a workaroud for XML namespace issues in some devices. Fixes #7.

This commit is contained in:
Zaid Abdulla committed 2014-05-10 16:22:40 +03:00
1 parent dfb2e624d9
commit de0774edeb
2 files changed
+12

No files matched your search

+1
View File
@@ -18,6 +18,7 @@ exports.LOG_INFORMS = false
exports.DEBUG_DEVICES = {} # {'202BC1-BM632w-8KA8WA1151100043' : true}
exports.DEVICE_ONLINE_THRESHOLD = 4000
exports.RETRY_DELAY = 300
exports.IGNORE_XML_NAMESPACES = false # Traverse XML using element's local name only
exports.MONGODB_OPTIONS = {
db : {
+11
View File
@@ -1,3 +1,4 @@
config = require './config'
libxmljs = require 'libxmljs'
SERVER_NAME = "GenieACS/#{require('../package.json').version}"
@@ -41,6 +42,16 @@ NAMESPACES = {
}
# Workaround for devices that don't use correct namespace declarations or prefixes
if config.IGNORE_XML_NAMESPACES
libxmljs.Element.prototype.__find = libxmljs.Element.prototype.find
libxmljs.Element.prototype.find = (xpath, namespaces) ->
# Modify xpath queries to work regardless of element's namespace
p = xpath.replace(/([^\/:]+:)?([^\/]+)(\/|$)/g, '$2$3') \
.replace(/([a-zA-Z0-9_-]+)([^\/]*)(\/|$)/g, "*[local-name()='$1']$2$3")
libxmljs.Element.prototype.__find.call(this, p, namespaces)
# Separation by comma is important as some devices don't comform to standard
COOKIE_REGEX = /\s*([a-zA-Z0-9\-_]+?)\s*=\s*"?([a-zA-Z0-9\-_]*?)"?\s*(,|;|$)/g