Compare commits
2 commits
disco_info
...
160-regres
Author | SHA1 | Date | |
---|---|---|---|
Bohdan Horbeshko | e55463fc98 | ||
5f99e1cd06 |
|
@ -51,11 +51,21 @@ func NewJid(sjid string) (*Jid, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Jid) Full() string {
|
func (j *Jid) Full() string {
|
||||||
return j.Node + "@" + j.Domain + "/" + j.Resource
|
if j.Resource == "" {
|
||||||
|
return j.Bare()
|
||||||
|
} else if j.Node == "" {
|
||||||
|
return j.Node + "/" + j.Resource
|
||||||
|
} else {
|
||||||
|
return j.Node + "@" + j.Domain + "/" + j.Resource
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Jid) Bare() string {
|
func (j *Jid) Bare() string {
|
||||||
return j.Node + "@" + j.Domain
|
if j.Node == "" {
|
||||||
|
return j.Domain
|
||||||
|
} else {
|
||||||
|
return j.Node + "@" + j.Domain
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
|
@ -61,26 +61,41 @@ func TestIncorrectJids(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFull(t *testing.T) {
|
func TestFull(t *testing.T) {
|
||||||
jid := "test@domain.com/my resource"
|
fullJids := []string{
|
||||||
parsedJid, err := NewJid(jid)
|
"test@domain.com/my resource",
|
||||||
if err != nil {
|
"test@domain.com",
|
||||||
t.Errorf("could not parse jid: %v", err)
|
"domain.com",
|
||||||
}
|
}
|
||||||
fullJid := parsedJid.Full()
|
for _, sjid := range fullJids {
|
||||||
if fullJid != jid {
|
parsedJid, err := NewJid(sjid)
|
||||||
t.Errorf("incorrect full jid: %s", fullJid)
|
if err != nil {
|
||||||
|
t.Errorf("could not parse jid: %v", err)
|
||||||
|
}
|
||||||
|
fullJid := parsedJid.Full()
|
||||||
|
if fullJid != sjid {
|
||||||
|
t.Errorf("incorrect full jid: %s", fullJid)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBare(t *testing.T) {
|
func TestBare(t *testing.T) {
|
||||||
jid := "test@domain.com"
|
tests := []struct {
|
||||||
fullJid := jid + "/my resource"
|
jidstr string
|
||||||
parsedJid, err := NewJid(fullJid)
|
expected string
|
||||||
if err != nil {
|
}{
|
||||||
t.Errorf("could not parse jid: %v", err)
|
{jidstr: "test@domain.com", expected: "test@domain.com"},
|
||||||
|
{jidstr: "test@domain.com/resource", expected: "test@domain.com"},
|
||||||
|
{jidstr: "domain.com", expected: "domain.com"},
|
||||||
}
|
}
|
||||||
bareJid := parsedJid.Bare()
|
|
||||||
if bareJid != jid {
|
for _, tt := range tests {
|
||||||
t.Errorf("incorrect bare jid: %s", bareJid)
|
parsedJid, err := NewJid(tt.jidstr)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("could not parse jid: %v", err)
|
||||||
|
}
|
||||||
|
bareJid := parsedJid.Bare()
|
||||||
|
if bareJid != tt.expected {
|
||||||
|
t.Errorf("incorrect bare jid: %s", bareJid)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,18 +114,23 @@ func (sm *StreamManager) Stop() {
|
||||||
|
|
||||||
func (sm *StreamManager) connect() error {
|
func (sm *StreamManager) connect() error {
|
||||||
if sm.client != nil {
|
if sm.client != nil {
|
||||||
if c, ok := sm.client.(*Client); ok {
|
var scs *SyncConnState
|
||||||
if c.CurrentState.getState() == StateDisconnected {
|
if client, ok := sm.client.(*Client); ok {
|
||||||
sm.Metrics = initMetrics()
|
scs = &client.CurrentState
|
||||||
err := c.Connect()
|
}
|
||||||
if err != nil {
|
if component, ok := sm.client.(*Component); ok {
|
||||||
return err
|
scs = &component.CurrentState
|
||||||
}
|
}
|
||||||
if sm.PostConnect != nil {
|
if scs != nil && scs.getState() == StateDisconnected {
|
||||||
sm.PostConnect(sm.client)
|
sm.Metrics = initMetrics()
|
||||||
}
|
err := sm.client.Connect()
|
||||||
return nil
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
if sm.PostConnect != nil {
|
||||||
|
sm.PostConnect(sm.client)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return errors.New("client is not disconnected")
|
return errors.New("client is not disconnected")
|
||||||
|
|
Loading…
Reference in a new issue