Made the namespace constants public.
authorChris Jones <chris@cjones.org>
Fri, 30 Dec 2011 17:27:14 -0700
changeset 34 7b1f924c75e2
parent 33 571713f49494
child 35 569833f08780
Made the namespace constants public.
stream.go
structs.go
structs_test.go
xmpp.go
xmpp_test.go
--- a/stream.go	Fri Dec 30 17:16:37 2011 -0700
+++ b/stream.go	Fri Dec 30 17:27:14 2011 -0700
@@ -107,7 +107,7 @@
 		// Allocate the appropriate structure for this token.
 		var obj interface{}
 		switch se.Name.Space + " " + se.Name.Local {
-		case nsStream + " stream":
+		case NsStream + " stream":
 			st, err := parseStream(se)
 			if err != nil {
 				log.Printf("unmarshal stream: %v",
@@ -116,14 +116,14 @@
 			}
 			ch <- st
 			continue
-		case "stream error", nsStream + " error":
+		case "stream error", NsStream + " error":
 			obj = &streamError{}
-		case nsStream + " features":
+		case NsStream + " features":
 			obj = &Features{}
-		case nsTLS + " proceed", nsTLS + " failure":
+		case NsTLS + " proceed", NsTLS + " failure":
 			obj = &starttls{}
-		case nsSASL + " challenge", nsSASL + " failure",
-			nsSASL + " success":
+		case NsSASL + " challenge", NsSASL + " failure",
+			NsSASL + " success":
 			obj = &auth{}
 		case "jabber:client iq":
 			obj = &Iq{}
@@ -255,7 +255,7 @@
 func (cl *Client) handleFeatures(fe *Features) {
 	cl.Features = fe
 	if fe.Starttls != nil {
-		start := &starttls{XMLName: xml.Name{Space: nsTLS,
+		start := &starttls{XMLName: xml.Name{Space: NsTLS,
 			Local: "starttls"}}
 		cl.xmlOut <- start
 		return
@@ -332,7 +332,7 @@
 	}
 
 	if digestMd5 {
-		auth := &auth{XMLName: xml.Name{Space: nsSASL, Local:
+		auth := &auth{XMLName: xml.Name{Space: NsSASL, Local:
 				"auth"}, Mechanism: "DIGEST-MD5"}
 		cl.xmlOut <- auth
 	}
@@ -434,7 +434,7 @@
 	// Encode the map and send it.
 	clStr := packSasl(clMap)
 	b64 := base64.StdEncoding
-	clObj := &auth{XMLName: xml.Name{Space: nsSASL, Local:
+	clObj := &auth{XMLName: xml.Name{Space: NsSASL, Local:
 			"response"}, Chardata:
 		b64.EncodeToString([]byte(clStr))}
 	cl.xmlOut <- clObj
@@ -442,13 +442,13 @@
 
 func (cl *Client) saslDigest2(srvMap map[string] string) {
 	if cl.saslExpected == srvMap["rspauth"] {
-		clObj := &auth{XMLName: xml.Name{Space: nsSASL, Local:
+		clObj := &auth{XMLName: xml.Name{Space: NsSASL, Local:
 				"response"}}
 		cl.xmlOut <- clObj
 	} else {
-		clObj := &auth{XMLName: xml.Name{Space: nsSASL, Local:
+		clObj := &auth{XMLName: xml.Name{Space: NsSASL, Local:
 				"failure"}, Any:
-			&Generic{XMLName: xml.Name{Space: nsSASL,
+			&Generic{XMLName: xml.Name{Space: NsSASL,
 				Local: "abort"}}}
 		cl.xmlOut <- clObj
 	}
@@ -508,7 +508,7 @@
 func (cl *Client) bind(bind *Generic) {
 	res := cl.Jid.Resource
 	msg := &Iq{Type: "set", Id: <- cl.Id, Any:
-		&Generic{XMLName: xml.Name{Space: nsBind, Local:
+		&Generic{XMLName: xml.Name{Space: NsBind, Local:
 					"bind"}}}
 	if res != "" {
 		msg.Any.Any = &Generic{XMLName: xml.Name{Local:
--- a/structs.go	Fri Dec 30 17:16:37 2011 -0700
+++ b/structs.go	Fri Dec 30 17:27:14 2011 -0700
@@ -205,7 +205,7 @@
 	buf := bytes.NewBuffer(nil)
 	buf.WriteString("<stream:stream")
 	writeField(buf, "xmlns", "jabber:client")
-	writeField(buf, "xmlns:stream", nsStream)
+	writeField(buf, "xmlns:stream", NsStream)
 	writeField(buf, "to", s.To)
 	writeField(buf, "from", s.From)
 	writeField(buf, "id", s.Id)
@@ -254,7 +254,7 @@
 func (e *errText) MarshalXML() ([]byte, os.Error) {
 	buf := bytes.NewBuffer(nil)
 	buf.WriteString("<text")
-	writeField(buf, "xmlns", nsStreams)
+	writeField(buf, "xmlns", NsStreams)
 	writeField(buf, "xml:lang", e.Lang)
 	buf.WriteString(">")
 	xml.Escape(buf, []byte(e.Text))
--- a/structs_test.go	Fri Dec 30 17:16:37 2011 -0700
+++ b/structs_test.go	Fri Dec 30 17:27:14 2011 -0700
@@ -52,40 +52,40 @@
 func TestStreamMarshal(t *testing.T) {
 	s := &stream{To: "bob"}
 	exp := `<stream:stream xmlns="jabber:client"` +
-		` xmlns:stream="` + nsStream + `" to="bob">`
+		` xmlns:stream="` + NsStream + `" to="bob">`
 	assertMarshal(t, exp, s)
 
 	s = &stream{To: "bob", From: "alice", Id: "#3", Version: "5.3"}
 	exp = `<stream:stream xmlns="jabber:client"` +
-		` xmlns:stream="` + nsStream + `" to="bob" from="alice"` +
+		` xmlns:stream="` + NsStream + `" to="bob" from="alice"` +
 		` id="#3" version="5.3">`
 	assertMarshal(t, exp, s)
 
 	s = &stream{Lang: "en_US"}
 	exp = `<stream:stream xmlns="jabber:client"` +
-		` xmlns:stream="` + nsStream + `" xml:lang="en_US">`
+		` xmlns:stream="` + NsStream + `" xml:lang="en_US">`
 	assertMarshal(t, exp, s)
 }
 
 func TestStreamErrorMarshal(t *testing.T) {
-	name := xml.Name{Space: nsStreams, Local: "ack"}
+	name := xml.Name{Space: NsStreams, Local: "ack"}
 	e := &streamError{Any: Generic{XMLName: name}}
-	exp := `<stream:error><ack xmlns="` + nsStreams +
+	exp := `<stream:error><ack xmlns="` + NsStreams +
 		`"></ack></stream:error>`;
 	assertMarshal(t, exp, e)
 
 	txt := errText{Lang: "pt", Text: "things happen"}
 	e = &streamError{Any: Generic{XMLName: name}, Text: &txt}
-	exp = `<stream:error><ack xmlns="` + nsStreams +
-		`"></ack><text xmlns="` + nsStreams +
+	exp = `<stream:error><ack xmlns="` + NsStreams +
+		`"></ack><text xmlns="` + NsStreams +
 		`" xml:lang="pt">things happen</text></stream:error>`
 	assertMarshal(t, exp, e)
 }
 
 func TestIqMarshal(t *testing.T) {
 	iq := &Iq{Type: "set", Id: "3", Any: &Generic{XMLName:
-			xml.Name{Space: nsBind, Local: "bind"}}}
-	exp := `<iq id="3" type="set"><bind xmlns="` + nsBind +
+			xml.Name{Space: NsBind, Local: "bind"}}}
+	exp := `<iq id="3" type="set"><bind xmlns="` + NsBind +
 		`"></bind></iq>`
 	assertMarshal(t, exp, iq)
 }
--- a/xmpp.go	Fri Dec 30 17:16:37 2011 -0700
+++ b/xmpp.go	Fri Dec 30 17:27:14 2011 -0700
@@ -26,12 +26,12 @@
 
 	// BUG(cjyar) These should be public.
 	// Various XML namespaces.
-	nsStreams = "urn:ietf:params:xml:ns:xmpp-streams"
-	nsStream = "http://etherx.jabber.org/streams"
-	nsTLS = "urn:ietf:params:xml:ns:xmpp-tls"
-	nsSASL = "urn:ietf:params:xml:ns:xmpp-sasl"
-	nsBind = "urn:ietf:params:xml:ns:xmpp-bind"
-	nsSession = "urn:ietf:params:xml:ns:xmpp-session"
+	NsStreams = "urn:ietf:params:xml:ns:xmpp-streams"
+	NsStream = "http://etherx.jabber.org/streams"
+	NsTLS = "urn:ietf:params:xml:ns:xmpp-tls"
+	NsSASL = "urn:ietf:params:xml:ns:xmpp-sasl"
+	NsBind = "urn:ietf:params:xml:ns:xmpp-bind"
+	NsSession = "urn:ietf:params:xml:ns:xmpp-session"
 	NsRoster = "jabber:iq:roster"
 
 	// DNS SRV names
@@ -257,7 +257,7 @@
 func (cl *Client) StartSession(getRoster bool, pr *Presence) os.Error {
 	id := <- cl.Id
 	iq := &Iq{To: cl.Jid.Domain, Id: id, Type: "set", Any:
-		&Generic{XMLName: xml.Name{Space: nsSession, Local:
+		&Generic{XMLName: xml.Name{Space: NsSession, Local:
 				"session"}}}
 	ch := make(chan os.Error)
 	f := func(st Stanza) bool {
--- a/xmpp_test.go	Fri Dec 30 17:16:37 2011 -0700
+++ b/xmpp_test.go	Fri Dec 30 17:27:14 2011 -0700
@@ -29,7 +29,7 @@
 	}
 
 	r = strings.NewReader(`<stream:error><bad-foo/>` +
-		`<text xml:lang="en" xmlns="` + nsStreams +
+		`<text xml:lang="en" xmlns="` + NsStreams +
 		`">Error text</text></stream:error>`)
 	ch = make(chan interface{})
 	go readXml(r, ch)
@@ -47,7 +47,7 @@
 func TestReadStream(t *testing.T) {
 	r := strings.NewReader(`<stream:stream to="foo.com" ` +
 		`from="bar.org" id="42"` +
-		`xmlns="jabber:client" xmlns:stream="` + nsStream +
+		`xmlns="jabber:client" xmlns:stream="` + NsStream +
 		`" version="1.0">`)
 	ch := make(chan interface{})
 	go readXml(r, ch)
@@ -85,11 +85,11 @@
 	assertEquals(t, exp, str)
 
 	se = &streamError{Any: Generic{XMLName: xml.Name{Space:
-				nsStreams, Local: "foo"}}, Text:
+				NsStreams, Local: "foo"}}, Text:
 		&errText{Lang: "ru", Text: "Пошёл ты"}}
 	str = testWrite(se)
-	exp = `<stream:error><foo xmlns="` + nsStreams +
-		`"></foo><text xmlns="` + nsStreams +
+	exp = `<stream:error><foo xmlns="` + NsStreams +
+		`"></foo><text xmlns="` + NsStreams +
 		`" xml:lang="ru">Пошёл ты</text></stream:error>`
 	assertEquals(t, exp, str)
 }
@@ -99,7 +99,7 @@
 		"en", Version: "1.0"}
 	str := testWrite(ss)
 	exp := `<stream:stream xmlns="jabber:client"` +
-		` xmlns:stream="` + nsStream + `" to="foo.org"` +
+		` xmlns:stream="` + NsStream + `" to="foo.org"` +
 		` from="bar.com" id="42" xml:lang="en" version="1.0">`
 	assertEquals(t, exp, str)
 }