forked from jshiffer/go-xmpp
commit
31c7eb6919
2
xmpp.go
2
xmpp.go
@ -511,7 +511,7 @@ func (c *Client) init(o *Options) error {
|
|||||||
} else {
|
} else {
|
||||||
clientFirstMessage = "n,,n=" + user + ",r=" + clientNonce
|
clientFirstMessage = "n,,n=" + user + ",r=" + clientNonce
|
||||||
}
|
}
|
||||||
fmt.Fprintf(c.stanzaWriter, "<auth xmlns='%s' mechanism='%s'>%s</auth>",
|
fmt.Fprintf(c.stanzaWriter, "<auth xmlns='%s' mechanism='%s'>%s</auth>\n",
|
||||||
nsSASL, mechanism, base64.StdEncoding.EncodeToString([]byte(clientFirstMessage)))
|
nsSASL, mechanism, base64.StdEncoding.EncodeToString([]byte(clientFirstMessage)))
|
||||||
var sfm string
|
var sfm string
|
||||||
if err = c.p.DecodeElement(&sfm, nil); err != nil {
|
if err = c.p.DecodeElement(&sfm, nil); err != nil {
|
||||||
|
@ -34,14 +34,14 @@ func (c *Client) DiscoverEntityItems(jid string) (string, error) {
|
|||||||
|
|
||||||
// RawInformationQuery sends an information query request to the server.
|
// RawInformationQuery sends an information query request to the server.
|
||||||
func (c *Client) RawInformationQuery(from, to, id, iqType, requestNamespace, body string) (string, error) {
|
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>"
|
const xmlIQ = "<iq from='%s' to='%s' id='%s' type='%s'><query xmlns='%s'>%s</query></iq>\n"
|
||||||
_, err := fmt.Fprintf(c.stanzaWriter, xmlIQ, xmlEscape(from), xmlEscape(to), id, iqType, requestNamespace, body)
|
_, err := fmt.Fprintf(c.stanzaWriter, xmlIQ, xmlEscape(from), xmlEscape(to), id, iqType, requestNamespace, body)
|
||||||
return id, err
|
return id, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// rawInformation send a IQ request with the payload body to the server
|
// rawInformation send a IQ request with the payload body to the server
|
||||||
func (c *Client) RawInformation(from, to, id, iqType, body string) (string, error) {
|
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>"
|
const xmlIQ = "<iq from='%s' to='%s' id='%s' type='%s'>%s</iq>\n"
|
||||||
_, err := fmt.Fprintf(c.stanzaWriter, xmlIQ, xmlEscape(from), xmlEscape(to), id, iqType, body)
|
_, err := fmt.Fprintf(c.stanzaWriter, xmlIQ, xmlEscape(from), xmlEscape(to), id, iqType, body)
|
||||||
return id, err
|
return id, err
|
||||||
}
|
}
|
||||||
|
88
xmpp_muc.go
88
xmpp_muc.go
@ -25,7 +25,7 @@ const (
|
|||||||
|
|
||||||
// Send sends room topic wrapped inside an XMPP message stanza body.
|
// Send sends room topic wrapped inside an XMPP message stanza body.
|
||||||
func (c *Client) SendTopic(chat Chat) (n int, err error) {
|
func (c *Client) SendTopic(chat Chat) (n int, err error) {
|
||||||
return fmt.Fprintf(c.stanzaWriter, "<message to='%s' type='%s' xml:lang='en'>"+"<subject>%s</subject></message>",
|
return fmt.Fprintf(c.stanzaWriter, "<message to='%s' type='%s' xml:lang='en'>"+"<subject>%s</subject></message>\n",
|
||||||
xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text))
|
xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,34 +47,34 @@ func (c *Client) JoinMUC(jid, nick string, history_type, history int, history_da
|
|||||||
}
|
}
|
||||||
switch history_type {
|
switch history_type {
|
||||||
case NoHistory:
|
case NoHistory:
|
||||||
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
|
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
|
||||||
"<x xmlns='%s' />\n"+
|
"<x xmlns='%s' />"+
|
||||||
"</presence>",
|
"</presence>\n",
|
||||||
xmlEscape(jid), xmlEscape(nick), nsMUC)
|
xmlEscape(jid), xmlEscape(nick), nsMUC)
|
||||||
case CharHistory:
|
case CharHistory:
|
||||||
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
|
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
|
||||||
"<x xmlns='%s'>\n"+
|
"<x xmlns='%s'>\n"+
|
||||||
"<history maxchars='%d'/></x>\n"+
|
"<history maxchars='%d'/></x>"+
|
||||||
"</presence>",
|
"</presence>\n",
|
||||||
xmlEscape(jid), xmlEscape(nick), nsMUC, history)
|
xmlEscape(jid), xmlEscape(nick), nsMUC, history)
|
||||||
case StanzaHistory:
|
case StanzaHistory:
|
||||||
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
|
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
|
||||||
"<x xmlns='%s'>\n"+
|
"<x xmlns='%s'>"+
|
||||||
"<history maxstanzas='%d'/></x>\n"+
|
"<history maxstanzas='%d'/></x>"+
|
||||||
"</presence>",
|
"</presence>\n",
|
||||||
xmlEscape(jid), xmlEscape(nick), nsMUC, history)
|
xmlEscape(jid), xmlEscape(nick), nsMUC, history)
|
||||||
case SecondsHistory:
|
case SecondsHistory:
|
||||||
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
|
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
|
||||||
"<x xmlns='%s'>\n"+
|
"<x xmlns='%s'>"+
|
||||||
"<history seconds='%d'/></x>\n"+
|
"<history seconds='%d'/></x>"+
|
||||||
"</presence>",
|
"</presence>\n",
|
||||||
xmlEscape(jid), xmlEscape(nick), nsMUC, history)
|
xmlEscape(jid), xmlEscape(nick), nsMUC, history)
|
||||||
case SinceHistory:
|
case SinceHistory:
|
||||||
if history_date != nil {
|
if history_date != nil {
|
||||||
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
|
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
|
||||||
"<x xmlns='%s'>\n"+
|
"<x xmlns='%s'>"+
|
||||||
"<history since='%s'/></x>\n"+
|
"<history since='%s'/></x>"+
|
||||||
"</presence>",
|
"</presence>\n",
|
||||||
xmlEscape(jid), xmlEscape(nick), nsMUC, history_date.Format(time.RFC3339))
|
xmlEscape(jid), xmlEscape(nick), nsMUC, history_date.Format(time.RFC3339))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,40 +88,40 @@ func (c *Client) JoinProtectedMUC(jid, nick string, password string, history_typ
|
|||||||
}
|
}
|
||||||
switch history_type {
|
switch history_type {
|
||||||
case NoHistory:
|
case NoHistory:
|
||||||
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
|
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
|
||||||
"<x xmlns='%s'>\n"+
|
"<x xmlns='%s'>"+
|
||||||
"<password>%s</password>"+
|
"<password>%s</password>"+
|
||||||
"</x>\n"+
|
"</x>"+
|
||||||
"</presence>",
|
"</presence>\n",
|
||||||
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password))
|
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password))
|
||||||
case CharHistory:
|
case CharHistory:
|
||||||
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
|
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
|
||||||
"<x xmlns='%s'>\n"+
|
"<x xmlns='%s'>"+
|
||||||
"<password>%s</password>\n"+
|
"<password>%s</password>"+
|
||||||
"<history maxchars='%d'/></x>\n"+
|
"<history maxchars='%d'/></x>"+
|
||||||
"</presence>",
|
"</presence>\n",
|
||||||
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
|
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
|
||||||
case StanzaHistory:
|
case StanzaHistory:
|
||||||
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
|
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
|
||||||
"<x xmlns='%s'>\n"+
|
"<x xmlns='%s'>"+
|
||||||
"<password>%s</password>\n"+
|
"<password>%s</password>"+
|
||||||
"<history maxstanzas='%d'/></x>\n"+
|
"<history maxstanzas='%d'/></x>"+
|
||||||
"</presence>",
|
"</presence>\n",
|
||||||
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
|
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
|
||||||
case SecondsHistory:
|
case SecondsHistory:
|
||||||
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
|
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
|
||||||
"<x xmlns='%s'>\n"+
|
"<x xmlns='%s'>"+
|
||||||
"<password>%s</password>\n"+
|
"<password>%s</password>"+
|
||||||
"<history seconds='%d'/></x>\n"+
|
"<history seconds='%d'/></x>"+
|
||||||
"</presence>",
|
"</presence>\n",
|
||||||
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
|
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
|
||||||
case SinceHistory:
|
case SinceHistory:
|
||||||
if history_date != nil {
|
if history_date != nil {
|
||||||
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
|
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
|
||||||
"<x xmlns='%s'>\n"+
|
"<x xmlns='%s'>"+
|
||||||
"<password>%s</password>\n"+
|
"<password>%s</password>"+
|
||||||
"<history since='%s'/></x>\n"+
|
"<history since='%s'/></x>"+
|
||||||
"</presence>",
|
"</presence>\n",
|
||||||
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history_date.Format(time.RFC3339))
|
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history_date.Format(time.RFC3339))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,6 +130,6 @@ func (c *Client) JoinProtectedMUC(jid, nick string, password string, history_typ
|
|||||||
|
|
||||||
// xep-0045 7.14
|
// xep-0045 7.14
|
||||||
func (c *Client) LeaveMUC(jid string) (n int, err error) {
|
func (c *Client) LeaveMUC(jid string) (n int, err error) {
|
||||||
return fmt.Fprintf(c.stanzaWriter, "<presence from='%s' to='%s' type='unavailable' />",
|
return fmt.Fprintf(c.stanzaWriter, "<presence from='%s' to='%s' type='unavailable' />\n",
|
||||||
c.jid, xmlEscape(jid))
|
c.jid, xmlEscape(jid))
|
||||||
}
|
}
|
||||||
|
14
xmpp_ping.go
14
xmpp_ping.go
@ -11,23 +11,23 @@ func (c *Client) PingC2S(jid, server string) error {
|
|||||||
if server == "" {
|
if server == "" {
|
||||||
server = c.domain
|
server = c.domain
|
||||||
}
|
}
|
||||||
_, err := fmt.Fprintf(c.stanzaWriter, "<iq from='%s' to='%s' id='c2s1' type='get'>\n"+
|
_, err := fmt.Fprintf(c.stanzaWriter, "<iq from='%s' to='%s' id='c2s1' type='get'>"+
|
||||||
"<ping xmlns='urn:xmpp:ping'/>\n"+
|
"<ping xmlns='urn:xmpp:ping'/>"+
|
||||||
"</iq>",
|
"</iq>\n",
|
||||||
xmlEscape(jid), xmlEscape(server))
|
xmlEscape(jid), xmlEscape(server))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) PingS2S(fromServer, toServer string) error {
|
func (c *Client) PingS2S(fromServer, toServer string) error {
|
||||||
_, err := fmt.Fprintf(c.stanzaWriter, "<iq from='%s' to='%s' id='s2s1' type='get'>\n"+
|
_, err := fmt.Fprintf(c.stanzaWriter, "<iq from='%s' to='%s' id='s2s1' type='get'>"+
|
||||||
"<ping xmlns='urn:xmpp:ping'/>\n"+
|
"<ping xmlns='urn:xmpp:ping'/>"+
|
||||||
"</iq>",
|
"</iq>\n",
|
||||||
xmlEscape(fromServer), xmlEscape(toServer))
|
xmlEscape(fromServer), xmlEscape(toServer))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) SendResultPing(id, toServer string) error {
|
func (c *Client) SendResultPing(id, toServer string) error {
|
||||||
_, err := fmt.Fprintf(c.stanzaWriter, "<iq type='result' to='%s' id='%s'/>",
|
_, err := fmt.Fprintf(c.stanzaWriter, "<iq type='result' to='%s' id='%s'/>\n",
|
||||||
xmlEscape(toServer), xmlEscape(id))
|
xmlEscape(toServer), xmlEscape(id))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -5,21 +5,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (c *Client) ApproveSubscription(jid string) {
|
func (c *Client) ApproveSubscription(jid string) {
|
||||||
fmt.Fprintf(c.stanzaWriter, "<presence to='%s' type='subscribed'/>",
|
fmt.Fprintf(c.stanzaWriter, "<presence to='%s' type='subscribed'/>\n",
|
||||||
xmlEscape(jid))
|
xmlEscape(jid))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) RevokeSubscription(jid string) {
|
func (c *Client) RevokeSubscription(jid string) {
|
||||||
fmt.Fprintf(c.stanzaWriter, "<presence to='%s' type='unsubscribed'/>",
|
fmt.Fprintf(c.stanzaWriter, "<presence to='%s' type='unsubscribed'/>\n",
|
||||||
xmlEscape(jid))
|
xmlEscape(jid))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) RetrieveSubscription(jid string) {
|
func (c *Client) RetrieveSubscription(jid string) {
|
||||||
fmt.Fprintf(c.conn, "<presence to='%s' type='unsubscribe'/>",
|
fmt.Fprintf(c.conn, "<presence to='%s' type='unsubscribe'/>\n",
|
||||||
xmlEscape(jid))
|
xmlEscape(jid))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) RequestSubscription(jid string) {
|
func (c *Client) RequestSubscription(jid string) {
|
||||||
fmt.Fprintf(c.stanzaWriter, "<presence to='%s' type='subscribe'/>",
|
fmt.Fprintf(c.stanzaWriter, "<presence to='%s' type='subscribe'/>\n",
|
||||||
xmlEscape(jid))
|
xmlEscape(jid))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user