summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core.go26
-rw-r--r--fetcher.go14
-rw-r--r--importer.go36
-rw-r--r--session.go38
-rw-r--r--session_store.go6
5 files changed, 60 insertions, 60 deletions
diff --git a/core.go b/core.go
index bb92d30..9927be9 100644
--- a/core.go
+++ b/core.go
@@ -51,17 +51,17 @@ func init() {
fetcherInit()
}
-type ImportProgressCB func(step int, stepName string, progress float64, userdata interface{}) bool
-type ImportDoneCB func(ImportResult, interface{}) bool
+type ProgressCB func(step int, stepName string, progress float64, userdata interface{}) bool
+type DoneCB func(Result, interface{}) bool
-type ImportResult struct {
+type Result struct {
ResponseCode int
ErrorString string
Cart uint
Cut uint
}
-type ImportContext struct {
+type Context struct {
conf *Config
rddb *RdDbChan
UserName string
@@ -81,13 +81,13 @@ type ImportContext struct {
SourceFile string
DeleteSourceFile bool
DeleteSourceDir bool
- ProgressCallBack ImportProgressCB
+ ProgressCallBack ProgressCB
ProgressCallBackData interface{}
Cancel <-chan bool
}
-func NewImportContext(conf *Config, rddb *RdDbChan, user string) *ImportContext {
- ctx := new(ImportContext)
+func NewContext(conf *Config, rddb *RdDbChan, user string) *Context {
+ ctx := new(Context)
ctx.conf = conf
ctx.rddb = rddb
ctx.UserName = user
@@ -112,7 +112,7 @@ func NewImportContext(conf *Config, rddb *RdDbChan, user string) *ImportContext
return ctx
}
-func (ctx *ImportContext) SanityCheck() error {
+func (ctx *Context) SanityCheck() error {
if ctx.UserName == "" {
return fmt.Errorf("empty Username is not allowed")
}
@@ -156,28 +156,28 @@ func (ctx *ImportContext) SanityCheck() error {
return nil
}
-func (ctx *ImportContext) getPassword(cached bool) (err error) {
+func (ctx *Context) getPassword(cached bool) (err error) {
ctx.Password, err = ctx.rddb.GetPassword(ctx.UserName, cached)
return
}
-func (ctx *ImportContext) getGroupOfCart() (err error) {
+func (ctx *Context) getGroupOfCart() (err error) {
ctx.GroupName, err = ctx.rddb.GetGroupOfCart(ctx.Cart)
return
}
-func (ctx *ImportContext) getShowInfo() (carts []uint, err error) {
+func (ctx *Context) getShowInfo() (carts []uint, err error) {
ctx.GroupName, ctx.NormalizationLevel, ctx.AutotrimLevel, carts, err = ctx.rddb.GetShowInfo(ctx.ShowId)
ctx.Channels = 2
ctx.UseMetaData = true
return
}
-func (ctx *ImportContext) checkMusicGroup() (bool, error) {
+func (ctx *Context) checkMusicGroup() (bool, error) {
return ctx.rddb.CheckMusicGroup(ctx.GroupName)
}
-func (ctx *ImportContext) getMusicInfo() (err error) {
+func (ctx *Context) getMusicInfo() (err error) {
ctx.NormalizationLevel, ctx.AutotrimLevel, err = ctx.rddb.GetMusicInfo(ctx.GroupName)
ctx.Channels = 2
ctx.UseMetaData = true
diff --git a/fetcher.go b/fetcher.go
index f5d5420..66c91a5 100644
--- a/fetcher.go
+++ b/fetcher.go
@@ -86,7 +86,7 @@ func curlWriteCallback(ptr []byte, userdata interface{}) bool {
return true
}
-func fetchFileCurl(ctx *ImportContext, res *ImportResult, uri *url.URL) (err error) {
+func fetchFileCurl(ctx *Context, res *Result, uri *url.URL) (err error) {
rhl.Printf("curl-based fetcher called for '%s'", ctx.SourceUri)
easy := curl.EasyInit()
@@ -150,7 +150,7 @@ func fetchFileCurl(ctx *ImportContext, res *ImportResult, uri *url.URL) (err err
return
}
-func fetchFileLocal(ctx *ImportContext, res *ImportResult, uri *url.URL) (err error) {
+func fetchFileLocal(ctx *Context, res *Result, uri *url.URL) (err error) {
rhl.Printf("Local fetcher called for '%s'", ctx.SourceUri)
if ctx.ProgressCallBack != nil {
if keep := ctx.ProgressCallBack(1, "fetching", 0.0, ctx.ProgressCallBackData); !keep {
@@ -187,7 +187,7 @@ func fetchFileLocal(ctx *ImportContext, res *ImportResult, uri *url.URL) (err er
return
}
-func fetchFileFake(ctx *ImportContext, res *ImportResult, uri *url.URL) error {
+func fetchFileFake(ctx *Context, res *Result, uri *url.URL) error {
rhdl.Printf("Fake fetcher for '%s'", ctx.SourceUri)
if duration, err := strconv.ParseUint(uri.Host, 10, 32); err != nil {
@@ -221,7 +221,7 @@ func fetchFileFake(ctx *ImportContext, res *ImportResult, uri *url.URL) error {
return nil
}
-type FetchFunc func(*ImportContext, *ImportResult, *url.URL) (err error)
+type FetchFunc func(*Context, *Result, *url.URL) (err error)
// TODO: implement fetchers for:
// archiv://
@@ -257,7 +257,7 @@ func fetcherInit() {
}
}
-func checkPassword(ctx *ImportContext, result *ImportResult) (err error) {
+func checkPassword(ctx *Context, result *Result) (err error) {
ok := false
if ok, err = ctx.rddb.CheckPassword(ctx.UserName, ctx.Password); err != nil {
return
@@ -269,8 +269,8 @@ func checkPassword(ctx *ImportContext, result *ImportResult) (err error) {
return
}
-func FetchFile(ctx *ImportContext) (res *ImportResult, err error) {
- res = &ImportResult{ResponseCode: http.StatusOK}
+func FetchFile(ctx *Context) (res *Result, err error) {
+ res = &Result{ResponseCode: http.StatusOK}
var uri *url.URL
if uri, err = url.Parse(ctx.SourceUri); err != nil {
diff --git a/importer.go b/importer.go
index 4a0bece..9af3765 100644
--- a/importer.go
+++ b/importer.go
@@ -35,7 +35,7 @@ import (
"path"
)
-func (self *ImportResult) fromRDWebResult(rdres *RDWebResult) {
+func (self *Result) fromRDWebResult(rdres *RDWebResult) {
self.ResponseCode = rdres.ResponseCode
self.ErrorString = rdres.ErrorString
if rdres.AudioConvertError != 0 {
@@ -43,7 +43,7 @@ func (self *ImportResult) fromRDWebResult(rdres *RDWebResult) {
}
}
-func addCart(ctx *ImportContext, res *ImportResult) (err error) {
+func addCart(ctx *Context, res *Result) (err error) {
rhdl.Printf("importer: addCart() called for cart: %d", ctx.Cart)
if ctx.GroupName == "" {
@@ -103,7 +103,7 @@ func addCart(ctx *ImportContext, res *ImportResult) (err error) {
return
}
-func addCut(ctx *ImportContext, res *ImportResult) (err error) {
+func addCut(ctx *Context, res *Result) (err error) {
rhdl.Printf("importer: addCut() called for cart/cut: %d/%d", ctx.Cart, ctx.Cut)
var b bytes.Buffer
w := multipart.NewWriter(&b)
@@ -150,7 +150,7 @@ func addCut(ctx *ImportContext, res *ImportResult) (err error) {
return
}
-func removeCart(ctx *ImportContext, res *ImportResult) (err error) {
+func removeCart(ctx *Context, res *Result) (err error) {
rhdl.Printf("importer: removeCart() called for cart: %d", ctx.Cart)
var b bytes.Buffer
w := multipart.NewWriter(&b)
@@ -184,7 +184,7 @@ func removeCart(ctx *ImportContext, res *ImportResult) (err error) {
return
}
-func removeCut(ctx *ImportContext, res *ImportResult) (err error) {
+func removeCut(ctx *Context, res *Result) (err error) {
rhdl.Printf("importer: removeCut() called for cart/cut: %d/%d", ctx.Cart, ctx.Cut)
var b bytes.Buffer
w := multipart.NewWriter(&b)
@@ -238,7 +238,7 @@ func sendPostRequest(url string, b *bytes.Buffer, contenttype string) (resp *htt
return
}
-func importAudioCreateRequest(ctx *ImportContext, easy *curl.CURL) (form *curl.Form, err error) {
+func importAudioCreateRequest(ctx *Context, easy *curl.CURL) (form *curl.Form, err error) {
form = curl.NewForm()
if err = form.Add("COMMAND", "2"); err != nil {
@@ -275,7 +275,7 @@ func importAudioCreateRequest(ctx *ImportContext, easy *curl.CURL) (form *curl.F
return
}
-func importAudio(ctx *ImportContext, res *ImportResult) (err error) {
+func importAudio(ctx *Context, res *Result) (err error) {
rhdl.Printf("importer: importAudio() called for cart/cut: %d/%d", ctx.Cart, ctx.Cut)
easy := curl.EasyInit()
@@ -343,24 +343,24 @@ func importAudio(ctx *ImportContext, res *ImportResult) (err error) {
return
}
-func addCartCut(ctx *ImportContext, res *ImportResult) (err error) {
+func addCartCut(ctx *Context, res *Result) (err error) {
if err = addCart(ctx, res); err != nil || res.ResponseCode != http.StatusOK {
return
}
if err = addCut(ctx, res); err != nil || res.ResponseCode != http.StatusOK {
- return removeCart(ctx, &ImportResult{ResponseCode: http.StatusOK})
+ return removeCart(ctx, &Result{ResponseCode: http.StatusOK})
}
return
}
-func removeAddCartCut(ctx *ImportContext, res *ImportResult) (err error) {
+func removeAddCartCut(ctx *Context, res *Result) (err error) {
if err = removeCart(ctx, res); err != nil || (res.ResponseCode != http.StatusOK && res.ResponseCode != http.StatusNotFound) {
return
}
return addCartCut(ctx, res)
}
-func isCartMemberOfShow(ctx *ImportContext, res *ImportResult, carts []uint) (found bool) {
+func isCartMemberOfShow(ctx *Context, res *Result, carts []uint) (found bool) {
if ctx.Cart == 0 {
return true
}
@@ -375,7 +375,7 @@ func isCartMemberOfShow(ctx *ImportContext, res *ImportResult, carts []uint) (fo
return false
}
-func clearShowCarts(ctx *ImportContext, res *ImportResult, carts []uint) (err error) {
+func clearShowCarts(ctx *Context, res *Result, carts []uint) (err error) {
if ctx.ClearShowCarts {
origCart := ctx.Cart
for _, cart := range carts {
@@ -389,14 +389,14 @@ func clearShowCarts(ctx *ImportContext, res *ImportResult, carts []uint) (err er
return
}
-func addShowCartCut(ctx *ImportContext, res *ImportResult, carts []uint) (err error) {
+func addShowCartCut(ctx *Context, res *Result, carts []uint) (err error) {
if err = addCart(ctx, res); err != nil || res.ResponseCode != http.StatusOK {
return
}
for _, cart := range carts {
if cart == ctx.Cart {
if err = addCut(ctx, res); err != nil || res.ResponseCode != http.StatusOK {
- return removeCart(ctx, &ImportResult{ResponseCode: http.StatusOK})
+ return removeCart(ctx, &Result{ResponseCode: http.StatusOK})
}
return
}
@@ -409,7 +409,7 @@ func addShowCartCut(ctx *ImportContext, res *ImportResult, carts []uint) (err er
return
}
-func cleanupFiles(ctx *ImportContext) {
+func cleanupFiles(ctx *Context) {
if ctx.DeleteSourceFile {
rhdl.Printf("importer: removing file: %s", ctx.SourceFile)
if err := os.Remove(ctx.SourceFile); err != nil {
@@ -427,7 +427,7 @@ func cleanupFiles(ctx *ImportContext) {
return
}
-func ImportFile(ctx *ImportContext) (res *ImportResult, err error) {
+func ImportFile(ctx *Context) (res *Result, err error) {
defer cleanupFiles(ctx)
rhl.Printf("importer: ImportFile called with: show-id: %d, pool-name: '%s', cart/cut: %d/%d", ctx.ShowId, ctx.GroupName, ctx.Cart, ctx.Cut)
@@ -447,7 +447,7 @@ func ImportFile(ctx *ImportContext) (res *ImportResult, err error) {
rmCartOnErr := false
rmCutOnErr := false
- res = &ImportResult{ResponseCode: http.StatusOK}
+ res = &Result{ResponseCode: http.StatusOK}
if ctx.ShowId != 0 { // Import to a show
var showCarts []uint
if showCarts, err = ctx.getShowInfo(); err != nil {
@@ -506,7 +506,7 @@ func ImportFile(ctx *ImportContext) (res *ImportResult, err error) {
rhl.Printf("Fileimport has failed (Cart/Cut %d/%d): %s", res.Cart, res.Cut, res.ErrorString)
}
// Try to clean up after failed import
- rmres := ImportResult{ResponseCode: http.StatusOK}
+ rmres := Result{ResponseCode: http.StatusOK}
if rmCartOnErr {
if rerr := removeCart(ctx, &rmres); rerr != nil {
return
diff --git a/session.go b/session.go
index e0f1a4b..8eab828 100644
--- a/session.go
+++ b/session.go
@@ -39,7 +39,7 @@ const (
)
type Session struct {
- ctx ImportContext
+ ctx Context
state int
removeFunc func()
done chan bool
@@ -47,7 +47,7 @@ type Session struct {
timer *time.Timer
cancelIntChan chan bool
progressIntChan chan ProgressData
- doneIntChan chan ImportResult
+ doneIntChan chan Result
runChan chan time.Duration
cancelChan chan bool
addProgressChan chan sessionAddProgressHandlerRequest
@@ -57,12 +57,12 @@ type Session struct {
}
type SessionProgressCB struct {
- cb ImportProgressCB
+ cb ProgressCB
userdata interface{}
}
type SessionDoneCB struct {
- cb ImportDoneCB
+ cb DoneCB
userdata interface{}
}
@@ -78,7 +78,7 @@ type sessionAddProgressHandlerResponse struct {
type sessionAddProgressHandlerRequest struct {
userdata interface{}
- callback ImportProgressCB
+ callback ProgressCB
response chan<- sessionAddProgressHandlerResponse
}
@@ -88,7 +88,7 @@ type sessionAddDoneHandlerResponse struct {
type sessionAddDoneHandlerRequest struct {
userdata interface{}
- callback ImportDoneCB
+ callback DoneCB
response chan<- sessionAddDoneHandlerResponse
}
@@ -98,14 +98,14 @@ func sessionProgressCallback(step int, stepName string, progress float64, userda
return true
}
-func sessionImportRun(ctx ImportContext, done chan<- ImportResult) {
+func sessionRun(ctx Context, done chan<- Result) {
if err := ctx.SanityCheck(); err != nil {
- done <- ImportResult{http.StatusBadRequest, err.Error(), 0, 0}
+ done <- Result{http.StatusBadRequest, err.Error(), 0, 0}
return
}
if res, err := FetchFile(&ctx); err != nil {
- done <- ImportResult{http.StatusInternalServerError, err.Error(), 0, 0}
+ done <- Result{http.StatusInternalServerError, err.Error(), 0, 0}
return
} else if res.ResponseCode != http.StatusOK {
done <- *res
@@ -113,7 +113,7 @@ func sessionImportRun(ctx ImportContext, done chan<- ImportResult) {
}
if res, err := ImportFile(&ctx); err != nil {
- done <- ImportResult{http.StatusInternalServerError, err.Error(), 0, 0}
+ done <- Result{http.StatusInternalServerError, err.Error(), 0, 0}
return
} else {
done <- *res
@@ -125,7 +125,7 @@ func (self *Session) run(timeout time.Duration) {
self.ctx.ProgressCallBack = sessionProgressCallback
self.ctx.ProgressCallBackData = (chan<- ProgressData)(self.progressIntChan)
self.ctx.Cancel = self.cancelIntChan
- go sessionImportRun(self.ctx, self.doneIntChan)
+ go sessionRun(self.ctx, self.doneIntChan)
self.state = SESSION_RUNNING
self.timer.Reset(timeout)
return
@@ -140,7 +140,7 @@ func (self *Session) cancel() {
self.state = SESSION_CANCELED
}
-func (self *Session) addProgressHandler(userdata interface{}, cb ImportProgressCB) (resp sessionAddProgressHandlerResponse) {
+func (self *Session) addProgressHandler(userdata interface{}, cb ProgressCB) (resp sessionAddProgressHandlerResponse) {
if self.state != SESSION_NEW && self.state != SESSION_RUNNING {
resp.err = fmt.Errorf("session is already done/canceled")
}
@@ -148,7 +148,7 @@ func (self *Session) addProgressHandler(userdata interface{}, cb ImportProgressC
return
}
-func (self *Session) addDoneHandler(userdata interface{}, cb ImportDoneCB) (resp sessionAddDoneHandlerResponse) {
+func (self *Session) addDoneHandler(userdata interface{}, cb DoneCB) (resp sessionAddDoneHandlerResponse) {
if self.state != SESSION_NEW && self.state != SESSION_RUNNING {
resp.err = fmt.Errorf("session is already done/canceled")
}
@@ -166,7 +166,7 @@ func (self *Session) callProgressHandler(p *ProgressData) {
}
}
-func (self *Session) callDoneHandler(r *ImportResult) {
+func (self *Session) callDoneHandler(r *Result) {
for _, cb := range self.doneCBs {
if cb.cb != nil {
if keep := cb.cb(*r, cb.userdata); !keep {
@@ -190,7 +190,7 @@ func (self *Session) dispatchRequests() {
self.cancel()
}
self.state = SESSION_TIMEOUT
- r := &ImportResult{500, "session timed out", 0, 0}
+ r := &Result{500, "session timed out", 0, 0}
self.callDoneHandler(r)
if self.removeFunc != nil {
self.removeFunc()
@@ -246,7 +246,7 @@ func (self *SessionChan) Cancel() {
}
}
-func (self *SessionChan) AddProgressHandler(userdata interface{}, cb ImportProgressCB) error {
+func (self *SessionChan) AddProgressHandler(userdata interface{}, cb ProgressCB) error {
resCh := make(chan sessionAddProgressHandlerResponse)
req := sessionAddProgressHandlerRequest{}
req.userdata = userdata
@@ -262,7 +262,7 @@ func (self *SessionChan) AddProgressHandler(userdata interface{}, cb ImportProgr
return res.err
}
-func (self *SessionChan) AddDoneHandler(userdata interface{}, cb ImportDoneCB) error {
+func (self *SessionChan) AddDoneHandler(userdata interface{}, cb DoneCB) error {
resCh := make(chan sessionAddDoneHandlerResponse)
req := sessionAddDoneHandlerRequest{}
req.userdata = userdata
@@ -309,7 +309,7 @@ func (self *Session) cleanup() {
rhdl.Printf("session is now cleaned up")
}
-func newSession(ctx *ImportContext, removeFunc func()) (session *Session) {
+func newSession(ctx *Context, removeFunc func()) (session *Session) {
session = new(Session)
session.state = SESSION_NEW
session.removeFunc = removeFunc
@@ -318,7 +318,7 @@ func newSession(ctx *ImportContext, removeFunc func()) (session *Session) {
session.timer = time.NewTimer(10 * time.Second)
session.cancelIntChan = make(chan bool, 1)
session.progressIntChan = make(chan ProgressData, 10)
- session.doneIntChan = make(chan ImportResult, 1)
+ session.doneIntChan = make(chan Result, 1)
session.runChan = make(chan time.Duration, 1)
session.cancelChan = make(chan bool, 1)
session.addProgressChan = make(chan sessionAddProgressHandlerRequest, 10)
diff --git a/session_store.go b/session_store.go
index bb4043b..db3f217 100644
--- a/session_store.go
+++ b/session_store.go
@@ -39,7 +39,7 @@ type newSessionResponse struct {
}
type newSessionRequest struct {
- ctx *ImportContext
+ ctx *Context
refId string
response chan newSessionResponse
}
@@ -107,7 +107,7 @@ func generateSessionId() (string, error) {
return base64.RawStdEncoding.EncodeToString(b[:]), nil
}
-func (self *SessionStore) new(ctx *ImportContext, refId string) (resp newSessionResponse) {
+func (self *SessionStore) new(ctx *Context, refId string) (resp newSessionResponse) {
resp.responsecode = http.StatusOK
resp.errorstring = "OK"
if !ctx.Trusted {
@@ -223,7 +223,7 @@ type SessionStoreChan struct {
removeChan chan<- removeSessionRequest
}
-func (self *SessionStoreChan) New(ctx *ImportContext, refId string) (string, *SessionChan, int, string) {
+func (self *SessionStoreChan) New(ctx *Context, refId string) (string, *SessionChan, int, string) {
resCh := make(chan newSessionResponse)
req := newSessionRequest{}
req.ctx = ctx