diff options
Diffstat (limited to 'src/rhimportd/ctrlWebSimple.go')
-rw-r--r-- | src/rhimportd/ctrlWebSimple.go | 40 |
1 files changed, 15 insertions, 25 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 } |