banshee r4435 - in trunk/banshee: . src/Core/Banshee.Core/Banshee.IO src/Core/Banshee.Core/Resources src/Core/Banshee.Services src/Core/Banshee.Services/Banshee.Web



Author: abock
Date: Wed Aug 27 16:04:27 2008
New Revision: 4435
URL: http://svn.gnome.org/viewvc/banshee?rev=4435&view=rev

Log:
2008-08-26  Aaron Bockover  <abock gnome org>

    * configure.ac: Fix the assembly versioning to eliminate the build
    revision so MD doesn't go apeshit. Awesome. (BNC #352440, not fixed)

    * src/Core/Banshee.Core/Banshee.IO/StreamAssist.cs: Provide some overrides
    to avoid closing streams when writing if desired

    * src/Core/Banshee.Services/Banshee.Web/HttpRequest.cs: A reusable
    HttpRequest object that makes fetching streams and making requests easier
    and more unified and consistent for Banshee; probably not complete and
    not used anywhere yet

    * src/Core/Banshee.Core/Resources/translators.xml: Updated



Added:
   trunk/banshee/src/Core/Banshee.Services/Banshee.Web/HttpRequest.cs
Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/configure.ac
   trunk/banshee/src/Core/Banshee.Core/Banshee.IO/StreamAssist.cs
   trunk/banshee/src/Core/Banshee.Core/Resources/translators.xml
   trunk/banshee/src/Core/Banshee.Services/Makefile.am

Modified: trunk/banshee/configure.ac
==============================================================================
--- trunk/banshee/configure.ac	(original)
+++ trunk/banshee/configure.ac	Wed Aug 27 16:04:27 2008
@@ -12,7 +12,7 @@
 DISTCHECK_CONFIGURE_FLAGS="--disable-docs --enable-mtp --enable-daap --enable-podcast"
 AC_SUBST(DISTCHECK_CONFIGURE_FLAGS)
 
-ASM_VERSION="$VERSION.*"
+ASM_VERSION="$VERSION.0"
 AC_SUBST(ASM_VERSION)
 AC_SUBST(ASM_DISPLAY_VERSION)
 AC_SUBST(DEVEL_BUILD)

Modified: trunk/banshee/src/Core/Banshee.Core/Banshee.IO/StreamAssist.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Core/Banshee.IO/StreamAssist.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Core/Banshee.IO/StreamAssist.cs	Wed Aug 27 16:04:27 2008
@@ -35,21 +35,29 @@
     {
         public static void Save (Stream from, Stream to)
         {
-            Save (from, to, 8192);
+            Save (from, to, 8192, true);
+        }
+        
+        public static void Save (Stream from, Stream to, bool close)
+        {
+            Save (from, to, 8192, close);
         }
 
-        public static void Save (Stream from, Stream to, int bufferSize)
+        public static void Save (Stream from, Stream to, int bufferSize, bool close)
         {
-            using (from) {
+            try {
                 long bytes_read = 0;
-                using (to) {
-                    byte [] buffer = new byte[bufferSize];
-                    int chunk_bytes_read = 0;
-
-                    while ((chunk_bytes_read = from.Read (buffer, 0, buffer.Length)) > 0) {
-                        to.Write (buffer, 0, chunk_bytes_read);
-                        bytes_read += chunk_bytes_read;
-                    }
+                byte [] buffer = new byte[bufferSize];
+                int chunk_bytes_read = 0;
+                
+                while ((chunk_bytes_read = from.Read (buffer, 0, buffer.Length)) > 0) {
+                    to.Write (buffer, 0, chunk_bytes_read);
+                    bytes_read += chunk_bytes_read;
+                }
+            } finally {
+                if (close) {
+                    from.Close ();
+                    to.Close ();
                 }
             }
         }

Modified: trunk/banshee/src/Core/Banshee.Core/Resources/translators.xml
==============================================================================
--- trunk/banshee/src/Core/Banshee.Core/Resources/translators.xml	(original)
+++ trunk/banshee/src/Core/Banshee.Core/Resources/translators.xml	Wed Aug 27 16:04:27 2008
@@ -100,7 +100,7 @@
   <language code="pa" name="Panjabi">
     <person>A S Alam</person>
   </language>
-  <language code="pl" name="Tomasz Dominikowski">
+  <language code="pl" name="Aviary.pl">
     <person>Tomasz Dominikowski</person>
   </language>
   <language code="pt" name="Portuguese">

Added: trunk/banshee/src/Core/Banshee.Services/Banshee.Web/HttpRequest.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Web/HttpRequest.cs	Wed Aug 27 16:04:27 2008
@@ -0,0 +1,213 @@
+// 
+// HttpRequest.cs
+//
+// Author:
+//   Aaron Bockover <abockover novell com>
+//
+// Copyright (C) 2008 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.IO;
+using System.Net;
+using System.Collections.Generic;
+
+using Banshee.Base;
+using Banshee.ServiceStack;
+using Banshee.Networking;
+
+namespace Banshee.Web
+{   
+    public class HttpRequest : IDisposable
+    {
+        private HttpWebRequest request;
+        private HttpWebResponse response;
+        private List<string> ignore_mimetypes;
+        
+        public HttpRequest ()            { }
+        public HttpRequest (string uri)  { CreateRequest (uri); }
+        public HttpRequest (SafeUri uri) { CreateRequest (uri); }
+        public HttpRequest (Uri uri)     { CreateRequest (uri); }
+        
+        public void Dispose ()
+        {
+            lock (this) {
+                if (response != null) {
+                    response.Close ();
+                    response = null;
+                }
+                
+                request = null;
+            }
+        }
+        
+        public void CreateRequest (string uri)
+        {
+            CreateRequest (new Uri (uri));
+        }
+        
+        public void CreateRequest (SafeUri uri)
+        {
+            CreateRequest (new Uri (uri.AbsoluteUri));
+        }
+        
+        public virtual void CreateRequest (Uri uri)
+        {
+            lock (this) {
+                Dispose ();
+                
+                request = (HttpWebRequest)WebRequest.Create (uri.AbsoluteUri);
+                request.UserAgent = Browser.UserAgent;
+                request.Timeout = (int)Timeout.TotalMilliseconds;
+                request.KeepAlive = false;
+                request.AllowAutoRedirect = true;
+            }
+        }
+        
+        public virtual void GetResponse ()
+        {
+            lock (this) {
+                if (response != null) {
+                    return;
+                }
+                
+                if (request == null) {
+                    throw new InvalidOperationException ("CreateRequest must be called first");
+                } else if (!InternetConnected) {
+                    throw new NetworkUnavailableException ();
+                }
+                
+                response = (HttpWebResponse)request.GetResponse ();
+                if (ignore_mimetypes == null) {
+                    return;
+                }
+                
+                string [] content_types = response.Headers.GetValues ("Content-Type");
+                if (content_types != null && content_types.Length > 0) {
+                    foreach (string content_type in content_types) {
+                        if (ignore_mimetypes.Contains (content_type)) {
+                            response.Close ();
+                            response = null;
+                        }
+                    }
+                }
+            }
+        }
+        
+        public void DumpResponseStream ()
+        {
+            using (Stream stream = response.GetResponseStream ()) {
+                StreamReader reader = new StreamReader (stream);
+                Console.WriteLine (reader.ReadToEnd ());
+                reader.Dispose ();
+            }
+        }
+        
+        public void SaveResponseStream (SafeUri path)
+        {
+            SaveResponseStream (path, true);
+        }
+        
+        public void SaveResponseStream (SafeUri path, bool closeResponse)
+        {
+            SaveResponseStream (Banshee.IO.File.OpenWrite (path, true), closeResponse);
+        }
+        
+        public virtual void SaveResponseStream (Stream toStream, bool closeResponse)
+        {
+            if (response == null) {
+                throw new InvalidOperationException ("No response");
+            }
+        
+            Stream from_stream = response.GetResponseStream ();
+            if (from_stream == null) {
+                if (response != null && closeResponse) {
+                    response.Close ();
+                }
+                
+                throw new InvalidDataException ("Response has no content stream");
+            }
+            
+            Banshee.IO.StreamAssist.Save (from_stream, toStream);
+            
+            from_stream.Close ();
+            if (closeResponse) {
+                response.Close ();
+            }
+        }
+
+        public HttpWebRequest Request {
+            get { return request; }
+        }
+        
+        public HttpWebResponse Response {
+            get { return response; }
+        }
+        
+        private static TimeSpan default_timeout = TimeSpan.FromSeconds (20);
+        protected virtual TimeSpan Timeout {
+            get { return default_timeout; }
+        }
+        
+#region Mimetypes
+        
+        public void AddIgnoreMimeType (string mimetype)
+        {
+            lock (this) {
+                if (ignore_mimetypes == null) {
+                    ignore_mimetypes = new List<string> ();
+                }
+                
+                ignore_mimetypes.Add (mimetype);
+            }
+        }
+        
+        public void RemoveIgnoreMimeType (string mimetype)
+        {
+             lock (this) {
+                if (ignore_mimetypes != null) {
+                    ignore_mimetypes.Remove (mimetype);
+                }
+            }
+        }
+        
+        public void ClearIgnoreMimeTypes ()
+        {
+            lock (this) {
+                if (ignore_mimetypes != null) {
+                    ignore_mimetypes.Clear ();
+                }
+            }
+        }
+        
+        public string [] IgnoreMimeTypes {
+            get { lock (this) { return ignore_mimetypes == null ? new string[0] : ignore_mimetypes.ToArray (); } }
+            set { lock (this) { ignore_mimetypes = new List<string> (value); } }
+        }
+        
+#endregion
+        
+        protected bool InternetConnected {
+            get { return ServiceManager.Get<Network> ().Connected; }
+        }
+    }
+}

Modified: trunk/banshee/src/Core/Banshee.Services/Makefile.am
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Makefile.am	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Makefile.am	Wed Aug 27 16:04:27 2008
@@ -177,7 +177,8 @@
 	Banshee.Sources/SourceMergeType.cs \
 	Banshee.Sources/SourceMessage.cs \
 	Banshee.Streaming/RadioTrackInfo.cs \
-	Banshee.Web/Browser.cs
+	Banshee.Web/Browser.cs \
+	Banshee.Web/HttpRequest.cs
 
 RESOURCES =  \
 	Banshee.Services.addin.xml \



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]