Compare commits

...

2 Commits

Author SHA1 Message Date
Chteufleur eccf505942 Add In-Band Registration support. 2016-09-15 09:33:54 +02:00
Chteufleur a52f910d62 Add code error in Error struct. 2016-09-15 09:33:21 +02:00
2 changed files with 42 additions and 4 deletions

29
src/xmpp/register.go Normal file
View File

@ -0,0 +1,29 @@
package xmpp
import (
"encoding/xml"
)
const (
NSRegister = "jabber:iq:register"
)
// XEP-0077: In-Band Registration
type RegisterQuery struct {
XMLName xml.Name `xml:"jabber:iq:register query"`
Instructions string `xml:"instructions"`
Username string `xml:"username"`
Password string `xml:"password"`
XForm AdHocXForm `xml:"x"`
Registered *RegisterRegistered `xmp:"registered"`
Remove *RegisterRemove `xmp:"remove"`
}
type RegisterRegistered struct {
XMLName xml.Name `xml:"registered"`
}
type RegisterRemove struct {
XMLName xml.Name `xml:"remove"`
}

View File

@ -103,6 +103,7 @@ type Presence struct {
// stanza, e.g. an <iq type="error"/>. // stanza, e.g. an <iq type="error"/>.
type Error struct { type Error struct {
XMLName xml.Name `xml:"error"` XMLName xml.Name `xml:"error"`
Code string `xml:"code,attr,omitempty"`
Type string `xml:"type,attr"` Type string `xml:"type,attr"`
Payload string `xml:",innerxml"` Payload string `xml:",innerxml"`
} }
@ -141,6 +142,12 @@ func NewError(errorType string, condition ErrorCondition, text string) *Error {
return &Error{Type: errorType, Payload: string(buf.Bytes())} return &Error{Type: errorType, Payload: string(buf.Bytes())}
} }
func NewErrorWithCode(code, errorType string, condition ErrorCondition, text string) *Error {
err := NewError(errorType, condition, text)
err.Code = code
return err
}
// Return the error text from the payload, or "" if not present. // Return the error text from the payload, or "" if not present.
func (e Error) Text() string { func (e Error) Text() string {
dec := xml.NewDecoder(bytes.NewBufferString(e.Payload)) dec := xml.NewDecoder(bytes.NewBufferString(e.Payload))
@ -176,8 +183,10 @@ type ErrorCondition xml.Name
// Stanza errors. // Stanza errors.
var ( var (
FeatureNotImplemented = ErrorCondition{nsErrorStanzas, "feature-not-implemented"} ErrorFeatureNotImplemented = ErrorCondition{nsErrorStanzas, "feature-not-implemented"}
RemoteServerNotFound = ErrorCondition{nsErrorStanzas, "remote-server-not-found"} ErrorRemoteServerNotFound = ErrorCondition{nsErrorStanzas, "remote-server-not-found"}
ServiceUnavailable = ErrorCondition{nsErrorStanzas, "service-unavailable"} ErrorServiceUnavailable = ErrorCondition{nsErrorStanzas, "service-unavailable"}
NotAuthorized = ErrorCondition{nsErrorStanzas, "not-authorized"} ErrorNotAuthorized = ErrorCondition{nsErrorStanzas, "not-authorized"}
ErrorConflict = ErrorCondition{nsErrorStanzas, "conflict"}
ErrorNotAcceptable = ErrorCondition{nsErrorStanzas, "not-acceptable"}
) )