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) { ...@@ -1214,45 +1214,49 @@ function SSDP(serviceType) {
} }
this.parseCommand = function parseCommand(msg, rinfo) { 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) { try {
// This is if we were discovering other devices, but we are not. var lines = msg.toString().split("\r\n");
case 'NOTIFY': var type = lines.shift().split(' ');
/* var method = type[0];
// Device coming to life. var uri = type[1];
if (heads['NTS'] == 'ssdp:alive') {
this.emit('advertise-alive', heads); var heads = {};
} for (ix in lines) {
// Device shutting down. var line = lines[ix];
else if (heads['NTS'] == 'ssdp:byebye') { if (line.length < 1) continue;
this.emit('advertise-bye', heads); var vv = line.match(/^([^:]+):\s*(.*)$/);
} heads[vv[1].toUpperCase()] = vv[2];
else console.log('############### Notify unhandled!'); }
*/
break; switch (method) {
// This is if we were discovering other devices, but we are not.
case 'M-SEARCH': case 'NOTIFY':
console.log('SSDP M-SEARCH: for ('+heads['ST']+') from ('+rinfo['address']+':'+rinfo['port']+')'); /*
if (!heads['MAN']) return; // Device coming to life.
if (!heads['MX']) return; if (heads['NTS'] == 'ssdp:alive') {
if (!heads['ST']) return; this.emit('advertise-alive', heads);
this.inMSearch(heads['ST'], rinfo); }
break; // Device shutting down.
default: else if (heads['NTS'] == 'ssdp:byebye') {
console.log("Unknown message: \r\n"+msg); 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) { 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