public UrlAcl(HTTP_SERVICE_CONFIG_URLACL_SET urlacl) { this.UrlPrefix = urlacl.KeyDesc.pUrlPrefix; var match = Regex.Match(this.UrlPrefix, ":([0-9]+?)/"); var port = match.Groups[1].Value; this.Port = port; }
private void RemoveUrlAcl() { var retVal = PInvoke.HttpInitialize(new HTTPAPI_VERSION(2, 0), PInvoke.HTTP_INITIALIZE_CONFIG, IntPtr.Zero); if ((uint)PInvoke.NO_ERROR != retVal) { throw new Exception(string.Format("Could not set the initialize the HTTP API. Code {0}", retVal)); } var url = string.Format("http://{0}.ngrok.com:{1}/", this.Subdomain, this.LocalhostPort); HTTP_SERVICE_CONFIG_URLACL_KEY keyDesc = new HTTP_SERVICE_CONFIG_URLACL_KEY(url); HTTP_SERVICE_CONFIG_URLACL_PARAM paramDesc = new HTTP_SERVICE_CONFIG_URLACL_PARAM("D:(A;;GX;;;WD)"); HTTP_SERVICE_CONFIG_URLACL_SET inputConfigInfoSet = new HTTP_SERVICE_CONFIG_URLACL_SET(); inputConfigInfoSet.KeyDesc = keyDesc; inputConfigInfoSet.ParamDesc = paramDesc; IntPtr pInputConfigInfo = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_URLACL_SET))); Marshal.StructureToPtr(inputConfigInfoSet, pInputConfigInfo, false); retVal = PInvoke.HttpDeleteServiceConfiguration(IntPtr.Zero, HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo, pInputConfigInfo, Marshal.SizeOf(inputConfigInfoSet), IntPtr.Zero); if (PInvoke.NO_ERROR != retVal) { throw new Exception(string.Format("Could not remove the Url Acl. Code {0}", retVal)); } Marshal.FreeCoTaskMem(pInputConfigInfo); PInvoke.HttpTerminate(PInvoke.HTTP_INITIALIZE_CONFIG, IntPtr.Zero); _hasUrlAcl = false; }
private void Load() { var retVal = PInvoke.HttpInitialize(new HTTPAPI_VERSION(2, 0), PInvoke.HTTP_INITIALIZE_CONFIG, IntPtr.Zero); if ((uint)PInvoke.NO_ERROR != retVal) { throw new Exception(string.Format("Could not set the initialize the HTTP API. Code {0}", retVal)); } HTTP_SERVICE_CONFIG_URLACL_QUERY inputConfigInfoQuery = new HTTP_SERVICE_CONFIG_URLACL_QUERY(); inputConfigInfoQuery.QueryDesc = HTTP_SERVICE_CONFIG_QUERY_TYPE.HttpServiceConfigQueryNext; int i = 0; while (retVal == 0) { inputConfigInfoQuery.dwToken = (uint)i; IntPtr pInputConfigInfo = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_URLACL_QUERY))); Marshal.StructureToPtr(inputConfigInfoQuery, pInputConfigInfo, false); HTTP_SERVICE_CONFIG_URLACL_SET outputConfigInfo = new HTTP_SERVICE_CONFIG_URLACL_SET(); IntPtr pOutputConfigInfo = Marshal.AllocCoTaskMem(0); int returnLength = 0; retVal = PInvoke.HttpQueryServiceConfiguration(IntPtr.Zero, HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo, pInputConfigInfo, Marshal.SizeOf(inputConfigInfoQuery), pOutputConfigInfo, returnLength, out returnLength, IntPtr.Zero); if (PInvoke.ERROR_INSUFFICIENT_BUFFER == retVal) { //Marshal the proper buffer size back from the response Marshal.FreeCoTaskMem(pOutputConfigInfo); pOutputConfigInfo = Marshal.AllocCoTaskMem(Convert.ToInt32(returnLength)); retVal = PInvoke.HttpQueryServiceConfiguration(IntPtr.Zero, HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo, pInputConfigInfo, Marshal.SizeOf(inputConfigInfoQuery), pOutputConfigInfo, returnLength, out returnLength, IntPtr.Zero); } if (PInvoke.NO_ERROR == retVal) { outputConfigInfo = (HTTP_SERVICE_CONFIG_URLACL_SET)Marshal.PtrToStructure(pOutputConfigInfo, typeof(HTTP_SERVICE_CONFIG_URLACL_SET)); Debug.WriteLine(outputConfigInfo.KeyDesc.pUrlPrefix); this.UrlAcls.Add(new UrlAcl(outputConfigInfo)); Marshal.FreeCoTaskMem(pOutputConfigInfo); Marshal.FreeCoTaskMem(pInputConfigInfo); } else if (PInvoke.ERROR_NO_MORE_ITEMS==retVal) { Marshal.FreeCoTaskMem(pOutputConfigInfo); Marshal.FreeCoTaskMem(pInputConfigInfo); } else { Marshal.FreeCoTaskMem(pOutputConfigInfo); Marshal.FreeCoTaskMem(pInputConfigInfo); throw new Exception(string.Format("Could not list Url Acls. Code {0}", retVal)); } //Marshal.FreeCoTaskMem(pOutputConfigInfo); //Marshal.FreeCoTaskMem(pInputConfigInfo); i++; } PInvoke.HttpTerminate(PInvoke.HTTP_INITIALIZE_CONFIG, IntPtr.Zero); }