Move some functions to go-xmpp, update deps, more lining
This commit is contained in:
57
vendor/github.com/eleksir/go-xmpp/xmpp_error.go
generated
vendored
Normal file
57
vendor/github.com/eleksir/go-xmpp/xmpp_error.go
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
package xmpp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// ErrorServiceUnavailable implements error response about feature that is not available. Currently implemented for
|
||||
// xep-0030.
|
||||
// QueryXmlns is about incoming xmlns attribute in query tag.
|
||||
// Node is about incoming node attribute in query tag (looks like it used only in disco#commands).
|
||||
//
|
||||
// If queried feature is not here on purpose, standards suggest answer with this stanza.
|
||||
func (c *Client) ErrorServiceUnavailable(v IQ, queryXmlns, node string) (string, error) {
|
||||
query := fmt.Sprintf("<query xmlns=\"%s\" ", queryXmlns)
|
||||
|
||||
if node != "" {
|
||||
query += fmt.Sprintf("node=\"%s\" />", node)
|
||||
} else {
|
||||
query += "/>"
|
||||
}
|
||||
|
||||
query += "<error type=\"cancel\">"
|
||||
query += "<service-unavailable xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\" />"
|
||||
query += "</error>"
|
||||
|
||||
return c.RawInformation(
|
||||
v.To,
|
||||
v.From,
|
||||
v.ID,
|
||||
IQTypeError,
|
||||
query,
|
||||
)
|
||||
}
|
||||
|
||||
// ErrorNotImplemented implements error response about feature that is not (yet?) implemented.
|
||||
// Xmlns is about not implemented feature.
|
||||
//
|
||||
// If queried feature is not here because of it under development or for similar reasons, standards suggest answer with
|
||||
// this stanza.
|
||||
func (c *Client) ErrorNotImplemented(v IQ, xmlns, feature string) (string, error) {
|
||||
query := "<error type=\"cancel\">"
|
||||
query += "<feature-not-implemented xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\" />"
|
||||
query += fmt.Sprintf(
|
||||
"<unsupported xmlns=\"%s\" feature=\"%s\" />",
|
||||
xmlns,
|
||||
feature,
|
||||
)
|
||||
query += "</error>"
|
||||
|
||||
return c.RawInformation(
|
||||
v.To,
|
||||
v.From,
|
||||
v.ID,
|
||||
IQTypeError,
|
||||
query,
|
||||
)
|
||||
}
|
||||
75
vendor/github.com/eleksir/go-xmpp/xmpp_information_query.go
generated
vendored
75
vendor/github.com/eleksir/go-xmpp/xmpp_information_query.go
generated
vendored
@@ -3,6 +3,7 @@ package xmpp
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
const IQTypeGet = "get"
|
||||
@@ -16,24 +17,24 @@ func (c *Client) Discovery() (string, error) {
|
||||
return c.RawInformationQuery(c.jid, c.domain, reqID, IQTypeGet, XMPPNS_DISCO_ITEMS, "")
|
||||
}
|
||||
|
||||
// Discover information about a node. Empty node queries info about server itself.
|
||||
// DiscoverNodeInfo discovers information about a node. Empty node queries info about server itself.
|
||||
func (c *Client) DiscoverNodeInfo(node string) (string, error) {
|
||||
query := fmt.Sprintf("<query xmlns='%s' node='%s'/>", XMPPNS_DISCO_INFO, node)
|
||||
return c.RawInformation(c.jid, c.domain, "info3", IQTypeGet, query)
|
||||
}
|
||||
|
||||
// Discover information about given item from given jid.
|
||||
// DiscoverInfo discovers information about given item from given jid.
|
||||
func (c *Client) DiscoverInfo(from string, to string) (string, error) {
|
||||
query := fmt.Sprintf("<query xmlns='%s'/>", XMPPNS_DISCO_INFO)
|
||||
return c.RawInformation(from, to, "info3", IQTypeGet, query)
|
||||
}
|
||||
|
||||
// Discover items that the server exposes
|
||||
// DiscoverServerItems discover items that the server exposes
|
||||
func (c *Client) DiscoverServerItems() (string, error) {
|
||||
return c.DiscoverEntityItems(c.domain)
|
||||
}
|
||||
|
||||
// Discover items that an entity exposes
|
||||
// DiscoverEntityItems discovers items that an entity exposes.
|
||||
func (c *Client) DiscoverEntityItems(jid string) (string, error) {
|
||||
query := fmt.Sprintf("<query xmlns='%s'/>", XMPPNS_DISCO_ITEMS)
|
||||
return c.RawInformation(c.jid, jid, "info1", IQTypeGet, query)
|
||||
@@ -46,9 +47,73 @@ func (c *Client) RawInformationQuery(from, to, id, iqType, requestNamespace, bod
|
||||
return id, err
|
||||
}
|
||||
|
||||
// rawInformation send a IQ request with the payload body to the server
|
||||
// RawInformation sends a IQ request with the payload body to the server.
|
||||
func (c *Client) RawInformation(from, to, id, iqType, body string) (string, error) {
|
||||
const xmlIQ = "<iq from='%s' to='%s' id='%s' type='%s'>%s</iq>"
|
||||
_, err := fmt.Fprintf(StanzaWriter, xmlIQ, xmlEscape(from), xmlEscape(to), id, iqType, body)
|
||||
return id, err
|
||||
}
|
||||
|
||||
// IqVersionResponse responding with software version, according to xep-0092.
|
||||
func (c *Client) IqVersionResponse(v IQ, name, version, os string) (string, error) {
|
||||
if name == "" {
|
||||
name = "go-xmpp"
|
||||
}
|
||||
|
||||
if version == "" {
|
||||
version = "undefined"
|
||||
}
|
||||
|
||||
query := "<query xmlns=\"jabber:iq:version\">" //nolint:wsl
|
||||
query += fmt.Sprintf("<name>%s</name>", name)
|
||||
query += fmt.Sprintf("<version>%s</version>", version)
|
||||
|
||||
if os != "" {
|
||||
query += fmt.Sprintf("<os>%s</os>", os)
|
||||
}
|
||||
|
||||
query += "</query>"
|
||||
|
||||
return c.RawInformation(
|
||||
v.To,
|
||||
v.From,
|
||||
v.ID,
|
||||
IQTypeResult,
|
||||
query,
|
||||
)
|
||||
}
|
||||
|
||||
// JabberIqLastResponse responding with relative time since last activity.
|
||||
// Here lastActivity is unix time stamp when last activity took place since.
|
||||
func (c *Client) JabberIqLastResponse(v IQ, lastActivity int64) (string, error) {
|
||||
query := fmt.Sprintf(
|
||||
"<query xmlns=\"jabber:iq:last\" seconds=\"%d\" />",
|
||||
time.Now().Unix()-lastActivity,
|
||||
)
|
||||
|
||||
return c.RawInformation(
|
||||
v.To,
|
||||
v.From,
|
||||
v.ID,
|
||||
IQTypeResult,
|
||||
query,
|
||||
)
|
||||
}
|
||||
|
||||
// UrnXmppTimeResponse implements response to query entity's current time (xep-0202).
|
||||
// TimezoneOffset have format +HH:MM or -HH:MM
|
||||
func (c *Client) UrnXmppTimeResponse(v IQ, timezoneOffset string) (string, error) {
|
||||
query := fmt.Sprintf(
|
||||
"<time xmlns=\"urn:xmpp:time\"><tzo>%s</tzo><utc>%s</utc></time>",
|
||||
timezoneOffset,
|
||||
time.Now().UTC().Format(time.RFC3339),
|
||||
)
|
||||
|
||||
return c.RawInformation(
|
||||
v.To,
|
||||
v.From,
|
||||
v.ID,
|
||||
IQTypeResult,
|
||||
query,
|
||||
)
|
||||
}
|
||||
|
||||
11
vendor/github.com/eleksir/go-xmpp/xmpp_ping.go
generated
vendored
11
vendor/github.com/eleksir/go-xmpp/xmpp_ping.go
generated
vendored
@@ -31,3 +31,14 @@ func (c *Client) SendResultPing(id, toServer string) error {
|
||||
xmlEscape(toServer), xmlEscape(id))
|
||||
return err
|
||||
}
|
||||
|
||||
// PingResponse responding to ping query according to xep-0199
|
||||
func (c *Client) PingResponse(v IQ) (string, error) {
|
||||
return c.RawInformation(
|
||||
v.To,
|
||||
v.From,
|
||||
v.ID,
|
||||
IQTypeResult,
|
||||
"",
|
||||
)
|
||||
}
|
||||
|
||||
16
vendor/github.com/eleksir/go-xmpp/xmpp_pubsub.go
generated
vendored
16
vendor/github.com/eleksir/go-xmpp/xmpp_pubsub.go
generated
vendored
@@ -106,28 +106,28 @@ func pubsubUnsubscriptionStanza(node, jid string) string {
|
||||
return pubsubStanza(body)
|
||||
}
|
||||
|
||||
func (c *Client) PubsubSubscribeNode(node, jid string) {
|
||||
c.RawInformation(c.jid,
|
||||
func (c *Client) PubsubSubscribeNode(node, jid string) (string, error) {
|
||||
return c.RawInformation(c.jid,
|
||||
jid,
|
||||
"sub1",
|
||||
"set",
|
||||
pubsubSubscriptionStanza(node, c.jid))
|
||||
}
|
||||
|
||||
func (c *Client) PubsubUnsubscribeNode(node, jid string) {
|
||||
c.RawInformation(c.jid,
|
||||
func (c *Client) PubsubUnsubscribeNode(node, jid string) (string, error) {
|
||||
return c.RawInformation(c.jid,
|
||||
jid,
|
||||
"unsub1",
|
||||
"set",
|
||||
pubsubUnsubscriptionStanza(node, c.jid))
|
||||
}
|
||||
|
||||
func (c *Client) PubsubRequestLastItems(node, jid string) {
|
||||
func (c *Client) PubsubRequestLastItems(node, jid string) (string, error) {
|
||||
body := fmt.Sprintf("<items node='%s'/>", node)
|
||||
c.RawInformation(c.jid, jid, "items1", "get", pubsubStanza(body))
|
||||
return c.RawInformation(c.jid, jid, "items1", "get", pubsubStanza(body))
|
||||
}
|
||||
|
||||
func (c *Client) PubsubRequestItem(node, jid, id string) {
|
||||
func (c *Client) PubsubRequestItem(node, jid, id string) (string, error) {
|
||||
body := fmt.Sprintf("<items node='%s'><item id='%s'/></items>", node, id)
|
||||
c.RawInformation(c.jid, jid, "items3", "get", pubsubStanza(body))
|
||||
return c.RawInformation(c.jid, jid, "items3", "get", pubsubStanza(body))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user