f-spot r4193 - in trunk/dpap-sharp: dpap-server launcher lib



Author: apart
Date: Mon Jul 21 09:24:17 2008
New Revision: 4193
URL: http://svn.gnome.org/viewvc/f-spot?rev=4193&view=rev

Log:
Client & server work


Added:
   trunk/dpap-sharp/dpap-server/
   trunk/dpap-sharp/dpap-server/AssemblyInfo.cs
   trunk/dpap-sharp/dpap-server/Main.cs
Removed:
   trunk/dpap-sharp/launcher/
Modified:
   trunk/dpap-sharp/lib/Client.cs
   trunk/dpap-sharp/lib/ContentCodeBag.cs
   trunk/dpap-sharp/lib/ContentFetcher.cs
   trunk/dpap-sharp/lib/ContentWriter.cs
   trunk/dpap-sharp/lib/Database.cs
   trunk/dpap-sharp/lib/Photo.cs
   trunk/dpap-sharp/lib/Server.cs
   trunk/dpap-sharp/lib/ServerInfo.cs
   trunk/dpap-sharp/lib/content-codes

Added: trunk/dpap-sharp/dpap-server/AssemblyInfo.cs
==============================================================================
--- (empty file)
+++ trunk/dpap-sharp/dpap-server/AssemblyInfo.cs	Mon Jul 21 09:24:17 2008
@@ -0,0 +1,30 @@
+// AssemblyInfo.cs created with MonoDevelop
+// User: andrzej at 11:03Â2008-07-17
+//
+// To change standard headers go to Edit->Preferences->Coding->Standard Headers
+//
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+// Information about this assembly is defined by the following attributes. 
+// Change them to the values specific to your project.
+
+[assembly: AssemblyTitle("dpap-server")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
+// If the build and revision are set to '*' they will be updated automatically.
+
+[assembly: AssemblyVersion("1.0.*.*")]
+
+// The following attributes are used to specify the signing key for the assembly, 
+// if desired. See the Mono documentation for more information about signing.
+
+[assembly: AssemblyDelaySign(false)]
+[assembly: AssemblyKeyFile("")]

Added: trunk/dpap-sharp/dpap-server/Main.cs
==============================================================================
--- (empty file)
+++ trunk/dpap-sharp/dpap-server/Main.cs	Mon Jul 21 09:24:17 2008
@@ -0,0 +1,76 @@
+// Main.cs created with MonoDevelop
+// User: andrzej at 10:26Â2008-06-01
+//
+// To change standard headers go to Edit->Preferences->Coding->Standard Headers
+//
+using System;
+using System.IO;
+using System.Collections.Generic;
+using System.Collections;
+using Mono.Unix;
+using System.Text.RegularExpressions;
+//using Gtk;
+
+using DPAP;
+
+
+
+namespace DPAP {
+	
+	class MainClass
+	{
+		
+		public static void Main(string[] args)
+		{
+			//Regex dbPhotoRegex = new Regex ("/databases/([0-9]*?)/items?session-id=([0-9]*)&meta=.*&query=('dmap.itemid:([0-9]*)')");
+			
+//			string path = "/databases/1/items?session-id=9527&meta=dpap.thumb,dmap.itemid,dpap.filedata&query=('dmap.itemid:35')$";
+			//string path = "'dmap.itemid:35'";
+	//		Console.WriteLine("regex:"+rg.IsMatch(path));
+			
+			Console.WriteLine("Starting DPAP server");
+			DPAP.Database database = new DPAP.Database("DPAP");
+			DPAP.Server server = new Server("apart photos");
+			server.Port = 8770;
+			server.AuthenticationMethod = AuthenticationMethod.None;
+			int collision_count = 0;
+			server.Collision += delegate {
+				server.Name = "apart photos" + " [" + ++collision_count + "]";
+			};
+            
+			Photo p = new Photo();
+			p.FileName = "/home/andrzej/Obrazy/tesco_droid.jpg";
+			p.Title = "test";
+			p.Format = "JPEG";
+			p.Size = 13946;
+			database.AddPhoto(p);
+			Album a = new Album("test album");
+			a.AddPhoto(p);			
+			database.AddAlbum(a);
+			Console.WriteLine("Album count is now " + database.Albums.Count);
+			Console.WriteLine("Photo name is " + database.Photos[0].FileName);
+			server.AddDatabase(database);
+			
+			//server.GetServerInfoNode();			
+			try {
+                server.Start();
+            } catch (System.Net.Sockets.SocketException) {
+				Console.WriteLine("Server socket exception!");
+                server.Port = 0;
+                server.Start();
+            }
+        
+             //DaapPlugin.ServerEnabledSchema.Set(true);
+            
+          //  if(!initial_db_committed) {
+                server.Commit();
+          //      initial_db_committed = true;
+          //  }
+			
+
+			Console.ReadLine();
+		
+			
+		}
+	}
+}

Modified: trunk/dpap-sharp/lib/Client.cs
==============================================================================
--- trunk/dpap-sharp/lib/Client.cs	(original)
+++ trunk/dpap-sharp/lib/Client.cs	Mon Jul 21 09:24:17 2008
@@ -158,14 +158,18 @@
 
         private void FetchDatabases () {
             ContentNode dbnode = ContentParser.Parse (bag, fetcher.Fetch ("/databases"));
-
+			// DEBUG
+			//dbnode.Dump();
             foreach (ContentNode child in (ContentNode[]) dbnode.Value) {
                 if (child.Name != "dmap.listing")
                     continue;
 
                 foreach (ContentNode item in (ContentNode[]) child.Value) {
+					// DEBUG
+					//item.Dump();
                     Database db = new Database (this, item);
-					Console.WriteLine("Adding database {0} with id={1} and roll count={2}." , db.Name,db.Id,db.Albums.Count); 
+					Console.WriteLine("Adding database {0} with id={1} and album count={2}." , db.Name,db.Id,db.Albums.Count);
+					//Console.WriteLine("Photo " + db.Photos[0].FileName);
                     databases.Add (db);
                 }
             }

Modified: trunk/dpap-sharp/lib/ContentCodeBag.cs
==============================================================================
--- trunk/dpap-sharp/lib/ContentCodeBag.cs	(original)
+++ trunk/dpap-sharp/lib/ContentCodeBag.cs	Mon Jul 21 09:24:17 2008
@@ -35,7 +35,8 @@
         String = 9,
         Date = 10,
         Version = 11,
-        Container = 12
+        Container = 12,
+		FileData = 13
     }
 
     internal struct ContentCode {
@@ -160,7 +161,7 @@
 			bag.AddCode ("abpl", "dpap.baseplaylist", ContentType.Char);
 			bag.AddCode ("apso", "dpap.playlistsongs", ContentType.Container);
 			bag.AddCode ("pasp", "dpap.aspectratio", ContentType.String);
-			bag.AddCode ("adbs", "daap.databasesongs", ContentType.Container);
+			bag.AddCode ("adbs", "dpap.databasesongs", ContentType.Container);
 			bag.AddCode ("picd", "dpap.creationdate", ContentType.Long);
 			bag.AddCode ("pifs", "dpap.imagefilesize", ContentType.Long);
 			bag.AddCode ("pwth", "dpap.imagepixelwidth", ContentType.Long);
@@ -170,7 +171,7 @@
 			bag.AddCode ("pimf", "dpap.imagefilename", ContentType.String);
 			bag.AddCode ("pfmt", "dpap.imageformat", ContentType.String);
 			bag.AddCode ("plsz", "dpap.imagelargefilesize", ContentType.Long);
-            //bag.AddCode ("pfdt", "dpap.filedata", ContentType.);
+			bag.AddCode ("pfdt", "dpap.filedata", ContentType.FileData);
             
             
 

Modified: trunk/dpap-sharp/lib/ContentFetcher.cs
==============================================================================
--- trunk/dpap-sharp/lib/ContentFetcher.cs	(original)
+++ trunk/dpap-sharp/lib/ContentFetcher.cs	Mon Jul 21 09:24:17 2008
@@ -157,6 +157,7 @@
             /*request.Headers.Set ("Client-DPAP-Validation", hash);
             request.Headers.Set ("Client-DPAP-Access-Index", "2");
 			*/
+// DEBUG data			
 			Console.Write(path + "?"+query);
 			Console.Write(request.Headers);
 			

Modified: trunk/dpap-sharp/lib/ContentWriter.cs
==============================================================================
--- trunk/dpap-sharp/lib/ContentWriter.cs	(original)
+++ trunk/dpap-sharp/lib/ContentWriter.cs	Mon Jul 21 09:24:17 2008
@@ -70,6 +70,36 @@
                 writer.Write ((byte) version.Minor);
                 writer.Write ((byte) version.Build);
                 break;
+			case ContentType.FileData:
+				Console.WriteLine("ContentWriter FileData!");
+				ContentNode[] nodes = (ContentNode[]) node.Value;
+				//writer.Write(IPAddress.HostToNetworkOrder (0));
+				Console.WriteLine(nodes[0].Value);
+				writer.Write(IPAddress.HostToNetworkOrder ((int)nodes[0].Value));
+				Console.WriteLine("reading file!");
+				FileInfo info = new FileInfo ((string)nodes[1].Value);
+
+				FileStream stream = info.Open(FileMode.Open, FileAccess.Read, FileShare.Read);
+				//writer.Write (client, stream, info.Length, offset);
+				int offset = -1;
+                using (BinaryReader reader = new BinaryReader (stream)) {
+                    if (offset > 0) {
+                        reader.BaseStream.Seek (offset, SeekOrigin.Begin);
+                    }
+
+                    long count = 0;
+					long len = info.Length;
+                    while (count < len) {
+                        byte[] buf = reader.ReadBytes (Math.Min (8192, (int) len - (int) count));
+                        if (buf.Length == 0) {
+                            break;
+                        }
+                        
+                        writer.Write (buf);
+                        count += buf.Length;
+                    }
+                }
+				break;
             case ContentType.Container:
                 MemoryStream childStream = new MemoryStream ();
                 BinaryWriter childWriter = new BinaryWriter (childStream);
@@ -86,6 +116,7 @@
                 writer.Write (bytes, 0, len);
                 childWriter.Close ();
                 break;
+				
             default:
                 Console.Error.WriteLine ("Cannot write node of type: " + code.Type);
                 break;

Modified: trunk/dpap-sharp/lib/Database.cs
==============================================================================
--- trunk/dpap-sharp/lib/Database.cs	(original)
+++ trunk/dpap-sharp/lib/Database.cs	Mon Jul 21 09:24:17 2008
@@ -62,7 +62,7 @@
         private const string PhotoQuery = "meta=dpap.aspectratio,dmap.itemid,dmap.itemname,dpap.imagefilename," +
 			"dpap.imagefilesize,dpap.creationdate,dpap.imagepixelwidth," +
 			"dpap.imagepixelheight,dpap.imageformat,dpap.imagerating," +
-			"dpap.imagecomments,dpap.imagelargefilesize&type=photo"; 
+			"dpap.imagecomments,dpap.imagelargefilesize,dpap.filedata&type=photo"; 
 			
 
         private static int nextid = 1;
@@ -72,7 +72,7 @@
         private string name;
 
         private List<Photo> photos = new List<Photo> ();
-        private List<Album> playlists = new List<Album> ();
+        private List<Album> albums = new List<Album> ();
         private Album baseAlbum = new Album ();
         private int nextPhotoId = 1;
 
@@ -110,7 +110,7 @@
 
         public IList<Album> Albums {
             get {
-                return new ReadOnlyCollection<Album> (playlists);
+                return new ReadOnlyCollection<Album> (albums);
             }
         }
 
@@ -164,7 +164,7 @@
             if (id == baseAlbum.Id)
                 return baseAlbum;
 
-            foreach (Album pl in playlists) {
+            foreach (Album pl in albums) {
                 if (pl.Id == id)
                     return pl;
             }
@@ -200,7 +200,7 @@
                 children.Add (new ContentNode ("dmap.deletedidlisting", deletedNodes));
             }
             
-            return new ContentNode ("daap.databasesongs", children);
+            return new ContentNode ("dpap.databasesongs", children);
         }
 
         internal ContentNode ToAlbumsNode () {
@@ -208,7 +208,7 @@
 
             nodes.Add (baseAlbum.ToNode (true));
             
-            foreach (Album pl in playlists) {
+            foreach (Album pl in albums) {
                 nodes.Add (pl.ToNode (false));
             }
 
@@ -226,7 +226,7 @@
                                     new ContentNode ("dmap.persistentid", (long) id),
                                     new ContentNode ("dmap.itemname", name),
                                     new ContentNode ("dmap.itemcount", photos.Count),
-                                    new ContentNode ("dmap.containercount", playlists.Count + 1));
+                                    new ContentNode ("dmap.containercount", albums.Count + 1));
         }
 
         public void Clear () {
@@ -238,7 +238,7 @@
         }
 
         private void ClearAlbums () {
-            foreach (Album pl in new List<Album> (playlists)) {
+            foreach (Album pl in new List<Album> (albums)) {
                 RemoveAlbum (pl);
             }
         }
@@ -254,24 +254,25 @@
         }
 
         private void RefreshAlbums (string revquery) {
-            byte[] playlistsData;
+            byte[] albumsData;
 
             try {
-                playlistsData = client.Fetcher.Fetch (String.Format ("/databases/{0}/containers", id, revquery));
+                albumsData = client.Fetcher.Fetch (String.Format ("/databases/{0}/containers", id, revquery));
             } catch (WebException) {
                 return;
             }
             
-            ContentNode playlistsNode = ContentParser.Parse (client.Bag, playlistsData);
-
-            if (IsUpdateResponse (playlistsNode))
+            ContentNode albumsNode = ContentParser.Parse (client.Bag, albumsData);
+			// DEBUG data			
+			//albumsNode.Dump();
+            if (IsUpdateResponse (albumsNode))
                 return;
 
-            // handle playlist additions/changes
+            // handle album additions/changes
             ArrayList plids = new ArrayList ();
             
-            foreach (ContentNode playlistNode in (ContentNode[]) playlistsNode.GetChild ("dmap.listing").Value) {
-                Album pl = Album.FromNode (playlistNode);
+            foreach (ContentNode albumNode in (ContentNode[]) albumsNode.GetChild ("dmap.listing").Value) {
+                Album pl = Album.FromNode (albumNode);
 
                 if (pl != null) {
                     plids.Add (pl.Id);
@@ -285,8 +286,8 @@
                 }
             }
 
-            // delete playlists that no longer exist
-            foreach (Album pl in new List<Album> (playlists)) {
+            // delete albums that no longer exist
+            foreach (Album pl in new List<Album> (albums)) {
                 if (!plids.Contains (pl.Id)) {
                     RemoveAlbum (pl);
                 }
@@ -294,19 +295,19 @@
 
             plids = null;
 
-            // add/remove photos in the playlists
-            foreach (Album pl in playlists) {
-                byte[] playlistPhotosData = client.Fetcher.Fetch (String.Format ("/databases/{0}/containers/{1}/items",
+            // add/remove photos in the albums
+            foreach (Album pl in albums) {
+                byte[] albumPhotosData = client.Fetcher.Fetch (String.Format ("/databases/{0}/containers/{1}/items",
                                                                                 id, pl.Id), revquery);
-                ContentNode playlistPhotosNode = ContentParser.Parse (client.Bag, playlistPhotosData);
+                ContentNode albumPhotosNode = ContentParser.Parse (client.Bag, albumPhotosData);
 
-                if (IsUpdateResponse (playlistPhotosNode))
+                if (IsUpdateResponse (albumPhotosNode))
                     return;
 
-                if ((byte) playlistPhotosNode.GetChild ("dmap.updatetype").Value == 1) {
+                if ((byte) albumPhotosNode.GetChild ("dmap.updatetype").Value == 1) {
 
-                    // handle playlist photo deletions
-                    ContentNode deleteList = playlistPhotosNode.GetChild ("dmap.deletedidlisting");
+                    // handle album photo deletions
+                    ContentNode deleteList = albumPhotosNode.GetChild ("dmap.deletedidlisting");
 
                     if (deleteList != null) {
                         foreach (ContentNode deleted in (ContentNode[]) deleteList.Value) {
@@ -323,7 +324,7 @@
                 // add new photos, or reorder existing ones
 
                 int plindex = 0;
-                foreach (ContentNode plPhotoNode in (ContentNode[]) playlistPhotosNode.GetChild ("dmap.listing").Value) {
+                foreach (ContentNode plPhotoNode in (ContentNode[]) albumPhotosNode.GetChild ("dmap.listing").Value) {
                     Photo plphoto = null;
                     int containerId = 0;
                     Photo.FromAlbumNode (this, plPhotoNode, out plphoto, out containerId);
@@ -341,7 +342,7 @@
         }
 
         private void RefreshPhotos (string revquery) {
-			foreach (Album pl in playlists){
+			foreach (Album pl in albums){
 	            byte[] photosData = client.Fetcher.Fetch (String.Format ("/databases/{0}/containers/{1}/items", id,pl.getId()),
 	                                                     PhotoQuery);
 	            ContentNode photosNode = ContentParser.Parse (client.Bag, photosData);
@@ -351,18 +352,19 @@
 
 	            // handle photo additions/changes
 	            foreach (ContentNode photoNode in (ContentNode[]) photosNode.GetChild ("dmap.listing").Value) {
+					// DEBUG data					
 					//photoNode.Dump();
 	                Photo photo = Photo.FromNode (photoNode);
 					
 	                Photo existing = LookupPhotoById (photo.Id);
 					
 	                if (existing == null){
-						Console.WriteLine("adding " + photo.Title);
+					//	Console.WriteLine("adding " + photo.Title);
 	                    AddPhoto (photo);
 					}
 	                else
 					{
-						Console.WriteLine("updating " + existing.Title);
+					//	Console.WriteLine("updating " + existing.Title);
 	                    existing.Update (photo);
 					}
 	            }
@@ -424,11 +426,11 @@
                     int count = 0;
                     byte[] buf = new byte[ChunkLength];
                     
-					count = reader.Read(buf,0,89);
+			/*		count = reader.Read(buf,0,89);
 					
 					if(count < 89)
 						count+=reader.Read(buf,0,89-count);
-					
+				*/	
                     do {
                         count = reader.Read (buf, 0, ChunkLength);
                         writer.Write (buf, 0, count);
@@ -454,7 +456,7 @@
             photos.Remove (photo);
             baseAlbum.RemovePhoto (photo);
 
-            foreach (Album pl in playlists) {
+            foreach (Album pl in albums) {
                 pl.RemovePhoto (photo);
             }
 
@@ -463,14 +465,14 @@
         }
 
         public void AddAlbum (Album pl) {
-            playlists.Add (pl);
+            albums.Add (pl);
 
             if (AlbumAdded != null)
                 AlbumAdded (this, new AlbumArgs (pl));
         }
 
         public void RemoveAlbum (Album pl) {
-            playlists.Remove (pl);
+            albums.Remove (pl);
 
             if (AlbumRemoved != null)
                 AlbumRemoved (this, new AlbumArgs (pl));
@@ -501,11 +503,11 @@
             db.photos = clonePhotos;
 
             List<Album> cloneAlbums = new List<Album> ();
-            foreach (Album pl in playlists) {
+            foreach (Album pl in albums) {
                 cloneAlbums.Add (CloneAlbum (db, pl));
             }
 
-            db.playlists = cloneAlbums;
+            db.albums = cloneAlbums;
             db.baseAlbum = CloneAlbum (db, baseAlbum);
             return db;
         }

Modified: trunk/dpap-sharp/lib/Photo.cs
==============================================================================
--- trunk/dpap-sharp/lib/Photo.cs	(original)
+++ trunk/dpap-sharp/lib/Photo.cs	Mon Jul 21 09:24:17 2008
@@ -146,18 +146,24 @@
             photo.fileName = fileName;
             photo.dateAdded = dateAdded;
             photo.dateModified = dateModified;
-       
+			
             return photo;
         }
 
         public override string ToString () {
-            return String.Format ("{0} - {1}.{2} ({3})", author, title, format, id);
+            return String.Format ("{0} - {1}.{2} ({3})", fileName, title, format, id);
         }
 
         internal void SetId (int id) {
             this.id = id;
         }
-
+		internal ContentNode ToFileData () {
+			return new ContentNode ("dpap.databasesongs",
+			                        new ContentNode ("dpap.filedata",
+                                    new ContentNode ("dpap.imagefilesize", size),
+                                    new ContentNode ("dpap.imagefilename", fileName))
+			                        );
+		}
         internal ContentNode ToNode (string[] fields) {
 
             ArrayList nodes = new ArrayList ();
@@ -189,7 +195,10 @@
                 case "dpap.imageformat":
                     val = format;
                     break;
-               
+				case "dpap.imagefilename":
+					val = fileName;
+					break;
+				
                 default:
                     break;
                 }
@@ -205,7 +214,7 @@
             
             return new ContentNode ("dmap.listingitem", nodes);
         }
-
+		
         internal static Photo FromNode (ContentNode node) {
             Photo photo = new Photo ();
             
@@ -243,7 +252,7 @@
         internal ContentNode ToAlbumNode (int containerId) {
             return new ContentNode ("dmap.listingitem",
                                     new ContentNode ("dmap.itemkind", (byte) 2),
-                                    new ContentNode ("daap.songdatakind", (byte) 0),
+                                    new ContentNode ("dpap.imagefilename", fileName),
                                     new ContentNode ("dmap.itemid", Id),
                                     new ContentNode ("dmap.containeritemid", containerId),
                                     new ContentNode ("dmap.itemname", Title == null ? String.Empty : Title));

Modified: trunk/dpap-sharp/lib/Server.cs
==============================================================================
--- trunk/dpap-sharp/lib/Server.cs	(original)
+++ trunk/dpap-sharp/lib/Server.cs	Mon Jul 21 09:24:17 2008
@@ -134,6 +134,8 @@
         }
 
         public void WriteResponseFile (Socket client, string file, long offset) {
+			// DEBUG data			
+			Console.WriteLine("WriteResponseFile!!");
             FileInfo info = new FileInfo (file);
 
             FileStream stream = info.Open(FileMode.Open, FileAccess.Read, FileShare.Read);
@@ -432,7 +434,8 @@
         internal static readonly TimeSpan DefaultTimeout = TimeSpan.FromMinutes (30);
         
         private static Regex dbItemsRegex = new Regex ("/databases/([0-9]*?)/items$");
-        private static Regex dbPhotoRegex = new Regex ("/databases/([0-9]*?)/items/([0-9]*).*");
+        private static Regex dbPhotoRegex0 = new Regex ("/databases/([0-9]*?)/items$");
+		private static Regex dbPhotoRegex = new Regex (".*'dmap.itemid:([0-9]*)'.*"); 
         private static Regex dbContainersRegex = new Regex ("/databases/([0-9]*?)/containers$");
         private static Regex dbContainerItemsRegex = new Regex ("/databases/([0-9]*?)/containers/([0-9]*?)/items$");
         
@@ -532,7 +535,7 @@
             running = true;
             ws.Start ();
 
-            if (publish)
+           // if (publish)
                 RegisterService ();
         }
 
@@ -587,7 +590,7 @@
                 zc_service = new RegisterService ();
                 zc_service.Name = serverInfo.Name;
                 zc_service.RegType = "_dpap._tcp";
-                zc_service.Port = (short)ws.BoundPort;
+                zc_service.Port = 8770; //(short)ws.BoundPort;
                 zc_service.TxtRecord = new TxtRecord ();
                 zc_service.TxtRecord.Add ("Password", auth);
                 zc_service.TxtRecord.Add ("Machine Name", serverInfo.Name);
@@ -660,12 +663,16 @@
         }
 
         internal bool OnHandleRequest (Socket client, string username, string path, NameValueCollection query, int range) {
-
+			string photoQuery;
+			if(query["query"] != null)
+				photoQuery = query["query"];
+			else
+				photoQuery = "";
             int session = 0;
             if (query["session-id"] != null) {
                 session = Int32.Parse (query["session-id"]);
             }
-
+			
 /*            if (!sessions.ContainsKey (session) && path != "/server-info" && path != "/content-codes" &&
                 path != "/login") {
                 ws.WriteResponse (client, HttpStatusCode.Forbidden, "invalid session id");
@@ -685,7 +692,7 @@
             if (query["delta"] != null) {
                 delta = Int32.Parse (query["delta"]);
             }
-			Console.WriteLine("Before returning resources");
+			Console.WriteLine("Before returning resources for path " + path);
             if (path == "/server-info") {
                 ws.WriteResponse (client, GetServerInfoNode ());
             } else if (path == "/content-codes") {
@@ -719,8 +726,10 @@
                 
                 return false;
             } else if (path == "/databases") {
+				Console.WriteLine("path==/databases");
                 ws.WriteResponse (client, GetDatabasesNode ());
-            } else if (dbItemsRegex.IsMatch (path)) {
+            } else if (dbItemsRegex.IsMatch (path) && photoQuery.Length==0 ){ //&& !dbPhotoRegex.IsMatch(query["query"])) {
+				Console.WriteLine("dbItemsRegex, query=" + query["query"] + " meta=" + query["meta"]);
                 int dbid = Int32.Parse (dbItemsRegex.Match (path).Groups[1].Value);
 
                 Database curdb = revmgr.GetDatabase (clientRev, dbid);
@@ -746,10 +755,12 @@
                 ContentNode node = curdb.ToPhotosNode (query["meta"].Split (','),
                                                       (int[]) deletedIds.ToArray (typeof (int)));
                 ws.WriteResponse (client, node);
-            } else if (dbPhotoRegex.IsMatch (path)) {
-                Match match = dbPhotoRegex.Match (path);
+            } else if (dbPhotoRegex.IsMatch (photoQuery)) {
+				Console.WriteLine("dbPhotoRegex");
+                Match match = dbPhotoRegex0.Match (path);
                 int dbid = Int32.Parse (match.Groups[1].Value);
-                int photoid = Int32.Parse (match.Groups[2].Value);
+				match = dbPhotoRegex.Match(photoQuery);
+                int photoid = Int32.Parse (match.Groups[1].Value);
 
                 Database db = revmgr.GetDatabase (clientRev, dbid);
                 if (db == null) {
@@ -758,6 +769,7 @@
                 }
 
                 Photo photo = db.LookupPhotoById (photoid);
+				Console.WriteLine(photo.ToString());
                 if (photo == null) {
                     ws.WriteResponse (client, HttpStatusCode.BadRequest, "invalid photo id");
                     return true;
@@ -772,8 +784,13 @@
                     } catch {}
                     
                     if (photo.FileName != null) {
+						Console.WriteLine("photo.Filename != null" + query["meta"].Split (',')[0]);
+						ContentNode node = photo.ToFileData();
+						node.Dump();
+						ws.WriteResponse (client, node);
                         ws.WriteResponseFile (client, photo.FileName, range);
                     } else if (db.Client != null) {
+						Console.WriteLine("db.Client != null");
                         long photoLength = 0;
                         Stream photoStream = db.StreamPhoto (photo, out photoLength);
                         
@@ -782,6 +799,7 @@
                         } catch (IOException) {
                         }
                     } else {
+						Console.WriteLine("Else - internal error");
                         ws.WriteResponse (client, HttpStatusCode.InternalServerError, "no file");
                     }
                 } finally {

Modified: trunk/dpap-sharp/lib/ServerInfo.cs
==============================================================================
--- trunk/dpap-sharp/lib/ServerInfo.cs	(original)
+++ trunk/dpap-sharp/lib/ServerInfo.cs	Mon Jul 21 09:24:17 2008
@@ -76,20 +76,21 @@
         internal ContentNode ToNode (int dbCount) {
             return new ContentNode ("dmap.serverinforesponse",
                                     new ContentNode ("dmap.status", 200),
-                                    new ContentNode ("dmap.protocolversion", new Version (2, 0, 2)),
-                                    //new ContentNode ("dpap.protocolversion", new Version (3, 0, 2)),
-                                    new ContentNode ("dmap.itemname", name),
+                                    new ContentNode ("dmap.protocolversion", new Version (2, 0, 0)),
+                                    new ContentNode ("dpap.protocolversion", new Version (1, 0, 1)),
+			                        
+                                    new ContentNode ("dmap.itemname", "photos"),
                                     new ContentNode ("dmap.loginrequired", (byte) 1),
-                                    new ContentNode ("dmap.authenticationmethod", (byte) authMethod),
+                                //    new ContentNode ("dmap.authenticationmethod", (byte) authMethod),
                                     new ContentNode ("dmap.timeoutinterval", (int) Server.DefaultTimeout.TotalSeconds),
                                     new ContentNode ("dmap.supportsautologout", (byte) 1),
-                                    new ContentNode ("dmap.supportsupdate", (byte) 1),
-                                    new ContentNode ("dmap.supportspersistentids", (byte) 1),
-                                    new ContentNode ("dmap.supportsextensions", (byte) 1),
-                                    new ContentNode ("dmap.supportsbrowse", (byte) 1),
-                                    new ContentNode ("dmap.supportsquery", (byte) 1),
+                                 //   new ContentNode ("dmap.supportsupdate", (byte) 1),
+                                 //   new ContentNode ("dmap.supportspersistentids", (byte) 1),
+                                 //   new ContentNode ("dmap.supportsextensions", (byte) 1),
+                                 //   new ContentNode ("dmap.supportsbrowse", (byte) 1),
+                                 //   new ContentNode ("dmap.supportsquery", (byte) 1),
                                     new ContentNode ("dmap.supportsindex", (byte) 1),
-                                    new ContentNode ("dmap.supportsresolve", (byte) 0),
+                                 //   new ContentNode ("dmap.supportsresolve", (byte) 0),
                                     new ContentNode ("dmap.databasescount", dbCount));
         }
 

Modified: trunk/dpap-sharp/lib/content-codes
==============================================================================
Binary files. No diff available.



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