2016-06-22 09:48:40 -07:00
|
|
|
package xmpp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
const IQTypeGet = "get"
|
|
|
|
const IQTypeSet = "set"
|
|
|
|
const IQTypeResult = "result"
|
|
|
|
|
|
|
|
func (c *Client) Discovery() (string, error) {
|
|
|
|
const namespace = "http://jabber.org/protocol/disco#items"
|
|
|
|
// use getCookie for a pseudo random id.
|
|
|
|
reqID := strconv.FormatUint(uint64(getCookie()), 10)
|
|
|
|
return c.RawInformationQuery(c.jid, c.domain, reqID, IQTypeGet, namespace, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
// RawInformationQuery sends an information query request to the server.
|
|
|
|
func (c *Client) RawInformationQuery(from, to, id, iqType, requestNamespace, body string) (string, error) {
|
|
|
|
const xmlIQ = "<iq from='%s' to='%s' id='%s' type='%s'><query xmlns='%s'>%s</query></iq>"
|
2023-03-01 20:22:44 -08:00
|
|
|
_, err := fmt.Fprintf(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) {
|
|
|
|
const xmlIQ = "<iq from='%s' to='%s' id='%s' type='%s'>%s</iq>"
|
2023-03-01 20:22:44 -08:00
|
|
|
_, err := fmt.Fprintf(StanzaWriter, xmlIQ, xmlEscape(from), xmlEscape(to), id, iqType, body)
|
2017-11-15 00:47:24 -08:00
|
|
|
return id, err
|
|
|
|
}
|