-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdisco.go
More file actions
99 lines (81 loc) · 2.59 KB
/
disco.go
File metadata and controls
99 lines (81 loc) · 2.59 KB
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
package oasis_sdk
import (
"fmt"
"log"
"strconv"
"golang.org/x/net/context"
"mellium.im/xmpp/disco"
"mellium.im/xmpp/disco/items"
jid2 "mellium.im/xmpp/jid"
)
/*
The error result returned by the function controls how WalkItem continues.
If the function returns the special value ErrSkipItem, WalkItem skips the current item.
Otherwise, if the function returns a non-nil error, WalkItem stops entirely and returns that error.
*/
// DiscoServerItem handles a server item being discovered. Implements WalkItemFunc
func (client *XmppClient) DiscoServerItem(level int, item items.Item, err error) error {
//fmt.Printf(
// "discovered server item at level %d, name: %s, jid %s, node %v, err %v\n",
// level, item.Name, item.JID.String(), item.Node, err,
//)
info, err := disco.GetInfo(context.Background(), "", item.JID, client.Session)
if err != nil {
fmt.Printf("Error while getting info about %s, %v\n", item.JID.String(), err)
}
// learned this happens when an item is unavailable. oops!
if len(info.Identity) < 1 {
return disco.ErrSkipItem
}
identity := info.Identity[0]
//fmt.Printf("%s: Type %s, Category %s\n", item.JID.String(), identity.Type, identity.Category)
if identity.Type == "text" && identity.Category == "conference" {
return disco.ErrSkipItem
}
if identity.Type == "file" && identity.Category == "store" {
httpUploadComponent := HttpUploadComponent{
Jid: item.JID,
}
for _, x := range info.Form {
v, ok := x.GetString("max-file-size")
if ok {
//fmt.Printf("max-file-size: %s\n", v)
maxFileSize, err := strconv.ParseInt(v, 10, 64)
if err != nil {
fmt.Printf("Could not parse max-file-size: %v\n", err)
maxFileSize = 0
}
httpUploadComponent.MaxFileSize = int(maxFileSize)
break
//httpUploadComponent.MaxFileSize
}
}
client.HttpUploadComponent = &httpUploadComponent
fmt.Println(client.HttpUploadComponent)
}
return nil
}
func (client *XmppClient) DiscoServicesOnSelf() {
item := items.Item{
JID: *client.JID,
Name: "self",
}
err := disco.WalkItem(context.Background(), item, client.Session, client.DiscoServerItem)
if err != nil {
fmt.Printf("Error while walking self items: %v\n", err)
}
}
func (client *XmppClient) DiscoServicesOnServer() {
jid, err := jid2.Parse(*client.Server)
if err != nil {
log.Fatalf("server string \"%s\" not a valid JID, %v", *client.Server, err)
}
item := items.Item{
JID: jid,
Name: *client.Server,
}
err = disco.WalkItem(context.Background(), item, client.Session, client.DiscoServerItem)
if err != nil {
fmt.Printf("Error while walking server items: %v\n", err)
}
}