forked from jshiffer/go-xmpp
Add support for generating delegation forwarded iq response
This commit is contained in:
parent
c6f0d03f60
commit
61cdac89e0
33
component.go
33
component.go
@ -225,8 +225,8 @@ func (handshakeDecoder) decode(p *xml.Decoder, se xml.StartElement) (Handshake,
|
|||||||
type Delegation struct {
|
type Delegation struct {
|
||||||
MsgExtension
|
MsgExtension
|
||||||
XMLName xml.Name `xml:"urn:xmpp:delegation:1 delegation"`
|
XMLName xml.Name `xml:"urn:xmpp:delegation:1 delegation"`
|
||||||
Forwarded Forwarded // This is used in iq to wrap delegated iqs
|
Forwarded *Forwarded // This is used in iq to wrap delegated iqs
|
||||||
Delegated Delegated // This is used in a message to confirm delegated namespace
|
Delegated *Delegated // This is used in a message to confirm delegated namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Delegation) Namespace() string {
|
func (d *Delegation) Namespace() string {
|
||||||
@ -235,9 +235,32 @@ func (d *Delegation) Namespace() string {
|
|||||||
|
|
||||||
type Forwarded struct {
|
type Forwarded struct {
|
||||||
XMLName xml.Name `xml:"urn:xmpp:forward:0 forwarded"`
|
XMLName xml.Name `xml:"urn:xmpp:forward:0 forwarded"`
|
||||||
IQ IQ
|
Stanza Packet
|
||||||
Message Message
|
}
|
||||||
Presence Presence
|
|
||||||
|
// 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 {
|
type Delegated struct {
|
||||||
|
@ -80,10 +80,16 @@ func TestParsingDelegationIQ(t *testing.T) {
|
|||||||
var node string
|
var node string
|
||||||
for _, ext := range iq.Payload {
|
for _, ext := range iq.Payload {
|
||||||
if delegation, ok := ext.(*Delegation); ok {
|
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 {
|
if len(payload) > 0 {
|
||||||
payload := delegation.Forwarded.IQ.Payload[0]
|
pl := payload[0]
|
||||||
if pubsub, ok := payload.(*PubSub); ok {
|
if pubsub, ok := pl.(*PubSub); ok {
|
||||||
node = pubsub.Publish.Node
|
node = pubsub.Publish.Node
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
6
pep.go
6
pep.go
@ -17,9 +17,13 @@ type Tune struct {
|
|||||||
Uri string `xml:"uri,omitempty"`
|
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 {
|
type Mood struct {
|
||||||
|
MsgExtension // Mood can be added as a message extension
|
||||||
XMLName xml.Name `xml:"http://jabber.org/protocol/mood mood"`
|
XMLName xml.Name `xml:"http://jabber.org/protocol/mood mood"`
|
||||||
// TODO: Custom parsing to extract mood type from tag name
|
// TODO: Custom parsing to extract mood type from tag name.
|
||||||
|
// Note: the list is predefined.
|
||||||
// Mood type
|
// Mood type
|
||||||
Text string `xml:"text,omitempty"`
|
Text string `xml:"text,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@ import (
|
|||||||
|
|
||||||
type PubSub struct {
|
type PubSub struct {
|
||||||
XMLName xml.Name `xml:"http://jabber.org/protocol/pubsub pubsub"`
|
XMLName xml.Name `xml:"http://jabber.org/protocol/pubsub pubsub"`
|
||||||
Publish Publish
|
Publish *Publish
|
||||||
Retract Retract
|
Retract *Retract
|
||||||
// TODO <configure/>
|
// TODO <configure/>
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,7 +24,8 @@ type Publish struct {
|
|||||||
type Item struct {
|
type Item struct {
|
||||||
XMLName xml.Name `xml:"item"`
|
XMLName xml.Name `xml:"item"`
|
||||||
Id string `xml:"id,attr,omitempty"`
|
Id string `xml:"id,attr,omitempty"`
|
||||||
Tune Tune
|
Tune *Tune
|
||||||
|
Mood *Mood
|
||||||
}
|
}
|
||||||
|
|
||||||
type Retract struct {
|
type Retract struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user