# HG changeset patch # User Chris Jones # Date 1326767429 21600 # Node ID 53f15893a1a7c3efe9278496d41f8cb058f14e0a # Parent 578c2a83dc189be42ec4ce68eb825ae287245b97 gofmt diff -r 578c2a83dc18 -r 53f15893a1a7 roster.go --- a/roster.go Thu Jan 12 23:14:25 2012 -0700 +++ b/roster.go Mon Jan 16 20:30:29 2012 -0600 @@ -12,32 +12,30 @@ // This file contains support for roster management, RFC 3921, Section 7. -var rosterExt Extension = Extension{StanzaHandlers: - map[string] func(*xml.Name) interface{}{NsRoster: - newRosterQuery}, Start: startRosterFilter} +var rosterExt Extension = Extension{StanzaHandlers: map[string]func(*xml.Name) interface{}{NsRoster: newRosterQuery}, Start: startRosterFilter} // Roster query/result type RosterQuery struct { XMLName xml.Name `xml:"jabber:iq:roster query"` - Item []RosterItem + Item []RosterItem } // See RFC 3921, Section 7.1. type RosterItem struct { - XMLName xml.Name `xml:"item"` - Jid string `xml:"attr"` - Subscription string `xml:"attr"` - Name string `xml:"attr"` - Group []string + XMLName xml.Name `xml:"item"` + Jid string `xml:"attr"` + Subscription string `xml:"attr"` + Name string `xml:"attr"` + Group []string } type rosterClient struct { - rosterChan <-chan []RosterItem + rosterChan <-chan []RosterItem rosterUpdate chan<- RosterItem } var ( - rosterClients = make(map[string] rosterClient) + rosterClients = make(map[string]rosterClient) ) // Implicitly becomes part of NewClient's extStanza arg. @@ -51,7 +49,7 @@ func fetchRoster(client *Client) os.Error { rosterUpdate := rosterClients[client.Uid].rosterUpdate - iq := &Iq{From: client.Jid.String(), Id: <- Id, Type: "get", + iq := &Iq{From: client.Jid.String(), Id: <-Id, Type: "get", Nested: []interface{}{RosterQuery{}}} ch := make(chan os.Error) f := func(st Stanza) bool { @@ -61,8 +59,8 @@ return false } var rq *RosterQuery - for _, ele := range(st.GetNested()) { - if q, ok := ele.(*RosterQuery) ; ok { + for _, ele := range st.GetNested() { + if q, ok := ele.(*RosterQuery); ok { rq = q break } @@ -72,7 +70,7 @@ "Roster query result not query: %v", st)) return false } - for _, item := range(rq.Item) { + for _, item := range rq.Item { rosterUpdate <- item } ch <- nil @@ -81,7 +79,7 @@ client.HandleStanza(iq.Id, f) client.Out <- iq // Wait for f to complete. - return <- ch + return <-ch } // The roster filter updates the Client's representation of the @@ -93,7 +91,7 @@ in := client.AddFilter(out) go func(in <-chan Stanza, out chan<- Stanza) { defer close(out) - for st := range(in) { + for st := range in { maybeUpdateRoster(client, st) out <- st } @@ -110,25 +108,24 @@ rosterUpdate := rosterClients[client.Uid].rosterUpdate var rq *RosterQuery - for _, ele := range(st.GetNested()) { - if q, ok := ele.(*RosterQuery) ; ok { + for _, ele := range st.GetNested() { + if q, ok := ele.(*RosterQuery); ok { rq = q break } } if st.GetName() == "iq" && st.GetType() == "set" && rq != nil { - for _, item := range(rq.Item) { + for _, item := range rq.Item { rosterUpdate <- item } // Send a reply. - iq := &Iq{To: st.GetFrom(), Id: st.GetId(), Type: - "result"} + iq := &Iq{To: st.GetFrom(), Id: st.GetId(), Type: "result"} client.Out <- iq } } func feedRoster(rosterCh chan<- []RosterItem, rosterUpdate <-chan RosterItem) { - roster := make(map[string] RosterItem) + roster := make(map[string]RosterItem) snapshot := []RosterItem{} for { select { @@ -141,7 +138,7 @@ case rosterCh <- snapshot: } snapshot = make([]RosterItem, 0, len(roster)) - for _, v := range(roster) { + for _, v := range roster { snapshot = append(snapshot, v) } } @@ -150,5 +147,5 @@ // Retrieve a snapshot of the roster for the given Client. func Roster(client *Client) []RosterItem { rosterChan := rosterClients[client.Uid].rosterChan - return <- rosterChan + return <-rosterChan } diff -r 578c2a83dc18 -r 53f15893a1a7 roster_test.go --- a/roster_test.go Thu Jan 12 23:14:25 2012 -0700 +++ b/roster_test.go Mon Jan 16 20:30:29 2012 -0600 @@ -14,8 +14,7 @@ // This is mostly just tests of the roster data structures. func TestRosterIqMarshal(t *testing.T) { - iq := &Iq{From: "from", Lang: "en", Nested: - []interface{}{RosterQuery{}}} + iq := &Iq{From: "from", Lang: "en", Nested: []interface{}{RosterQuery{}}} exp := `` assertMarshal(t, exp, iq) @@ -27,7 +26,7 @@ r := strings.NewReader(str) var st Stanza = &Iq{} xml.Unmarshal(r, st) - m := map[string] func(*xml.Name) interface{}{NsRoster: newRosterQuery} + m := map[string]func(*xml.Name) interface{}{NsRoster: newRosterQuery} err := parseExtended(st, m) if err != nil { t.Fatalf("parseExtended: %v", err) diff -r 578c2a83dc18 -r 53f15893a1a7 stream.go --- a/stream.go Thu Jan 12 23:14:25 2012 -0700 +++ b/stream.go Mon Jan 16 20:30:29 2012 -0600 @@ -47,7 +47,7 @@ } nr, err := cl.socket.Read(p) if nr == 0 { - if errno, ok := err.(*net.OpError) ; ok { + if errno, ok := err.(*net.OpError); ok { if errno.Timeout() { continue } @@ -89,7 +89,7 @@ } func readXml(r io.Reader, ch chan<- interface{}, - extStanza map[string] func(*xml.Name) interface{}) { +extStanza map[string]func(*xml.Name) interface{}) { if Loglevel >= syslog.LOG_DEBUG { pr, pw := io.Pipe() go tee(r, pw, "S: ") @@ -112,7 +112,7 @@ } var se xml.StartElement var ok bool - if se, ok = t.(xml.StartElement) ; !ok { + if se, ok = t.(xml.StartElement); !ok { continue } @@ -165,7 +165,7 @@ // If it's a Stanza, we try to unmarshal its innerxml // into objects of the appropriate respective // types. This is specified by our extensions. - if st, ok := obj.(Stanza) ; ok { + if st, ok := obj.(Stanza); ok { err = parseExtended(st, extStanza) if err != nil { if Log != nil { @@ -181,7 +181,7 @@ } } -func parseExtended(st Stanza, extStanza map[string] func(*xml.Name) interface{}) os.Error { +func parseExtended(st Stanza, extStanza map[string]func(*xml.Name) interface{}) os.Error { // Now parse the stanza's innerxml to find the string that we // can unmarshal this nested element from. reader := strings.NewReader(st.innerxml()) @@ -194,8 +194,8 @@ if err != nil { return err } - if se, ok := t.(xml.StartElement) ; ok { - if con, ok := extStanza[se.Name.Space] ; ok { + if se, ok := t.(xml.StartElement); ok { + if con, ok := extStanza[se.Name.Space]; ok { // Call the indicated constructor. nested := con(&se.Name) @@ -220,7 +220,7 @@ w = pw } defer func(w io.Writer) { - if c, ok := w.(io.Closer) ; ok { + if c, ok := w.(io.Closer); ok { c.Close() } }(w) @@ -239,13 +239,13 @@ func (cl *Client) readStream(srvIn <-chan interface{}, cliOut chan<- Stanza) { defer close(cliOut) - handlers := make(map[string] func(Stanza) bool) + handlers := make(map[string]func(Stanza) bool) Loop: for { select { - case h := <- cl.handlers: + case h := <-cl.handlers: handlers[h.id] = h.f - case x, ok := <- srvIn: + case x, ok := <-srvIn: if !ok { break Loop } @@ -292,14 +292,14 @@ // with the server. The control channel controls this loop's // activity. func writeStream(srvOut chan<- interface{}, cliIn <-chan Stanza, - control <-chan int) { +control <-chan int) { defer close(srvOut) var input <-chan Stanza Loop: for { select { - case status := <- control: + case status := <-control: switch status { case 0: input = nil @@ -308,7 +308,7 @@ case -1: break Loop } - case x, ok := <- input: + case x, ok := <-input: if !ok { break Loop } @@ -327,12 +327,12 @@ // Stanzas from the remote go up through a stack of filters to the // app. This function manages the filters. func filterTop(filterOut <-chan <-chan Stanza, filterIn chan<- <-chan Stanza, - topFilter <-chan Stanza, app chan<- Stanza) { +topFilter <-chan Stanza, app chan<- Stanza) { defer close(app) Loop: for { select { - case newFilterOut := <- filterOut: + case newFilterOut := <-filterOut: if newFilterOut == nil { if Log != nil { Log.Warning("Received nil filter") @@ -354,7 +354,7 @@ func filterBottom(from <-chan Stanza, to chan<- Stanza) { defer close(to) - for data := range(from) { + for data := range from { to <- data } } @@ -443,7 +443,7 @@ // BUG(cjyar): Doesn't implement TLS/SASL EXTERNAL. func (cl *Client) chooseSasl(fe *Features) { var digestMd5 bool - for _, m := range(fe.Mechanisms.Mechanism) { + for _, m := range fe.Mechanisms.Mechanism { switch strings.ToLower(m) { case "digest-md5": digestMd5 = true @@ -451,8 +451,7 @@ } if digestMd5 { - auth := &auth{XMLName: xml.Name{Space: NsSASL, Local: - "auth"}, Mechanism: "DIGEST-MD5"} + auth := &auth{XMLName: xml.Name{Space: NsSASL, Local: "auth"}, Mechanism: "DIGEST-MD5"} cl.xmlOut <- auth } } @@ -467,7 +466,7 @@ Log.Err("SASL challenge decode: " + err.String()) } - return; + return } srvMap := parseSasl(string(str)) @@ -490,10 +489,10 @@ } } -func (cl *Client) saslDigest1(srvMap map[string] string) { +func (cl *Client) saslDigest1(srvMap map[string]string) { // Make sure it supports qop=auth var hasAuth bool - for _, qop := range(strings.Fields(srvMap["qop"])) { + for _, qop := range strings.Fields(srvMap["qop"]) { if qop == "auth" { hasAuth = true } @@ -502,7 +501,7 @@ if Log != nil { Log.Err("Server doesn't support SASL auth") } - return; + return } // Pick a realm. @@ -552,7 +551,7 @@ clMap["username"] = `"` + username + `"` clMap["nonce"] = `"` + nonce + `"` clMap["cnonce"] = `"` + cnonceStr + `"` - clMap["nc"] = nonceCountStr + clMap["nc"] = nonceCountStr clMap["qop"] = "auth" clMap["digest-uri"] = `"` + digestUri + `"` clMap["response"] = response @@ -563,22 +562,17 @@ // Encode the map and send it. clStr := packSasl(clMap) b64 := base64.StdEncoding - clObj := &auth{XMLName: xml.Name{Space: NsSASL, Local: - "response"}, Chardata: - b64.EncodeToString([]byte(clStr))} + clObj := &auth{XMLName: xml.Name{Space: NsSASL, Local: "response"}, Chardata: b64.EncodeToString([]byte(clStr))} cl.xmlOut <- clObj } -func (cl *Client) saslDigest2(srvMap map[string] string) { +func (cl *Client) saslDigest2(srvMap map[string]string) { if cl.saslExpected == srvMap["rspauth"] { - clObj := &auth{XMLName: xml.Name{Space: NsSASL, Local: - "response"}} + clObj := &auth{XMLName: xml.Name{Space: NsSASL, Local: "response"}} cl.xmlOut <- clObj } else { - clObj := &auth{XMLName: xml.Name{Space: NsSASL, Local: - "failure"}, Any: - &Generic{XMLName: xml.Name{Space: NsSASL, - Local: "abort"}}} + clObj := &auth{XMLName: xml.Name{Space: NsSASL, Local: "failure"}, Any: &Generic{XMLName: xml.Name{Space: NsSASL, + Local: "abort"}}} cl.xmlOut <- clObj } } @@ -589,7 +583,7 @@ re := regexp.MustCompile(`([^=]+)="?([^",]+)"?,?`) strs := re.FindAllStringSubmatch(in, -1) m := make(map[string]string) - for _, pair := range(strs) { + for _, pair := range strs { key := strings.ToLower(string(pair[1])) value := string(pair[2]) m[key] = value @@ -600,18 +594,18 @@ // Inverse of parseSasl(). func packSasl(m map[string]string) string { var terms []string - for key, value := range(m) { + for key, value := range m { if key == "" || value == "" || value == `""` { continue } - terms = append(terms, key + "=" + value) + terms = append(terms, key+"="+value) } return strings.Join(terms, ",") } // Computes the response string for digest authentication. func saslDigestResponse(username, realm, passwd, nonce, cnonceStr, - authenticate, digestUri, nonceCountStr string) string { +authenticate, digestUri, nonceCountStr string) string { h := func(text string) []byte { h := md5.New() h.Write([]byte(text)) @@ -624,11 +618,11 @@ return h(secret + ":" + data) } - a1 := string(h(username + ":" + realm + ":" + passwd)) + ":" + + a1 := string(h(username+":"+realm+":"+passwd)) + ":" + nonce + ":" + cnonceStr a2 := authenticate + ":" + digestUri - response := hex(kd(hex(h(a1)), nonce + ":" + - nonceCountStr + ":" + cnonceStr + ":auth:" + + response := hex(kd(hex(h(a1)), nonce+":"+ + nonceCountStr+":"+cnonceStr+":auth:"+ hex(h(a2)))) return response } @@ -640,7 +634,7 @@ if res != "" { bindReq.Resource = &res } - msg := &Iq{Type: "set", Id: <- Id, Nested: []interface{}{bindReq}} + msg := &Iq{Type: "set", Id: <-Id, Nested: []interface{}{bindReq}} f := func(st Stanza) bool { if st.GetType() == "error" { if Log != nil { @@ -649,8 +643,8 @@ return false } var bindRepl *bindIq - for _, ele := range(st.GetNested()) { - if b, ok := ele.(*bindIq) ; ok { + for _, ele := range st.GetNested() { + if b, ok := ele.(*bindIq); ok { bindRepl = b break } diff -r 578c2a83dc18 -r 53f15893a1a7 structs.go --- a/structs.go Thu Jan 12 23:14:25 2012 -0700 +++ b/structs.go Mon Jan 16 20:30:29 2012 -0600 @@ -21,47 +21,51 @@ // entities. It looks like node@domain/resource. Node and resource are // sometimes optional. type JID struct { - Node string - Domain string + Node string + Domain string Resource string } + var _ fmt.Stringer = &JID{} var _ flag.Value = &JID{} // XMPP's XML element type stream struct { - To string `xml:"attr"` - From string `xml:"attr"` - Id string `xml:"attr"` - Lang string `xml:"attr"` + To string `xml:"attr"` + From string `xml:"attr"` + Id string `xml:"attr"` + Lang string `xml:"attr"` Version string `xml:"attr"` } + var _ xml.Marshaler = &stream{} var _ fmt.Stringer = &stream{} // type streamError struct { - Any Generic + Any Generic Text *errText } + var _ xml.Marshaler = &streamError{} type errText struct { Lang string `xml:"attr"` Text string `xml:"chardata"` } + var _ xml.Marshaler = &errText{} type Features struct { - Starttls *starttls + Starttls *starttls Mechanisms mechs - Bind *bindIq - Session *Generic - Any *Generic + Bind *bindIq + Session *Generic + Any *Generic } type starttls struct { - XMLName xml.Name + XMLName xml.Name Required *string } @@ -70,10 +74,10 @@ } type auth struct { - XMLName xml.Name - Chardata string `xml:"chardata"` + XMLName xml.Name + Chardata string `xml:"chardata"` Mechanism string `xml:"attr"` - Any *Generic + Any *Generic } // One of the three core XMPP stanza types: iq, message, presence. See @@ -102,49 +106,52 @@ // message stanza type Message struct { - To string `xml:"attr"` - From string `xml:"attr"` - Id string `xml:"attr"` - Type string `xml:"attr"` - Lang string `xml:"attr"` + To string `xml:"attr"` + From string `xml:"attr"` + Id string `xml:"attr"` + Type string `xml:"attr"` + Lang string `xml:"attr"` Innerxml string `xml:"innerxml"` - Error *Error - Subject *Generic - Body *Generic - Thread *Generic - Nested []interface{} + Error *Error + Subject *Generic + Body *Generic + Thread *Generic + Nested []interface{} } + var _ xml.Marshaler = &Message{} var _ Stanza = &Message{} // presence stanza type Presence struct { - To string `xml:"attr"` - From string `xml:"attr"` - Id string `xml:"attr"` - Type string `xml:"attr"` - Lang string `xml:"attr"` + To string `xml:"attr"` + From string `xml:"attr"` + Id string `xml:"attr"` + Type string `xml:"attr"` + Lang string `xml:"attr"` Innerxml string `xml:"innerxml"` - Error *Error - Show *Generic - Status *Generic + Error *Error + Show *Generic + Status *Generic Priority *Generic - Nested []interface{} + Nested []interface{} } + var _ xml.Marshaler = &Presence{} var _ Stanza = &Presence{} // iq stanza type Iq struct { - To string `xml:"attr"` - From string `xml:"attr"` - Id string `xml:"attr"` - Type string `xml:"attr"` - Lang string `xml:"attr"` + To string `xml:"attr"` + From string `xml:"attr"` + Id string `xml:"attr"` + Type string `xml:"attr"` + Lang string `xml:"attr"` Innerxml string `xml:"innerxml"` - Error *Error - Nested []interface{} + Error *Error + Nested []interface{} } + var _ xml.Marshaler = &Iq{} var _ Stanza = &Iq{} @@ -156,21 +163,23 @@ // Any nested element, if present. Any *Generic } + var _ os.Error = &Error{} // Used for resource binding as a nested element inside . type bindIq struct { - XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-bind bind"` - Resource *string `xml:"resource"` - Jid *string `xml:"jid"` + XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-bind bind"` + Resource *string `xml:"resource"` + Jid *string `xml:"jid"` } // Holds an XML element not described by the more specific types. type Generic struct { - XMLName xml.Name - Any *Generic + XMLName xml.Name + Any *Generic Chardata string `xml:"chardata"` } + var _ fmt.Stringer = &Generic{} func (jid *JID) String() string { @@ -303,7 +312,7 @@ } buf.WriteString(">") - if m, ok := st.(*Message) ; ok { + if m, ok := st.(*Message); ok { err := xml.Marshal(buf, m.Subject) if err != nil { return nil, err @@ -317,7 +326,7 @@ return nil, err } } - if p, ok := st.(*Presence) ; ok { + if p, ok := st.(*Presence); ok { err := xml.Marshal(buf, p.Show) if err != nil { return nil, err @@ -331,8 +340,8 @@ return nil, err } } - if nested := st.GetNested() ; nested != nil { - for _, n := range(nested) { + if nested := st.GetNested(); nested != nil { + for _, n := range nested { xml.Marshal(buf, n) } } else if st.innerxml() != "" { @@ -369,7 +378,7 @@ func (m *Message) GetType() string { return m.Type - } +} func (m *Message) GetLang() string { return m.Lang @@ -413,7 +422,7 @@ func (p *Presence) GetType() string { return p.Type - } +} func (p *Presence) GetLang() string { return p.Lang @@ -457,7 +466,7 @@ func (iq *Iq) GetType() string { return iq.Type - } +} func (iq *Iq) GetLang() string { return iq.Lang @@ -514,9 +523,8 @@ return stan, nil } -var bindExt Extension = Extension{StanzaHandlers: - map[string] func(*xml.Name) interface{}{NsBind: newBind}, - Start: func(cl *Client) {}} +var bindExt Extension = Extension{StanzaHandlers: map[string]func(*xml.Name) interface{}{NsBind: newBind}, + Start: func(cl *Client) {}} func newBind(name *xml.Name) interface{} { return &bindIq{} diff -r 578c2a83dc18 -r 53f15893a1a7 structs_test.go --- a/structs_test.go Thu Jan 12 23:14:25 2012 -0700 +++ b/structs_test.go Mon Jan 16 20:30:29 2012 -0600 @@ -71,7 +71,7 @@ name := xml.Name{Space: NsStreams, Local: "ack"} e := &streamError{Any: Generic{XMLName: name}} exp := ``; + `">` assertMarshal(t, exp, e) txt := errText{Lang: "pt", Text: "things happen"} @@ -83,9 +83,8 @@ } func TestIqMarshal(t *testing.T) { - iq := &Iq{Type: "set", Id: "3", Nested: - []interface{}{Generic{XMLName: xml.Name{Space: NsBind, - Local: "bind"}}}} + iq := &Iq{Type: "set", Id: "3", Nested: []interface{}{Generic{XMLName: xml.Name{Space: NsBind, + Local: "bind"}}}} exp := `` assertMarshal(t, exp, iq) diff -r 578c2a83dc18 -r 53f15893a1a7 xmpp.go --- a/xmpp.go Thu Jan 12 23:14:25 2012 -0700 +++ b/xmpp.go Mon Jan 16 20:30:29 2012 -0600 @@ -23,12 +23,12 @@ // Various XML namespaces. NsStreams = "urn:ietf:params:xml:ns:xmpp-streams" - 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" + 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" NsSession = "urn:ietf:params:xml:ns:xmpp-session" - NsRoster = "jabber:iq:roster" + NsRoster = "jabber:iq:roster" // DNS SRV names serverSrv = "xmpp-server" @@ -63,8 +63,8 @@ // Extensions can add stanza filters and/or new XML element types. type Extension struct { - StanzaHandlers map[string] func(*xml.Name) interface{} - Start func(*Client) + StanzaHandlers map[string]func(*xml.Name) interface{} + Start func(*Client) } // The client in a client-server XMPP connection. @@ -75,13 +75,13 @@ Uid string // This client's JID. This will be updated asynchronously by // the time StartSession() returns. - Jid JID - password string - socket net.Conn - socketSync sync.WaitGroup + Jid JID + password string + socket net.Conn + socketSync sync.WaitGroup saslExpected string - authDone bool - handlers chan *stanzaHandler + authDone bool + handlers chan *stanzaHandler inputControl chan int // Incoming XMPP stanzas from the server will be published on // this channel. Information which is only used by this @@ -89,15 +89,15 @@ In <-chan Stanza // Outgoing XMPP stanzas to the server should be sent to this // channel. - Out chan<- Stanza + Out chan<- Stanza xmlOut chan<- interface{} // Features advertised by the remote. This will be updated // asynchronously as new features are received throughout the // connection process. It should not be updated once // StartSession() returns. - Features *Features + Features *Features filterOut chan<- <-chan Stanza - filterIn <-chan <-chan Stanza + filterIn <-chan <-chan Stanza } // Connect to the appropriate server and authenticate as the given JID @@ -107,7 +107,7 @@ // send operation to Client.Out will block until negotiation (resource // binding) is complete. func NewClient(jid *JID, password string, exts []Extension) (*Client, - os.Error) { +os.Error) { // Include the mandatory extensions. exts = append(exts, rosterExt) exts = append(exts, bindExt) @@ -140,16 +140,16 @@ } cl := new(Client) - cl.Uid = <- Id + cl.Uid = <-Id cl.password = password cl.Jid = *jid cl.socket = tcp cl.handlers = make(chan *stanzaHandler, 100) cl.inputControl = make(chan int) - extStanza := make(map[string] func(*xml.Name) interface{}) - for _, ext := range(exts) { - for k, v := range(ext.StanzaHandlers) { + extStanza := make(map[string]func(*xml.Name) interface{}) + for _, ext := range exts { + for k, v := range ext.StanzaHandlers { extStanza[k] = v } } @@ -173,7 +173,7 @@ cl.In = clIn // Add filters for our extensions. - for _, ext := range(exts) { + for _, ext := range exts { ext.Start(cl) } @@ -193,7 +193,7 @@ } func startXmlReader(r io.Reader, - extStanza map[string] func(*xml.Name) interface{}) <-chan interface{} { +extStanza map[string]func(*xml.Name) interface{}) <-chan interface{} { ch := make(chan interface{}) go readXml(r, ch, extStanza) return ch @@ -231,7 +231,7 @@ func tee(r io.Reader, w io.Writer, prefix string) { defer func(w io.Writer) { - if c, ok := w.(io.Closer) ; ok { + if c, ok := w.(io.Closer); ok { c.Close() } }(w) @@ -272,10 +272,8 @@ // presence. The presence can be as simple as a newly-initialized // Presence struct. See RFC 3921, Section 3. func (cl *Client) StartSession(getRoster bool, pr *Presence) os.Error { - id := <- Id - iq := &Iq{To: cl.Jid.Domain, Id: id, Type: "set", Nested: - []interface{}{ Generic{XMLName: xml.Name{Space: - NsSession, Local: "session"}}}} + id := <-Id + iq := &Iq{To: cl.Jid.Domain, Id: id, Type: "set", Nested: []interface{}{Generic{XMLName: xml.Name{Space: NsSession, Local: "session"}}}} ch := make(chan os.Error) f := func(st Stanza) bool { if st.GetType() == "error" { @@ -293,7 +291,7 @@ cl.Out <- iq // Now wait until the callback is called. - if err := <- ch ; err != nil { + if err := <-ch; err != nil { return err } if getRoster { @@ -315,5 +313,5 @@ // channel closes, the filter should close its output channel. func (cl *Client) AddFilter(out <-chan Stanza) <-chan Stanza { cl.filterOut <- out - return <- cl.filterIn + return <-cl.filterIn } diff -r 578c2a83dc18 -r 53f15893a1a7 xmpp_test.go --- a/xmpp_test.go Thu Jan 12 23:14:25 2012 -0700 +++ b/xmpp_test.go Mon Jan 16 20:30:29 2012 -0600 @@ -16,8 +16,8 @@ func TestReadError(t *testing.T) { r := strings.NewReader(``) ch := make(chan interface{}) - go readXml(r, ch, make(map[string] func(*xml.Name) interface{})) - x := <- ch + go readXml(r, ch, make(map[string]func(*xml.Name) interface{})) + x := <-ch se, ok := x.(*streamError) if !ok { t.Fatalf("not StreamError: %v", reflect.TypeOf(x)) @@ -32,8 +32,8 @@ `Error text`) ch = make(chan interface{}) - go readXml(r, ch, make(map[string] func(*xml.Name) interface{})) - x = <- ch + go readXml(r, ch, make(map[string]func(*xml.Name) interface{})) + x = <-ch se, ok = x.(*streamError) if !ok { t.Fatalf("not StreamError: %v", reflect.TypeOf(x)) @@ -50,8 +50,8 @@ `xmlns="jabber:client" xmlns:stream="` + NsStream + `" version="1.0">`) ch := make(chan interface{}) - go readXml(r, ch, make(map[string] func(*xml.Name) interface{})) - x := <- ch + go readXml(r, ch, make(map[string]func(*xml.Name) interface{})) + x := <-ch ss, ok := x.(*stream) if !ok { t.Fatalf("not stream: %v", reflect.TypeOf(x)) @@ -78,15 +78,12 @@ } func TestWriteError(t *testing.T) { - se := &streamError{Any: Generic{XMLName: xml.Name{Local: - "blah"}}} + se := &streamError{Any: Generic{XMLName: xml.Name{Local: "blah"}}} str := testWrite(se) exp := `` assertEquals(t, exp, str) - se = &streamError{Any: Generic{XMLName: xml.Name{Space: - NsStreams, Local: "foo"}}, Text: - &errText{Lang: "ru", Text: "Пошёл ты"}} + se = &streamError{Any: Generic{XMLName: xml.Name{Space: NsStreams, Local: "foo"}}, Text: &errText{Lang: "ru", Text: "Пошёл ты"}} str = testWrite(se) exp = `