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 == "" {
|
||||
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()
|
||||
if err != nil {
|
||||
|
|
|
@ -42,8 +42,14 @@ func (client *Client) startStream() (*messages.StreamFeatures, error) {
|
|||
debug += " tls"
|
||||
}
|
||||
debug += " mechanism("
|
||||
mFirst := true
|
||||
for _, m := range f.Mechanisms.Mechanism {
|
||||
if mFirst {
|
||||
mFirst = false
|
||||
debug += m
|
||||
} else {
|
||||
debug += ", " + m
|
||||
}
|
||||
}
|
||||
debug += ")"
|
||||
if f.Bind != nil {
|
||||
|
@ -81,11 +87,13 @@ func (client *Client) connect(password string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if _, err := client.startStream(); err != nil {
|
||||
f, err := client.startStream()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
bind := f.Bind
|
||||
if f.Bind == nil || (f.Bind.JID == nil && f.Bind.Resource == "") {
|
||||
// bind to resource
|
||||
bind := &messages.Bind{}
|
||||
if client.JID.Resource != "" {
|
||||
bind.Resource = client.JID.Resource
|
||||
}
|
||||
|
@ -102,20 +110,24 @@ func (client *Client) connect(password string) error {
|
|||
return err
|
||||
}
|
||||
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)))
|
||||
} else {
|
||||
client.Logging.Warn("connected without setting resource with bind after auth: service-unavailable")
|
||||
}
|
||||
} else if iq.Bind == nil {
|
||||
return errors.New("<iq> result missing <bind>")
|
||||
} else if iq.Bind.JID != nil {
|
||||
client.JID.Local = iq.Bind.JID.Local
|
||||
client.JID.Domain = iq.Bind.JID.Domain
|
||||
client.JID.Resource = iq.Bind.JID.Resource
|
||||
client.Logging.Info("set resource by server bind")
|
||||
return errors.New("iq>bind is nil :" + messages.XMLChildrenString(iq.Other))
|
||||
}
|
||||
bind = iq.Bind
|
||||
}
|
||||
if bind == nil {
|
||||
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 {
|
||||
return errors.New(messages.XMLChildrenString(iq.Other))
|
||||
return errors.New("bind>jid is nil" + messages.XMLChildrenString(bind))
|
||||
}
|
||||
// set status
|
||||
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 {
|
||||
if first {
|
||||
first = false
|
||||
} else {
|
||||
allAdmins += ", "
|
||||
}
|
||||
allAdmins += jid.Bare()
|
||||
} else {
|
||||
allAdmins += ", " + jid.Bare()
|
||||
}
|
||||
if jid.Bare() == msg.From.Bare() {
|
||||
isAdmin = true
|
||||
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)
|
||||
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 += ">"
|
||||
return debug
|
||||
|
@ -54,10 +54,10 @@ func XMLChildrenString(o interface{}) (result string) {
|
|||
if xmlElement, ok := valueField.Interface().(*xml.Name); ok && xmlElement != nil {
|
||||
if first {
|
||||
first = false
|
||||
} else {
|
||||
result += ", "
|
||||
}
|
||||
result += xmlElement.Local
|
||||
} else {
|
||||
result += ", " + xmlElement.Local
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
tlsdir = "tmp/ssl"
|
||||
state_path = "tmp/yaja-tester.json"
|
||||
logging = 5
|
||||
accounts_path = "tmp/yaja-tester.json"
|
||||
output_path = "tmp/yaja-tester-output.json"
|
||||
|
||||
webserver = ":https"
|
||||
logging = 4
|
||||
logging_clients = 4
|
||||
logging_bots = 3
|
||||
|
||||
interval = "30s"
|
||||
timeout = "10s"
|
||||
|
||||
admins = ["a.admin@chat.sum7.eu"]
|
||||
|
||||
|
|
Reference in New Issue