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); }
/// <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); }