Author: gonzalo
Date: 2006-08-07 23:35:09 -0400 (Mon, 07 Aug 2006)
New Revision: 63463

Added:
   trunk/gnome-keyring-sharp/src/Gnome.Keyring/AccessRights.cs
   trunk/gnome-keyring-sharp/src/Gnome.Keyring/ItemACL.cs
   trunk/gnome-keyring-sharp/src/Gnome.Keyring/KeyringInfo.cs
Modified:
   trunk/gnome-keyring-sharp/ChangeLog
   trunk/gnome-keyring-sharp/README
   trunk/gnome-keyring-sharp/sample/secret.cs
   trunk/gnome-keyring-sharp/src/Gnome.Keyring/Makefile.am
   trunk/gnome-keyring-sharp/src/Gnome.Keyring/ResponseMessage.cs
   trunk/gnome-keyring-sharp/src/Gnome.Keyring/Ring.cs
   trunk/gnome-keyring-sharp/src/Makefile.am
Log:
2006-08-07 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>

        * sample/secret.cs: updated example.

        * src/Makefile.am:
        * src/Gnome.Keyring/Makefile.am: add new files.

        * src/Gnome.Keyring/ItemACL.cs: new class that stores ACL information.
        * src/Gnome.Keyring/AccessRights.cs: enum with access rights.
        * src/Gnome.Keyring/KeyringInfo.cs: keyring information.
        * src/Gnome.Keyring/ResponseMessage.cs: add GetDateTime().
        * src/Gnome.Keyring/Ring.cs: implemented Get/SetItemACL,
        Get/SetKeyringInfo. Nothing left to implement.
        * README: typo.



Modified: trunk/gnome-keyring-sharp/ChangeLog
===================================================================
--- trunk/gnome-keyring-sharp/ChangeLog 2006-08-08 03:31:57 UTC (rev 63462)
+++ trunk/gnome-keyring-sharp/ChangeLog 2006-08-08 03:35:09 UTC (rev 63463)
@@ -1,5 +1,20 @@
 2006-08-07 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
 
+       * sample/secret.cs: updated example.
+
+       * src/Makefile.am:
+       * src/Gnome.Keyring/Makefile.am: add new files.
+
+       * src/Gnome.Keyring/ItemACL.cs: new class that stores ACL information.
+       * src/Gnome.Keyring/AccessRights.cs: enum with access rights.
+       * src/Gnome.Keyring/KeyringInfo.cs: keyring information.
+       * src/Gnome.Keyring/ResponseMessage.cs: add GetDateTime().
+       * src/Gnome.Keyring/Ring.cs: implemented Get/SetItemACL,
+       Get/SetKeyringInfo. Nothing left to implement.
+       * README: typo.
+
+2006-08-07 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
        * src/Gnome.Keyring/RequestMessage.cs: the application name is not
        obtained here any more.
        

Modified: trunk/gnome-keyring-sharp/README
===================================================================
--- trunk/gnome-keyring-sharp/README    2006-08-08 03:31:57 UTC (rev 63462)
+++ trunk/gnome-keyring-sharp/README    2006-08-08 03:35:09 UTC (rev 63463)
@@ -2,7 +2,7 @@
 
 README for gnome-keyring-sharp
 ---------------------------
-gnome-keyring-sharp is a fully managed implementation if libgnome-keyring.
+gnome-keyring-sharp is a fully managed implementation of libgnome-keyring.
 
 When the gnome-keyring-daemon is running, you can use this to retrive/store
 confidential information such as passwords, notes or network services user

Modified: trunk/gnome-keyring-sharp/sample/secret.cs
===================================================================
--- trunk/gnome-keyring-sharp/sample/secret.cs  2006-08-08 03:31:57 UTC (rev 
63462)
+++ trunk/gnome-keyring-sharp/sample/secret.cs  2006-08-08 03:35:09 UTC (rev 
63463)
@@ -77,6 +77,7 @@
 
                        atts ["object"] = "new attributes";
                        Ring.SetItemAttributes (deflt, i, atts);
+                       Console.WriteLine ("Press any key to continue...");
                        Console.ReadLine ();
 
                        Console.WriteLine ("Deleting it (ID = {0})", i);
@@ -85,6 +86,22 @@
                        foreach (int nn in Ring.ListItemIDs (deflt)) {
                                Console.WriteLine (nn);
                        }
+
+                       KeyringInfo info = new KeyringInfo (true, 15);
+                       Ring.SetKeyringInfo (deflt, info);
+
+                       info = Ring.GetKeyringInfo (deflt);
+                       Console.WriteLine (info);
+                       ArrayList acl_list = Ring.GetItemACL (deflt, 3);
+                       foreach (ItemACL acl in acl_list)
+                               Console.WriteLine (acl);
+
+                       ArrayList list2 = new ArrayList (acl_list);
+                       list2.Add (new ItemACL ("test", "/test", 
AccessRights.Read));
+                       Ring.SetItemACL (deflt, 3, list2);
+                       Console.WriteLine ("Press any key to continue...");
+                       Console.ReadLine ();
+                       Ring.SetItemACL (deflt, 3, acl_list);
                }
        }
 }

Added: trunk/gnome-keyring-sharp/src/Gnome.Keyring/AccessRights.cs
===================================================================
--- trunk/gnome-keyring-sharp/src/Gnome.Keyring/AccessRights.cs 2006-08-08 
03:31:57 UTC (rev 63462)
+++ trunk/gnome-keyring-sharp/src/Gnome.Keyring/AccessRights.cs 2006-08-08 
03:35:09 UTC (rev 63463)
@@ -0,0 +1,39 @@
+//
+// Gnome.Keyring.AccessRights.cs
+//
+// Authors:
+//     Gonzalo Paniagua Javier ([EMAIL PROTECTED])
+//
+// (C) Copyright 2006 Novell, Inc. (http://www.novell.com)
+//
+
+// 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;
+namespace Gnome.Keyring {
+       [Flags]
+       public enum AccessRights {
+               Read = 1,
+               Write = 1 << 1,
+               Remove = 1 << 2
+       }
+}
+


Property changes on: trunk/gnome-keyring-sharp/src/Gnome.Keyring/AccessRights.cs
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/gnome-keyring-sharp/src/Gnome.Keyring/ItemACL.cs
===================================================================
--- trunk/gnome-keyring-sharp/src/Gnome.Keyring/ItemACL.cs      2006-08-08 
03:31:57 UTC (rev 63462)
+++ trunk/gnome-keyring-sharp/src/Gnome.Keyring/ItemACL.cs      2006-08-08 
03:35:09 UTC (rev 63463)
@@ -0,0 +1,63 @@
+//
+// Gnome.Keyring.ItemACL.cs
+//
+// Authors:
+//     Gonzalo Paniagua Javier ([EMAIL PROTECTED])
+//
+// (C) Copyright 2006 Novell, Inc. (http://www.novell.com)
+//
+
+// 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;
+
+namespace Gnome.Keyring {
+       public class ItemACL {
+               string display_name;
+               string path;
+               AccessRights access;
+
+               public ItemACL (string displayName, string path, AccessRights 
access)
+               {
+                       this.display_name = displayName;
+                       this.path = path;
+                       this.access = (AccessRights) access;
+               }
+
+               public override string ToString ()
+               {
+                       return String.Format ("Name: {0} Path: {1} Access: 
{2}", display_name, path, access);
+               }
+
+               public string DisplayName {
+                       get { return display_name; }
+               }
+
+               public string FullPath {
+                       get { return path; }
+               }
+
+               public AccessRights Access {
+                       get { return access; }
+               }
+       }
+}
+


Property changes on: trunk/gnome-keyring-sharp/src/Gnome.Keyring/ItemACL.cs
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/gnome-keyring-sharp/src/Gnome.Keyring/KeyringInfo.cs
===================================================================
--- trunk/gnome-keyring-sharp/src/Gnome.Keyring/KeyringInfo.cs  2006-08-08 
03:31:57 UTC (rev 63462)
+++ trunk/gnome-keyring-sharp/src/Gnome.Keyring/KeyringInfo.cs  2006-08-08 
03:35:09 UTC (rev 63463)
@@ -0,0 +1,99 @@
+//
+// Gnome.Keyring.KeyringInfo.cs
+//
+// Authors:
+//     Gonzalo Paniagua Javier ([EMAIL PROTECTED])
+//
+// (C) Copyright 2006 Novell, Inc. (http://www.novell.com)
+//
+
+// 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;
+namespace Gnome.Keyring {
+       public class KeyringInfo {
+               int lock_timeout;
+               DateTime mtime;
+               DateTime ctime;
+               bool lock_on_idle;
+               bool locked;
+
+               internal KeyringInfo (bool lock_on_idle, int lock_timeout, 
DateTime mtime, DateTime ctime, bool locked)
+               {
+                       this.lock_timeout = lock_timeout;
+                       this.mtime = mtime;
+                       this.ctime = ctime;
+                       this.lock_on_idle = lock_on_idle;
+                       this.locked = locked;
+               }
+
+               public KeyringInfo ()
+               {
+               }
+
+               public KeyringInfo (bool lockOnIdle) : this (lockOnIdle, 0)
+               {
+               }
+
+               public KeyringInfo (bool lockOnIdle, int lockTimeout)
+               {
+                       this.lock_on_idle = lockOnIdle;
+                       LockTimeoutSeconds = lockTimeout;
+               }
+
+               public override string ToString ()
+               {
+                       return String.Format ("LockOnIdle: {0}\n" +
+                                               "Locked: {1}\n" +
+                                               "Lock timeout: {2}\n" +
+                                               "Creation time: {3}\n" +
+                                               "Modification time: {4}\n",
+                                               lock_on_idle, locked, 
lock_timeout, ctime, mtime);
+               }
+
+               public bool LockOnIdle {
+                       get { return lock_on_idle; }
+                       set { lock_on_idle = value; }
+               }
+
+               public int LockTimeoutSeconds {
+                       get { return lock_timeout; }
+                       set {
+                               if (value < 0)
+                                       throw new ArgumentOutOfRangeException 
("value");
+                               lock_timeout = value;
+                       }
+               }
+
+               public DateTime ModificationTime {
+                       get { return mtime; }
+               }
+
+               public DateTime CreationTime {
+                       get { return ctime; }
+               }
+
+               public bool Locked {
+                       get { return locked; }
+               }
+       }
+}
+


Property changes on: trunk/gnome-keyring-sharp/src/Gnome.Keyring/KeyringInfo.cs
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: trunk/gnome-keyring-sharp/src/Gnome.Keyring/Makefile.am
===================================================================
--- trunk/gnome-keyring-sharp/src/Gnome.Keyring/Makefile.am     2006-08-08 
03:31:57 UTC (rev 63462)
+++ trunk/gnome-keyring-sharp/src/Gnome.Keyring/Makefile.am     2006-08-08 
03:35:09 UTC (rev 63463)
@@ -1,11 +1,13 @@
 EXTRA_DIST=\
+               AccessRights.cs \
                AssemblyInfo.cs.in \
                AttributeType.cs \
                GenericItemData.cs \
+               ItemACL.cs \
                ItemData.cs \
                ItemType.cs \
                KeyringException.cs \
-               Makefile.am \
+               KeyringInfo.cs \
                NetItemData.cs \
                NoteItemData.cs \
                Operation.cs \

Modified: trunk/gnome-keyring-sharp/src/Gnome.Keyring/ResponseMessage.cs
===================================================================
--- trunk/gnome-keyring-sharp/src/Gnome.Keyring/ResponseMessage.cs      
2006-08-08 03:31:57 UTC (rev 63462)
+++ trunk/gnome-keyring-sharp/src/Gnome.Keyring/ResponseMessage.cs      
2006-08-08 03:35:09 UTC (rev 63463)
@@ -32,6 +32,8 @@
 using System.IO;
 using System.Text;
 
+using Mono.Unix.Native;
+
 namespace Gnome.Keyring {
        class ResponseMessage {
                byte [] buffer;
@@ -79,6 +81,11 @@
                        return (b0 + (b1 << 8) + (b2 << 16) + (b3 << 24));
                }
 
+               public DateTime GetDateTime ()
+               {
+                       return NativeConvert.FromTimeT ((GetInt32 () << 32) + 
GetInt32 ());
+               }
+
                public void ReadAttributes (Hashtable tbl)
                {
                        int natts = GetInt32 ();

Modified: trunk/gnome-keyring-sharp/src/Gnome.Keyring/Ring.cs
===================================================================
--- trunk/gnome-keyring-sharp/src/Gnome.Keyring/Ring.cs 2006-08-08 03:31:57 UTC 
(rev 63462)
+++ trunk/gnome-keyring-sharp/src/Gnome.Keyring/Ring.cs 2006-08-08 03:35:09 UTC 
(rev 63463)
@@ -35,7 +35,6 @@
 using System.Reflection;
 
 using Mono.Unix;
-using Mono.Unix.Native;
 
 namespace Gnome.Keyring {
        public class Ring {
@@ -336,15 +335,15 @@
                        ItemData item = ItemData.GetInstanceFromItemType 
(itype);
                        string name = resp.GetString ();
                        string secret = resp.GetString ();
-                       long mtime = (resp.GetInt32 () << 32) + resp.GetInt32 
();
-                       long ctime = (resp.GetInt32 () << 32) + resp.GetInt32 
();
+                       DateTime mtime = resp.GetDateTime ();
+                       DateTime ctime =  resp.GetDateTime ();
                        item.Keyring = keyring;
                        item.ItemID = id;
                        item.Secret = secret;
                        Hashtable tbl = new Hashtable ();
                        tbl ["name"] = name;
-                       tbl ["keyring_ctime"] = NativeConvert.FromTimeT (ctime);
-                       tbl ["keyring_mtime"] = NativeConvert.FromTimeT (mtime);
+                       tbl ["keyring_ctime"] = ctime;
+                       tbl ["keyring_mtime"] = mtime;
                        item.Attributes = tbl;
                        item.SetValuesFromAttributes ();
                        return item;
@@ -393,12 +392,88 @@
                        SendRequest (req.Stream);
                }
 
-               /*
-               * TODO:
-                       GetKeyringInfo,
-                       SetKeyringInfo,
-                       GetItemACL,
-                       SetItemACL
-               */
+               public static KeyringInfo GetKeyringInfo (string keyring)
+               {
+                       if (keyring == null)
+                               throw new ArgumentNullException ("keyring");
+
+                       RequestMessage req = new RequestMessage ();
+                       req.CreateSimpleOperation (Operation.GetKeyringInfo, 
keyring);
+                       ResponseMessage resp = SendRequest (req.Stream);
+                       return new KeyringInfo ((resp.GetInt32 () != 0),
+                                                       resp.GetInt32 (),
+                                                       resp.GetDateTime (),
+                                                       resp.GetDateTime (),
+                                                       (resp.GetInt32 () != 
0));
+               }
+
+               public static void SetKeyringInfo (string keyring, KeyringInfo 
info)
+               {
+                       if (keyring == null)
+                               throw new ArgumentNullException ("keyring");
+
+                       if (info == null)
+                               throw new ArgumentNullException ("info");
+
+                       RequestMessage req = new RequestMessage ();
+                       req.StartOperation (Operation.SetKeyringInfo);
+                       req.Write (keyring);
+                       req.Write (info.LockOnIdle ? 1 : 0);
+                       req.Write (info.LockTimeoutSeconds);
+                       req.EndOperation ();
+                       SendRequest (req.Stream);
+               }
+
+               public static ArrayList GetItemACL (string keyring, int id)
+               {
+                       if (keyring == null)
+                               throw new ArgumentNullException ("keyring");
+
+                       RequestMessage req = new RequestMessage ();
+                       req.CreateSimpleOperation (Operation.GetItemACL, 
keyring, id);
+                       ResponseMessage resp = SendRequest (req.Stream);
+                       int count = resp.GetInt32 ();
+                       ArrayList list = new ArrayList (count);
+                       for (int i = 0; i < count; i++) {
+                               list.Add (new ItemACL (resp.GetString (), 
resp.GetString (), (AccessRights) resp.GetInt32 ()));
+                       }
+                       return list;
+               }
+
+               public static void SetItemACL (string keyring, int id, 
ICollection acls)
+               {
+                       if (acls == null)
+                               throw new ArgumentNullException ("acls");
+
+                       ItemACL [] arr = new ItemACL [acls.Count];
+                       acls.CopyTo (arr, 0);
+                       SetItemACL (keyring, id, arr);
+               }
+
+               public static void SetItemACL (string keyring, int id, ItemACL 
[] acls)
+               {
+                       if (keyring == null)
+                               throw new ArgumentNullException ("keyring");
+
+                       if (acls == null)
+                               throw new ArgumentNullException ("acls");
+
+                       if (acls.Length == 0)
+                               throw new ArgumentException ("Empty ACL set.", 
"acls");
+
+                       RequestMessage req = new RequestMessage ();
+                       req.StartOperation (Operation.SetItemACL);
+                       req.Write (keyring);
+                       req.Write (id);
+                       req.Write (acls.Length);
+                       foreach (ItemACL acl in acls) {
+                               req.Write (acl.DisplayName);
+                               req.Write (acl.FullPath);
+                               req.Write ((int) acl.Access);
+                       }
+                       req.EndOperation ();
+                       SendRequest (req.Stream);
+               }
        }
 }
+

Modified: trunk/gnome-keyring-sharp/src/Makefile.am
===================================================================
--- trunk/gnome-keyring-sharp/src/Makefile.am   2006-08-08 03:31:57 UTC (rev 
63462)
+++ trunk/gnome-keyring-sharp/src/Makefile.am   2006-08-08 03:35:09 UTC (rev 
63463)
@@ -13,11 +13,14 @@
 gnomekeyring_references=
 
 gnomekeyring_sources  = \
+                       Gnome.Keyring/AccessRights.cs \
                        Gnome.Keyring/AttributeType.cs \
                        Gnome.Keyring/GenericItemData.cs \
+                       Gnome.Keyring/ItemACL.cs \
                        Gnome.Keyring/ItemData.cs \
                        Gnome.Keyring/ItemType.cs \
                        Gnome.Keyring/KeyringException.cs \
+                       Gnome.Keyring/KeyringInfo.cs \
                        Gnome.Keyring/NetItemData.cs \
                        Gnome.Keyring/NoteItemData.cs \
                        Gnome.Keyring/Operation.cs \

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to