2021年12月11日 星期六

tel URI

RFC3966 說明 tel URI

telephone-subscriber = global-number / local-number

telephone-subscriber 可以看成是 user 是電話號碼的特例,看開頭有無「+」分成全球號碼 (global-number) 和區域號碼 (local-number) 兩種。

全球號碼 (global-number, E.164):tel: +十進位數字

global-number        = global-number-digits *par
global-number-digits = "+" *phonedigit DIGIT *phonedigit

全球號碼是「+」開頭十進位數字,至少一碼。可用 visual-separator「-」「.」「(」「)」隔開便於閱讀,比較或撥號時都忽略。後面可有參數,每個「;」表示有一個。依照 E.123E.164,數字必須包含國碼 (CC) 和受話國國內有效號碼 (National Significant Number, NSN),是全球唯一的。

範例

tel:+1-201-555-0123

一個美國門號,國碼 1、區碼 ...、、、。

有些號碼無法用全球號碼表示,需要用區域號碼,例如私人號碼、緊急電話 119/110、查號台 104、服務電話等。號碼含有 有 A ~ D、* 或 # 也不行。

區域號碼:tel: 十六進位數字;phone-context=網址

local-number         = local-number-digits *par context *par
local-number-digits  = *phonedigit-hex (HEXDIG / "*" / "#")*phonedigit-hex

區域號碼用十六進位數字和「*」「#」,一樣可以隔開便於閱讀,後面一樣可以有參數。

參考

  1. RFC3966 The tel URI for Telephone Numbers obsolete RFC2806 URLs for Telephone Calls
  • http://tools.ietf.org/html/rfc3261#section-19.1.6 說明跟 sip: 的轉換。
  • cpc (Calling Party's Category)
    • https://itectec.com/spec/c-1-interworking-sip-to-isup/
    • https://www.etsi.org/deliver/etsi_TS/129100_129199/129163/11.07.00_60/ts_129163v110700p.pdf
  • Numbering Plan
    • ISDN 和 PSTN 使用 E.164 (I.330),PSPDN (Packet Switched Public Data Networks) 一般使用 X.121。不同 numbering plan 轉換需要 numbering plan interworking,有 Escape Code、NPI 等方式。
    • National ISDN number = Nataional destination code + ISDN subscriber number
    • Internation ISDN number = Country code + National ISDN number
    • prefix
    • E.164 Escape Code

SIP URI

SIP 最基本的 URI scheme 是 sip:,TLS 加密用 sips:,像 email 格式,用在 SIP 請求行及批頭值等,整個會使拆著 4 個部份:

格式sip:user:password@host:port;uri-parameter?header
4 個部份
帳號主機URI 參數URI 批頭
ABNF
userinfohostporturi-parametersheaders

其中只有主機的 host 是必要的。URI 可作為 addr-spec,但有 URI 參數時,需要整個用 <> 包起來成為 name-addr,才能區別「批頭參數」。

ABNF 格式:

SIP-URI    = "sip:" [ userinfo ] hostport uri-parameters [ headers ]
SIPS-URI   = "sips:" [ userinfo ] hostport uri-parameters [ headers ]

有「@」表示在主機有帳號,「@」之前就是帳號部份,分大小寫,可用 user 或 telephone-subscriber。帳號內如果有「:」表示含有密碼 password,毋過有安全問題不建議用。

userinfo   = ( user / telephone-subscriber ) [ ":" password ] "@"

user 大多字元都可以使用,即使「,」「;」「?」也可以。「@」區別帳號不能使用,「:」表示有密碼也不行,可用「% 跳脫」。

user            =  1*( unreserved / escaped / user-unreserved )
user-unreserved =  "&" / "=" / "+" / "$" / "," / ";" / "?" / "/"

telephone-subscriber 是電話號碼,由 tel URI 來,可視為 user 的特例,可用 URI 參數 user=phone 明確表示用電話號碼。電話號碼本身可能包括「;」開頭的參數,這是出現在「@」之前,和主機之後的 URI 參數是不同的。電話號碼參數在 tel URI 是不分大小寫的,且不同順序是相同的。轉遮 SIP/SIPS URI 愛換遮小寫,isub 排頭前,賰的照字母順序排,這樣比較才會一致。例如:

tel:+358-555-1234567;tsp=a.b;phone-context=5

變成

sip:+358-555-1234567;phone-context=5;tsp=a.b@foo.com;user=phone

密碼也大多字元都可以使用,只比 user 少了「;」「?」和「/」。(為什麼需要少這 3 個?)

password        =  *( unreserved / escaped /
                   "&" / "=" / "+" / "$" / "," )

主機可以是網域名稱或 IP 網址,如果有「:」表示含有 port。

hostport       = host [ ":" port ]
host           = hostname / IPv4address / IPv6reference
hostname       = *( domainlabel "." ) toplabel [ "." ]
domainlabel    = alphanum / alphanum *( alphanum / "-" ) alphanum
toplabel       = ALPHA / ALPHA *( alphanum / "-" ) alphanum
IPv4address    = 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT
IPv6reference  = "[" IPv6address "]"
IPv6address    = hexpart [ ":" IPv4address ]
hexpart        = hexseq / hexseq "::" [ hexseq ] / "::" [ hexseq ]
hexseq         = hex4 *( ":" hex4)
hex4           = 1*4HEXDIG
port           = 1*DIGIT

URI 參數可有多個,每個以「;」開始,格式是 名稱=值,名稱不能重複,有 transport、maddr、ttl、user、method、lr 等。和批頭參數是不同的東西。整個 URI 可作為 addr-spec,可用到「,」、「?」、和「;」,但為了跟信頭參數的「;」區別,整個 URI 需要用 <> 包起來成為 name-addr

uri-parameters = *( ";" uri-parameter)
uri-parameter     = transport-param / user-param / method-param
                    / ttl-param / maddr-param / lr-param / other-param
transport-param   = "transport="
                    ( "udp" / "tcp" / "sctp" / "tls"
                    / other-transport)
other-transport   = token
user-param        = "user=" ( "phone" / "ip" / other-user)
other-user        = token
method-param      = "method=" Method
ttl-param         = "ttl=" ttl
maddr-param       = "maddr=" host
lr-param          = "lr"
other-param       = pname [ "=" pvalue ]
pname             = 1*paramchar
pvalue            = 1*paramchar
paramchar         = param-unreserved / unreserved / escaped
param-unreserved  = "[" / "]" / "/" / ":" / "&" / "+" / "$"

說明

  • user=phone:特別表示帳號是電話號碼。

「?」表示有 header,每個用「&」格開。

headers        = "?" header *( "&" header )
header          =  hname "=" hvalue
hname           =  1*( hnv-unreserved / unreserved / escaped )
hvalue          =  *( hnv-unreserved / unreserved / escaped )
hnv-unreserved  =  "[" / "]" / "/" / "?" / ":" / "+" / "$"

其它 scheme URI,可以是網路路徑、絕對路徑等。

absoluteURI    =  scheme ":" ( hier-part / opaque-part )
scheme         =  ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
hier-part      =  ( net-path / abs-path ) [ "?" query ]
net-path       =  "//" authority [ abs-path ]
authority      =  srvr / reg-name
srvr           =  [ [ userinfo "@" ] hostport ]
reg-name       =  1*( unreserved / escaped / "$" / ","
                  / ";" / ":" / "@" / "&" / "=" / "+" )
query          =  *uric
abs-path       =  "/" path-segments
opaque-part    =  uric-no-slash *uric
uric           =  reserved / unreserved / escaped
uric-no-slash  =  unreserved / escaped / ";" / "?" / ":" / "@"
                  / "&" / "=" / "+" / "$" / ","
path-segments  =  segment *( "/" segment )
segment        =  *pchar *( ";" *pchar )
pchar          =  unreserved / escaped /
                  ":" / "@" / "&" / "=" / "+" / "$" / ","

參考

  1. RFC3261 §19.1
  • SIP/SIPS URL follow RFC3986 guideline

Windows Subsystem for Linux

Windows Subsystem for Linux

WSL 1

WSL 2

參考:https://docs.microsoft.com/zh-tw/windows/wsl
  • 使用受控 VM 內經過微調的實際 Linux 核心、支援完整的系統呼叫相容性,以及最佳化的效能。
  • 以最新版的 VMware 和 VirtualBox 執行
  • 可以在 WSL 內執行一套全新的應用程式,例如 Docker 等。
  • 跨 Linux 和 Windows 的檔案效能比 WSL1 差
  • 不包含存取序列埠的支援。
  • 記憶體需求
  • VirtualBox 的使用者需要考慮版本是否與 WSL 2 相容。
  • WSL 2 以 hyper-v 虛擬機器的形式執行,網路使用網路位址轉譯 (NAT)。

安裝

  • wsl --install
  • wsl --install -d Ubuntu

.hushlogin

參考

  1. https://docs.microsoft.com/en-us/windows/wsl/

SIP header Via

所有 SIP 訊息 都要有 Via,縮寫 v。一開始的 UAC 和後續途經的每個 proxy 都會疊加一個 Via 放傳送的位址,依序作為回應的路徑。 格式 sent-protocol sent-by [ ;branch= branch ][ ; 參數 ...] s...