From a7cc96b83b8f740e31dfda52636c06dc06c5223c Mon Sep 17 00:00:00 2001 From: Jaex Date: Mon, 11 Aug 2014 13:40:14 +0300 Subject: [PATCH] Make sure ssl bypass dispose --- HelpersLib/CodeMenu.cs | 29 +++++++++++++++-- HelpersLib/CodeMenuEntry.cs | 29 +++++++++++++++-- HelpersLib/ExtCodeMenuEntry.cs | 29 +++++++++++++++-- UploadersLib/FileUploaders/OwnCloud.cs | 44 ++++++++++++++++---------- 4 files changed, 108 insertions(+), 23 deletions(-) diff --git a/HelpersLib/CodeMenu.cs b/HelpersLib/CodeMenu.cs index 16b9f9650..f69512886 100644 --- a/HelpersLib/CodeMenu.cs +++ b/HelpersLib/CodeMenu.cs @@ -1,4 +1,29 @@ -using System; +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (C) 2007-2014 ShareX Developers + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using System; using System.Collections.Generic; using System.Drawing; using System.Linq; @@ -64,4 +89,4 @@ public static ContextMenuStrip Create(TextBox tb, params TEntry[] ignore return cms; } } -} +} \ No newline at end of file diff --git a/HelpersLib/CodeMenuEntry.cs b/HelpersLib/CodeMenuEntry.cs index 63fa25afc..cd3d0538a 100644 --- a/HelpersLib/CodeMenuEntry.cs +++ b/HelpersLib/CodeMenuEntry.cs @@ -1,4 +1,29 @@ -using System; +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (C) 2007-2014 ShareX Developers + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -20,4 +45,4 @@ public CodeMenuEntry(string value, string description) public abstract string ToPrefixString(); } -} +} \ No newline at end of file diff --git a/HelpersLib/ExtCodeMenuEntry.cs b/HelpersLib/ExtCodeMenuEntry.cs index 6464ebd5c..7ddf8316b 100644 --- a/HelpersLib/ExtCodeMenuEntry.cs +++ b/HelpersLib/ExtCodeMenuEntry.cs @@ -1,4 +1,29 @@ -using System; +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (C) 2007-2014 ShareX Developers + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -17,4 +42,4 @@ public class ExtCodeMenuEntry : CodeMenuEntry public static readonly ExtCodeMenuEntry png = new ExtCodeMenuEntry("png", "Portable Network Graphic"); public static readonly ExtCodeMenuEntry tif = new ExtCodeMenuEntry("tif", "Tagged Image File"); } -} +} \ No newline at end of file diff --git a/UploadersLib/FileUploaders/OwnCloud.cs b/UploadersLib/FileUploaders/OwnCloud.cs index 5d818e36a..5875c1c3f 100644 --- a/UploadersLib/FileUploaders/OwnCloud.cs +++ b/UploadersLib/FileUploaders/OwnCloud.cs @@ -72,30 +72,40 @@ public override UploadResult Upload(Stream stream, string fileName) NameValueCollection headers = CreateAuthenticationHeader(Username, Password); SSLBypassHelper sslBypassHelper = null; - if (IgnoreInvalidCert) - sslBypassHelper = new SSLBypassHelper(); - - string response = SendRequestStream(url, stream, Helpers.GetMimeType(fileName), headers, method: HttpMethod.PUT); - UploadResult result = new UploadResult(response); - - if (!IsError) + try { - if (CreateShare) + if (IgnoreInvalidCert) { - AllowReportProgress = false; - result.URL = ShareFile(path); + sslBypassHelper = new SSLBypassHelper(); } - else + + string response = SendRequestStream(url, stream, Helpers.GetMimeType(fileName), headers, method: HttpMethod.PUT); + + UploadResult result = new UploadResult(response); + + if (!IsError) { - result.IsURLExpected = false; + if (CreateShare) + { + AllowReportProgress = false; + result.URL = ShareFile(path); + } + else + { + result.IsURLExpected = false; + } + } + + return result; + } + finally + { + if (sslBypassHelper != null) + { + sslBypassHelper.Dispose(); } } - - if (sslBypassHelper != null) - sslBypassHelper.Dispose(); - - return result; } // http://doc.owncloud.org/server/7.0/developer_manual/core/ocs-share-api.html#create-a-new-share