Пример #1
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);
        }
Пример #2
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);
        }
Пример #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);
        }
Пример #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);
 }
Пример #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);
 }
Пример #6
0
        private static AGDnsApi.ag_dns64_settings ToNativeObject(
            Dns64Settings dns64,
            Queue <IntPtr> allocatedPointers)
        {
            AGDnsApi.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);
        }
Пример #7
0
        /// <summary>
        /// Converts the managed <see cref="listenerSettings"/>
        /// (<seealso cref="ListenerSettings"/>) to the native <see cref="AGDnsApi.ag_listener_settings"/> object
        /// </summary>
        /// <param name="listenerSettings"><see cref="ListenerSettings"/> 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_listener_settings"/></returns>
        private static AGDnsApi.ag_listener_settings ToNativeObject(
            ListenerSettings listenerSettings,
            Queue <IntPtr> allocatedPointers)
        {
            ushort port    = (ushort)listenerSettings.EndPoint.Port;
            IntPtr address = MarshalUtils.StringToPtr(
                listenerSettings.EndPoint.Address.ToString(),
                allocatedPointers);

            AGDnsApi.ag_listener_settings listenerSettingsC = new AGDnsApi.ag_listener_settings
            {
                address = address,
                port    = port
            };

            MarshalUtils.CopyPropertiesToFields(listenerSettings, ref listenerSettingsC);
            return(listenerSettingsC);
        }