sip

package module
v0.0.0-...-9d926e1 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2015 License: MIT Imports: 16 Imported by: 0

README

sip

SIP in idiomatic Go

Documentation

Index

Constants

View Source
const (
	ACK       = "ACK"
	BYE       = "BYE"
	CANCEL    = "CANCEL"
	INVITE    = "INVITE"
	OPTIONS   = "OPTIONS"
	REGISTER  = "REGISTER"
	NOTIFY    = "NOTIFY"
	SUBSCRIBE = "SUBSCRIBE"
	MESSAGE   = "MESSAGE"
	REFER     = "REFER"
	INFO      = "INFO"
	PRACK     = "PRACK"
	UPDATE    = "UPDATE"
)
View Source
const (
	TRYING                             = 100
	RINGING                            = 180
	CALL_IS_BEING_FORWARDED            = 181
	QUEUED                             = 182
	SESSION_PROGRESS                   = 183
	OK                                 = 200
	ACCEPTED                           = 202
	MULTIPLE_CHOICES                   = 300
	MOVED_PERMANENTLY                  = 301
	MOVED_TEMPORARILY                  = 302
	USE_PROXY                          = 305
	ALTERNATIVE_SERVICE                = 380
	BAD_REQUEST                        = 400
	UNAUTHORIZED                       = 401
	PAYMENT_REQUIRED                   = 402
	FORBIDDEN                          = 403
	NOT_FOUND                          = 404
	METHOD_NOT_ALLOWED                 = 405
	NOT_ACCEPTABLE                     = 406
	PROXY_AUTHENTICATION_REQUIRED      = 407
	REQUEST_TIMEOUT                    = 408
	GONE                               = 410
	REQUEST_ENTITY_TOO_LARGE           = 413
	REQUEST_URI_TOO_LONG               = 414
	UNSUPPORTED_MEDIA_TYPE             = 415
	UNSUPPORTED_URI_SCHEME             = 416
	BAD_EXTENSION                      = 420
	EXTENSION_REQUIRED                 = 421
	INTERVAL_TOO_BRIEF                 = 423
	TEMPORARILY_UNAVAILABLE            = 480
	CALL_OR_TRANSACTION_DOES_NOT_EXIST = 481
	LOOP_DETECTED                      = 482
	TOO_MANY_HOPS                      = 483
	ADDRESS_INCOMPLETE                 = 484
	AMBIGUOUS                          = 485
	BUSY_HERE                          = 486
	REQUEST_TERMINATED                 = 487
	NOT_ACCEPTABLE_HERE                = 488
	BAD_EVENT                          = 489
	REQUEST_PENDING                    = 491
	UNDECIPHERABLE                     = 493
	SERVER_INTERNAL_ERROR              = 500
	NOT_IMPLEMENTED                    = 501
	BAD_GATEWAY                        = 502
	SERVICE_UNAVAILABLE                = 503
	SERVER_TIMEOUT                     = 504
	VERSION_NOT_SUPPORTED              = 505
	MESSAGE_TOO_LARGE                  = 513
	BUSY_EVERYWHERE                    = 600
	DECLINE                            = 603
	DOES_NOT_EXIST_ANYWHERE            = 604
	SESSION_NOT_ACCEPTABLE             = 606
)
View Source
const (
	TIMEOUT_RETRANSMIT  = iota //0
	TIMEOUT_TRANSACTION        //1
)
View Source
const (
	UDP  = "udp"
	TCP  = "tcp"
	TLS  = "tls"
	SCTP = "sctp"
)
View Source
const TimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT"

TimeFormat is the time format to use with time.Parse and time.Time.Format when parsing or generating times in HTTP headers. It is like time.RFC1123 but hard codes GMT as the time zone.

Variables

This section is empty.

Functions

func CanonicalHeaderKey

func CanonicalHeaderKey(s string) string

CanonicalHeaderKey returns the canonical format of the header key s. The canonicalization converts the first letter and any letter following a hyphen to upper case; the rest are converted to lowercase. For example, the canonical key for "accept-encoding" is "Accept-Encoding". If s contains a space or invalid header field bytes, it is returned without modifications.

func NewRequest

func NewRequest(method, requestURI string, body io.Reader) *request

func NewResponse

func NewResponse(statusCode int, reasonPhrase string, body io.Reader) *response

func ParseSIPVersion

func ParseSIPVersion(vers string) (major, minor int, ok bool)

ParseSIPVersion parses a SIP version string. "SIP/2.0" returns (2, 0, true).

func ParseTime

func ParseTime(text string) (t time.Time, err error)

ParseTime parses a time header (such as the Date: header), trying each of the three formats allowed by HTTP/1.1: TimeFormat, time.RFC850, and time.ANSIC.

Types

type ClientTransaction

type ClientTransaction interface {
	Transaction

	SendRequest() error
	CreateCancel() (Request, error)
	CreateAck() (Request, error)
}

type Dialog

type Dialog interface {
	GetLocalParty() string
	GetRemoteParty() string
	GetRemoteTarget() string
	GetDialogId() string
	GetCallId() string
	GetLocalSequenceNumber() int
	GetRemoteSequenceNumber() int
	GetRouteSet() []string
	IsSecure() bool
	IsServer() bool
	IncrementLocalSequenceNumber()
	CreateRequest(method string) (Request, error)
	SendRequest(ct ClientTransaction) error
	SendAck(ack Request) error
	GetState() DialogState
	Close()
	GetFirstTransaction() Transaction
	GetLocalTag() string
	GetRemoteTag() string
	SetApplicationData(applicationData interface{})
	GetApplicationData() interface{}
}

type DialogState

type DialogState int
const (
	DIALOGSTATE_EARLY      DialogState = iota //0
	DIALOGSTATE_CONFIRMED                     //1
	DIALOGSTATE_COMPLETED                     //2
	DIALOGSTATE_TERMINATED                    //3
)
type Header map[string][]string

A Header represents the key-value pairs in an HTTP header.

func (Header) Add

func (h Header) Add(key, value string)

Add adds the key, value pair to the header. It appends to any existing values associated with key.

func (Header) Del

func (h Header) Del(key string)

Del deletes the values associated with key.

func (Header) Get

func (h Header) Get(key string) string

Get gets the first value associated with the given key. If there are no values associated with the key, Get returns "". To access multiple values of a key, access the map directly with CanonicalHeaderKey.

func (Header) Set

func (h Header) Set(key, value string)

Set sets the header entries associated with key to the single element value. It replaces any existing values associated with key.

func (Header) Write

func (h Header) Write(w io.Writer) error

Write writes a header in wire format.

func (Header) WriteSubset

func (h Header) WriteSubset(w io.Writer, exclude map[string]bool) error

WriteSubset writes a header in wire format. If exclude is not nil, keys where exclude[key] == true are not written.

type Listener

type Listener interface {
	ProcessRequest(requestEvent RequestEvent)
	ProcessResponse(responseEvent ResponseEvent)
	ProcessTimeout(timeoutEvent TimeoutEvent)
}

type Message

type Message interface {
	StartLineWriter

	GetSIPVersion() string
	SetSIPVersion(string) error
	GetHeader() Header
	SetHeader(Header)
	GetContentLength() int64
	SetContentLength(l int64)
	GetBody() io.Reader
	SetBody(io.Reader)
	Write(io.Writer) error
}

func ReadMessage

func ReadMessage(b *bufio.Reader) (msg Message, err error)

ReadMessage reads and parses an incoming message from b.

type Provider

type Provider interface {
	AddTransport(Transport)
	RemoveTransport(Transport)

	AddListener(Listener)
	RemoveListener(Listener)

	GetNewCallId() string

	GetNewClientTransaction(Request) ClientTransaction
	GetNewServerTransaction(Request) ServerTransaction

	SendRequest(Request) error
	SendResponse(Response) error
}

type Request

type Request interface {
	Message

	GetMethod() string
	SetMethod(method string) error
	GetRequestURI() string
	SetRequestURI(uri string) error
}

type RequestEvent

type RequestEvent struct {
	// contains filtered or unexported fields
}

func NewRequestEvent

func NewRequestEvent(serverTransaction ServerTransaction, request Request) *RequestEvent

func (*RequestEvent) GetRequest

func (this *RequestEvent) GetRequest() Request

func (*RequestEvent) GetServerTransaction

func (this *RequestEvent) GetServerTransaction() ServerTransaction

type Response

type Response interface {
	Message

	SetStatusCode(statusCode int) error
	GetStatusCode() int
	SetReasonPhrase(reasonPhrase string) error
	GetReasonPhrase() string
}

type ResponseEvent

type ResponseEvent struct {
	// contains filtered or unexported fields
}

func NewResponseEvent

func NewResponseEvent(clientTransaction ClientTransaction, response Response) *ResponseEvent

func (*ResponseEvent) GetClientTransaction

func (this *ResponseEvent) GetClientTransaction() ClientTransaction

func (*ResponseEvent) GetResponse

func (this *ResponseEvent) GetResponse() Response

type ServerTransaction

type ServerTransaction interface {
	Transaction

	SendResponse(Response) error
}

type Stack

type Stack interface {
	CreateTransport(network string, address string, port int, tlsc *tls.Config) Transport
	GetTransports() []Transport
	DeleteTransport(t Transport)

	CreateProvider() Provider
	GetProviders() []Provider
	DeleteProvider(p Provider)

	Run()
	Stop()
}

func GetStack

func GetStack(tracer Tracer) Stack

type StartLineWriter

type StartLineWriter interface {
	StartLineWrite(io.Writer) error
}

type Timeout

type Timeout struct {
	// contains filtered or unexported fields
}

func NewTimeout

func NewTimeout(timeout int) *Timeout

func (*Timeout) GetValue

func (this *Timeout) GetValue() int

func (*Timeout) SetValue

func (this *Timeout) SetValue(timeout int)

func (*Timeout) String

func (this *Timeout) String() string

type TimeoutEvent

type TimeoutEvent struct {
	// contains filtered or unexported fields
}

func NewTimeoutEvent

func NewTimeoutEvent(transaction Transaction, timeout Timeout) *TimeoutEvent

func (*TimeoutEvent) GetTimeout

func (this *TimeoutEvent) GetTimeout() Timeout

func (*TimeoutEvent) GetTransaction

func (this *TimeoutEvent) GetTransaction() Transaction

func (*TimeoutEvent) IsServerTransaction

func (this *TimeoutEvent) IsServerTransaction() bool

type Tracer

type Tracer interface {
	Println(...interface{})
	Printf(string, ...interface{})
}

func TraceOff

func TraceOff() Tracer

func TraceOn

func TraceOn(w io.Writer) Tracer

type Transaction

type Transaction interface {
	GetDialog() Dialog
	GetState() TransactionState
	GetRetransmitTimer() int
	SetRetransmitTimer(retransmitTimer int)
	GetBranchId() string
	GetRequest() Request
	Close()
}

type TransactionState

type TransactionState int
const (
	TRANSACTIONSTATE_CALLING    TransactionState = iota //0
	TRANSACTIONSTATE_TRYING                             //1
	TRANSACTIONSTATE_PROCEEDING                         //2
	TRANSACTIONSTATE_COMPLETED                          //3
	TRANSACTIONSTATE_CONFIRMED                          //4
	TRANSACTIONSTATE_TERMINATED                         //5
)

type Transport

type Transport interface {
	GetNetwork() string //""udp", tcp", or "tls"...
	GetAddress() string
	GetPort() int
	GetTLSConfig() *tls.Config

	Dial() (net.Conn, error)

	Listen() error
	Accept() (net.Conn, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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