2016-06-22 09:48:40 -07:00
|
|
|
package xmpp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
2024-01-31 21:54:58 -08:00
|
|
|
const (
|
|
|
|
IQTypeGet = "get"
|
|
|
|
IQTypeSet = "set"
|
|
|
|
IQTypeResult = "result"
|
|
|
|
)
|
2016-06-22 09:48:40 -07:00
|
|
|
|
|
|
|
func (c *Client) Discovery() (string, error) {
|
2024-04-09 01:53:38 -07:00
|
|
|
// use UUIDv4 for a pseudo random id.
|
2016-06-22 09:48:40 -07:00
|
|
|
reqID := strconv.FormatUint(uint64(getCookie()), 10)
|
2023-03-01 20:23:29 -08:00
|
|
|
return c.RawInformationQuery(c.jid, c.domain, reqID, IQTypeGet, XMPPNS_DISCO_ITEMS, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Discover information about a node
|
|
|
|
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 items that the server exposes
|
|
|
|
func (c *Client) DiscoverServerItems() (string, error) {
|
|
|
|
return c.DiscoverEntityItems(c.domain)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Discover 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)
|
2016-06-22 09:48:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// RawInformationQuery sends an information query request to the server.
|
|
|
|
func (c *Client) RawInformationQuery(from, to, id, iqType, requestNamespace, body string) (string, error) {
|
2023-08-14 01:28:33 -07:00
|
|
|
const xmlIQ = "<iq from='%s' to='%s' id='%s' type='%s'><query xmlns='%s'>%s</query></iq>\n"
|
2023-07-28 07:42:12 -07:00
|
|
|
_, err := fmt.Fprintf(c.stanzaWriter, xmlIQ, xmlEscape(from), xmlEscape(to), id, iqType, requestNamespace, body)
|
2016-06-22 09:48:40 -07:00
|
|
|
return id, err
|
|
|
|
}
|
2017-11-15 00:47:24 -08:00
|
|
|
|
2021-07-22 19:55:38 -07:00
|
|
|
// rawInformation send a IQ request with the payload body to the server
|
2017-11-15 00:47:24 -08:00
|
|
|
func (c *Client) RawInformation(from, to, id, iqType, body string) (string, error) {
|
2023-08-14 01:28:33 -07:00
|
|
|
const xmlIQ = "<iq from='%s' to='%s' id='%s' type='%s'>%s</iq>\n"
|
2023-07-28 07:42:12 -07:00
|
|
|
_, err := fmt.Fprintf(c.stanzaWriter, xmlIQ, xmlEscape(from), xmlEscape(to), id, iqType, body)
|
2017-11-15 00:47:24 -08:00
|
|
|
return id, err
|
|
|
|
}
|