Esempio n. 1
0
        internal static AGDnsApi.ag_upstream_options ToNativeObject(
            UpstreamOptions upstreamOptions,
            Queue <IntPtr> allocatedPointers)
        {
            MarshalUtils.ag_list bootstrapC = MarshalUtils.ListToAgList(
                upstreamOptions.Bootstrap,
                MarshalUtils.StringToPtr,
                allocatedPointers);

            byte[] addressBytes = null;
            if (upstreamOptions.ResolvedIpAddress != null)
            {
                addressBytes = upstreamOptions.ResolvedIpAddress.GetAddressBytes();
            }

            MarshalUtils.ag_buffer addressC = MarshalUtils.BytesToAgBuffer(addressBytes);

            if (allocatedPointers != null)
            {
                allocatedPointers.Enqueue(addressC.data);
            }

            AGDnsApi.ag_upstream_options upstreamOptionsC = new AGDnsApi.ag_upstream_options
            {
                bootstrap           = bootstrapC,
                resolved_ip_address = addressC
            };

            MarshalUtils.CopyPropertiesToFields(upstreamOptions, ref upstreamOptionsC);
            MarshalUtils.AllStringsToPtrs(upstreamOptions, ref upstreamOptionsC, allocatedPointers);
            return(upstreamOptionsC);
        }
Esempio n. 2
0
        /// <summary>
        /// Converts the managed <see cref="dnsProxySettings"/>
        /// (<seealso cref="DnsProxySettings"/>) to the native <see cref="AGDnsApi.ag_dnsproxy_settings"/> object
        /// </summary>
        /// <param name="dnsProxySettings"><see cref="DnsProxySettings"/> instance to convert</param>
        /// <param name="allocatedPointers">List of pointers, which were allocated.
        /// Pointers, which will be referred to a newly allocated memory
        /// (within the process of marshaling the string to the pointer)
        /// will be added to this list.
        /// If this list is not specified (null),
        /// a new created pointer will not be added anywhere</param>
        /// The resulting pointer (<seealso cref="IntPtr"/>) must be freed
        /// with <see cref="MarshalUtils.SafeFreeHGlobal(IntPtr)"/>>
        /// <returns>An instance of <see cref="AGDnsApi.ag_dnsproxy_settings"/></returns>
        internal static AGDnsApi.ag_dnsproxy_settings ToNativeObject(
            DnsProxySettings dnsProxySettings,
            Queue <IntPtr> allocatedPointers)
        {
            MarshalUtils.ag_list upstreamsC = MarshalUtils.ListToAgList(
                dnsProxySettings.Upstreams,
                ToNativeObject,
                allocatedPointers);

            MarshalUtils.ag_list fallbacksC = MarshalUtils.ListToAgList(
                dnsProxySettings.Fallbacks,
                ToNativeObject,
                allocatedPointers);

            MarshalUtils.ag_list fallbackDomains = MarshalUtils.ListToAgList(
                dnsProxySettings.FallbackDomains,
                MarshalUtils.StringToPtr,
                allocatedPointers);

            IntPtr pDns64C = IntPtr.Zero;

            if (dnsProxySettings.Dns64 != null)
            {
                AGDnsApi.ag_dns64_settings dns64C =
                    ToNativeObject(dnsProxySettings.Dns64, allocatedPointers);
                pDns64C = MarshalUtils.StructureToPtr(dns64C, allocatedPointers);
            }

            AGDnsApi.ag_filter_engine_params filterEngineParamsC =
                ToNativeObject(dnsProxySettings.EngineParams, allocatedPointers);
            MarshalUtils.ag_list listenersC = MarshalUtils.ListToAgList(
                dnsProxySettings.Listeners,
                ToNativeObject,
                allocatedPointers);

            IntPtr pOutboundProxySessionC = IntPtr.Zero;

            if (dnsProxySettings.OutboundProxySettings != null)
            {
                AGDnsApi.ag_outbound_proxy_settings outboundProxySettingsC =
                    ToNativeObject(dnsProxySettings.OutboundProxySettings, allocatedPointers);
                pOutboundProxySessionC = MarshalUtils.StructureToPtr(outboundProxySettingsC, allocatedPointers);
            }

            AGDnsApi.ag_dnsproxy_settings dnsProxySettingsC = new AGDnsApi.ag_dnsproxy_settings
            {
                upstreams       = upstreamsC,
                fallbacks       = fallbacksC,
                pDns64          = pDns64C,
                FilterParams    = filterEngineParamsC,
                listeners       = listenersC,
                outbound_proxy  = pOutboundProxySessionC,
                fallbackDomains = fallbackDomains,
            };

            MarshalUtils.CopyPropertiesToFields(dnsProxySettings, ref dnsProxySettingsC);
            MarshalUtils.AllStringsToPtrs(dnsProxySettings, ref dnsProxySettingsC, allocatedPointers);
            return(dnsProxySettingsC);
        }
Esempio n. 3
0
        private static AGDnsApi.ag_filter_engine_params ToNativeObject(
            EngineParams engineParams,
            Queue <IntPtr> allocatedPointers)
        {
            MarshalUtils.ag_list filterParamsC = MarshalUtils.ListToAgList(
                engineParams.FilterParams,
                ToNativeObject,
                allocatedPointers);
            AGDnsApi.ag_filter_engine_params filterEngineParamsC = new AGDnsApi.ag_filter_engine_params
            {
                filters = filterParamsC
            };

            return(filterEngineParamsC);
        }
Esempio n. 4
0
        private static AGDnsApi.ag_dns64_settings ToNativeObject(
            Dns64Settings dns64,
            Queue <IntPtr> allocatedPointers)
        {
            MarshalUtils.ag_list dns64upstreamsC = MarshalUtils.ListToAgList(
                dns64.Upstreams,
                ToNativeObject,
                allocatedPointers);

            AGDnsApi.ag_dns64_settings dns64C = new AGDnsApi.ag_dns64_settings
            {
                upstreams = dns64upstreamsC
            };

            MarshalUtils.CopyPropertiesToFields(dns64, ref dns64C);
            return(dns64C);
        }
Esempio n. 5
0
 public static AGDnsApi.ag_dns_stamp ToNativeObject(
     DnsStamp dnsStamp,
     Queue <IntPtr> allocatedPointers)
 {
     MarshalUtils.ag_buffer publicKeyC = MarshalUtils.BytesToAgBuffer(dnsStamp.PublicKey);
     MarshalUtils.ag_list   hashesC    = MarshalUtils.ListToAgList(
         dnsStamp.Hashes,
         (x, y) => MarshalUtils.BytesToAgBuffer(x),
         allocatedPointers);
     AGDnsApi.ag_dns_stamp dnsStampС = new AGDnsApi.ag_dns_stamp
     {
         ProtoType         = dnsStamp.ProtoType,
         ServerAddress     = MarshalUtils.StringToPtr(dnsStamp.ServerAddress),
         ProviderName      = MarshalUtils.StringToPtr(dnsStamp.ProviderName),
         DoHPath           = MarshalUtils.StringToPtr(dnsStamp.DoHPath),
         server_public_key = publicKeyC,
         hashes            = hashesC,
         Properties        = dnsStamp.Properties
     };
     return(dnsStampС);
 }