aboutsummaryrefslogtreecommitdiff
path: root/connector
diff options
context:
space:
mode:
Diffstat (limited to 'connector')
-rw-r--r--connector/xmpp/iq.go51
-rw-r--r--connector/xmpp/xmpp.go63
2 files changed, 110 insertions, 4 deletions
diff --git a/connector/xmpp/iq.go b/connector/xmpp/iq.go
new file mode 100644
index 0000000..1405614
--- /dev/null
+++ b/connector/xmpp/iq.go
@@ -0,0 +1,51 @@
+package xmpp
+
+import (
+ "encoding/xml"
+)
+
+type DiscoQuery struct {
+ XMLName xml.Name `xml:"http://jabber.org/protocol/disco#items query"`
+ Items []Node `xml:"item"`
+}
+
+type Node struct {
+ XMLName xml.Name `xml:"item"`
+ Jid string `xml:"jid,attr"`
+ Node string `xml:"node,attr"`
+}
+
+type PubSub struct {
+ XMLName xml.Name `xml:"http://jabber.org/protocol/pubsub pubsub"`
+ Subscribe []Subscribe `xml:"subscribe"`
+ Subscription []Subscription `xml:"subscription"`
+ Subscriptions []Subscription `xml:"subscriptions"`
+ Publish *Publish `xml:"publish"`
+}
+
+type Subscribe struct {
+ XMLName xml.Name `xml:"subscribe"`
+ Jid string `xml:"jid,attr"`
+ Node string `xml:"node,attr"`
+}
+
+type Subscription struct {
+ XMLName xml.Name `xml:"subscription"`
+ Jid string `xml:"jid,attr"`
+ Node string `xml:"node,attr"`
+ SubID string `xml:"subid,attr"`
+ Subscription string `xml:"subscription,attr"`
+}
+
+type Publish struct {
+ XMLName xml.Name `xml:"publish"`
+ Node string `xml:"node,attr"`
+ Item []Item `xml:"item"`
+ Items []Item `xml:"items"`
+}
+
+type Item struct {
+ XMLName xml.Name `xml:"publish"`
+ Id string `xml:"id,attr"`
+ Data string `xml:",innerxml"`
+}
diff --git a/connector/xmpp/xmpp.go b/connector/xmpp/xmpp.go
index e50bb58..a62cdc4 100644
--- a/connector/xmpp/xmpp.go
+++ b/connector/xmpp/xmpp.go
@@ -6,9 +6,11 @@ import (
"strings"
"fmt"
"crypto/tls"
+ "encoding/xml"
log "github.com/sirupsen/logrus"
- gxmpp "github.com/mattn/go-xmpp"
+ //gxmpp "github.com/mattn/go-xmpp"
+ gxmpp "git.deuxfleurs.fr/lx/go-xmpp"
. "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector"
)
@@ -177,10 +179,10 @@ func (xm *XMPP) handleXMPP() error {
return err
}
- fmt.Printf("XMPP: %#v\n", m)
switch v := m.(type) {
case gxmpp.Chat:
+ fmt.Printf("XMPP chat: %#v\n", v)
remote_sp := strings.Split(v.Remote, "/")
// Skip self-sent events
@@ -228,6 +230,8 @@ func (xm *XMPP) handleXMPP() error {
}
}
case gxmpp.Presence:
+ fmt.Printf("XMPP presence: %#v\n", v)
+
remote := strings.Split(v.From, "/")
if ismuc, ok := xm.isMUC[remote[0]]; ok && ismuc {
// skip presence with no user and self-presence
@@ -248,8 +252,59 @@ func (xm *XMPP) handleXMPP() error {
xm.handler.UserInfoUpdated(user, &UserInfo{
DisplayName: remote[1],
})
+ } else {
+ // Send discovery query
+ iq, err := xml.Marshal(&DiscoQuery{})
+ if err != nil {
+ fmt.Printf("XML marshall error: %s\n", err)
+ } else {
+ xm.conn.SendIQ(gxmpp.IQ{
+ Type: "get",
+ To: remote[0],
+ ID: "items1",
+ Query: iq,
+ })
+ }
+ }
+ case gxmpp.IQ:
+ fmt.Printf("XMPP iq: from=%s to=%s id=%s type=%s\n", v.From, v.To, v.ID, v.Type)
+ if len(v.Query) > 0 {
+ fmt.Printf("Query data: %s\n", string(v.Query))
+ }
+
+ if v.Type == "result" && v.ID == "items1" {
+ var q DiscoQuery
+ err := xml.Unmarshal(v.Query, &q)
+ if err != nil {
+ fmt.Printf("XML unmarshall error: %s\n", err)
+ continue
+ }
+
+ for _, item := range q.Items {
+ if item.Node == "urn:xmpp:avatar:metadata" || item.Node == "urn:xmpp:avatar:data" {
+ sub := &PubSub{
+ Subscribe: []Subscribe{
+ Subscribe{
+ Jid: xm.jid,
+ Node: item.Node,
+ },
+ },
+ }
+ iq, err := xml.Marshal(sub)
+ if err != nil {
+ fmt.Printf("XML marshall error: %s\n", err)
+ } else {
+ fmt.Printf("IQ AVATAR SUB: %s\n", iq)
+ xm.conn.SendIQ(gxmpp.IQ{
+ To: v.From,
+ Type: "set",
+ ID: "sub1",
+ Query: iq,
+ })
+ }
+ }
+ }
}
- // Do nothing.
}
}
}
@@ -297,7 +352,7 @@ func (xm *XMPP) Invite(userId UserID, roomId RoomID) error {
}
func (xm *XMPP) Leave(roomId RoomID) {
- // TODO
+ xm.conn.LeaveMUC(string(roomId))
}
func (xm *XMPP) Send(event *Event) error {