improve use bind of stream start + logging
This commit is contained in:
parent
3c13b83657
commit
940d328b09
|
@ -86,7 +86,7 @@ func (client *Client) auth(password string) error {
|
||||||
if mechanism == "" {
|
if mechanism == "" {
|
||||||
return fmt.Errorf("PLAIN authentication is not an option: %s", f.Mechanisms.Mechanism)
|
return fmt.Errorf("PLAIN authentication is not an option: %s", f.Mechanisms.Mechanism)
|
||||||
}
|
}
|
||||||
client.Logging.Info("used auth with '%s'", mechanism)
|
client.Logging.Infof("used auth with '%s'", mechanism)
|
||||||
|
|
||||||
element, err := client.Read()
|
element, err := client.Read()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -42,8 +42,14 @@ func (client *Client) startStream() (*messages.StreamFeatures, error) {
|
||||||
debug += " tls"
|
debug += " tls"
|
||||||
}
|
}
|
||||||
debug += " mechanism("
|
debug += " mechanism("
|
||||||
|
mFirst := true
|
||||||
for _, m := range f.Mechanisms.Mechanism {
|
for _, m := range f.Mechanisms.Mechanism {
|
||||||
|
if mFirst {
|
||||||
|
mFirst = false
|
||||||
debug += m
|
debug += m
|
||||||
|
} else {
|
||||||
|
debug += ", " + m
|
||||||
|
}
|
||||||
}
|
}
|
||||||
debug += ")"
|
debug += ")"
|
||||||
if f.Bind != nil {
|
if f.Bind != nil {
|
||||||
|
@ -81,11 +87,13 @@ func (client *Client) connect(password string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := client.startStream(); err != nil {
|
f, err := client.startStream()
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
bind := f.Bind
|
||||||
|
if f.Bind == nil || (f.Bind.JID == nil && f.Bind.Resource == "") {
|
||||||
// bind to resource
|
// bind to resource
|
||||||
bind := &messages.Bind{}
|
|
||||||
if client.JID.Resource != "" {
|
if client.JID.Resource != "" {
|
||||||
bind.Resource = client.JID.Resource
|
bind.Resource = client.JID.Resource
|
||||||
}
|
}
|
||||||
|
@ -102,20 +110,24 @@ func (client *Client) connect(password string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if iq.Error != nil {
|
if iq.Error != nil {
|
||||||
if iq.Error.ServiceUnavailable == nil {
|
|
||||||
return errors.New(fmt.Sprintf("recv error on iq>bind: %s[%s]: %s -> %s -> %s", iq.Error.Code, iq.Error.Type, iq.Error.Text, messages.XMLChildrenString(iq.Error.StanzaErrorGroup), messages.XMLChildrenString(iq.Error.Other)))
|
return errors.New(fmt.Sprintf("recv error on iq>bind: %s[%s]: %s -> %s -> %s", iq.Error.Code, iq.Error.Type, iq.Error.Text, messages.XMLChildrenString(iq.Error.StanzaErrorGroup), messages.XMLChildrenString(iq.Error.Other)))
|
||||||
} else {
|
|
||||||
client.Logging.Warn("connected without setting resource with bind after auth: service-unavailable")
|
|
||||||
}
|
|
||||||
} else if iq.Bind == nil {
|
} else if iq.Bind == nil {
|
||||||
return errors.New("<iq> result missing <bind>")
|
return errors.New("iq>bind is nil :" + messages.XMLChildrenString(iq.Other))
|
||||||
} else if iq.Bind.JID != nil {
|
}
|
||||||
client.JID.Local = iq.Bind.JID.Local
|
bind = iq.Bind
|
||||||
client.JID.Domain = iq.Bind.JID.Domain
|
}
|
||||||
client.JID.Resource = iq.Bind.JID.Resource
|
if bind == nil {
|
||||||
client.Logging.Info("set resource by server bind")
|
return errors.New("bind is nil")
|
||||||
|
} else if bind.JID != nil {
|
||||||
|
client.JID.Local = bind.JID.Local
|
||||||
|
client.JID.Domain = bind.JID.Domain
|
||||||
|
client.JID.Resource = bind.JID.Resource
|
||||||
|
client.Logging.Infof("set jid by server bind '%s'", bind.JID.Full())
|
||||||
|
} else if bind.Resource != "" {
|
||||||
|
client.JID.Resource = bind.Resource
|
||||||
|
client.Logging.Infof("set resource by server bind '%s'", bind.Resource)
|
||||||
} else {
|
} else {
|
||||||
return errors.New(messages.XMLChildrenString(iq.Other))
|
return errors.New("bind>jid is nil" + messages.XMLChildrenString(bind))
|
||||||
}
|
}
|
||||||
// set status
|
// set status
|
||||||
return client.Send(&messages.PresenceClient{Show: messages.PresenceShowXA, Status: "online"})
|
return client.Send(&messages.PresenceClient{Show: messages.PresenceShowXA, Status: "online"})
|
||||||
|
|
|
@ -112,10 +112,10 @@ func (t *Tester) StartBot(status *Status) {
|
||||||
for _, jid := range t.Admins {
|
for _, jid := range t.Admins {
|
||||||
if first {
|
if first {
|
||||||
first = false
|
first = false
|
||||||
} else {
|
|
||||||
allAdmins += ", "
|
|
||||||
}
|
|
||||||
allAdmins += jid.Bare()
|
allAdmins += jid.Bare()
|
||||||
|
} else {
|
||||||
|
allAdmins += ", " + jid.Bare()
|
||||||
|
}
|
||||||
if jid.Bare() == msg.From.Bare() {
|
if jid.Bare() == msg.From.Bare() {
|
||||||
isAdmin = true
|
isAdmin = true
|
||||||
status.client.Send(messages.MessageClient{Type: msg.Type, To: jid, Body: "last message, disconnect requested by " + msg.From.Bare()})
|
status.client.Send(messages.MessageClient{Type: msg.Type, To: jid, Body: "last message, disconnect requested by " + msg.From.Bare()})
|
||||||
|
|
|
@ -23,7 +23,7 @@ func XMLStartElementToString(element *xml.StartElement) string {
|
||||||
}
|
}
|
||||||
debug := fmt.Sprintf("<%s xmlns=\"%s\"", element.Name.Local, element.Name.Space)
|
debug := fmt.Sprintf("<%s xmlns=\"%s\"", element.Name.Local, element.Name.Space)
|
||||||
for _, attr := range element.Attr {
|
for _, attr := range element.Attr {
|
||||||
debug = fmt.Sprintf("%s %s=\"%s\"", debug, attr.Name, attr.Value)
|
debug = fmt.Sprintf("%s %s=\"%s\"", debug, attr.Name.Local, attr.Value)
|
||||||
}
|
}
|
||||||
debug += ">"
|
debug += ">"
|
||||||
return debug
|
return debug
|
||||||
|
@ -54,10 +54,10 @@ func XMLChildrenString(o interface{}) (result string) {
|
||||||
if xmlElement, ok := valueField.Interface().(*xml.Name); ok && xmlElement != nil {
|
if xmlElement, ok := valueField.Interface().(*xml.Name); ok && xmlElement != nil {
|
||||||
if first {
|
if first {
|
||||||
first = false
|
first = false
|
||||||
} else {
|
|
||||||
result += ", "
|
|
||||||
}
|
|
||||||
result += xmlElement.Local
|
result += xmlElement.Local
|
||||||
|
} else {
|
||||||
|
result += ", " + xmlElement.Local
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
tlsdir = "tmp/ssl"
|
accounts_path = "tmp/yaja-tester.json"
|
||||||
state_path = "tmp/yaja-tester.json"
|
output_path = "tmp/yaja-tester-output.json"
|
||||||
logging = 5
|
|
||||||
|
|
||||||
webserver = ":https"
|
logging = 4
|
||||||
|
logging_clients = 4
|
||||||
|
logging_bots = 3
|
||||||
|
|
||||||
|
interval = "30s"
|
||||||
|
timeout = "10s"
|
||||||
|
|
||||||
admins = ["a.admin@chat.sum7.eu"]
|
admins = ["a.admin@chat.sum7.eu"]
|
||||||
|
|
||||||
|
|
Reference in New Issue