New XML config options

Removed unnecessary config options and added new ones for configuring
XML output.
This commit is contained in:
Zaid Abdulla committed 2017-01-03 03:18:00 -08:00
1 parent b11ae252bf
commit 7620628e52
2 files changed
+25 -17

No files matched your search

+18 -9
View File
@@ -81,15 +81,24 @@ NAMESPACES = {
}
}
# Generate Libxmljs options
LIBXMLJS_OPTIONS = {}
for k, v of config.allConfig
if k.lastIndexOf('XML_PARSE_', 0) == 0
LIBXMLJS_OPTIONS[k] = v
LIBXMLJS_PARSE_OPTIONS = {
'nocdata' : true,
'noent' : true,
'recover' : config.get('XML_RECOVER'),
'ignore_enc' : config.get('XML_IGNORE_ENC')
}
LIBXMLJS_SAVE_OPTIONS = {
'format' : config.get('XML_FORMAT'),
'declaration' : not config.get('XML_NO_DECL'),
'selfCloseEmpty' : not config.get('XML_NO_EMPTY')
}
XML_IGNORE_NAMESPACE = config.get('XML_IGNORE_NAMESPACE')
# Workaround for devices that don't use correct namespace declarations or prefixes
if config.get('IGNORE_XML_NAMESPACES')
if XML_IGNORE_NAMESPACE
libxmljs.Element.prototype.__find = libxmljs.Element.prototype.find
libxmljs.Element.prototype.find = (xpath, namespaces) ->
# Modify xpath queries to work regardless of element's namespace
@@ -319,7 +328,7 @@ exports.request = (httpRequest, cwmpVersion) ->
data = httpRequest.getBody()
if data.length > 0
xml = libxmljs.parseXml(data, LIBXMLJS_OPTIONS)
xml = libxmljs.parseXml(data, LIBXMLJS_PARSE_OPTIONS)
if not cwmpRequest.cwmpVersion?
# cwmpVersion not passed, thus it's an inform request
@@ -346,7 +355,7 @@ exports.request = (httpRequest, cwmpVersion) ->
cwmpRequest.id = try xml.get('/soap-env:Envelope/soap-env:Header/cwmp:ID', NAMESPACES[cwmpRequest.cwmpVersion]).text() catch then null
if methodElement? and not (config.get('IGNORE_XML_NAMESPACES') and methodElement.name() is 'Fault')
if methodElement? and not (XML_IGNORE_NAMESPACE and methodElement.name() is 'Fault')
switch methodElement.name()
when 'Inform'
cwmpRequest.methodRequest = acsInform(methodElement)
@@ -450,6 +459,6 @@ exports.response = (cwmpResponse) ->
if env?
headers['Content-Type'] = 'text/xml; charset="utf-8"'
return {code: 200, headers: headers, data: new Buffer(env.doc().toString(false))}
return {code: 200, headers: headers, data: new Buffer(env.doc().toString(LIBXMLJS_SAVE_OPTIONS))}
else
return {code: 204, headers: headers, data: new Buffer(0)}