kirm / sip.js

Session Initiation Protocol for node.js
MIT License
431 stars 171 forks source link

Fixed stringifing messages with no VIA headers, such as a 404 #78

Closed nguyer closed 9 years ago

nguyer commented 9 years ago

With the current version, if you try to send a SIP message to an IP/port that does not have a process listening for SIP, and you try to stringily the response, an uncaught exception is thrown as it tries to call toUpperCase() on the undefined protocol string.

/Users/nguyer/Code/sip.js/sip.js:299
  return 'Via: SIP/'+stringifyVersion(via.version)+'/'+via.protocol.toUpperCas
                                                                    ^
TypeError: Cannot call method 'toUpperCase' of undefined
    at /Users/nguyer/Code/sip.js/sip.js:299:73
    at Array.map (native)
    at Object.stringifiers.via (/Users/nguyer/Code/sip.js/sip.js:298:14)
    at Object.stringify (/Users/nguyer/Code/sip.js/sip.js:363:29)
    at /Users/nguyer/Code/sendsip/app.js:78:18
    at next (/Users/nguyer/Code/sip.js/sip.js:1241:7)
    at sequentialSearch (/Users/nguyer/Code/sip.js/sip.js:1255:3)
    at /Users/nguyer/Code/sip.js/sip.js:1358:13
    at /Users/nguyer/Code/sip.js/sip.js:1335:13
    at Object.send (/Users/nguyer/Code/sip.js/sip.js:1339:11)

This is fixed with this patch. If no hostname is present in the VIA header, it is invalid anyway, and will not be stringified with the rest of the message.

nguyer commented 9 years ago

Thanks for merging so quickly!