Exemple #1
0
        public static Hashtable QueryConfig()
        {
            Hashtable items = new Hashtable();

            HttpApi.HTTP_SERVICE_CONFIG_URLACL_QUERY query = new HttpApi.HTTP_SERVICE_CONFIG_URLACL_QUERY();

            query.QueryDesc = HttpApi.HTTP_SERVICE_CONFIG_QUERY_TYPE.HttpServiceConfigQueryNext;

            HttpApi.Error error = HttpApi.Error.NO_ERROR;

            IntPtr pInput = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HttpApi.HTTP_SERVICE_CONFIG_URLACL_QUERY)));

            try
            {
                for (query.dwToken = 0; ; query.dwToken++)
                {
                    Marshal.StructureToPtr(query, pInput, false);

                    int requiredBufferLength = 0;

                    error = QueryServiceConfig(pInput, IntPtr.Zero, 0, out requiredBufferLength);

                    if (error == HttpApi.Error.ERROR_NO_MORE_ITEMS)
                    {
                        break;
                    }
                    else if (error != HttpApi.Error.ERROR_INSUFFICIENT_BUFFER)
                    {
                        throw new HttpApiException(error, "HttpQueryServiceConfiguration (URLACL) failed.  Error = " + error);
                    }

                    IntPtr pOutput = Marshal.AllocHGlobal(requiredBufferLength);

                    try
                    {
                        HttpApi.ZeroMemory(pOutput, requiredBufferLength);

                        error = QueryServiceConfig(pInput, pOutput, requiredBufferLength, out requiredBufferLength);

                        if (error != HttpApi.Error.NO_ERROR)
                        {
                            throw new HttpApiException(error, "HttpQueryServiceConfiguration (URLACL) failed.  Error = " + error);
                        }

                        UrlAclConfigItem item = Deserialize(pOutput);

                        items.Add(item.Key, item);
                    }
                    finally
                    {
                        Marshal.FreeHGlobal(pOutput);
                    }
                }
            }
            finally
            {
                Marshal.FreeHGlobal(pInput);
            }

            return(items);
        }
        internal static Dictionary<string, UrlAclConfigItem> QueryConfig()
        {
            Dictionary<string, UrlAclConfigItem> items = new Dictionary<string, UrlAclConfigItem>();

            HttpApi.HTTP_SERVICE_CONFIG_URLACL_QUERY query = new HttpApi.HTTP_SERVICE_CONFIG_URLACL_QUERY();

            query.QueryDesc = HttpApi.HTTP_SERVICE_CONFIG_QUERY_TYPE.HttpServiceConfigQueryNext;
            
            HttpApi.Error error = HttpApi.Error.NO_ERROR;

            IntPtr pInput = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HttpApi.HTTP_SERVICE_CONFIG_URLACL_QUERY)));

            try
            {
                for(query.dwToken = 0; ; query.dwToken++)
                {
                    Marshal.StructureToPtr(query, pInput, false);

                    int requiredBufferLength = 0;
                    
                    error = QueryServiceConfig(pInput, IntPtr.Zero, 0, out requiredBufferLength);

                    if(error == HttpApi.Error.ERROR_NO_MORE_ITEMS)
                        break;
                    else if(error != HttpApi.Error.ERROR_INSUFFICIENT_BUFFER)
                        ErrorCheck.VerifySuccess(error, "HttpQueryServiceConfiguration (URLACL) failed.");

                    IntPtr pOutput = Marshal.AllocHGlobal(requiredBufferLength);

                    try
                    {
                        HttpApi.ZeroMemory(pOutput, requiredBufferLength);

                        error = QueryServiceConfig(pInput, pOutput, requiredBufferLength, out requiredBufferLength);

                        ErrorCheck.VerifySuccess(error, "HttpQueryServiceConfiguration (URLACL) failed.");
                        
                        UrlAclConfigItem item = Deserialize(pOutput);

                        items.Add(item.Key, item);
                    }
                    finally
                    {
                        Marshal.FreeHGlobal(pOutput);
                    }
                }
            }
            finally
            {
                Marshal.FreeHGlobal(pInput);
            }            

            return items;
        }