summaryrefslogtreecommitdiff
path: root/xmpp/xmpp.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-05-22 22:00:22 +0200
committerxengineering <me@xengineering.eu>2023-05-22 22:00:22 +0200
commit191acba6587b766770cc2bf1d3ff2bc699cb668d (patch)
treeed1e9db69a0f8b4f7900d5608e26752e4461ef28 /xmpp/xmpp.go
parentdde404aeefacdbb3d62187544a409cf9cef71258 (diff)
downloadlimox-191acba6587b766770cc2bf1d3ff2bc699cb668d.tar
limox-191acba6587b766770cc2bf1d3ff2bc699cb668d.tar.zst
limox-191acba6587b766770cc2bf1d3ff2bc699cb668d.zip
Rename xmpp/xmpp.go -> xmpp/conn.go
Diffstat (limited to 'xmpp/xmpp.go')
-rw-r--r--xmpp/xmpp.go96
1 files changed, 0 insertions, 96 deletions
diff --git a/xmpp/xmpp.go b/xmpp/xmpp.go
deleted file mode 100644
index f017889..0000000
--- a/xmpp/xmpp.go
+++ /dev/null
@@ -1,96 +0,0 @@
-package xmpp
-
-import (
- "crypto/tls"
- "crypto/x509"
- "log"
-)
-
-type Event uint8
-
-const (
- DisconnectEvent Event = iota
- ConnectEvent
- ShouldDisconnectEvent
-)
-
-type Conn struct {
- ch chan Event
- jid, pwd string
- tcp *tls.Conn
- enc encoder
-}
-
-func NewConn(ch chan Event, jid string, pwd string) *Conn {
- c := Conn{
- ch: ch,
- jid: jid,
- pwd: pwd}
-
- return &c
-}
-
-func (c *Conn) Connect() error {
- var err error
-
- domain := domainpart(c.jid)
-
- roots, err := x509.SystemCertPool()
- if err != nil {
- log.Println(err)
- return err
- }
-
- c.tcp, err = tls.Dial("tcp", domain+":"+"5223", &tls.Config{RootCAs: roots})
- if err != nil {
- log.Println(err)
- return err
- }
-
- return nil
-}
-
-func (c *Conn) Disconnect() {
- c.tcp.Close()
-}
-
-func (c *Conn) Run() {
- err := c.Connect()
- if err != nil {
- return
- }
- defer c.Disconnect()
-
- decoder := newDecoder(c.tcp)
- go decoder.run()
- defer decoder.stop()
-
- c.enc = newEncoder(c.tcp)
- defer c.enc.Close()
-
- tr := newTokenRouter()
-
- end := sendStreamStart(&c.enc, c.jid)
- defer sendStreamEnd(&c.enc, end)
-
- c.ch <- ConnectEvent
- defer func() { c.ch <- DisconnectEvent }()
-
- for {
- select {
- case ev := <-c.ch:
- switch ev {
- case ShouldDisconnectEvent:
- return
- default:
- log.Printf("Unknown Event '%d'!\n", ev)
- }
- case token := <-decoder.data:
- err = tr.route(token, c)
- if err != nil {
- log.Println(err)
- return
- }
- }
- }
-}