summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/helsinki.at/rhimportd/ctrlWebSocket.go49
1 files changed, 28 insertions, 21 deletions
diff --git a/src/helsinki.at/rhimportd/ctrlWebSocket.go b/src/helsinki.at/rhimportd/ctrlWebSocket.go
index 93134fd..b3f10f6 100644
--- a/src/helsinki.at/rhimportd/ctrlWebSocket.go
+++ b/src/helsinki.at/rhimportd/ctrlWebSocket.go
@@ -83,7 +83,31 @@ func sendWebSocketErrorResponse(ws *websocket.Conn, code int, err_str string) {
}
}
-func webSocketSessionHandler() {
+func webSocketSessionHandler(reqchan <-chan webSocketRequestData, ws *websocket.Conn) {
+ defer ws.Close()
+
+ select {
+ case reqdata := <-reqchan:
+ switch reqdata.Command {
+ case "new":
+ sendWebSocketErrorResponse(ws, http.StatusNotImplemented, "new session - not yet implemented")
+ return
+ case "reconnect":
+ if reqdata.UserName == "" {
+ sendWebSocketErrorResponse(ws, http.StatusBadRequest, "missing mandotary field LOGIN_NAME")
+ return
+ }
+ if reqdata.Id == "" {
+ sendWebSocketErrorResponse(ws, http.StatusBadRequest, "missing mandotary field ID")
+ return
+ }
+ sendWebSocketErrorResponse(ws, http.StatusNotImplemented, "reconnect session - not yet implemented")
+ return
+ default:
+ sendWebSocketErrorResponse(ws, http.StatusBadRequest, fmt.Sprintf("unknown command '%s'", reqdata.Command))
+ return
+ }
+ }
}
func webSocketHandler(conf *rhimport.Config, rddb *rhimport.RdDbChan, sessions *rhimport.SessionStoreChan, trusted bool, w http.ResponseWriter, r *http.Request) {
@@ -98,6 +122,8 @@ func webSocketHandler(conf *rhimport.Config, rddb *rhimport.RdDbChan, sessions *
return
}
rhdl.Println("WebSocket Client", ws.RemoteAddr(), "connected")
+ reqchan := make(chan webSocketRequestData)
+ go webSocketSessionHandler(reqchan, ws)
for {
reqdata := newWebSocketRequestData(conf)
@@ -109,26 +135,7 @@ func webSocketHandler(conf *rhimport.Config, rddb *rhimport.RdDbChan, sessions *
if trusted {
reqdata.UserName = r.Header.Get("X-Forwarded-User")
}
-
- switch reqdata.Command {
- case "new":
- sendWebSocketErrorResponse(ws, http.StatusNotImplemented, "new session - not yet implemented")
- return
- case "reconnect":
- if reqdata.UserName == "" {
- sendWebSocketErrorResponse(ws, http.StatusBadRequest, "missing mandotary field LOGIN_NAME")
- return
- }
- if reqdata.Id == "" {
- sendWebSocketErrorResponse(ws, http.StatusBadRequest, "missing mandotary field ID")
- return
- }
- sendWebSocketErrorResponse(ws, http.StatusNotImplemented, "get session - not yet implemented")
- return
- default:
- sendWebSocketErrorResponse(ws, http.StatusBadRequest, fmt.Sprintf("unknown command '%s'", reqdata.Command))
- return
- }
+ reqchan <- *reqdata
}
}