mirror of
https://github.com/FluuxIO/go-xmpp
synced 2024-11-05 12:00:50 +00:00
Add support for generating delegation forwarded iq response
This commit is contained in:
parent
c6f0d03f60
commit
61cdac89e0
37
component.go
37
component.go
@ -224,9 +224,9 @@ func (handshakeDecoder) decode(p *xml.Decoder, se xml.StartElement) (Handshake,
|
||||
// depending on the context.
|
||||
type Delegation struct {
|
||||
MsgExtension
|
||||
XMLName xml.Name `xml:"urn:xmpp:delegation:1 delegation"`
|
||||
Forwarded Forwarded // This is used in iq to wrap delegated iqs
|
||||
Delegated Delegated // This is used in a message to confirm delegated namespace
|
||||
XMLName xml.Name `xml:"urn:xmpp:delegation:1 delegation"`
|
||||
Forwarded *Forwarded // This is used in iq to wrap delegated iqs
|
||||
Delegated *Delegated // This is used in a message to confirm delegated namespace
|
||||
}
|
||||
|
||||
func (d *Delegation) Namespace() string {
|
||||
@ -234,10 +234,33 @@ func (d *Delegation) Namespace() string {
|
||||
}
|
||||
|
||||
type Forwarded struct {
|
||||
XMLName xml.Name `xml:"urn:xmpp:forward:0 forwarded"`
|
||||
IQ IQ
|
||||
Message Message
|
||||
Presence Presence
|
||||
XMLName xml.Name `xml:"urn:xmpp:forward:0 forwarded"`
|
||||
Stanza Packet
|
||||
}
|
||||
|
||||
// UnmarshalXML is a custom unmarshal function used by xml.Unmarshal to
|
||||
// transform generic XML content into hierarchical Node structure.
|
||||
func (f *Forwarded) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
// Check subelements to extract required field as boolean
|
||||
for {
|
||||
t, err := d.Token()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch tt := t.(type) {
|
||||
|
||||
case xml.StartElement:
|
||||
if packet, err := decodeClient(d, tt); err == nil {
|
||||
f.Stanza = packet
|
||||
}
|
||||
|
||||
case xml.EndElement:
|
||||
if tt == start.End() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type Delegated struct {
|
||||
|
@ -80,10 +80,16 @@ func TestParsingDelegationIQ(t *testing.T) {
|
||||
var node string
|
||||
for _, ext := range iq.Payload {
|
||||
if delegation, ok := ext.(*Delegation); ok {
|
||||
payload := delegation.Forwarded.IQ.Payload
|
||||
packet := delegation.Forwarded.Stanza
|
||||
forwardedIQ, ok := packet.(IQ)
|
||||
if !ok {
|
||||
t.Errorf("Could not extract packet IQ")
|
||||
return
|
||||
}
|
||||
payload := forwardedIQ.Payload
|
||||
if len(payload) > 0 {
|
||||
payload := delegation.Forwarded.IQ.Payload[0]
|
||||
if pubsub, ok := payload.(*PubSub); ok {
|
||||
pl := payload[0]
|
||||
if pubsub, ok := pl.(*PubSub); ok {
|
||||
node = pubsub.Publish.Node
|
||||
}
|
||||
}
|
||||
|
8
pep.go
8
pep.go
@ -17,9 +17,13 @@ type Tune struct {
|
||||
Uri string `xml:"uri,omitempty"`
|
||||
}
|
||||
|
||||
// Mood defines deta model for XEP-0107 - User Mood
|
||||
// See: https://xmpp.org/extensions/xep-0107.html
|
||||
type Mood struct {
|
||||
XMLName xml.Name `xml:"http://jabber.org/protocol/mood mood"`
|
||||
// TODO: Custom parsing to extract mood type from tag name
|
||||
MsgExtension // Mood can be added as a message extension
|
||||
XMLName xml.Name `xml:"http://jabber.org/protocol/mood mood"`
|
||||
// TODO: Custom parsing to extract mood type from tag name.
|
||||
// Note: the list is predefined.
|
||||
// Mood type
|
||||
Text string `xml:"text,omitempty"`
|
||||
}
|
||||
|
@ -6,8 +6,8 @@ import (
|
||||
|
||||
type PubSub struct {
|
||||
XMLName xml.Name `xml:"http://jabber.org/protocol/pubsub pubsub"`
|
||||
Publish Publish
|
||||
Retract Retract
|
||||
Publish *Publish
|
||||
Retract *Retract
|
||||
// TODO <configure/>
|
||||
}
|
||||
|
||||
@ -24,7 +24,8 @@ type Publish struct {
|
||||
type Item struct {
|
||||
XMLName xml.Name `xml:"item"`
|
||||
Id string `xml:"id,attr,omitempty"`
|
||||
Tune Tune
|
||||
Tune *Tune
|
||||
Mood *Mood
|
||||
}
|
||||
|
||||
type Retract struct {
|
||||
|
Loading…
Reference in New Issue
Block a user