# HG changeset patch # User Chris Jones # Date 1325291234 25200 # Node ID 7b1f924c75e2c25d5b23fa6c8d9daa5248bb4838 # Parent 571713f494940d47e48296daf56fd206a3d3eba3 Made the namespace constants public. diff -r 571713f49494 -r 7b1f924c75e2 stream.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: diff -r 571713f49494 -r 7b1f924c75e2 structs.go --- 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("") xml.Escape(buf, []byte(e.Text)) diff -r 571713f49494 -r 7b1f924c75e2 structs_test.go --- 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 := `` + ` xmlns:stream="` + NsStream + `" to="bob">` assertMarshal(t, exp, s) s = &stream{To: "bob", From: "alice", Id: "#3", Version: "5.3"} exp = `` assertMarshal(t, exp, s) s = &stream{Lang: "en_US"} exp = `` + ` 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 := ``; assertMarshal(t, exp, e) txt := errText{Lang: "pt", Text: "things happen"} e = &streamError{Any: Generic{XMLName: name}, Text: &txt} - exp = `things happen` 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 := `` assertMarshal(t, exp, iq) } diff -r 571713f49494 -r 7b1f924c75e2 xmpp.go --- 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 { diff -r 571713f49494 -r 7b1f924c75e2 xmpp_test.go --- 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(`` + - `Error text`) ch = make(chan interface{}) go readXml(r, ch) @@ -47,7 +47,7 @@ func TestReadStream(t *testing.T) { r := strings.NewReader(``) 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 = `Пошёл ты` assertEquals(t, exp, str) } @@ -99,7 +99,7 @@ "en", Version: "1.0"} str := testWrite(ss) exp := `` assertEquals(t, exp, str) }