internal

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2019 License: BSD-2-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package internal provides non-exported functionality used by xmpp and its child packages.

Index

Constants

View Source
const IDLen = 16

IDLen is the standard length of stanza identifiers in bytes.

View Source
const (
	// XMLHeader is an XML header like the one in encoding/xml but without a
	// newline at the end.
	XMLHeader = `<?xml version="1.0" encoding="UTF-8"?>`
)

Variables

View Source
var (
	DefaultVersion = Version{1, 0} // The default version to send.
	EmptyVersion   = Version{0, 9} // The value of a missing version attribute.
)

Common XMPP versions.

Functions

func GetAttr

func GetAttr(attr []xml.Attr, local string) string

GetAttr returns the value of the first attribute with the provided local name from a list of attributes or an empty string if no such attribute exists.

func RandomID

func RandomID() string

RandomID generates a new random identifier of length IDLen. If the OS's entropy pool isn't initialized, or we can't generate random numbers for some other reason, panic.

Types

type StreamInfo added in v0.1.0

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

StreamInfo contains metadata extracted from a stream start token.

func ExpectNewStream added in v0.1.0

func ExpectNewStream(ctx context.Context, d xml.TokenReader, recv bool) (streamData StreamInfo, err error)

ExpectNewStream reads a token from d and expects that it will be a new stream start token. If not, an error is returned. It then handles feature negotiation for the new stream. If an XML header is discovered instead, it is skipped.

func SendNewStream added in v0.1.0

func SendNewStream(rw io.ReadWriter, s2s bool, version Version, lang string, location, origin, id string) (StreamInfo, error)

SendNewStream sends a new XML header followed by a stream start element on the given io.Writer. We don't use an xml.Encoder both because Go's standard library xml package really doesn't like the namespaced stream:stream attribute and because we can guarantee well-formedness of the XML with a print in this case and printing is much faster than encoding. Afterwards, clear the StreamRestartRequired bit and set the output stream information.

type Version

type Version struct {
	Major uint8
	Minor uint8
}

Version is a version of XMPP.

func MustParseVersion

func MustParseVersion(s string) Version

MustParseVersion parses a version string and panics if an error is returned.

func ParseVersion

func ParseVersion(s string) (Version, error)

ParseVersion parses a string of the form "Major.Minor" into a Version struct or returns an error.

func (Version) Less

func (v Version) Less(b Version) bool

Less compares the major and minor version numbers, returning true if a is less than b.

func (Version) MarshalXMLAttr

func (v Version) MarshalXMLAttr(name xml.Name) (xml.Attr, error)

MarshalXMLAttr satisfies the MarshalerAttr interface and marshals the version as an XML attribute using its string representation.

func (Version) String

func (v Version) String() string

Prints a string representation of the XMPP version in the form "Major.Minor".

func (*Version) UnmarshalXMLAttr

func (v *Version) UnmarshalXMLAttr(attr xml.Attr) error

UnmarshalXMLAttr satisfies the UnmarshalerAttr interface and unmarshals an XML attribute into a valid XMPP version (or returns an error).

Directories

Path Synopsis
Package discover is used to look up information about XMPP-based services.
Package discover is used to look up information about XMPP-based services.
Package ns provides namespace constants that are used by the xmpp package and other internal packages.
Package ns provides namespace constants that are used by the xmpp package and other internal packages.
Package saslerr provides error conditions for the XMPP profile of SASL as defined by RFC 6120 §6.5.
Package saslerr provides error conditions for the XMPP profile of SASL as defined by RFC 6120 §6.5.
Package xmpptest provides utilities for XMPP testing.
Package xmpptest provides utilities for XMPP testing.

Jump to

Keyboard shortcuts

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