1
0
Fork 0

Extract startClient function.

This commit is contained in:
Matt Goodall 2012-06-27 13:16:11 +01:00
parent 4e7d9e68d1
commit b908366544
1 changed files with 18 additions and 10 deletions

View File

@ -26,17 +26,8 @@ func NewClient(jid JID, password string, config *ClientConfig) (*client, error)
}
for {
// Send stream start.
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'>",
jid,
jid.Domain)
if err := stream.Send(fmt.Sprintf(s)); err != nil {
return nil, err
}
// Receive stream start.
if _, err := stream.Next(&xml.Name{nsStream, "stream"}); err != nil {
if err := startClient(stream, jid); err != nil {
return nil, err
}
@ -70,6 +61,23 @@ func NewClient(jid JID, password string, config *ClientConfig) (*client, error)
return &client{jid, stream}, nil
}
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'>",
jid,
jid.Domain)
if err := stream.Send(s); err != nil {
return err
}
if _, err := stream.Next(&xml.Name{nsStream, "stream"}); err != nil {
return err
}
return nil
}
func authenticate(stream *Stream, mechanisms []string, user, password string) error {
log.Println("authenticate, mechanisms=", mechanisms)