equal
deleted
inserted
replaced
96 |
96 |
97 // message stanza |
97 // message stanza |
98 type Message struct { |
98 type Message struct { |
99 XMLName xml.Name `xml:"jabber:client message"` |
99 XMLName xml.Name `xml:"jabber:client message"` |
100 Header |
100 Header |
101 Subject *Generic `xml:"jabber:client subject"` |
101 Subject []Text `xml:"jabber:client subject"` |
102 Body *Generic `xml:"jabber:client body"` |
102 Body []Text `xml:"jabber:client body"` |
103 Thread *Generic `xml:"jabber:client thread"` |
103 Thread *Data `xml:"jabber:client thread"` |
104 } |
104 } |
105 |
105 |
106 var _ Stanza = &Message{} |
106 var _ Stanza = &Message{} |
107 |
107 |
108 // presence stanza |
108 // presence stanza |
109 type Presence struct { |
109 type Presence struct { |
110 XMLName xml.Name `xml:"presence"` |
110 XMLName xml.Name `xml:"presence"` |
111 Header |
111 Header |
112 Show *Generic `xml:"jabber:client show"` |
112 Show *Data `xml:"jabber:client show"` |
113 Status *Generic `xml:"jabber:client status"` |
113 Status []Text `xml:"jabber:client status"` |
114 Priority *Generic `xml:"jabber:client priority"` |
114 Priority *Data `xml:"jabber:client priority"` |
115 } |
115 } |
116 |
116 |
117 var _ Stanza = &Presence{} |
117 var _ Stanza = &Presence{} |
118 |
118 |
119 // iq stanza |
119 // iq stanza |
140 XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-bind bind"` |
140 XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-bind bind"` |
141 Resource *string `xml:"resource"` |
141 Resource *string `xml:"resource"` |
142 Jid *string `xml:"jid"` |
142 Jid *string `xml:"jid"` |
143 } |
143 } |
144 |
144 |
|
145 // Holds human-readable text, with an optional language |
|
146 // specification. Generally multiple instances of these can be found |
|
147 // together, allowing the software to choose which language to present |
|
148 // to the user. |
|
149 type Text struct { |
|
150 XMLName xml.Name |
|
151 Lang string `xml:"http://www.w3.org/XML/1998/namespace lang,attr,omitempty"` |
|
152 Chardata string `xml:",chardata"` |
|
153 } |
|
154 |
|
155 // Non-human-readable content of some sort, used by the protocol. |
|
156 type Data struct { |
|
157 XMLName xml.Name |
|
158 Chardata string `xml:",chardata"` |
|
159 } |
|
160 |
145 // Holds an XML element not described by the more specific types. |
161 // Holds an XML element not described by the more specific types. |
146 type Generic struct { |
162 type Generic struct { |
147 XMLName xml.Name |
163 XMLName xml.Name |
148 Any *Generic `xml:",any"` |
164 Any *Generic `xml:",any"` |
149 Chardata string `xml:",chardata"` |
165 Chardata string `xml:",chardata"` |
160 result = result + "/" + jid.Resource |
176 result = result + "/" + jid.Resource |
161 } |
177 } |
162 return result |
178 return result |
163 } |
179 } |
164 |
180 |
165 // Set implements flag.Value. It returns true if it successfully |
181 // Set implements flag.Value. |
166 // parses the string. |
|
167 func (jid *JID) Set(val string) error { |
182 func (jid *JID) Set(val string) error { |
168 r := regexp.MustCompile("^(([^@/]+)@)?([^@/]+)(/([^@/]+))?$") |
183 r := regexp.MustCompile("^(([^@/]+)@)?([^@/]+)(/([^@/]+))?$") |
169 parts := r.FindStringSubmatch(val) |
184 parts := r.FindStringSubmatch(val) |
170 if parts == nil { |
185 if parts == nil { |
171 return fmt.Errorf("%s doesn't match user@domain/resource", val) |
186 return fmt.Errorf("%s doesn't match user@domain/resource", val) |