From 81c86054778dc78f66fdd787e1410a89c667d8c5 Mon Sep 17 00:00:00 2001 From: Martin/Geno Date: Tue, 13 Feb 2018 20:05:18 +0100 Subject: [PATCH] messages after RFC 6120 completed --- client/auth.go | 5 +- client/client.go | 13 ++- client/connect.go | 2 +- client/start.go | 97 ++++++++++++++++++++ daemon/tester/account.go | 4 +- daemon/tester/bot.go | 7 +- daemon/tester/config.go | 8 +- daemon/tester/output.go | 4 +- daemon/tester/status.go | 9 +- daemon/tester/tester.go | 9 +- database/main.go | 5 +- messages/client_error.go | 17 ++++ messages/client_iq.go | 23 +++++ messages/client_message.go | 25 +++++ messages/client_presence.go | 29 ++++++ messages/connection.go | 26 +++--- messages/enum_error.go | 12 +++ messages/enum_iq.go | 11 +++ messages/enum_message.go | 12 +++ messages/enum_presence.go | 24 +++++ messages/error.go | 83 ----------------- messages/error_stanze.go | 32 +++++++ messages/error_stream.go | 42 +++++++++ messages/global.go | 24 +++++ messages/iq.go | 48 ---------- messages/iq_utils.go | 25 +++++ {model => messages}/jid.go | 2 +- {model => messages}/jid_test.go | 2 +- messages/message.go | 35 ------- messages/namespaces.go | 24 +++-- messages/presence.go | 46 ---------- messages/roster.go | 12 +-- messages/sasl.go | 6 +- messages/server_error.go | 17 ++++ messages/server_iq.go | 23 +++++ messages/server_message.go | 25 +++++ messages/server_presence.go | 29 ++++++ messages/utils.go | 9 -- model/account.go | 12 ++- server/extension/iq_disco.bak | 2 +- server/extension/iq_discovery.bak | 2 +- server/extension/iq_last.bak | 2 +- server/extension/iq_ping.go | 3 +- server/extension/iq_private_bookmarks.bak | 2 +- server/extension/iq_private_metacontacts.bak | 2 +- server/extension/iq_private_roster.bak | 2 +- server/server.go | 4 +- server/state/connect.go | 7 +- server/toclient/connect.go | 3 +- server/toclient/register.go | 6 +- server/utils/client.go | 3 +- server/utils/main.go | 6 +- 52 files changed, 573 insertions(+), 309 deletions(-) create mode 100644 client/start.go create mode 100644 messages/client_error.go create mode 100644 messages/client_iq.go create mode 100644 messages/client_message.go create mode 100644 messages/client_presence.go create mode 100644 messages/enum_error.go create mode 100644 messages/enum_iq.go create mode 100644 messages/enum_message.go create mode 100644 messages/enum_presence.go delete mode 100644 messages/error.go create mode 100644 messages/error_stanze.go create mode 100644 messages/error_stream.go create mode 100644 messages/global.go delete mode 100644 messages/iq.go create mode 100644 messages/iq_utils.go rename {model => messages}/jid.go (98%) rename {model => messages}/jid_test.go (99%) delete mode 100644 messages/message.go delete mode 100644 messages/presence.go create mode 100644 messages/server_error.go create mode 100644 messages/server_iq.go create mode 100644 messages/server_message.go create mode 100644 messages/server_presence.go diff --git a/client/auth.go b/client/auth.go index 003264f..7240ed0 100644 --- a/client/auth.go +++ b/client/auth.go @@ -94,7 +94,10 @@ func (client *Client) auth(password string) error { } fail := messages.SASLFailure{} if err := client.Decode(&fail, element); err == nil { - return errors.New(messages.XMLChildrenString(fail) + " : " + fail.Body) + if txt := fail.Text; txt != nil { + return errors.New(messages.XMLChildrenString(fail) + " : " + txt.Body) + } + return errors.New(messages.XMLChildrenString(fail)) } if err := client.Decode(&messages.SASLSuccess{}, element); err != nil { return errors.New("auth failed - with unexpected answer") diff --git a/client/client.go b/client/client.go index 109674e..9f0a651 100644 --- a/client/client.go +++ b/client/client.go @@ -10,7 +10,7 @@ import ( log "github.com/sirupsen/logrus" - "dev.sum7.eu/genofire/yaja/model" + "dev.sum7.eu/genofire/yaja/messages" ) // Client holds XMPP connection opitons @@ -23,10 +23,17 @@ type Client struct { Logging *log.Logger - JID *model.JID + JID *messages.JID + + reply map[string]chan *messages.IQClient + + skipError bool + iq chan *messages.IQClient + presence chan *messages.PresenceClient + mesage chan *messages.MessageClient } -func NewClient(jid *model.JID, password string) (*Client, error) { +func NewClient(jid *messages.JID, password string) (*Client, error) { client := &Client{ Protocol: "tcp", JID: jid, diff --git a/client/connect.go b/client/connect.go index a97bdc9..55db231 100644 --- a/client/connect.go +++ b/client/connect.go @@ -99,7 +99,7 @@ func (client *Client) connect(password string) error { } if err := client.Send(&messages.IQClient{ Type: messages.IQTypeSet, - To: model.NewJID(client.JID.Domain), + To: messages.NewJID(client.JID.Domain), Bind: bind, }); err != nil { return err diff --git a/client/start.go b/client/start.go new file mode 100644 index 0000000..fd934b5 --- /dev/null +++ b/client/start.go @@ -0,0 +1,97 @@ +package client + +import ( + "fmt" + + "dev.sum7.eu/genofire/yaja/messages" +) + +var DefaultChannelSize = 30 + +func (client *Client) Start() error { + client.iq = make(chan *messages.IQClient, DefaultChannelSize) + client.presence = make(chan *messages.PresenceClient, DefaultChannelSize) + client.mesage = make(chan *messages.MessageClient, DefaultChannelSize) + client.reply = make(map[string]chan *messages.IQClient) + + for { + + element, err := client.Read() + if err != nil { + return err + } + + errMSG := &messages.StreamError{} + err = client.Decode(errMSG, element) + if err == nil { + return fmt.Errorf("recv stream error: %s: %s -> %s", errMSG.Text, messages.XMLChildrenString(errMSG.StreamErrorGroup), messages.XMLChildrenString(errMSG.Other)) + } + + iq := &messages.IQClient{} + err = client.Decode(iq, element) + if err == nil { + if iq.Ping != nil { + client.Logging.Debug("answer ping") + iq.Type = messages.IQTypeResult + iq.To = iq.From + iq.From = client.JID + client.Send(iq) + } else { + if client.skipError && iq.Error != nil { + continue + } + if ch, ok := client.reply[iq.ID]; ok { + delete(client.reply, iq.ID) + ch <- iq + continue + } + client.iq <- iq + } + continue + } + + pres := &messages.PresenceClient{} + err = client.Decode(pres, element) + if err == nil { + if client.skipError && pres.Error != nil { + continue + } + client.presence <- pres + continue + } + + msg := &messages.MessageClient{} + err = client.Decode(msg, element) + if err == nil { + if client.skipError && msg.Error != nil { + continue + } + client.mesage <- msg + continue + } + client.Logging.Warnf("unsupport xml recv: %v", element) + } +} + +func (client *Client) SendRecv(iq *messages.IQClient) *messages.IQClient { + if iq.ID == "" { + iq.ID = messages.CreateCookieString() + } + ch := make(chan *messages.IQClient, 1) + client.reply[iq.ID] = ch + client.Send(iq) + defer close(ch) + return <-ch +} + +func (client *Client) RecvIQ() *messages.IQClient { + return <-client.iq +} + +func (client *Client) RecvPresence() *messages.PresenceClient { + return <-client.presence +} + +func (client *Client) RecvMessage() *messages.MessageClient { + return <-client.mesage +} diff --git a/daemon/tester/account.go b/daemon/tester/account.go index 778ad87..722fdf3 100644 --- a/daemon/tester/account.go +++ b/daemon/tester/account.go @@ -1,9 +1,9 @@ package tester -import "dev.sum7.eu/genofire/yaja/model" +import "dev.sum7.eu/genofire/yaja/messages" type Account struct { - JID *model.JID `json:"jid"` + JID *messages.JID `json:"jid"` Password string `json:"password"` Admins map[string]interface{} `json:"admins"` } diff --git a/daemon/tester/bot.go b/daemon/tester/bot.go index 198d970..9b1d0ff 100644 --- a/daemon/tester/bot.go +++ b/daemon/tester/bot.go @@ -7,7 +7,6 @@ import ( log "github.com/sirupsen/logrus" "dev.sum7.eu/genofire/yaja/messages" - "dev.sum7.eu/genofire/yaja/model" ) func (t *Tester) StartBot(status *Status) { @@ -141,15 +140,15 @@ func (t *Tester) StartBot(status *Status) { } } } -func botAllowed(list []*model.JID, toConvert map[string]interface{}) []*model.JID { +func botAllowed(list []*messages.JID, toConvert map[string]interface{}) []*messages.JID { alist := list for jid, _ := range toConvert { - alist = append(alist, model.NewJID(jid)) + alist = append(alist, messages.NewJID(jid)) } return alist } -func botAdmin(cmd []string, log *log.Entry, status *Status, from *model.JID, allowed []*model.JID) { +func botAdmin(cmd []string, log *log.Entry, status *Status, from *messages.JID, allowed []*messages.JID) { msg := "" if len(cmd) == 2 { isAdmin := false diff --git a/daemon/tester/config.go b/daemon/tester/config.go index 2540dbb..0b4df47 100644 --- a/daemon/tester/config.go +++ b/daemon/tester/config.go @@ -1,7 +1,7 @@ package tester import ( - "dev.sum7.eu/genofire/yaja/model" + "dev.sum7.eu/genofire/yaja/messages" "github.com/FreifunkBremen/yanic/lib/duration" log "github.com/sirupsen/logrus" ) @@ -15,9 +15,9 @@ type Config struct { LoggingBots log.Level `toml:"logging_bots"` Timeout duration.Duration `toml:"timeout"` Interval duration.Duration `toml:"interval"` - Admins []*model.JID `toml:"admins"` + Admins []*messages.JID `toml:"admins"` Client struct { - JID *model.JID `toml:"jid"` - Password string `toml:"password"` + JID *messages.JID `toml:"jid"` + Password string `toml:"password"` } `toml:"client"` } diff --git a/daemon/tester/output.go b/daemon/tester/output.go index c25f23e..822bee7 100644 --- a/daemon/tester/output.go +++ b/daemon/tester/output.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "dev.sum7.eu/genofire/yaja/model" + "dev.sum7.eu/genofire/yaja/messages" "github.com/FreifunkBremen/yanic/lib/jsontime" ) @@ -53,7 +53,7 @@ func (t *Tester) Output() *Output { } continue } - toJID := model.NewJID(to) + toJID := messages.NewJID(to) link := &Link{ Source: status.JID.Domain, SourceJID: status.JID.Bare(), diff --git a/daemon/tester/status.go b/daemon/tester/status.go index 2524e29..8bd298e 100644 --- a/daemon/tester/status.go +++ b/daemon/tester/status.go @@ -7,14 +7,13 @@ import ( "dev.sum7.eu/genofire/yaja/client" "dev.sum7.eu/genofire/yaja/messages" - "dev.sum7.eu/genofire/yaja/model" ) type Status struct { backupClient *client.Client client *client.Client account *Account - JID *model.JID `json:"jid"` + JID *messages.JID `json:"jid"` Domain string `json:"domain"` Login bool `json:"is_online"` MessageForConnection map[string]string `json:"-"` @@ -41,7 +40,7 @@ func (s *Status) Disconnect(reason string) { Body: fmt.Sprintf("you recieve a notify that '%s' disconnect: %s", s.JID.Full(), reason), } for jid, _ := range s.account.Admins { - msg.To = model.NewJID(jid) + msg.To = messages.NewJID(jid) if err := s.backupClient.Send(msg); err != nil { s.client.Send(msg) } @@ -59,7 +58,7 @@ func (s *Status) Update(timeout time.Duration) { } c := &client.Client{ - JID: model.NewJID(s.account.JID.Bare()), + JID: messages.NewJID(s.account.JID.Bare()), Protocol: "tcp4", Logging: s.client.Logging, Timeout: timeout / 2, @@ -72,7 +71,7 @@ func (s *Status) Update(timeout time.Duration) { s.IPv4 = false } - c.JID = model.NewJID(s.account.JID.Bare()) + c.JID = messages.NewJID(s.account.JID.Bare()) c.Protocol = "tcp6" if err := c.Connect(s.account.Password); err == nil { diff --git a/daemon/tester/tester.go b/daemon/tester/tester.go index 9222e19..7b4cc70 100644 --- a/daemon/tester/tester.go +++ b/daemon/tester/tester.go @@ -8,7 +8,6 @@ import ( "dev.sum7.eu/genofire/yaja/client" "dev.sum7.eu/genofire/yaja/messages" - "dev.sum7.eu/genofire/yaja/model" ) type Tester struct { @@ -17,9 +16,9 @@ type Tester struct { Accounts map[string]*Account `json:"accounts"` Status map[string]*Status `json:"-"` mux sync.Mutex - LoggingClients *log.Logger `json:"-"` - LoggingBots log.Level `json:"-"` - Admins []*model.JID `json:"-"` + LoggingClients *log.Logger `json:"-"` + LoggingBots log.Level `json:"-"` + Admins []*messages.JID `json:"-"` } func NewTester() *Tester { @@ -89,7 +88,7 @@ func (t *Tester) Connect(acc *Account) { } } -func (t *Tester) UpdateConnectionStatus(from, to *model.JID, recvmsg string) { +func (t *Tester) UpdateConnectionStatus(from, to *messages.JID, recvmsg string) { logCTX := log.WithFields(log.Fields{ "jid": to.Full(), "from": from.Full(), diff --git a/database/main.go b/database/main.go index bf069f4..465f01b 100644 --- a/database/main.go +++ b/database/main.go @@ -4,6 +4,7 @@ import ( "errors" "sync" + "dev.sum7.eu/genofire/yaja/messages" "dev.sum7.eu/genofire/yaja/model" log "github.com/sirupsen/logrus" ) @@ -48,7 +49,7 @@ func (s *State) AddAccount(a *model.Account) error { return errors.New("no give domain") } -func (s *State) Authenticate(jid *model.JID, password string) (bool, error) { +func (s *State) Authenticate(jid *messages.JID, password string) (bool, error) { logger := log.WithField("database", "auth") if domain, ok := s.Domains[jid.Domain]; ok { @@ -67,7 +68,7 @@ func (s *State) Authenticate(jid *model.JID, password string) (bool, error) { return false, nil } -func (s *State) GetAccount(jid *model.JID) *model.Account { +func (s *State) GetAccount(jid *messages.JID) *model.Account { logger := log.WithField("database", "get") if domain, ok := s.Domains[jid.Domain]; ok { diff --git a/messages/client_error.go b/messages/client_error.go new file mode 100644 index 0000000..6d15be5 --- /dev/null +++ b/messages/client_error.go @@ -0,0 +1,17 @@ +package messages + +import "encoding/xml" + +// RFC 6120 - A.5 Client Namespace (a part) +type ErrorClient struct { + XMLName xml.Name `xml:"jabber:client error"` + Code string `xml:"code,attr,omitempty"` + Type ErrorType `xml:"type,attr"` // required + Text *Text + + // RFC 6120 A.8 Resource binding namespace + StanzaErrorGroup + + // Any hasn't matched element + Other []XMLElement `xml:",any"` +} diff --git a/messages/client_iq.go b/messages/client_iq.go new file mode 100644 index 0000000..4c7db67 --- /dev/null +++ b/messages/client_iq.go @@ -0,0 +1,23 @@ +package messages + +import ( + "encoding/xml" +) + +// RFC 6120 - A.5 Client Namespace (a part) +type IQClient struct { + XMLName xml.Name `xml:"jabber:client iq"` + From *JID `xml:"from,attr,omitempty"` + ID string `xml:"id,attr"` // required + To *JID `xml:"to,attr,omitempty"` + Type IQType `xml:"type,attr"` // required + Error *ErrorClient + + Bind *Bind // which XEP ? + Ping *Ping // which XEP ? + PrivateQuery *IQPrivateQuery // which XEP ? + PrivateRegister *IQPrivateRegister // which XEP ? + + // Any hasn't matched element + Other []XMLElement `xml:",any"` +} diff --git a/messages/client_message.go b/messages/client_message.go new file mode 100644 index 0000000..c6f2c62 --- /dev/null +++ b/messages/client_message.go @@ -0,0 +1,25 @@ +package messages + +import ( + "encoding/xml" +) + +// RFC 6120 - A.5 Client Namespace (a part) +type MessageClient struct { + XMLName xml.Name `xml:"jabber:client message"` + From *JID `xml:"from,attr,omitempty"` + ID string `xml:"id,attr,omitempty"` + To *JID `xml:"to,attr,omitempty"` + Type MessageType `xml:"type,attr,omitempty"` // default: normal + Lang string `xml:"lang,attr,omitempty"` + + Subject string `xml:"subject,omitempty"` + Body string `xml:"body,omitempty"` + Thread string `xml:"thread,omitempty"` + Error *ErrorClient + + Delay *Delay `xml:"delay"` // which XEP ? + + // Any hasn't matched element + Other []XMLElement `xml:",any"` +} diff --git a/messages/client_presence.go b/messages/client_presence.go new file mode 100644 index 0000000..160c632 --- /dev/null +++ b/messages/client_presence.go @@ -0,0 +1,29 @@ +package messages + +import ( + "encoding/xml" +) + +// RFC 6120 - A.5 Client Namespace (a part) +type PresenceClient struct { + XMLName xml.Name `xml:"jabber:client presence"` + From *JID `xml:"from,attr,omitempty"` + ID string `xml:"id,attr,omitempty"` + To *JID `xml:"to,attr,omitempty"` + Type PresenceType `xml:"type,attr,omitempty"` + Lang string `xml:"lang,attr,omitempty"` + + Show PresenceShow `xml:"show,omitempty"` + Status string `xml:"status,omitempty"` + Priority uint `xml:"priority,omitempty"` // default: 0 + + Error *ErrorClient + + Delay *Delay `xml:"delay"` // which XEP ? + + // which XEP ? + // Caps *ClientCaps `xml:"c"` + + // Any hasn't matched element + Other []XMLElement `xml:",any"` +} diff --git a/messages/connection.go b/messages/connection.go index 39924ad..07b84be 100644 --- a/messages/connection.go +++ b/messages/connection.go @@ -2,11 +2,9 @@ package messages import ( "encoding/xml" - - "dev.sum7.eu/genofire/yaja/model" ) -// RFC 3920 C.1 Streams name space +// RFC 6120 - A.1 Stream Namespace type StreamFeatures struct { XMLName xml.Name `xml:"http://etherx.jabber.org/streams features"` StartTLS *TLSStartTLS @@ -15,23 +13,25 @@ type StreamFeatures struct { Session bool } -// RFC 3920 C.3 TLS name space +// RFC 6120 - A.3 StartTLS Namespace type TLSStartTLS struct { XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-tls starttls"` Required *string `xml:"required"` } -type TLSFailure struct { - XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-tls failure"` -} - +// RFC 6120 - A.3 StartTLS Namespace type TLSProceed struct { XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-tls proceed"` } -// RFC 3920 C.5 Resource binding name space -type Bind struct { - XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-bind bind"` - Resource string `xml:"resource"` - JID *model.JID `xml:"jid"` +// RFC 6120 - A.3 StartTLS Namespace +type TLSFailure struct { + XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-tls failure"` +} + +// RFC 6120 A.7 Resource binding namespace +type Bind struct { + XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-bind bind"` + Resource string `xml:"resource"` + JID *JID `xml:"jid"` } diff --git a/messages/enum_error.go b/messages/enum_error.go new file mode 100644 index 0000000..db4c6e6 --- /dev/null +++ b/messages/enum_error.go @@ -0,0 +1,12 @@ +package messages + +type ErrorType string + +// RFC 6120 part of A.5 Client Namespace and A.6 Server Namespace +const ( + ErrorTypeAuth ErrorType = "auth" + ErrorTypeCancel ErrorType = "cancel" + ErrorTypeContinue ErrorType = "continue" + ErrorTypeModify ErrorType = "motify" + ErrorTypeWait ErrorType = "wait" +) diff --git a/messages/enum_iq.go b/messages/enum_iq.go new file mode 100644 index 0000000..712ea50 --- /dev/null +++ b/messages/enum_iq.go @@ -0,0 +1,11 @@ +package messages + +type IQType string + +// RFC 6120 part of A.5 Client Namespace and A.6 Server Namespace +const ( + IQTypeError IQType = "error" + IQTypeGet IQType = "get" + IQTypeResult IQType = "result" + IQTypeSet IQType = "set" +) diff --git a/messages/enum_message.go b/messages/enum_message.go new file mode 100644 index 0000000..821c60c --- /dev/null +++ b/messages/enum_message.go @@ -0,0 +1,12 @@ +package messages + +type MessageType string + +// RFC 6120 part of A.5 Client Namespace and A.6 Server Namespace +const ( + MessageTypeChat MessageType = "chat" + MessageTypeError MessageType = "error" + MessageTypeGroupchat MessageType = "groupchat" + MessageTypeHeadline MessageType = "headline" + MessageTypeNormal MessageType = "normal" +) diff --git a/messages/enum_presence.go b/messages/enum_presence.go new file mode 100644 index 0000000..eb2ef95 --- /dev/null +++ b/messages/enum_presence.go @@ -0,0 +1,24 @@ +package messages + +type PresenceType string + +// RFC 6120 part of A.5 Client Namespace and A.6 Server Namespace +const ( + PresenceTypeError PresenceType = "error" + PresenceTypeProbe PresenceType = "probe" + PresenceTypeSubscribe PresenceType = "subscribe" + PresenceTypeSubscribed PresenceType = "subscribed" + PresenceTypeUnavailable PresenceType = "unavailable" + PresenceTypeUnsubscribe PresenceType = "unsubscribe" + PresenceTypeUnsubscribed PresenceType = "unsubscribed" +) + +type PresenceShow string + +// RFC 6120 part of A.5 Client Namespace and A.6 Server Namespace +const ( + PresenceShowAway PresenceShow = "away" + PresenceShowChat PresenceShow = "chat" + PresenceShowDND PresenceShow = "dnd" + PresenceShowXA PresenceShow = "xa" +) diff --git a/messages/error.go b/messages/error.go deleted file mode 100644 index 9414be6..0000000 --- a/messages/error.go +++ /dev/null @@ -1,83 +0,0 @@ -package messages - -import "encoding/xml" - -type StreamErrorGroup struct { - BadFormat *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams bad-format"` - BadNamespacePrefix *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams bad-namespace-prefix"` - Conflict *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams conflict"` - ConnectionTimeout *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams connection-timeout"` - HostGone *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams host-gone"` - HostUnknown *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams host-unknown"` - ImproperAddressing *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams improper-addressing"` - InternalServerError *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams internal-server-error"` - InvalidFrom *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams invalid-from"` - InvalidID *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams invalid-id"` - InvalidNamespace *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams invalid-namespace"` - InvalidXML *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams invalid-xml"` - NotAuthorized *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams not-authorized"` - NotWellFormed *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams not-well-formed"` - PolicyViolation *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams policy-violation"` - RemoteConnectionFailed *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams remote-connection-failed"` - Reset *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams reset"` - ResourceConstraint *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams resource-constraint"` - RestrictedXML *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams restricted-xml"` - SeeOtherHost string `xml:"urn:ietf:params:xml:ns:xmpp-streams see-other-host"` - SystemShutdown *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams system-shutdown"` - UndefinedCondition *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams undefined-condition"` - UnsupportedEncoding *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams unsupported-encoding"` - UnsupportedStanzaType *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams unsupported-stanza-type"` - UnsupportedVersion *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams unsupported-version"` -} - -type StreamError struct { - XMLName xml.Name `xml:"http://etherx.jabber.org/streams error"` - Text string `xml:"urn:ietf:params:xml:ns:xmpp-streams text"` - Other []XMLElement `xml:",any"` - StreamErrorGroup -} - -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 ErrorClientType `xml:"type,attr"` - Text string `xml:"text"` - Other []XMLElement `xml:",any"` - StanzaErrorGroup -} diff --git a/messages/error_stanze.go b/messages/error_stanze.go new file mode 100644 index 0000000..7ba8ca6 --- /dev/null +++ b/messages/error_stanze.go @@ -0,0 +1,32 @@ +package messages + +import "encoding/xml" + +// RFC 6120 A.8 Resource binding namespace +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"` + + // Any hasn't matched element + Other []XMLElement `xml:",any"` +} diff --git a/messages/error_stream.go b/messages/error_stream.go new file mode 100644 index 0000000..2ed686e --- /dev/null +++ b/messages/error_stream.go @@ -0,0 +1,42 @@ +package messages + +import "encoding/xml" + +// RFC 6120 A.2 Stream Error Namespace +type StreamErrorGroup struct { + BadFormat *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams bad-format"` + BadNamespacePrefix *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams bad-namespace-prefix"` + Conflict *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams conflict"` + ConnectionTimeout *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams connection-timeout"` + HostGone *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams host-gone"` + HostUnknown *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams host-unknown"` + ImproperAddressing *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams improper-addressing"` + InternalServerError *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams internal-server-error"` + InvalidFrom *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams invalid-from"` + InvalidID *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams invalid-id"` + InvalidNamespace *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams invalid-namespace"` + InvalidXML *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams invalid-xml"` + NotAuthorized *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams not-authorized"` + NotWellFormed *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams not-well-formed"` + PolicyViolation *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams policy-violation"` + RemoteConnectionFailed *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams remote-connection-failed"` + Reset *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams reset"` + ResourceConstraint *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams resource-constraint"` + RestrictedXML *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams restricted-xml"` + SeeOtherHost string `xml:"urn:ietf:params:xml:ns:xmpp-streams see-other-host"` + SystemShutdown *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams system-shutdown"` + UndefinedCondition *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams undefined-condition"` + UnsupportedEncoding *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams unsupported-encoding"` + UnsupportedStanzaType *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams unsupported-stanza-type"` + UnsupportedVersion *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-streams unsupported-version"` +} + +// RFC 6120 A.2 Stream Error Namespace +type StreamError struct { + XMLName xml.Name `xml:"http://etherx.jabber.org/streams error"` + Text *Text + StreamErrorGroup + + // Any hasn't matched element + Other []XMLElement `xml:",any"` +} diff --git a/messages/global.go b/messages/global.go new file mode 100644 index 0000000..7b4aa28 --- /dev/null +++ b/messages/global.go @@ -0,0 +1,24 @@ +package messages + +import "encoding/xml" + +// RFC 6120 part of A.2 Stream Error Namespace, A.4 SASL Namespace and A.8 Stanza Error Namespace +type Text struct { + // `xml:"urn:ietf:params:xml:ns:xmpp-streams text"` + // `xml:"urn:ietf:params:xml:ns:xmpp-sasl text"` + // `xml:"urn:ietf:params:xml:ns:xmpp-stanzas text"` + XMLName xml.Name `xml:"text"` + Lang string `xml:"lang,attr,omitempty"` + Body string `xml:",innerxml"` +} + +// Fallback - any hasn't matched element +type XMLElement struct { + XMLName xml.Name + InnerXML string `xml:",innerxml"` +} + +// which XEP ? +type Delay struct { + Stamp string `xml:"stamp,attr"` +} diff --git a/messages/iq.go b/messages/iq.go deleted file mode 100644 index d1167d0..0000000 --- a/messages/iq.go +++ /dev/null @@ -1,48 +0,0 @@ -package messages - -import ( - "encoding/xml" - - "dev.sum7.eu/genofire/yaja/model" -) - -type IQType string - -const ( - IQTypeGet IQType = "get" - IQTypeSet IQType = "set" - IQTypeResult IQType = "result" - IQTypeError IQType = "error" -) - -// IQ element - info/query -type IQClient struct { - XMLName xml.Name `xml:"jabber:client iq"` - From *model.JID `xml:"from,attr"` - ID string `xml:"id,attr"` - To *model.JID `xml:"to,attr"` - Type IQType `xml:"type,attr"` - Error *ErrorClient `xml:"error"` - Bind *Bind - Ping *Ping - PrivateQuery *IQPrivateQuery - PrivateRegister *IQPrivateRegister - // Any hasn't matched element - Other []XMLElement `xml:",any"` -} - -type Ping struct { - XMLName xml.Name `xml:"urn:xmpp:ping ping"` -} - -type IQPrivateQuery struct { - XMLName xml.Name `xml:"jabber:iq:private query"` - Body []byte `xml:",innerxml"` -} - -type IQPrivateRegister struct { - XMLName xml.Name `xml:"jabber:iq:register query"` - Instructions string `xml:"instructions"` - Username string `xml:"username"` - Password string `xml:"password"` -} diff --git a/messages/iq_utils.go b/messages/iq_utils.go new file mode 100644 index 0000000..356f28b --- /dev/null +++ b/messages/iq_utils.go @@ -0,0 +1,25 @@ +package messages + +// which XEP ???? + +import ( + "encoding/xml" +) + +// where to put: (server part debug? is it part) + +type Ping struct { + XMLName xml.Name `xml:"urn:xmpp:ping ping"` +} + +type IQPrivateQuery struct { + XMLName xml.Name `xml:"jabber:iq:private query"` + Body []byte `xml:",innerxml"` +} + +type IQPrivateRegister struct { + XMLName xml.Name `xml:"jabber:iq:register query"` + Instructions string `xml:"instructions"` + Username string `xml:"username"` + Password string `xml:"password"` +} diff --git a/model/jid.go b/messages/jid.go similarity index 98% rename from model/jid.go rename to messages/jid.go index 4a693a0..0e4f2f8 100644 --- a/model/jid.go +++ b/messages/jid.go @@ -1,4 +1,4 @@ -package model +package messages import ( "errors" diff --git a/model/jid_test.go b/messages/jid_test.go similarity index 99% rename from model/jid_test.go rename to messages/jid_test.go index 1315f3d..7baae4f 100644 --- a/model/jid_test.go +++ b/messages/jid_test.go @@ -1,4 +1,4 @@ -package model +package messages import ( "testing" diff --git a/messages/message.go b/messages/message.go deleted file mode 100644 index 2fc27ac..0000000 --- a/messages/message.go +++ /dev/null @@ -1,35 +0,0 @@ -package messages - -import ( - "encoding/xml" - - "dev.sum7.eu/genofire/yaja/model" -) - -type MessageType string - -const ( - MessageTypeChat MessageType = "chat" - MessageTypeGroupchat MessageType = "groupchat" - MessageTypeError MessageType = "error" - MessageTypeHeadline MessageType = "headline" - MessageTypeNormal MessageType = "normal" -) - -// MessageClient element -type MessageClient struct { - XMLName xml.Name `xml:"jabber:client message"` - From *model.JID `xml:"from,attr,omitempty"` - ID string `xml:"id,attr,omitempty"` - To *model.JID `xml:"to,attr,omitempty"` - Type MessageType `xml:"type,attr,omitempty"` - Lang string `xml:"lang,attr,omitempty"` - Subject string `xml:"subject"` - Body string `xml:"body"` - Thread string `xml:"thread"` - // Any hasn't matched element - Other []XMLElement `xml:",any"` - - Delay *Delay `xml:"delay"` - Error *ErrorClient -} diff --git a/messages/namespaces.go b/messages/namespaces.go index 73cb3f7..c4613b3 100644 --- a/messages/namespaces.go +++ b/messages/namespaces.go @@ -1,17 +1,29 @@ package messages const ( - // NSStream stream namesapce + // RFC 6120 - A.1 Stream Namespace NSStream = "http://etherx.jabber.org/streams" - // NSTLS xmpp-tls xml namespace - NSTLS = "urn:ietf:params:xml:ns:xmpp-tls" - // NSSASL xmpp-sasl xml namespace + + // RFC 6120 - A.2 Stream Error Namespace + NSStreamError = "urn:ietf:params:xml:ns:xmpp-streams" + + // RFC 6120 - A.3 StartTLS Namespace + NSStartTLS = "urn:ietf:params:xml:ns:xmpp-tls" + + // RFC 6120 - A.4 SASL Namespace NSSASL = "urn:ietf:params:xml:ns:xmpp-sasl" + // RFC 6120 - A.5 Client Namespace + NSClient = "jabber:client" + + // RFC 6120 - A.6 Server Namespace + NSServer = "jabber:server" + + // RFC 6120 - A.7 Resource Binding Namespace NSBind = "urn:ietf:params:xml:ns:xmpp-bind" - // NSClient jabbet client namespace - NSClient = "jabber:client" + // RFC 6120 - A.8 Stanza Error Binding Namespace + NSStanzaError = "urn:ietf:params:xml:ns:xmpp-stanzas" NSIQRegister = "jabber:iq:register" diff --git a/messages/presence.go b/messages/presence.go deleted file mode 100644 index f9e324a..0000000 --- a/messages/presence.go +++ /dev/null @@ -1,46 +0,0 @@ -package messages - -import ( - "encoding/xml" - - "dev.sum7.eu/genofire/yaja/model" -) - -type PresenceType string - -const ( - PresenceTypeUnavailable PresenceType = "unavailable" - PresenceTypeSubscribe PresenceType = "subscribe" - PresenceTypeSubscribed PresenceType = "subscribed" - PresenceTypeUnsubscribe PresenceType = "unsubscribe" - PresenceTypeUnsubscribed PresenceType = "unsubscribed" - PresenceTypeProbe PresenceType = "probe" - PresenceTypeError PresenceType = "error" -) - -type PresenceShow string - -const ( - PresenceShowAway PresenceShow = "away" - PresenceShowChat PresenceShow = "chat" - PresenceShowDND PresenceShow = "dnd" - PresenceShowXA PresenceShow = "xa" -) - -// PresenceClient element -type PresenceClient struct { - XMLName xml.Name `xml:"jabber:client presence"` - From *model.JID `xml:"from,attr,omitempty"` - ID string `xml:"id,attr,omitempty"` - To *model.JID `xml:"to,attr,omitempty"` - Type PresenceType `xml:"type,attr,omitempty"` - Lang string `xml:"lang,attr,omitempty"` - - Show PresenceShow `xml:"show,omitempty"` // away, chat, dnd, xa - Status string `xml:"status,omitempty"` // sb []clientText - Priority string `xml:"priority,omitempty"` - // Caps *ClientCaps `xml:"c"` - Delay *Delay `xml:"delay"` - - Error *ErrorClient -} diff --git a/messages/roster.go b/messages/roster.go index ec240a1..4f26110 100644 --- a/messages/roster.go +++ b/messages/roster.go @@ -1,9 +1,9 @@ package messages +// which XEP ???? + import ( "encoding/xml" - - "dev.sum7.eu/genofire/yaja/model" ) type ClientQuery struct { @@ -11,9 +11,9 @@ type ClientQuery struct { } type RosterItem struct { - XMLName xml.Name `xml:"jabber:iq:roster item"` - JID *model.JID `xml:",attr"` - Name string `xml:",attr"` - Subscription string `xml:",attr"` + XMLName xml.Name `xml:"jabber:iq:roster item"` + JID *JID `xml:",attr"` + Name string `xml:",attr"` + Subscription string `xml:",attr"` Group []string } diff --git a/messages/sasl.go b/messages/sasl.go index 04edc7f..9de4c8f 100644 --- a/messages/sasl.go +++ b/messages/sasl.go @@ -4,7 +4,7 @@ import ( "encoding/xml" ) -// RFC 3920 C.4 SASL name space +// RFC 6120 - A.4 SASL Namespace type SASLMechanisms struct { XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl mechanisms"` Mechanism []string `xml:"mechanism"` @@ -40,7 +40,7 @@ type SASLAbout struct { XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl abort"` } -// SASLFailure element +// RFC 6120 - A.4 SASL Namespace type SASLFailure struct { XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl failure"` @@ -56,5 +56,5 @@ type SASLFailure struct { NotAuthorized *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl not-authorized"` TemporaryAuthFailure *xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl temporary-auth-failure"` - Body string `xml:",chardata"` + Text *Text } diff --git a/messages/server_error.go b/messages/server_error.go new file mode 100644 index 0000000..4db6b50 --- /dev/null +++ b/messages/server_error.go @@ -0,0 +1,17 @@ +package messages + +import "encoding/xml" + +// RFC 6120 - A.6 Server Namespace (a part) +type ErrorServer struct { + XMLName xml.Name `xml:"jabber:server error"` + Code string `xml:"code,attr,omitempty"` + Type ErrorType `xml:"type,attr"` // required + Text *Text + + // RFC 6120 A.8 Resource binding namespace + StanzaErrorGroup + + // Any hasn't matched element + Other []XMLElement `xml:",any"` +} diff --git a/messages/server_iq.go b/messages/server_iq.go new file mode 100644 index 0000000..5a3c086 --- /dev/null +++ b/messages/server_iq.go @@ -0,0 +1,23 @@ +package messages + +import ( + "encoding/xml" +) + +// RFC 6120 - A.6 Server Namespace (a part) +type IQServer struct { + XMLName xml.Name `xml:"jabber:server iq"` + From *JID `xml:"from,attr,omitempty"` + ID string `xml:"id,attr"` // required + To *JID `xml:"to,attr"` // required + Type IQType `xml:"type,attr"` // required + Error *ErrorServer + + Bind *Bind // which XEP ? + Ping *Ping // which XEP ? + PrivateQuery *IQPrivateQuery // which XEP ? + PrivateRegister *IQPrivateRegister // which XEP ? + + // Any hasn't matched element + Other []XMLElement `xml:",any"` +} diff --git a/messages/server_message.go b/messages/server_message.go new file mode 100644 index 0000000..a878479 --- /dev/null +++ b/messages/server_message.go @@ -0,0 +1,25 @@ +package messages + +import ( + "encoding/xml" +) + +// RFC 6120 - A.6 Server Namespace (a part) +type MessageServer struct { + XMLName xml.Name `xml:"jabber:server message"` + From *JID `xml:"from,attr"` // required + ID string `xml:"id,attr,omitempty"` + To *JID `xml:"to,attr"` // required + Type MessageType `xml:"type,attr,omitempty"` // default: normal + Lang string `xml:"lang,attr,omitempty"` + + Subject string `xml:"subject,omitempty"` + Body string `xml:"body,omitempty"` + Thread string `xml:"thread,omitempty"` + Error *ErrorServer + + Delay *Delay `xml:"delay"` // which XEP ? + + // Any hasn't matched element + Other []XMLElement `xml:",any"` +} diff --git a/messages/server_presence.go b/messages/server_presence.go new file mode 100644 index 0000000..9f83d3c --- /dev/null +++ b/messages/server_presence.go @@ -0,0 +1,29 @@ +package messages + +import ( + "encoding/xml" +) + +// RFC 6120 - A.6 Server Namespace (a part) +type PresenceServer struct { + XMLName xml.Name `xml:"jabber:server presence"` + From *JID `xml:"from,attr"` // required + ID string `xml:"id,attr,omitempty"` + To *JID `xml:"to,attr"` // required + Type PresenceType `xml:"type,attr,omitempty"` + Lang string `xml:"lang,attr,omitempty"` + + Show PresenceShow `xml:"show,omitempty"` + Status string `xml:"status,omitempty"` + Priority uint `xml:"priority,omitempty"` // default: 0 + + Error *ErrorServer + + Delay *Delay `xml:"delay"` // which XEP ? + + // which XEP ? + // Caps *ClientCaps `xml:"c"` + + // Any hasn't matched element + Other []XMLElement `xml:",any"` +} diff --git a/messages/utils.go b/messages/utils.go index ffa0e47..645fd31 100644 --- a/messages/utils.go +++ b/messages/utils.go @@ -8,15 +8,6 @@ import ( "reflect" ) -type Delay struct { - Stamp string `xml:"stamp,attr"` -} - -type XMLElement struct { - XMLName xml.Name - InnerXML string `xml:",innerxml"` -} - func XMLStartElementToString(element *xml.StartElement) string { if element == nil { return "" diff --git a/model/account.go b/model/account.go index 6652b4e..ec5d802 100644 --- a/model/account.go +++ b/model/account.go @@ -3,6 +3,8 @@ package model import ( "errors" "sync" + + "dev.sum7.eu/genofire/yaja/messages" ) type Domain struct { @@ -11,8 +13,8 @@ type Domain struct { sync.Mutex } -func (d *Domain) GetJID() *JID { - return &JID{ +func (d *Domain) GetJID() *messages.JID { + return &messages.JID{ Domain: d.FQDN, } } @@ -36,7 +38,7 @@ type Account struct { Bookmarks map[string]*Bookmark `json:"bookmarks"` } -func NewAccount(jid *JID, password string) *Account { +func NewAccount(jid *messages.JID, password string) *Account { if jid == nil { return nil } @@ -49,8 +51,8 @@ func NewAccount(jid *JID, password string) *Account { } } -func (a *Account) GetJID() *JID { - return &JID{ +func (a *Account) GetJID() *messages.JID { + return &messages.JID{ Domain: a.Domain.FQDN, Local: a.Local, } diff --git a/server/extension/iq_disco.bak b/server/extension/iq_disco.bak index f548d45..d776765 100644 --- a/server/extension/iq_disco.bak +++ b/server/extension/iq_disco.bak @@ -61,7 +61,7 @@ func (ex *IQDisco) Get(msg *messages.IQClient, client *utils.Client) bool { client.Messages <- &messages.IQClient{ Type: messages.IQTypeResult, To: client.JID, - From: model.NewJID(client.JID.Domain), + From: messages.NewJID(client.JID.Domain), ID: msg.ID, Body: queryByte, } diff --git a/server/extension/iq_discovery.bak b/server/extension/iq_discovery.bak index 60ff323..4588731 100644 --- a/server/extension/iq_discovery.bak +++ b/server/extension/iq_discovery.bak @@ -61,7 +61,7 @@ func (ex *IQExtensionDiscovery) Get(msg *messages.IQClient, client *utils.Client client.Messages <- &messages.IQClient{ Type: messages.IQTypeResult, To: client.JID, - From: model.NewJID(client.JID.Domain), + From: messages.NewJID(client.JID.Domain), ID: msg.ID, Body: queryByte, } diff --git a/server/extension/iq_last.bak b/server/extension/iq_last.bak index 9cddba8..bb0acfe 100644 --- a/server/extension/iq_last.bak +++ b/server/extension/iq_last.bak @@ -49,7 +49,7 @@ func (ex *IQLast) Get(msg *messages.IQClient, client *utils.Client) bool { client.Messages <- &messages.IQClient{ Type: messages.IQTypeResult, To: client.JID, - From: model.NewJID(client.JID.Domain), + From: messages.NewJID(client.JID.Domain), ID: msg.ID, Body: queryByte, } diff --git a/server/extension/iq_ping.go b/server/extension/iq_ping.go index e589835..7f49ec2 100644 --- a/server/extension/iq_ping.go +++ b/server/extension/iq_ping.go @@ -2,7 +2,6 @@ package extension import ( "dev.sum7.eu/genofire/yaja/messages" - "dev.sum7.eu/genofire/yaja/model" "dev.sum7.eu/genofire/yaja/server/utils" ) @@ -23,7 +22,7 @@ func (ex *IQPing) Get(msg *messages.IQClient, client *utils.Client) bool { client.Messages <- &messages.IQClient{ Type: messages.IQTypeResult, To: client.JID, - From: model.NewJID(client.JID.Domain), + From: messages.NewJID(client.JID.Domain), ID: msg.ID, } diff --git a/server/extension/iq_private_bookmarks.bak b/server/extension/iq_private_bookmarks.bak index b5ac095..0374a39 100644 --- a/server/extension/iq_private_bookmarks.bak +++ b/server/extension/iq_private_bookmarks.bak @@ -39,7 +39,7 @@ func (ex *IQPrivateBookmark) Handle(msg *messages.IQClient, client *utils.Client client.Messages <- &messages.IQClient{ Type: messages.IQTypeResult, To: client.JID, - From: model.NewJID(client.JID.Domain), + From: messages.NewJID(client.JID.Domain), ID: msg.ID, Body: queryByte, } diff --git a/server/extension/iq_private_metacontacts.bak b/server/extension/iq_private_metacontacts.bak index b8db2ff..9d830a1 100644 --- a/server/extension/iq_private_metacontacts.bak +++ b/server/extension/iq_private_metacontacts.bak @@ -40,7 +40,7 @@ func (ex *IQPrivateMetacontact) Handle(msg *messages.IQClient, client *utils.Cli client.Messages <- &messages.IQClient{ Type: messages.IQTypeResult, To: client.JID, - From: model.NewJID(client.JID.Domain), + From: messages.NewJID(client.JID.Domain), ID: msg.ID, Body: queryByte, } diff --git a/server/extension/iq_private_roster.bak b/server/extension/iq_private_roster.bak index 2e13ca5..967dc8c 100644 --- a/server/extension/iq_private_roster.bak +++ b/server/extension/iq_private_roster.bak @@ -44,7 +44,7 @@ func (ex *IQPrivateRoster) Handle(msg *messages.IQClient, client *utils.Client) client.Messages <- &messages.IQClient{ Type: messages.IQTypeResult, To: client.JID, - From: model.NewJID(client.JID.Domain), + From: messages.NewJID(client.JID.Domain), ID: msg.ID, Body: queryByte, } diff --git a/server/server.go b/server/server.go index cab6d54..f62e390 100644 --- a/server/server.go +++ b/server/server.go @@ -5,7 +5,7 @@ import ( "net" "dev.sum7.eu/genofire/yaja/database" - "dev.sum7.eu/genofire/yaja/model" + "dev.sum7.eu/genofire/yaja/messages" "dev.sum7.eu/genofire/yaja/server/extension" "dev.sum7.eu/genofire/yaja/server/toclient" "dev.sum7.eu/genofire/yaja/server/toserver" @@ -109,7 +109,7 @@ func (srv *Server) handleClient(conn net.Conn) { } } -func (srv *Server) DomainRegisterAllowed(jid *model.JID) bool { +func (srv *Server) DomainRegisterAllowed(jid *messages.JID) bool { if jid.Domain == "" { return false } diff --git a/server/state/connect.go b/server/state/connect.go index a75681f..98f91c0 100644 --- a/server/state/connect.go +++ b/server/state/connect.go @@ -5,7 +5,6 @@ import ( "fmt" "dev.sum7.eu/genofire/yaja/messages" - "dev.sum7.eu/genofire/yaja/model" "dev.sum7.eu/genofire/yaja/server/utils" "golang.org/x/crypto/acme/autocert" ) @@ -33,7 +32,7 @@ func (state *Start) Process() State { } for _, attr := range element.Attr { if attr.Name.Local == "to" { - state.Client.JID = &model.JID{Domain: attr.Value} + state.Client.JID = &messages.JID{Domain: attr.Value} state.Client.Log = state.Client.Log.WithField("jid", state.Client.JID.Full()) } } @@ -75,11 +74,11 @@ func (state *TLSUpgrade) Process() State { state.Client.Log.Warn("unable to read: ", err) return nil } - if element.Name.Space != messages.NSTLS || element.Name.Local != "starttls" { + if element.Name.Space != messages.NSStartTLS || element.Name.Local != "starttls" { state.Client.Log.Warn("is no starttls", element) return nil } - fmt.Fprintf(state.Client.Conn, "", messages.NSTLS) + fmt.Fprintf(state.Client.Conn, "", messages.NSStartTLS) // perform the TLS handshake var tlsConfig *tls.Config if m := state.TLSManager; m != nil { diff --git a/server/toclient/connect.go b/server/toclient/connect.go index 7f9d0ca..f00d447 100644 --- a/server/toclient/connect.go +++ b/server/toclient/connect.go @@ -8,7 +8,6 @@ import ( "dev.sum7.eu/genofire/yaja/database" "dev.sum7.eu/genofire/yaja/messages" - "dev.sum7.eu/genofire/yaja/model" "dev.sum7.eu/genofire/yaja/server/extension" "dev.sum7.eu/genofire/yaja/server/state" "dev.sum7.eu/genofire/yaja/server/utils" @@ -226,7 +225,7 @@ func (state *AuthedStream) Process() state.State { state.Client.Out.Encode(&messages.IQClient{ Type: messages.IQTypeResult, To: state.Client.JID, - From: model.NewJID(state.Client.JID.Domain), + From: messages.NewJID(state.Client.JID.Domain), ID: msg.ID, Bind: &messages.Bind{JID: state.Client.JID}, }) diff --git a/server/toclient/register.go b/server/toclient/register.go index 1703d1c..cb9bbbc 100644 --- a/server/toclient/register.go +++ b/server/toclient/register.go @@ -49,7 +49,7 @@ func (state *RegisterFormRequest) Process() state.State { state.Client.Out.Encode(&messages.IQClient{ Type: messages.IQTypeResult, To: state.Client.JID, - From: model.NewJID(state.Client.JID.Domain), + From: messages.NewJID(state.Client.JID.Domain), ID: msg.ID, PrivateRegister: &messages.IQPrivateRegister{ Instructions: "Choose a username and password for use with this service.", @@ -109,7 +109,7 @@ func (state *RegisterRequest) Process() state.State { state.Client.Out.Encode(&messages.IQClient{ Type: messages.IQTypeResult, To: state.Client.JID, - From: model.NewJID(state.Client.JID.Domain), + From: messages.NewJID(state.Client.JID.Domain), ID: msg.ID, PrivateRegister: msg.PrivateRegister, Error: &messages.ErrorClient{ @@ -126,7 +126,7 @@ func (state *RegisterRequest) Process() state.State { state.Client.Out.Encode(&messages.IQClient{ Type: messages.IQTypeResult, To: state.Client.JID, - From: model.NewJID(state.Client.JID.Domain), + From: messages.NewJID(state.Client.JID.Domain), ID: msg.ID, }) diff --git a/server/utils/client.go b/server/utils/client.go index 479a1dc..e484359 100644 --- a/server/utils/client.go +++ b/server/utils/client.go @@ -4,6 +4,7 @@ import ( "encoding/xml" "net" + "dev.sum7.eu/genofire/yaja/messages" "dev.sum7.eu/genofire/yaja/model" log "github.com/sirupsen/logrus" ) @@ -15,7 +16,7 @@ type Client struct { Out *xml.Encoder In *xml.Decoder - JID *model.JID + JID *messages.JID account *model.Account Messages chan interface{} diff --git a/server/utils/main.go b/server/utils/main.go index c602c1f..94b5ef3 100644 --- a/server/utils/main.go +++ b/server/utils/main.go @@ -1,7 +1,5 @@ package utils -import ( - "dev.sum7.eu/genofire/yaja/model" -) +import "dev.sum7.eu/genofire/yaja/messages" -type DomainRegisterAllowed func(*model.JID) bool +type DomainRegisterAllowed func(*messages.JID) bool