tayler6000 / pyVoIP

Pure python VoIP/SIP/RTP library. Currently supports PCMA, PCMU, and telephone-event
https://pypi.org/project/pyVoIP/
GNU General Public License v3.0
225 stars 96 forks source link

Request to send XML in body when registering #109

Open pergolafabio opened 1 year ago

pergolafabio commented 1 year ago

Hi, is it possible to make a feature request to send xml in the body register like example below?

Thnx in advance!!

    def send_sip_register(self, register_frequency=600):
        self.register_packet = Packet()
        call_id = self.get_call_id()
        self.register_packet.set_header("Via", f"SIP/2.0/UDP {self.ip}:{self.bind_port};rport")
        self.register_packet.set_header("Max-Forwards", "70")
        self.register_packet.set_header("Contact", f"<sip:{self.username}@{self.ip}:{self.bind_port}>")
        self.register_packet.set_header("To", f'""<sip:{self.username}@{self.domain}:{self.domain_port}>')
        self.register_packet.set_header("From", f'"{self.display_name}"<sip:{self.username}@{self.domain}:{self.domain_port}>')
        self.register_packet.set_header("Call-ID", call_id)
        self.register_packet.set_header("CSeq", "1 REGISTER")
        self.register_packet.set_header("Expires", str(register_frequency))
        self.register_packet.set_header("Allow", "NOTIFY, INVITE, ACK, CANCEL, BYE, REFER, INFO, OPTIONS, MESSAGE")
        self.register_packet.set_header("Content-Type", "text/xml")
        self.register_packet.set_header("User-Agent", str(self.USER_AGENT))
        self.register_packet.body = '''\
<regXML>
<version>V2.0.0</version>
<regDevName>Name</regDevName>
<regDevSerial>Q12345678</regDevSerial>
<regDevMacAddr>00:01:22:12:12:12</regDevMacAddr>
</regXML>'''
tayler6000 commented 1 year ago

I have seen a few instances of sending XML in SIP messages in the real world, but could you explain what benefit this would have? Also, what other messages would need XML in them? I'm just trying to think of a way that I could add this FR in and make sure it still looks nice.

pergolafabio commented 1 year ago

Hey @tayler6000 , offcourse, my case is specific for Hikvision Hardware and Video Intercoms, they talk with a private SIP hik protocol, and the devices itself exchange information with XML data, the example above, thats for a trunk setting to register, if the REGXML is missing, the sip protocol doesnt allow the trunk in Asterisk to be registered...

Its because you are now working getting a release ready for HA, want we want to use your pyVoip then instead offcourse...

Other examples bellow, for the message header

MESSAGE sip:10010100000@192.168.0.70:5065 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.71:5060;rport;branch=z9hG4bK153267426
From: Embedded Net VIS <sip:10010110001@192.168.0.71>;tag=1873039053
To: <sip:10010100000@192.168.0.70:5065>
Call-ID: 1101016445
CSeq: 20 MESSAGE
Content-Type: text/xml
Max-Forwards: 70
User-Agent: eXosip/3.6.0
Content-Length:   269

<sipMsg>
<header>
<version>V2.0.0</version>
<msgId>b8e363ef</msgId>
<encrypt>false</encrypt>
<uri>/SIP/Query/OutdoorInfo</uri>
<from>
<deviceSN>XXXXX</deviceSN>
<ipAddr>192.168.0.71</ipAddr>
<phoneNo>10010110001</phoneNo>
</from>
</header>
<body>
</body>
</sipMsg>
MESSAGE sip:10010100000@192.168.0.70:5065 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.71:5060;rport;branch=z9hG4bK153267426
From: Embedded Net VIS <sip:10010110001@192.168.0.71>;tag=1873039053
To: <sip:10010100000@192.168.0.70:5065>
Call-ID: 1101016445
CSeq: 20 MESSAGE
Content-Type: text/xml
Max-Forwards: 70
User-Agent: eXosip/3.6.0
Content-Length:   269

<sipMsg>
<header>
<version>V2.0.0</version>
<msgId>b8e363ef</msgId>
<encrypt>false</encrypt>
<uri>/SIP/Query/OutdoorInfo</uri>
<from>
<deviceSN>XXXX</deviceSN>
<ipAddr>192.168.0.71</ipAddr>
<phoneNo>10010110001</phoneNo>
</from>
</header>
<body>
</body>
</sipMsg>
tayler6000 commented 1 year ago

Thanks for the examples! PyVoIP recently gained additional support for receiving text/plain and text/xml messages in commit 8922a62. Since the merge of #100, basically, everything except registration is broken. But once I finish the VoIPSocket migration, you should be able to properly send and receive XML MESSAGE requests.

With HA's sponsorship of pyVoIP I can definitely add additional XML body requirements where necessary. I'd like to get pyVoIP 2.0.0 out relatively soon, and to do that I'd like to not overload it will too many feature requests since there are many bugs to solve at the moment. But this can definitely be a 2.1.0 priority!

pergolafabio commented 1 year ago

Thx for this info, much appreciated!!! Will make a lot of users happy!