Checked in for changes in ADLib for Add-Modify-Delete for KWallet and
Keyring
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user