Documentation ¶
Overview ¶
Package sipnet contains tools for connecting and communicating to SIP UAs.
Index ¶
- Constants
- Variables
- func Dial(addr, transport string) (net.Conn, error)
- func ParseList(value string) []string
- func ParseUserHeader(h Header) (User, User, error)
- func StatusText(code int) string
- type Conn
- type Flushable
- type Header
- type HeaderArgs
- type Listener
- type Request
- type Response
- type URI
- type User
- type Via
Constants ¶
const ( MethodInvite = "INVITE" MethodAck = "ACK" MethodBye = "BYE" MethodCancel = "CANCEL" MethodRegister = "REGISTER" MethodOptions = "OPTIONS" MethodInfo = "INFO" )
SIP request methods.
const ( StatusTrying = 100 StatusRinging = 180 StatusCallIsBeingForwarded = 181 StatusQueued = 182 StatusSessionProgress = 183 StatusOK = 200 StatusMultipleChoices = 300 StatusMovedPermanently = 301 StatusMovedTemporarily = 302 StatusUseProxy = 305 StatusAlternativeService = 380 StatusBadRequest = 400 StatusPaymentRequired = 402 StatusForbidden = 403 StatusNotFound = 404 StatusMethodNotAllowed = 405 StatusNotAcceptable = 406 StatusProxyAuthenticationRequired = 407 StatusRequestTimeout = 408 StatusGone = 410 StatusRequestEntityTooLarge = 413 StatusRequestURITooLong = 414 StatusUnsupportedMediaType = 415 StatusUnsupportedURIScheme = 416 StatusBadExtension = 420 StatusExtensionRequired = 421 StatusIntervalTooBrief = 423 StatusNoResponse = 480 StatusCallTransactionDoesNotExist = 481 StatusLoopDetected = 482 StatusTooManyHops = 483 StatusAddressIncomplete = 484 StatusAmbigious = 485 StatusBusyHere = 486 StatusRequestTerminated = 487 StatusNotAcceptableHere = 488 StatusRequestPending = 491 StatusUndecipherable = 493 StatusServerInternalError = 500 StatusNotImplemented = 501 StatusBadGateway = 502 StatusServerTimeout = 504 StatusVersionNotSupported = 505 StatusMessageTooLarge = 513 StatusBusyEverywhere = 600 StatusDecline = 603 StatusDoesNotExistAnywhere = 604 StatusUnacceptable = 606 )
SIP response status codes.
const SIPVersion = "SIP/2.0"
SIPVersion is the version of SIP used by this library.
Variables ¶
var ErrBadMessage = errors.New("sip: bad message")
ErrBadMessage is returned by ReadRequest and ReadResponse if the message received failed to be parsed.
var ErrClosed = errors.New("sip: closed")
ErrClosed is returned if AcceptRequest is called on a closed listener. io.EOF may also be returned on a closed underlying connection, in which the connection itself will also be returned.
var ErrInvalidTransport = errors.New("sip: invalid transport")
ErrInvalidTransport is returned by Dial if the transport provided is invalid.
var ErrParseError = errors.New("sip: parse error")
ErrParseError is returned when a piece of data fails to be parsed (i.e. a user line or via).
Functions ¶
func Dial ¶
Dial creates a connection to a SIP UA. It does NOT "dial" a user. addr is an IP:port string, transport is the transport protocol to be used, (i.e. "tcp" or "udp").
After dialling, you should use ReadResponse to read from the connection, and Request.WriteTo to write requests to the connection.
func ParseList ¶
ParseList parses a comma, semicolon, or new line separated list of values and returns list elements.
Lifted from https://code.google.com/p/gorilla/source/browse/http/parser/parser.go which was ported from urllib2.parse_http_list, from the Python standard library.
func ParseUserHeader ¶
ParseUserHeader returns the parsed users from the From, and the To fields respectively from the header.
func StatusText ¶
StatusText returns the human readable text representation of a status code.
Types ¶
type Conn ¶
type Conn struct { Transport string Listener *Listener Conn net.Conn Address net.Addr UdpReceiver chan []byte Closed bool Locked bool WriteBuffer *bytes.Buffer ReadMessage chan interface{} LastMessage time.Time ReceivedBranches map[string]time.Time BranchMutex *sync.Mutex }
Conn represents a connection with a UA. It can be on UDP or TCP.
func (*Conn) Flush ¶
Flush flushes the buffered data to be written. In the case of using UDP, the buffered data will be written in a single UDP packet.
func (*Conn) Lock ¶
func (c *Conn) Lock()
Lock must be called to use Read(). It locks the connection to be read by the user rather than by read by AcceptRequest().
func (*Conn) Read ¶
func (c *Conn) Read() interface{}
Read reads either a *Request, a *Response, or an error from the connection.
type Flushable ¶
type Flushable interface {
Flush() error
}
Flushable is used by Request.WriteTo to determine whether or not the provided connection is flushable, and if so, writes and then flushes it.
type Header ¶
Header represents the headers of a SIP Request or Response.
func (Header) Del ¶
Del deletes the key and its value from the header. Deleting a non-existent key is a no-op.
type HeaderArgs ¶
HeaderArgs represents the arguments which can be found in headers, and in other simple key value fields whose format is of a key=value with a delimiter.
func ParseHeaderArgs ¶
func ParseHeaderArgs(str string) HeaderArgs
ParseHeaderArgs parses header arguments from a full header.
func ParsePairs ¶
func ParsePairs(value string) HeaderArgs
ParsePairs extracts key/value pairs from comma, semicolon, or new line separated values.
Lifted from https://code.google.com/p/gorilla/source/browse/http/parser/parser.go
func (HeaderArgs) CRLFString ¶
func (h HeaderArgs) CRLFString() string
CRLFString returns the header arguments as a CRLF separated string.
func (HeaderArgs) CommaString ¶
func (h HeaderArgs) CommaString() string
CommaString returns the header arguments as a comma and space separated string.
func (HeaderArgs) Del ¶
func (h HeaderArgs) Del(key string)
Del deletes the key and its value from the header arguments. Deleting a non-existent key is a no-op.
func (HeaderArgs) Get ¶
func (h HeaderArgs) Get(key string) string
Get returns the value at a given key. It returns an empty string if the key does not exist.
func (HeaderArgs) SemicolonString ¶
func (h HeaderArgs) SemicolonString() string
SemicolonString returns the header arguments as a semicolon separated unquoted strings with a leading semicolon.
func (HeaderArgs) Set ¶
func (h HeaderArgs) Set(key, value string)
Set sets a header argument key with a value.
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener represents a TCP and UDP wrapper listener.
func (*Listener) AcceptRequest ¶
AcceptRequest blocks until it receives a Request message on either TCP or UDP listeners. Responses are to be written to *Conn (and then flushed).
type Request ¶
Request represents a SIP request (i.e. a message sent by a UAC to a UAS).
func ReadRequest ¶
ReadRequest reads a SIP request (i.e. message from a UAC) from a reader.
type Response ¶
Response represents a SIP response (i.e. a message sent by a UAS to a UAC).
func ReadResponse ¶
ReadResponse reads a SIP response (i.e. message from a UAS) from a reader.
func (*Response) BadRequest ¶
BadRequest responds to a Conn with a StatusBadRequest for convenience.
func (*Response) ServerError ¶
ServerError responds to a Conn with a StatusServerInternalError for convenience.
type URI ¶
type URI struct { Scheme string Username string Domain string Arguments HeaderArgs }
URI represents a Uniform Resource Identifier.
func (URI) SchemeUserDomain ¶
SchemeUserDomain returns the text representation of the scheme:user@domain.
func (URI) String ¶
String returns the full text representation of the URI with additional semicolon arguments.
func (URI) UserDomain ¶
UserDomain returns the text representation of user@domain.
type User ¶
type User struct { Name string URI URI Arguments HeaderArgs }
User represents a SIP user.