Merge pull request #31 from max107/anonymous

Add anonymous auth via empty User and Password
This commit is contained in:
mattn 2014-09-15 16:36:31 +09:00
commit 11887e6acb

13
xmpp.go
View File

@ -268,6 +268,19 @@ func (c *Client) init(o *Options) error {
} }
mechanism := "" mechanism := ""
for _, m := range f.Mechanisms.Mechanism { for _, m := range f.Mechanisms.Mechanism {
if m == "ANONYMOUS" {
mechanism = m
fmt.Fprintf(c.conn, "<auth xmlns='%s' mechanism='ANONYMOUS' />\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" { if m == "PLAIN" {
mechanism = m mechanism = m
// Plain authentication: send base64-encoded \x00 user \x00 password. // Plain authentication: send base64-encoded \x00 user \x00 password.