sip

package
Version: v0.0.0-...-4e7924e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2020 License: Apache-2.0 Imports: 8 Imported by: 10

Documentation

Index

Constants

View Source
const (
	MethodInvite    = "INVITE"    // Indicates a client is being invited to participate in a call session.
	MethodAck       = "ACK"       // Confirms that the client has received a final response to an INVITE request.
	MethodBye       = "BYE"       // Terminates a call and can be sent by either the caller or the callee.
	MethodCancel    = "CANCEL"    // Cancels any pending request.
	MethodOptions   = "OPTIONS"   // Queries the capabilities of servers.
	MethodRegister  = "REGISTER"  // Registers the address listed in the To header field with a SIP server.
	MethodPrack     = "PRACK"     // Provisional acknowledgement.
	MethodSubscribe = "SUBSCRIBE" // Subscribes for an Event of Notification from the Notifier.
	MethodNotify    = "NOTIFY"    // Notify the subscriber of a new Event.
	MethodPublish   = "PUBLISH"   // Publishes an event to the Server.
	MethodInfo      = "INFO"      // Sends mid-session information that does not modify the session state.
	MethodRefer     = "REFER"     // Asks recipient to issue SIP request (call transfer.)
	MethodMessage   = "MESSAGE"   // Transports instant messages using SIP.
	MethodUpdate    = "UPDATE"    // Modifies the state of a session without changing the state of the dialog.
)
View Source
const (
	// 1xx: Provisional -- request received, continuing to process the request.
	StatusTrying               = 100 // Indicates server is not totally pwnd.
	StatusRinging              = 180 // Remote phone is definitely ringing.
	StatusCallIsBeingForwarded = 181
	StatusQueued               = 182
	StatusSessionProgress      = 183 // Establish early media (PSTN ringback)

	// 2xx: Success -- the action was successfully received, understood,
	//      and accepted;
	StatusOK             = 200 // Call is answered
	StatusAccepted       = 202 // [RFC3265]
	StatusNoNotification = 204 // [RFC5839]

	// 3xx: Redirection -- further action needs to be taken in order to
	//      complete the request;
	StatusMultipleChoices    = 300
	StatusMovedPermanently   = 301
	StatusMovedTemporarily   = 302 // Send your call there instead kthx.
	StatusUseProxy           = 305 // You fool! Send your call there instead.
	StatusAlternativeService = 380

	// 4xx: Client Error -- the request contains bad syntax or cannot be
	//      fulfilled at this server;
	StatusBadRequest                   = 400 // Missing headers, bad format, etc.
	StatusUnauthorized                 = 401 // Resend request with auth header.
	StatusPaymentRequired              = 402 // I am greedy.
	StatusForbidden                    = 403 // gtfo
	StatusNotFound                     = 404 // wat?
	StatusMethodNotAllowed             = 405 // I don't support that type of request.
	StatusNotAcceptable                = 406
	StatusProxyAuthenticationRequired  = 407
	StatusRequestTimeout               = 408
	StatusConflict                     = 409
	StatusGone                         = 410 // Shaniqua don't live here no more.
	StatusLengthRequired               = 411
	StatusConditionalRequestFailed     = 412 // [RFC3903]
	StatusRequestEntityTooLarge        = 413
	StatusRequestURITooLong            = 414
	StatusUnsupportedMediaType         = 415
	StatusUnsupportedURIScheme         = 416
	StatusUnknownResourcePriority      = 417
	StatusBadExtension                 = 420
	StatusExtensionRequired            = 421
	StatusSessionIntervalTooSmall      = 422 // [RFC4028]
	StatusIntervalTooBrief             = 423
	StatusUseIdentityHeader            = 428 // [RFC4474]
	StatusProvideReferrerIdentity      = 429 // [RFC3892]
	StatusFlowFailed                   = 430 // [RFC5626]
	StatusAnonymityDisallowed          = 433 // [RFC5079]
	StatusBadIdentityInfo              = 436 // [RFC4474]
	StatusUnsupportedCertificate       = 437 // [RFC4474]
	StatusInvalidIdentityHeader        = 438 // [RFC4474]
	StatusFirstHopLacksOutboundSupport = 439 // [RFC5626]
	StatusMaxBreadthExceeded           = 440 // [RFC5393]
	StatusConsentNeeded                = 470 // [RFC5360]
	StatusTemporarilyUnavailable       = 480 // fast busy or soft fail
	StatusCallTransactionDoesNotExist  = 481 // Bad news
	StatusLoopDetected                 = 482 // Froot looping
	StatusTooManyHops                  = 483 // Froot looping
	StatusAddressIncomplete            = 484
	StatusAmbiguous                    = 485
	StatusBusyHere                     = 486
	StatusRequestTerminated            = 487
	StatusNotAcceptableHere            = 488
	StatusBadEvent                     = 489 // [RFC3265]
	StatusRequestPending               = 491
	StatusUndecipherable               = 493
	StatusSecurityAgreementRequired    = 494 // [RFC3329]

	// 5xx: Server Error -- the server failed to fulfill an apparently
	//      valid request;
	StatusInternalServerError = 500
	StatusNotImplemented      = 501
	StatusBadGateway          = 502
	StatusServiceUnavailable  = 503
	StatusGatewayTimeout      = 504
	StatusVersionNotSupported = 505
	StatusMessageTooLarge     = 513
	StatusPreconditionFailure = 580 // [RFC3312]

	// 6xx: Global Failure -- the request cannot be fulfilled at any
	//      server.
	StatusBusyEverywhere       = 600
	StatusDecline              = 603
	StatusDoesNotExistAnywhere = 604
	StatusNotAcceptable606     = 606
	StatusDialogTerminated     = 687
)

Variables

This section is empty.

Functions

func Phrase

func Phrase(status int) string

Types

type Addr

type Addr struct {
	Uri     *URI   // never nil
	Display string // blank if not specified
	Param   *Param // these look like ;key=lol;rport;key=wut
	Next    *Addr  // for comma separated lists of addresses
}

Represents a SIP Address Linked List

func (*Addr) Append

func (addr *Addr) Append(b *bytes.Buffer)

Reassembles a SIP address into a buffer.

func (*Addr) CompareHostPort

func (addr *Addr) CompareHostPort(other *Addr) bool

func (*Addr) Copy

func (addr *Addr) Copy() *Addr

Deep copies a new Addr object.

func (*Addr) Last

func (addr *Addr) Last() *Addr

Returns pointer to last addr in linked list.

func (*Addr) Len

func (addr *Addr) Len() int

Returns number of items in the linked list.

func (*Addr) Or

func (addr *Addr) Or(other *Addr) *Addr

Returns self if non-nil, otherwise other.

func (*Addr) Reversed

func (addr *Addr) Reversed() *Addr

Returns self with linked list reversed.

func (*Addr) String

func (addr *Addr) String() string

func (*Addr) Tag

func (addr *Addr) Tag() *Addr

Sets newly generated tag ID and returns self.

type MiscPayload

type MiscPayload struct {
	T string
	D []byte
}

func (*MiscPayload) ContentType

func (p *MiscPayload) ContentType() string

func (*MiscPayload) Data

func (p *MiscPayload) Data() []byte

type Msg

type Msg struct {
	// Fields that aren't headers.
	VersionMajor uint8
	VersionMinor uint8
	Method       string  // Indicates type of request (if request)
	Request      *URI    // dest URI (nil if response)
	Status       int     // Indicates happiness of response (if response)
	Phrase       string  // Explains happiness of response (if response)
	Payload      Payload // Stuff that comes after two line breaks

	// Special non-SIP fields.
	SourceAddr *net.UDPAddr // Set by transport layer as received address.

	// Important headers should be further up in the struct.
	From        *Addr  // Logical sender of message
	To          *Addr  // Logical destination of message
	Via         *Via   // Linked list of agents traversed (must have one)
	Route       *Addr  // Used for goose routing and loose routing
	RecordRoute *Addr  // Used for loose routing
	Contact     *Addr  // Where we send response packets or nil
	CallID      string // Identifies call from invite to bye
	CSeq        int    // Counter for network packet ordering
	CSeqMethod  string // Helps with matching to orig message
	MaxForwards int    // 0 has context specific meaning
	UserAgent   string

	// All the other RFC 3261 headers in plus some extras.
	Accept             string
	AcceptContact      string
	AcceptEncoding     string
	AcceptLanguage     string
	AlertInfo          string
	Allow              string
	AllowEvents        string
	AuthenticationInfo string
	Authorization      string
	CallInfo           string
	ContentDisposition string
	ContentEncoding    string
	ContentLanguage    string
	Date               string
	ErrorInfo          string
	Event              string
	Expires            int // Seconds registration should expire.
	InReplyTo          string
	MIMEVersion        string
	MinExpires         int // Registrars need this when responding
	Organization       string
	PAssertedIdentity  *Addr // P-Asserted-Identity or nil (used for PSTN ANI)
	Priority           string
	ProxyAuthenticate  string
	ProxyAuthorization string
	ProxyRequire       string
	ReferTo            string
	ReferredBy         string
	RemotePartyID      *Addr // Evil twin of P-Asserted-Identity.
	ReplyTo            string
	Require            string
	RetryAfter         string
	Server             string
	Subject            string
	Supported          string
	Timestamp          string
	Unsupported        string
	WWWAuthenticate    string
	Warning            string

	// Extension headers.
	XHeader *XHeader
}

Msg represents a SIP message. This can either be a request or a response. These fields are never nil unless otherwise specified.

func ParseMsg

func ParseMsg(data []byte) (msg *Msg, err error)

ParseMsg turns a SIP message byte slice into a data structure.

func (*Msg) Append

func (msg *Msg) Append(b *bytes.Buffer)

I turn a SIP message back into a packet.

func (*Msg) Copy

func (msg *Msg) Copy() *Msg

func (*Msg) IsResponse

func (msg *Msg) IsResponse() bool

func (*Msg) String

func (msg *Msg) String() string

type MsgIncompleteError

type MsgIncompleteError struct {
	Msg []byte
}

func (MsgIncompleteError) Error

func (err MsgIncompleteError) Error() string

type MsgParseError

type MsgParseError struct {
	Msg    []byte
	Offset int
}

func (MsgParseError) Error

func (err MsgParseError) Error() string

type Param

type Param struct {
	Name  string
	Value string
	Next  *Param
}

Param is a linked list of ;key="values" for Addr/Via parameters.

func (*Param) Append

func (p *Param) Append(b *bytes.Buffer)

Append serializes parameters in insertion order.

func (*Param) Get

func (p *Param) Get(name string) *Param

Get returns an entry in O(n) time.

type Payload

type Payload interface {
	ContentType() string
	Data() []byte
}

type ResponseError

type ResponseError struct {
	Msg *Msg
}

ResponseError encapsulates an unhandled >=400 SIP error response.

func (*ResponseError) Error

func (err *ResponseError) Error() string

type URI

type URI struct {
	Scheme string     // e.g. sip, sips, tel, etc.
	User   string     // e.g. sip:USER@host
	Pass   string     // e.g. sip:user:PASS@host
	Host   string     // e.g. example.com, 1.2.3.4, etc.
	Port   uint16     // e.g. 5060, 80, etc.
	Param  *URIParam  // e.g. ;isup-oli=00;day=tuesday
	Header *URIHeader // e.g. ?subject=project%20x&lol=cat
}

func ParseURI

func ParseURI(data []byte) (uri *URI, err error)

ParseURI turns a a SIP URI byte slice into a data structure.

func (*URI) Append

func (uri *URI) Append(b *bytes.Buffer)

func (*URI) CompareHostPort

func (uri *URI) CompareHostPort(other *URI) bool

func (*URI) Copy

func (uri *URI) Copy() *URI

Deep copies a URI object.

func (*URI) GetPort

func (uri *URI) GetPort() uint16

func (*URI) String

func (uri *URI) String() string

type URIHeader

type URIHeader struct {
	Name  string
	Value string
	Next  *URIHeader
}

URIHeader is a linked list of ?key=values for URI headers.

func (*URIHeader) Append

func (p *URIHeader) Append(b *bytes.Buffer)

Append serializes URI headers in insertion order.

func (*URIHeader) Get

func (p *URIHeader) Get(name string) *URIHeader

Get returns an entry in O(n) time.

type URIParam

type URIParam struct {
	Name  string
	Value string
	Next  *URIParam
}

URIParam is a linked list of ;key=values for URI parameters.

func (*URIParam) Append

func (p *URIParam) Append(b *bytes.Buffer)

Append serializes URI parameters in insertion order.

func (*URIParam) Get

func (p *URIParam) Get(name string) *URIParam

Get returns an entry in O(n) time.

type Via

type Via struct {
	Protocol  string // should be "SIP"
	Version   string // protocol version e.g. "2.0"
	Transport string // transport type "UDP"
	Host      string // name or ip of egress interface
	Port      uint16 // network port number
	Param     *Param // param like branch, received, rport, etc.
	Next      *Via   // pointer to next via header if any
}

Example: SIP/2.0/UDP 1.2.3.4:5060;branch=z9hG4bK556f77e6.

func (*Via) Append

func (via *Via) Append(b *bytes.Buffer)

func (*Via) Branch

func (via *Via) Branch() *Via

Branch adds a randomly generated branch ID.

func (*Via) CompareBranch

func (via *Via) CompareBranch(other *Via) bool

func (*Via) CompareHostPort

func (via *Via) CompareHostPort(other *Via) bool

func (*Via) Copy

func (via *Via) Copy() *Via

Copy returns a deep copy of via.

func (*Via) Detach

func (via *Via) Detach() *Via

Detach returns a shallow copy of via with Next set to nil.

func (*Via) Last

func (via *Via) Last() *Via

Last returns pointer to last via in linked list.

type XHeader

type XHeader struct {
	Name  string // tokenc
	Value []byte // UTF8, never nil
	Next  *XHeader
}

XHeader is a linked list storing an unrecognized SIP headers.

func (*XHeader) Append

func (h *XHeader) Append(b *bytes.Buffer)

Append serializes headers in insertion order.

func (*XHeader) Get

func (h *XHeader) Get(name string) *XHeader

Get returns an entry in O(n) time.

func (*XHeader) String

func (h *XHeader) String() string

String turns XHeader into a string.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL