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