forked from jshiffer/go-xmpp
commit
4e8e43b7ca
26
xmpp.go
26
xmpp.go
@ -501,15 +501,14 @@ func (c *Client) startStream(o *Options, domain string) (*streamFeatures, error)
|
|||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsEncrypted will return true if the client is connected using a TLS transport, either because it used
|
// IsEncrypted will return true if the client is connected using a TLS transport, either because it used.
|
||||||
// TLS to connect from the outset, or because it successfully used STARTTLS to promote a TCP connection
|
// TLS to connect from the outset, or because it successfully used STARTTLS to promote a TCP connection to TLS.
|
||||||
// to TLS.
|
|
||||||
func (c *Client) IsEncrypted() bool {
|
func (c *Client) IsEncrypted() bool {
|
||||||
_, ok := c.conn.(*tls.Conn)
|
_, ok := c.conn.(*tls.Conn)
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chat is an incoming or outgoing XMPP chat message
|
// Chat is an incoming or outgoing XMPP chat message.
|
||||||
type Chat struct {
|
type Chat struct {
|
||||||
Remote string
|
Remote string
|
||||||
Type string
|
Type string
|
||||||
@ -517,7 +516,7 @@ type Chat struct {
|
|||||||
Other []string
|
Other []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Presence is an XMPP presence message
|
// Presence is an XMPP presence notification.
|
||||||
type Presence struct {
|
type Presence struct {
|
||||||
From string
|
From string
|
||||||
To string
|
To string
|
||||||
@ -525,8 +524,9 @@ type Presence struct {
|
|||||||
Show string
|
Show string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recv wait next token of chat.
|
// Recv waits to receive the next XMPP stanza.
|
||||||
func (c *Client) Recv() (event interface{}, err error) {
|
// Return type is either a presence notification or a chat message.
|
||||||
|
func (c *Client) Recv() (stanza interface{}, err error) {
|
||||||
for {
|
for {
|
||||||
_, val, err := next(c.p)
|
_, val, err := next(c.p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -542,10 +542,9 @@ func (c *Client) Recv() (event interface{}, err error) {
|
|||||||
panic("unreachable")
|
panic("unreachable")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send sends message text.
|
// Send sends the message wrapped inside an XMPP message stanza body.
|
||||||
func (c *Client) Send(chat Chat) (n int, err error) {
|
func (c *Client) Send(chat Chat) (n int, err error) {
|
||||||
return fmt.Fprintf(c.conn, "<message to='%s' type='%s' xml:lang='en'>"+
|
return fmt.Fprintf(c.conn, "<message to='%s' type='%s' xml:lang='en'>"+"<body>%s</body></message>",
|
||||||
"<body>%s</body></message>",
|
|
||||||
xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text))
|
xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -570,7 +569,6 @@ type streamError struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RFC 3920 C.3 TLS name space
|
// RFC 3920 C.3 TLS name space
|
||||||
|
|
||||||
type tlsStartTLS struct {
|
type tlsStartTLS struct {
|
||||||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-tls starttls"`
|
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-tls starttls"`
|
||||||
Required *string `xml:"required"`
|
Required *string `xml:"required"`
|
||||||
@ -585,7 +583,6 @@ type tlsFailure struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RFC 3920 C.4 SASL name space
|
// RFC 3920 C.4 SASL name space
|
||||||
|
|
||||||
type saslMechanisms struct {
|
type saslMechanisms struct {
|
||||||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl mechanisms"`
|
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl mechanisms"`
|
||||||
Mechanism []string `xml:"mechanism"`
|
Mechanism []string `xml:"mechanism"`
|
||||||
@ -616,7 +613,6 @@ type saslFailure struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RFC 3920 C.5 Resource binding name space
|
// RFC 3920 C.5 Resource binding name space
|
||||||
|
|
||||||
type bindBind struct {
|
type bindBind struct {
|
||||||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-bind bind"`
|
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-bind bind"`
|
||||||
Resource string
|
Resource string
|
||||||
@ -624,7 +620,6 @@ type bindBind struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RFC 3921 B.1 jabber:client
|
// RFC 3921 B.1 jabber:client
|
||||||
|
|
||||||
type clientMessage struct {
|
type clientMessage struct {
|
||||||
XMLName xml.Name `xml:"jabber:client message"`
|
XMLName xml.Name `xml:"jabber:client message"`
|
||||||
From string `xml:"from,attr"`
|
From string `xml:"from,attr"`
|
||||||
@ -632,8 +627,7 @@ type clientMessage struct {
|
|||||||
To string `xml:"to,attr"`
|
To string `xml:"to,attr"`
|
||||||
Type string `xml:"type,attr"` // chat, error, groupchat, headline, or normal
|
Type string `xml:"type,attr"` // chat, error, groupchat, headline, or normal
|
||||||
|
|
||||||
// These should technically be []clientText,
|
// These should technically be []clientText, but string is much more convenient.
|
||||||
// but string is much more convenient.
|
|
||||||
Subject string `xml:"subject"`
|
Subject string `xml:"subject"`
|
||||||
Body string `xml:"body"`
|
Body string `xml:"body"`
|
||||||
Thread string `xml:"thread"`
|
Thread string `xml:"thread"`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user