summaryrefslogtreecommitdiff
path: root/rhimport/session_store.go
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-07-28 20:23:33 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-07-28 20:23:33 (GMT)
commitc7f6ff81175a78c4fb497a5ac98c3806457f762f (patch)
treec22084fa654295a6ce1e01a7735cbe0459aafefb /rhimport/session_store.go
parent12c91ff577dd956f357c17c6026439a54dd1f9ac (diff)
major name refactoring (don't export all the internal stuff)
Diffstat (limited to 'rhimport/session_store.go')
-rw-r--r--rhimport/session_store.go66
1 files changed, 33 insertions, 33 deletions
diff --git a/rhimport/session_store.go b/rhimport/session_store.go
index dafe71e..bb36473 100644
--- a/rhimport/session_store.go
+++ b/rhimport/session_store.go
@@ -38,7 +38,7 @@ import (
type newSessionResponse struct {
id string
- session *SessionChan
+ session *Session
responsecode int
errorstring string
}
@@ -50,7 +50,7 @@ type newSessionRequest struct {
}
type getSessionResponse struct {
- session *SessionChan
+ session *Session
refId string
responsecode int
errorstring string
@@ -96,17 +96,17 @@ type removeSessionRequest struct {
response chan removeSessionResponse
}
-type SessionStoreSessionElement struct {
- s *Session
+type sessionStoreSessionElement struct {
+ s *session
refId string
}
-type SessionStoreUserElement struct {
- sessions map[string]*SessionStoreSessionElement
+type sessionStoreUserElement struct {
+ sessions map[string]*sessionStoreSessionElement
updateCBs []SessionsListCB
}
-func (user *SessionStoreUserElement) callUpdateHandler(added, removed map[string]string) {
+func (user *sessionStoreUserElement) callUpdateHandler(added, removed map[string]string) {
var keptCBs []SessionsListCB
for _, cb := range user.updateCBs {
if cb.cb != nil {
@@ -118,20 +118,20 @@ func (user *SessionStoreUserElement) callUpdateHandler(added, removed map[string
user.updateCBs = keptCBs
}
-func (user *SessionStoreUserElement) callUpdateHandlerAdd(id, refId string) {
+func (user *sessionStoreUserElement) callUpdateHandlerAdd(id, refId string) {
added := make(map[string]string)
added[id] = refId
user.callUpdateHandler(added, nil)
}
-func (user *SessionStoreUserElement) callUpdateHandlerRemove(id, refId string) {
+func (user *sessionStoreUserElement) callUpdateHandlerRemove(id, refId string) {
removed := make(map[string]string)
removed[id] = refId
user.callUpdateHandler(nil, removed)
}
-type SessionStore struct {
- store map[string]*SessionStoreUserElement
+type sessionStore struct {
+ store map[string]*sessionStoreUserElement
conf *Config
db *rddb.DBChan
stdlog *log.Logger
@@ -152,7 +152,7 @@ func generateSessionId() (string, error) {
return base64.RawURLEncoding.EncodeToString(b[:]), nil
}
-func (store *SessionStore) new(ctx *Context, refId string) (resp newSessionResponse) {
+func (store *sessionStore) new(ctx *Context, refId string) (resp newSessionResponse) {
resp.responsecode = http.StatusOK
resp.errorstring = "OK"
if !ctx.Trusted {
@@ -175,8 +175,8 @@ func (store *SessionStore) new(ctx *Context, refId string) (resp newSessionRespo
resp.id = id
if _, exists := store.store[ctx.UserName]; !exists {
- newuser := &SessionStoreUserElement{}
- newuser.sessions = make(map[string]*SessionStoreSessionElement)
+ newuser := &sessionStoreUserElement{}
+ newuser.sessions = make(map[string]*sessionStoreSessionElement)
store.store[ctx.UserName] = newuser
}
ctx.conf = store.conf
@@ -187,7 +187,7 @@ func (store *SessionStore) new(ctx *Context, refId string) (resp newSessionRespo
if pref := ctx.dbglog.Prefix(); strings.Contains(pref, "%s") {
ctx.dbglog.SetPrefix(fmt.Sprintf(pref, resp.id))
}
- s := &SessionStoreSessionElement{newSession(ctx, func() { store.GetInterface().Remove(ctx.UserName, resp.id) }), refId}
+ s := &sessionStoreSessionElement{newSession(ctx, func() { store.GetInterface().Remove(ctx.UserName, resp.id) }), refId}
store.store[ctx.UserName].sessions[resp.id] = s
resp.session = store.store[ctx.UserName].sessions[resp.id].s.getInterface()
store.dbglog.Printf("SessionStore: created session for '%s' -> %s", ctx.UserName, resp.id)
@@ -195,7 +195,7 @@ func (store *SessionStore) new(ctx *Context, refId string) (resp newSessionRespo
return
}
-func (store *SessionStore) get(username, id string) (resp getSessionResponse) {
+func (store *sessionStore) get(username, id string) (resp getSessionResponse) {
resp.responsecode = http.StatusOK
resp.errorstring = "OK"
@@ -216,7 +216,7 @@ func (store *SessionStore) get(username, id string) (resp getSessionResponse) {
return
}
-func (store *SessionStore) list(username, password string, trusted bool, userdata interface{}, cb SessionsUpdateCB) (resp listSessionsResponse) {
+func (store *sessionStore) list(username, password string, trusted bool, userdata interface{}, cb SessionsUpdateCB) (resp listSessionsResponse) {
resp.responsecode = http.StatusOK
resp.errorstring = "OK"
if !trusted {
@@ -239,15 +239,15 @@ func (store *SessionStore) list(username, password string, trusted bool, userdat
user.updateCBs = append(user.updateCBs, SessionsListCB{cb, userdata})
}
} else if cb != nil {
- newuser := &SessionStoreUserElement{}
- newuser.sessions = make(map[string]*SessionStoreSessionElement)
+ newuser := &sessionStoreUserElement{}
+ newuser.sessions = make(map[string]*sessionStoreSessionElement)
newuser.updateCBs = []SessionsListCB{SessionsListCB{cb, userdata}}
store.store[username] = newuser
}
return
}
-func (store *SessionStore) remove(username, id string) (resp removeSessionResponse) {
+func (store *sessionStore) remove(username, id string) (resp removeSessionResponse) {
resp.responsecode = http.StatusOK
resp.errorstring = "OK"
@@ -276,7 +276,7 @@ func (store *SessionStore) remove(username, id string) (resp removeSessionRespon
return
}
-func (store *SessionStore) maintenanceTask() {
+func (store *sessionStore) maintenanceTask() {
for name, user := range store.store {
user.callUpdateHandler(nil, nil)
if len(user.sessions) == 0 && len(user.updateCBs) == 0 {
@@ -286,7 +286,7 @@ func (store *SessionStore) maintenanceTask() {
}
}
-func (store *SessionStore) dispatchRequests() {
+func (store *sessionStore) dispatchRequests() {
defer func() { store.done <- true }()
mt := time.NewTicker(1 * time.Minute)
@@ -311,14 +311,14 @@ func (store *SessionStore) dispatchRequests() {
// *********************************************************
// Public Interface
-type SessionStoreChan struct {
+type SessionStore struct {
newChan chan<- newSessionRequest
getChan chan<- getSessionRequest
listChan chan listSessionsRequest
removeChan chan<- removeSessionRequest
}
-func (store *SessionStoreChan) New(ctx *Context, refId string) (string, *SessionChan, int, string) {
+func (store *SessionStore) New(ctx *Context, refId string) (string, *Session, int, string) {
resCh := make(chan newSessionResponse)
req := newSessionRequest{}
req.ctx = ctx
@@ -330,7 +330,7 @@ func (store *SessionStoreChan) New(ctx *Context, refId string) (string, *Session
return res.id, res.session, res.responsecode, res.errorstring
}
-func (store *SessionStoreChan) Get(user, id string) (*SessionChan, string, int, string) {
+func (store *SessionStore) Get(user, id string) (*Session, string, int, string) {
resCh := make(chan getSessionResponse)
req := getSessionRequest{}
req.user = user
@@ -342,7 +342,7 @@ func (store *SessionStoreChan) Get(user, id string) (*SessionChan, string, int,
return res.session, res.refId, res.responsecode, res.errorstring
}
-func (store *SessionStoreChan) List(user, password string, trusted bool, userdata interface{}, cb SessionsUpdateCB) (map[string]string, int, string) {
+func (store *SessionStore) List(user, password string, trusted bool, userdata interface{}, cb SessionsUpdateCB) (map[string]string, int, string) {
resCh := make(chan listSessionsResponse)
req := listSessionsRequest{}
req.user = user
@@ -357,7 +357,7 @@ func (store *SessionStoreChan) List(user, password string, trusted bool, userdat
return res.sessions, res.responsecode, res.errorstring
}
-func (store *SessionStoreChan) Remove(user, id string) (int, string) {
+func (store *SessionStore) Remove(user, id string) (int, string) {
resCh := make(chan removeSessionResponse)
req := removeSessionRequest{}
req.user = user
@@ -369,8 +369,8 @@ func (store *SessionStoreChan) Remove(user, id string) (int, string) {
return res.responsecode, res.errorstring
}
-func (store *SessionStore) GetInterface() *SessionStoreChan {
- ch := &SessionStoreChan{}
+func (store *sessionStore) GetInterface() *SessionStore {
+ ch := &SessionStore{}
ch.newChan = store.newChan
ch.getChan = store.getChan
ch.listChan = store.listChan
@@ -378,7 +378,7 @@ func (store *SessionStore) GetInterface() *SessionStoreChan {
return ch
}
-func (store *SessionStore) Cleanup() {
+func (store *sessionStore) Cleanup() {
store.quit <- true
<-store.done
close(store.quit)
@@ -389,15 +389,15 @@ func (store *SessionStore) Cleanup() {
close(store.removeChan)
}
-func NewSessionStore(conf *Config, db *rddb.DBChan, stdlog, dbglog *log.Logger) (store *SessionStore, err error) {
- store = new(SessionStore)
+func NewSessionStore(conf *Config, db *rddb.DBChan, stdlog, dbglog *log.Logger) (store *sessionStore, err error) {
+ store = &sessionStore{}
store.conf = conf
store.db = db
store.stdlog = stdlog
store.dbglog = dbglog
store.quit = make(chan bool, 1)
store.done = make(chan bool)
- store.store = make(map[string]*SessionStoreUserElement)
+ store.store = make(map[string]*sessionStoreUserElement)
store.newChan = make(chan newSessionRequest, 10)
store.getChan = make(chan getSessionRequest, 10)
store.listChan = make(chan listSessionsRequest, 10)