Make Stream public again, so we actually get some documentation for it.

This commit is contained in:
Matt Goodall 2012-07-06 14:29:15 +01:00
parent 72dc222360
commit 678b9c48a1
5 changed files with 21 additions and 19 deletions

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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(
"<stream:stream from='%s' to='%s' version='1.0' xml:lang='en' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>",
@ -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(
"<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>%s</auth>",

View File

@ -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(
"<stream:stream xmlns='jabber:component:accept' xmlns:stream='http://etherx.jabber.org/streams' to='%s'>",
@ -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))

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 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)
}