Ran gofix from weekly-2012-01-15.
authorChris Jones <christian.jones@sri.com>
Thu, 19 Jan 2012 12:25:36 -0600
changeset 74 e619e18dcec3
parent 73 acca351fb8f0
child 75 03a923eb5c01
Ran gofix from weekly-2012-01-15.
roster.go
roster_test.go
stream.go
structs.go
structs_test.go
xmpp.go
xmpp_test.go
--- a/roster.go	Thu Jan 19 11:06:42 2012 -0600
+++ b/roster.go	Thu Jan 19 12:25:36 2012 -0600
@@ -5,9 +5,10 @@
 package xmpp
 
 import (
+	"errors"
 	"fmt"
-	"os"
-	"xml"
+
+	"encoding/xml"
 )
 
 // This file contains support for roster management, RFC 3921, Section 7.
@@ -46,12 +47,12 @@
 // Synchronously fetch this entity's roster from the server and cache
 // that information. This is called once from a fairly deep call stack
 // as part of XMPP negotiation.
-func fetchRoster(client *Client) os.Error {
+func fetchRoster(client *Client) error {
 	rosterUpdate := rosterClients[client.Uid].rosterUpdate
 
 	iq := &Iq{From: client.Jid.String(), Id: <-Id, Type: "get",
 		Nested: []interface{}{RosterQuery{}}}
-	ch := make(chan os.Error)
+	ch := make(chan error)
 	f := func(st Stanza) bool {
 		defer close(ch)
 		if iq.Type == "error" {
@@ -66,7 +67,7 @@
 			}
 		}
 		if rq == nil {
-			ch <- os.NewError(fmt.Sprintf(
+			ch <- errors.New(fmt.Sprintf(
 				"Roster query result not query: %v", st))
 			return false
 		}
@@ -131,7 +132,7 @@
 		select {
 		case newIt := <-rosterUpdate:
 			if newIt.Subscription == "remove" {
-				roster[newIt.Jid] = RosterItem{}, false
+				delete(roster, newIt.Jid)
 			} else {
 				roster[newIt.Jid] = newIt
 			}
--- a/roster_test.go	Thu Jan 19 11:06:42 2012 -0600
+++ b/roster_test.go	Thu Jan 19 12:25:36 2012 -0600
@@ -5,10 +5,10 @@
 package xmpp
 
 import (
+	"encoding/xml"
 	"reflect"
 	"strings"
 	"testing"
-	"xml"
 )
 
 // This is mostly just tests of the roster data structures.
--- a/stream.go	Thu Jan 19 11:06:42 2012 -0600
+++ b/stream.go	Thu Jan 19 12:25:36 2012 -0600
@@ -11,20 +11,19 @@
 package xmpp
 
 import (
-	"big"
 	"crypto/md5"
 	"crypto/rand"
 	"crypto/tls"
 	"encoding/base64"
+	"encoding/xml"
 	"fmt"
 	"io"
+	"log/syslog"
+	"math/big"
 	"net"
-	"os"
 	"regexp"
 	"strings"
-	"syslog"
 	"time"
-	"xml"
 )
 
 // Callback to handle a stanza with a particular id.
@@ -53,14 +52,14 @@
 				}
 			}
 			if Log != nil {
-				Log.Err("read: " + err.String())
+				Log.Err("read: " + err.Error())
 			}
 			break
 		}
 		nw, err := w.Write(p[:nr])
 		if nw < nr {
 			if Log != nil {
-				Log.Err("read: " + err.String())
+				Log.Err("read: " + err.Error())
 			}
 			break
 		}
@@ -74,14 +73,14 @@
 		nr, err := r.Read(p)
 		if nr == 0 {
 			if Log != nil {
-				Log.Err("write: " + err.String())
+				Log.Err("write: " + err.Error())
 			}
 			break
 		}
 		nw, err := cl.socket.Write(p[:nr])
 		if nw < nr {
 			if Log != nil {
-				Log.Err("write: " + err.String())
+				Log.Err("write: " + err.Error())
 			}
 			break
 		}
@@ -89,7 +88,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: ")
@@ -103,9 +102,9 @@
 		// Sniff the next token on the stream.
 		t, err := p.Token()
 		if t == nil {
-			if err != os.EOF {
+			if err != io.EOF {
 				if Log != nil {
-					Log.Err("read: " + err.String())
+					Log.Err("read: " + err.Error())
 				}
 			}
 			break
@@ -124,7 +123,7 @@
 			if err != nil {
 				if Log != nil {
 					Log.Err("unmarshal stream: " +
-						err.String())
+						err.Error())
 				}
 				break Loop
 			}
@@ -157,7 +156,7 @@
 		err = p.Unmarshal(obj, &se)
 		if err != nil {
 			if Log != nil {
-				Log.Err("unmarshal: " + err.String())
+				Log.Err("unmarshal: " + err.Error())
 			}
 			break Loop
 		}
@@ -170,7 +169,7 @@
 			if err != nil {
 				if Log != nil {
 					Log.Err("ext unmarshal: " +
-						err.String())
+						err.Error())
 				}
 				break Loop
 			}
@@ -181,14 +180,14 @@
 	}
 }
 
-func parseExtended(st Stanza, extStanza map[string]func(*xml.Name) interface{}) os.Error {
+func parseExtended(st Stanza, extStanza map[string]func(*xml.Name) interface{}) error {
 	// Now parse the stanza's innerxml to find the string that we
 	// can unmarshal this nested element from.
 	reader := strings.NewReader(st.innerxml())
 	p := xml.NewParser(reader)
 	for {
 		t, err := p.Token()
-		if err == os.EOF {
+		if err == io.EOF {
 			break
 		}
 		if err != nil {
@@ -229,7 +228,7 @@
 		err := xml.Marshal(w, obj)
 		if err != nil {
 			if Log != nil {
-				Log.Err("write: " + err.String())
+				Log.Err("write: " + err.Error())
 			}
 			break
 		}
@@ -292,7 +291,7 @@
 // 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
@@ -327,7 +326,7 @@
 // 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 {
@@ -464,7 +463,7 @@
 		if err != nil {
 			if Log != nil {
 				Log.Err("SASL challenge decode: " +
-					err.String())
+					err.Error())
 			}
 			return
 		}
@@ -531,7 +530,7 @@
 	cnonce, err := rand.Int(rand.Reader, randSize)
 	if err != nil {
 		if Log != nil {
-			Log.Err("SASL rand: " + err.String())
+			Log.Err("SASL rand: " + err.Error())
 		}
 		return
 	}
@@ -605,11 +604,11 @@
 
 // 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))
-		return h.Sum()
+		return h.Sum(nil)
 	}
 	hex := func(bytes []byte) string {
 		return fmt.Sprintf("%x", bytes)
--- a/structs.go	Thu Jan 19 11:06:42 2012 -0600
+++ b/structs.go	Thu Jan 19 12:25:36 2012 -0600
@@ -8,13 +8,13 @@
 
 import (
 	"bytes"
+	"encoding/xml"
+	"errors"
 	"flag"
 	"fmt"
 	"io"
-	"os"
 	"regexp"
 	"strings"
-	"xml"
 )
 
 // JID represents an entity that can communicate with other
@@ -164,7 +164,7 @@
 	Any *Generic
 }
 
-var _ os.Error = &Error{}
+var _ error = &Error{}
 
 // Used for resource binding as a nested element inside <iq/>.
 type bindIq struct {
@@ -207,7 +207,7 @@
 	return true
 }
 
-func (s *stream) MarshalXML() ([]byte, os.Error) {
+func (s *stream) MarshalXML() ([]byte, error) {
 	buf := bytes.NewBuffer(nil)
 	buf.WriteString("<stream:stream")
 	writeField(buf, "xmlns", "jabber:client")
@@ -227,7 +227,7 @@
 	return string(result)
 }
 
-func parseStream(se xml.StartElement) (*stream, os.Error) {
+func parseStream(se xml.StartElement) (*stream, error) {
 	s := &stream{}
 	for _, attr := range se.Attr {
 		switch strings.ToLower(attr.Name.Local) {
@@ -246,7 +246,7 @@
 	return s, nil
 }
 
-func (s *streamError) MarshalXML() ([]byte, os.Error) {
+func (s *streamError) MarshalXML() ([]byte, error) {
 	buf := bytes.NewBuffer(nil)
 	buf.WriteString("<stream:error>")
 	xml.Marshal(buf, s.Any)
@@ -257,7 +257,7 @@
 	return buf.Bytes(), nil
 }
 
-func (e *errText) MarshalXML() ([]byte, os.Error) {
+func (e *errText) MarshalXML() ([]byte, error) {
 	buf := bytes.NewBuffer(nil)
 	buf.WriteString("<text")
 	writeField(buf, "xmlns", NsStreams)
@@ -291,7 +291,7 @@
 		u.XMLName.Local)
 }
 
-func marshalXML(st Stanza) ([]byte, os.Error) {
+func marshalXML(st Stanza) ([]byte, error) {
 	buf := bytes.NewBuffer(nil)
 	buf.WriteString("<")
 	buf.WriteString(st.GetName())
@@ -354,7 +354,7 @@
 	return buf.Bytes(), nil
 }
 
-func (er *Error) String() string {
+func (er *Error) Error() string {
 	buf := bytes.NewBuffer(nil)
 	xml.Marshal(buf, er)
 	return buf.String()
@@ -400,7 +400,7 @@
 	return m.Innerxml
 }
 
-func (m *Message) MarshalXML() ([]byte, os.Error) {
+func (m *Message) MarshalXML() ([]byte, error) {
 	return marshalXML(m)
 }
 
@@ -444,7 +444,7 @@
 	return p.Innerxml
 }
 
-func (p *Presence) MarshalXML() ([]byte, os.Error) {
+func (p *Presence) MarshalXML() ([]byte, error) {
 	return marshalXML(p)
 }
 
@@ -488,13 +488,13 @@
 	return iq.Innerxml
 }
 
-func (iq *Iq) MarshalXML() ([]byte, os.Error) {
+func (iq *Iq) MarshalXML() ([]byte, error) {
 	return marshalXML(iq)
 }
 
 // Parse a string into a struct implementing Stanza -- this will be
 // either an Iq, a Message, or a Presence.
-func ParseStanza(str string) (Stanza, os.Error) {
+func ParseStanza(str string) (Stanza, error) {
 	r := strings.NewReader(str)
 	p := xml.NewParser(r)
 	tok, err := p.Token()
@@ -503,7 +503,7 @@
 	}
 	se, ok := tok.(xml.StartElement)
 	if !ok {
-		return nil, os.NewError("Not a start element")
+		return nil, errors.New("Not a start element")
 	}
 	var stan Stanza
 	switch se.Name.Local {
@@ -514,7 +514,7 @@
 	case "presence":
 		stan = &Presence{}
 	default:
-		return nil, os.NewError("Not iq, message, or presence")
+		return nil, errors.New("Not iq, message, or presence")
 	}
 	err = p.Unmarshal(stan, &se)
 	if err != nil {
--- a/structs_test.go	Thu Jan 19 11:06:42 2012 -0600
+++ b/structs_test.go	Thu Jan 19 12:25:36 2012 -0600
@@ -6,8 +6,8 @@
 
 import (
 	"bytes"
+	"encoding/xml"
 	"testing"
-	"xml"
 )
 
 func assertEquals(t *testing.T, expected, observed string) {
--- a/xmpp.go	Thu Jan 19 11:06:42 2012 -0600
+++ b/xmpp.go	Thu Jan 19 12:25:36 2012 -0600
@@ -8,13 +8,13 @@
 
 import (
 	"bytes"
+	"encoding/xml"
+	"errors"
 	"fmt"
 	"io"
+	"log/syslog"
 	"net"
-	"os"
 	"sync"
-	"syslog"
-	"xml"
 )
 
 const (
@@ -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) {
+	error) {
 	// Include the mandatory extensions.
 	exts = append(exts, rosterExt)
 	exts = append(exts, bindExt)
@@ -115,8 +115,8 @@
 	// Resolve the domain in the JID.
 	_, srvs, err := net.LookupSRV(clientSrv, "tcp", jid.Domain)
 	if err != nil {
-		return nil, os.NewError("LookupSrv " + jid.Domain +
-			": " + err.String())
+		return nil, errors.New("LookupSrv " + jid.Domain +
+			": " + err.Error())
 	}
 
 	var tcp *net.TCPConn
@@ -124,14 +124,14 @@
 		addrStr := fmt.Sprintf("%s:%d", srv.Target, srv.Port)
 		addr, err := net.ResolveTCPAddr("tcp", addrStr)
 		if err != nil {
-			err = os.NewError(fmt.Sprintf("ResolveTCPAddr(%s): %s",
-				addrStr, err.String()))
+			err = errors.New(fmt.Sprintf("ResolveTCPAddr(%s): %s",
+				addrStr, err.Error()))
 			continue
 		}
 		tcp, err = net.DialTCP("tcp", nil, addr)
 		if err != nil {
-			err = os.NewError(fmt.Sprintf("DialTCP(%s): %s",
-				addr, err.String()))
+			err = errors.New(fmt.Sprintf("DialTCP(%s): %s",
+				addr, err.Error()))
 			continue
 		}
 	}
@@ -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
@@ -271,10 +271,10 @@
 // session, retrieve the roster, and broadcast an initial
 // 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 {
+func (cl *Client) StartSession(getRoster bool, pr *Presence) error {
 	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)
+	ch := make(chan error)
 	f := func(st Stanza) bool {
 		if st.GetType() == "error" {
 			if Log != nil {
--- a/xmpp_test.go	Thu Jan 19 11:06:42 2012 -0600
+++ b/xmpp_test.go	Thu Jan 19 12:25:36 2012 -0600
@@ -6,11 +6,11 @@
 
 import (
 	"bytes"
+	"encoding/xml"
 	"reflect"
 	"strings"
 	"sync"
 	"testing"
-	"xml"
 )
 
 func TestReadError(t *testing.T) {