- Timestamp:
- Jan 19, 2019, 6:12:21 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Web/Handlers/ApiHandler.cs
r332 r351 11 11 private readonly string staticPart; 12 12 13 public ApiHandler (string staticPart, string moduleName = null) : base (moduleName) {14 this.staticPart =staticPart;13 public ApiHandler (string _staticPart, string _moduleName = null) : base (_moduleName) { 14 staticPart = _staticPart; 15 15 16 16 foreach (Type t in Assembly.GetExecutingAssembly ().GetTypes ()) { … … 45 45 #endif 46 46 47 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 48 int permissionLevel) { 49 string apiName = req.Url.AbsolutePath.Remove (0, staticPart.Length); 50 if (!AuthorizeForCommand (apiName, user, permissionLevel)) { 51 resp.StatusCode = (int) HttpStatusCode.Forbidden; 52 if (user != null) { 47 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 48 int _permissionLevel) { 49 string apiName = _req.Url.AbsolutePath.Remove (0, staticPart.Length); 50 51 WebAPI api; 52 if (!apis.TryGetValue (apiName, out api)) { 53 Log.Out ("Error in ApiHandler.HandleRequest(): No handler found for API \"" + apiName + "\""); 54 _resp.StatusCode = (int) HttpStatusCode.NotFound; 55 return; 56 } 57 58 if (!AuthorizeForCommand (apiName, _user, _permissionLevel)) { 59 _resp.StatusCode = (int) HttpStatusCode.Forbidden; 60 if (_user != null) { 53 61 //Log.Out ("ApiHandler: user '{0}' not allowed to execute '{1}'", user.SteamID, apiName); 54 62 } … … 57 65 } 58 66 59 WebAPI api; 60 if (apis.TryGetValue (apiName, out api)) { 61 try { 67 try { 62 68 #if ENABLE_PROFILER 63 69 apiHandlerSampler.Begin (); 64 70 #endif 65 api.HandleRequest (req, resp, user,permissionLevel);71 api.HandleRequest (_req, _resp, _user, _permissionLevel); 66 72 #if ENABLE_PROFILER 67 73 apiHandlerSampler.End (); 68 74 #endif 69 return; 70 } catch (Exception e) { 71 Log.Error ("Error in ApiHandler.HandleRequest(): Handler {0} threw an exception:", api.Name); 72 Log.Exception (e); 73 resp.StatusCode = (int) HttpStatusCode.InternalServerError; 74 return; 75 } 75 } catch (Exception e) { 76 Log.Error ("Error in ApiHandler.HandleRequest(): Handler {0} threw an exception:", api.Name); 77 Log.Exception (e); 78 _resp.StatusCode = (int) HttpStatusCode.InternalServerError; 76 79 } 77 78 Log.Out ("Error in ApiHandler.HandleRequest(): No handler found for API \"" + apiName + "\"");79 resp.StatusCode = (int) HttpStatusCode.NotFound;80 80 } 81 81 82 private bool AuthorizeForCommand (string apiName, WebConnection user, intpermissionLevel) {83 return WebPermissions.Instance.ModuleAllowedWithLevel ("webapi." + apiName,permissionLevel);82 private bool AuthorizeForCommand (string _apiName, WebConnection _user, int _permissionLevel) { 83 return WebPermissions.Instance.ModuleAllowedWithLevel ("webapi." + _apiName, _permissionLevel); 84 84 } 85 85 }
Note:
See TracChangeset
for help on using the changeset viewer.