From f97ed9ea37525990f7be9786966aa413828dfbf2 Mon Sep 17 00:00:00 2001 From: Matt Goodall Date: Thu, 12 Jul 2012 00:48:44 +0100 Subject: [PATCH] Remove element name match test from Stream.Next(). Only one place still used it, so it might as well go. --- src/xmpp/client.go | 2 +- src/xmpp/component.go | 6 +++++- src/xmpp/stream.go | 12 +++--------- src/xmpp/xmpp.go | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/xmpp/client.go b/src/xmpp/client.go index 44089dc..9a30638 100644 --- a/src/xmpp/client.go +++ b/src/xmpp/client.go @@ -150,7 +150,7 @@ func authenticatePlain(stream *Stream, user, password string) error { } func authenticateResponse(stream *Stream) error { - if se, err := stream.Next(nil); err != nil { + if se, err := stream.Next(); err != nil { return err } else { switch se.Name.Local { diff --git a/src/xmpp/component.go b/src/xmpp/component.go index d6c2877..f534284 100644 --- a/src/xmpp/component.go +++ b/src/xmpp/component.go @@ -70,8 +70,12 @@ func handshake(stream *Stream, streamId, secret string) error { } // Get handshake response. - if _, err := stream.Next(&xml.Name{"jabber:component:accept", "handshake"}); err != nil { + if start, err := stream.Next(); err != nil { return err + } else { + if start.Name != (xml.Name{"jabber:component:accept", "handshake"}) { + return fmt.Errorf("Expected , for %s", start.Name) + } } if err := stream.Skip(); err != nil { return err diff --git a/src/xmpp/stream.go b/src/xmpp/stream.go index 87556bb..7f5b850 100644 --- a/src/xmpp/stream.go +++ b/src/xmpp/stream.go @@ -4,7 +4,6 @@ import ( "bytes" "crypto/tls" "encoding/xml" - "fmt" "io" "log" "net" @@ -124,11 +123,10 @@ func (stream *Stream) send(b []byte) error { return nil } -// Find start of next stanza. If match is not nil the stanza's XML name -// is compared and must be equal. +// Find start of next stanza. // Bad things are very likely to happen if a call to Next() is successful but // you don't actually decode or skip the element. -func (stream *Stream) Next(match *xml.Name) (*xml.StartElement, error) { +func (stream *Stream) Next() (*xml.StartElement, error) { start, err := nextStartElement(stream.dec) if err != nil { @@ -144,10 +142,6 @@ func (stream *Stream) Next(match *xml.Name) (*xml.StartElement, error) { log.Println("recv:", stream.stanzaBuf) } - if match != nil && start.Name != *match { - return nil, fmt.Errorf("Expected %s, got %s", *match, start.Name) - } - return start, nil } @@ -194,7 +188,7 @@ func (stream *Stream) DecodeElement(v interface{}, start *xml.StartElement) erro // Explicity lookup next start element to ensure stream is validated, // stanza is logged, etc. if start == nil { - if se, err := stream.Next(nil); err != nil { + if se, err := stream.Next(); err != nil { return err } else { start = se diff --git a/src/xmpp/xmpp.go b/src/xmpp/xmpp.go index 9cfa6ce..057efdd 100644 --- a/src/xmpp/xmpp.go +++ b/src/xmpp/xmpp.go @@ -151,7 +151,7 @@ func (x *XMPP) receiver() { defer close(x.in) for { - start, err := x.stream.Next(nil) + start, err := x.stream.Next() if err != nil { x.in <- err return