Unverified Commit db4ec5ab authored by Ola Bini's avatar Ola Bini

Make the #info and #items lookups work better with respect to nodes

parent cd014ba7
......@@ -29,6 +29,7 @@ type DiscoveryFeature struct {
// DiscoveryItemsQuery contains a query for discovery items
type DiscoveryItemsQuery struct {
XMLName xml.Name `xml:"http://jabber.org/protocol/disco#items query"`
Node string `xml:"node,omitempty"`
DiscoveryItems []DiscoveryItem `xml:"item,omitempty"`
}
......
package main
import (
"encoding/xml"
"fmt"
xco "github.com/sheenobu/go-xco"
......@@ -34,33 +35,71 @@ func processIQ(stanza *xco.Iq) (ret interface{}, iqtype string, ignore bool) {
return nil, "", false
}
func discoInfoIQ(_ *xco.Iq) (interface{}, string, bool) {
return DiscoveryInfoQuery{
Identities: []DiscoveryIdentity{
{
Category: "auth",
Type: "otr-prekey",
Name: "OTR Prekey Server",
func discoInfoIQ(ii *xco.Iq) (interface{}, string, bool) {
q := &DiscoveryInfoQuery{}
e := xml.Unmarshal([]byte(ii.Content), q)
if e != nil {
return nil, "", true
}
if q.Node == "" {
return DiscoveryInfoQuery{
Identities: []DiscoveryIdentity{
{
Category: "auth",
Type: "otr-prekey",
Name: "OTR Prekey Server",
},
},
Features: []DiscoveryFeature{
{Var: "http://jabber.org/protocol/disco#info"},
{Var: "http://jabber.org/protocol/disco#items"},
{Var: "http://jabber.org/protocol/otrv4-prekey-server"},
},
}, "", false
} else if q.Node == "fingerprint" {
return DiscoveryInfoQuery{
Node: q.Node,
Identities: []DiscoveryIdentity{
{
Category: "auth",
Type: "otr-prekey",
Name: *prekeyServerFingerprint,
},
},
},
Features: []DiscoveryFeature{
{Var: "http://jabber.org/protocol/disco#info"},
{Var: "http://jabber.org/protocol/disco#items"},
{Var: "http://jabber.org/protocol/otrv4-prekey-server"},
},
}, "", false
Features: []DiscoveryFeature{
{Var: "http://jabber.org/protocol/disco#info"},
{Var: "http://jabber.org/protocol/disco#items"},
{Var: "http://jabber.org/protocol/otrv4-prekey-server"},
},
}, "", false
}
return DiscoveryItemsQuery{}, "", false
}
func discoItemsIQ(_ *xco.Iq) (interface{}, string, bool) {
return DiscoveryItemsQuery{
DiscoveryItems: []DiscoveryItem{
{
Jid: *xmppName,
Node: "fingerprint",
Name: *prekeyServerFingerprint,
func discoItemsIQ(ii *xco.Iq) (interface{}, string, bool) {
q := &DiscoveryItemsQuery{}
e := xml.Unmarshal([]byte(ii.Content), q)
if e != nil {
return nil, "", true
}
if q.Node == "" {
return DiscoveryItemsQuery{
DiscoveryItems: []DiscoveryItem{
{
Jid: *xmppName,
Node: "fingerprint",
Name: *prekeyServerFingerprint,
},
},
},
}, "", false
}, "", false
} else if q.Node == "fingerprint" {
return DiscoveryItemsQuery{
Node: q.Node,
DiscoveryItems: []DiscoveryItem{},
}, "", false
}
return DiscoveryItemsQuery{}, "", false
}
func init() {
......
......@@ -7,21 +7,23 @@ import (
)
func iqHandler(c *xco.Component, m *xco.Iq) error {
ret, _, _ := processIQ(m)
resp := xco.Iq{
Header: xco.Header{
From: m.To,
To: m.From,
ID: m.ID,
},
Type: "result",
Content: xmlToString(ret),
XMLName: m.XMLName,
}
ret, _, ignore := processIQ(m)
if !ignore {
resp := xco.Iq{
Header: xco.Header{
From: m.To,
To: m.From,
ID: m.ID,
},
Type: "result",
Content: xmlToString(ret),
XMLName: m.XMLName,
}
e := c.Send(&resp)
if e != nil {
fmt.Printf("encountered error when sending response: %v\n", e)
e := c.Send(&resp)
if e != nil {
fmt.Printf("encountered error when sending response: %v\n", e)
}
}
return nil
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment