| 1 |
package xmpp |
| 2 |
|
| 3 |
import ( |
| 4 |
"encoding/xml" |
| 5 |
) |
| 6 |
|
| 7 |
type clientDiscoFeature struct { |
| 8 |
XMLName xml.Name `xml:"feature"` |
| 9 |
Var string `xml:"var,attr"` |
| 10 |
} |
| 11 |
|
| 12 |
type clientDiscoIdentity struct { |
| 13 |
XMLName xml.Name `xml:"identity"` |
| 14 |
Category string `xml:"category,attr"` |
| 15 |
Type string `xml:"type,attr"` |
| 16 |
Name string `xml:"name,attr"` |
| 17 |
} |
| 18 |
|
| 19 |
type clientDiscoQuery struct { |
| 20 |
XMLName xml.Name `xml:"query"` |
| 21 |
Features []clientDiscoFeature `xml:"feature"` |
| 22 |
Identities []clientDiscoIdentity `xml:"identity"` |
| 23 |
X []DiscoX `xml:"x"` |
| 24 |
} |
| 25 |
|
| 26 |
type clientDiscoItem struct { |
| 27 |
XMLName xml.Name `xml:"item"` |
| 28 |
Jid string `xml:"jid,attr"` |
| 29 |
Node string `xml:"node,attr"` |
| 30 |
Name string `xml:"name,attr"` |
| 31 |
} |
| 32 |
|
| 33 |
type clientDiscoItemsQuery struct { |
| 34 |
XMLName xml.Name `xml:"query"` |
| 35 |
Items []clientDiscoItem `xml:"item"` |
| 36 |
} |
| 37 |
|
| 38 |
type DiscoIdentity struct { |
| 39 |
Category string |
| 40 |
Type string |
| 41 |
Name string |
| 42 |
} |
| 43 |
|
| 44 |
type DiscoItem struct { |
| 45 |
Jid string |
| 46 |
Name string |
| 47 |
Node string |
| 48 |
} |
| 49 |
|
| 50 |
type DiscoResult struct { |
| 51 |
ID string |
| 52 |
From string |
| 53 |
To string |
| 54 |
Features []string |
| 55 |
Identities []DiscoIdentity |
| 56 |
X []DiscoX |
| 57 |
} |
| 58 |
|
| 59 |
type DiscoX struct { |
| 60 |
XMLName xml.Name `xml:"x"` |
| 61 |
Field []DiscoXField `xml:"field"` |
| 62 |
} |
| 63 |
|
| 64 |
type DiscoXField struct { |
| 65 |
Type string `xml:"type,attr"` |
| 66 |
Var string `xml:"var,attr"` |
| 67 |
Value []string `xml:"value"` |
| 68 |
} |
| 69 |
|
| 70 |
type DiscoItems struct { |
| 71 |
ID string |
| 72 |
Jid string |
| 73 |
Items []DiscoItem |
| 74 |
} |
| 75 |
|
| 76 |
func clientFeaturesToReturn(features []clientDiscoFeature) []string { |
| 77 |
var ret []string |
| 78 |
|
| 79 |
for _, feature := range features { |
| 80 |
ret = append(ret, feature.Var) |
| 81 |
} |
| 82 |
|
| 83 |
return ret |
| 84 |
} |
| 85 |
|
| 86 |
func clientIdentitiesToReturn(identities []clientDiscoIdentity) []DiscoIdentity { |
| 87 |
var ret []DiscoIdentity |
| 88 |
|
| 89 |
for _, id := range identities { |
| 90 |
ret = append(ret, DiscoIdentity{ |
| 91 |
Category: id.Category, |
| 92 |
Type: id.Type, |
| 93 |
Name: id.Name, |
| 94 |
}) |
| 95 |
} |
| 96 |
|
| 97 |
return ret |
| 98 |
} |
| 99 |
|
| 100 |
func clientDiscoItemsToReturn(items []clientDiscoItem) []DiscoItem { |
| 101 |
var ret []DiscoItem |
| 102 |
for _, item := range items { |
| 103 |
ret = append(ret, DiscoItem{ |
| 104 |
Jid: item.Jid, |
| 105 |
Name: item.Name, |
| 106 |
Node: item.Node, |
| 107 |
}) |
| 108 |
} |
| 109 |
|
| 110 |
return ret |
| 111 |
} |