Documentation ¶
Overview ¶
Forked from github.com/StefanKopieczek/gossip by @StefanKopieczek
Forked from github.com/StefanKopieczek/gossip by @StefanKopieczek
Index ¶
- func GetNextHeaderLine(contents []string) (headerText string, consumed int)
- func ParseAddressValue(addressText string) (displayName sip.MaybeString, uri sip.Uri, headerParams sip.Params, err error)
- func ParseAddressValues(addresses string) (displayNames []sip.MaybeString, uris []sip.Uri, headerParams []sip.Params, ...)
- func ParseHostPort(rawText string) (host string, port *sip.Port, err error)
- func ParseMessage(msgData []byte, logger log.Logger) (sip.Message, error)
- func ParseParams(source string, start uint8, sep uint8, end uint8, quoteValues bool, ...) (params sip.Params, consumed int, err error)
- func ParseRequestLine(requestLine string) (method sip.RequestMethod, recipient sip.Uri, sipVersion string, err error)
- func ParseSipUri(uriStr string) (uri sip.SipUri, err error)
- func ParseStatusLine(statusLine string) (sipVersion string, statusCode sip.StatusCode, reasonPhrase string, err error)
- func ParseUri(uriStr string) (uri sip.Uri, err error)
- func SplitByWhitespace(text string) []string
- type Error
- type HeaderParser
- type InvalidMessageFormat
- type InvalidStartLineError
- type PacketParser
- type Parser
- type WriteError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetNextHeaderLine ¶
Extract the next logical header line from the message. This may run over several actual lines; lines that start with whitespace are a continuation of the previous line. Therefore also return how many lines we consumed so the parent parser can keep track of progress through the message.
func ParseAddressValue ¶
func ParseAddressValue(addressText string) ( displayName sip.MaybeString, uri sip.Uri, headerParams sip.Params, err error, )
ParseAddressValue parses an address - such as from a From, To, or Contact header. It returns:
- a MaybeString containing the display name (or not)
- a parsed SipUri object
- a map containing any header parameters present
- the error object
See RFC 3261 section 20.10 for details on parsing an address. Note that this method will not accept a comma-separated list of addresses; addresses in that form should be handled by ParseAddressValues.
func ParseAddressValues ¶
func ParseAddressValues(addresses string) ( displayNames []sip.MaybeString, uris []sip.Uri, headerParams []sip.Params, err error, )
ParseAddressValues parses a comma-separated list of addresses, returning any display names and header params, as well as the SIP URIs themselves. ParseAddressValues is aware of < > bracketing and quoting, and will not break on commas within these structures.
func ParseHostPort ¶
Parse a text representation of a host[:port] pair. The port may or may not be present, so we represent it with a *uint16, and return 'nil' if no port was present.
func ParseMessage ¶
Parse a SIP message by creating a parser on the fly. This is more costly than reusing a parser, but is necessary when we do not have a guarantee that all messages coming over a connection are from the same endpoint (e.g. UDP).
func ParseParams ¶
func ParseParams( source string, start uint8, sep uint8, end uint8, quoteValues bool, permitSingletons bool, ) (params sip.Params, consumed int, err error)
General utility method for parsing 'key=value' parameters. Takes a string (source), ensures that it begins with the 'start' character provided, and then parses successive key/value pairs separated with 'sep', until either 'end' is reached or there are no characters remaining. A map of keys to values will be returned, along with the number of characters consumed. Provide 0 for start or end to indicate that there is no starting/ending delimiter. If quoteValues is true, values can be enclosed in double-quotes which will be validated by the parser and omitted from the returned map. If permitSingletons is true, keys with no values are permitted. These will result in a nil value in the returned map.
func ParseRequestLine ¶
func ParseRequestLine(requestLine string) ( method sip.RequestMethod, recipient sip.Uri, sipVersion string, err error)
Parse the first line of a SIP request, e.g:
INVITE bob@example.com SIP/2.0 REGISTER jane@telco.com SIP/1.0
func ParseSipUri ¶
ParseSipUri converts a string representation of a SIP or SIPS URI into a SipUri object.
func ParseStatusLine ¶
func ParseStatusLine(statusLine string) ( sipVersion string, statusCode sip.StatusCode, reasonPhrase string, err error)
Parse the first line of a SIP response, e.g:
SIP/2.0 200 OK SIP/1.0 403 Forbidden
func ParseUri ¶
parseUri converts a string representation of a URI into a Uri object. If the URI is malformed, or the URI schema is not recognised, an error is returned. URIs have the general form of schema:address.
func SplitByWhitespace ¶
Splits the given string into sections, separated by one or more characters from c_ABNF_WS.
Types ¶
type HeaderParser ¶
A HeaderParser is any function that turns raw header data into one or more Header objects. The HeaderParser will receive arguments of the form ("max-forwards", "70"). It should return a slice of headers, which should have length > 1 unless it also returns an error.
type InvalidMessageFormat ¶
type InvalidMessageFormat string
func (InvalidMessageFormat) Broken ¶
func (err InvalidMessageFormat) Broken() bool
func (InvalidMessageFormat) Error ¶
func (err InvalidMessageFormat) Error() string
func (InvalidMessageFormat) Malformed ¶
func (err InvalidMessageFormat) Malformed() bool
func (InvalidMessageFormat) Syntax ¶
func (err InvalidMessageFormat) Syntax() bool
type InvalidStartLineError ¶
type InvalidStartLineError string
func (InvalidStartLineError) Broken ¶
func (err InvalidStartLineError) Broken() bool
func (InvalidStartLineError) Error ¶
func (err InvalidStartLineError) Error() string
func (InvalidStartLineError) Malformed ¶
func (err InvalidStartLineError) Malformed() bool
func (InvalidStartLineError) Syntax ¶
func (err InvalidStartLineError) Syntax() bool
type PacketParser ¶
type PacketParser struct {
// contains filtered or unexported fields
}
func NewPacketParser ¶
func NewPacketParser(logger log.Logger) *PacketParser
func (*PacketParser) ParseMessage ¶
func (pp *PacketParser) ParseMessage(msgData []byte) (sip.Message, error)
func (*PacketParser) Stop ¶
func (pp *PacketParser) Stop()
type Parser ¶
type Parser interface { // Implements io.Writer. Queues the given bytes to be parsed. // If the parser has terminated due to a previous fatal error, it will return n=0 and an appropriate error. // Otherwise, it will return n=len(p) and err=nil. // Note that err=nil does not indicate that the data provided is valid - simply that the data was successfully queued for parsing. Write(p []byte) (n int, err error) // Register a custom header parser for a particular header type. // This will overwrite any existing registered parser for that header type. // If a parser is not available for a header type in a message, the parser will produce a core.GenericHeader struct. SetHeaderParser(headerName string, headerParser HeaderParser) Stop() String() string // Reset resets parser state Reset() ParseHeader(headerText string) (headers []sip.Header, err error) }
A Parser converts the raw bytes of SIP messages into core.Message objects. It allows
func NewParser ¶
func NewParser( output chan<- sip.Message, errs chan<- error, streamed bool, logger log.Logger, ) Parser
'streamed' should be set to true whenever the caller cannot reliably identify the starts and ends of messages from the transport frames, e.g. when using streamed protocols such as TCP.
type WriteError ¶
type WriteError string
func (WriteError) Error ¶
func (err WriteError) Error() string
func (WriteError) Syntax ¶
func (err WriteError) Syntax() bool