xmpp

package module
v0.0.0-...-c0a0d10 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: MIT Imports: 13 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Authenticate

func Authenticate(conn *XMPPConnection, username, password string) error

Authenticate performs SASL PLAIN authentication with the XMPP server.

func BindResource

func BindResource(conn *XMPPConnection) error

func CreateUser

func CreateUser(conn *XMPPConnection, username, password string) error

func StartTLS

func StartTLS(conn *XMPPConnection) error

StartTLS sends the STARTTLS command to the server and upgrades the connection to TLS.

Types

type AuthRequest

type AuthRequest struct {
	XMLName   xml.Name `xml:"auth"`
	Mechanism string   `xml:"mechanism,attr"`
	Text      string   `xml:",chardata"`
}

func (*AuthRequest) ToXML

func (a *AuthRequest) ToXML() (string, error)

type ChatWindow

type ChatWindow struct {
	Window      fyne.Window
	ChatContent *fyne.Container
	Handler     *XMPPHandler
	Recipient   string
}

func (*ChatWindow) AddMessage

func (cw *ChatWindow) AddMessage(msg *Message)

type IQ

type IQ struct {
	XMLName xml.Name    `xml:"iq"`
	From    string      `xml:"from,attr,omitempty"`
	To      string      `xml:"to,attr,omitempty"`
	Type    string      `xml:"type,attr"`
	ID      string      `xml:"id,attr"`
	Query   interface{} `xml:",omitempty"`
}

func NewIQ

func NewIQ(iqType, iqID string) *IQ

func (*IQ) SetQuery

func (iq *IQ) SetQuery(query interface{})

func (*IQ) ToXML

func (iq *IQ) ToXML() (string, error)

type IQItem

type IQItem struct {
	JID          string `xml:"jid,attr"`
	Name         string `xml:"name,attr,omitempty"`
	Subscription string `xml:"subscription,attr"`
}

type Message

type Message struct {
	XMLName xml.Name `xml:"message"`
	To      string   `xml:"to,attr,omitempty"`
	From    string   `xml:"from,attr,omitempty"`
	Type    string   `xml:"type,attr,omitempty"`
	Body    string   `xml:"body,omitempty"`
	Subject string   `xml:"subject,omitempty"`
	Thread  string   `xml:"thread,omitempty"`
}

Message represents an XMPP message stanza.

func NewMessage

func NewMessage(to, msgType, body string) *Message

NewMessage creates a new message with the specified type, recipient, and body.

func ParseMessage

func ParseMessage(data []byte) (*Message, error)

ParseMessage parses an XML string into a Message struct.

func (*Message) IsChatMessage

func (m *Message) IsChatMessage() bool

IsChatMessage checks if the message is of type "chat".

func (*Message) IsErrorMessage

func (m *Message) IsErrorMessage() bool

IsErrorMessage checks if the message is of type "error".

func (*Message) IsGroupChatMessage

func (m *Message) IsGroupChatMessage() bool

IsGroupChatMessage checks if the message is of type "groupchat".

func (*Message) ToXML

func (m *Message) ToXML() (string, error)

ToXML converts the Message struct to an XML string.

type Presence

type Presence struct {
	XMLName  xml.Name `xml:"presence"`
	From     string   `xml:"from,attr,omitempty"`
	To       string   `xml:"to,attr,omitempty"`
	Type     string   `xml:"type,attr,omitempty"` // "available", "unavailable", "subscribe", etc.
	Show     string   `xml:"show,omitempty"`      // "chat", "away", "dnd", "xa" (extended away)
	Status   string   `xml:"status,omitempty"`    // User-defined status message
	Priority int      `xml:"priority,omitempty"`  // Priority level (-128 to +127)
}

Presence represents an XMPP presence stanza.

func NewPresence

func NewPresence(to, presenceType, show, status string, priority int) *Presence

NewPresence creates a new presence stanza with the specified parameters.

func ParsePresence

func ParsePresence(data []byte) (*Presence, error)

ParsePresence parses an XML string into a Presence struct.

func (*Presence) HasStatus

func (p *Presence) HasStatus() bool

func (*Presence) IsAvailable

func (p *Presence) IsAvailable() bool

IsAvailable checks if the presence type is "available".

func (*Presence) IsSubscriptionRequest

func (p *Presence) IsSubscriptionRequest() bool

IsSubscriptionRequest checks if the presence type is "subscribe" or "subscribed".

func (*Presence) IsUnavailable

func (p *Presence) IsUnavailable() bool

IsUnavailable checks if the presence type is "unavailable".

func (*Presence) ToXML

func (p *Presence) ToXML() (string, error)

ToXML converts the Presence struct to an XML string.

type RawXML

type RawXML []byte

type RegisterRequest

type RegisterRequest struct {
	XMLName  xml.Name `xml:"query"`
	XMLNS    string   `xml:"xmlns,attr"`
	Username string   `xml:"username"`
	Password string   `xml:"password"`
}

type Stanza

type Stanza interface {
	ToXML() (string, error)
}

func ParseStanza

func ParseStanza(data []byte) (Stanza, error)

type XMPPConnection

type XMPPConnection struct {
	Conn   net.Conn
	Domain string
}

func NewXMPPConnection

func NewXMPPConnection(domain string, port string, useTLS bool) (*XMPPConnection, error)

func (*XMPPConnection) Close

func (xc *XMPPConnection) Close() error

func (*XMPPConnection) CloseStream

func (xc *XMPPConnection) CloseStream() error

func (*XMPPConnection) StartStream

func (xc *XMPPConnection) StartStream(domain string) error

type XMPPHandler

type XMPPHandler struct {
	Conn          *XMPPConnection
	Server        string
	Username      string
	Password      string
	ChatWindows   map[string]*ChatWindow
	MessageChan   chan *Message
	MessageQueue  map[string][]*Message
	PresenceStack map[string]*Presence
	VCardStack    map[string]*IQ
}

func NewXMPPHandler

func NewXMPPHandler(domain, port, username, password string) (*XMPPHandler, error)

func (*XMPPHandler) DispatchMessage

func (h *XMPPHandler) DispatchMessage(msg *Message)

func (*XMPPHandler) HandleIncomingStanzas

func (h *XMPPHandler) HandleIncomingStanzas() error

func (*XMPPHandler) ListenForIncomingStanzas

func (h *XMPPHandler) ListenForIncomingStanzas()

func (*XMPPHandler) LoginAndFetchMessages

func (h *XMPPHandler) LoginAndFetchMessages(status string) error

func (*XMPPHandler) PromptSubscriptionRequest

func (h *XMPPHandler) PromptSubscriptionRequest(from string)

func (*XMPPHandler) RequestOfflineMessages

func (h *XMPPHandler) RequestOfflineMessages() error

func (*XMPPHandler) SendMessage

func (h *XMPPHandler) SendMessage(to, message string) error

SendMessage sends a message stanza to the specified recipient.

func (*XMPPHandler) SendPresence

func (h *XMPPHandler) SendPresence(presenceType, status string) error

SendPresence sends a presence stanza to update the user's availability status.

func (*XMPPHandler) WaitForShutdown

func (h *XMPPHandler) WaitForShutdown()

WaitForShutdown keeps the connection alive until shutdown is requested.

Jump to

Keyboard shortcuts

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