From 678b9c48a1b236a4608c0769319623524ca18878 Mon Sep 17 00:00:00 2001 From: Matt Goodall Date: Fri, 6 Jul 2012 14:29:15 +0100 Subject: [PATCH] Make Stream public again, so we actually get some documentation for it. --- client.go | 2 +- component.go | 2 +- src/xmpp/client.go | 11 ++++++----- src/xmpp/component.go | 9 +++++---- src/xmpp/stream.go | 16 ++++++++-------- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/client.go b/client.go index 4f32383..51f7f6c 100644 --- a/client.go +++ b/client.go @@ -17,7 +17,7 @@ func main() { jid, _ := xmpp.ParseJID(*jid) password := *password - stream, err := xmpp.ClientStream(jid, password, &xmpp.ClientConfig{}) + stream, err := xmpp.NewClientStream(jid, password, &xmpp.ClientConfig{}) if err != nil { log.Fatal(err) } diff --git a/component.go b/component.go index 4784cc0..55034f3 100644 --- a/component.go +++ b/component.go @@ -16,7 +16,7 @@ func main() { jid, _ := xmpp.ParseJID(*jid) secret := *secret - stream, err := xmpp.ComponentStream("localhost:5347", jid, secret) + stream, err := xmpp.NewComponentStream("localhost:5347", jid, secret) if err != nil { log.Fatal(err) } diff --git a/src/xmpp/client.go b/src/xmpp/client.go index ecdc255..38ce43f 100644 --- a/src/xmpp/client.go +++ b/src/xmpp/client.go @@ -19,9 +19,10 @@ type ClientConfig struct { InsecureSkipVerify bool } -func ClientStream(jid JID, password string, config *ClientConfig) (*stream, error) { +// Create a client XMPP stream. +func NewClientStream(jid JID, password string, config *ClientConfig) (*Stream, error) { - stream, err := Stream(jid.Domain + ":5222") + stream, err := NewStream(jid.Domain + ":5222") if err != nil { return nil, err } @@ -62,7 +63,7 @@ func ClientStream(jid JID, password string, config *ClientConfig) (*stream, erro return stream, nil } -func startClient(stream *stream, jid JID) error { +func startClient(stream *Stream, jid JID) error { s := fmt.Sprintf( "", @@ -79,7 +80,7 @@ func startClient(stream *stream, jid JID) error { return nil } -func authenticate(stream *stream, mechanisms []string, user, password string) error { +func authenticate(stream *Stream, mechanisms []string, user, password string) error { log.Println("authenticate, mechanisms=", mechanisms) @@ -90,7 +91,7 @@ func authenticate(stream *stream, mechanisms []string, user, password string) er return authenticatePlain(stream, user, password) } -func authenticatePlain(stream *stream, user, password string) error { +func authenticatePlain(stream *Stream, user, password string) error { x := fmt.Sprintf( "%s", diff --git a/src/xmpp/component.go b/src/xmpp/component.go index 64de1c0..895e614 100644 --- a/src/xmpp/component.go +++ b/src/xmpp/component.go @@ -8,9 +8,10 @@ import ( "log" ) -func ComponentStream(addr string, jid JID, secret string) (*stream, error) { +// Create a component XMPP stream. +func NewComponentStream(addr string, jid JID, secret string) (*Stream, error) { - stream, err := Stream(addr) + stream, err := NewStream(addr) if err != nil { return nil, err } @@ -27,7 +28,7 @@ func ComponentStream(addr string, jid JID, secret string) (*stream, error) { return stream, nil } -func startComponent(stream *stream, jid JID) (string, error) { +func startComponent(stream *Stream, jid JID) (string, error) { s := fmt.Sprintf( "", @@ -55,7 +56,7 @@ func startComponent(stream *stream, jid JID) (string, error) { return streamId, nil } -func handshake(stream *stream, streamId, secret string) error { +func handshake(stream *Stream, streamId, secret string) error { hash := sha1.New() hash.Write([]byte(streamId)) diff --git a/src/xmpp/stream.go b/src/xmpp/stream.go index f6a7db9..e7cff9e 100644 --- a/src/xmpp/stream.go +++ b/src/xmpp/stream.go @@ -14,12 +14,12 @@ const ( nsTLS = "urn:ietf:params:xml:ns:xmpp-tls" ) -type stream struct { +type Stream struct { conn net.Conn dec *xml.Decoder } -func Stream(addr string) (*stream, error) { +func NewStream(addr string) (*Stream, error) { log.Println("Connecting to", addr) @@ -33,10 +33,10 @@ func Stream(addr string) (*stream, error) { } dec := xml.NewDecoder(conn) - return &stream{conn, dec}, nil + return &Stream{conn, dec}, nil } -func (stream *stream) UpgradeTLS(config *tls.Config) error { +func (stream *Stream) UpgradeTLS(config *tls.Config) error { log.Println("Upgrading to TLS") @@ -60,14 +60,14 @@ func (stream *stream) UpgradeTLS(config *tls.Config) error { return nil } -func (stream *stream) Send(s string) error { +func (stream *Stream) Send(s string) error { if _, err := stream.conn.Write([]byte(s)); err != nil { return err } return nil } -func (stream *stream) Next(match *xml.Name) (*xml.StartElement, error) { +func (stream *Stream) Next(match *xml.Name) (*xml.StartElement, error) { for { t, err := stream.dec.Token() if err != nil { @@ -83,11 +83,11 @@ func (stream *stream) Next(match *xml.Name) (*xml.StartElement, error) { panic("Unreachable") } -func (stream *stream) Decode(i interface{}) error { +func (stream *Stream) Decode(i interface{}) error { return stream.dec.Decode(i) } -func (stream *stream) DecodeElement(i interface{}, se *xml.StartElement) error { +func (stream *Stream) DecodeElement(i interface{}, se *xml.StartElement) error { return stream.dec.DecodeElement(i, se) }