From 9e930acec552ad1b2d499c5be9481382b00ec79c Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 30 Jun 2018 00:01:50 +0200 Subject: [PATCH] modules.builtin --- .../Duplicati.Library.Modules.Builtin.csproj | 154 ++++-------------- .../Builtin/Properties/AssemblyInfo.cs | 56 ------- .../Modules/Builtin/SendJabberMessage.cs | 89 ++++------ .../Library/Modules/Builtin/packages.config | 8 - 4 files changed, 65 insertions(+), 242 deletions(-) delete mode 100644 Duplicati/Library/Modules/Builtin/Properties/AssemblyInfo.cs delete mode 100644 Duplicati/Library/Modules/Builtin/packages.config diff --git a/Duplicati/Library/Modules/Builtin/Duplicati.Library.Modules.Builtin.csproj b/Duplicati/Library/Modules/Builtin/Duplicati.Library.Modules.Builtin.csproj index 442af65b5..0b40e9c85 100644 --- a/Duplicati/Library/Modules/Builtin/Duplicati.Library.Modules.Builtin.csproj +++ b/Duplicati/Library/Modules/Builtin/Duplicati.Library.Modules.Builtin.csproj @@ -1,140 +1,48 @@ - - + + - Debug - AnyCPU - {52826615-7964-47FE-B4B3-1B2DBDF605B9} - Library - Properties - Duplicati.Library.Modules.Builtin - Duplicati.Library.Modules.Builtin - 512 + netstandard2.0 + 2.0.0.7 + true Duplicati.snk - - - 3.5 - - v4.6.2 - - false - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - false - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false + LGPL, Copyright ? Duplicati Team 2015 + Duplicati.Library.Modules.Builtin + Duplicati Team + Duplicati Team + Buildin modules for Duplicati + ModulesBuiltin + Duplicati.Library.Modules.Builtin + Duplicati.Library.Modules.Builtin + - - ..\..\..\..\packages\BouncyCastle.1.8.1\lib\BouncyCastle.Crypto.dll - True - - - - - - ..\..\..\..\packages\agsXMPP.1.1.1.0\lib\agsXMPP.dll - - - - - - ..\..\..\..\packages\MimeKit.1.18.1\lib\net45\MimeKit.dll - - - ..\..\..\..\packages\MailKit.1.18.1.1\lib\net45\MailKit.dll - - - ..\..\..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll - + + + + + + + + + + + + + + + - - - - - - - - - - - - DnsLite.cs - - - - - - - - - {C5899F45-B0FF-483C-9D38-24A9FCAAB237} - Duplicati.Library.Interface - - - {D63E53E4-A458-4C2F-914D-92F715F58ACE} - Duplicati.Library.Snapshots - - - {DE3E5D4C-51AB-4E5E-BEE8-E636CEBFBA65} - Duplicati.Library.Utility - - - {D10A5FC0-11B4-4E70-86AA-8AEA52BD9798} - Duplicati.Library.Logging - - - {B68F2214-951F-4F78-8488-66E1ED3F50BF} - Duplicati.Library.Localization - - - {D4C37C33-5E73-4B56-B2C3-DC4A6BAA36BB} - Duplicati.Library.OAuthHelper - - - - - + PreserveNewest mozroots.exe PreserveNewest - - - - - - - - PreserveNewest - - - - + \ No newline at end of file diff --git a/Duplicati/Library/Modules/Builtin/Properties/AssemblyInfo.cs b/Duplicati/Library/Modules/Builtin/Properties/AssemblyInfo.cs deleted file mode 100644 index 03f8cb13a..000000000 --- a/Duplicati/Library/Modules/Builtin/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,56 +0,0 @@ -#region Disclaimer / License -// Copyright (C) 2015, The Duplicati Team -// http://www.duplicati.com, info@duplicati.com -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -// -#endregion -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Duplicati.Library.Modules.Builtin")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Duplicati Team")] -[assembly: AssemblyProduct("Duplicati.Library.Modules.Builtin")] -[assembly: AssemblyCopyright("LGPL, Copyright © Duplicati Team 2015")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("3794e72f-a1ee-4dc7-b658-e8ac8a3aaa3c")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("2.0.0.7")] -[assembly: AssemblyVersion("2.0.0.7")] -[assembly: AssemblyFileVersion("2.0.0.7")] -[assembly: InternalsVisibleTo("Duplicati.Library.Modules.Builtin.UnitTest")] diff --git a/Duplicati/Library/Modules/Builtin/SendJabberMessage.cs b/Duplicati/Library/Modules/Builtin/SendJabberMessage.cs index 755ae54f9..17505f419 100644 --- a/Duplicati/Library/Modules/Builtin/SendJabberMessage.cs +++ b/Duplicati/Library/Modules/Builtin/SendJabberMessage.cs @@ -2,9 +2,9 @@ using System.Collections.Generic; using System.Linq; using Duplicati.Library.Interface; -using Duplicati.Library.Logging; -using System.Net.NetworkInformation; -using Duplicati.Library.Modules.Builtin.ResultSerialization; +using Matrix; +using Matrix.Xmpp.Client; +using Enum = System.Enum; namespace Duplicati.Library.Modules.Builtin { @@ -172,73 +172,52 @@ namespace Duplicati.Library.Modules.Builtin return base.ReplaceTemplate(input, result, subjectline); } - protected override void SendMessage(string subject, string body) + protected override async void SendMessage(string subject, string body) { Exception ex = null; var waitEvent = new System.Threading.ManualResetEvent(false); var uri = new Library.Utility.Uri(m_username.Contains("://") ? m_username : "http://" + m_username); - var con = new agsXMPP.XmppClientConnection(uri.Host, uri.Port == -1 ? (uri.Scheme == "https" ? 5223 :5222) : uri.Port); - if (uri.Scheme == "https") - con.UseSSL = true; var resource = uri.Path ?? ""; if (resource.StartsWith("/", StringComparison.Ordinal)) resource = resource.Substring(1); - - if (string.IsNullOrWhiteSpace(resource)) - resource = "Duplicati"; - - agsXMPP.ObjectHandler loginDelegate = (sender) => + + var xmppClient = new XmppClient { - try - { - foreach(var recipient in m_to.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)) - con.Send(new agsXMPP.protocol.client.Message(recipient, agsXMPP.protocol.client.MessageType.chat, body)); - } - catch (Exception e) - { - Logging.Log.WriteWarningMessage(LOGTAG, "XMPPSendError", e, "Failed to send to XMPP messages: {0}", e.Message); - ex = e; - } - finally - { - waitEvent.Set(); - } + Username = uri.Username, + Password = string.IsNullOrWhiteSpace(m_password) ? uri.Password : m_password, + XmppDomain = uri.Host, + Port = uri.Port == -1 ? (uri.Scheme == "https" ? 5223 : 5222) : uri.Port, + Tls = uri.Scheme == "https", + Resource = string.IsNullOrWhiteSpace(resource) ? "Duplicati" : resource, + HostnameResolver = new Matrix.Network.Resolver.NameResolver() }; - agsXMPP.ErrorHandler errorHandler = (sender, e) => { - Logging.Log.WriteWarningMessage(LOGTAG, "XMPPError", e, "An error ocurred in XMPP: {0}", e.Message); - - ex = e; - waitEvent.Set(); - }; - - agsXMPP.XmppElementHandler loginErroHandler = (sender, e) => { - Logging.Log.WriteWarningMessage(LOGTAG, "XMPPLoginError", null, "Failed to login to XMPP: {0}", e); - - ex = new Exception(string.Format("Failed to log in: {0}", e)); - waitEvent.Set(); - }; - - con.OnLogin += loginDelegate; - con.OnError += errorHandler; - con.OnAuthError += loginErroHandler; - //con.OnBinded += (sender) => {Console.WriteLine("Binded: {0}", sender);}; - //con.OnIq += (sender, iq) => {Console.WriteLine("Iq: {0}", iq);}; - //con.OnReadXml += (sender, xml) => {Console.WriteLine("ReadXml: {0}", xml);}; - //con.OnWriteXml += (sender, xml) => {Console.WriteLine("writeXml: {0}", xml);};; - con.Open(uri.Username, string.IsNullOrWhiteSpace(m_password) ? uri.Password : m_password, resource); - - var timeout = !waitEvent.WaitOne(TimeSpan.FromSeconds(30), true); - - con.OnLogin -= loginDelegate; - con.OnError -= errorHandler; - con.OnAuthError -= loginErroHandler; + // connect so the server + await xmppClient.ConnectAsync(); try { - con.Close(); + foreach (var recipient in m_to.Split(new[] {","}, StringSplitOptions.RemoveEmptyEntries)) + await xmppClient.SendAsync(new Message(recipient, body, subject)); + } + catch (Exception e) + { + Logging.Log.WriteWarningMessage(LOGTAG, "XMPPSendError", e, "Failed to send to XMPP messages: {0}", e.Message); + ex = e; + } + finally + { + waitEvent.Set(); + } + + var timeout = !waitEvent.WaitOne(TimeSpan.FromSeconds(30), true); + + try + { + // Close connection again + await xmppClient.DisconnectAsync(); } catch (Exception lex) { diff --git a/Duplicati/Library/Modules/Builtin/packages.config b/Duplicati/Library/Modules/Builtin/packages.config deleted file mode 100644 index 75d5024ea..000000000 --- a/Duplicati/Library/Modules/Builtin/packages.config +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file