Commit e71db022 authored by Steve Johnson's avatar Steve Johnson

added exception handler for parsing bad messages

parent 9bed0571
......@@ -1214,45 +1214,49 @@ function SSDP(serviceType) {
}
this.parseCommand = function parseCommand(msg, rinfo) {
var lines = msg.toString().split("\r\n");
var type = lines.shift().split(' ');
var method = type[0];
var uri = type[1];
var heads = {};
for (ix in lines) {
var line = lines[ix];
if (line.length < 1) continue;
var vv = line.match(/^([^:]+):\s*(.*)$/);
heads[vv[1].toUpperCase()] = vv[2];
}
switch (method) {
// This is if we were discovering other devices, but we are not.
case 'NOTIFY':
/*
// Device coming to life.
if (heads['NTS'] == 'ssdp:alive') {
this.emit('advertise-alive', heads);
}
// Device shutting down.
else if (heads['NTS'] == 'ssdp:byebye') {
this.emit('advertise-bye', heads);
}
else console.log('############### Notify unhandled!');
*/
break;
case 'M-SEARCH':
console.log('SSDP M-SEARCH: for ('+heads['ST']+') from ('+rinfo['address']+':'+rinfo['port']+')');
if (!heads['MAN']) return;
if (!heads['MX']) return;
if (!heads['ST']) return;
this.inMSearch(heads['ST'], rinfo);
break;
default:
console.log("Unknown message: \r\n"+msg);
try {
var lines = msg.toString().split("\r\n");
var type = lines.shift().split(' ');
var method = type[0];
var uri = type[1];
var heads = {};
for (ix in lines) {
var line = lines[ix];
if (line.length < 1) continue;
var vv = line.match(/^([^:]+):\s*(.*)$/);
heads[vv[1].toUpperCase()] = vv[2];
}
switch (method) {
// This is if we were discovering other devices, but we are not.
case 'NOTIFY':
/*
// Device coming to life.
if (heads['NTS'] == 'ssdp:alive') {
this.emit('advertise-alive', heads);
}
// Device shutting down.
else if (heads['NTS'] == 'ssdp:byebye') {
this.emit('advertise-bye', heads);
}
else console.log('############### Notify unhandled!');
*/
break;
case 'M-SEARCH':
console.log('SSDP M-SEARCH: for ('+heads['ST']+') from ('+rinfo['address']+':'+rinfo['port']+')');
if (!heads['MAN']) return;
if (!heads['MX']) return;
if (!heads['ST']) return;
this.inMSearch(heads['ST'], rinfo);
break;
default:
console.log("Unknown message: \r\n"+msg);
}
}
catch(e) {}
}
this.parseResponse = function parseResponse(msg, rinfo) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment