aiosip icon indicating copy to clipboard operation
aiosip copied to clipboard

Contact/SIP URI overhaul

Open vodik opened this issue 7 years ago • 2 comments

Hey, so my team, specifically my coworker @dtkerr, has put together a yarl-like like library for SIP URIs: ursine

I'd like to integrate it into aiosip as it will solve a lot of problems:

  • We've had bugs in the part with mutability (e.g. passing from_details into a function which adds a tag, and suddenly having tags propagate everywhere inappropriately)

  • Building to_uri/from_uri/contact_uri can be very tedious:

to_details=Contact.from_header(f"<sip:{user}@{host}:{port};transport={transport}")
from_details=...
contact_details=...
  • Its tedious properly handling contact details. Say I'm handling an inbound REGISTER to then later route out calls:
contact_addr = (msg.contact_details['uri']['host'],
                msg.contact_details['uri']['port'])
                
peer = await app.connect(contact_addr, aiosip.UDP,
                         local_addr=("0.0.0.0", 5060))

Not to mention this ignores transport - which can be mixed. I've just been assuming this whole time I'll be using UDP only because its easiest and I'll revisit other transports later. I do have a need to support sips:... eventually.

What I'd really like to see:

to_uri=URI.build(scheme="sip", user=user, host=host, port=port)
from_uri=...
contact_uri=...

This can also help with #63 and we can create the URI with to_uri.with_user(None)

And I think we should support making connections with SIP uris directly:

peer = await app.connect(msg.contact_uri, local_addr=("0.0.0.0", 5060))

Its a small library with no other external dependencies, which we've done separately intentionally so we can use it in a few other projects that do SIP stuff but don't use aiosip, but I'm open to merging it as well.

vodik avatar Apr 20 '18 04:04 vodik

Big thumbs up for that :+1:

Changing contact / uri handling was always on my mind as it was quite complicated. That looks like it will solve quite a few problems so I'm all for it

ovv avatar Apr 20 '18 08:04 ovv

Ok for me also.

ludovic-gasc avatar Apr 20 '18 19:04 ludovic-gasc