Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.0.0a4] - Can't hangup my own call + Solution #252

Open
Wufus opened this issue Mar 18, 2024 · 2 comments
Open

[2.0.0a4] - Can't hangup my own call + Solution #252

Wufus opened this issue Mar 18, 2024 · 2 comments

Comments

@Wufus
Copy link

Wufus commented Mar 18, 2024

When i make call with:
mycall = phone.call(number)
and when the caller answers, I want to hang up:
mycall.hangup()
the message BYE seems not properly, because Asterisk say

SIP/2.0 401 Unauthorized

and

SIP/2.0 501 Not Implemented

The To: tag seems to be missing, but it should be there
<--- Received SIP request (430 bytes) from UDP:192.168.7.214:20020 --->
BYE sip:192.168.7.200:5060 SIP/2.0
Via: SIP/2.0/UDP 192.168.7.214:20020;branch=z9hG4bK4e07408562bedb8b60ce05c1d
From: <sip:77501@192.168.7.214:20020>;tag=4bd9541c
To: <sip:210@192.168.7.200>
Call-ID: 4b227777d4dd1fc61c6f884f48641d02@192.168.7.214:20020
CSeq: 2 BYE
Max-Forwards: 70
Contact: <sip:77501@192.168.7.214:20020>
User-Agent: pyVoIP 2.0.0a4
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, NOTIFY
Content-Length: 0
@Wufus
Copy link
Author

Wufus commented Mar 18, 2024

Found a workaround for me, but it may break any other scenarios:

client.py
class SIPClient:
 def _gen_bye_cancel(self, request: SIPMessage, cmd: str) -> str:
  ...
  if request.headers["From"]["tag"] == tag:
   byeRequest += self.__gen_from_to_via_request(request, "From", tag)
   byeRequest += f"To: {to['raw']};tag={to['tag']}\r\n"                # added ";tag={to['tag']}"
  ...
  cseq = request.headers["CSeq"]["check"] + 1                          # added "+ 1"
  ...

@Wufus
Copy link
Author

Wufus commented Mar 18, 2024

pyVoIP/pyVoIP/SIP.py

Lines 1517 to 1537 in 6c2aaef

def gen_bye(self, request: SIPMessage) -> str:
tag = self.tagLibrary[request.headers["Call-ID"]]
c = request.headers["Contact"].strip("<").strip(">")
byeRequest = f"BYE {c} SIP/2.0\r\n"
byeRequest += self._gen_response_via_header(request)
fromH = request.headers["From"]["raw"]
toH = request.headers["To"]["raw"]
if request.headers["From"]["tag"] == tag:
byeRequest += f"From: {fromH};tag={tag}\r\n"
if request.headers["To"]["tag"] != "":
to = toH + ";tag=" + request.headers["To"]["tag"]
else:
to = toH
byeRequest += f"To: {to}\r\n"
else:
byeRequest += (
f"To: {fromH};tag=" + f"{request.headers['From']['tag']}\r\n"
)
byeRequest += f"From: {toH};tag={tag}\r\n"
byeRequest += f"Call-ID: {request.headers['Call-ID']}\r\n"
cseq = int(request.headers["CSeq"]["check"]) + 1

It seems, that bug does not exist in v1.6.8

@Wufus Wufus changed the title [2.0.0a4] - Can't hangup my own call [2.0.0a4] - Can't hangup my own call + Solution Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant