/// <summary> /// This method is called from the CoreLibs and passed to managed code /// </summary> /// <param name="attachment">Pointer to the native logger</param> /// <param name="logLevel">Log level</param> /// <param name="pMessage">Pointer to the log message</param> /// <param name="length">Message length</param> private static void AGOnDnsLogged( IntPtr attachment, AGDnsApi.ag_log_level logLevel, IntPtr pMessage, UInt32 length) { try { LogBylogLevel logByLogLevel = LOG_LEVELS_MAPPING[logLevel]; MarshalUtils.ag_buffer agBuffer = new MarshalUtils.ag_buffer { data = pMessage, size = length }; string message = MarshalUtils.AgBufferToString(agBuffer); // We have to forcibly trim trailing CR due to // https://bit.adguard.com/projects/ADGUARD-CORE-LIBS/repos/dns-libs/pull-requests/306/diff#platform/windows/capi/include/ag_dns.h message = message.TrimEnd(Environment.NewLine.ToCharArray()); logByLogLevel(message); } catch (Exception ex) { DnsExceptionHandler.HandleManagedException(ex); } }
/// <summary> /// <see cref="AGDnsApi.AGDnsProxyServerCallbacks.ag_dns_request_processed_cb"/> adapter /// </summary> /// <param name="pInfo">The pointer to an instance of /// <see cref="AGDnsApi.ag_dns_request_processed_event"/></param> private void AGCOnDnsRequestProcessed(IntPtr pInfo) { try { AGDnsApi.ag_dns_request_processed_event coreArgs = MarshalUtils.PtrToStructure <AGDnsApi.ag_dns_request_processed_event>(pInfo); DnsRequestProcessedEventArgs args = DnsApiConverter.FromNativeObject(coreArgs); m_DnsServerCallbackConfiguration.OnDnsRequestProcessed(m_ProxyServer, args); } catch (Exception ex) { DnsExceptionHandler.HandleManagedException(ex); } }
/// <summary> /// <see cref="AGDnsApi.cbd_onCertificateVerification"/> adapter /// </summary> /// <param name="pInfo">The pointer to an instance of /// <see cref="AGDnsApi.ag_certificate_verification_event"/></param> /// <returns>Certificate verification result /// (<seealso cref="AGDnsApi.ag_certificate_verification_result"/>)</returns> private AGDnsApi.ag_certificate_verification_result AGCOnCertificateVerification(IntPtr pInfo) { try { AGDnsApi.ag_certificate_verification_event coreArgs = MarshalUtils.PtrToStructure <AGDnsApi.ag_certificate_verification_event>(pInfo); CertificateVerificationEventArgs args = DnsApiConverter.FromNativeObject(coreArgs); AGDnsApi.ag_certificate_verification_result certificateVerificationResult = m_CertificateVerificationCallback.OnCertificateVerification(this, args); return(certificateVerificationResult); } catch (Exception ex) { DnsExceptionHandler.HandleManagedException(ex); return(AGDnsApi.ag_certificate_verification_result.AGCVR_ERROR_CERT_VERIFICATION); } }
/// <summary> /// Sets an unhandled exception configuration /// (<seealso cref="IUnhandledExceptionConfiguration"/>) /// </summary> /// <param name="unhandledExceptionConfiguration"> /// Callbacks configuration to execute when native and/or managed exception occurred</param> public void SetUnhandledExceptionConfiguration( IUnhandledExceptionConfiguration unhandledExceptionConfiguration) { lock (SYNC_ROOT) { try { LOG.InfoFormat("Setting unhandled exception configuration"); DnsExceptionHandler.Init(unhandledExceptionConfiguration); DnsExceptionHandler.SetUnhandledExceptionConfiguration(); LOG.InfoFormat("Setting unhandled exception configuration has been successfully completed"); } catch (Exception ex) { LOG.ErrorFormat("Setting unhandled exception configuration failed with an error", ex); } } }
/// <summary> /// This method is called from the CoreLibs and passed to managed code /// </summary> /// <param name="attachment">Pointer to the native logger</param> /// <param name="pName">Pointer to the logging category name</param> /// <param name="logLevel">Log level</param> /// <param name="pMessage">Pointer to the log message</param> private static void AGOnDnsLogged( IntPtr attachment, IntPtr pName, AGDnsApi.ag_log_level logLevel, IntPtr pMessage) { try { LogLevel level = LOG_LEVELS_MAPPING[logLevel]; string name = MarshalUtils.PtrToString(pName); string message = MarshalUtils.PtrToString(pMessage); LOG.Log(level, "{0}: {1}".AsFunc(), null, name, message); } catch (Exception ex) { DnsExceptionHandler.HandleManagedException(ex); } }