From a2af6617175d95fa4937b8aa38ed0bfc955085a8 Mon Sep 17 00:00:00 2001 From: xengineering Date: Sat, 15 Apr 2023 22:44:44 +0200 Subject: Implement domain part extraction in Go This is needed to continue with DNS resolution. --- go/main.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'go/main.go') diff --git a/go/main.go b/go/main.go index 18f2105..8bfb1fa 100644 --- a/go/main.go +++ b/go/main.go @@ -79,6 +79,7 @@ func (l *Limox) buttonCallback() { switch l.State { case Disconnected: log.Println("Starting connection establishment") + go xmpp(l.JidEditor.Text(), l.PwdEditor.Text()) l.State = Connecting case Connecting: log.Println("Aborted connection establishment") @@ -89,6 +90,35 @@ func (l *Limox) buttonCallback() { } } +func xmpp(jid string, pwd string) { + log.Printf("JID: '%s' PWD: '%s'\n", jid, pwd) + log.Printf("Domain: '%s'\n", domainpart(jid)) +} + +// domainpart extracts the domain name from a JID / XMPP address. See +// https://datatracker.ietf.org/doc/html/rfc7622#section-3.2 for details. +func domainpart(jid string) string { + list := []rune(jid) + + for i, v := range(list) { + if v == '/' { + log.Printf("Index of / rune: %d\n", i) + list = list[:i] + break + } + } + + for i, v := range(list) { + if v == '@' { + log.Printf("Index of @ rune: %d\n", i) + list = list[i+1:] + break + } + } + + return string(list) +} + func (l *Limox) draw(e system.FrameEvent) { gtx := layout.NewContext(&l.Operations, e) -- cgit v1.2.3-70-g09d2