BRIDGE-AI / 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
2 stars 0 forks source link

[처음넷] REGI 직후 OPTIONS 요청 왔을 때 패턴 오류 #1

Open BRIDGE-AI opened 3 months ago

BRIDGE-AI commented 3 months ago

brief.

OPTIONS sip:100@43.202.127.199 SIP/2.0
Via: SIP/2.0/UDP 127.0.0.1:5155;branch=z9hG4bK-2274944591;rport
Max-Forwards: 70
To: "sipvicious"<sip:100@1.1.1.1>
From: "sipvicious"<sip:100@1.1.1.1>;tag=32626361376663373133633401363430333631303737
User-Agent: friendly-scanner
Call-ID: 1192769561637410423630270
Contact: sip:100@127.0.0.1:5155
CSeq: 1 OPTIONS
Accept: application/sdp
Content-Length: 0
BRIDGE-AI commented 3 months ago

fix

pyVoIP/regex.py에서 아래의 2개 패턴에 대해

TO_FROM_MATCH = re.compile(
    r'(?P<display_name>"?[\w ]*"? )?<?(?P<uri_type>sips?):(?P<user>[\w+]+)(?P<password>:\w+)?@(?P<host>[\w.]+)(?P<port>:[0-9]+)?>?'
)
TO_FROM_DIRECT_MATCH = re.compile(
    r'(?P<display_name>"?[\w ]*"? )?<?(?P<uri_type>sips?):(?P<host>[\w.]+)(?P<port>:[0-9]+)?>?'
)

기존 패턴에서

    r'(?P<display_name>"?[\w ]*"? )?<?(?P<uri_type>sips?):(?P<user>[\w+]+)(?P<password>:\w+)?@(?P<host>[\w.]+)(?P<port>:[0-9]+)?>?'

display_name 뒤에 항상 공백 하나가 있어야 되도록 패턴 정의됨

아래의 테스트 코드 검증

    import re

    #TO_FROM_MATCH = re.compile(
    #   r'(?P<display_name>"?[\w ]*"? )?<?(?P<uri_type>sips?):(?P<user>[\w+]+)(?P<password>:\w+)?@(?P<host>[\w.]+)(?P<port>:[0-9]+)?>?'
    #)
    TO_FROM_MATCH = re.compile(
        r'(?P<display_name>"?[\w ]*"?[ ]*)?<?(?P<uri_type>sips?):(?P<user>[\w+]+)(?P<password>:\w+)?@(?P<host>[\w.]+)(?P<port>:[0-9]+)?>?'
    )

    data = "\"sipvicious\"<sip:100@1.1.1.1>"

    reg = TO_FROM_MATCH
    match = reg.match(data)
    print(f"match:{match}")

수정

TO_FROM_MATCH = re.compile(
    r'(?P<display_name>"?[\w ]*"?[ ]*)?<?(?P<uri_type>sips?):(?P<user>[\w+]+)(?P<password>:\w+)?@(?P<host>[\w.]+)(?P<port>:[0-9]+)?>?'
)
TO_FROM_DIRECT_MATCH = re.compile(
    r'(?P<display_name>"?[\w ]*"?[ ]*)?<?(?P<uri_type>sips?):(?P<host>[\w.]+)(?P<port>:[0-9]+)?>?'
)

display_name 뒤에 공백이 없거나 1개 또는 여러개 있을 수 있는 형태로 수정