Skip to content

Commit

Permalink
Merge branch 'tayler6000:development' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
key2peace authored Jan 19, 2024
2 parents 11a1938 + 9b02be6 commit 717559a
Showing 1 changed file with 55 additions and 24 deletions.
79 changes: 55 additions & 24 deletions pyVoIP/SIP/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"<sip:{self.user}@{self.bind_ip}:{self.bind_port}>;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"<sip:{self.user}@{self.server}:{self.port}>\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,
Expand All @@ -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"<sip:{self.user}@{self.server}>;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: <sip:{self.user}@{self.server}>\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
Expand All @@ -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"<sip:{self.user}@{self.bind_ip}:{self.bind_port}>;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"<sip:{self.user}@{self.server}:{self.port}>\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"
Expand Down Expand Up @@ -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: <sip:{number}@{self.server}>\r\n"
msg += (
f"From: <sip:{self.user}@{self.bind_ip}>;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"
Expand Down

0 comments on commit 717559a

Please sign in to comment.