Documentation ¶
Index ¶
- Constants
- Variables
- type Attribute
- type AttributeSet
- type Element
- func (e *Element) AppendElement(element XElement)
- func (e *Element) AppendElements(elements []XElement)
- func (e *Element) Attributes() AttributeSet
- func (el *Element) BadRequestError() XElement
- func (e *Element) ClearElements()
- func (el *Element) ConflictError() XElement
- func (e *Element) Delay(from string, text string)
- func (e *Element) Elements() ElementSet
- func (e *Element) Error() XElement
- func (el *Element) FeatureNotImplementedError() XElement
- func (el *Element) ForbiddenError() XElement
- func (e *Element) From() string
- func (e *Element) FromGob(dec *gob.Decoder)
- func (el *Element) GoneError() XElement
- func (e *Element) ID() string
- func (el *Element) InternalServerError() XElement
- func (e *Element) IsError() bool
- func (e *Element) IsStanza() bool
- func (el *Element) ItemNotFoundError() XElement
- func (el *Element) JidMalformedError() XElement
- func (e *Element) Language() string
- func (e *Element) Name() string
- func (e *Element) Namespace() string
- func (el *Element) NotAcceptableError() XElement
- func (el *Element) NotAllowedError() XElement
- func (el *Element) NotAuthorizedError() XElement
- func (el *Element) PaymentRequiredError() XElement
- func (el *Element) RecipientUnavailableError() XElement
- func (el *Element) RedirectError() XElement
- func (el *Element) RegistrationRequiredError() XElement
- func (el *Element) RemoteServerNotFoundError() XElement
- func (el *Element) RemoteServerTimeoutError() XElement
- func (e *Element) RemoveAttribute(label string)
- func (e *Element) RemoveElements(name string)
- func (e *Element) RemoveElementsNamespace(name, namespace string)
- func (el *Element) ResourceConstraintError() XElement
- func (el *Element) ServiceUnavailableError() XElement
- func (e *Element) SetAttribute(label, value string)
- func (e *Element) SetFrom(from string)
- func (e *Element) SetID(identifier string)
- func (e *Element) SetLanguage(language string)
- func (e *Element) SetName(name string)
- func (e *Element) SetNamespace(namespace string)
- func (e *Element) SetText(text string)
- func (e *Element) SetTo(to string)
- func (e *Element) SetType(tp string)
- func (e *Element) SetVersion(version string)
- func (e *Element) String() string
- func (el *Element) SubscriptionRequiredError() XElement
- func (e *Element) Text() string
- func (e *Element) To() string
- func (e *Element) ToGob(enc *gob.Encoder)
- func (e *Element) ToXML(w io.Writer, includeClosing bool)
- func (e *Element) Type() string
- func (el *Element) UndefinedConditionError() XElement
- func (el *Element) UnexpectedConditionError() XElement
- func (e *Element) Version() string
- type ElementSet
- type IQ
- type Message
- func (m *Message) FromJID() *jid.JID
- func (m *Message) IsChat() bool
- func (m *Message) IsGroupChat() bool
- func (m *Message) IsHeadline() bool
- func (m *Message) IsMessageWithBody() bool
- func (m *Message) IsNormal() bool
- func (m *Message) SetFromJID(from *jid.JID)
- func (m *Message) SetToJID(to *jid.JID)
- func (m *Message) ToJID() *jid.JID
- type Parser
- type ParsingMode
- type Presence
- func (p *Presence) FromJID() *jid.JID
- func (p *Presence) IsAvailable() bool
- func (p *Presence) IsProbe() bool
- func (p *Presence) IsSubscribe() bool
- func (p *Presence) IsSubscribed() bool
- func (p *Presence) IsUnavailable() bool
- func (p *Presence) IsUnsubscribe() bool
- func (p *Presence) IsUnsubscribed() bool
- func (p *Presence) Priority() int8
- func (p *Presence) SetFromJID(from *jid.JID)
- func (p *Presence) SetToJID(to *jid.JID)
- func (p *Presence) ShowState() ShowState
- func (p *Presence) Status() string
- func (p *Presence) ToJID() *jid.JID
- type ShowState
- type Stanza
- type StanzaError
- type XElement
Constants ¶
const ( // GetType represents a 'get' IQ type. GetType = "get" // SetType represents a 'set' IQ type. SetType = "set" // ResultType represents a 'result' IQ type. ResultType = "result" )
const ( // NormalType represents a 'normal' message type. NormalType = "normal" // HeadlineType represents a 'headline' message type. HeadlineType = "headline" // ChatType represents a 'chat' message type. ChatType = "chat" // GroupChatType represents a 'groupchat' message type. GroupChatType = "groupchat" )
const ( // DefaultMode treats incoming elements as provided from raw byte reader. DefaultMode = ParsingMode(iota) // SocketStream treats incoming elements as provided from a socket transport. SocketStream // WebSocketStream treats incoming elements as provided from a websocket transport. WebSocketStream )
const ( // AvailableType represents an 'available' Presence type. AvailableType = "" UnavailableType = "unavailable" // SubscribeType represents a 'subscribe' Presence type. SubscribeType = "subscribe" // UnsubscribeType represents a 'unsubscribe' Presence type. UnsubscribeType = "unsubscribe" // SubscribedType represents a 'subscribed' Presence type. SubscribedType = "subscribed" // UnsubscribedType represents a 'unsubscribed' Presence type. UnsubscribedType = "unsubscribed" // ProbeType represents a 'probe' Presence type. ProbeType = "probe" )
const ErrorType = "error"
ErrorType represents an 'error' stanza type.
Variables ¶
var ( // ErrBadRequest is returned by the stream when the sender // has sent XML that is malformed or that cannot be processed. ErrBadRequest = newStanzaError(400, modifyErrorType, badRequestErrorReason) // ErrConflict is returned by the stream when access cannot be // granted because an existing resource or session exists with // the same name or address. ErrConflict = newStanzaError(409, cancelErrorType, conflictErrorReason) // ErrFeatureNotImplemented is returned by the stream when the feature // requested is not implemented by the server and therefore cannot be processed. ErrFeatureNotImplemented = newStanzaError(501, cancelErrorType, featureNotImplementedErrorReason) // ErrForbidden is returned by the stream when the requesting // entity does not possess the required permissions to perform the action. ErrForbidden = newStanzaError(403, authErrorType, forbiddenErrorReason) // ErrGone is returned by the stream when the recipient or server // can no longer be contacted at this address. ErrGone = newStanzaError(302, modifyErrorType, goneErrorReason) // ErrInternalServerError is returned by the stream when the server // could not process the stanza because of a misconfiguration // or an otherwise-undefined internal server error. ErrInternalServerError = newStanzaError(500, waitErrorType, internalServerErrorErrorReason) // ErrItemNotFound is returned by the stream when the addressed // JID or item requested cannot be found. ErrItemNotFound = newStanzaError(404, cancelErrorType, itemNotFoundErrorReason) // ErrJidMalformed is returned by the stream when the sending entity // has provided or communicated an XMPP address or aspect thereof that // does not adhere to the syntax defined in https://xmpp.org/rfcs/rfc3920.html#addressing. ErrJidMalformed = newStanzaError(400, modifyErrorType, jidMalformedErrorReason) // ErrNotAcceptable is returned by the stream when the server // understands the request but is refusing to process it because // it does not meet the defined criteria. ErrNotAcceptable = newStanzaError(406, modifyErrorType, notAcceptableErrorReason) // ErrNotAllowed is returned by the stream when the recipient // or server does not allow any entity to perform the action. ErrNotAllowed = newStanzaError(405, cancelErrorType, notAllowedErrorReason) // ErrNotAuthorized is returned by the stream when the sender // must provide proper credentials before being allowed to perform the action, // or has provided improper credentials. ErrNotAuthorized = newStanzaError(405, authErrorType, notAuthroizedErrorReason) // ErrPaymentRequired is returned by the stream when the requesting entity // is not authorized to access the requested service because payment is required. ErrPaymentRequired = newStanzaError(402, authErrorType, paymentRequiredErrorReason) // recipient is temporarily unavailable. ErrRecipientUnavailable = newStanzaError(404, waitErrorType, recipientUnavailableErrorReason) // ErrRedirect is returned by the stream when the recipient or server // is redirecting requests for this information to another entity, usually temporarily. ErrRedirect = newStanzaError(302, modifyErrorType, redirectErrorReason) // ErrRegistrationRequired is returned by the stream when the requesting entity // is not authorized to access the requested service because registration is required. ErrRegistrationRequired = newStanzaError(407, authErrorType, registrationRequiredErrorReason) // ErrRemoteServerNotFound is returned by the stream when a remote server // or service specified as part or all of the JID of the intended recipient does not exist. ErrRemoteServerNotFound = newStanzaError(404, cancelErrorType, remoteServerNotFoundErrorReason) // ErrRemoteServerTimeout is returned by the stream when a remote server // or service specified as part or all of the JID of the intended recipient // could not be contacted within a reasonable amount of time. ErrRemoteServerTimeout = newStanzaError(504, waitErrorType, remoteServerTimeoutErrorReason) // ErrResourceConstraint is returned by the stream when the server or recipient // lacks the system resources necessary to service the request. ErrResourceConstraint = newStanzaError(500, waitErrorType, resourceConstraintErrorReason) // does not currently provide the requested service. ErrServiceUnavailable = newStanzaError(503, cancelErrorType, serviceUnavailableErrorReason) // ErrSubscriptionRequired is returned by the stream when the requesting entity // is not authorized to access the requested service because a subscription is required. ErrSubscriptionRequired = newStanzaError(407, authErrorType, subscriptionRequiredErrorReason) // ErrUndefinedCondition is returned by the stream when the error condition // is not one of those defined by the other conditions in this list. ErrUndefinedCondition = newStanzaError(500, waitErrorType, undefinedConditionErrorReason) // ErrUnexpectedCondition is returned by the stream when the recipient or server // understood the request but was not expecting it at this time. ErrUnexpectedCondition = newStanzaError(400, waitErrorType, unexpectedConditionErrorReason) )
var ErrStreamClosedByPeer = errors.New("xml: stream closed by peer")
ErrStreamClosedByPeer is returned by Parse when peer closes the stream.
var ErrTooLargeStanza = errors.New("xml: too large stanza")
ErrTooLargeStanza is returned by ReadElement when the size of the incoming stanza is too large.
Functions ¶
This section is empty.
Types ¶
type AttributeSet ¶ added in v0.2.0
AttributeSet interface represents a read-only set of XML attributes.
type Element ¶
type Element struct {
// contains filtered or unexported fields
}
Element represents a generic and mutable XML node element.
func NewElementFromElement ¶
NewElementFromElement creates a mutable XML XElement by copying an element.
func NewElementName ¶
NewElementName creates a mutable XML XElement instance with a given name.
func NewElementNamespace ¶
NewElementNamespace creates a mutable XML XElement instance with a given name and namespace.
func NewErrorElementFromElement ¶ added in v0.2.0
func NewErrorElementFromElement(elem XElement, stanzaErr *StanzaError, errorElements []XElement) *Element
NewErrorElementFromElement returns a copy of an element of stanza error class.
func (*Element) AppendElement ¶ added in v0.2.0
AppendElement appends a new sub element.
func (*Element) AppendElements ¶ added in v0.2.0
AppendElements appends an array of sub elements.
func (*Element) Attributes ¶
func (e *Element) Attributes() AttributeSet
Attributes returns XML node attribute value.
func (*Element) BadRequestError ¶ added in v0.2.0
BadRequestError returns an error copy of the element attaching 'bad-request' error sub element.
func (*Element) ClearElements ¶ added in v0.2.0
func (e *Element) ClearElements()
ClearElements removes all elements.
func (*Element) ConflictError ¶ added in v0.2.0
ConflictError returns an error copy of the element attaching 'conflict' error sub element.
func (*Element) Elements ¶
func (e *Element) Elements() ElementSet
Elements returns all instance's child elements.
func (*Element) FeatureNotImplementedError ¶ added in v0.2.0
FeatureNotImplementedError returns an error copy of the element attaching 'feature-not-implemented' error sub element.
func (*Element) ForbiddenError ¶ added in v0.2.0
ForbiddenError returns an error copy of the element attaching 'forbidden' error sub element.
func (*Element) FromGob ¶ added in v0.2.0
FromGob deserializes an element node from it's gob binary representation.
func (*Element) GoneError ¶ added in v0.2.0
GoneError returns an error copy of the element attaching 'gone' error sub element.
func (*Element) InternalServerError ¶ added in v0.2.0
InternalServerError returns an error copy of the element attaching 'internal-server-error' error sub element.
func (*Element) IsError ¶ added in v0.2.0
IsError returns true if element has a 'type' attribute of value 'error'.
func (*Element) ItemNotFoundError ¶ added in v0.2.0
ItemNotFoundError returns an error copy of the element attaching 'item-not-found' error sub element.
func (*Element) JidMalformedError ¶ added in v0.2.0
JidMalformedError returns an error copy of the element attaching 'jid-malformed' error sub element.
func (*Element) NotAcceptableError ¶ added in v0.2.0
NotAcceptableError returns an error copy of the element attaching 'not-acceptable' error sub element.
func (*Element) NotAllowedError ¶ added in v0.2.0
NotAllowedError returns an error copy of the element attaching 'not-allowed' error sub element.
func (*Element) NotAuthorizedError ¶ added in v0.2.0
NotAuthorizedError returns an error copy of the element attaching 'not-authorized' error sub element.
func (*Element) PaymentRequiredError ¶ added in v0.2.0
PaymentRequiredError returns an error copy of the element attaching 'payment-required' error sub element.
func (*Element) RecipientUnavailableError ¶ added in v0.2.0
RecipientUnavailableError returns an error copy of the element attaching 'recipient-unavailable' error sub element.
func (*Element) RedirectError ¶ added in v0.2.0
RedirectError returns an error copy of the element attaching 'redirect' error sub element.
func (*Element) RegistrationRequiredError ¶ added in v0.2.0
RegistrationRequiredError returns an error copy of the element attaching 'registration-required' error sub element.
func (*Element) RemoteServerNotFoundError ¶ added in v0.2.0
RemoteServerNotFoundError returns an error copy of the element attaching 'remote-server-not-found' error sub element.
func (*Element) RemoteServerTimeoutError ¶ added in v0.2.0
RemoteServerTimeoutError returns an error copy of the element attaching 'remote-server-timeout' error sub element.
func (*Element) RemoveAttribute ¶ added in v0.2.0
RemoveAttribute removes an XML node attribute.
func (*Element) RemoveElements ¶ added in v0.2.0
RemoveElements removes all elements with a given name.
func (*Element) RemoveElementsNamespace ¶ added in v0.2.0
RemoveElementsNamespace removes all elements with a given name and namespace.
func (*Element) ResourceConstraintError ¶ added in v0.2.0
ResourceConstraintError returns an error copy of the element attaching 'resource-constraint' error sub element.
func (*Element) ServiceUnavailableError ¶ added in v0.2.0
ServiceUnavailableError returns an error copy of the element attaching 'service-unavailable' error sub element.
func (*Element) SetAttribute ¶ added in v0.2.0
SetAttribute sets an XML node attribute (label=value)
func (*Element) SetLanguage ¶ added in v0.2.0
SetLanguage sets 'xml:lang' node attribute.
func (*Element) SetNamespace ¶ added in v0.2.0
SetNamespace sets 'xmlns' node attribute.
func (*Element) SetVersion ¶ added in v0.2.0
SetVersion sets 'version' node attribute.
func (*Element) SubscriptionRequiredError ¶ added in v0.2.0
SubscriptionRequiredError returns an error copy of the element attaching 'subscription-required' error sub element.
func (*Element) ToGob ¶ added in v0.2.0
ToGob serializes an element node to it's gob binary representation.
func (*Element) ToXML ¶
ToXML serializes element to a raw XML representation. includeClosing determines if closing tag should be attached.
func (*Element) UndefinedConditionError ¶ added in v0.2.0
UndefinedConditionError returns an error copy of the element attaching 'undefined-condition' error sub element.
func (*Element) UnexpectedConditionError ¶ added in v0.2.0
UnexpectedConditionError returns an error copy of the element attaching 'unexpected-condition' error sub element.
type ElementSet ¶ added in v0.2.0
type ElementSet interface { // Children returns all elements identified by name. // Returns an empty array if no elements are found. Children(name string) []XElement // Child returns first element identified by name. // Returns nil if no element is found. Child(name string) XElement // ChildrenNamespace returns all elements identified by name and namespace. // Returns an empty array if no elements are found. ChildrenNamespace(name, namespace string) []XElement // ChildNamespace returns first element identified by name and namespace. // Returns nil if no element is found. ChildNamespace(name, namespace string) XElement // All returns a list of all child nodes. All() []XElement // Count returns child elements count. Count() int }
ElementSet interface represents a read-only set of XML sub elements.
type IQ ¶
type IQ struct { Element // contains filtered or unexported fields }
IQ type represents an <iq> element. All incoming <iq> elements providing from the stream will automatically be converted to IQ objects.
func NewIQFromElement ¶
NewIQFromElement creates an IQ object from XElement.
func (*IQ) SetFromJID ¶
SetFromJID sets the IQ 'from' JID value.
type Message ¶
type Message struct { Element // contains filtered or unexported fields }
Message type represents a <message> element. All incoming <message> elements providing from the stream will automatically be converted to Message objects.
func NewMessageFromElement ¶
NewMessageFromElement creates a Message object from XElement.
func NewMessageType ¶
NewMessageType creates and returns a new Message element.
func (*Message) IsGroupChat ¶
IsGroupChat returns true if this is a 'groupchat' type Message.
func (*Message) IsHeadline ¶
IsHeadline returns true if this is a 'headline' type Message.
func (*Message) IsMessageWithBody ¶
IsMessageWithBody returns true if the message has a body sub element.
func (*Message) SetFromJID ¶
SetFromJID sets the message 'from' JID value.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses arbitrary XML input and builds an array with the structure of all tag and data elements.
func NewParser ¶
func NewParser(reader io.Reader, mode ParsingMode, maxStanzaSize int) *Parser
NewParser creates an empty Parser instance.
func (*Parser) ParseElement ¶
ParseElement parses next available XML element from reader.
type ParsingMode ¶ added in v0.3.0
type ParsingMode int
ParsingMode defines the way in which special parsed element should be considered or not according to the reader nature.
type Presence ¶
type Presence struct { Element // contains filtered or unexported fields }
Presence type represents an <presence> element. All incoming <presence> elements providing from the stream will automatically be converted to Presence objects.
func NewPresence ¶
NewPresence creates and returns a new Presence element.
func NewPresenceFromElement ¶
NewPresenceFromElement creates a Presence object from XElement.
func (*Presence) IsAvailable ¶
IsAvailable returns true if this is an 'available' type Presence.
func (*Presence) IsProbe ¶ added in v0.3.0
IsProbe returns true if this is an 'probe' type Presence.
func (*Presence) IsSubscribe ¶
IsSubscribe returns true if this is a 'subscribe' type Presence.
func (*Presence) IsSubscribed ¶
IsSubscribed returns true if this is a 'subscribed' type Presence.
func (*Presence) IsUnavailable ¶
IsUnavailable returns true if this is an 'unavailable' type Presence.
func (*Presence) IsUnsubscribe ¶
IsUnsubscribe returns true if this is an 'unsubscribe' type Presence.
func (*Presence) IsUnsubscribed ¶
IsUnsubscribed returns true if this is an 'unsubscribed' type Presence.
func (*Presence) SetFromJID ¶
SetFromJID sets the presence 'from' JID value.
type ShowState ¶
type ShowState int
ShowState represents Presence show state.
const ( // AvailableShowState represents 'available' Presence show state. AvailableShowState ShowState = iota // AwayShowState represents 'away' Presence show state. AwayShowState // ChatShowState represents 'chat' Presence show state. ChatShowState // DoNotDisturbShowState represents 'dnd' Presence show state. DoNotDisturbShowState // ExtendedAwaysShowState represents 'xa' Presence show state. ExtendedAwaysShowState )
type StanzaError ¶
type StanzaError struct {
// contains filtered or unexported fields
}
StanzaError represents a stanza "error" element.
func (*StanzaError) Element ¶
func (se *StanzaError) Element() *Element
Element returns StanzaError equivalent XML element.
type XElement ¶ added in v0.2.0
type XElement interface { fmt.Stringer Name() string Attributes() AttributeSet Elements() ElementSet Text() string ID() string Namespace() string Language() string Version() string From() string To() string Type() string IsStanza() bool IsError() bool Error() XElement ToXML(w io.Writer, includeClosing bool) ToGob(enc *gob.Encoder) }
XElement represents a generic XML node element.