2020-08-09 15:29:54 -07:00
|
|
|
package ldap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
|
|
|
|
ber "github.com/go-asn1-ber/asn1-ber"
|
2024-05-24 14:08:09 -07:00
|
|
|
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
2020-08-09 15:29:54 -07:00
|
|
|
)
|
|
|
|
|
2024-05-24 14:08:09 -07:00
|
|
|
type debugging struct {
|
|
|
|
logger mlog.LoggerIFace
|
|
|
|
levels []mlog.Level
|
|
|
|
}
|
2020-08-09 15:29:54 -07:00
|
|
|
|
|
|
|
// Enable controls debugging mode.
|
2024-05-24 14:08:09 -07:00
|
|
|
func (debug *debugging) Enable(logger mlog.LoggerIFace, levels ...mlog.Level) {
|
|
|
|
*debug = debugging{
|
|
|
|
logger: logger,
|
|
|
|
levels: levels,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (debug debugging) Enabled() bool {
|
|
|
|
return debug.logger != nil
|
2020-08-09 15:29:54 -07:00
|
|
|
}
|
|
|
|
|
2024-05-24 14:08:09 -07:00
|
|
|
// Log writes debug output.
|
|
|
|
func (debug debugging) Log(msg string, fields ...mlog.Field) {
|
|
|
|
if debug.Enabled() {
|
|
|
|
debug.logger.LogM(debug.levels, msg, fields...)
|
2020-08-09 15:29:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-24 14:08:09 -07:00
|
|
|
type Packet ber.Packet
|
|
|
|
|
|
|
|
func (p Packet) LogClone() any {
|
|
|
|
bp := ber.Packet(p)
|
|
|
|
var b bytes.Buffer
|
|
|
|
ber.WritePacket(&b, &bp)
|
|
|
|
return b.String()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func PacketToField(packet *ber.Packet) mlog.Field {
|
|
|
|
if packet == nil {
|
|
|
|
return mlog.Any("packet", nil)
|
2020-08-09 15:29:54 -07:00
|
|
|
}
|
2024-05-24 14:08:09 -07:00
|
|
|
return mlog.Any("packet", Packet(*packet))
|
2020-08-09 15:29:54 -07:00
|
|
|
}
|