# HG changeset patch # User Chris Jones # Date 1383795576 25200 # Node ID 52c100897e9dade702661ee2118f68a89ab4c937 # Parent fc8702a8572ea2cbea9370c32ff6e2df018371e1# Parent 25b9d58daa136c07316a60f5ef1720eeac4aa260 Merge. diff -r fc8702a8572e -r 52c100897e9d README --- a/README Wed Nov 06 20:38:03 2013 -0700 +++ b/README Wed Nov 06 20:39:36 2013 -0700 @@ -4,4 +4,11 @@ The core of the protocol is handled by xmpp.go, structs.go, and stream.go. Everything else is an extension, though some of the -provided "extensions" are mandatory pieces of the protocol. +provided "extensions" are mandatory pieces of the protocol. Many of +the XEPs at http://xmpp.org/xmpp-protocols/xmpp-extensions/ can be +supported by this library, though at present only base protocol +support is here. + +An simple client using this library is in the example directory. A +more interesting example can be found at +https://cjones.org/hg/foosfiend. diff -r fc8702a8572e -r 52c100897e9d TODO.txt --- a/TODO.txt Wed Nov 06 20:38:03 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -Review all the *Client receiver methods in layer3.go. They should -probably either all be receivers, or none. - -Add a Reconnect() function. - -Eliminate as many uses of Generic as possible. diff -r fc8702a8572e -r 52c100897e9d xmpp/layer1.go --- a/xmpp/layer1.go Wed Nov 06 20:38:03 2013 -0700 +++ b/xmpp/layer1.go Wed Nov 06 20:39:36 2013 -0700 @@ -64,7 +64,7 @@ for { select { case stat := <-status: - if stat.fatal() { + if stat.Fatal() { return } diff -r fc8702a8572e -r 52c100897e9d xmpp/status.go --- a/xmpp/status.go Wed Nov 06 20:38:03 2013 -0700 +++ b/xmpp/status.go Wed Nov 06 20:39:36 2013 -0700 @@ -42,7 +42,9 @@ StatusError Status = statusError ) -func (s Status) fatal() bool { +// Does the status value indicate that the client is or has +// disconnected? +func (s Status) Fatal() bool { switch s { default: return false @@ -135,7 +137,7 @@ if current == waitFor { return nil } - if current.fatal() { + if current.Fatal() { break } if current > waitFor { diff -r fc8702a8572e -r 52c100897e9d xmpp/structs.go --- a/xmpp/structs.go Wed Nov 06 20:38:03 2013 -0700 +++ b/xmpp/structs.go Wed Nov 06 20:39:36 2013 -0700 @@ -98,9 +98,9 @@ type Message struct { XMLName xml.Name `xml:"jabber:client message"` Header - Subject *Generic `xml:"jabber:client subject"` - Body *Generic `xml:"jabber:client body"` - Thread *Generic `xml:"jabber:client thread"` + Subject []Text `xml:"jabber:client subject"` + Body []Text `xml:"jabber:client body"` + Thread *Data `xml:"jabber:client thread"` } var _ Stanza = &Message{} @@ -109,9 +109,9 @@ type Presence struct { XMLName xml.Name `xml:"presence"` Header - Show *Generic `xml:"jabber:client show"` - Status *Generic `xml:"jabber:client status"` - Priority *Generic `xml:"jabber:client priority"` + Show *Data `xml:"jabber:client show"` + Status []Text `xml:"jabber:client status"` + Priority *Data `xml:"jabber:client priority"` } var _ Stanza = &Presence{} @@ -142,6 +142,22 @@ Jid *string `xml:"jid"` } +// Holds human-readable text, with an optional language +// specification. Generally multiple instances of these can be found +// together, allowing the software to choose which language to present +// to the user. +type Text struct { + XMLName xml.Name + Lang string `xml:"http://www.w3.org/XML/1998/namespace lang,attr,omitempty"` + Chardata string `xml:",chardata"` +} + +// Non-human-readable content of some sort, used by the protocol. +type Data struct { + XMLName xml.Name + Chardata string `xml:",chardata"` +} + // Holds an XML element not described by the more specific types. type Generic struct { XMLName xml.Name @@ -162,8 +178,7 @@ return result } -// Set implements flag.Value. It returns true if it successfully -// parses the string. +// Set implements flag.Value. func (jid *JID) Set(val string) error { r := regexp.MustCompile("^(([^@/]+)@)?([^@/]+)(/([^@/]+))?$") parts := r.FindStringSubmatch(val) diff -r fc8702a8572e -r 52c100897e9d xmpp/structs_test.go --- a/xmpp/structs_test.go Wed Nov 06 20:38:03 2013 -0700 +++ b/xmpp/structs_test.go Wed Nov 06 20:39:36 2013 -0700 @@ -108,8 +108,8 @@ } func TestMarshalEscaping(t *testing.T) { - msg := &Message{Body: &Generic{XMLName: xml.Name{Local: "body"}, - Chardata: `&