diff --git a/pyVoIP/SIP/client.py b/pyVoIP/SIP/client.py index 83d592c..07052c5 100644 --- a/pyVoIP/SIP/client.py +++ b/pyVoIP/SIP/client.py @@ -544,19 +544,21 @@ def gen_urn_uuid(self) -> str: def gen_first_request(self, deregister=False) -> str: regRequest = f"REGISTER sip:{self.server}:{self.port} SIP/2.0\r\n" regRequest += self.__gen_via(self.server, self.gen_branch()) - - regRequest += ( - f'From: "{self.user}" ' - + f";tag=" - + f'{self.tagLibrary["register"]}\r\n' + tag = self.tagLibrary["register"] + method = "sips" if self.transport_mode is TransportMode.TLS else "sip" + regRequest += self.__gen_from_to( + "From", + self.user, + self.nat.get_host(self.server), + method=method, + port=self.bind_port, + header_parms=f";tag={tag}", ) - regRequest += ( - f'To: "{self.user}" ' - + f"\r\n" + regRequest += self.__gen_from_to( + "To", self.user, self.server, method=method, port=self.port ) regRequest += f"Call-ID: {self.gen_call_id()}\r\n" regRequest += f"CSeq: {self.registerCounter.next()} REGISTER\r\n" - method = "sips" if self.transport_mode is TransportMode.TLS else "sip" trans_mode = str(self.transport_mode) regRequest += self.__gen_contact( method, @@ -583,12 +585,22 @@ def gen_first_request(self, deregister=False) -> str: def gen_subscribe(self, response: SIPMessage) -> str: subRequest = f"SUBSCRIBE sip:{self.user}@{self.server} SIP/2.0\r\n" subRequest += self.__gen_via(self.server, self.gen_branch()) - subRequest += ( - f'From: "{self.user}" ' - + f";tag=" - + f"{self.gen_tag()}\r\n" + method = "sips" if self.transport_mode is TransportMode.TLS else "sip" + subRequest += self.__gen_from_to( + "From", + self.user, + self.nat.get_host(self.server), + method=method, + port=self.bind_port, + header_parms=f";tag={self.gen_tag()}", + ) + subRequest += self.__gen_from_to( + "To", + self.user, + self.server, + method=method, + port=self.port, ) - subRequest += f"To: \r\n" subRequest += f'Call-ID: {response.headers["Call-ID"]}\r\n' subRequest += f"CSeq: {self.subscribeCounter.next()} SUBSCRIBE\r\n" # TODO: check if transport is needed @@ -615,14 +627,21 @@ def gen_subscribe(self, response: SIPMessage) -> str: def gen_register(self, request: SIPMessage, deregister=False) -> str: regRequest = f"REGISTER sip:{self.server}:{self.port} SIP/2.0\r\n" regRequest += self.__gen_via(self.server, self.gen_branch()) - regRequest += ( - f'From: "{self.user}" ' - + f";tag=" - + f'{self.tagLibrary["register"]}\r\n' + method = "sips" if self.transport_mode is TransportMode.TLS else "sip" + regRequest += self.__gen_from_to( + "From", + self.user, + self.nat.get_host(self.server), + method=method, + port=self.bind_port, + header_parms=f";tag={self.tagLibrary['register']}", ) - regRequest += ( - f'To: "{self.user}" ' - + f"\r\n" + regRequest += self.__gen_from_to( + "To", + self.user, + self.server, + method=method, + port=self.port, ) call_id = request.headers.get("Call-ID", self.gen_call_id()) regRequest += f"Call-ID: {call_id}\r\n" @@ -1133,9 +1152,21 @@ def gen_message( msg = f"MESSAGE sip:{number}@{self.server} SIP/2.0\r\n" msg += self.__gen_via(self.server, branch) msg += "Max-Forwards: 70\r\n" - msg += f"To: \r\n" - msg += ( - f"From: ;tag={self.gen_tag()}\r\n" + method = "sips" if self.transport_mode is TransportMode.TLS else "sip" + msg += self.__gen_from_to( + "From", + self.user, + self.nat.get_host(self.server), + method=method, + port=self.bind_port, + header_parms=f";tag={self.gen_tag()}", + ) + msg += self.__gen_from_to( + "To", + number, + self.server, + method=method, + port=self.port, ) msg += f"Call-ID: {call_id}\r\n" msg += f"CSeq: {self.messageCounter.next()} MESSAGE\r\n"