/// <summary>
        /// Deletes the given reservation from the HTTP.sys configuration.
        /// </summary>
        /// <param name="urlReservation">The reservation to delete.</param>
        public static void Delete(UrlReservation urlReservation)
        {
            string sddl = generateSddl(urlReservation._securityIdentifiers);

            freeURL(urlReservation.Url, sddl);
        }
        /// <summary>
        /// Creates the reservation in HTTP.sys.
        /// </summary>
        /// <param name="urlReservation">The reservation to create</param>
        /// <param name="deleteIfExists">If the given reservation exists, will delete the existing reservation and recreate it.</param>
        public static void Create(UrlReservation urlReservation, bool deleteIfExists = false)
        {
            string sddl = generateSddl(urlReservation._securityIdentifiers);

            reserveURL(urlReservation.Url, sddl, deleteIfExists);
        }
 /// <summary>
 /// Deletes this reservation from the HTTP.sys configuration.
 /// </summary>
 /// <exception cref="Win32Exception">Throw if an unexpected error occures while deleting the reservation.</exception>
 public void Delete() => UrlReservation.Delete(this);
        /// <summary>
        /// Returns a list of all configured URL reservations on this computer.
        /// </summary>
        /// <returns></returns>
        public static IReadOnlyList <UrlReservation> GetAll()
        {
            var  revs   = new List <UrlReservation>();
            uint retVal = NativeMethods.HttpInitialize(HTTPAPI_VERSION.VERSION_1, Flags.HTTP_INITIALIZE_CONFIG, IntPtr.Zero);

            if (retVal == ReturnCodes.NO_ERROR)
            {
                var inputConfigInfoSet = new HTTP_SERVICE_CONFIG_URLACL_QUERY
                {
                    QueryDesc = HTTP_SERVICE_CONFIG_QUERY_TYPE.HttpServiceConfigQueryNext
                };

                uint i = 0;
                while (retVal == ReturnCodes.NO_ERROR)
                {
                    inputConfigInfoSet.dwToken = i;

                    IntPtr pInputConfigInfo = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(HTTP_SERVICE_CONFIG_URLACL_QUERY)));
                    Marshal.StructureToPtr(inputConfigInfoSet, pInputConfigInfo, false);

                    var    outputConfigInfo  = new HTTP_SERVICE_CONFIG_URLACL_SET();
                    IntPtr pOutputConfigInfo = Marshal.AllocCoTaskMem(0);

                    int returnLength = 0;
                    retVal = NativeMethods.HttpQueryServiceConfiguration(IntPtr.Zero,
                                                                         HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo,
                                                                         pInputConfigInfo,
                                                                         Marshal.SizeOf(inputConfigInfoSet),
                                                                         pOutputConfigInfo,
                                                                         returnLength,
                                                                         out returnLength,
                                                                         IntPtr.Zero);

                    if (retVal == ReturnCodes.ERROR_INSUFFICIENT_BUFFER)
                    {
                        Marshal.FreeCoTaskMem(pOutputConfigInfo);
                        pOutputConfigInfo = Marshal.AllocCoTaskMem(Convert.ToInt32(returnLength));

                        retVal = NativeMethods.HttpQueryServiceConfiguration(IntPtr.Zero,
                                                                             HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo,
                                                                             pInputConfigInfo,
                                                                             Marshal.SizeOf(inputConfigInfoSet),
                                                                             pOutputConfigInfo,
                                                                             returnLength,
                                                                             out returnLength,
                                                                             IntPtr.Zero);
                    }

                    if (retVal == ReturnCodes.NO_ERROR)
                    {
                        outputConfigInfo = (HTTP_SERVICE_CONFIG_URLACL_SET)Marshal.PtrToStructure(pOutputConfigInfo, typeof(HTTP_SERVICE_CONFIG_URLACL_SET));
                        UrlReservation rev = new UrlReservation(outputConfigInfo.KeyDesc.pUrlPrefix, securityIdentifiersFromSDDL(outputConfigInfo.ParamDesc.pStringSecurityDescriptor));
                        revs.Add(rev);
                    }

                    Marshal.FreeCoTaskMem(pOutputConfigInfo);
                    Marshal.FreeCoTaskMem(pInputConfigInfo);

                    i++;
                }
                retVal = NativeMethods.HttpTerminate(Flags.HTTP_INITIALIZE_CONFIG, IntPtr.Zero);
            }

            if (retVal != ReturnCodes.NO_ERROR)
            {
                throw new Win32Exception(Convert.ToInt32(retVal));
            }
            return(revs);
        }
 /// <summary>
 /// Creates the reservation in HTTP.sys.
 /// </summary>
 /// <param name="deleteIfExists">If the given reservation exists, will delete the existing reservation and recreate it.</param>
 /// <exception cref="ArgumentException">Thrown if a reservation for this URL already exists.</exception>
 /// <exception cref="Win32Exception">Throw if an unexpected error occures while creating the reservation.</exception>
 public void Create(bool deleteIfExists = false) => UrlReservation.Create(this, deleteIfExists);