diff options
-rw-r--r-- | xmpp/message.go | 17 | ||||
-rw-r--r-- | xmpp/routing.go | 4 |
2 files changed, 21 insertions, 0 deletions
diff --git a/xmpp/message.go b/xmpp/message.go new file mode 100644 index 0000000..58dc657 --- /dev/null +++ b/xmpp/message.go @@ -0,0 +1,17 @@ +package xmpp + +import ( + "log" +) + +type message struct { + Type string `xml:"type,attr"` + From string `xml:"from,attr"` + Body string `xml:"body"` +} + +func handleMessage(s *session, m message) { + if m.Type == "chat" { + log.Printf("Got message '%s' from '%s'.\n", m.Body, m.From) + } +} diff --git a/xmpp/routing.go b/xmpp/routing.go index 5cd2040..2f2347a 100644 --- a/xmpp/routing.go +++ b/xmpp/routing.go @@ -13,6 +13,8 @@ func route(s *xml.StartElement, d *xml.Decoder, c chan<- any) { parse(saslSuccess{}, s, d, c) case xml.Name{`jabber:client`, `iq`}: parse(iqResponse{}, s, d, c) + case xml.Name{`jabber:client`, `message`}: + parse(message{}, s, d, c) default: d.Skip() } @@ -35,6 +37,8 @@ func handle(s *session, element any) { handleSaslSuccess(s) case iqResponse: handleIqResponse(s, t) + case message: + handleMessage(s, t) default: log.Printf("Unknown parsed element: %v", t) } |