New XML config options
Removed unnecessary config options and added new ones for configuring XML output.
This commit is contained in:
1 parent
b11ae252bf
commit
7620628e52
2 files changed
+25
-17
No files matched your search
+7
-8
@@ -47,20 +47,19 @@ options = {
|
|||||||
LOG_INFORMS : {type : 'bool', default : true},
|
LOG_INFORMS : {type : 'bool', default : true},
|
||||||
DEBUG : {type : 'bool', default : false},
|
DEBUG : {type : 'bool', default : false},
|
||||||
RETRY_DELAY : {type : 'int', default : 300},
|
RETRY_DELAY : {type : 'int', default : 300},
|
||||||
IGNORE_XML_NAMESPACES : {type : 'bool', default : false},
|
|
||||||
SESSION_TIMEOUT : {type : 'int', default : 30},
|
SESSION_TIMEOUT : {type : 'int', default : 30},
|
||||||
GET_PARAMETER_NAMES_DEPTH_THRESHOLD : {type : 'int', default : 0},
|
GET_PARAMETER_NAMES_DEPTH_THRESHOLD : {type : 'int', default : 0},
|
||||||
TASK_PARAMETERS_BATCH_SIZE : {type : 'int', default : 32},
|
TASK_PARAMETERS_BATCH_SIZE : {type : 'int', default : 32},
|
||||||
MAX_DEPTH : {type: 'int', default : 16},
|
MAX_DEPTH : {type: 'int', default : 16},
|
||||||
COOKIES_PATH : {type : 'string'},
|
COOKIES_PATH : {type : 'string'},
|
||||||
|
|
||||||
# Libxml related configuration
|
# XML configuration
|
||||||
XML_PARSE_RECOVER : {type : 'bool'},
|
XML_RECOVER : {type : 'bool', default : false},
|
||||||
XML_PARSE_NOENT : {type : 'bool'},
|
XML_IGNORE_ENC : {type : 'bool', default : false},
|
||||||
XML_PARSE_NOBLANKS : {type : 'bool'},
|
XML_FORMAT : {type : 'bool', default : false},
|
||||||
XML_PARSE_NSCLEAN : {type : 'bool'},
|
XML_NO_DECL : {type : 'bool', default : false},
|
||||||
XML_PARSE_NOCDATA : {type : 'bool'},
|
XML_NO_EMPTY : {type : 'bool', default : false},
|
||||||
XML_PARSE_IGNORE_ENC : {type : 'bool'},
|
XML_IGNORE_NAMESPACE : {type : 'bool', default : false},
|
||||||
|
|
||||||
# Should probably never be changed
|
# Should probably never be changed
|
||||||
PRESETS_TIME_PADDING : {type : 'int', default : 1},
|
PRESETS_TIME_PADDING : {type : 'int', default : 1},
|
||||||
|
|||||||
+18
-9
@@ -81,15 +81,24 @@ NAMESPACES = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Generate Libxmljs options
|
LIBXMLJS_PARSE_OPTIONS = {
|
||||||
LIBXMLJS_OPTIONS = {}
|
'nocdata' : true,
|
||||||
for k, v of config.allConfig
|
'noent' : true,
|
||||||
if k.lastIndexOf('XML_PARSE_', 0) == 0
|
'recover' : config.get('XML_RECOVER'),
|
||||||
LIBXMLJS_OPTIONS[k] = v
|
'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
|
# 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 = libxmljs.Element.prototype.find
|
||||||
libxmljs.Element.prototype.find = (xpath, namespaces) ->
|
libxmljs.Element.prototype.find = (xpath, namespaces) ->
|
||||||
# Modify xpath queries to work regardless of element's namespace
|
# Modify xpath queries to work regardless of element's namespace
|
||||||
@@ -319,7 +328,7 @@ exports.request = (httpRequest, cwmpVersion) ->
|
|||||||
data = httpRequest.getBody()
|
data = httpRequest.getBody()
|
||||||
|
|
||||||
if data.length > 0
|
if data.length > 0
|
||||||
xml = libxmljs.parseXml(data, LIBXMLJS_OPTIONS)
|
xml = libxmljs.parseXml(data, LIBXMLJS_PARSE_OPTIONS)
|
||||||
|
|
||||||
if not cwmpRequest.cwmpVersion?
|
if not cwmpRequest.cwmpVersion?
|
||||||
# cwmpVersion not passed, thus it's an inform request
|
# 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
|
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()
|
switch methodElement.name()
|
||||||
when 'Inform'
|
when 'Inform'
|
||||||
cwmpRequest.methodRequest = acsInform(methodElement)
|
cwmpRequest.methodRequest = acsInform(methodElement)
|
||||||
@@ -450,6 +459,6 @@ exports.response = (cwmpResponse) ->
|
|||||||
|
|
||||||
if env?
|
if env?
|
||||||
headers['Content-Type'] = 'text/xml; charset="utf-8"'
|
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
|
else
|
||||||
return {code: 204, headers: headers, data: new Buffer(0)}
|
return {code: 204, headers: headers, data: new Buffer(0)}
|
||||||
Reference in new issue
Block a user