Example #1
0
 def testParseAddress(self):
     for address, name, urls, params in [
         (
             '"A. G. Bell" <sip:[email protected]>',
             "A. G. Bell",
             "sip:[email protected]",
             {},
         ),
         ("Anon <sip:[email protected]>", "Anon", "sip:[email protected]", {}),
         ("sip:[email protected]", "", "sip:[email protected]", {}),
         ("<sip:[email protected]>", "", "sip:[email protected]", {}),
         (
             "foo <sip:[email protected]>;tag=bar;foo=baz",
             "foo",
             "sip:[email protected]",
             {
                 "tag": "bar",
                 "foo": "baz"
             },
         ),
     ]:
         gname, gurl, gparams = sip.parseAddress(address)
         self.assertEqual(name, gname)
         self.assertEqual(gurl.toString(), urls)
         self.assertEqual(gparams, params)
Example #2
0
 def testAddressClass(self):
     addrs = [
         '"anthony" <sip:[email protected]>;tag=03860126',
         'sip:96748002@gw2;tag=3409638C-1B50',
         'sip:[email protected]',
         '"foo bar" <sip:[email protected]>',
         'sip:[email protected];tag=01234567',
     ]
     ae = self.assertEquals
     for addr in addrs:
         ae(addr, str(shsip.Address(addr)))
     addr = shsip.Address(('anthony', 'sip:[email protected]', {
         'tag': '03860126',
     }))
     ae(str(addr), '"anthony" <sip:[email protected]>;tag=03860126')
     addr1 = shsip.Address(('anthony', 'sip:[email protected]', {}),
                           ensureTag=False)
     addr2 = shsip.Address('"anthony" <sip:[email protected]>',
                           ensureTag=False)
     ae(str(addr1), '"anthony" <sip:[email protected]>')
     ae(str(addr1), str(addr2))
     addr = shsip.Address('"anthony" <sip:[email protected]>',
                          ensureTag=True)
     d, u, p = tpsip.parseAddress(str(addr))
     ae(p.has_key('tag'), True)
     ae(str(shsip.Address('sip:[email protected]')),
        str(shsip.Address(('', 'sip:[email protected]', {}))))
Example #3
0
 def testParsingAndFormatting(self):
     addrs = [ '"anthony" <sip:[email protected]>;tag=03860126',
               'sip:96748002@gw2;tag=3409638C-1B50',
               'sip:[email protected]',
               'sip:[email protected];tag=01234567',
             ]
     ae = self.assertEqual
     for addr in addrs:
         ae(addr, shsip.formatAddress(tpsip.parseAddress(addr)))
Example #4
0
 def testParseAddress(self):
     for address, name, urls, params in [
         ('"A. G. Bell" <sip:[email protected]>', "A. G. Bell", "sip:[email protected]", {}),
         ("Anon <sip:[email protected]>", "Anon", "sip:[email protected]", {}),
         ("sip:[email protected]", "", "sip:[email protected]", {}),
         ("<sip:[email protected]>", "", "sip:[email protected]", {}),
         ("foo <sip:[email protected]>;tag=bar;foo=baz", "foo", "sip:[email protected]", {"tag": "bar", "foo": "baz"}),
         ]:
         gname, gurl, gparams = sip.parseAddress(address)
         self.assertEquals(name, gname)
         self.assertEquals(gurl.toString(), urls)
         self.assertEquals(gparams, params)
Example #5
0
 def handle_request(self, req, addr):
     print "Received SIP request from %s:%d:" % addr
     print req.toString()
     # Add a via header for us
     via = self.getVia()
     if not via.branch:
         # Twisted SIP is still not compliant with RFC3261 s16.11.
         # Work around this, assuming our caller *is* compliant.
         topVia = sip.parseViaHeader(req.headers["via"][0])
         via.branch = topVia.branch + "-AS-059"  # chosen by fair random.org. guaranteed to be random.
     req.headers["via"].insert(0, via.toString())
     # Determine the next hop - use the route headers if present, else the request URI
     uri = req.uri
     if "route" in req.headers:
         # If we're the first route header, strip it
         _, route, _ = sip.parseAddress(req.headers["route"][0])
         if route.host == self.host:
             req.headers["route"].pop(0)
         # Now find the next hop
         if len(req.headers["route"]) > 0:
             _, uri, _ = sip.parseAddress(req.headers["route"][0])
     # Insert a record-route header to keep us in the path
     req.headers.setdefault("record-route", []).insert(
         0,
         sip.URL(host=self.host,
                 port=self.port,
                 other=["transport=UDP", "lr"]))
     # Assert that we're authorized. Workaround pending sto131 completion.
     if "authorization" not in req.headers:
         req.addHeader(
             "authorization",
             'Digest username="******", realm="cw-ngv.com", nonce="0000000000000000", uri="sip:cw-ngv.com", response="00000000000000000000000000000000", algorithm=md5, opaque="0000000000000000",integrity-protected="yes"'
         )
     print "Sending SIP request to %s:" % uri
     print req.toString()
     print "==============================================================================="
     # Send the message on
     self.sendMessage(uri, req)
Example #6
0
 def handle_request(self, req, addr):
     print "Received SIP request from %s:%d:" % addr
     print req.toString()
     # Add a via header for us
     via = self.getVia()
     if not via.branch:
         # Twisted SIP is still not compliant with RFC3261 s16.11.
         # Work around this, assuming our caller *is* compliant.
         topVia = sip.parseViaHeader(req.headers["via"][0])
         via.branch = topVia.branch + "-AS-059"  # chosen by fair random.org. guaranteed to be random.
     req.headers["via"].insert(0, via.toString())
     # Determine the next hop - use the route headers if present, else the request URI
     uri = req.uri
     if "route" in req.headers:
         # If we're the first route header, strip it
         _, route, _ = sip.parseAddress(req.headers["route"][0])
         if route.host == self.host:
             req.headers["route"].pop(0)
         # Now find the next hop
         if len(req.headers["route"]) > 0:
             _, uri, _ = sip.parseAddress(req.headers["route"][0])
     # Insert a record-route header to keep us in the path
     req.headers.setdefault("record-route", []).insert(
         0, sip.URL(host=self.host, port=self.port, other=["transport=UDP", "lr"])
     )
     # Assert that we're authorized. Workaround pending sto131 completion.
     if "authorization" not in req.headers:
         req.addHeader(
             "authorization",
             'Digest username="******", realm="cw-ngv.com", nonce="0000000000000000", uri="sip:cw-ngv.com", response="00000000000000000000000000000000", algorithm=md5, opaque="0000000000000000",integrity-protected="yes"',
         )
     print "Sending SIP request to %s:" % uri
     print req.toString()
     print "==============================================================================="
     # Send the message on
     self.sendMessage(uri, req)
 def handle_request(self, message, addr):
     to = message.uri.username
     fromm = sip.parseAddress(message.headers['from'][0])[1].username
     if message.method == 'MESSAGE':
         rpdu = sms_utilities.rpdu.RPDU.fromPDU(message.body)
         sms_deliver = SMS_DELIVER.fromPDU(rpdu.user_data,
                                           rpdu.rp_originator_address)
         self.sms_h(to, fromm, sms_deliver.user_data)
         r = self.responseFromRequest(200, message)
     elif message.method == 'ACK':
         r = self.responseFromRequest(200, message)
     elif message.method == 'INVITE':
         self.call_h(to, fromm)
         # We don't know how to actually handle calls.
         r = self.responseFromRequest(487, message)
     else:
         raise Exception("Received unhandled request")
     self.deliverResponse(r)