summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-12-30 21:11:56 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-12-30 21:11:56 (GMT)
commita37f02747e587b25d45de98d175427d4ccb5cdf7 (patch)
tree0e456bfd7f2b4b5fa39a11a51ad32da6f985e434 /src
parentc37f07d1416b7e371db7b32799df53df39210aa6 (diff)
session store list works now (needs auth check)
Diffstat (limited to 'src')
-rw-r--r--src/helsinki.at/rhimportd/ctrlWebSocket.go39
1 files changed, 30 insertions, 9 deletions
diff --git a/src/helsinki.at/rhimportd/ctrlWebSocket.go b/src/helsinki.at/rhimportd/ctrlWebSocket.go
index ca1092c..da2978e 100644
--- a/src/helsinki.at/rhimportd/ctrlWebSocket.go
+++ b/src/helsinki.at/rhimportd/ctrlWebSocket.go
@@ -83,6 +83,11 @@ type webSocketResponseBaseData struct {
RefId string `json:"REFERENCE_ID"`
}
+type webSocketResponseListData struct {
+ webSocketResponseBaseData
+ Sessions map[string]string `json:"SESSIONS"`
+}
+
type webSocketResponseProgressData struct {
webSocketResponseBaseData
Step int `json:"PROGRESS_STEP"`
@@ -102,21 +107,30 @@ func sendWebSocketResponse(ws *websocket.Conn, rd interface{}) {
}
}
-func sendWebSocketAckResponse(ws *websocket.Conn, code int, err_str, id, refid string) {
+func sendWebSocketErrorResponse(ws *websocket.Conn, code int, err_str string) {
rd := &webSocketResponseBaseData{}
rd.ResponseCode = code
- rd.Type = "ACK"
+ rd.Type = "ERROR"
rd.ErrorString = err_str
- rd.Id = id
- rd.RefId = refid
sendWebSocketResponse(ws, rd)
}
-func sendWebSocketErrorResponse(ws *websocket.Conn, code int, err_str string) {
+func sendWebSocketAckResponse(ws *websocket.Conn, code int, id, refid string) {
rd := &webSocketResponseBaseData{}
rd.ResponseCode = code
- rd.Type = "ERROR"
- rd.ErrorString = err_str
+ rd.Type = "ACK"
+ rd.ErrorString = "OK"
+ rd.Id = id
+ rd.RefId = refid
+ sendWebSocketResponse(ws, rd)
+}
+
+func sendWebSocketListResponse(ws *websocket.Conn, sessions map[string]string) {
+ rd := &webSocketResponseListData{}
+ rd.ResponseCode = http.StatusOK
+ rd.Type = "LIST"
+ rd.ErrorString = "OK"
+ rd.Sessions = sessions
sendWebSocketResponse(ws, rd)
}
@@ -248,7 +262,7 @@ func webSocketSessionHandler(reqchan <-chan webSocketRequestData, ws *websocket.
if code != http.StatusOK {
sendWebSocketErrorResponse(ws, code, errstring)
} else {
- sendWebSocketAckResponse(ws, code, "OK", session.id, session.refId)
+ sendWebSocketAckResponse(ws, code, session.id, session.refId)
}
}
case "cancel":
@@ -265,9 +279,16 @@ func webSocketSessionHandler(reqchan <-chan webSocketRequestData, ws *websocket.
if code != http.StatusOK {
sendWebSocketErrorResponse(ws, code, errstring)
} else {
- sendWebSocketAckResponse(ws, code, "OK", session.id, session.refId)
+ sendWebSocketAckResponse(ws, code, session.id, session.refId)
}
}
+ case "list":
+ list, code, errstring := sessions.List(reqdata.UserName, reqdata.Password, true) // TODO: set this to false as soon as the interface is working
+ if code != http.StatusOK {
+ sendWebSocketErrorResponse(ws, code, errstring)
+ } else {
+ sendWebSocketListResponse(ws, list)
+ }
default:
sendWebSocketErrorResponse(ws, http.StatusBadRequest, fmt.Sprintf("unknown command '%s'", reqdata.Command))
}