* /control/querylog_config: support optional parameters

This commit is contained in:
Simon Zolin
2019-11-12 15:36:17 +03:00
parent 0b7ac93076
commit 81e8bbe63c
4 changed files with 22 additions and 18 deletions

View File

@@ -6,6 +6,7 @@ import (
"net/http"
"time"
"github.com/AdguardTeam/golibs/jsonutil"
"github.com/AdguardTeam/golibs/log"
"github.com/miekg/dns"
)
@@ -129,24 +130,29 @@ func (l *queryLog) handleQueryLogInfo(w http.ResponseWriter, r *http.Request) {
// Set configuration
func (l *queryLog) handleQueryLogConfig(w http.ResponseWriter, r *http.Request) {
reqData := qlogConfig{}
err := json.NewDecoder(r.Body).Decode(&reqData)
d := qlogConfig{}
req, err := jsonutil.DecodeObject(&d, r.Body)
if err != nil {
httpError(r, w, http.StatusBadRequest, "json decode: %s", err)
httpError(r, w, http.StatusBadRequest, "%s", err)
return
}
if !checkInterval(reqData.Interval) {
if req.Exists("interval") && !checkInterval(d.Interval) {
httpError(r, w, http.StatusBadRequest, "Unsupported interval")
return
}
conf := Config{
Enabled: reqData.Enabled,
Interval: reqData.Interval,
l.lock.Lock()
// copy data, modify it, then activate. Other threads (readers) don't need to use this lock.
conf := *l.conf
if req.Exists("enabled") {
conf.Enabled = d.Enabled
}
l.configure(conf)
if req.Exists("interval") {
conf.Interval = d.Interval
}
l.conf = &conf
l.lock.Unlock()
l.conf.ConfigModified()
}