From c3ac597871af10b7292cb7e8923736400eb815b1 Mon Sep 17 00:00:00 2001 From: pharrisee Date: Wed, 11 Sep 2013 12:01:05 +0100 Subject: [PATCH 01/18] Create README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..12e4a25 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +go-xmpp +======= + +go xmpp library (original was written by russ cox ) 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 02/18] 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 03/18] 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"` From ba140e5eb7ffffedd38612720fd36788ea89e175 Mon Sep 17 00:00:00 2001 From: Specode <0x0000e000@gmail.com> Date: Mon, 21 Oct 2013 03:07:59 +0000 Subject: [PATCH 04/18] fix example --- example/example-gui.go | 4 ++-- example/example.go | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/example/example-gui.go b/example/example-gui.go index f29bdf0..0787cfc 100644 --- a/example/example-gui.go +++ b/example/example-gui.go @@ -1,8 +1,8 @@ package main import ( - "github.com/mattn/go-xmpp" "github.com/mattn/go-gtk/gtk" + "github.com/mattn/go-xmpp" "log" "os" "strings" @@ -67,7 +67,7 @@ func main() { os.Exit(0) } - talk, err := xmpp.NewClient("talk.google.com:443", username_, password_) + talk, err := xmpp.NewClient("talk.google.com:443", username_, password_, false) if err != nil { log.Fatal(err) } diff --git a/example/example.go b/example/example.go index 5702a74..f69099f 100644 --- a/example/example.go +++ b/example/example.go @@ -2,18 +2,19 @@ package main import ( "bufio" - "fmt" "flag" + "fmt" "github.com/mattn/go-xmpp" "log" "os" "strings" ) -var server = flag.String("server", "talk.google.com:443", "server") +var server = flag.String("server", "talk.google.com:443", "server") var username = flag.String("username", "", "username") var password = flag.String("password", "", "password") var notls = flag.Bool("notls", false, "No TLS") +var debug = flag.Bool("debug", false, "debug output") func main() { flag.Usage = func() { @@ -29,9 +30,9 @@ func main() { var talk *xmpp.Client var err error if *notls { - talk, err = xmpp.NewClientNoTLS(*server, *username, *password) + talk, err = xmpp.NewClientNoTLS(*server, *username, *password, *debug) } else { - talk, err = xmpp.NewClient(*server, *username, *password) + talk, err = xmpp.NewClient(*server, *username, *password, *debug) } if err != nil { log.Fatal(err) From cbdf478ba76b7c62f6ac8c2f6343f6cfa0f8d8bc Mon Sep 17 00:00:00 2001 From: Specode <0x0000e000@gmail.com> Date: Wed, 30 Oct 2013 17:13:02 +0800 Subject: [PATCH 05/18] clientMessage add ",any" tag, use for hasn't matched element --- xmpp.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/xmpp.go b/xmpp.go index 3f9f527..2a705cb 100644 --- a/xmpp.go +++ b/xmpp.go @@ -367,6 +367,7 @@ type Chat struct { Remote string Type string Text string + Other []string } type Presence struct { @@ -385,7 +386,7 @@ func (c *Client) Recv() (event interface{}, err error) { } switch v := val.(type) { case *clientMessage: - return Chat{v.From, v.Type, v.Body}, nil + return Chat{v.From, v.Type, v.Body, v.Other}, nil case *clientPresence: return Presence{v.From, v.To, v.Type, v.Show}, nil } @@ -488,6 +489,11 @@ type clientMessage struct { Subject string `xml:"subject"` Body string `xml:"body"` Thread string `xml:"thread"` + + Other []string `xml:",any"` + + // // Any hasn't matched element + // Other string `xml:",any"` } type clientText struct { From 64821d5df97100c4e61c60280d65d60a4fd623d1 Mon Sep 17 00:00:00 2001 From: Specode <0x0000e000@gmail.com> Date: Wed, 30 Oct 2013 17:14:11 +0800 Subject: [PATCH 06/18] clientMessage add ",any" tag, use for hasn't matched element --- xmpp.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/xmpp.go b/xmpp.go index 2a705cb..52c1e66 100644 --- a/xmpp.go +++ b/xmpp.go @@ -490,10 +490,8 @@ type clientMessage struct { Body string `xml:"body"` Thread string `xml:"thread"` + // Any hasn't matched element Other []string `xml:",any"` - - // // Any hasn't matched element - // Other string `xml:",any"` } type clientText struct { From b67dc40516077760b3d69e92635ca92c5e22ffe5 Mon Sep 17 00:00:00 2001 From: Specode <0x0000e000@gmail.com> Date: Mon, 4 Nov 2013 15:13:55 +0800 Subject: [PATCH 07/18] fix some error handling --- xmpp.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/xmpp.go b/xmpp.go index 52c1e66..ab5eade 100644 --- a/xmpp.go +++ b/xmpp.go @@ -314,6 +314,9 @@ func (c *Client) init(o *Options) error { // Next message should be either success or failure. name, val, err := next(c.p) + if err != nil { + return err + } switch v := val.(type) { case *saslSuccess: case *saslFailure: @@ -535,8 +538,8 @@ type clientError struct { func nextStart(p *xml.Decoder) (xml.StartElement, error) { for { t, err := p.Token() - if err != nil { - log.Fatal("token", err) + if err != nil && err != io.EOF { + return nil, err } switch t := t.(type) { case xml.StartElement: From 8a80c8abe319ccc0e61b63684158bffd1a61ca5a Mon Sep 17 00:00:00 2001 From: Specode <0x0000e000@gmail.com> Date: Tue, 5 Nov 2013 10:03:26 +0800 Subject: [PATCH 08/18] fix bug --- xmpp.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/xmpp.go b/xmpp.go index ab5eade..6786432 100644 --- a/xmpp.go +++ b/xmpp.go @@ -23,7 +23,6 @@ import ( "errors" "fmt" "io" - "log" "math/big" "net" "net/http" @@ -539,7 +538,7 @@ func nextStart(p *xml.Decoder) (xml.StartElement, error) { for { t, err := p.Token() if err != nil && err != io.EOF { - return nil, err + return xml.StartElement{}, err } switch t := t.(type) { case xml.StartElement: From e71f933d7c7642c5bac14ff9b164aaa30ab6b681 Mon Sep 17 00:00:00 2001 From: Martin Bonnin Date: Wed, 16 Apr 2014 17:25:20 +0200 Subject: [PATCH 09/18] fix digest-md5 with some ejabberd server * it looke like some response parameters need to be quoted * so quote username, realm, nonce, etc, ... as in http://tools.ietf.org/html/rfc3920#ref-SASL --- xmpp.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xmpp.go b/xmpp.go index 6786432..65f0841 100644 --- a/xmpp.go +++ b/xmpp.go @@ -292,7 +292,8 @@ func (c *Client) init(o *Options) error { digestUri := "xmpp/" + domain nonceCount := fmt.Sprintf("%08x", 1) digest := saslDigestResponse(user, realm, o.Password, nonce, cnonceStr, "AUTHENTICATE", digestUri, nonceCount) - message := "username=" + user + ", realm=" + realm + ", nonce=" + nonce + ", cnonce=" + cnonceStr + ", nc=" + nonceCount + ", qop=" + qop + ", digest-uri=" + digestUri + ", response=" + digest + ", charset=" + charset + message := "username=\"" + user + "\", realm=\"" + realm + "\", nonce=\"" + nonce + "\", cnonce=\"" + cnonceStr + "\", nc=" + nonceCount + ", qop=" + qop + ", digest-uri=\"" + digestUri + "\", response=" + digest + ", charset=" + charset + fmt.Fprintf(c.conn, "%s\n", nsSASL, base64.StdEncoding.EncodeToString([]byte(message))) var rspauth saslRspAuth From 8a08b956bbcb0bdd88b6eba7bc9b8a146b1cef8c Mon Sep 17 00:00:00 2001 From: Ilya Beda Date: Wed, 23 Apr 2014 00:05:35 +0800 Subject: [PATCH 10/18] Ejabberd compatibility Add unique cookie for iq requests Add session parameter --- example/example.go | 15 ++++++++++----- xmpp.go | 41 +++++++++++++++++++++++++++++++++-------- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/example/example.go b/example/example.go index f69099f..3981192 100644 --- a/example/example.go +++ b/example/example.go @@ -15,6 +15,7 @@ var username = flag.String("username", "", "username") var password = flag.String("password", "", "password") var notls = flag.Bool("notls", false, "No TLS") var debug = flag.Bool("debug", false, "debug output") +var session = flag.Bool("session", false, "use server session") func main() { flag.Usage = func() { @@ -29,11 +30,15 @@ func main() { var talk *xmpp.Client var err error - if *notls { - talk, err = xmpp.NewClientNoTLS(*server, *username, *password, *debug) - } else { - talk, err = xmpp.NewClient(*server, *username, *password, *debug) - } + options := xmpp.Options{Host: *server, + User: *username, + Password: *password, + NoTLS: *notls, + Debug: *debug, + Session: *session} + + talk, err = options.NewClient() + if err != nil { log.Fatal(err) } diff --git a/xmpp.go b/xmpp.go index 65f0841..6515fcc 100644 --- a/xmpp.go +++ b/xmpp.go @@ -19,6 +19,7 @@ import ( "crypto/rand" "crypto/tls" "encoding/base64" + "encoding/binary" "encoding/xml" "errors" "fmt" @@ -32,15 +33,26 @@ import ( ) const ( - nsStream = "http://etherx.jabber.org/streams" - nsTLS = "urn:ietf:params:xml:ns:xmpp-tls" - nsSASL = "urn:ietf:params:xml:ns:xmpp-sasl" - nsBind = "urn:ietf:params:xml:ns:xmpp-bind" - nsClient = "jabber:client" + nsStream = "http://etherx.jabber.org/streams" + nsTLS = "urn:ietf:params:xml:ns:xmpp-tls" + nsSASL = "urn:ietf:params:xml:ns:xmpp-sasl" + nsBind = "urn:ietf:params:xml:ns:xmpp-bind" + nsClient = "jabber:client" + NsSession = "urn:ietf:params:xml:ns:xmpp-session" ) var DefaultConfig tls.Config +type Cookie uint64 + +func getCookie() Cookie { + var buf [8]byte + if _, err := rand.Reader.Read(buf[:]); err != nil { + panic("Failed to read random bytes: " + err.Error()) + } + return Cookie(binary.LittleEndian.Uint64(buf[:])) +} + type Client struct { conn net.Conn // connection to server jid string // Jabber ID for our connection @@ -117,6 +129,9 @@ type Options struct { // Debug output Debug bool + + //Use server sessions + Session bool } // NewClient establishes a new Client connection based on a set of Options. @@ -161,6 +176,7 @@ func NewClient(host, user, passwd string, debug bool) (*Client, error) { User: user, Password: passwd, Debug: debug, + Session: false, } return opts.NewClient() } @@ -172,6 +188,7 @@ func NewClientNoTLS(host, user, passwd string, debug bool) (*Client, error) { Password: passwd, NoTLS: true, Debug: debug, + Session: false, } return opts.NewClient() } @@ -343,14 +360,17 @@ func (c *Client) init(o *Options) error { } if err = c.p.DecodeElement(&f, nil); err != nil { // TODO: often stream stop. - //return os.NewError("unmarshal : " + err.String()) + //return errors.New("unmarshal : " + err.Error()) } + //Generate uniq cookie + cookie := getCookie() + // Send IQ message asking to bind to the local user name. if o.Resource == "" { - fmt.Fprintf(c.conn, "\n", nsBind) + fmt.Fprintf(c.conn, "\n", cookie, nsBind) } else { - fmt.Fprintf(c.conn, "%s\n", nsBind, o.Resource) + fmt.Fprintf(c.conn, "%s\n", cookie, nsBind, o.Resource) } var iq clientIQ if err = c.p.DecodeElement(&iq, nil); err != nil { @@ -361,6 +381,11 @@ func (c *Client) init(o *Options) error { } c.jid = iq.Bind.Jid // our local id + if o.Session { + //if server support session, open it + fmt.Fprintf(c.conn, "", xmlEscape(domain), cookie, NsSession) + } + // We're connected and can now receive and send messages. fmt.Fprintf(c.conn, "xaI for one welcome our new codebot overlords.") return nil From 0fd114068f2a065bdd566a7a02a45ef6109bc22b Mon Sep 17 00:00:00 2001 From: Falaleev Maxim Date: Mon, 15 Sep 2014 10:12:12 +0400 Subject: [PATCH 11/18] Add anonymous auth --- xmpp.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/xmpp.go b/xmpp.go index 6515fcc..00d86b5 100644 --- a/xmpp.go +++ b/xmpp.go @@ -268,6 +268,19 @@ func (c *Client) init(o *Options) error { } mechanism := "" for _, m := range f.Mechanisms.Mechanism { + if m == "ANONYMOUS" { + mechanism = m + fmt.Fprintf(c.conn, "\n", nsSASL) + break + } + + a := strings.SplitN(o.User, "@", 2) + if len(a) != 2 { + return errors.New("xmpp: invalid username (want user@domain): " + o.User) + } + user := a[0] + domain := a[1] + if m == "PLAIN" { mechanism = m // Plain authentication: send base64-encoded \x00 user \x00 password. From 41fd432f889d7a6fb73135dfc4a42d49ccae7544 Mon Sep 17 00:00:00 2001 From: Marin Date: Sun, 14 Sep 2014 23:15:56 -0700 Subject: [PATCH 12/18] optional TLS config --- xmpp.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/xmpp.go b/xmpp.go index 6515fcc..e647087 100644 --- a/xmpp.go +++ b/xmpp.go @@ -135,7 +135,7 @@ type Options struct { } // NewClient establishes a new Client connection based on a set of Options. -func (o Options) NewClient() (*Client, error) { +func (o Options) NewClient(tlsCfg ...tls.Config) (*Client, error) { host := o.Host c, err := connect(host, o.User, o.Password) if err != nil { @@ -146,7 +146,12 @@ func (o Options) NewClient() (*Client, error) { if o.NoTLS { client.conn = c } else { - tlsconn := tls.Client(c, &DefaultConfig) + var tlsconn *tls.Conn + if len(tlsCfg) > 0 { + tlsconn = tls.Client(c, &tlsCfg[0]) + } else { + tlsconn = tls.Client(c, &DefaultConfig) + } if err = tlsconn.Handshake(); err != nil { return nil, err } From f06f19e1217d95b49fe4917944251ea028e1c4bf Mon Sep 17 00:00:00 2001 From: Marin Date: Sun, 14 Sep 2014 23:21:06 -0700 Subject: [PATCH 13/18] moved to Options instead of NewClient --- xmpp.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/xmpp.go b/xmpp.go index e647087..afdf593 100644 --- a/xmpp.go +++ b/xmpp.go @@ -123,6 +123,9 @@ type Options struct { // from the server. Use "" to let the server generate one for your client. Resource string + // TLS Config + TLSConfig *tls.Config + // NoTLS disables TLS and specifies that a plain old unencrypted TCP connection should // be used. NoTLS bool @@ -135,7 +138,7 @@ type Options struct { } // NewClient establishes a new Client connection based on a set of Options. -func (o Options) NewClient(tlsCfg ...tls.Config) (*Client, error) { +func (o Options) NewClient() (*Client, error) { host := o.Host c, err := connect(host, o.User, o.Password) if err != nil { @@ -147,8 +150,8 @@ func (o Options) NewClient(tlsCfg ...tls.Config) (*Client, error) { client.conn = c } else { var tlsconn *tls.Conn - if len(tlsCfg) > 0 { - tlsconn = tls.Client(c, &tlsCfg[0]) + if o.TLSConfig != nil { + tlsconn = tls.Client(c, o.TLSConfig) } else { tlsconn = tls.Client(c, &DefaultConfig) } From 15989a19c32eb12c6e1224cf9066530ae26632e5 Mon Sep 17 00:00:00 2001 From: mattn Date: Wed, 17 Sep 2014 12:27:06 +0900 Subject: [PATCH 14/18] mv --- {example => _example}/example-gui.go | 0 {example => _example}/example.go | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {example => _example}/example-gui.go (100%) rename {example => _example}/example.go (100%) diff --git a/example/example-gui.go b/_example/example-gui.go similarity index 100% rename from example/example-gui.go rename to _example/example-gui.go diff --git a/example/example.go b/_example/example.go similarity index 100% rename from example/example.go rename to _example/example.go From 748282a14a0f5c71a80ec4deefd4a4efb7ad8741 Mon Sep 17 00:00:00 2001 From: Gabriel Guzman Date: Tue, 16 Sep 2014 18:17:55 -0400 Subject: [PATCH 15/18] Remove a declared variable that isn't used. So the library will compile again. --- xmpp.go | 1 - 1 file changed, 1 deletion(-) diff --git a/xmpp.go b/xmpp.go index a403f3a..08749e1 100644 --- a/xmpp.go +++ b/xmpp.go @@ -249,7 +249,6 @@ func (c *Client) init(o *Options) error { if len(a) != 2 { return errors.New("xmpp: invalid username (want user@domain): " + o.User) } - user := a[0] domain := a[1] // Declare intent to be a jabber client. From f402673c8c11698083b2d2414e9787c7050a995d Mon Sep 17 00:00:00 2001 From: mattn Date: Wed, 17 Sep 2014 12:35:47 +0900 Subject: [PATCH 16/18] Fix examples --- _example/example-gui.go | 8 +++++++- _example/example.go | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/_example/example-gui.go b/_example/example-gui.go index 0787cfc..70c250b 100644 --- a/_example/example-gui.go +++ b/_example/example-gui.go @@ -1,6 +1,7 @@ package main import ( + "crypto/tls" "github.com/mattn/go-gtk/gtk" "github.com/mattn/go-xmpp" "log" @@ -56,7 +57,7 @@ func main() { dialog.AddButton(gtk.STOCK_OK, gtk.RESPONSE_OK) dialog.AddButton(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) - dialog.SetDefaultResponse(int(gtk.RESPONSE_OK)) + dialog.SetDefaultResponse(gtk.RESPONSE_OK) dialog.SetTransientFor(window) dialog.ShowAll() res := dialog.Run() @@ -67,6 +68,11 @@ func main() { os.Exit(0) } + xmpp.DefaultConfig = tls.Config { + ServerName: "talk.google.com", + InsecureSkipVerify: false, + } + talk, err := xmpp.NewClient("talk.google.com:443", username_, password_, false) if err != nil { log.Fatal(err) diff --git a/_example/example.go b/_example/example.go index 3981192..e4834aa 100644 --- a/_example/example.go +++ b/_example/example.go @@ -2,6 +2,7 @@ package main import ( "bufio" + "crypto/tls" "flag" "fmt" "github.com/mattn/go-xmpp" @@ -17,6 +18,10 @@ var notls = flag.Bool("notls", false, "No TLS") var debug = flag.Bool("debug", false, "debug output") var session = flag.Bool("session", false, "use server session") +func serverName(host string) string { + return strings.Split(host, ":")[0] +} + func main() { flag.Usage = func() { fmt.Fprintf(os.Stderr, "usage: example [options]\n") @@ -28,6 +33,13 @@ func main() { flag.Usage() } + if !*notls { + xmpp.DefaultConfig = tls.Config { + ServerName: serverName(*server), + InsecureSkipVerify: false, + } + } + var talk *xmpp.Client var err error options := xmpp.Options{Host: *server, From c9bbe151b21c1a79482fab80715655b322f14dea Mon Sep 17 00:00:00 2001 From: crackcomm Date: Sat, 4 Oct 2014 18:22:05 +0200 Subject: [PATCH 17/18] Status message option --- _example/example.go | 5 ++++- xmpp.go | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/_example/example.go b/_example/example.go index e4834aa..6e5daff 100644 --- a/_example/example.go +++ b/_example/example.go @@ -14,6 +14,7 @@ import ( var server = flag.String("server", "talk.google.com:443", "server") var username = flag.String("username", "", "username") var password = flag.String("password", "", "password") +var status = flag.String("status", "", "status") var notls = flag.Bool("notls", false, "No TLS") var debug = flag.Bool("debug", false, "debug output") var session = flag.Bool("session", false, "use server session") @@ -47,7 +48,9 @@ func main() { Password: *password, NoTLS: *notls, Debug: *debug, - Session: *session} + Session: *session, + Status: *status, + } talk, err = options.NewClient() diff --git a/xmpp.go b/xmpp.go index 08749e1..b5d15cb 100644 --- a/xmpp.go +++ b/xmpp.go @@ -133,8 +133,11 @@ type Options struct { // Debug output Debug bool - //Use server sessions + // Use server sessions Session bool + + // Status message + Status string } // NewClient establishes a new Client connection based on a set of Options. @@ -407,7 +410,7 @@ func (c *Client) init(o *Options) error { } // We're connected and can now receive and send messages. - fmt.Fprintf(c.conn, "xaI for one welcome our new codebot overlords.") + fmt.Fprintf(c.conn, "xa%s", o.Status) return nil } From aa9390a115618d8ef110769036e07938eff21c69 Mon Sep 17 00:00:00 2001 From: crackcomm Date: Sat, 4 Oct 2014 18:29:19 +0200 Subject: [PATCH 18/18] Status and status message --- _example/example-gui.go | 4 ++-- _example/example.go | 20 +++++++++++--------- xmpp.go | 8 ++++++-- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/_example/example-gui.go b/_example/example-gui.go index 70c250b..f8d3dbc 100644 --- a/_example/example-gui.go +++ b/_example/example-gui.go @@ -68,8 +68,8 @@ func main() { os.Exit(0) } - xmpp.DefaultConfig = tls.Config { - ServerName: "talk.google.com", + xmpp.DefaultConfig = tls.Config{ + ServerName: "talk.google.com", InsecureSkipVerify: false, } diff --git a/_example/example.go b/_example/example.go index 6e5daff..9c01d45 100644 --- a/_example/example.go +++ b/_example/example.go @@ -14,7 +14,8 @@ import ( var server = flag.String("server", "talk.google.com:443", "server") var username = flag.String("username", "", "username") var password = flag.String("password", "", "password") -var status = flag.String("status", "", "status") +var status = flag.String("status", "xa", "status") +var statusMessage = flag.String("status-msg", "I for one welcome our new codebot overlords.", "status message") var notls = flag.Bool("notls", false, "No TLS") var debug = flag.Bool("debug", false, "debug output") var session = flag.Bool("session", false, "use server session") @@ -35,8 +36,8 @@ func main() { } if !*notls { - xmpp.DefaultConfig = tls.Config { - ServerName: serverName(*server), + xmpp.DefaultConfig = tls.Config{ + ServerName: serverName(*server), InsecureSkipVerify: false, } } @@ -44,12 +45,13 @@ func main() { var talk *xmpp.Client var err error options := xmpp.Options{Host: *server, - User: *username, - Password: *password, - NoTLS: *notls, - Debug: *debug, - Session: *session, - Status: *status, + User: *username, + Password: *password, + NoTLS: *notls, + Debug: *debug, + Session: *session, + Status: *status, + StatusMessage: *statusMessage, } talk, err = options.NewClient() diff --git a/xmpp.go b/xmpp.go index b5d15cb..2b8a298 100644 --- a/xmpp.go +++ b/xmpp.go @@ -136,8 +136,11 @@ type Options struct { // Use server sessions Session bool - // Status message + // Presence Status Status string + + // Status message + StatusMessage string } // NewClient establishes a new Client connection based on a set of Options. @@ -410,7 +413,8 @@ func (c *Client) init(o *Options) error { } // We're connected and can now receive and send messages. - fmt.Fprintf(c.conn, "xa%s", o.Status) + fmt.Fprintf(c.conn, "%s%s", o.Status, o.StatusMessage) + return nil }