Xmpp ping fixed to use the obtained jid.

Though a client function, ping does not use the client jid.
Fixed ping to use the obtained jid and configured server domain by default.
Client now exposes jid.
This commit is contained in:
David Bolshoy 2016-04-10 18:43:42 +03:00
parent 0e6327115f
commit e3871c2deb
2 changed files with 10 additions and 0 deletions

View File

@ -64,6 +64,10 @@ type Client struct {
p *xml.Decoder p *xml.Decoder
} }
func (c *Client) JID() string {
return c.jid
}
func connect(host, user, passwd string) (net.Conn, error) { func connect(host, user, passwd string) (net.Conn, error) {
addr := host addr := host

View File

@ -5,6 +5,12 @@ import (
) )
func (c *Client) PingC2S(jid, server string) error { func (c *Client) PingC2S(jid, server string) error {
if jid == "" {
jid = c.jid
}
if server == "" {
server = c.domain
}
_, err := fmt.Fprintf(c.conn, "<iq from='%s' to='%s' id='c2s1' type='get'>\n"+ _, err := fmt.Fprintf(c.conn, "<iq from='%s' to='%s' id='c2s1' type='get'>\n"+
"<ping xmlns='urn:xmpp:ping'/>\n"+ "<ping xmlns='urn:xmpp:ping'/>\n"+
"</iq>", "</iq>",