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
disco_info_form
Mickael Remond 5 years ago
parent 269f78b30d
commit 1be04b0fba
No known key found for this signature in database
GPG Key ID: E6F6045D79965AA3

@ -7,9 +7,9 @@ import (
) )
type Jid struct { type Jid struct {
username string Node string
domain string Domain string
resource string Resource string
} }
func NewJid(sjid string) (*Jid, error) { func NewJid(sjid string) (*Jid, error) {
@ -21,29 +21,29 @@ func NewJid(sjid string) (*Jid, error) {
s1 := strings.SplitN(sjid, "@", 2) s1 := strings.SplitN(sjid, "@", 2)
if len(s1) == 1 { // This is a server or component JID 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 } else { // JID has a local username part
if s1[0] == "" { if s1[0] == "" {
return jid, fmt.Errorf("invalid jid '%s", sjid) return jid, fmt.Errorf("invalid jid '%s", sjid)
} }
jid.username = s1[0] jid.Node = s1[0]
if s1[1] == "" { if s1[1] == "" {
return jid, fmt.Errorf("domain cannot be empty") return jid, fmt.Errorf("domain cannot be empty")
} }
jid.domain = s1[1] jid.Domain = s1[1]
} }
// Extract resource from domain field // 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 if len(s2) == 2 { // If len = 1, domain is already correct, and resource is already empty
jid.domain = s2[0] jid.Domain = s2[0]
jid.resource = s2[1] jid.Resource = s2[1]
} }
if !isUsernameValid(jid.username) { if !isUsernameValid(jid.Node) {
return jid, fmt.Errorf("invalid username in JID '%s'", sjid) 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) return jid, fmt.Errorf("invalid domain in JID '%s'", sjid)
} }

@ -28,16 +28,16 @@ func TestValidJids(t *testing.T) {
t.Error("jid should not be nil") t.Error("jid should not be nil")
} }
if jid.username != tt.expected.username { if jid.Node != tt.expected.Node {
t.Errorf("incorrect jid username (%s): %s", tt.expected.username, jid.username) t.Errorf("incorrect jid Node (%s): %s", tt.expected.Node, jid.Node)
} }
if jid.username != tt.expected.username { if jid.Node != tt.expected.Node {
t.Errorf("incorrect jid domain (%s): %s", tt.expected.domain, jid.domain) t.Errorf("incorrect jid domain (%s): %s", tt.expected.Domain, jid.Domain)
} }
if jid.resource != tt.expected.resource { if jid.Resource != tt.expected.Resource {
t.Errorf("incorrect jid resource (%s): %s", tt.expected.resource, jid.resource) t.Errorf("incorrect jid resource (%s): %s", tt.expected.Resource, jid.Resource)
} }
} }
} }

@ -37,7 +37,7 @@ func NewSession(conn net.Conn, o Config) (net.Conn, *Session, error) {
// starttls // starttls
var tlsConn net.Conn var tlsConn net.Conn
tlsConn = s.startTlsIfSupported(conn, o.parsedJid.domain) tlsConn = s.startTlsIfSupported(conn, o.parsedJid.Domain)
if s.TlsEnabled { if s.TlsEnabled {
s.reset(conn, tlsConn, o) s.reset(conn, tlsConn, o)
} }
@ -64,7 +64,7 @@ func (s *Session) PacketId() string {
func (s *Session) init(conn net.Conn, o Config) { func (s *Session) init(conn net.Conn, o Config) {
s.setProxy(nil, conn, o) 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) { 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.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 // TODO: setProxyLogger ? better name ? This is not a TCP / HTTP proxy
@ -141,7 +141,7 @@ func (s *Session) auth(o Config) {
return 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) { 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. // Send IQ message asking to bind to the local user name.
var resource = o.parsedJid.resource var resource = o.parsedJid.Resource
if resource != "" { if resource != "" {
fmt.Fprintf(s.socketProxy, "<iq type='set' id='%s'><bind xmlns='%s'><resource>%s</resource></bind></iq>", fmt.Fprintf(s.socketProxy, "<iq type='set' id='%s'><bind xmlns='%s'><resource>%s</resource></bind></iq>",
s.PacketId(), nsBind, resource) s.PacketId(), nsBind, resource)

Loading…
Cancel
Save