mirror of
https://github.com/FluuxIO/go-xmpp.git
synced 2025-04-13 09:29:33 -07:00
Merge 19e0222910
into 7186c058fd
This commit is contained in:
commit
b6952bfeb2
@ -65,7 +65,7 @@ func (c *ServerCheck) Check() error {
|
|||||||
var f stanza.StreamFeatures
|
var f stanza.StreamFeatures
|
||||||
packet, err := stanza.NextPacket(decoder)
|
packet, err := stanza.NextPacket(decoder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("stream open decode features: %s", err)
|
err = fmt.Errorf("stream open decode features: %w", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ func (c *ServerCheck) Check() error {
|
|||||||
|
|
||||||
var k stanza.TLSProceed
|
var k stanza.TLSProceed
|
||||||
if err = decoder.DecodeElement(&k, nil); err != nil {
|
if err = decoder.DecodeElement(&k, nil); err != nil {
|
||||||
return fmt.Errorf("expecting starttls proceed: %s", err)
|
return fmt.Errorf("expecting starttls proceed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var tlsConfig tls.Config
|
var tlsConfig tls.Config
|
||||||
|
@ -8,16 +8,22 @@ import (
|
|||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Message Packet
|
// Message Packet
|
||||||
|
|
||||||
|
// LocalizedString is a string node with a language attribute.
|
||||||
|
type LocalizedString struct {
|
||||||
|
Content string `xml:",chardata"`
|
||||||
|
Lang string `xml:"http://www.w3.org/XML/1998/namespace lang,attr,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// Message implements RFC 6120 - A.5 Client Namespace (a part)
|
// Message implements RFC 6120 - A.5 Client Namespace (a part)
|
||||||
type Message struct {
|
type Message struct {
|
||||||
XMLName xml.Name `xml:"message"`
|
XMLName xml.Name `xml:"message"`
|
||||||
Attrs
|
Attrs
|
||||||
|
|
||||||
Subject string `xml:"subject,omitempty"`
|
Subject []LocalizedString `xml:"subject,omitempty"`
|
||||||
Body string `xml:"body,omitempty"`
|
Body []LocalizedString `xml:"body,omitempty"`
|
||||||
Thread string `xml:"thread,omitempty"`
|
Thread string `xml:"thread,omitempty"`
|
||||||
Error Err `xml:"error,omitempty"`
|
Error Err `xml:"error,omitempty"`
|
||||||
Extensions []MsgExtension `xml:",omitempty"`
|
Extensions []MsgExtension `xml:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Message) Name() string {
|
func (Message) Name() string {
|
||||||
|
@ -10,7 +10,7 @@ type Attrs struct {
|
|||||||
Id string `xml:"id,attr,omitempty"`
|
Id string `xml:"id,attr,omitempty"`
|
||||||
From string `xml:"from,attr,omitempty"`
|
From string `xml:"from,attr,omitempty"`
|
||||||
To string `xml:"to,attr,omitempty"`
|
To string `xml:"to,attr,omitempty"`
|
||||||
Lang string `xml:"lang,attr,omitempty"`
|
Lang string `xml:"http://www.w3.org/XML/1998/namespace lang,attr,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type packetFormatter interface {
|
type packetFormatter interface {
|
||||||
|
@ -91,7 +91,7 @@ func NextXmppToken(p *xml.Decoder) (xml.Token, error) {
|
|||||||
return xml.StartElement{}, errors.New("connection closed")
|
return xml.StartElement{}, errors.New("connection closed")
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xml.StartElement{}, fmt.Errorf("NextStart %s", err)
|
return xml.StartElement{}, fmt.Errorf("NextStart: %w", err)
|
||||||
}
|
}
|
||||||
switch t := t.(type) {
|
switch t := t.(type) {
|
||||||
case xml.StartElement:
|
case xml.StartElement:
|
||||||
@ -112,7 +112,7 @@ func NextStart(p *xml.Decoder) (xml.StartElement, error) {
|
|||||||
return xml.StartElement{}, errors.New("connection closed")
|
return xml.StartElement{}, errors.New("connection closed")
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xml.StartElement{}, fmt.Errorf("NextStart %s", err)
|
return xml.StartElement{}, fmt.Errorf("NextStart: %w", err)
|
||||||
}
|
}
|
||||||
switch t := t.(type) {
|
switch t := t.(type) {
|
||||||
case xml.StartElement:
|
case xml.StartElement:
|
||||||
|
@ -113,22 +113,27 @@ func (sm *StreamManager) Stop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sm *StreamManager) connect() error {
|
func (sm *StreamManager) connect() error {
|
||||||
if sm.client != nil {
|
if sm.client == nil {
|
||||||
if c, ok := sm.client.(*Client); ok {
|
return errors.New("client is not set")
|
||||||
if c.CurrentState.getState() == StateDisconnected {
|
}
|
||||||
sm.Metrics = initMetrics()
|
|
||||||
err := c.Connect()
|
if c, ok := sm.client.(*Client); ok {
|
||||||
if err != nil {
|
if c.CurrentState.getState() != StateDisconnected {
|
||||||
return err
|
return errors.New("client is not disconnected")
|
||||||
}
|
|
||||||
if sm.PostConnect != nil {
|
|
||||||
sm.PostConnect(sm.client)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return errors.New("client is not disconnected")
|
|
||||||
|
sm.Metrics = initMetrics()
|
||||||
|
|
||||||
|
if err := sm.client.Connect(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if sm.PostConnect != nil {
|
||||||
|
sm.PostConnect(sm.client)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// resume manages the reconnection loop and apply the define backoff to avoid overloading the server.
|
// resume manages the reconnection loop and apply the define backoff to avoid overloading the server.
|
||||||
|
@ -155,7 +155,7 @@ func respondToIQ(t *testing.T, sc *ServerConn) {
|
|||||||
mResp, err := xml.Marshal(iqResp)
|
mResp, err := xml.Marshal(iqResp)
|
||||||
_, err = fmt.Fprintln(sc.connection, string(mResp))
|
_, err = fmt.Fprintln(sc.connection, string(mResp))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Could not send response stanza : %s", err)
|
t.Errorf("Could not send response stanza : %w", err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -175,15 +175,15 @@ func discardPresence(t *testing.T, sc *ServerConn) {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
|
if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
|
||||||
t.Errorf("read timeout: %s", err)
|
t.Errorf("read timeout: %w", err)
|
||||||
} else {
|
} else {
|
||||||
t.Errorf("read error: %s", err)
|
t.Errorf("read error: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = xml.Unmarshal(recvBuf, &presenceStz)
|
err = xml.Unmarshal(recvBuf, &presenceStz)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Expected presence but this happened : %s", err.Error())
|
t.Errorf("Expected presence but this happened : %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,7 +223,7 @@ func sendStreamFeatures(t *testing.T, sc *ServerConn) {
|
|||||||
</mechanisms>
|
</mechanisms>
|
||||||
</stream:features>`
|
</stream:features>`
|
||||||
if _, err := fmt.Fprintln(sc.connection, features); err != nil {
|
if _, err := fmt.Fprintln(sc.connection, features); err != nil {
|
||||||
t.Errorf("cannot send stream feature: %s", err)
|
t.Errorf("cannot send stream feature: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,7 +231,7 @@ func sendStreamFeatures(t *testing.T, sc *ServerConn) {
|
|||||||
func readAuth(t *testing.T, decoder *xml.Decoder) string {
|
func readAuth(t *testing.T, decoder *xml.Decoder) string {
|
||||||
se, err := stanza.NextStart(decoder)
|
se, err := stanza.NextStart(decoder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("cannot read auth: %s", err)
|
t.Errorf("cannot read auth: %w", err)
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,7 +239,7 @@ func readAuth(t *testing.T, decoder *xml.Decoder) string {
|
|||||||
nv = &stanza.SASLAuth{}
|
nv = &stanza.SASLAuth{}
|
||||||
// Decode element into pointer storage
|
// Decode element into pointer storage
|
||||||
if err = decoder.DecodeElement(nv, &se); err != nil {
|
if err = decoder.DecodeElement(nv, &se); err != nil {
|
||||||
t.Errorf("cannot decode auth: %s", err)
|
t.Errorf("cannot decode auth: %w", err)
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,7 +256,7 @@ func sendBindFeature(t *testing.T, sc *ServerConn) {
|
|||||||
<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>
|
<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>
|
||||||
</stream:features>`
|
</stream:features>`
|
||||||
if _, err := fmt.Fprintln(sc.connection, features); err != nil {
|
if _, err := fmt.Fprintln(sc.connection, features); err != nil {
|
||||||
t.Errorf("cannot send stream feature: %s", err)
|
t.Errorf("cannot send stream feature: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,21 +267,21 @@ func sendRFC3921Feature(t *testing.T, sc *ServerConn) {
|
|||||||
<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>
|
<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>
|
||||||
</stream:features>`
|
</stream:features>`
|
||||||
if _, err := fmt.Fprintln(sc.connection, features); err != nil {
|
if _, err := fmt.Fprintln(sc.connection, features); err != nil {
|
||||||
t.Errorf("cannot send stream feature: %s", err)
|
t.Errorf("cannot send stream feature: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func bind(t *testing.T, sc *ServerConn) {
|
func bind(t *testing.T, sc *ServerConn) {
|
||||||
se, err := stanza.NextStart(sc.decoder)
|
se, err := stanza.NextStart(sc.decoder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("cannot read bind: %s", err)
|
t.Errorf("cannot read bind: %w", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
iq := &stanza.IQ{}
|
iq := &stanza.IQ{}
|
||||||
// Decode element into pointer storage
|
// Decode element into pointer storage
|
||||||
if err = sc.decoder.DecodeElement(&iq, &se); err != nil {
|
if err = sc.decoder.DecodeElement(&iq, &se); err != nil {
|
||||||
t.Errorf("cannot decode bind iq: %s", err)
|
t.Errorf("cannot decode bind iq: %w", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,14 +300,14 @@ func bind(t *testing.T, sc *ServerConn) {
|
|||||||
func session(t *testing.T, sc *ServerConn) {
|
func session(t *testing.T, sc *ServerConn) {
|
||||||
se, err := stanza.NextStart(sc.decoder)
|
se, err := stanza.NextStart(sc.decoder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("cannot read session: %s", err)
|
t.Errorf("cannot read session: %w", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
iq := &stanza.IQ{}
|
iq := &stanza.IQ{}
|
||||||
// Decode element into pointer storage
|
// Decode element into pointer storage
|
||||||
if err = sc.decoder.DecodeElement(&iq, &se); err != nil {
|
if err = sc.decoder.DecodeElement(&iq, &se); err != nil {
|
||||||
t.Errorf("cannot decode session iq: %s", err)
|
t.Errorf("cannot decode session iq: %w", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ func (t *WebsocketTransport) cleanup(code websocket.StatusCode) error {
|
|||||||
t.queue = nil
|
t.queue = nil
|
||||||
}
|
}
|
||||||
if t.wsConn != nil {
|
if t.wsConn != nil {
|
||||||
err = t.wsConn.Close(websocket.StatusGoingAway, "Done")
|
err = t.wsConn.Close(code, "Done")
|
||||||
t.wsConn = nil
|
t.wsConn = nil
|
||||||
}
|
}
|
||||||
if t.closeFunc != nil {
|
if t.closeFunc != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user