From af110491a0f6918de29550b2ff1b7dc25d94f8cf Mon Sep 17 00:00:00 2001 From: Specode <0x0000e000@gmail.com> Date: Fri, 18 Oct 2013 15:49:41 +0800 Subject: [PATCH 1/2] add debug options --- xmpp.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/xmpp.go b/xmpp.go index b5edcf1..90db6ba 100644 --- a/xmpp.go +++ b/xmpp.go @@ -115,6 +115,9 @@ type Options struct { // NoTLS disables TLS and specifies that a plain old unencrypted TCP connection should // be used. NoTLS bool + + // Debug output + Debug bool } // NewClient establishes a new Client connection based on a set of Options. @@ -153,21 +156,23 @@ func (o Options) NewClient() (*Client, error) { // NewClient creates a new connection to a host given as "hostname" or "hostname:port". // If host is not specified, the DNS SRV should be used to find the host from the domainpart of the JID. // Default the port to 5222. -func NewClient(host, user, passwd string) (*Client, error) { +func NewClient(host, user, passwd string, debug bool) (*Client, error) { opts := Options{ Host: host, User: user, Password: passwd, + Debug: debug, } return opts.NewClient() } -func NewClientNoTLS(host, user, passwd string) (*Client, error) { +func NewClientNoTLS(host, user, passwd string, debug bool) (*Client, error) { opts := Options{ Host: host, User: user, Password: passwd, NoTLS: true, + Debug: debug, } return opts.NewClient() } @@ -210,9 +215,11 @@ func cnonce() string { } func (c *Client) init(o *Options) error { - // For debugging: the following causes the plaintext of the connection to be duplicated to stdout. - //c.p = xml.NewDecoder(tee{c.conn, os.Stdout}) c.p = xml.NewDecoder(c.conn) + // For debugging: the following causes the plaintext of the connection to be duplicated to stdout. + if o.Debug { + c.p = xml.NewDecoder(tee{c.conn, os.Stdout}) + } a := strings.SplitN(o.User, "@", 2) if len(a) != 2 { @@ -617,6 +624,7 @@ func (t tee) Read(p []byte) (n int, err error) { n, err = t.r.Read(p) if n > 0 { t.w.Write(p[0:n]) + t.w.Write([]byte("\n")) } return } From c88c22763aea019b4e99ade78a6526af89a089b3 Mon Sep 17 00:00:00 2001 From: Specode <0x0000e000@gmail.com> Date: Fri, 18 Oct 2013 15:52:01 +0800 Subject: [PATCH 2/2] add SendOrg for send origin text --- xmpp.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/xmpp.go b/xmpp.go index 90db6ba..3f9f527 100644 --- a/xmpp.go +++ b/xmpp.go @@ -400,6 +400,11 @@ func (c *Client) Send(chat Chat) { xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text)) } +// Send origin +func (c *Client) SendOrg(org string) { + fmt.Fprint(c.conn, org) +} + // RFC 3920 C.1 Streams name space type streamFeatures struct { XMLName xml.Name `xml:"http://etherx.jabber.org/streams features"`