summaryrefslogtreecommitdiff
path: root/src/rhimportd
diff options
context:
space:
mode:
Diffstat (limited to 'src/rhimportd')
-rw-r--r--src/rhimportd/ctrlTelnet.go29
-rw-r--r--src/rhimportd/ctrlWatchDir.go17
-rw-r--r--src/rhimportd/ctrlWeb.go15
-rw-r--r--src/rhimportd/ctrlWebSimple.go9
-rw-r--r--src/rhimportd/ctrlWebSocket.go3
-rw-r--r--src/rhimportd/main.go19
6 files changed, 47 insertions, 45 deletions
diff --git a/src/rhimportd/ctrlTelnet.go b/src/rhimportd/ctrlTelnet.go
index 5d0aebe..974627d 100644
--- a/src/rhimportd/ctrlTelnet.go
+++ b/src/rhimportd/ctrlTelnet.go
@@ -28,16 +28,17 @@ import (
"fmt"
"github.com/spreadspace/telgo"
"helsinki.at/rhimport"
+ "helsinki.at/rhrd-go/rddb"
"net/http"
"strconv"
"strings"
)
-func telnetQuit(c *telgo.Client, args []string, conf *rhimport.Config, rddb *rhimport.RdDbChan) bool {
+func telnetQuit(c *telgo.Client, args []string, conf *rhimport.Config, db *rddb.DBChan) bool {
return true
}
-func telnetHelp(c *telgo.Client, args []string, conf *rhimport.Config, rddb *rhimport.RdDbChan) bool {
+func telnetHelp(c *telgo.Client, args []string, conf *rhimport.Config, db *rddb.DBChan) bool {
switch len(args) {
case 2:
switch args[1] {
@@ -145,7 +146,7 @@ func telnetSetBool(c *telgo.Client, param *bool, val string) {
}
}
-func telnetSet(c *telgo.Client, args []string, conf *rhimport.Config, rddb *rhimport.RdDbChan) bool {
+func telnetSet(c *telgo.Client, args []string, conf *rhimport.Config, db *rddb.DBChan) bool {
if len(args) != 3 {
c.Sayln("wrong number of arguments")
return false
@@ -153,7 +154,7 @@ func telnetSet(c *telgo.Client, args []string, conf *rhimport.Config, rddb *rhim
var ctx *rhimport.Context
if c.UserData == nil {
- c.UserData = rhimport.NewContext(conf, rddb)
+ c.UserData = rhimport.NewContext(conf, db)
ctx = c.UserData.(*rhimport.Context)
ctx.Trusted = false
} else {
@@ -192,7 +193,7 @@ func telnetSet(c *telgo.Client, args []string, conf *rhimport.Config, rddb *rhim
return false
}
-func telnetReset(c *telgo.Client, args []string, conf *rhimport.Config, rddb *rhimport.RdDbChan) bool {
+func telnetReset(c *telgo.Client, args []string, conf *rhimport.Config, db *rddb.DBChan) bool {
if len(args) > 1 {
c.Sayln("too many arguments")
return false
@@ -202,7 +203,7 @@ func telnetReset(c *telgo.Client, args []string, conf *rhimport.Config, rddb *rh
return false
}
-func telnetShow(c *telgo.Client, args []string, conf *rhimport.Config, rddb *rhimport.RdDbChan) bool {
+func telnetShow(c *telgo.Client, args []string, conf *rhimport.Config, db *rddb.DBChan) bool {
if len(args) > 1 {
c.Sayln("too many arguments")
return false
@@ -235,7 +236,7 @@ func telnetProgressCallback(step int, stepName string, progress float64, userdat
return true
}
-func telnetRun(c *telgo.Client, args []string, conf *rhimport.Config, rddb *rhimport.RdDbChan) bool {
+func telnetRun(c *telgo.Client, args []string, conf *rhimport.Config, db *rddb.DBChan) bool {
if c.UserData == nil {
c.Sayln("context is empty please set at least one option")
return false
@@ -275,14 +276,14 @@ func telnetRun(c *telgo.Client, args []string, conf *rhimport.Config, rddb *rhim
return false
}
-func StartControlTelnet(addr string, conf *rhimport.Config, rddb *rhimport.RdDbChan, sessions *rhimport.SessionStoreChan) {
+func StartControlTelnet(addr string, conf *rhimport.Config, db *rddb.DBChan, sessions *rhimport.SessionStoreChan) {
cmdlist := make(telgo.CmdList)
- cmdlist["quit"] = func(c *telgo.Client, args []string) bool { return telnetQuit(c, args, conf, rddb) }
- cmdlist["help"] = func(c *telgo.Client, args []string) bool { return telnetHelp(c, args, conf, rddb) }
- cmdlist["set"] = func(c *telgo.Client, args []string) bool { return telnetSet(c, args, conf, rddb) }
- cmdlist["reset"] = func(c *telgo.Client, args []string) bool { return telnetReset(c, args, conf, rddb) }
- cmdlist["show"] = func(c *telgo.Client, args []string) bool { return telnetShow(c, args, conf, rddb) }
- cmdlist["run"] = func(c *telgo.Client, args []string) bool { return telnetRun(c, args, conf, rddb) }
+ cmdlist["quit"] = func(c *telgo.Client, args []string) bool { return telnetQuit(c, args, conf, db) }
+ cmdlist["help"] = func(c *telgo.Client, args []string) bool { return telnetHelp(c, args, conf, db) }
+ cmdlist["set"] = func(c *telgo.Client, args []string) bool { return telnetSet(c, args, conf, db) }
+ cmdlist["reset"] = func(c *telgo.Client, args []string) bool { return telnetReset(c, args, conf, db) }
+ cmdlist["show"] = func(c *telgo.Client, args []string) bool { return telnetShow(c, args, conf, db) }
+ cmdlist["run"] = func(c *telgo.Client, args []string) bool { return telnetRun(c, args, conf, db) }
rhl.Println("telnet-ctrl: listening on", addr)
s := telgo.NewServer(addr, "rhimportd> ", cmdlist, nil)
diff --git a/src/rhimportd/ctrlWatchDir.go b/src/rhimportd/ctrlWatchDir.go
index 6f84c15..037f8ea 100644
--- a/src/rhimportd/ctrlWatchDir.go
+++ b/src/rhimportd/ctrlWatchDir.go
@@ -28,6 +28,7 @@ import (
"encoding/json"
"fmt"
"helsinki.at/rhimport"
+ "helsinki.at/rhrd-go/rddb"
"net/http"
"os"
"path/filepath"
@@ -97,7 +98,7 @@ func watchDirResponse(filename string, result *rhimport.Result) {
watchDirWriteResponse(filename, &watchDirResponseData{result.ResponseCode, result.ErrorString, result.Cart, result.Cut})
}
-func watchDirParseRequest(conf *rhimport.Config, rddb *rhimport.RdDbChan, req *os.File) (ctx *rhimport.Context, err error) {
+func watchDirParseRequest(conf *rhimport.Config, db *rddb.DBChan, req *os.File) (ctx *rhimport.Context, err error) {
decoder := json.NewDecoder(req)
reqdata := newWatchDirRequestData(conf)
@@ -106,7 +107,7 @@ func watchDirParseRequest(conf *rhimport.Config, rddb *rhimport.RdDbChan, req *o
return
}
- ctx = rhimport.NewContext(conf, rddb)
+ ctx = rhimport.NewContext(conf, db)
ctx.UserName = reqdata.UserName
ctx.Trusted = true
ctx.ShowId = reqdata.ShowId
@@ -123,7 +124,7 @@ func watchDirParseRequest(conf *rhimport.Config, rddb *rhimport.RdDbChan, req *o
return
}
-func watchDirHandler(conf *rhimport.Config, rddb *rhimport.RdDbChan, ctx *rhimport.Context, filename string) {
+func watchDirHandler(conf *rhimport.Config, db *rddb.DBChan, ctx *rhimport.Context, filename string) {
rhdl.Printf("WatchDirHandler: request for '%s'", filename)
var err error
@@ -156,7 +157,7 @@ func watchDirHandler(conf *rhimport.Config, rddb *rhimport.RdDbChan, ctx *rhimpo
return
}
-func watchDirRun(dir *os.File, conf *rhimport.Config, rddb *rhimport.RdDbChan) {
+func watchDirRun(dir *os.File, conf *rhimport.Config, db *rddb.DBChan) {
rhl.Printf("watch-dir-ctrl: watching for files in %s", dir.Name())
for {
var err error
@@ -181,11 +182,11 @@ func watchDirRun(dir *os.File, conf *rhimport.Config, rddb *rhimport.RdDbChan) {
rhl.Printf("watch-dir-ctrl: error reading new file: %s", err)
continue
}
- if ctx, err := watchDirParseRequest(conf, rddb, file); err == nil {
+ if ctx, err := watchDirParseRequest(conf, db, file); err == nil {
file.Close()
dstname := strings.TrimSuffix(srcname, ".new") + ".running"
os.Rename(srcname, dstname)
- go watchDirHandler(conf, rddb, ctx, dstname)
+ go watchDirHandler(conf, db, ctx, dstname)
} else { // ignoring files with json errors -> maybe the file has not been written completely
file.Close()
rhdl.Printf("watch-dir-ctrl: new file %s parser error: %s, ignoring for now", srcname, err)
@@ -197,7 +198,7 @@ func watchDirRun(dir *os.File, conf *rhimport.Config, rddb *rhimport.RdDbChan) {
}
}
-func StartWatchDir(dirname string, conf *rhimport.Config, rddb *rhimport.RdDbChan) {
+func StartWatchDir(dirname string, conf *rhimport.Config, db *rddb.DBChan) {
for {
time.Sleep(5 * time.Second)
dir, err := os.Open(dirname)
@@ -214,6 +215,6 @@ func StartWatchDir(dirname string, conf *rhimport.Config, rddb *rhimport.RdDbCha
continue
}
}
- watchDirRun(dir, conf, rddb)
+ watchDirRun(dir, conf, db)
}
}
diff --git a/src/rhimportd/ctrlWeb.go b/src/rhimportd/ctrlWeb.go
index c1cd4b5..46e384a 100644
--- a/src/rhimportd/ctrlWeb.go
+++ b/src/rhimportd/ctrlWeb.go
@@ -26,6 +26,7 @@ package main
import (
"helsinki.at/rhimport"
+ "helsinki.at/rhrd-go/rddb"
"net/http"
_ "net/http/pprof"
"time"
@@ -33,21 +34,21 @@ import (
type webHandler struct {
*rhimport.Config
- *rhimport.RdDbChan
+ *rddb.DBChan
*rhimport.SessionStoreChan
trusted bool
- H func(*rhimport.Config, *rhimport.RdDbChan, *rhimport.SessionStoreChan, bool, http.ResponseWriter, *http.Request)
+ H func(*rhimport.Config, *rddb.DBChan, *rhimport.SessionStoreChan, bool, http.ResponseWriter, *http.Request)
}
func (self webHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
- self.H(self.Config, self.RdDbChan, self.SessionStoreChan, self.trusted, w, r)
+ self.H(self.Config, self.DBChan, self.SessionStoreChan, self.trusted, w, r)
}
-func StartControlWeb(addr 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})
+func StartControlWeb(addr string, conf *rhimport.Config, db *rddb.DBChan, sessions *rhimport.SessionStoreChan) {
+ http.Handle("/public/simple", webHandler{conf, db, sessions, false, webSimpleHandler})
+ // http.Handle("/trusted/simple", webHandler{conf, db, sessions, true, webSimpleHandler})
- http.Handle("/public/socket", webHandler{conf, rddb, sessions, false, webSocketHandler})
+ http.Handle("/public/socket", webHandler{conf, db, sessions, false, webSocketHandler})
rhl.Println("web-ctrl: listening on", addr)
server := &http.Server{Addr: addr, ReadTimeout: 60 * time.Second, WriteTimeout: 60 * time.Second}
diff --git a/src/rhimportd/ctrlWebSimple.go b/src/rhimportd/ctrlWebSimple.go
index cd2c556..15f06ee 100644
--- a/src/rhimportd/ctrlWebSimple.go
+++ b/src/rhimportd/ctrlWebSimple.go
@@ -28,6 +28,7 @@ import (
"encoding/json"
"fmt"
"helsinki.at/rhimport"
+ "helsinki.at/rhrd-go/rddb"
"html"
"net/http"
)
@@ -90,7 +91,7 @@ func webSimpleResponse(w http.ResponseWriter, result *rhimport.Result) {
encoder.Encode(respdata)
}
-func webSimpleParseRequest(conf *rhimport.Config, rddb *rhimport.RdDbChan, trusted bool, r *http.Request) (ctx *rhimport.Context, err error) {
+func webSimpleParseRequest(conf *rhimport.Config, db *rddb.DBChan, trusted bool, r *http.Request) (ctx *rhimport.Context, err error) {
decoder := json.NewDecoder(r.Body)
reqdata := newWebSimpleRequestData(conf)
@@ -99,7 +100,7 @@ func webSimpleParseRequest(conf *rhimport.Config, rddb *rhimport.RdDbChan, trust
return
}
- ctx = rhimport.NewContext(conf, rddb)
+ ctx = rhimport.NewContext(conf, db)
if trusted {
ctx.UserName = r.Header.Get("X-Forwarded-User")
} else {
@@ -121,12 +122,12 @@ func webSimpleParseRequest(conf *rhimport.Config, rddb *rhimport.RdDbChan, trust
return
}
-func webSimpleHandler(conf *rhimport.Config, rddb *rhimport.RdDbChan, sessions *rhimport.SessionStoreChan, trusted bool, w http.ResponseWriter, r *http.Request) {
+func webSimpleHandler(conf *rhimport.Config, db *rddb.DBChan, 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.Context
var err error
- if ctx, err = webSimpleParseRequest(conf, rddb, trusted, r); err != nil {
+ if ctx, err = webSimpleParseRequest(conf, db, trusted, r); err != nil {
webSimpleErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
diff --git a/src/rhimportd/ctrlWebSocket.go b/src/rhimportd/ctrlWebSocket.go
index a0386f1..0fd83f0 100644
--- a/src/rhimportd/ctrlWebSocket.go
+++ b/src/rhimportd/ctrlWebSocket.go
@@ -28,6 +28,7 @@ import (
"fmt"
"github.com/gorilla/websocket"
"helsinki.at/rhimport"
+ "helsinki.at/rhrd-go/rddb"
"html"
"math"
"net/http"
@@ -302,7 +303,7 @@ func webSocketSessionHandler(reqchan <-chan webSocketRequestData, ws *websocket.
}
}
-func webSocketHandler(conf *rhimport.Config, rddb *rhimport.RdDbChan, sessions *rhimport.SessionStoreChan, trusted bool, w http.ResponseWriter, r *http.Request) {
+func webSocketHandler(conf *rhimport.Config, db *rddb.DBChan, 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)
diff --git a/src/rhimportd/main.go b/src/rhimportd/main.go
index d941b05..e9608c1 100644
--- a/src/rhimportd/main.go
+++ b/src/rhimportd/main.go
@@ -28,6 +28,7 @@ import (
"flag"
"fmt"
"helsinki.at/rhimport"
+ "helsinki.at/rhrd-go/rddb"
"io/ioutil"
"log"
"os"
@@ -88,20 +89,16 @@ func main() {
return
}
- conf, err := rhimport.NewConfig(rdconf.Get().(string), rdxportUrl.Get().(string), tempDir.Get().(string), localFetchDir.Get().(string))
- if err != nil {
- rhl.Println("Error reading configuration:", err)
- return
- }
+ conf := rhimport.NewConfig(rdxportUrl.Get().(string), tempDir.Get().(string), localFetchDir.Get().(string))
- rddb, err := rhimport.NewRdDb(conf)
+ db, err := rddb.NewDB(rdconf.Get().(string))
if err != nil {
rhl.Println("Error initializing Rivdenll DB:", err)
return
}
- defer rddb.Cleanup()
+ defer db.Cleanup()
- sessions, err := rhimport.NewSessionStore(conf, rddb.GetInterface())
+ sessions, err := rhimport.NewSessionStore(conf, db.GetInterface())
if err != nil {
rhl.Println("Error initializing Session Store:", err)
return
@@ -115,7 +112,7 @@ func main() {
go func() {
defer wg.Done()
rhl.Println("starting web-ctrl")
- StartControlWeb(webAddr.Get().(string), conf, rddb.GetInterface(), sessions.GetInterface())
+ StartControlWeb(webAddr.Get().(string), conf, db.GetInterface(), sessions.GetInterface())
rhl.Println("web-ctrl finished")
}()
}
@@ -125,7 +122,7 @@ func main() {
go func() {
defer wg.Done()
rhl.Println("starting telnet-ctrl")
- StartControlTelnet(telnetAddr.Get().(string), conf, rddb.GetInterface(), sessions.GetInterface())
+ StartControlTelnet(telnetAddr.Get().(string), conf, db.GetInterface(), sessions.GetInterface())
rhl.Println("telnet-ctrl finished")
}()
}
@@ -135,7 +132,7 @@ func main() {
go func() {
defer wg.Done()
rhl.Println("starting watch-dir-ctrl")
- StartWatchDir(watchDir.Get().(string), conf, rddb.GetInterface())
+ StartWatchDir(watchDir.Get().(string), conf, db.GetInterface())
rhl.Println("watch-dir-ctrl finished")
}()
}