astoeckel / femtosip

Minimal Python SIP implementation ringing phones as a door bell replacement
GNU Affero General Public License v3.0
48 stars 15 forks source link

Add optional displayname argument #1

Closed Mayerch1 closed 3 years ago

Mayerch1 commented 3 years ago

This PR adds the possibility to set the display name of the call to a custom string.

Motivation

When using this lib for home-automation the reason for triggering the call cannot be distinguished, if the same SIP-User is used for multiple use-cases. Adding the displayname will gives the option to show a short ascii string at the receiving end of the call.

Implementation

The previous state will not send a specific display name and the called phones will therefore always displaye the default name set by the SIP server/login.

This can be changed by prepending a string to the "from" field.

Previous "from"-string: From: <sip:Login@gateway>;tag=123456

"from"-string with custom display name: From: "MyName" <sip:Login@gateway>;tag=123456

"from"-string with default display name after PR: From: "" <sip:Login@gateway>;tag=123456

I added a new optional parser argument --displayname and a new consturctor parameter display_name='', defaulting to the previous behaviour. This achieves full backwards compatibility.

Validation

The empty string "" will result in the display of the default name, as before this PR. This is tested with FritzBox 7490 (and some Phillips dect phones), PhonerLite and Wireshark. The test cases are still running successfull (the tested code was not changed anyway)

astoeckel commented 3 years ago

Thank you for this PR, this looks really useful! Also, sorry for responding so late, I just stumbled over this.

Looking at your changes, I have one small suggestion. Could you remove the leading "" in the From field if display_name is empty (i.e., exactly restore the original behaviour)? It might be best to move assembling the From field to a separate helper function, where you can easily distinguish between the two cases.

Mayerch1 commented 3 years ago

I added the new function make_from_field(self, remote_host:str, tag: str)

It'll only prepend the string if display_name is not None

Behaviour: display_name is None (default) From: <sip:Login@gateway>;tag=123456

display_name is "MyName" From: "MyName" <sip:Login@gateway>;tag=123456

astoeckel commented 3 years ago

Awesome, looks great! Thank you very much!