summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-07-28 22:40:14 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-07-28 22:40:14 (GMT)
commit29c5920353da2ff8811d1518b411dfe957e397f5 (patch)
tree0f75fb134d01735f40243bebed9592ffc694a504 /src
parent5e6fa43f66f87c2be836b1a95230473b080293c6 (diff)
web simple control interface now uses sessions as well
Diffstat (limited to 'src')
-rw-r--r--src/rhimportd/ctrlWebSimple.go40
-rw-r--r--src/rhimportd/ctrlWebSocket.go2
2 files changed, 16 insertions, 26 deletions
diff --git a/src/rhimportd/ctrlWebSimple.go b/src/rhimportd/ctrlWebSimple.go
index f5d5225..86e6893 100644
--- a/src/rhimportd/ctrlWebSimple.go
+++ b/src/rhimportd/ctrlWebSimple.go
@@ -99,8 +99,7 @@ func webSimpleParseRequest(conf *rhimport.Config, db *rddb.DB, trusted bool, r *
return
}
- logname := "simple-" + r.RemoteAddr
- ctx = rhimport.NewContext(conf, db, getStdLog(logname+"-std"), getDbgLog(logname+"-dbg"))
+ ctx = rhimport.NewContext(conf, nil, getStdLog("sess-%s-std"), getDbgLog("sess-%s-dbg"))
if trusted {
ctx.UserName = r.Header.Get("X-Forwarded-User")
} else {
@@ -122,6 +121,12 @@ func webSimpleParseRequest(conf *rhimport.Config, db *rddb.DB, trusted bool, r *
return
}
+func webSimpleDone(res rhimport.Result, userdata interface{}) bool {
+ c := userdata.(chan<- rhimport.Result)
+ c <- res
+ return true
+}
+
func webSimpleHandler(conf *rhimport.Config, db *rddb.DB, sessions *rhimport.SessionStore, trusted bool, w http.ResponseWriter, r *http.Request) {
rhdl.Printf("WebSimpleHandler: %s requests '%s'", r.RemoteAddr, html.EscapeString(r.URL.Path))
@@ -132,35 +137,20 @@ func webSimpleHandler(conf *rhimport.Config, db *rddb.DB, sessions *rhimport.Ses
return
}
- if err = ctx.SanityCheck(); err != nil {
- webSimpleErrorResponse(w, http.StatusBadRequest, err.Error())
- return
- }
-
- var res *rhimport.Result
- if res, err = rhimport.FetchFile(ctx); err != nil {
- webSimpleErrorResponse(w, http.StatusInternalServerError, err.Error())
- return
- }
- if res.ResponseCode != http.StatusOK {
- webSimpleErrorResponse(w, res.ResponseCode, res.ErrorString)
- return
- }
-
- if res, err = rhimport.NormalizeFile(ctx); err != nil {
- webSimpleErrorResponse(w, http.StatusInternalServerError, err.Error())
- return
- }
- if res.ResponseCode != http.StatusOK {
- webSimpleErrorResponse(w, res.ResponseCode, res.ErrorString)
+ _, s, code, errstring := sessions.New(ctx, "")
+ if code != http.StatusOK {
+ webSimpleErrorResponse(w, code, errstring)
return
}
- if res, err = rhimport.ImportFile(ctx); err != nil {
+ donechan := make(chan rhimport.Result, 1)
+ if err := s.AddDoneHandler((chan<- rhimport.Result)(donechan), webSimpleDone); err != nil {
webSimpleErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
- webSimpleResponse(w, res)
+ s.Run(0)
+ res := <-donechan
+ webSimpleResponse(w, &res)
return
}
diff --git a/src/rhimportd/ctrlWebSocket.go b/src/rhimportd/ctrlWebSocket.go
index f6b84da..51c2929 100644
--- a/src/rhimportd/ctrlWebSocket.go
+++ b/src/rhimportd/ctrlWebSocket.go
@@ -226,7 +226,7 @@ func webSocketDone(res rhimport.Result, userdata interface{}) bool {
}
func (self *webSocketSession) startNewSession(reqdata *webSocketRequestData, conf *rhimport.Config, sessions *rhimport.SessionStore) (int, string) {
- ctx := rhimport.NewContext(conf, nil, getStdLog("sess-%s-std"), getDbgLog("sess-%s-dbg")) // session store will take of db, stdlog and dbglog
+ ctx := rhimport.NewContext(conf, nil, getStdLog("sess-%s-std"), getDbgLog("sess-%s-dbg"))
ctx.UserName = reqdata.UserName
ctx.Password = reqdata.Password
ctx.Trusted = false