diff options
author | Christian Pointner <equinox@helsinki.at> | 2015-12-29 12:16:20 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2015-12-29 12:16:20 (GMT) |
commit | 485e0b2bdcec3c82d6c0b4d7719808a0dfc9289c (patch) | |
tree | f3cf076abd2745f91e39c0c30228a77bbeda3bb4 /src | |
parent | b84ca16ba73b56229b3c99dc2a9dd61508519c5e (diff) |
export session store to control interfaces
Diffstat (limited to 'src')
-rw-r--r-- | src/helsinki.at/rhimportd/ctrlTelnet.go | 2 | ||||
-rw-r--r-- | src/helsinki.at/rhimportd/ctrlWeb.go | 15 | ||||
-rw-r--r-- | src/helsinki.at/rhimportd/ctrlWebSimple.go | 2 | ||||
-rw-r--r-- | src/helsinki.at/rhimportd/ctrlWebSocket.go | 7 | ||||
-rw-r--r-- | src/helsinki.at/rhimportd/main.go | 201 |
5 files changed, 118 insertions, 109 deletions
diff --git a/src/helsinki.at/rhimportd/ctrlTelnet.go b/src/helsinki.at/rhimportd/ctrlTelnet.go index 45579e2..4ea7c66 100644 --- a/src/helsinki.at/rhimportd/ctrlTelnet.go +++ b/src/helsinki.at/rhimportd/ctrlTelnet.go @@ -275,7 +275,7 @@ func telnet_run(c *telgo.TelnetClient, args []string, conf *rhimport.Config, rdd return false } -func StartControlTelnet(addr_s string, conf *rhimport.Config, rddb *rhimport.RdDbChan) { +func StartControlTelnet(addr_s string, conf *rhimport.Config, rddb *rhimport.RdDbChan, sessions *rhimport.SessionStoreChan) { cmdlist := make(telgo.TelgoCmdList) cmdlist["quit"] = func(c *telgo.TelnetClient, args []string) bool { return telnet_quit(c, args, conf, rddb) } cmdlist["help"] = func(c *telgo.TelnetClient, args []string) bool { return telnet_help(c, args, conf, rddb) } diff --git a/src/helsinki.at/rhimportd/ctrlWeb.go b/src/helsinki.at/rhimportd/ctrlWeb.go index 894780c..2a95676 100644 --- a/src/helsinki.at/rhimportd/ctrlWeb.go +++ b/src/helsinki.at/rhimportd/ctrlWeb.go @@ -34,20 +34,21 @@ import ( type webHandler struct { *rhimport.Config *rhimport.RdDbChan + *rhimport.SessionStoreChan trusted bool - H func(*rhimport.Config, *rhimport.RdDbChan, bool, http.ResponseWriter, *http.Request) + H func(*rhimport.Config, *rhimport.RdDbChan, *rhimport.SessionStoreChan, bool, http.ResponseWriter, *http.Request) } func (self webHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - self.H(self.Config, self.RdDbChan, self.trusted, w, r) + self.H(self.Config, self.RdDbChan, self.SessionStoreChan, self.trusted, w, r) } -func StartControlWeb(addr_s string, conf *rhimport.Config, rddb *rhimport.RdDbChan) { - http.Handle("/public/simple", webHandler{conf, rddb, false, webSimpleHandler}) - http.Handle("/trusted/simple", webHandler{conf, rddb, true, webSimpleHandler}) +func StartControlWeb(addr_s string, conf *rhimport.Config, rddb *rhimport.RdDbChan, sessions *rhimport.SessionStoreChan) { + http.Handle("/public/simple", webHandler{conf, rddb, sessions, false, webSimpleHandler}) + http.Handle("/trusted/simple", webHandler{conf, rddb, sessions, true, webSimpleHandler}) - http.Handle("/public/socket", webHandler{conf, rddb, false, webSocketHandler}) - http.Handle("/trusted/socket", webHandler{conf, rddb, true, webSocketHandler}) + http.Handle("/public/socket", webHandler{conf, rddb, sessions, false, webSocketHandler}) + http.Handle("/trusted/socket", webHandler{conf, rddb, sessions, true, webSocketHandler}) rhl.Println("web-ctrl: listening on", addr_s) server := &http.Server{Addr: addr_s, ReadTimeout: 60 * time.Second, WriteTimeout: 60 * time.Second} diff --git a/src/helsinki.at/rhimportd/ctrlWebSimple.go b/src/helsinki.at/rhimportd/ctrlWebSimple.go index 7217584..12e17a3 100644 --- a/src/helsinki.at/rhimportd/ctrlWebSimple.go +++ b/src/helsinki.at/rhimportd/ctrlWebSimple.go @@ -121,7 +121,7 @@ func webSimpleParseRequest(conf *rhimport.Config, rddb *rhimport.RdDbChan, trust return } -func webSimpleHandler(conf *rhimport.Config, rddb *rhimport.RdDbChan, trusted bool, w http.ResponseWriter, r *http.Request) { +func webSimpleHandler(conf *rhimport.Config, rddb *rhimport.RdDbChan, sessions *rhimport.SessionStoreChan, trusted bool, w http.ResponseWriter, r *http.Request) { rhdl.Printf("WebSimpleHandler: request for '%s'", html.EscapeString(r.URL.Path)) var ctx *rhimport.ImportContext diff --git a/src/helsinki.at/rhimportd/ctrlWebSocket.go b/src/helsinki.at/rhimportd/ctrlWebSocket.go index 09095dd..93134fd 100644 --- a/src/helsinki.at/rhimportd/ctrlWebSocket.go +++ b/src/helsinki.at/rhimportd/ctrlWebSocket.go @@ -83,7 +83,10 @@ func sendWebSocketErrorResponse(ws *websocket.Conn, code int, err_str string) { } } -func webSocketHandler(conf *rhimport.Config, rddb *rhimport.RdDbChan, trusted bool, w http.ResponseWriter, r *http.Request) { +func webSocketSessionHandler() { +} + +func webSocketHandler(conf *rhimport.Config, rddb *rhimport.RdDbChan, sessions *rhimport.SessionStoreChan, trusted bool, w http.ResponseWriter, r *http.Request) { rhdl.Printf("WebSocketHandler: request for '%s'", html.EscapeString(r.URL.Path)) ws, err := websocket.Upgrade(w, r, nil, 1024, 1024) @@ -111,7 +114,7 @@ func webSocketHandler(conf *rhimport.Config, rddb *rhimport.RdDbChan, trusted bo case "new": sendWebSocketErrorResponse(ws, http.StatusNotImplemented, "new session - not yet implemented") return - case "get": + case "reconnect": if reqdata.UserName == "" { sendWebSocketErrorResponse(ws, http.StatusBadRequest, "missing mandotary field LOGIN_NAME") return diff --git a/src/helsinki.at/rhimportd/main.go b/src/helsinki.at/rhimportd/main.go index 3ce61da..87fa3ab 100644 --- a/src/helsinki.at/rhimportd/main.go +++ b/src/helsinki.at/rhimportd/main.go @@ -26,14 +26,14 @@ package main import ( "flag" - "fmt" + // "fmt" "helsinki.at/rhimport" "log" - "net/http" + // "net/http" "os" "os/signal" "sync" - "time" + // "time" // "io/ioutil" ) @@ -43,98 +43,98 @@ var ( //rhdl = log.New(ioutil.Discard, "[rhimportd-dbg]\t", log.LstdFlags) ) -func session_test_progress1(step int, step_name string, progress float64, userdata interface{}) bool { - out := userdata.(chan<- string) - select { - case out <- fmt.Sprintf("CB1 %d, %s: %3.2f%%", step, step_name, progress*100): - default: - } - if step > 1 { - return false - } - return true -} - -func session_test_progress2(step int, step_name string, progress float64, userdata interface{}) bool { - out := userdata.(chan<- string) - select { - case out <- fmt.Sprintf("CB2 %d, %s: %3.2f%%", step, step_name, progress*100): - default: - } - return true -} - -func session_test_done(res rhimport.ImportResult, userdata interface{}) bool { - done := userdata.(chan<- rhimport.ImportResult) - done <- res - return true -} - -func session_test(conf *rhimport.Config, rddb *rhimport.RdDbChan) { - sessions, err := rhimport.NewSessionStore(conf) - if err != nil { - rhl.Println("Error initializing Session Store:", err) - return - } - defer sessions.Cleanup() - - store := sessions.GetInterface() - - ctx := rhimport.NewImportContext(conf, rddb, "heslinki") - ctx.Trusted = true - ctx.ShowId = 10002 - ctx.ClearShowCarts = true - ctx.SourceUri = "http://www.tonycuffe.com/mp3/tail%20toddle.mp3" - - id, _, code, errstring := store.New(ctx) - if code != http.StatusOK { - rhl.Printf("MAIN: Error SessionStore.New(): %s", errstring) - return - } - - var session *rhimport.SessionChan - if session, code, errstring = store.Get(ctx.UserName, id); code != http.StatusOK { - rhl.Printf("MAIN: Error SessionStore.Get(): %s", errstring) - return - } - - dch := make(chan rhimport.ImportResult, 1) - if err = session.AddDoneHandler((chan<- rhimport.ImportResult)(dch), session_test_done); err != nil { - rhl.Printf("MAIN: Error Session.AddDoneHandler(): %s", err) - return - } - - pch := make(chan string, 10) - if err = session.AddProgressHandler((chan<- string)(pch), session_test_progress1); err != nil { - rhl.Printf("MAIN: Error Session.AddProgressHandler(): %s", err) - } - go func() { - time.Sleep(3 * time.Second) - if err = session.AddProgressHandler((chan<- string)(pch), session_test_progress2); err != nil { - rhl.Printf("MAIN: Error Session.AddProgressHandler(): %s", err) - } - }() - - rhl.Printf("MAIN: calling run for %s/%s", ctx.UserName, id) - session.Run(30 * time.Second) - - for { - select { - case p := <-pch: - fmt.Println(p) - case r := <-dch: - fmt.Printf("Import finished: %+v\n", r) - break - } - } - - rhl.Printf("MAIN: calling remove for %s/%s", ctx.UserName, id) - if code, errstring = store.Remove(ctx.UserName, id); code != http.StatusOK { - rhl.Printf("MAIN: Error SessionStore.Remove(): %s", errstring) - } - - rhl.Printf("MAIN: remove done") -} +// func session_test_progress1(step int, step_name string, progress float64, userdata interface{}) bool { +// out := userdata.(chan<- string) +// select { +// case out <- fmt.Sprintf("CB1 %d, %s: %3.2f%%", step, step_name, progress*100): +// default: +// } +// if step > 1 { +// return false +// } +// return true +// } + +// func session_test_progress2(step int, step_name string, progress float64, userdata interface{}) bool { +// out := userdata.(chan<- string) +// select { +// case out <- fmt.Sprintf("CB2 %d, %s: %3.2f%%", step, step_name, progress*100): +// default: +// } +// return true +// } + +// func session_test_done(res rhimport.ImportResult, userdata interface{}) bool { +// done := userdata.(chan<- rhimport.ImportResult) +// done <- res +// return true +// } + +// func session_test(conf *rhimport.Config, rddb *rhimport.RdDbChan) { +// sessions, err := rhimport.NewSessionStore(conf) +// if err != nil { +// rhl.Println("Error initializing Session Store:", err) +// return +// } +// defer sessions.Cleanup() + +// store := sessions.GetInterface() + +// ctx := rhimport.NewImportContext(conf, rddb, "heslinki") +// ctx.Trusted = true +// ctx.ShowId = 10002 +// ctx.ClearShowCarts = true +// ctx.SourceUri = "http://www.tonycuffe.com/mp3/tail%20toddle.mp3" + +// id, _, code, errstring := store.New(ctx) +// if code != http.StatusOK { +// rhl.Printf("MAIN: Error SessionStore.New(): %s", errstring) +// return +// } + +// var session *rhimport.SessionChan +// if session, code, errstring = store.Get(ctx.UserName, id); code != http.StatusOK { +// rhl.Printf("MAIN: Error SessionStore.Get(): %s", errstring) +// return +// } + +// dch := make(chan rhimport.ImportResult, 1) +// if err = session.AddDoneHandler((chan<- rhimport.ImportResult)(dch), session_test_done); err != nil { +// rhl.Printf("MAIN: Error Session.AddDoneHandler(): %s", err) +// return +// } + +// pch := make(chan string, 10) +// if err = session.AddProgressHandler((chan<- string)(pch), session_test_progress1); err != nil { +// rhl.Printf("MAIN: Error Session.AddProgressHandler(): %s", err) +// } +// go func() { +// time.Sleep(3 * time.Second) +// if err = session.AddProgressHandler((chan<- string)(pch), session_test_progress2); err != nil { +// rhl.Printf("MAIN: Error Session.AddProgressHandler(): %s", err) +// } +// }() + +// rhl.Printf("MAIN: calling run for %s/%s", ctx.UserName, id) +// session.Run(30 * time.Second) + +// for { +// select { +// case p := <-pch: +// fmt.Println(p) +// case r := <-dch: +// fmt.Printf("Import finished: %+v\n", r) +// break +// } +// } + +// rhl.Printf("MAIN: calling remove for %s/%s", ctx.UserName, id) +// if code, errstring = store.Remove(ctx.UserName, id); code != http.StatusOK { +// rhl.Printf("MAIN: Error SessionStore.Remove(): %s", errstring) +// } + +// rhl.Printf("MAIN: remove done") +// } func main() { web_addr_s := flag.String("web-addr", ":4080", "addr:port to listen on") @@ -164,7 +164,12 @@ func main() { } defer rddb.Cleanup() - // go session_test(conf, rddb.GetInterface()) + sessions, err := rhimport.NewSessionStore(conf) + if err != nil { + rhl.Println("Error initializing Session Store:", err) + return + } + defer sessions.Cleanup() var wg sync.WaitGroup @@ -172,7 +177,7 @@ func main() { go func() { defer wg.Done() rhl.Println("starting web-ctrl") - StartControlWeb(*web_addr_s, conf, rddb.GetInterface()) + StartControlWeb(*web_addr_s, conf, rddb.GetInterface(), sessions.GetInterface()) rhl.Println("web-ctrl finished") }() @@ -180,7 +185,7 @@ func main() { go func() { defer wg.Done() rhl.Println("starting telnet-ctrl") - StartControlTelnet(*telnet_addr_s, conf, rddb.GetInterface()) + StartControlTelnet(*telnet_addr_s, conf, rddb.GetInterface(), sessions.GetInterface()) rhl.Println("telnet-ctrl finished") }() |