Renamed the somewhat obscure XTo(), etc. to GetTo(), etc.
--- a/roster.go Sun Jan 01 17:19:03 2012 -0700
+++ b/roster.go Sun Jan 01 17:22:48 2012 -0700
@@ -43,7 +43,7 @@
ch <- iq.Error
return false
}
- rq, ok := st.XNested().(*RosterQuery)
+ rq, ok := st.GetNested().(*RosterQuery)
if !ok {
ch <- os.NewError(fmt.Sprintf(
"Roster query result not query: %v", st))
--- a/roster_test.go Sun Jan 01 17:19:03 2012 -0700
+++ b/roster_test.go Sun Jan 01 17:22:48 2012 -0700
@@ -30,10 +30,10 @@
if err != nil {
t.Fatalf("parseExtended: %v", err)
}
- assertEquals(t, "iq", st.XName())
- assertEquals(t, "from", st.XFrom())
- assertEquals(t, "en", st.XLang())
- nested := st.XNested()
+ assertEquals(t, "iq", st.GetName())
+ assertEquals(t, "from", st.GetFrom())
+ assertEquals(t, "en", st.GetLang())
+ nested := st.GetNested()
if nested == nil {
t.Fatalf("nested nil")
}
--- a/stream.go Sun Jan 01 17:19:03 2012 -0700
+++ b/stream.go Sun Jan 01 17:22:48 2012 -0700
@@ -255,9 +255,9 @@
x)
continue
}
- if handlers[st.XId()] != nil {
- f := handlers[st.XId()]
- handlers[st.XId()] = nil
+ if handlers[st.GetId()] != nil {
+ f := handlers[st.GetId()]
+ handlers[st.GetId()] = nil
send = f(st)
}
if send {
@@ -562,11 +562,11 @@
}
msg := &Iq{Type: "set", Id: <- cl.Id, Nested: &bindReq}
f := func(st Stanza) bool {
- if st.XType() == "error" {
+ if st.GetType() == "error" {
log.Println("Resource binding failed")
return false
}
- bindRepl, ok := st.XNested().(*bindIq)
+ bindRepl, ok := st.GetNested().(*bindIq)
if !ok {
log.Printf("bad bind reply: %v", bindRepl)
return false
--- a/structs.go Sun Jan 01 17:19:03 2012 -0700
+++ b/structs.go Sun Jan 01 17:22:48 2012 -0700
@@ -76,27 +76,25 @@
Any *Generic
}
-// BUG(cjyar) Change XTo() to GetTo(), etc.
-
// One of the three core XMPP stanza types: iq, message, presence. See
// RFC3920, section 9.
type Stanza interface {
// Returns "iq", "message", or "presence".
- XName() string
+ GetName() string
// The to attribute.
- XTo() string
+ GetTo() string
// The from attribute.
- XFrom() string
+ GetFrom() string
// The id attribute.
- XId() string
+ GetId() string
// The type attribute.
- XType() string
+ GetType() string
// The xml:lang attribute.
- XLang() string
+ GetLang() string
// A nested error element, if any.
- XError() *Error
+ GetError() *Error
// A (non-error) nested element, if any.
- XNested() interface{}
+ GetNested() interface{}
setNested(interface{})
generic() *Generic
innerxml() string
@@ -288,26 +286,26 @@
func marshalXML(st Stanza) ([]byte, os.Error) {
buf := bytes.NewBuffer(nil)
buf.WriteString("<")
- buf.WriteString(st.XName())
- if st.XTo() != "" {
- writeField(buf, "to", st.XTo())
+ buf.WriteString(st.GetName())
+ if st.GetTo() != "" {
+ writeField(buf, "to", st.GetTo())
}
- if st.XFrom() != "" {
- writeField(buf, "from", st.XFrom())
+ if st.GetFrom() != "" {
+ writeField(buf, "from", st.GetFrom())
}
- if st.XId() != "" {
- writeField(buf, "id", st.XId())
+ if st.GetId() != "" {
+ writeField(buf, "id", st.GetId())
}
- if st.XType() != "" {
- writeField(buf, "type", st.XType())
+ if st.GetType() != "" {
+ writeField(buf, "type", st.GetType())
}
- if st.XLang() != "" {
- writeField(buf, "xml:lang", st.XLang())
+ if st.GetLang() != "" {
+ writeField(buf, "xml:lang", st.GetLang())
}
buf.WriteString(">")
- if st.XNested() != nil {
- xml.Marshal(buf, st.XNested())
+ if st.GetNested() != nil {
+ xml.Marshal(buf, st.GetNested())
} else if st.generic() != nil {
xml.Marshal(buf, st.generic())
} else if st.innerxml() != "" {
@@ -315,7 +313,7 @@
}
buf.WriteString("</")
- buf.WriteString(st.XName())
+ buf.WriteString(st.GetName())
buf.WriteString(">")
return buf.Bytes(), nil
}
@@ -339,35 +337,35 @@
return string(bytes)
}
-func (m *Message) XName() string {
+func (m *Message) GetName() string {
return "message"
}
-func (m *Message) XTo() string {
+func (m *Message) GetTo() string {
return m.To
}
-func (m *Message) XFrom() string {
+func (m *Message) GetFrom() string {
return m.From
}
-func (m *Message) XId() string {
+func (m *Message) GetId() string {
return m.Id
}
-func (m *Message) XType() string {
+func (m *Message) GetType() string {
return m.Type
}
-func (m *Message) XLang() string {
+func (m *Message) GetLang() string {
return m.Lang
}
-func (m *Message) XError() *Error {
+func (m *Message) GetError() *Error {
return m.Error
}
-func (m *Message) XNested() interface{} {
+func (m *Message) GetNested() interface{} {
return m.Nested
}
@@ -403,35 +401,35 @@
return nil
}
-func (p *Presence) XName() string {
+func (p *Presence) GetName() string {
return "presence"
}
-func (p *Presence) XTo() string {
+func (p *Presence) GetTo() string {
return p.To
}
-func (p *Presence) XFrom() string {
+func (p *Presence) GetFrom() string {
return p.From
}
-func (p *Presence) XId() string {
+func (p *Presence) GetId() string {
return p.Id
}
-func (p *Presence) XType() string {
+func (p *Presence) GetType() string {
return p.Type
}
-func (p *Presence) XLang() string {
+func (p *Presence) GetLang() string {
return p.Lang
}
-func (p *Presence) XError() *Error {
+func (p *Presence) GetError() *Error {
return p.Error
}
-func (p *Presence) XNested() interface{} {
+func (p *Presence) GetNested() interface{} {
return p.Nested
}
@@ -467,35 +465,35 @@
return nil
}
-func (iq *Iq) XName() string {
+func (iq *Iq) GetName() string {
return "iq"
}
-func (iq *Iq) XTo() string {
+func (iq *Iq) GetTo() string {
return iq.To
}
-func (iq *Iq) XFrom() string {
+func (iq *Iq) GetFrom() string {
return iq.From
}
-func (iq *Iq) XId() string {
+func (iq *Iq) GetId() string {
return iq.Id
}
-func (iq *Iq) XType() string {
+func (iq *Iq) GetType() string {
return iq.Type
}
-func (iq *Iq) XLang() string {
+func (iq *Iq) GetLang() string {
return iq.Lang
}
-func (iq *Iq) XError() *Error {
+func (iq *Iq) GetError() *Error {
return iq.Error
}
-func (iq *Iq) XNested() interface{} {
+func (iq *Iq) GetNested() interface{} {
return iq.Nested
}
--- a/structs_test.go Sun Jan 01 17:19:03 2012 -0700
+++ b/structs_test.go Sun Jan 01 17:22:48 2012 -0700
@@ -97,14 +97,14 @@
if err != nil {
t.Fatalf("iq: %v", err)
}
- assertEquals(t, "iq", st.XName())
- assertEquals(t, "alice", st.XTo())
- assertEquals(t, "bob", st.XFrom())
- assertEquals(t, "1", st.XId())
- assertEquals(t, "A", st.XType())
- assertEquals(t, "en", st.XLang())
- if st.XError() != nil {
- t.Errorf("iq: error %v", st.XError())
+ assertEquals(t, "iq", st.GetName())
+ assertEquals(t, "alice", st.GetTo())
+ assertEquals(t, "bob", st.GetFrom())
+ assertEquals(t, "1", st.GetId())
+ assertEquals(t, "A", st.GetType())
+ assertEquals(t, "en", st.GetLang())
+ if st.GetError() != nil {
+ t.Errorf("iq: error %v", st.GetError())
}
if st.generic() == nil {
t.Errorf("iq: nil child")
@@ -117,13 +117,13 @@
if err != nil {
t.Fatalf("message: %v", err)
}
- assertEquals(t, "message", st.XName())
- assertEquals(t, "alice", st.XTo())
- assertEquals(t, "bob", st.XFrom())
- assertEquals(t, "", st.XId())
- assertEquals(t, "", st.XLang())
- if st.XError() != nil {
- t.Errorf("message: error %v", st.XError())
+ assertEquals(t, "message", st.GetName())
+ assertEquals(t, "alice", st.GetTo())
+ assertEquals(t, "bob", st.GetFrom())
+ assertEquals(t, "", st.GetId())
+ assertEquals(t, "", st.GetLang())
+ if st.GetError() != nil {
+ t.Errorf("message: error %v", st.GetError())
}
if st.generic() != nil {
t.Errorf("message: child %v", st.generic())
@@ -134,5 +134,5 @@
if err != nil {
t.Fatalf("presence: %v", err)
}
- assertEquals(t, "presence", st.XName())
+ assertEquals(t, "presence", st.GetName())
}
--- a/xmpp.go Sun Jan 01 17:19:03 2012 -0700
+++ b/xmpp.go Sun Jan 01 17:22:48 2012 -0700
@@ -269,9 +269,9 @@
"session"}}}
ch := make(chan os.Error)
f := func(st Stanza) bool {
- if st.XType() == "error" {
+ if st.GetType() == "error" {
log.Printf("Can't start session: %v", st)
- ch <- st.XError()
+ ch <- st.GetError()
return false
}
ch <- nil