-
Notifications
You must be signed in to change notification settings - Fork 1
/
interface.go
117 lines (91 loc) · 3.02 KB
/
interface.go
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright 2020 The jackal Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package stravaganza
import (
"encoding"
"fmt"
"io"
"github.com/jackal-xmpp/stravaganza/jid"
)
// Attribute represents an XML node attribute (label=value).
type Attribute struct {
Label string
Value string
}
// AttributeReader defines an XML attributes read-only interface.
type AttributeReader interface {
// AllChildren returns a list of all node attributes.
AllAttributes() []Attribute
// AttributeCount returns node total attribute count.
AttributeCount() int
// Attribute returns XML node attribute value.
Attribute(label string) string
}
// ElementReader defines an XML sub elements read-only interface.
type ElementReader interface {
// AllChildren returns a list of all child nodes.
AllChildren() []Element
// ChildrenCount returns child elements count.
ChildrenCount() int
// Child returns first element identified by name.
Child(name string) Element
// Children returns all elements identified by name.
// Returns an empty array if no elements are found.
Children(name string) []Element
// ChildNamespace returns first element identified by name and namespace.
// Returns nil if no element is found.
ChildNamespace(name, ns string) Element
// ChildrenNamespace returns all elements identified by name and namespace.
ChildrenNamespace(name, ns string) []Element
}
// XMLSerializer represents element common XML serializer interface.
type XMLSerializer interface {
// ToXML serializes element to a raw XML representation.
// includeClosing determines if closing tag should be attached.
ToXML(w io.Writer, includeClosing bool) error
}
// Element represents a generic XML node element.
type Element interface {
AttributeReader
ElementReader
XMLSerializer
encoding.BinaryMarshaler
encoding.BinaryUnmarshaler
fmt.Stringer
fmt.GoStringer
// Name returns XML node name.
Name() string
// Text returns XML node text value.
Text() string
// Proto returns element protobuf message.
Proto() *PBElement
}
// Stanza represents an XMPP stanza element.
type Stanza interface {
Element
// ToJID returns stanza 'to' JID value.
ToJID() *jid.JID
// FromJID returns stanza 'from' JID value.
FromJID() *jid.JID
// ID returns 'id' node attribute.
ID() string
// Namespace returns 'xmlns' node attribute.
Namespace() string
// Type returns 'type' node attribute.
Type() string
// IsError returns true if stanza has a 'type' attribute of value 'error'.
IsError() bool
// Error returns stanza error sub element.
Error() Element
}