Make the stream struct private. Rename factory func.

This commit is contained in:
Matt Goodall 2012-07-06 11:46:43 +01:00
parent b879d2cfef
commit 72dc222360
3 changed files with 17 additions and 17 deletions

View File

@ -19,9 +19,9 @@ type ClientConfig struct {
InsecureSkipVerify bool
}
func ClientStream(jid JID, password string, config *ClientConfig) (*Stream, error) {
func ClientStream(jid JID, password string, config *ClientConfig) (*stream, error) {
stream, err := NewStream(jid.Domain + ":5222")
stream, err := Stream(jid.Domain + ":5222")
if err != nil {
return nil, err
}
@ -62,7 +62,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(
"<stream:stream from='%s' to='%s' version='1.0' xml:lang='en' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>",
@ -79,7 +79,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 +90,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(
"<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>%s</auth>",

View File

@ -8,9 +8,9 @@ import (
"log"
)
func ComponentStream(addr string, jid JID, secret string) (*Stream, error) {
func ComponentStream(addr string, jid JID, secret string) (*stream, error) {
stream, err := NewStream(addr)
stream, err := Stream(addr)
if err != nil {
return nil, err
}
@ -27,7 +27,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(
"<stream:stream xmlns='jabber:component:accept' xmlns:stream='http://etherx.jabber.org/streams' to='%s'>",
@ -55,7 +55,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))

View File

@ -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 NewStream(addr string) (*Stream, error) {
func Stream(addr string) (*stream, error) {
log.Println("Connecting to", addr)
@ -33,10 +33,10 @@ func NewStream(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)
}