public Hashtable Handler(Hashtable request) { //m_log.Debug("[CONNECTION DEBUGGING]: ObjectHandler Called"); //m_log.Debug("---------------------------"); //m_log.Debug(" >> uri=" + request["uri"]); //m_log.Debug(" >> content-type=" + request["content-type"]); //m_log.Debug(" >> http-method=" + request["http-method"]); //m_log.Debug("---------------------------\n"); Hashtable responsedata = new Hashtable(); responsedata["content_type"] = "text/html"; UUID objectID; UUID regionID; string action; if (!Utils.GetParams((string)request["uri"], out objectID, out regionID, out action)) { m_log.InfoFormat("[OBJECT HANDLER]: Invalid parameters for object message {0}", request["uri"]); responsedata["int_response_code"] = 404; responsedata["str_response_string"] = "false"; return(responsedata); } try { // Next, let's parse the verb string method = (string)request["http-method"]; if (method.Equals("POST")) { DoObjectPost(request, responsedata, regionID); return(responsedata); } //else if (method.Equals("DELETE")) //{ // DoObjectDelete(request, responsedata, agentID, action, regionHandle); // return responsedata; //} else { m_log.InfoFormat("[OBJECT HANDLER]: method {0} not supported in object message", method); responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed; responsedata["str_response_string"] = "Method not allowed"; return(responsedata); } } catch (Exception e) { m_log.WarnFormat("[OBJECT HANDLER]: Caught exception {0}", e.StackTrace); responsedata["int_response_code"] = HttpStatusCode.InternalServerError; responsedata["str_response_string"] = "Internal server error"; return(responsedata); } }
public Hashtable Handler(Hashtable request) { if (m_log.IsDebugEnabled) { m_log.Debug("[CONNECTION DEBUGGING]: AgentHandler Called"); m_log.Debug("---------------------------"); m_log.Debug(" >> uri=" + request ["uri"]); m_log.Debug(" >> content-type=" + request ["content-type"]); m_log.Debug(" >> http-method=" + request ["http-method"]); m_log.Debug("---------------------------\n"); } Hashtable responsedata = new Hashtable(); responsedata["content_type"] = "text/html"; responsedata["keepalive"] = false; UUID agentID; UUID regionID; string action; if (!Utils.GetParams((string)request["uri"], out agentID, out regionID, out action)) { m_log.InfoFormat("[AGENT HANDLER]: Invalid parameters for agent message {0}", request["uri"]); responsedata["int_response_code"] = 404; responsedata["str_response_string"] = "false"; return(responsedata); } // Next, let's parse the verb string method = (string)request["http-method"]; if (method.Equals("DELETE")) { string auth_token = string.Empty; if (request.ContainsKey("auth")) { auth_token = request["auth"].ToString(); } DoAgentDelete(request, responsedata, agentID, action, regionID, auth_token); return(responsedata); } else if (method.Equals("QUERYACCESS")) { DoQueryAccess(request, responsedata, agentID, regionID); return(responsedata); } else { m_log.ErrorFormat("[AGENT HANDLER]: method {0} not supported in agent message {1} (caller is {2})", method, (string)request["uri"], Util.GetCallerIP(request)); responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed; responsedata["str_response_string"] = "Method not allowed"; return(responsedata); } }
public Hashtable Handler(Hashtable request) { // m_log.Debug("[CONNECTION DEBUGGING]: AgentHandler Called"); // // m_log.Debug("---------------------------"); // m_log.Debug(" >> uri=" + request["uri"]); // m_log.Debug(" >> content-type=" + request["content-type"]); // m_log.Debug(" >> http-method=" + request["http-method"]); // m_log.Debug("---------------------------\n"); Hashtable responsedata = new Hashtable(); responsedata["content_type"] = "text/html"; responsedata["keepalive"] = false; UUID agentID; UUID regionID; string action; if (!Utils.GetParams((string)request["uri"], out agentID, out regionID, out action)) { m_log.InfoFormat("[AGENT HANDLER]: Invalid parameters for agent message {0}", request["uri"]); responsedata["int_response_code"] = 404; responsedata["str_response_string"] = "false"; return(responsedata); } // Next, let's parse the verb string method = (string)request["http-method"]; if (method.Equals("GET")) { DoAgentGet(request, responsedata, agentID, regionID); return(responsedata); } else if (method.Equals("DELETE")) { DoAgentDelete(request, responsedata, agentID, action, regionID); return(responsedata); } else if (method.Equals("QUERYACCESS")) { DoQueryAccess(request, responsedata, agentID, regionID); return(responsedata); } else { m_log.InfoFormat("[AGENT HANDLER]: method {0} not supported in agent message", method); responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed; responsedata["str_response_string"] = "Method not allowed"; return(responsedata); } }
protected override void ProcessRequest(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { // m_log.DebugFormat("[SIMULATION]: Stream handler called"); httpResponse.ContentType = "text/html"; //?? httpResponse.KeepAlive = false; if (httpRequest.HttpMethod != "POST") { httpResponse.StatusCode = (int)HttpStatusCode.MethodNotAllowed; httpResponse.RawBuffer = Utils.falseStrBytes; } if (httpRequest.ContentType != "application/json" && httpRequest.ContentType != "application/x-gzip") { httpResponse.StatusCode = (int)HttpStatusCode.NotAcceptable; httpResponse.RawBuffer = Utils.falseStrBytes; } UUID agentID; UUID regionID; string action; if (!Utils.GetParams(httpRequest.UriPath, out agentID, out regionID, out action)) { m_log.InfoFormat("[AGENT HANDLER]: Invalid parameters for agent message {0}", httpRequest.RawUrl); httpResponse.StatusCode = (int)HttpStatusCode.NotFound; httpResponse.RawBuffer = Utils.falseStrBytes; } OSDMap args = Utils.DeserializeJSONOSMap(httpRequest); if (args == null) { httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; httpResponse.RawBuffer = Utils.falseStrBytes; } DoAgentPost(args, httpRequest.RemoteIPEndPoint.Address.ToString(), httpResponse, agentID); httpResponse.StatusCode = 200; }
protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { // m_log.DebugFormat("[SIMULATION]: Stream handler called"); Hashtable keysvals = new Hashtable(); Hashtable headervals = new Hashtable(); string[] querystringkeys = httpRequest.QueryString.AllKeys; string[] rHeaders = httpRequest.Headers.AllKeys; keysvals.Add("uri", httpRequest.RawUrl); keysvals.Add("content-type", httpRequest.ContentType); keysvals.Add("http-method", httpRequest.HttpMethod); foreach (string queryname in querystringkeys) { keysvals.Add(queryname, httpRequest.QueryString[queryname]); } foreach (string headername in rHeaders) { headervals[headername] = httpRequest.Headers[headername]; } keysvals.Add("headers", headervals); keysvals.Add("querystringkeys", querystringkeys); String requestBody; Encoding encoding = Encoding.UTF8; Stream inputStream = request; Stream innerStream = null; try { if ((httpRequest.ContentType == "application/x-gzip" || httpRequest.Headers["Content-Encoding"] == "gzip") || (httpRequest.Headers["X-Content-Encoding"] == "gzip")) { innerStream = inputStream; inputStream = new GZipStream(innerStream, CompressionMode.Decompress); } using (StreamReader reader = new StreamReader(inputStream, encoding)) { requestBody = reader.ReadToEnd(); } } finally { if (innerStream != null) { innerStream.Dispose(); } inputStream.Dispose(); } keysvals.Add("body", requestBody); httpResponse.StatusCode = 200; httpResponse.ContentType = "text/html"; httpResponse.KeepAlive = false; Hashtable responsedata = new Hashtable(); UUID agentID; UUID regionID; string action; if (!Utils.GetParams((string)keysvals["uri"], out agentID, out regionID, out action)) { m_log.InfoFormat("[AGENT HANDLER]: Invalid parameters for agent message {0}", keysvals["uri"]); httpResponse.StatusCode = 404; return(encoding.GetBytes("false")); } DoAgentPut(keysvals, responsedata); httpResponse.StatusCode = (int)responsedata["int_response_code"]; return(encoding.GetBytes((string)responsedata["str_response_string"])); }
protected override void ProcessRequest(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { httpResponse.KeepAlive = false; httpResponse.ContentType = "application/json"; if (m_SimulationService == null) { httpResponse.StatusCode = (int)HttpStatusCode.InternalServerError; httpResponse.RawBuffer = Util.UTF8.GetBytes("false"); return; } if (!Utils.GetParams(httpRequest.UriPath, out UUID agentID, out UUID regionID, out string action)) { m_log.InfoFormat("[AGENT HANDLER]: Invalid parameters for agent message {0}", httpRequest.UriPath); httpResponse.StatusCode = (int)HttpStatusCode.NotFound; httpResponse.RawBuffer = Util.UTF8.GetBytes("false"); return; } switch (httpRequest.HttpMethod) { case "QUERYACCESS": { if (agentID == UUID.Zero || regionID == UUID.Zero) { httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; httpResponse.RawBuffer = Util.UTF8.GetBytes("false"); return; } OSDMap args = Deserialize(httpRequest); if (args == null) { httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; httpResponse.RawBuffer = Util.UTF8.GetBytes("false"); return; } DoQueryAccess(args, httpResponse, agentID, regionID); break; } case "PUT": { OSDMap args = Deserialize(httpRequest); if (args == null) { httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; httpResponse.RawBuffer = Util.UTF8.GetBytes("false"); return; } DoAgentPut(args, httpResponse); break; } case "POST": { if (agentID == UUID.Zero) { httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; httpResponse.RawBuffer = Util.UTF8.GetBytes("false"); return; } OSDMap args = Deserialize(httpRequest); if (args == null) { httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; httpResponse.RawBuffer = Util.UTF8.GetBytes("false"); return; } DoAgentPost(args, httpRequest, httpResponse, agentID); break; } case "DELETE": { if (agentID == UUID.Zero || regionID == UUID.Zero) { httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; httpResponse.RawBuffer = Util.UTF8.GetBytes("false"); return; } httpRequest.QueryAsDictionary.TryGetValue("auth", out string auth_token); DoAgentDelete(httpRequest, httpResponse, agentID, action, regionID, auth_token); break; } default: { httpResponse.StatusCode = (int)HttpStatusCode.MethodNotAllowed; httpResponse.RawBuffer = Util.UTF8.GetBytes("false"); return; } } }
protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { if (m_log.IsDebugEnabled) { m_log.DebugFormat("{0} called", System.Reflection.MethodBase.GetCurrentMethod().Name); } Hashtable keysvals = new Hashtable(); Hashtable headervals = new Hashtable(); string[] querystringkeys = httpRequest.QueryString.AllKeys; string[] rHeaders = httpRequest.Headers.AllKeys; keysvals.Add("uri", httpRequest.RawUrl); keysvals.Add("content-type", httpRequest.ContentType); keysvals.Add("http-method", httpRequest.HttpMethod); foreach (string queryname in querystringkeys) { keysvals.Add(queryname, httpRequest.QueryString[queryname]); } foreach (string headername in rHeaders) { headervals[headername] = httpRequest.Headers[headername]; } keysvals.Add("headers", headervals); keysvals.Add("querystringkeys", querystringkeys); Stream inputStream; if (httpRequest.ContentType == "application/x-gzip") { inputStream = new GZipStream(request, CompressionMode.Decompress); } else { inputStream = request; } Encoding encoding = Encoding.UTF8; StreamReader reader = new StreamReader(inputStream, encoding); string requestBody = reader.ReadToEnd(); reader.Close(); keysvals.Add("body", requestBody); httpResponse.StatusCode = 200; httpResponse.ContentType = "text/html"; httpResponse.KeepAlive = false; Hashtable responsedata = new Hashtable(); UUID agentID; UUID regionID; string action; if (!Utils.GetParams((string)keysvals["uri"], out agentID, out regionID, out action)) { m_log.InfoFormat("[AGENT HANDLER]: Invalid parameters for agent message {0}", keysvals["uri"]); httpResponse.StatusCode = 404; return(encoding.GetBytes("false")); } DoAgentPut(keysvals, responsedata); httpResponse.StatusCode = (int)responsedata["int_response_code"]; return(encoding.GetBytes((string)responsedata["str_response_string"])); }