X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=go%2Fr3-netstatus%2Fr3xmppbot%2Fr3xmppbot.go;h=3ad4177c0ffec3cb9fbe0d4cd632881d784c70d9;hb=3ccab0493b7a182ef2efce4cfffb1e5107eab14b;hp=6740a844d54858c805a6c453952a454b4cd5d50e;hpb=762ecd62c9bca5d9a4c9696dcf477d1000a28f42;p=svn42.git diff --git a/go/r3-netstatus/r3xmppbot/r3xmppbot.go b/go/r3-netstatus/r3xmppbot/r3xmppbot.go index 6740a84..3ad4177 100644 --- a/go/r3-netstatus/r3xmppbot/r3xmppbot.go +++ b/go/r3-netstatus/r3xmppbot/r3xmppbot.go @@ -254,9 +254,6 @@ func (botdata *XmppBot) handleIncomingMessageDialog(inmsg xmpp.Message, xmppout if inmsg.Body == nil || inmsg.GetHeader() == nil { return } - if inmsg.Type == "error" || inmsg.Error != nil { - Syslog_.Printf("XMPP Message Error: %s", inmsg.Error.Error()) - } bodytext :=inmsg.Body.Chardata if botdata.isAuthenticated(inmsg.GetHeader().From) { switch bodytext { @@ -315,16 +312,42 @@ func (botdata *XmppBot) handleIncomingXMPPStanzas(xmppin <- chan xmpp.Stanza, xm close(jabber_events) }() + var error_count int = 0 var incoming_stanza interface{} + + handleStanzaError := func() bool { + error_count++ + if error_count > 15 { + Syslog_.Println("handleIncomingXMPPStanzas: too many errors in series.. bailing out") + botdata.StopBot() + return true + } + return false + } + for incoming_stanza = range xmppin { switch stanza := incoming_stanza.(type) { case *xmpp.Message: + if stanza.GetHeader() == nil { continue } + if stanza.Type == "error" || stanza.Error != nil { + Syslog_.Printf("XMPP %T Error: %s", stanza, stanza) + if stanza.Error.Type == "cancel" { + // asume receipient not reachable -> disable + Syslog_.Printf("Error reaching %s. Disabling user, please reenable manually", stanza.From) + jabber_events <- JabberEvent{stanza.From, false, R3NeverInfo, false} + continue + } + if handleStanzaError() { return } + continue + } else { error_count = 0 } botdata.handleIncomingMessageDialog(*stanza, xmppout, jabber_events) case *xmpp.Presence: if stanza.GetHeader() == nil { continue } if stanza.Type == "error" || stanza.Error != nil { - Syslog_.Printf("XMPP Presence Error: %s", stanza.Error.Error()) - } + Syslog_.Printf("XMPP %T Error: %s", stanza, stanza) + if handleStanzaError() { return } + continue + } else { error_count = 0 } switch stanza.GetHeader().Type { case "subscribe": xmppout <- botdata.makeXMPPPresence(stanza.GetHeader().From, "subscribed", "", "") @@ -340,11 +363,15 @@ func (botdata *XmppBot) handleIncomingXMPPStanzas(xmppin <- chan xmpp.Stanza, xm default: jabber_events <- JabberEvent{stanza.GetHeader().From, true, R3NoChange, false} } + case *xmpp.Iq: if stanza.GetHeader() == nil { continue } if stanza.Type == "error" || stanza.Error != nil { - Syslog_.Printf("XMPP Iq Error: %s", stanza.Error.Error()) - } + Syslog_.Printf("XMPP %T Error: %s", stanza, stanza) + if handleStanzaError() { return } + continue + } else { error_count = 0 } + if HandleServerToClientPing(stanza, xmppout) {continue} //if true then routine handled it and we can continue Debug_.Printf("Unhandled Iq: %s", stanza) }