forked from coyim/coyim
/
streams.go
44 lines (36 loc) · 1.36 KB
/
streams.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package xmpp implements the XMPP IM protocol, as specified in RFC 6120 and
// 6121.
package xmpp
import (
"errors"
"fmt"
)
//Send an initial stream header and receive the features required for
//continuation of the stream negotiation process.
//RFC 6120 section 4.3
func (c *conn) SendInitialStreamHeader() error {
if _, err := fmt.Fprintf(c.out, "<?xml version='1.0'?><stream:stream to='%s' xmlns='%s' xmlns:stream='%s' version='1.0'>\n", xmlEscape(c.originDomain), NsClient, NsStream); err != nil {
return err
}
se, err := nextStart(c.in)
if err != nil {
return err
}
if se.Name.Space != NsStream || se.Name.Local != "stream" {
//TODO: should send bad-namespace-prefix error?
return errors.New("xmpp: expected <stream> but got <" + se.Name.Local + "> in " + se.Name.Space)
}
//TODO: there must be an ID in the response stream header
//TODO: there must be an xml:lang in the response stream header
//RFC 6120, Section 4.7.3
// Stream features MUST follow the response stream header
// RFC 6120, section 4.3.2
if err := c.in.DecodeElement(&c.features, nil); err != nil {
//TODO: should send bad-format error?
return errors.New("xmpp: error to unmarshal <features>: " + err.Error())
}
return nil
}