sum7
/
yaja
Archived
1
0
Fork 0

improve stanze error handling

This commit is contained in:
Martin/Geno 2018-02-11 15:11:52 +01:00
parent 5964a8fb3c
commit f4bc539cd7
No known key found for this signature in database
GPG Key ID: F0D39A37E925E941
4 changed files with 53 additions and 14 deletions

View File

@ -149,10 +149,15 @@ func (client *Client) connect(password string) error {
if err := client.ReadElement(&iq); err != nil {
return err
}
if iq.Bind == nil {
if iq.Error != nil {
if iq.Error.Type == messages.ErrorClientTypeCancel && iq.Error.ServiceUnavailable != nil {
//TODO binding service unavailable
} else {
return errors.New(fmt.Sprintf("recv error on iq>bind: %s[%s]: %s -> %v", iq.Error.Code, iq.Error.Type, iq.Error.Text, iq.Error.Other))
}
} else if iq.Bind == nil {
return errors.New("<iq> result missing <bind>")
}
if iq.Bind.JID != nil {
} else if iq.Bind.JID != nil {
client.JID.Local = iq.Bind.JID.Local
client.JID.Domain = iq.Bind.JID.Domain
client.JID.Resource = iq.Bind.JID.Resource
@ -160,7 +165,7 @@ func (client *Client) connect(password string) error {
return errors.New(fmt.Sprintf("%v", iq.Other))
}
// set status
client.Send(&messages.PresenceClient{Show: messages.ShowTypeXA, Status: "online"})
err = client.Send(&messages.PresenceClient{Show: messages.ShowTypeXA, Status: "online"})
return err
}

View File

@ -82,7 +82,7 @@ func (t *Tester) StartBot(status *Status) {
}
logCTX = logCTX.WithField("from", msg.From.Full()).WithField("msg-recv", msg.Body)
if msg.Error != nil {
logCTX.Debugf("recv msg with error %s: %s", msg.Error.Code, msg.Error.Text)
logCTX.Debugf("recv msg with error %s[%s]: %s -> %v -> %v", msg.Error.Code, msg.Error.Type, msg.Error.Text, msg.Error.StanzaErrorGroup, msg.Error.Other)
continue
}

View File

@ -9,12 +9,47 @@ type StreamError struct {
Any xml.Name `xml:",any"`
}
type ErrorClientType string
const (
ErrorClientTypeAuth ErrorClientType = "auth"
ErrorClientTypeCancel ErrorClientType = "cancel"
ErrorClientTypeContinue ErrorClientType = "continue"
ErrorClientTypeModify ErrorClientType = "motify"
ErrorClientTypeWait ErrorClientType = "wait"
)
type StanzaErrorGroup struct {
BadRequest *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas bad-request"`
Conflict *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas conflict"`
FeatureNotImplemented *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas feature-not-implemented"`
Forbidden *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas forbidden"`
Gone string `xml:"urn:ietf:params:xml:ns:xmpp-stanzas gone"`
InternalServerError *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas internal-server-error"`
ItemNotFound *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas item-not-found"`
JIDMalformed *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas jid-malformed"`
NotAcceptable *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas not-acceptable"`
NotAllowed *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas not-allowed"`
NotAuthorized *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas not-authorized"`
PolicyViolation *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas policy-violation"`
RecipientUnavailable *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas recipient-unavailable"`
Redirect string `xml:"urn:ietf:params:xml:ns:xmpp-stanzas redirect"`
RegistrationRequired *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas registration-required"`
RemoteServerNotFound *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas remote-server-not-found"`
RemoteServerTimeout *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas remote-server-timeout"`
ResourceConstraint *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas resource-constraint"`
ServiceUnavailable *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas service-unavailable"`
SubscriptionRequired *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas subscription-required"`
UndefinedCondition *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas undefined-condition"`
UnexpectedRequest *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-stanzas unexpected-request"`
}
// ErrorClient element
type ErrorClient struct {
XMLName xml.Name `xml:"jabber:client error"`
Code string `xml:"code,attr"`
Type string `xml:"type,attr"`
Text string `xml:"text"`
Any xml.Name `xml:",any"`
XMLName xml.Name `xml:"jabber:client error"`
Code string `xml:"code,attr"`
Type ErrorClientType `xml:"type,attr"`
Text string `xml:"text"`
Other []XMLElement `xml:",any"`
StanzaErrorGroup
}

View File

@ -115,9 +115,8 @@ func (state *RegisterRequest) Process() state.State {
Error: &messages.ErrorClient{
Code: "409",
Type: "cancel",
Any: xml.Name{
Local: "conflict",
Space: "urn:ietf:params:xml:ns:xmpp-stanzas",
StanzaErrorGroup: messages.StanzaErrorGroup{
Conflict: &xml.Name{},
},
},
})