Commits

Marcin Kasperski committed 02326df

Sensible example

Comments (0)

Files changed (2)

experiments/dbus_introspect.txt

+DBus connected
+org.kde.kwalletd connected
+/modules/kwalletd connected
+net_wallet id: kdewallet
+Opened, handle = 188466638
+*****************************************************************
+* API information
+*****************************************************************
+* Supported interfaces:
+    org.freedesktop.DBus.Properties
+    org.freedesktop.DBus.Introspectable
+    org.freedesktop.DBus.Peer
+    org.kde.KWallet
+
+* org.kde.KWallet methods:
+
+changePassword 
+    Params:
+        wallet: string
+        wId: int64
+        appid: string
+    Returns:
+
+close 
+    Params:
+        handle: int32
+        force: bool
+        appid: string
+    Returns:
+        : int32
+
+closeAllWallets 
+    Params:
+    Returns:
+
+createFolder 
+    Params:
+        handle: int32
+        folder: string
+        appid: string
+    Returns:
+        : bool
+
+deleteWallet 
+    Params:
+        wallet: string
+    Returns:
+        : int32
+
+disconnectApplication 
+    Params:
+        wallet: string
+        application: string
+    Returns:
+        : bool
+
+entryList 
+    Params:
+        handle: int32
+        folder: string
+        appid: string
+    Returns:
+        : (array, string)
+
+entryType 
+    Params:
+        handle: int32
+        folder: string
+        key: string
+        appid: string
+    Returns:
+        : int32
+
+folderDoesNotExist 
+    Params:
+        wallet: string
+        folder: string
+    Returns:
+        : bool
+
+folderList 
+    Params:
+        handle: int32
+        appid: string
+    Returns:
+        : (array, string)
+
+hasEntry 
+    Params:
+        handle: int32
+        folder: string
+        key: string
+        appid: string
+    Returns:
+        : bool
+
+hasFolder 
+    Params:
+        handle: int32
+        folder: string
+        appid: string
+    Returns:
+        : bool
+
+isEnabled 
+    Params:
+    Returns:
+        : bool
+
+isOpen 
+    Params:
+        handle: int32
+    Returns:
+        : bool
+
+keyDoesNotExist 
+    Params:
+        wallet: string
+        folder: string
+        key: string
+    Returns:
+        : bool
+
+localWallet 
+    Params:
+    Returns:
+        : string
+
+networkWallet 
+    Params:
+    Returns:
+        : string
+
+open 
+    Params:
+        wallet: string
+        wId: int64
+        appid: string
+    Returns:
+        : int32
+
+openAsync 
+    Params:
+        wallet: string
+        wId: int64
+        appid: string
+        handleSession: bool
+    Returns:
+        : int32
+
+openPath 
+    Params:
+        path: string
+        wId: int64
+        appid: string
+    Returns:
+        : int32
+
+openPathAsync 
+    Params:
+        path: string
+        wId: int64
+        appid: string
+        handleSession: bool
+    Returns:
+        : int32
+
+pamOpen 
+    Params:
+        wallet: string
+        passwordHash: (array, byte)
+        sessionTimeout: int32
+    No reply
+
+readEntry 
+    Params:
+        handle: int32
+        folder: string
+        key: string
+        appid: string
+    Returns:
+        : (array, byte)
+
+readEntryList 
+    Params:
+        handle: int32
+        folder: string
+        key: string
+        appid: string
+    Returns:
+        : (dict, string, (variant))
+
+readMap 
+    Params:
+        handle: int32
+        folder: string
+        key: string
+        appid: string
+    Returns:
+        : (array, byte)
+
+readMapList 
+    Params:
+        handle: int32
+        folder: string
+        key: string
+        appid: string
+    Returns:
+        : (dict, string, (variant))
+
+readPassword 
+    Params:
+        handle: int32
+        folder: string
+        key: string
+        appid: string
+    Returns:
+        : string
+
+readPasswordList 
+    Params:
+        handle: int32
+        folder: string
+        key: string
+        appid: string
+    Returns:
+        : (dict, string, (variant))
+
+reconfigure 
+    Params:
+    Returns:
+
+removeEntry 
+    Params:
+        handle: int32
+        folder: string
+        key: string
+        appid: string
+    Returns:
+        : int32
+
+removeFolder 
+    Params:
+        handle: int32
+        folder: string
+        appid: string
+    Returns:
+        : bool
+
+renameEntry 
+    Params:
+        handle: int32
+        folder: string
+        oldName: string
+        newName: string
+        appid: string
+    Returns:
+        : int32
+
+sync 
+    Params:
+        handle: int32
+        appid: string
+    No reply
+
+users 
+    Params:
+        wallet: string
+    Returns:
+        : (array, string)
+
+wallets 
+    Params:
+    Returns:
+        : (array, string)
+
+writeEntry 
+    Params:
+        handle: int32
+        folder: string
+        key: string
+        value: (array, byte)
+        appid: string
+    Returns:
+        : int32
+
+writeMap 
+    Params:
+        handle: int32
+        folder: string
+        key: string
+        value: (array, byte)
+        appid: string
+    Returns:
+        : int32
+
+writePassword 
+    Params:
+        handle: int32
+        folder: string
+        key: string
+        value: string
+        appid: string
+    Returns:
+        : int32
+*****************************************************************

experiments/kwallet_by_dbus.pl

 use feature 'say';
 
 my $APP_NAME = "DBUStest";
+my $FOLDER_NAME = "DBUStestfolder";
 
 my $dbus = Net::DBus->session()
   or die("KWallet not available (can't access DBus)");
   or die "No handle";
 say "Opened, handle = $handle";
 
-say "*****************************************************************";
-say "* API information";
-say "*****************************************************************";
-
-use List::MoreUtils qw(pairwise zip);
-
-say "Supported interfaces:\n    ", join("\n    ", keys(%{$kwallet->{introspector}->{interfaces}}));
-say "org.kde.KWallet methods:";
-my $methods = $kwallet->{introspector}->{interfaces}->{'org.kde.KWallet'}->{methods};
-foreach my $methodName (sort keys %$methods) {
-    my $spec = $methods->{$methodName};
-    say "- $methodName ", $spec->{deprecated} ? "DEPRECATED" : "";
-    say "    Params:";
-    foreach my $paramSpec (pairwise {"$a: $b"} @{$spec->{paramnames}}, @{$spec->{params}}) {
-        say "      $paramSpec";
-    }
-    unless($spec->{no_reply}) {
-        say "    Returns:";
-        foreach my $retSpec (pairwise {($a || ''). ": $b"} @{$spec->{returnnames}}, @{$spec->{returns}}) {
-            say "      $retSpec";
-        }
-    } else {
-        say "    No reply";
-    }
-    #print Dumper($spec);
-}
-
-say "*****************************************************************";
-
-
 my $is_open = $kwallet->isOpen($handle);
-say "is open: $is_open";
+say "is open($handle): $is_open";
 
 my $folders = $kwallet->folderList($handle, $APP_NAME);
 say "Folders = ", join(", ", @$folders);
 
+unless($kwallet->hasFolder($handle, $FOLDER_NAME, $APP_NAME)) {
+    say "Folder $FOLDER_NAME does not exists";
+    $kwallet->createFolder($handle, $FOLDER_NAME, $APP_NAME) or die "Failed to create";
+    say "Folder $FOLDER_NAME created";
+} else {
+    say "Folder $FOLDER_NAME already exists";
+}
 
-$kwallet->close($handle, 'force');
+my $password = $kwallet->readPassword($handle, $FOLDER_NAME, "Some key", $APP_NAME);
+say "Read password: ", $password || "(undef)";
+
+my $sth = $kwallet->writePassword($handle, $FOLDER_NAME, "Some key", "Some pass 1", $APP_NAME);
+say "Wrote password, got $sth";
+# NOn-zero output seems to mean failure
+
+my $password = $kwallet->readPassword($handle, $FOLDER_NAME, "Some key", $APP_NAME);
+say "Read password: ", $password || "(undef)";
+
+my $sth = $kwallet->writePassword($handle, $FOLDER_NAME, "Some key", "Some pass 2", $APP_NAME);
+say "Wrote password, got $sth";
+
+my $password = $kwallet->readPassword($handle, $FOLDER_NAME, "Some key", $APP_NAME);
+say "Read password: ", $password || "(undef)";
+
+my $sth = $kwallet->writePassword($handle, $FOLDER_NAME, "Some key", undef, $APP_NAME);
+say "Wrote undef password, got $sth";
+
+my $password = $kwallet->readPassword($handle, $FOLDER_NAME, "Some key", $APP_NAME);
+say "Read password: ", $password || "(undef)";
+
+
+
+
+$kwallet->removeFolder($handle, $FOLDER_NAME, $APP_NAME);
+say "Folder $FOLDER_NAME removed";
+
+# Po close przy ponownym otwieraniu będzie pytanie (cośtam prosi...), bez tego - nie, mimo końca programu
+$kwallet->close($handle, 1, $APP_NAME); # drugi parametr: force
 say "Closed $handle";
 
 $is_open = $kwallet->isOpen($handle);
 __END__
 
 
-$kwallet->createFolder($kwallet_handle, "Test Folder", $APP_NAME);
 
 $kwallet->writePassword( handle, folder, key, value, appid ):
 #???$kwallet->changePassword($kwallet_handle