From 1be04b0fba234c1ccd3b1854dc643fea8a05493d Mon Sep 17 00:00:00 2001 From: Mickael Remond Date: Fri, 7 Jun 2019 15:56:41 +0200 Subject: [PATCH] Expose JID fields and rename to match XEP-0029 wording See: XEP-0029 - Definition of Jabber Identifiers (JIDs) https://xmpp.org/extensions/xep-0029.html --- jid.go | 24 ++++++++++++------------ jid_test.go | 12 ++++++------ session.go | 10 +++++----- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/jid.go b/jid.go index e025911..05f7274 100644 --- a/jid.go +++ b/jid.go @@ -7,9 +7,9 @@ import ( ) type Jid struct { - username string - domain string - resource string + Node string + Domain string + Resource string } func NewJid(sjid string) (*Jid, error) { @@ -21,29 +21,29 @@ func NewJid(sjid string) (*Jid, error) { s1 := strings.SplitN(sjid, "@", 2) if len(s1) == 1 { // This is a server or component JID - jid.domain = s1[0] + jid.Domain = s1[0] } else { // JID has a local username part if s1[0] == "" { return jid, fmt.Errorf("invalid jid '%s", sjid) } - jid.username = s1[0] + jid.Node = s1[0] if s1[1] == "" { return jid, fmt.Errorf("domain cannot be empty") } - jid.domain = s1[1] + jid.Domain = s1[1] } // Extract resource from domain field - s2 := strings.SplitN(jid.domain, "/", 2) + s2 := strings.SplitN(jid.Domain, "/", 2) if len(s2) == 2 { // If len = 1, domain is already correct, and resource is already empty - jid.domain = s2[0] - jid.resource = s2[1] + jid.Domain = s2[0] + jid.Resource = s2[1] } - if !isUsernameValid(jid.username) { - return jid, fmt.Errorf("invalid username in JID '%s'", sjid) + if !isUsernameValid(jid.Node) { + return jid, fmt.Errorf("invalid Node in JID '%s'", sjid) } - if !isDomainValid(jid.domain) { + if !isDomainValid(jid.Domain) { return jid, fmt.Errorf("invalid domain in JID '%s'", sjid) } diff --git a/jid_test.go b/jid_test.go index 4b27de4..64efdd5 100644 --- a/jid_test.go +++ b/jid_test.go @@ -28,16 +28,16 @@ func TestValidJids(t *testing.T) { t.Error("jid should not be nil") } - if jid.username != tt.expected.username { - t.Errorf("incorrect jid username (%s): %s", tt.expected.username, jid.username) + if jid.Node != tt.expected.Node { + t.Errorf("incorrect jid Node (%s): %s", tt.expected.Node, jid.Node) } - if jid.username != tt.expected.username { - t.Errorf("incorrect jid domain (%s): %s", tt.expected.domain, jid.domain) + if jid.Node != tt.expected.Node { + t.Errorf("incorrect jid domain (%s): %s", tt.expected.Domain, jid.Domain) } - if jid.resource != tt.expected.resource { - t.Errorf("incorrect jid resource (%s): %s", tt.expected.resource, jid.resource) + if jid.Resource != tt.expected.Resource { + t.Errorf("incorrect jid resource (%s): %s", tt.expected.Resource, jid.Resource) } } } diff --git a/session.go b/session.go index fd31f1a..0c0b278 100644 --- a/session.go +++ b/session.go @@ -37,7 +37,7 @@ func NewSession(conn net.Conn, o Config) (net.Conn, *Session, error) { // starttls var tlsConn net.Conn - tlsConn = s.startTlsIfSupported(conn, o.parsedJid.domain) + tlsConn = s.startTlsIfSupported(conn, o.parsedJid.Domain) if s.TlsEnabled { s.reset(conn, tlsConn, o) } @@ -64,7 +64,7 @@ func (s *Session) PacketId() string { func (s *Session) init(conn net.Conn, o Config) { s.setProxy(nil, conn, o) - s.Features = s.open(o.parsedJid.domain) + s.Features = s.open(o.parsedJid.Domain) } func (s *Session) reset(conn net.Conn, newConn net.Conn, o Config) { @@ -73,7 +73,7 @@ func (s *Session) reset(conn net.Conn, newConn net.Conn, o Config) { } s.setProxy(conn, newConn, o) - s.Features = s.open(o.parsedJid.domain) + s.Features = s.open(o.parsedJid.Domain) } // TODO: setProxyLogger ? better name ? This is not a TCP / HTTP proxy @@ -141,7 +141,7 @@ func (s *Session) auth(o Config) { return } - s.err = authSASL(s.socketProxy, s.decoder, s.Features, o.parsedJid.username, o.Password) + s.err = authSASL(s.socketProxy, s.decoder, s.Features, o.parsedJid.Node, o.Password) } func (s *Session) bind(o Config) { @@ -150,7 +150,7 @@ func (s *Session) bind(o Config) { } // Send IQ message asking to bind to the local user name. - var resource = o.parsedJid.resource + var resource = o.parsedJid.Resource if resource != "" { fmt.Fprintf(s.socketProxy, "%s", s.PacketId(), nsBind, resource)