1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
|
package extensions
import (
"encoding/xml"
"strconv"
"gosrc.io/xmpp/stanza"
)
// PresenceNickExtension is from XEP-0172
type PresenceNickExtension struct {
XMLName xml.Name `xml:"http://jabber.org/protocol/nick nick"`
Text string `xml:",chardata"`
}
// PresenceXVCardUpdateExtension is from XEP-0153
type PresenceXVCardUpdateExtension struct {
XMLName xml.Name `xml:"vcard-temp:x:update x"`
Photo PresenceXVCardUpdatePhoto
}
// PresenceXVCardUpdatePhoto is from XEP-0153
type PresenceXVCardUpdatePhoto struct {
XMLName xml.Name `xml:"photo"`
Text string `xml:",chardata"`
}
// IqVcardTemp is from XEP-0054
type IqVcardTemp struct {
XMLName xml.Name `xml:"vcard-temp vCard"`
Fn IqVcardFn
Nickname IqVcardNickname
N IqVcardN
Tel IqVcardTel
Photo IqVcardPhoto
Desc IqVcardDesc
ResultSet *stanza.ResultSet `xml:"set,omitempty"`
}
// IqVcardFn is vCard/FN
type IqVcardFn struct {
XMLName xml.Name `xml:"FN"`
Text string `xml:",chardata"`
}
// IqVcardNickname is vCard/NICKNAME
type IqVcardNickname struct {
XMLName xml.Name `xml:"NICKNAME"`
Text string `xml:",chardata"`
}
// IqVcardN is vCard/N
type IqVcardN struct {
XMLName xml.Name `xml:"N"`
Family IqVcardNFamily
Given IqVcardNGiven
Middle IqVcardNMiddle
}
// IqVcardNFamily is vCard/N/FAMILY
type IqVcardNFamily struct {
XMLName xml.Name `xml:"FAMILY"`
Text string `xml:",chardata"`
}
// IqVcardNGiven is vCard/N/GIVEN
type IqVcardNGiven struct {
XMLName xml.Name `xml:"GIVEN"`
Text string `xml:",chardata"`
}
// IqVcardNMiddle is vCard/N/MIDDLE
type IqVcardNMiddle struct {
XMLName xml.Name `xml:"MIDDLE"`
Text string `xml:",chardata"`
}
// IqVcardTel is vCard/TEL
type IqVcardTel struct {
XMLName xml.Name `xml:"TEL"`
Number IqVcardTelNumber
}
// IqVcardTelNumber is vCard/TEL/NUMBER
type IqVcardTelNumber struct {
XMLName xml.Name `xml:"NUMBER"`
Text string `xml:",chardata"`
}
// IqVcardPhoto is vCard/PHOTO
type IqVcardPhoto struct {
XMLName xml.Name `xml:"PHOTO"`
Type IqVcardPhotoType
Binval IqVcardPhotoBinval
}
// IqVcardPhotoType is vCard/PHOTO/TYPE
type IqVcardPhotoType struct {
XMLName xml.Name `xml:"TYPE"`
Text string `xml:",chardata"`
}
// IqVcardPhotoBinval is vCard/PHOTO/BINVAL
type IqVcardPhotoBinval struct {
XMLName xml.Name `xml:"BINVAL"`
Text string `xml:",chardata"`
}
// IqVcardDesc is vCard/DESC
type IqVcardDesc struct {
XMLName xml.Name `xml:"DESC"`
Text string `xml:",chardata"`
}
// Reply is from XEP-0461
type Reply struct {
XMLName xml.Name `xml:"urn:xmpp:reply:0 reply"`
To string `xml:"to,attr"`
Id string `xml:"id,attr"`
}
// Fallback is from XEP-0428
type Fallback struct {
XMLName xml.Name `xml:"urn:xmpp:fallback:0 fallback"`
For string `xml:"for,attr"`
Body []FallbackBody `xml:"urn:xmpp:fallback:0 body"`
Subject []FallbackSubject `xml:"urn:xmpp:fallback:0 subject"`
}
// FallbackBody is from XEP-0428
type FallbackBody struct {
XMLName xml.Name `xml:"urn:xmpp:fallback:0 body"`
Start string `xml:"start,attr"`
End string `xml:"end,attr"`
}
// FallbackSubject is from XEP-0428
type FallbackSubject struct {
XMLName xml.Name `xml:"urn:xmpp:fallback:0 subject"`
Start string `xml:"start,attr"`
End string `xml:"end,attr"`
}
// CarbonReceived is from XEP-0280
type CarbonReceived struct {
XMLName xml.Name `xml:"urn:xmpp:carbons:2 received"`
Forwarded stanza.Forwarded `xml:"urn:xmpp:forward:0 forwarded"`
}
// CarbonSent is from XEP-0280
type CarbonSent struct {
XMLName xml.Name `xml:"urn:xmpp:carbons:2 sent"`
Forwarded stanza.Forwarded `xml:"urn:xmpp:forward:0 forwarded"`
}
// ComponentPrivilege is from XEP-0356
type ComponentPrivilege1 struct {
XMLName xml.Name `xml:"urn:xmpp:privilege:1 privilege"`
Perms []ComponentPerm `xml:"perm"`
Forwarded stanza.Forwarded `xml:"urn:xmpp:forward:0 forwarded"`
}
// ComponentPrivilege is from XEP-0356
type ComponentPrivilege2 struct {
XMLName xml.Name `xml:"urn:xmpp:privilege:2 privilege"`
Perms []ComponentPerm `xml:"perm"`
Forwarded stanza.Forwarded `xml:"urn:xmpp:forward:0 forwarded"`
}
// ComponentPerm is from XEP-0356
type ComponentPerm struct {
XMLName xml.Name `xml:"perm"`
Access string `xml:"access,attr"`
Type string `xml:"type,attr"`
Push bool `xml:"push,attr"`
}
// ClientMessage is a jabber:client NS message compatible with Prosody's XEP-0356 implementation
type ClientMessage struct {
XMLName xml.Name `xml:"jabber:client message"`
stanza.Attrs
Subject string `xml:"subject,omitempty"`
Body string `xml:"body,omitempty"`
Thread string `xml:"thread,omitempty"`
Error stanza.Err `xml:"error,omitempty"`
Extensions []stanza.MsgExtension `xml:",omitempty"`
}
// Replace is from XEP-0308
type Replace struct {
XMLName xml.Name `xml:"urn:xmpp:message-correct:0 replace"`
Id string `xml:"id,attr"`
}
// QueryRegister is from XEP-0077
type QueryRegister struct {
XMLName xml.Name `xml:"jabber:iq:register query"`
Instructions string `xml:"instructions"`
Username string `xml:"username"`
Registered *QueryRegisterRegistered `xml:"registered"`
Remove *QueryRegisterRemove `xml:"remove"`
ResultSet *stanza.ResultSet `xml:"set,omitempty"`
}
// QueryRegisterRegistered is a child element from XEP-0077
type QueryRegisterRegistered struct {
XMLName xml.Name `xml:"registered"`
}
// QueryRegisterRemove is a child element from XEP-0077
type QueryRegisterRemove struct {
XMLName xml.Name `xml:"remove"`
}
// PresenceXMucUserExtension is from XEP-0045
type PresenceXMucUserExtension struct {
XMLName xml.Name `xml:"http://jabber.org/protocol/muc#user x"`
Item PresenceXMucUserItem
}
// PresenceXMucUserItem is from XEP-0045
type PresenceXMucUserItem struct {
XMLName xml.Name `xml:"item"`
Affiliation string `xml:"affiliation,attr"`
Role string `xml:"role,attr"`
}
// Namespace is a namespace!
func (c PresenceNickExtension) Namespace() string {
return c.XMLName.Space
}
// Namespace is a namespace!
func (c PresenceXVCardUpdateExtension) Namespace() string {
return c.XMLName.Space
}
// Namespace is a namespace!
func (c IqVcardTemp) Namespace() string {
return c.XMLName.Space
}
// GetSet getsets!
func (c IqVcardTemp) GetSet() *stanza.ResultSet {
return c.ResultSet
}
// Namespace is a namespace!
func (c Reply) Namespace() string {
return c.XMLName.Space
}
// Namespace is a namespace!
func (c Fallback) Namespace() string {
return c.XMLName.Space
}
// Namespace is a namespace!
func (c CarbonReceived) Namespace() string {
return c.XMLName.Space
}
// Namespace is a namespace!
func (c CarbonSent) Namespace() string {
return c.XMLName.Space
}
// Namespace is a namespace!
func (c ComponentPrivilege1) Namespace() string {
return c.XMLName.Space
}
// Namespace is a namespace!
func (c ComponentPrivilege2) Namespace() string {
return c.XMLName.Space
}
// Namespace is a namespace!
func (c Replace) Namespace() string {
return c.XMLName.Space
}
// Namespace is a namespace!
func (c QueryRegister) Namespace() string {
return c.XMLName.Space
}
// GetSet getsets!
func (c QueryRegister) GetSet() *stanza.ResultSet {
return c.ResultSet
}
// Namespace is a namespace!
func (c PresenceXMucUserExtension) Namespace() string {
return c.XMLName.Space
}
// Name is a packet name
func (ClientMessage) Name() string {
return "message"
}
// NewReplyFallback initializes a fallback range
func NewReplyFallback(start uint64, end uint64) Fallback {
return Fallback{
For: "urn:xmpp:reply:0",
Body: []FallbackBody{
FallbackBody{
Start: strconv.FormatUint(start, 10),
End: strconv.FormatUint(end, 10),
},
},
}
}
func init() {
// presence nick
stanza.TypeRegistry.MapExtension(stanza.PKTPresence, xml.Name{
"http://jabber.org/protocol/nick",
"nick",
}, PresenceNickExtension{})
// presence vcard update
stanza.TypeRegistry.MapExtension(stanza.PKTPresence, xml.Name{
"vcard-temp:x:update",
"x",
}, PresenceXVCardUpdateExtension{})
// iq vcard request
stanza.TypeRegistry.MapExtension(stanza.PKTIQ, xml.Name{
"vcard-temp",
"vCard",
}, IqVcardTemp{})
// reply
stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
"urn:xmpp:reply:0",
"reply",
}, Reply{})
// fallback
stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
"urn:xmpp:fallback:0",
"fallback",
}, Fallback{})
// carbon received
stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
"urn:xmpp:carbons:2",
"received",
}, CarbonReceived{})
// carbon sent
stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
"urn:xmpp:carbons:2",
"sent",
}, CarbonSent{})
// component privilege v1
stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
"urn:xmpp:privilege:1",
"privilege",
}, ComponentPrivilege1{})
// component privilege v2
stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
"urn:xmpp:privilege:2",
"privilege",
}, ComponentPrivilege2{})
// message edit
stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
"urn:xmpp:message-correct:0",
"replace",
}, Replace{})
// register query
stanza.TypeRegistry.MapExtension(stanza.PKTIQ, xml.Name{
"jabber:iq:register",
"query",
}, QueryRegister{})
// presence muc user
stanza.TypeRegistry.MapExtension(stanza.PKTPresence, xml.Name{
"http://jabber.org/protocol/muc#user",
"x",
}, PresenceXMucUserExtension{})
}
|