Skip to content

Commit

Permalink
add default parsing for lines we don't understand, and add verifiabil…
Browse files Browse the repository at this point in the history
…ity of it to the checker - for #19
  • Loading branch information
clux committed Jan 28, 2014
1 parent 87aa44b commit 1727261
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 6 deletions.
14 changes: 12 additions & 2 deletions checker.js
Expand Up @@ -11,6 +11,14 @@ var transform = require('./')
, numNew = 0
;

var parseFails = 0;
parsed.media.forEach(function (media, i) {
(media.invalid || []).forEach(function (inv) {
console.warn('unrecognized a=' + inv.value + ' belonging to m=' + media.type);
parseFails += 1;
});
});
var parseStr = parseFails + ' unrecognized line(s) copied blindly';

origLines.forEach(function (line, i) {
if (writtenLines.indexOf(line) < 0) {
Expand All @@ -29,9 +37,11 @@ writtenLines.forEach(function (line, i) {
var failed = (numMissing > 0 || numNew > 0);
if (failed) {
console.log('\n' + file + ' changes during transform:');
console.log(numMissing + ' missing lines, ' + numNew + ' new lines')
console.log(numMissing + ' missing line(s), ' + numNew + ' new line(s)%s',
parseFails > 0 ? ', ' + parseStr : ''
);
}
else {
console.log(file + ' verified');
console.log(file + ' verified%s', parseFails > 0 ? ', but had ' + parseStr : '');
}
process.exit(failed ? 1 : 0);
4 changes: 4 additions & 0 deletions lib/grammar.js
Expand Up @@ -198,6 +198,10 @@ var grammar = module.exports = {
{ //a=rtcp-mux
name: 'rtcpMux',
reg: /^(rtcp-mux)/
},
{ // any a= that we don't understand is kepts verbatim on media.invalid
push: 'invalid',
names: ["value"]
}
]
};
Expand Down
5 changes: 1 addition & 4 deletions lib/parser.js
Expand Up @@ -37,8 +37,7 @@ var parseReg = function (obj, location, content) {
var grammar = require('./grammar');
var validLine = RegExp.prototype.test.bind(/^([a-z])=(.*)/);

exports.parse = function (sdp, opts) {
opts = opts || {};
exports.parse = function (sdp) {
var session = {}
, media = []
, location = session; // points at where properties go under (one of the above)
Expand All @@ -58,8 +57,6 @@ exports.parse = function (sdp, opts) {
return parseReg(obj, location, content);
}
}
// TODO: if here && opts.keepInvalid
// return parseReg({push: "invalid", reg: /(.*)/, format: "%s"}, location, content)
});

session.media = media; // link it up
Expand Down
26 changes: 26 additions & 0 deletions test/basic.js
Expand Up @@ -186,3 +186,29 @@ test("chrome.sdp", function (t) {
t.end();
});
});



test("invalid.sdp", function (t) {
fs.readFile('./invalid.sdp', function (err, sdp) {
if (err) {
t.ok(false, "failed to read file:" + err);
t.end();
return;
}
var session = parse(sdp+'');
t.ok(session, "got session info");
var media = session.media;
t.ok(media && media.length > 0, "got media");

// verify a=rtcp:65179 IN IP4 193.84.77.194
t.equal(media[0].rtcp.port, 1, 'rtcp port');
t.equal(media[0].rtcp.netType, 'IN', 'rtcp netType');
t.equal(media[0].rtcp.ipVer, 7, 'rtcp ipVer');
t.equal(media[0].rtcp.address, 'X', 'rtcp address');
t.equal(media[0].invalid.length, 1, 'found exactly 1 invalid line'); // f= lost
t.equal(media[0].invalid[0].value, 'goo:hithere', 'copied verbatim');

t.end();
});
});
10 changes: 10 additions & 0 deletions test/invalid.sdp
@@ -0,0 +1,10 @@
v=0
o=- 3710604898417546434 2 IN IP4 127.0.0.1
s=-
t=0 0
m=audio 1 RTP/AVP 0
c=IN IP4 0.0.0.0
a=rtcp:1 IN IP7 X
a=rtpmap:0 PCMU/8000
a=goo:hithere
f=invalid:yes

0 comments on commit 1727261

Please sign in to comment.