summaryrefslogtreecommitdiff
path: root/src/helsinki.at/rhimportd
diff options
context:
space:
mode:
Diffstat (limited to 'src/helsinki.at/rhimportd')
-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))
}