Handle invalid xml chars gracefully
This commit is contained in:
1 parent
0ac2bdf656
commit
95ee9ffd0e
2 files changed
+14
-13
No files matched your search
+4
-2
@@ -135,9 +135,11 @@ else
|
|||||||
process.on('uncaughtException', (err) ->
|
process.on('uncaughtException', (err) ->
|
||||||
# dump request/response logs and stack trace
|
# dump request/response logs and stack trace
|
||||||
util.log("Unexpected error occured. Writing log to debug/#{currentClientIP}.log.")
|
util.log("Unexpected error occured. Writing log to debug/#{currentClientIP}.log.")
|
||||||
memcached.get("debug-#{currentClientIP}", (er, l) ->
|
memcached.get("debug-#{currentClientIP}", (err, l) ->
|
||||||
|
util.error(err) if err
|
||||||
fs = require 'fs'
|
fs = require 'fs'
|
||||||
fs.writeFile("debug/#{currentClientIP}.log", l + "\n\n" + err.stack, (err) ->
|
fs.writeFile("debug/#{currentClientIP}.log", l + "\n\n" + err.stack, (err) ->
|
||||||
|
util.error(err) if err
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -181,7 +183,7 @@ else
|
|||||||
)
|
)
|
||||||
|
|
||||||
resParams = {}
|
resParams = {}
|
||||||
reqParams = tr069.request(request.headers, request.getBody())
|
reqParams = tr069.request(request)
|
||||||
|
|
||||||
if reqParams.inform
|
if reqParams.inform
|
||||||
resParams.inform = true
|
resParams.inform = true
|
||||||
|
|||||||
+10
-11
@@ -117,16 +117,19 @@ setParameterValuesResponse = (xml) ->
|
|||||||
return undefined
|
return undefined
|
||||||
|
|
||||||
|
|
||||||
exports.request = (headers, data) ->
|
exports.request = (request) ->
|
||||||
#console.log '<<< REQUEST'
|
|
||||||
#console.dir [headers, data]
|
|
||||||
#console.log data
|
|
||||||
|
|
||||||
req = {cookies: {}}
|
req = {cookies: {}}
|
||||||
req.cookies = cookiesToObj(headers.cookie) if headers.cookie
|
req.cookies = cookiesToObj(request.headers.cookie) if request.headers.cookie
|
||||||
|
|
||||||
if +headers['Content-Length'] > 0 || data.length > 0
|
data = request.getBody()
|
||||||
|
|
||||||
|
if +request.headers['Content-Length'] > 0 || data.length > 0
|
||||||
|
try
|
||||||
xml = libxmljs.parseXml data
|
xml = libxmljs.parseXml data
|
||||||
|
catch err
|
||||||
|
# some devices send invalid utf8 characters
|
||||||
|
xml = libxmljs.parseXml request.getBody('binary')
|
||||||
|
|
||||||
req.sessionId = sessionId xml
|
req.sessionId = sessionId xml
|
||||||
req.inform = true if xml.get('//soap-env:Envelope/soap-env:Body/cwmp:Inform', NAMESPACES)
|
req.inform = true if xml.get('//soap-env:Envelope/soap-env:Body/cwmp:Inform', NAMESPACES)
|
||||||
req.informParameterValues = informParameterValues xml
|
req.informParameterValues = informParameterValues xml
|
||||||
@@ -195,8 +198,4 @@ exports.response = (sessionId, params, cookies = null) ->
|
|||||||
data = xml.toString()
|
data = xml.toString()
|
||||||
headers['Content-Length'] = data.length
|
headers['Content-Length'] = data.length
|
||||||
|
|
||||||
#console.log '>>> RESPONSE'
|
|
||||||
#console.dir headers
|
|
||||||
#console.log data
|
|
||||||
|
|
||||||
return {code: 200, headers: headers, data: data}
|
return {code: 200, headers: headers, data: data}
|
||||||
Reference in new issue
Block a user