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

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

            AGDnsApi.ag_buffer           addressC         = MarshalUtils.BytesToAgBuffer(addressBytes, allocatedPointers);
            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);
        }
Beispiel #2
0
        private static AGDnsApi.ag_outbound_proxy_settings ToNativeObject(
            OutboundProxySettings outboundProxySettings,
            Queue <IntPtr> allocatedPointers)
        {
            IntPtr pOutboundProxyAuthInfoC = IntPtr.Zero;

            if (outboundProxySettings.AuthInfo != null)
            {
                AGDnsApi.ag_outbound_proxy_auth_info outboundProxyAuthInfoC = ToNativeObject(
                    outboundProxySettings.AuthInfo,
                    allocatedPointers);
                pOutboundProxyAuthInfoC = MarshalUtils.StructureToPtr(
                    outboundProxyAuthInfoC,
                    allocatedPointers);
            }

            AGDnsApi.ag_outbound_proxy_settings outboundProxySettingsC =
                new AGDnsApi.ag_outbound_proxy_settings
            {
                auth_info = pOutboundProxyAuthInfoC
            };

            MarshalUtils.CopyPropertiesToFields(outboundProxySettings, ref outboundProxySettingsC);
            MarshalUtils.AllStringsToPtrs(
                outboundProxySettings,
                ref outboundProxySettingsC,
                allocatedPointers);

            return(outboundProxySettingsC);
        }
Beispiel #3
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);
        }
Beispiel #4
0
 private static AGDnsApi.ag_filter_params ToNativeObject(
     FilterParams filterParams,
     Queue <IntPtr> allocatedPointers)
 {
     AGDnsApi.ag_filter_params filterParamsC = new AGDnsApi.ag_filter_params();
     MarshalUtils.CopyPropertiesToFields(filterParams, ref filterParamsC);
     MarshalUtils.AllStringsToPtrs(filterParams, ref filterParamsC, allocatedPointers);
     return(filterParamsC);
 }
Beispiel #5
0
 private static AGDnsApi.ag_outbound_proxy_auth_info ToNativeObject(
     OutboundProxyAuthInfo outboundProxyAuthInfo,
     Queue <IntPtr> allocatedPointers)
 {
     AGDnsApi.ag_outbound_proxy_auth_info outboundProxyAuthInfoC =
         new AGDnsApi.ag_outbound_proxy_auth_info();
     MarshalUtils.CopyPropertiesToFields(outboundProxyAuthInfo, ref outboundProxyAuthInfoC);
     MarshalUtils.AllStringsToPtrs(
         outboundProxyAuthInfo,
         ref outboundProxyAuthInfoC,
         allocatedPointers);
     return(outboundProxyAuthInfoC);
 }