- Changed the GetDefaultWallet() function to address all scenarios.

This commit is contained in:
lsreevatsa 2006-03-07 17:37:30 +00:00
parent c7cb705272
commit 9c4ea3868b
2 changed files with 40 additions and 41 deletions

View File

@ -1,3 +1,8 @@
-------------------------------------------------------------------
Tue Mar 7 23:02:38 IST 2006 - lsreevatsa@novell.com
- Changed the GetDefaultWallet() function to address all scenarios.
------------------------------------------------------------------- -------------------------------------------------------------------
Tue Mar 7 19:20:50 IST 2006 - smanojna@novell.com Tue Mar 7 19:20:50 IST 2006 - smanojna@novell.com

View File

@ -27,6 +27,8 @@
#include <dcopclient.h> #include <dcopclient.h>
#include<iostream.h> #include<iostream.h>
#define MAX_LENGTH 256
using namespace KWallet; using namespace KWallet;
using namespace std; using namespace std;
@ -253,54 +255,44 @@ extern "C"
} }
void GetDefaultWallet(char dwallet[100]) char * GetDefaultWallet()
{ {
char *ptr = NULL; char *homedir = getenv("HOME");;
char homedir[100]; char *defaultwallet = NULL;
char defaultwallet[100]; defaultwallet = (char *)malloc(MAX_LENGTH);
strcpy(homedir, getenv("HOME"));
FILE *fs; FILE *fs;
char str[100]; char str[MAX_LENGTH];
int i; char *str1 = "Default Wallet=";
int i,j,k;
//cout<<"kwallets_rw.cpp : Home Directory =" << homedir; //cout<<"kwallets_rw.cpp : Home Directory =" << homedir;
strcat(homedir, "/.kde/share/config/kwalletrc"); strcat(homedir, "/.kde/share/config/kwalletrc");
//cout << "\nkwallets_rw.cpp : Home directory full path = " << homedir;
fs = fopen(homedir,"r"); fs = fopen(homedir,"r");
//fs = fopen("/root/.kde/share/config/kwalletrc","r");
if(!fs) if(!fs)
{ {
strcpy(dwallet, "kdewallet"); return "kdewallet";
return;
} }
while(!feof(fs)) while(!feof(fs))
{ {
fgets(str,80,fs); fgets(str,MAX_LENGTH,fs);
//cout<<str; for(i=0;str[i]&&str1[i];i++)
ptr = strstr(str,"Default Wallet"); {
//cout<<"got it"; if(str[i] == str1[i])
if(ptr == NULL)
continue; continue;
else else
{
ptr = strchr(str,'=');
ptr++;
i=0;
while(*ptr != '\n')
{
//printf("%c",*ptr);
defaultwallet[i] = *ptr;
ptr++;
i++;
}
defaultwallet[i] = '\0';
break; break;
} }
if(i==strlen(str1))
{
for(j=i,k=0;j<strlen(str);j++,k++)
defaultwallet[k] = str[j];
defaultwallet[k-1] = '\0';
return defaultwallet;
} }
//return NULL; else
//cout<<"Default Wallet : " << defaultwallet; continue;
strcpy(dwallet,defaultwallet); }
//return defaultwallet; return "kdewallet";
} }
int RemoveEntry(char *name, char *foldername, char *keyname) int RemoveEntry(char *name, char *foldername, char *keyname)
@ -310,16 +302,18 @@ void GetDefaultWallet(char dwallet[100])
} }
int SetEntry(char *name, char *foldername, int entryType, char *keyname, char *value, int valueLen ) int SetEntry(char *name, char *foldername, int entryType, char *keyname, char *value, int valueLen )
{ {
char dwallet[100]; char *dwallet = NULL;
GetDefaultWallet(dwallet); //function called here dwallet = (char *)malloc(MAX_LENGTH);
dwallet = GetDefaultWallet(); //function called here
DCOPDemoWidget kw; DCOPDemoWidget kw;
//printf("kwallet : In Set Entry\n"); //printf("kwallet : In Set Entry\n");
return(kw.SetEntry(dwallet,foldername,entryType,keyname,value,valueLen)); return(kw.SetEntry(dwallet,foldername,entryType,keyname,value,valueLen));
} }
int SetMapEntry(char *name, char *foldername, char *keyname, char **value, int eleCount ) int SetMapEntry(char *name, char *foldername, char *keyname, char **value, int eleCount )
{ {
char dwallet[100]; char *dwallet = NULL;
GetDefaultWallet(dwallet);//function called here dwallet = (char *)malloc(MAX_LENGTH);
dwallet = GetDefaultWallet(); //function called here
DCOPDemoWidget kw; DCOPDemoWidget kw;
//printf("kwallet: SetMapEntry\n"); //printf("kwallet: SetMapEntry\n");
return(kw.SetMap(dwallet,foldername,keyname,value,eleCount)); return(kw.SetMap(dwallet,foldername,keyname,value,eleCount));