Template variables

Introduction

This page documents all the template variables that may be used for each SIP message. Some of the exposed variables are used to build other variables but this depends on the context (i.e. the SIP method) and usage.

For information about the template engine, please consult the official Go documentation for text/template.

Variable definition

Each variable that can be used within a template is defined below.

Note that some of the variables have different meanings depending on the context.

Variable: AddrFamily

AddrFamily is the transport protocol used in for the SIP message and is based on the target address. This is typically UDP, TCP, TLS, WS or WSS. E.g. Via: SIP/2.0/{{.AddrFamily}} 127.0.0.1:5060;rport;branch=z9hG4bK-abcdefg results in Via: SIP/2.0/UDP 127.0.0.1:5060;rport;branch=z9hG4bK-abcdefg.

Variable: ServerAddr

ServerAddr will result in the FQDN or IP address and port of the target in the form: <IP|FQDN>:<port>. For example, it might be used to construct the first line of a register message as follows: REGISTER sip:{{.ServerAddr}} SIP/2.0. This may result in REGISTER sip:127.0.0.1:5060 SIP/2.0 if the server address is 127.0.0.1:5060.

Variable: ServerHost

ServerHost is the IP or FQDN of the target address. E.g. it may be used as follows: OPTIONS sip:{{.ServerHost}} SIP/2.0 resulting in OPTIONS sip:example.org SIP/2.0.

Variable: ServerPort

ServerPort is the target port which is used to construct the ServerAddr. E.g., it may be used as follows: OPTIONS sip:1.2.3.4:{{.ServerPort}} SIP/2.0.

Variable: LocalAddr

LocalAddr in the form <IP|FQDN>:<port> and is the address of the local listening IP and port. This is useful when building the Via header that requires the local address. E.g.: Via: SIP/2.0/UDP {{.LocalAddr}};rport;branch=z9hG4bK-abcdefg.

Variable: LocalHost

LocalHost is the SIPVicious local IP address. This may be useful whenever one needs to specify the local IP address for any responses. It is used to build the LocalAddr variable.

Variable: LocalPort

LocalPort is the SIPVicious local port used to handle SIP responses. This may be useful whenever one needs to specify the local port for any responses. It is used to build the LocalAddr variable.

Variable: Username

Username is the authentication username. E.g., Authorization: Digest username="{{.Username}}",realm="127.0.0.1" would result in Authorization: Digest username="test",realm="127.0.0.1",algorithm=MD5 if the authentication username were set to test.

Variable: Domain

Domain can be used in the Request-URI (such as REGISTER sip:{{.Domain}} SIP/2.0). If the field is not set, it’s value is set to ServerHost.

Variable: ToDomain

ToDomain can be used to set the domain part of the To header. If it not defined then the value of ToDomain will be set to Domain. For example, X-to-domain: {{.ToDomain}} would result in X-to-domain: 127.0.0.1 if the To header value were <sip:example@127.0.0.1>.

Variable: To

To is the value of the To header for the current SIP message. This is not context specific and usually one would use ToVal instead.

Variable: ToUser

ToUser is the user part of a To SIP URI. For example, To: <sip:{{.ToUser}}@example.org> will result in To: <sip:nzRfnCyJ@example.org>.

Variable: ToTag

ToTag is the tag value to be used in a To header. This is not set in the initial SIP request and usually based on the SIP response to the initial request. E.g. To: <sip:user@example.org>;tag={{.ToTag}} will result in To: <sip:Ejj1veeh@127.0.0.1>;tag=GUKmpc067LjAop1W.

Variable: FromDomain

FromDomain can be used to set the domain part of the From header. If it is not defined then the value of FromDomain will be set to Domain. For example, From: <sip:user@{{.FromDomain}}>;tag=statictag would be translated to From: <sip:user@127.0.0.1>;tag=statictag.

Variable: From

From is the value of the From header for the current SIP message. This is not context specific and normally one would use FromVal instead.

Variable: FromUser

FromUser is the user part of a From SIP URI. For example, From: <sip:{{.FromUser}}@example.org> will result in From: <sip:nzRfnCyJ@example.org>.

Variable: FromTag

FromTag is the tag value to be used in a From header. E.g. From: <sip:user@example.org>;tag={{.FromTag}} will result in From: <sip:Ejj1veeh@127.0.0.1>;tag=GUKmpc067LjAop1W.

Variable: CallID

CallID is the value of the CallID header, which may be randomly generated or copied from the SIP session. E.g. Call-ID: {{.CallID}} will result in Call-ID: ZiILuQpRx2dXyAMJ.

Variable: Branch

Branch is the value of the branch within the Via header, which may be randomly generated or copied from the SIP session. E.g. Via: SIP/2.0/UDP 127.0.0.1:5060;rport;branch=z9hG4bK-{{.Branch}} will result in Via: SIP/2.0/UDP 127.0.0.1:5060;rport;branch=z9hG4bK-uyH0QfwmTHirukoA.

Variable: CSeq

CSeq is the value of the CSeq header for the current SIP message. E.g. CSeq: {{.CSeq}} OPTIONS will result in CSeq: 1 OPTIONS.

Variable: Expires

Expires tag can be used for the Expires header as described in the SIP RFC, section 20.19. E.g. Expires: {{.Expires}} will result in Expires: 0.

Variable: ToVal

ToVal is the value for the To header. It is a context-sensitive header that is calculated according to the standard or best practice. E.g. To: {{.ToVal}} will result in To: <sip:JWTBfyqc@127.0.0.1>.

Variable: FromVal

FromVal is the value for the From header. It is a context-sensitive header that is calculated according to the standard or best practice. E.g. From: {{.FromVal}} will result in From: <sip:vbWL28Zu@127.0.0.1>;tag=dS6yKXwU0SiAow3M.

Variable: ContactVal

ContactVal is the value for the Contact header. It is a context-sensitive header that is calculated according to the standard or best practice. E.g. Contact: {{.ContactVal}} will result in Contact: <sip:q6xgnDyb@127.0.0.1:10011;transport=tcp>.

Variable: RequestURI

RequestURI is the value for the request URI in the first line. It is a context-sensitive header that is calculated according to the standard or best practice. E.g. OPTIONS {{.RequestURI}} SIP/2.0 will result in OPTIONS sip:127.0.0.1 SIP/2.0.

Variable: Body

Body is the SIP message body that is generated automatically and specific to the SIP method in use. E.g.:

INVITE {{.RequestURI}} SIP/2.0
Via: SIP/2.0/{{.AddrFamily}} {{.LocalAddr}};rport;branch=z9hG4bK-{{.Branch}}
Max-Forwards: 70
From: {{.FromVal}}
To: {{.ToVal}}
Call-ID: {{.CallID}}
CSeq: {{.CSeq}} INVITE
Contact: {{.ContactVal}}
Content-Length: {{.Body | len}}
Content-Type: application/sdp

{{.Body -}}

Results in the following:

INVITE sip:hFPnX68S@127.0.0.1 SIP/2.0
Via: SIP/2.0/TCP 127.0.0.1:10011;rport;branch=z9hG4bK-aoL0yL6TXQAR5Rz4
Max-Forwards: 70
From: <sip:Gu7AyiJg@127.0.0.1>;tag=fPYVgbsr9r5M8GmG
To: <sip:hFPnX68S@127.0.0.1>
Call-ID: 9QglEp1iZe0yfZvW
CSeq: 1 INVITE
Contact: <sip:Gu7AyiJg@127.0.0.1:10011;transport=tcp>
Content-Length: 236
Content-Type: application/sdp

v=0
o=- 1590581258 1590581258 IN IP4 127.0.0.1
s=-
c=IN IP4 127.0.0.1
t=0 0
m=audio 9999 RTP/AVP 0 8 96 101
a=rtpmap:0 PCMU/8000/1
a=rtpmap:8 PCMA/8000/1
a=rtpmap:96 opus/8000/2
a=rtpmap:101 telephone-event/8000/1
a=sendrecv