Checked in for changes in ADLib for Add-Modify-Delete for KWallet and

Keyring
This commit is contained in:
austinsfdsouza
2005-12-16 10:29:25 +00:00
parent aa9c895a41
commit ec113054eb
9 changed files with 1037 additions and 72 deletions

View File

@@ -30,7 +30,13 @@ public class kwallet
[DllImport(CPP_LIB)]
public static extern void FreeList();
[DllImport(CPP_LIB)]
public static extern int SetEntry(string walletName, string folderName, int entryType, string keyName, string value, int valueLen);
[DllImport(CPP_LIB)]
public static extern int SetMapEntry(string walletName, string folderName, string keyName, String[,] value, int eleCount);
[DllImport(CPP_LIB)]
public static extern int RemoveEntry(string walletName, string folderName, string keyName);
/*
public static int Try(EnumSecretList enumSecretList)
@@ -53,6 +59,88 @@ public class kwallet
FreeList();
return 0;
}
public static int SetSecret(string walletName, string folderName, int entryType, string keyName, string value, int valueLen )
{
return(SetEntry(walletName, folderName, entryType, keyName, value, valueLen ));
}
public static int SetSecret(string walletName, string folderName, string keyName, NameValueCollection nvc)
{
//IntPtr[] mapele = new IntPtr[nvc.Count * 2];
String[,] mapele = new String[nvc.Count,2 ];
String str=" ";
int j=0;
for (int i=0; i< nvc.Count; i++)
{
mapele[i,0] = nvc.GetKey(i);
mapele[i,1] = nvc.Get(nvc.GetKey(i));
}
/*
for (int i=0; i< nvc.Count; i++)
{
str = String.Concat(str,nvc.GetKey(i));
str = String.Concat(str, "\0");
str = String.Concat(str,nvc.Get(nvc.GetKey(i)));
str = String.Concat(str, "\0");
}
*/
char[] strarr = str.ToCharArray();
/*for (int i=0; i< nvc.Count; i++)
{
string strKey = nvc.GetKey(i);
Console.WriteLine("Key is " + strKey);
//IntPtr ptr1 = Marshal.AllocHGlobal(strKey.Length);
//Marshal.StructureToPtr(strKey,ptr1,false);
IntPtr ptr1 = Marshal.StringToHGlobalAnsi(strKey);
string strValue = nvc.Get(strKey);
//IntPtr ptr2 = Marshal.AllocHGlobal(strValue.Length);
//Marshal.StructureToPtr(strValue,ptr2,false);
IntPtr ptr2 = Marshal.StringToHGlobalAnsi(strValue);
Console.WriteLine("Value is " + strValue);
//IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(kv));
// Marshal.StructureToPtr(kv,ptr,false);
mapele[j++] = ptr1;
Console.WriteLine("Pointer is " +ptr1);
mapele[j++] = ptr2;
Console.WriteLine("Pointer is " +ptr2);
}
*/
//IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(mapele));
//Marshal.StructureToPtr(mapele,ptr,false);
/*string[] str = {"a","bb","ccc"};
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(str));
Marshal.StructureToPtr(str,ptr,false);
*/
/*Console.WriteLine("Setting Map Entry Keys name is " + keyName); */
return(SetMapEntry(walletName, folderName, keyName, mapele, nvc.Count));
}
public static int DeleteSecret(string walletName, string folderName, string keyName)
{
return(RemoveEntry(walletName, folderName, keyName));
}
//TBD: All this for future.
/*

View File

@@ -46,7 +46,8 @@ using namespace KWallet;
{
// Read the secret from the entry
QByteArray value;
QByteArray value;
printf("kwallet: Read Key entered\n");
if (wallet->readEntry(key, value)==0)
{
@@ -61,9 +62,13 @@ using namespace KWallet;
if (wallet->entryType(key) == 1 )
{
// Convert the ByteArray to QString
//Commented by Austin
/* // Convert the ByteArray to QString
QString passwd;
printf("In read Entry Convert Final before success\n");
convert >> passwd;
printf("In read Entry Convert Final success\n");
*/
} else if (wallet->entryType(key) == 3)
{
@@ -137,14 +142,15 @@ using namespace KWallet;
extern "C"
{
static struct EnumSecretList *tempEnumSecrets = NULL;
static struct EnumSecretList *tempEnumSecrets = NULL;
//void MyTest(struct EnumSecretList *enumWalletSecrets)
void Aggregate(struct EnumSecretList *enumWalletSecrets)
{
printf("inside natiove agg");
int retVal = 0;
tempEnumSecrets = NULL;
tempEnumSecrets = NULL;
retVal = win->ReadAllWalletSecrets(&tempEnumSecrets);
struct EnumSecretList *iter = tempEnumSecrets;
@@ -203,6 +209,28 @@ extern "C"
*/
}
int RemoveEntry(char *name, char *foldername, char *keyname)
{
DCOPDemoWidget kw;
return(kw.RemoveEntry(name,foldername,keyname));
}
int SetEntry(char *name, char *foldername, int entryType, char *keyname, char *value, int valueLen )
{
DCOPDemoWidget kw;
printf("kwallet : In Set Entry\n");
return(kw.SetEntry(name,foldername,entryType,keyname,value,valueLen));
}
int SetMapEntry(char *name, char *foldername, char *keyname, char **value, int eleCount )
{
DCOPDemoWidget kw;
printf("kwallet: SetMapEntry\n");
return(kw.SetMap(name,foldername,keyname,value,eleCount));
}
@@ -223,11 +251,12 @@ extern "C"
free(head);
head = temp;
}
tempEnumSecrets = NULL;
tempEnumSecrets = NULL;
}
}
@@ -334,10 +363,12 @@ extern "C"
//Commented by Austin
QDataStream convert(*secretVal, IO_ReadOnly);
QString passwd;
convert >> passwd;
//QString passwd(*secretVal);
printf("kwallet : ReadAll key %s value %s \n",key.latin1(), passwd.latin1());
tempWalletSecrets->secretVal = (char*)malloc(512);
if (tempWalletSecrets->secretVal == NULL)
@@ -385,6 +416,143 @@ extern "C"
}
int DCOPDemoWidget::SetEntry(char *name, char *foldername, int entryType, char *keyname, char *value, int valueLen )
{
QString qWalletName(name);
QString qKey(keyname);
QString qFolderName(foldername);
QString &refQKey = qKey;
// Open the wallet
Wallet *wallet = NULL;
wallet = Wallet::openWallet(qWalletName,0,Wallet::Synchronous);
if (wallet == NULL)
{
printf("Could not open the wallet %s \n", qWalletName.latin1());
return KWALLET_RESULT_CANNOT_OPEN_WALLET;
}
if (wallet->setFolder(qFolderName) == false)
{
printf("Could not open the folder %s \n", qFolderName.latin1());
return KWALLET_RESULT_CANNOT_OPEN_FOLDER;
}
QString unicodeValue = tr(value);
// Read the secret from the entry
//QByteArray secretVal(valueLen *2 );
QByteArray secretVal;
QDataStream ds(secretVal, IO_WriteOnly);
ds << unicodeValue;
/*for(int i=0; i< valueLen; i++)
{
secretVal[i] = 0;
secretVal[i+1] = value[i];
}
*/
//secretVal[valueLen] = '\0';
// secretVal.fill('a');
//secretVal.setRawData(value,valueLen);
QByteArray &refSecretVal = secretVal;
//QDataStream convert( secretVal, IO_WriteOnly );
//convert.readBytes( value, (uint)valueLen);
// Wallet::EntryType MyEntryType = 3;
if (wallet->entryType(qKey) != 3)
{
printf("kwallet : SetEntry : Before setting Entry key %s value = %s EntryType =%d \n" , qKey.latin1() , value, entryType );
if (wallet->writeEntry(refQKey, refSecretVal , (Wallet::EntryType) entryType ) != 0)
{
return KWALLET_RESULT_CANNOT_WRITE_ENTRY;
}
}
// Free memory
wallet->sync();
return KWALLET_RESULT_OK;
}
int DCOPDemoWidget::SetMap(char *name, char *foldername, char *keyname, char **value, int numOfKeys )
{
QString qWalletName(name);
QString qKey(keyname);
QString qFolderName(foldername);
printf("kwallet : SetMap : Wallet %s Folder %s Key =%s\n", name, foldername, keyname);
// Open the wallet
Wallet *wallet = NULL;
wallet = Wallet::openWallet(qWalletName,0,Wallet::Synchronous);
if (wallet == NULL)
{
printf("Could not open the wallet\n");
return KWALLET_RESULT_CANNOT_OPEN_WALLET;
}
if (wallet->hasFolder(qFolderName) == false)
{
if(wallet->createFolder(qFolderName) == false)
{
return KWALLET_RESULT_CANNOT_CREATE_FOLDER;
}
}
if (wallet->setFolder(qFolderName) == false)
{
return KWALLET_RESULT_CANNOT_OPEN_FOLDER;
}
QMap<QString,QString> mapSecret;
for (int i=0; i < numOfKeys * 2; i+=2)
{
QString mapelekey((char *)value[i]);
QString mapelevalue((char *)value[i+1]);
mapSecret.insert(mapelekey,mapelevalue);
}
if (wallet->writeMap(qKey,mapSecret) != 0 )
{
return KWALLET_RESULT_CANNOT_WRITE_ENTRY;
}
wallet->sync();
return KWALLET_RESULT_OK;
}
int DCOPDemoWidget::RemoveEntry(char *name, char *foldername, char *keyname )
{
QString qWalletName(name);
QString qKey(keyname);
QString qFolderName(foldername);
printf("In DCOPDemoWidget:RemoveEntry\n");
printf("In DCOPDemoWidget:False %d\n",false);
printf("In DCOPDemoWidget:False %d\n",FALSE);
// Open the wallet
Wallet *wallet = NULL;
wallet = Wallet::openWallet(qWalletName,0,Wallet::Synchronous);
if (wallet == NULL)
{
printf("Could not open the wallet %s \n", qWalletName.latin1());
return KWALLET_RESULT_CANNOT_OPEN_WALLET;
}
if (wallet->setFolder(qFolderName) == false)
{
printf("Could not set the folder %s \n", qFolderName.latin1());
return KWALLET_RESULT_CANNOT_OPEN_FOLDER;
}
if (wallet->removeEntry(qKey) != 0)
{
printf("Could not remove Entry %s \n", qKey.latin1());
return KWALLET_RESULT_CANNOT_REMOVE_ENTRY;
}
wallet->sync();
printf("In DCOPDemoWidget:RemoveEntry Exit\n");
return KWALLET_RESULT_OK;
}

View File

@@ -3,6 +3,22 @@
#define DCOPIFACEDEMO_H
#include <qvbox.h>
enum KWalletResult
{ KWALLET_RESULT_OK,
KWALLET_RESULT_CANNOT_OPEN_WALLET,
KWALLET_RESULT_CANNOT_OPEN_FOLDER,
KWALLET_RESULT_CANNOT_WRITE_ENTRY,
KWALLET_RESULT_MALFORMED_XML,
KWALLET_RESULT_CANNOT_CREATE_FOLDER,
KWALLET_RESULT_CANNOT_CREATE_WALLET,
KWALLET_RESULT_CANNOT_REMOVE_ENTRY,
KWALLET_RESULT_UNKNOWN_ERROR
};
/**
* Adding DCOP interface to an app.
@@ -43,6 +59,10 @@ public slots:
int ReadAllWalletSecrets(struct EnumSecretList **);
// int ReadWalletSecret(QString, QString, QString, QByteArray*);
// int WriteWalletSecret(QString, QString, QString, QByteArray , int);
int SetEntry(char *, char *, int , char *, char *, int);
int SetMap(char *, char *, char *, char** , int );
int RemoveEntry(char *, char *, char *);
private: