summaryrefslogtreecommitdiff
path: root/src/helsinki.at
diff options
context:
space:
mode:
Diffstat (limited to 'src/helsinki.at')
-rw-r--r--src/helsinki.at/rhimport/rddb.go215
1 files changed, 109 insertions, 106 deletions
diff --git a/src/helsinki.at/rhimport/rddb.go b/src/helsinki.at/rhimport/rddb.go
index ead1ac0..8bec3c0 100644
--- a/src/helsinki.at/rhimport/rddb.go
+++ b/src/helsinki.at/rhimport/rddb.go
@@ -97,14 +97,6 @@ type getMusicInfoRequest struct {
response chan<- getMusicInfoResult
}
-type RdDbChan struct {
- getPasswordChan chan<- getPasswordRequest
- getGroupOfCartChan chan<- getGroupOfCartRequest
- getShowInfoChan chan<- getShowInfoRequest
- checkMusicGroupChan chan<- checkMusicGroupRequest
- getMusicInfoChan chan<- getMusicInfoRequest
-}
-
type RdDb struct {
dbh *sql.DB
password_cache map[string]string
@@ -177,48 +169,6 @@ func (self *RdDb) getPassword(username string, cached bool) (result getPasswordR
return
}
-func (self *RdDbChan) GetPassword(username string, cached bool) (string, error) {
- res_ch := make(chan getPasswordResult)
- req := getPasswordRequest{}
- req.username = username
- req.cached = cached
- req.response = res_ch
- self.getPasswordChan <- req
-
- res := <-res_ch
- if res.err != nil {
- return "", res.err
- }
- return res.password, nil
-}
-
-func (self *RdDbChan) CheckPassword(username, password string) (bool, error) {
- cached := true
-
- for {
- res_ch := make(chan getPasswordResult)
- req := getPasswordRequest{}
- req.username = username
- req.cached = cached
- req.response = res_ch
- self.getPasswordChan <- req
-
- res := <-res_ch
- if res.err != nil {
- return false, res.err
- }
- if password == res.password {
- return true, nil
- }
- if cached {
- cached = false
- } else {
- break
- }
- }
- return false, nil
-}
-
func (self *RdDb) getGroupOfCart(cart uint) (result getGroupOfCartResult) {
var rows *sql.Rows
if rows, result.err = self.getGroupOfCartStmt.Query(cart, cart); result.err != nil {
@@ -249,20 +199,6 @@ func (self *RdDb) getGroupOfCart(cart uint) (result getGroupOfCartResult) {
return
}
-func (self *RdDbChan) GetGroupOfCart(cart uint) (string, error) {
- res_ch := make(chan getGroupOfCartResult)
- req := getGroupOfCartRequest{}
- req.cart = cart
- req.response = res_ch
- self.getGroupOfCartChan <- req
-
- res := <-res_ch
- if res.err != nil {
- return "", res.err
- }
- return res.group, nil
-}
-
func (self *RdDb) getLogTableName(log string) (logtable string, err error) {
logtable = strings.Replace(log, " ", "_", -1) + "_LOG"
if !mysqlTableNameRe.MatchString(logtable) {
@@ -309,20 +245,6 @@ func (self *RdDb) getShowInfo(showid uint) (result getShowInfoResult) {
return
}
-func (self *RdDbChan) GetShowInfo(showid uint) (string, int, int, []uint, error) {
- res_ch := make(chan getShowInfoResult)
- req := getShowInfoRequest{}
- req.showid = showid
- req.response = res_ch
- self.getShowInfoChan <- req
-
- res := <-res_ch
- if res.err != nil {
- return "", 0, 0, nil, res.err
- }
- return res.group, res.norm_lvl, res.trim_lvl, res.carts, nil
-}
-
func (self *RdDb) checkMusicGroup(group string) (result checkMusicGroupResult) {
var cnt int
if result.err = self.checkMusicGroupStmt.QueryRow(group).Scan(&cnt); result.err != nil {
@@ -336,20 +258,6 @@ func (self *RdDb) checkMusicGroup(group string) (result checkMusicGroupResult) {
return
}
-func (self *RdDbChan) CheckMusicGroup(groupname string) (bool, error) {
- res_ch := make(chan checkMusicGroupResult)
- req := checkMusicGroupRequest{}
- req.group = groupname
- req.response = res_ch
- self.checkMusicGroupChan <- req
-
- res := <-res_ch
- if res.err != nil {
- return false, res.err
- }
- return res.ismusic, nil
-}
-
func (self *RdDb) getMusicInfo(group string) (result getMusicInfoResult) {
result.err = self.getMusicInfoStmt.QueryRow(group).Scan(&result.norm_lvl, &result.trim_lvl)
if result.err != nil {
@@ -361,20 +269,6 @@ func (self *RdDb) getMusicInfo(group string) (result getMusicInfoResult) {
return
}
-func (self *RdDbChan) GetMusicInfo(groupname string) (int, int, error) {
- res_ch := make(chan getMusicInfoResult)
- req := getMusicInfoRequest{}
- req.group = groupname
- req.response = res_ch
- self.getMusicInfoChan <- req
-
- res := <-res_ch
- if res.err != nil {
- return 0, 0, res.err
- }
- return res.norm_lvl, res.trim_lvl, nil
-}
-
func (self *RdDb) dispatchRequests() {
defer func() { self.done <- true }()
for {
@@ -395,6 +289,115 @@ func (self *RdDb) dispatchRequests() {
}
}
+// *********************************************************
+// Public Interface
+
+type RdDbChan struct {
+ getPasswordChan chan<- getPasswordRequest
+ getGroupOfCartChan chan<- getGroupOfCartRequest
+ getShowInfoChan chan<- getShowInfoRequest
+ checkMusicGroupChan chan<- checkMusicGroupRequest
+ getMusicInfoChan chan<- getMusicInfoRequest
+}
+
+func (self *RdDbChan) GetPassword(username string, cached bool) (string, error) {
+ res_ch := make(chan getPasswordResult)
+ req := getPasswordRequest{}
+ req.username = username
+ req.cached = cached
+ req.response = res_ch
+ self.getPasswordChan <- req
+
+ res := <-res_ch
+ if res.err != nil {
+ return "", res.err
+ }
+ return res.password, nil
+}
+
+func (self *RdDbChan) CheckPassword(username, password string) (bool, error) {
+ cached := true
+
+ for {
+ res_ch := make(chan getPasswordResult)
+ req := getPasswordRequest{}
+ req.username = username
+ req.cached = cached
+ req.response = res_ch
+ self.getPasswordChan <- req
+
+ res := <-res_ch
+ if res.err != nil {
+ return false, res.err
+ }
+ if password == res.password {
+ return true, nil
+ }
+ if cached {
+ cached = false
+ } else {
+ break
+ }
+ }
+ return false, nil
+}
+
+func (self *RdDbChan) GetGroupOfCart(cart uint) (string, error) {
+ res_ch := make(chan getGroupOfCartResult)
+ req := getGroupOfCartRequest{}
+ req.cart = cart
+ req.response = res_ch
+ self.getGroupOfCartChan <- req
+
+ res := <-res_ch
+ if res.err != nil {
+ return "", res.err
+ }
+ return res.group, nil
+}
+
+func (self *RdDbChan) GetShowInfo(showid uint) (string, int, int, []uint, error) {
+ res_ch := make(chan getShowInfoResult)
+ req := getShowInfoRequest{}
+ req.showid = showid
+ req.response = res_ch
+ self.getShowInfoChan <- req
+
+ res := <-res_ch
+ if res.err != nil {
+ return "", 0, 0, nil, res.err
+ }
+ return res.group, res.norm_lvl, res.trim_lvl, res.carts, nil
+}
+
+func (self *RdDbChan) CheckMusicGroup(groupname string) (bool, error) {
+ res_ch := make(chan checkMusicGroupResult)
+ req := checkMusicGroupRequest{}
+ req.group = groupname
+ req.response = res_ch
+ self.checkMusicGroupChan <- req
+
+ res := <-res_ch
+ if res.err != nil {
+ return false, res.err
+ }
+ return res.ismusic, nil
+}
+
+func (self *RdDbChan) GetMusicInfo(groupname string) (int, int, error) {
+ res_ch := make(chan getMusicInfoResult)
+ req := getMusicInfoRequest{}
+ req.group = groupname
+ req.response = res_ch
+ self.getMusicInfoChan <- req
+
+ res := <-res_ch
+ if res.err != nil {
+ return 0, 0, res.err
+ }
+ return res.norm_lvl, res.trim_lvl, nil
+}
+
func (self *RdDb) GetInterface() *RdDbChan {
ch := &RdDbChan{}
ch.getPasswordChan = self.getPasswordChan