Rework printing of sent stanzas when debug is enabled (#148)

* Rework printing of sent stanzas when debug is enabled

This got reworked to also work with multiple connections
as pointed out by @vcabbage in
https://github.com/mattn/go-xmpp/pull/141#issuecomment-1557334066

* Remove StanzaWriter.
This commit is contained in:
Martin 2023-07-28 16:42:12 +02:00 committed by GitHub
parent bef3e549f7
commit 98ff0d4df7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 47 deletions

52
xmpp.go
View File

@ -55,7 +55,6 @@ var DefaultConfig = &tls.Config{}
// DebugWriter is the writer used to write debugging output to. // DebugWriter is the writer used to write debugging output to.
var DebugWriter io.Writer = os.Stderr var DebugWriter io.Writer = os.Stderr
var StanzaWriter io.Writer
// Cookie is a unique XMPP session identifier // Cookie is a unique XMPP session identifier
type Cookie uint64 type Cookie uint64
@ -70,10 +69,11 @@ func getCookie() Cookie {
// Client holds XMPP connection options // Client holds XMPP connection options
type Client struct { type Client struct {
conn net.Conn // connection to server conn net.Conn // connection to server
jid string // Jabber ID for our connection jid string // Jabber ID for our connection
domain string domain string
p *xml.Decoder p *xml.Decoder
stanzaWriter io.Writer
} }
func (c *Client) JID() string { func (c *Client) JID() string {
@ -378,7 +378,7 @@ func (c *Client) init(o *Options) error {
foundAnonymous := false foundAnonymous := false
for _, m := range f.Mechanisms.Mechanism { for _, m := range f.Mechanisms.Mechanism {
if m == "ANONYMOUS" { if m == "ANONYMOUS" {
fmt.Fprintf(StanzaWriter, "<auth xmlns='%s' mechanism='ANONYMOUS' />\n", nsSASL) fmt.Fprintf(c.stanzaWriter, "<auth xmlns='%s' mechanism='ANONYMOUS' />\n", nsSASL)
foundAnonymous = true foundAnonymous = true
break break
} }
@ -436,7 +436,7 @@ func (c *Client) init(o *Options) error {
} }
clientNonce := cnonce() clientNonce := cnonce()
clientFirstMessage := "n=" + user + ",r=" + clientNonce clientFirstMessage := "n=" + user + ",r=" + clientNonce
fmt.Fprintf(StanzaWriter, "<auth xmlns='%s' mechanism='%s'>%s</auth>", fmt.Fprintf(c.stanzaWriter, "<auth xmlns='%s' mechanism='%s'>%s</auth>",
nsSASL, mechanism, base64.StdEncoding.EncodeToString([]byte("n,,"+ nsSASL, mechanism, base64.StdEncoding.EncodeToString([]byte("n,,"+
clientFirstMessage))) clientFirstMessage)))
var sfm string var sfm string
@ -536,7 +536,7 @@ func (c *Client) init(o *Options) error {
} }
clientFinalMessage := base64.StdEncoding.EncodeToString([]byte(clientFinalMessageBare + clientFinalMessage := base64.StdEncoding.EncodeToString([]byte(clientFinalMessageBare +
",p=" + base64.StdEncoding.EncodeToString(clientProof))) ",p=" + base64.StdEncoding.EncodeToString(clientProof)))
fmt.Fprintf(StanzaWriter, "<response xmlns='%s'>%s</response>", nsSASL, fmt.Fprintf(c.stanzaWriter, "<response xmlns='%s'>%s</response>", nsSASL,
clientFinalMessage) clientFinalMessage)
} }
if mechanism == "X-OAUTH2" && o.OAuthToken != "" && o.OAuthScope != "" { if mechanism == "X-OAUTH2" && o.OAuthToken != "" && o.OAuthScope != "" {
@ -544,7 +544,7 @@ func (c *Client) init(o *Options) error {
raw := "\x00" + user + "\x00" + o.OAuthToken raw := "\x00" + user + "\x00" + o.OAuthToken
enc := make([]byte, base64.StdEncoding.EncodedLen(len(raw))) enc := make([]byte, base64.StdEncoding.EncodedLen(len(raw)))
base64.StdEncoding.Encode(enc, []byte(raw)) base64.StdEncoding.Encode(enc, []byte(raw))
fmt.Fprintf(StanzaWriter, "<auth xmlns='%s' mechanism='X-OAUTH2' auth:service='oauth2' "+ fmt.Fprintf(c.stanzaWriter, "<auth xmlns='%s' mechanism='X-OAUTH2' auth:service='oauth2' "+
"xmlns:auth='%s'>%s</auth>\n", nsSASL, o.OAuthXmlNs, enc) "xmlns:auth='%s'>%s</auth>\n", nsSASL, o.OAuthXmlNs, enc)
} }
if mechanism == "PLAIN" { if mechanism == "PLAIN" {
@ -556,7 +556,7 @@ func (c *Client) init(o *Options) error {
} }
if mechanism == "DIGEST-MD5" { if mechanism == "DIGEST-MD5" {
// Digest-MD5 authentication // Digest-MD5 authentication
fmt.Fprintf(StanzaWriter, "<auth xmlns='%s' mechanism='DIGEST-MD5'/>\n", nsSASL) fmt.Fprintf(c.stanzaWriter, "<auth xmlns='%s' mechanism='DIGEST-MD5'/>\n", nsSASL)
var ch saslChallenge var ch saslChallenge
if err = c.p.DecodeElement(&ch, nil); err != nil { if err = c.p.DecodeElement(&ch, nil); err != nil {
return errors.New("unmarshal <challenge>: " + err.Error()) return errors.New("unmarshal <challenge>: " + err.Error())
@ -586,7 +586,7 @@ func (c *Client) init(o *Options) error {
message := "username=\"" + user + "\", realm=\"" + realm + "\", nonce=\"" + nonce + "\", cnonce=\"" + cnonceStr + message := "username=\"" + user + "\", realm=\"" + realm + "\", nonce=\"" + nonce + "\", cnonce=\"" + cnonceStr +
"\", nc=" + nonceCount + ", qop=" + qop + ", digest-uri=\"" + digestURI + "\", response=" + digest + ", charset=" + charset "\", nc=" + nonceCount + ", qop=" + qop + ", digest-uri=\"" + digestURI + "\", response=" + digest + ", charset=" + charset
fmt.Fprintf(StanzaWriter, "<response xmlns='%s'>%s</response>\n", nsSASL, base64.StdEncoding.EncodeToString([]byte(message))) fmt.Fprintf(c.stanzaWriter, "<response xmlns='%s'>%s</response>\n", nsSASL, base64.StdEncoding.EncodeToString([]byte(message)))
var rspauth saslRspAuth var rspauth saslRspAuth
if err = c.p.DecodeElement(&rspauth, nil); err != nil { if err = c.p.DecodeElement(&rspauth, nil); err != nil {
@ -596,7 +596,7 @@ func (c *Client) init(o *Options) error {
if err != nil { if err != nil {
return err return err
} }
fmt.Fprintf(StanzaWriter, "<response xmlns='%s'/>\n", nsSASL) fmt.Fprintf(c.stanzaWriter, "<response xmlns='%s'/>\n", nsSASL)
} }
} }
if mechanism == "" { if mechanism == "" {
@ -649,9 +649,9 @@ func (c *Client) init(o *Options) error {
// Send IQ message asking to bind to the local user name. // Send IQ message asking to bind to the local user name.
if o.Resource == "" { if o.Resource == "" {
fmt.Fprintf(StanzaWriter, "<iq type='set' id='%x'><bind xmlns='%s'></bind></iq>\n", cookie, nsBind) fmt.Fprintf(c.stanzaWriter, "<iq type='set' id='%x'><bind xmlns='%s'></bind></iq>\n", cookie, nsBind)
} else { } else {
fmt.Fprintf(StanzaWriter, "<iq type='set' id='%x'><bind xmlns='%s'><resource>%s</resource></bind></iq>\n", cookie, nsBind, o.Resource) fmt.Fprintf(c.stanzaWriter, "<iq type='set' id='%x'><bind xmlns='%s'><resource>%s</resource></bind></iq>\n", cookie, nsBind, o.Resource)
} }
var iq clientIQ var iq clientIQ
if err = c.p.DecodeElement(&iq, nil); err != nil { if err = c.p.DecodeElement(&iq, nil); err != nil {
@ -665,11 +665,11 @@ func (c *Client) init(o *Options) error {
if o.Session { if o.Session {
//if server support session, open it //if server support session, open it
fmt.Fprintf(StanzaWriter, "<iq to='%s' type='set' id='%x'><session xmlns='%s'/></iq>", xmlEscape(domain), cookie, nsSession) fmt.Fprintf(c.stanzaWriter, "<iq to='%s' type='set' id='%x'><session xmlns='%s'/></iq>", xmlEscape(domain), cookie, nsSession)
} }
// We're connected and can now receive and send messages. // We're connected and can now receive and send messages.
fmt.Fprintf(StanzaWriter, "<presence xml:lang='en'><show>%s</show><status>%s</status></presence>", o.Status, o.StatusMessage) fmt.Fprintf(c.stanzaWriter, "<presence xml:lang='en'><show>%s</show><status>%s</status></presence>", o.Status, o.StatusMessage)
return nil return nil
} }
@ -691,7 +691,7 @@ func (c *Client) startTLSIfRequired(f *streamFeatures, o *Options, domain string
} }
var err error var err error
fmt.Fprintf(StanzaWriter, "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>\n") fmt.Fprintf(c.stanzaWriter, "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>\n")
var k tlsProceed var k tlsProceed
if err = c.p.DecodeElement(&k, nil); err != nil { if err = c.p.DecodeElement(&k, nil); err != nil {
return f, errors.New("unmarshal <proceed>: " + err.Error()) return f, errors.New("unmarshal <proceed>: " + err.Error())
@ -724,13 +724,13 @@ func (c *Client) startTLSIfRequired(f *streamFeatures, o *Options, domain string
func (c *Client) startStream(o *Options, domain string) (*streamFeatures, error) { func (c *Client) startStream(o *Options, domain string) (*streamFeatures, error) {
if o.Debug { if o.Debug {
c.p = xml.NewDecoder(tee{c.conn, DebugWriter}) c.p = xml.NewDecoder(tee{c.conn, DebugWriter})
StanzaWriter = io.MultiWriter(c.conn, DebugWriter) c.stanzaWriter = io.MultiWriter(c.conn, DebugWriter)
} else { } else {
c.p = xml.NewDecoder(c.conn) c.p = xml.NewDecoder(c.conn)
StanzaWriter = c.conn c.stanzaWriter = c.conn
} }
_, err := fmt.Fprintf(StanzaWriter, "<?xml version='1.0'?>"+ _, err := fmt.Fprintf(c.stanzaWriter, "<?xml version='1.0'?>"+
"<stream:stream to='%s' xmlns='%s'"+ "<stream:stream to='%s' xmlns='%s'"+
" xmlns:stream='%s' version='1.0'>", " xmlns:stream='%s' version='1.0'>",
xmlEscape(domain), nsClient, nsStream) xmlEscape(domain), nsClient, nsStream)
@ -1058,7 +1058,7 @@ func (c *Client) Send(chat Chat) (n int, err error) {
stanza := "<message to='%s' type='%s' id='%s' xml:lang='en'>" + subtext + "<body>%s</body>" + oobtext + thdtext + "</message>" stanza := "<message to='%s' type='%s' id='%s' xml:lang='en'>" + subtext + "<body>%s</body>" + oobtext + thdtext + "</message>"
return fmt.Fprintf(StanzaWriter, stanza, return fmt.Fprintf(c.stanzaWriter, stanza,
xmlEscape(chat.Remote), xmlEscape(chat.Type), cnonce(), xmlEscape(chat.Text)) xmlEscape(chat.Remote), xmlEscape(chat.Type), cnonce(), xmlEscape(chat.Text))
} }
@ -1075,17 +1075,17 @@ func (c *Client) SendOOB(chat Chat) (n int, err error) {
} }
oobtext += `</x>` oobtext += `</x>`
} }
return fmt.Fprintf(StanzaWriter, "<message to='%s' type='%s' id='%s' xml:lang='en'>"+oobtext+thdtext+"</message>", return fmt.Fprintf(c.stanzaWriter, "<message to='%s' type='%s' id='%s' xml:lang='en'>"+oobtext+thdtext+"</message>",
xmlEscape(chat.Remote), xmlEscape(chat.Type), cnonce()) xmlEscape(chat.Remote), xmlEscape(chat.Type), cnonce())
} }
// SendOrg sends the original text without being wrapped in an XMPP message stanza. // SendOrg sends the original text without being wrapped in an XMPP message stanza.
func (c *Client) SendOrg(org string) (n int, err error) { func (c *Client) SendOrg(org string) (n int, err error) {
return fmt.Fprint(StanzaWriter, org) return fmt.Fprint(c.stanzaWriter, org)
} }
func (c *Client) SendPresence(presence Presence) (n int, err error) { func (c *Client) SendPresence(presence Presence) (n int, err error) {
return fmt.Fprintf(StanzaWriter, "<presence from='%s' to='%s'/>", xmlEscape(presence.From), xmlEscape(presence.To)) return fmt.Fprintf(c.stanzaWriter, "<presence from='%s' to='%s'/>", xmlEscape(presence.From), xmlEscape(presence.To))
} }
// SendKeepAlive sends a "whitespace keepalive" as described in chapter 4.6.1 of RFC6120. // SendKeepAlive sends a "whitespace keepalive" as described in chapter 4.6.1 of RFC6120.
@ -1095,7 +1095,7 @@ func (c *Client) SendKeepAlive() (n int, err error) {
// SendHtml sends the message as HTML as defined by XEP-0071 // SendHtml sends the message as HTML as defined by XEP-0071
func (c *Client) SendHtml(chat Chat) (n int, err error) { func (c *Client) SendHtml(chat Chat) (n int, err error) {
return fmt.Fprintf(StanzaWriter, "<message to='%s' type='%s' xml:lang='en'>"+ return fmt.Fprintf(c.stanzaWriter, "<message to='%s' type='%s' xml:lang='en'>"+
"<body>%s</body>"+ "<body>%s</body>"+
"<html xmlns='http://jabber.org/protocol/xhtml-im'><body xmlns='http://www.w3.org/1999/xhtml'>%s</body></html></message>", "<html xmlns='http://jabber.org/protocol/xhtml-im'><body xmlns='http://www.w3.org/1999/xhtml'>%s</body></html></message>",
xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text), chat.Text) xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text), chat.Text)
@ -1103,7 +1103,7 @@ func (c *Client) SendHtml(chat Chat) (n int, err error) {
// Roster asks for the chat roster. // Roster asks for the chat roster.
func (c *Client) Roster() error { func (c *Client) Roster() error {
fmt.Fprintf(StanzaWriter, "<iq from='%s' type='get' id='roster1'><query xmlns='jabber:iq:roster'/></iq>\n", xmlEscape(c.jid)) fmt.Fprintf(c.stanzaWriter, "<iq from='%s' type='get' id='roster1'><query xmlns='jabber:iq:roster'/></iq>\n", xmlEscape(c.jid))
return nil return nil
} }

View File

@ -35,13 +35,13 @@ 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>"
_, err := fmt.Fprintf(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>"
_, err := fmt.Fprintf(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
} }

View File

@ -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(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>",
xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text)) xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text))
} }
@ -33,7 +33,7 @@ func (c *Client) JoinMUCNoHistory(jid, nick string) (n int, err error) {
if nick == "" { if nick == "" {
nick = c.jid nick = c.jid
} }
return fmt.Fprintf(StanzaWriter, "<presence to='%s/%s'>\n"+ return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
"<x xmlns='%s'>"+ "<x xmlns='%s'>"+
"<history maxchars='0'/></x>\n"+ "<history maxchars='0'/></x>\n"+
"</presence>", "</presence>",
@ -47,31 +47,31 @@ 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(StanzaWriter, "<presence to='%s/%s'>\n"+ return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
"<x xmlns='%s' />\n"+ "<x xmlns='%s' />\n"+
"</presence>", "</presence>",
xmlEscape(jid), xmlEscape(nick), nsMUC) xmlEscape(jid), xmlEscape(nick), nsMUC)
case CharHistory: case CharHistory:
return fmt.Fprintf(StanzaWriter, "<presence to='%s/%s'>\n"+ return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
"<x xmlns='%s'>\n"+ "<x xmlns='%s'>\n"+
"<history maxchars='%d'/></x>\n"+ "<history maxchars='%d'/></x>\n"+
"</presence>", "</presence>",
xmlEscape(jid), xmlEscape(nick), nsMUC, history) xmlEscape(jid), xmlEscape(nick), nsMUC, history)
case StanzaHistory: case StanzaHistory:
return fmt.Fprintf(StanzaWriter, "<presence to='%s/%s'>\n"+ return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
"<x xmlns='%s'>\n"+ "<x xmlns='%s'>\n"+
"<history maxstanzas='%d'/></x>\n"+ "<history maxstanzas='%d'/></x>\n"+
"</presence>", "</presence>",
xmlEscape(jid), xmlEscape(nick), nsMUC, history) xmlEscape(jid), xmlEscape(nick), nsMUC, history)
case SecondsHistory: case SecondsHistory:
return fmt.Fprintf(StanzaWriter, "<presence to='%s/%s'>\n"+ return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
"<x xmlns='%s'>\n"+ "<x xmlns='%s'>\n"+
"<history seconds='%d'/></x>\n"+ "<history seconds='%d'/></x>\n"+
"</presence>", "</presence>",
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(StanzaWriter, "<presence to='%s/%s'>\n"+ return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
"<x xmlns='%s'>\n"+ "<x xmlns='%s'>\n"+
"<history since='%s'/></x>\n"+ "<history since='%s'/></x>\n"+
"</presence>", "</presence>",
@ -88,28 +88,28 @@ func (c *Client) JoinProtectedMUC(jid, nick string, password string, history_typ
} }
switch history_type { switch history_type {
case NoHistory: case NoHistory:
return fmt.Fprintf(StanzaWriter, "<presence to='%s/%s'>\n"+ return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
"<x xmlns='%s'>\n"+ "<x xmlns='%s'>\n"+
"<password>%s</password>"+ "<password>%s</password>"+
"</x>\n"+ "</x>\n"+
"</presence>", "</presence>",
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password)) xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password))
case CharHistory: case CharHistory:
return fmt.Fprintf(StanzaWriter, "<presence to='%s/%s'>\n"+ return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
"<x xmlns='%s'>\n"+ "<x xmlns='%s'>\n"+
"<password>%s</password>\n"+ "<password>%s</password>\n"+
"<history maxchars='%d'/></x>\n"+ "<history maxchars='%d'/></x>\n"+
"</presence>", "</presence>",
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history) xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
case StanzaHistory: case StanzaHistory:
return fmt.Fprintf(StanzaWriter, "<presence to='%s/%s'>\n"+ return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
"<x xmlns='%s'>\n"+ "<x xmlns='%s'>\n"+
"<password>%s</password>\n"+ "<password>%s</password>\n"+
"<history maxstanzas='%d'/></x>\n"+ "<history maxstanzas='%d'/></x>\n"+
"</presence>", "</presence>",
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history) xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
case SecondsHistory: case SecondsHistory:
return fmt.Fprintf(StanzaWriter, "<presence to='%s/%s'>\n"+ return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
"<x xmlns='%s'>\n"+ "<x xmlns='%s'>\n"+
"<password>%s</password>\n"+ "<password>%s</password>\n"+
"<history seconds='%d'/></x>\n"+ "<history seconds='%d'/></x>\n"+
@ -117,7 +117,7 @@ func (c *Client) JoinProtectedMUC(jid, nick string, password string, history_typ
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(StanzaWriter, "<presence to='%s/%s'>\n"+ return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
"<x xmlns='%s'>\n"+ "<x xmlns='%s'>\n"+
"<password>%s</password>\n"+ "<password>%s</password>\n"+
"<history since='%s'/></x>\n"+ "<history since='%s'/></x>\n"+
@ -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(StanzaWriter, "<presence from='%s' to='%s' type='unavailable' />", return fmt.Fprintf(c.stanzaWriter, "<presence from='%s' to='%s' type='unavailable' />",
c.jid, xmlEscape(jid)) c.jid, xmlEscape(jid))
} }

View File

@ -11,7 +11,7 @@ func (c *Client) PingC2S(jid, server string) error {
if server == "" { if server == "" {
server = c.domain server = c.domain
} }
_, err := fmt.Fprintf(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'>\n"+
"<ping xmlns='urn:xmpp:ping'/>\n"+ "<ping xmlns='urn:xmpp:ping'/>\n"+
"</iq>", "</iq>",
xmlEscape(jid), xmlEscape(server)) xmlEscape(jid), xmlEscape(server))
@ -19,7 +19,7 @@ func (c *Client) PingC2S(jid, server string) error {
} }
func (c *Client) PingS2S(fromServer, toServer string) error { func (c *Client) PingS2S(fromServer, toServer string) error {
_, err := fmt.Fprintf(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'>\n"+
"<ping xmlns='urn:xmpp:ping'/>\n"+ "<ping xmlns='urn:xmpp:ping'/>\n"+
"</iq>", "</iq>",
xmlEscape(fromServer), xmlEscape(toServer)) xmlEscape(fromServer), xmlEscape(toServer))
@ -27,7 +27,7 @@ func (c *Client) PingS2S(fromServer, toServer string) error {
} }
func (c *Client) SendResultPing(id, toServer string) error { func (c *Client) SendResultPing(id, toServer string) error {
_, err := fmt.Fprintf(StanzaWriter, "<iq type='result' to='%s' id='%s'/>", _, err := fmt.Fprintf(c.stanzaWriter, "<iq type='result' to='%s' id='%s'/>",
xmlEscape(toServer), xmlEscape(id)) xmlEscape(toServer), xmlEscape(id))
return err return err
} }

View File

@ -5,12 +5,12 @@ import (
) )
func (c *Client) ApproveSubscription(jid string) { func (c *Client) ApproveSubscription(jid string) {
fmt.Fprintf(StanzaWriter, "<presence to='%s' type='subscribed'/>", fmt.Fprintf(c.stanzaWriter, "<presence to='%s' type='subscribed'/>",
xmlEscape(jid)) xmlEscape(jid))
} }
func (c *Client) RevokeSubscription(jid string) { func (c *Client) RevokeSubscription(jid string) {
fmt.Fprintf(StanzaWriter, "<presence to='%s' type='unsubscribed'/>", fmt.Fprintf(c.stanzaWriter, "<presence to='%s' type='unsubscribed'/>",
xmlEscape(jid)) xmlEscape(jid))
} }
@ -20,6 +20,6 @@ func (c *Client) RetrieveSubscription(jid string) {
} }
func (c *Client) RequestSubscription(jid string) { func (c *Client) RequestSubscription(jid string) {
fmt.Fprintf(StanzaWriter, "<presence to='%s' type='subscribe'/>", fmt.Fprintf(c.stanzaWriter, "<presence to='%s' type='subscribe'/>",
xmlEscape(jid)) xmlEscape(jid))
} }