diff --git a/extensions/wallet/src/makefile.win b/extensions/wallet/src/makefile.win index 0fa7db202e98..f60c10ae1552 100644 --- a/extensions/wallet/src/makefile.win +++ b/extensions/wallet/src/makefile.win @@ -40,10 +40,8 @@ EXPORTS= $(NULL) LLIBS=$(LLIBS) $(LIBNSPR) \ $(WALLETLIBS) \ - $(DIST)\lib\secfreenav32.lib \ $(DIST)\lib\xppref32.lib \ $(DIST)\lib\xpcom.lib \ - $(DIST)\lib\xplib.lib \ !ifndef NECKO $(DIST)\lib\netlib.lib \ !endif diff --git a/extensions/wallet/src/singsign.cpp b/extensions/wallet/src/singsign.cpp index 683ee950bc2a..db711b85448f 100644 --- a/extensions/wallet/src/singsign.cpp +++ b/extensions/wallet/src/singsign.cpp @@ -39,9 +39,9 @@ #include "nsINetSupportDialogService.h" #include "nsIServiceManager.h" #include "nsIDOMHTMLDocument.h" -#include "xp_mem.h" #include "prmem.h" #include "prprf.h" +#include "nsVoidArray.h" static NS_DEFINE_IID(kIPrefServiceIID, NS_IPREF_IID); static NS_DEFINE_IID(kPrefServiceCID, NS_PREF_CID); @@ -581,13 +581,13 @@ si_StrippedURL (char* URLName) { char *s, *t; /* check for null URLName */ - if (URLName == NULL || XP_STRLEN(URLName) == 0) { + if (URLName == NULL || PL_strlen(URLName) == 0) { return NULL; } /* remove protocol */ s = URLName; - s = (char*) XP_STRCHR(s+1, '/'); + s = (char*) PL_strchr(s+1, '/'); if (s && *s == '/' && *(s+1) == '/') { s += 2; } @@ -599,25 +599,25 @@ si_StrippedURL (char* URLName) { /* remove everything after hostname */ s = result; - s = (char*) XP_STRCHR(s, '/'); + s = (char*) PL_strchr(s, '/'); if (s) { *s = '\0'; } /* remove everything after and including first question mark */ s = result; - s = (char*) XP_STRCHR(s, '?'); + s = (char*) PL_strchr(s, '?'); if (s) { *s = '\0'; } /* remove socket number from result */ s = result; - while ((s = (char*) XP_STRCHR(s+1, ':'))) { + while ((s = (char*) PL_strchr(s+1, ':'))) { /* s is at next colon */ if (*(s+1) != '/') { /* and it's not :// so it must be start of socket number */ - if ((t = (char*) XP_STRCHR(s+1, '/'))) { + if ((t = (char*) PL_strchr(s+1, '/'))) { /* t is at slash terminating the socket number */ do { /* copy remainder of t to s */ @@ -629,7 +629,7 @@ si_StrippedURL (char* URLName) { } /* all done */ - if (XP_STRLEN(result)) { + if (PL_strlen(result)) { return result; } else { return PL_strdup(empty); @@ -639,8 +639,8 @@ si_StrippedURL (char* URLName) { /* remove terminating CRs or LFs */ PRIVATE void si_StripLF(char* buffer) { - while ((buffer[XP_STRLEN(buffer)-1] == '\n') || (buffer[XP_STRLEN(buffer)-1] == '\r')) { - buffer[XP_STRLEN(buffer)-1] = '\0'; + while ((buffer[PL_strlen(buffer)-1] == '\n') || (buffer[PL_strlen(buffer)-1] == '\r')) { + buffer[PL_strlen(buffer)-1] = '\0'; } } @@ -650,7 +650,7 @@ si_Randomize(char * password) { PRIntervalTime random; int i; const char * hexDigits = "0123456789AbCdEf"; - if (XP_STRCMP(password, "********") == 0) { + if (PL_strcmp(password, "********") == 0) { random = PR_IntervalNow(); for (i=0; i<8; i++) { password[i] = hexDigits[random%16]; @@ -671,13 +671,13 @@ typedef struct _SignonDataStruct { } si_SignonDataStruct; typedef struct _SignonUserStruct { - XP_List * signonData_list; + nsVoidArray * signonData_list; } si_SignonUserStruct; typedef struct _SignonURLStruct { char * URLName; si_SignonUserStruct* chosen_user; /* this is a state variable */ - XP_List * signonUser_list; + nsVoidArray * signonUser_list; } si_SignonURLStruct; @@ -686,9 +686,9 @@ typedef struct _RejectStruct { char * userName; } si_Reject; -PRIVATE XP_List * si_signon_list=0; -PRIVATE XP_List * si_reject_list=0; - +PRIVATE nsVoidArray * si_signon_list=0; +PRIVATE nsVoidArray * si_reject_list=0; +#define LIST_COUNT(list) (list ? list->Count() : 0) PRIVATE PRBool si_signon_list_changed = PR_FALSE; /* @@ -698,21 +698,22 @@ PRIVATE PRBool si_signon_list_changed = PR_FALSE; */ PRIVATE si_SignonURLStruct * si_GetURL(char * URLName) { - XP_List * list_ptr = si_signon_list; si_SignonURLStruct * url; char *strippedURLName = 0; if (!URLName) { /* no URLName specified, return first URL (returns NULL if not URLs) */ - return (si_SignonURLStruct *) XP_ListNextObject(list_ptr); + return (si_SignonURLStruct *) (si_signon_list->ElementAt(0)); } strippedURLName = si_StrippedURL(URLName); - while((url = (si_SignonURLStruct *) XP_ListNextObject(list_ptr))!=0) { - if(url->URLName && !XP_STRCMP(strippedURLName, url->URLName)) { - XP_FREE(strippedURLName); + PRInt32 urlCount = LIST_COUNT(si_signon_list); + for (PRInt32 i=0; iElementAt(i)); + if(url->URLName && !PL_strcmp(strippedURLName, url->URLName)) { + PR_Free(strippedURLName); return url; } } - XP_FREE(strippedURLName); + PR_Free(strippedURLName); return (NULL); } @@ -722,8 +723,6 @@ si_RemoveUser(char *URLName, char *userName, PRBool save) { si_SignonURLStruct * url; si_SignonUserStruct * user; si_SignonDataStruct * data; - XP_List * user_ptr; - XP_List * data_ptr; /* do nothing if signon preference is not enabled */ if (!si_GetSignonRememberingPref()) { @@ -741,19 +740,21 @@ si_RemoveUser(char *URLName, char *userName, PRBool save) { } /* free the data in each node of the specified user node for this URL */ - user_ptr = url->signonUser_list; if (userName == NULL) { /* no user specified so remove the first one */ - user = (si_SignonUserStruct *) XP_ListNextObject(user_ptr); + user = (si_SignonUserStruct *) (url->signonUser_list->ElementAt(0)); } else { /* find the specified user */ - while((user = (si_SignonUserStruct *) XP_ListNextObject(user_ptr))!=0) { - data_ptr = user->signonData_list; - while((data = (si_SignonDataStruct *) XP_ListNextObject(data_ptr))!=0) { - if (XP_STRCMP(data->value, userName)==0) { + PRInt32 userCount = LIST_COUNT(url->signonUser_list); + for (PRInt32 i=0; isignonUser_list->ElementAt(i)); + PRInt32 dataCount = LIST_COUNT(user->signonData_list); + for (PRInt32 i=0; isignonData_list->ElementAt(i)); + if (PL_strcmp(data->value, userName)==0) { goto foundUser; } } @@ -764,22 +765,23 @@ si_RemoveUser(char *URLName, char *userName, PRBool save) { } /* free the items in the data list */ - data_ptr = user->signonData_list; - while((data = (si_SignonDataStruct *) XP_ListNextObject(data_ptr))!=0) { - XP_FREE(data->name); - XP_FREE(data->value); + PRInt32 dataCount = LIST_COUNT(user->signonData_list); + for (PRInt32 i=0; isignonData_list->ElementAt(i)); + PR_Free(data->name); + PR_Free(data->value); } /* free the data list */ - XP_ListDestroy(user->signonData_list); + delete user->signonData_list; /* free the user node */ - XP_ListRemoveObject(url->signonUser_list, user); + url->signonUser_list->RemoveElement(user); /* remove this URL if it contains no more users */ - if (XP_ListCount(url->signonUser_list) == 0) { - XP_FREE(url->URLName); - XP_ListRemoveObject(si_signon_list, url); + if (LIST_COUNT(url->signonUser_list) == 0) { + PR_Free(url->URLName); + si_signon_list->RemoveElement(url); } /* write out the change to disk */ @@ -798,8 +800,6 @@ si_CheckForUser(char *URLName, char *userName) { si_SignonURLStruct * url; si_SignonUserStruct * user; si_SignonDataStruct * data; - XP_List * user_ptr; - XP_List * data_ptr; /* do nothing if signon preference is not enabled */ if (!si_GetSignonRememberingPref()) { @@ -817,11 +817,13 @@ si_CheckForUser(char *URLName, char *userName) { } /* find the specified user */ - user_ptr = url->signonUser_list; - while((user = (si_SignonUserStruct *) XP_ListNextObject(user_ptr))!=0) { - data_ptr = user->signonData_list; - while((data = (si_SignonDataStruct *) XP_ListNextObject(data_ptr))!=0) { - if (XP_STRCMP(data->value, userName)==0) { + PRInt32 userCount = LIST_COUNT(url->signonUser_list); + for (PRInt32 i=0; isignonUser_list->ElementAt(i)); + PRInt32 dataCount = LIST_COUNT(user->signonData_list); + for (PRInt32 i=0; isignonData_list->ElementAt(i)); + if (PL_strcmp(data->value, userName)==0) { si_unlock_signon_list(); return PR_TRUE; } @@ -843,8 +845,6 @@ si_GetUser(char* URLName, PRBool pickFirstUser, char* userText) { si_SignonURLStruct* url; si_SignonUserStruct* user; si_SignonDataStruct* data; - XP_List * data_ptr=0; - XP_List * user_ptr=0; /* get to node for this URL */ url = si_GetURL(URLName); @@ -852,15 +852,14 @@ si_GetUser(char* URLName, PRBool pickFirstUser, char* userText) { /* node for this URL was found */ PRInt32 user_count; - user_ptr = url->signonUser_list; - if ((user_count = XP_ListCount(user_ptr)) == 1) { + if ((user_count = LIST_COUNT(url->signonUser_list)) == 1) { /* only one set of data exists for this URL so select it */ - user = (si_SignonUserStruct *) XP_ListNextObject(user_ptr); + user = (si_SignonUserStruct *) (url->signonUser_list->ElementAt(0)); url->chosen_user = user; } else if (pickFirstUser) { - user = (si_SignonUserStruct *) XP_ListNextObject(user_ptr); + user = (si_SignonUserStruct *) (url->signonUser_list->ElementAt(0)); url->chosen_user = user; } else { @@ -869,8 +868,8 @@ si_GetUser(char* URLName, PRBool pickFirstUser, char* userText) { char ** list2; si_SignonUserStruct** users; si_SignonUserStruct** users2; - list = (char**)XP_ALLOC(user_count*sizeof(char*)); - users = (struct _SignonUserStruct **) XP_ALLOC(user_count*sizeof(si_SignonUserStruct*)); + list = (char**)PR_Malloc(user_count*sizeof(char*)); + users = (struct _SignonUserStruct **) PR_Malloc(user_count*sizeof(si_SignonUserStruct*)); list2 = list; users2 = users; @@ -880,10 +879,11 @@ si_GetUser(char* URLName, PRBool pickFirstUser, char* userText) { * ordering of users in the list we present for selection will disagree */ user_count = 0; - while((user = (si_SignonUserStruct *) XP_ListNextObject(user_ptr))!=0) { - data_ptr = user->signonData_list; + PRInt32 userCount = LIST_COUNT(url->signonUser_list); + for (PRInt32 i=0; isignonUser_list->ElementAt(i)); /* consider first data node to be the identifying item */ - data = (si_SignonDataStruct *) XP_ListNextObject(data_ptr); + data = (si_SignonDataStruct *) (user->signonData_list->ElementAt(0)); if (PL_strcmp(data->name, userText)) { /* name of current data item does not match name in data node */ continue; @@ -895,12 +895,11 @@ si_GetUser(char* URLName, PRBool pickFirstUser, char* userText) { url = si_GetURL(URLName); if (url == NULL) { /* This will happen if user fails to unlock database in SI_LoadSignonData above */ - XP_FREE(list); - XP_FREE(users); + PR_Free(list); + PR_Free(users); return NULL; } } - user_ptr = url->signonUser_list; /* step through set of user nodes for this URL and create list of * first data node of each (presumably that is the user name). @@ -908,10 +907,11 @@ si_GetUser(char* URLName, PRBool pickFirstUser, char* userText) { * most-recently-used so the first one in the list is the most * likely one to be chosen. */ - while((user = (si_SignonUserStruct *) XP_ListNextObject(user_ptr))!=0) { - data_ptr = user->signonData_list; + PRInt32 userCount2 = LIST_COUNT(url->signonUser_list); + for (PRInt32 i2=0; i2signonUser_list->ElementAt(i2)); /* consider first data node to be the identifying item */ - data = (si_SignonDataStruct *) XP_ListNextObject(data_ptr); + data = (si_SignonDataStruct *) (user->signonData_list->ElementAt(0)); if (PL_strcmp(data->name, userText)) { /* name of current data item does not match name in data node */ continue; @@ -925,8 +925,7 @@ si_GetUser(char* URLName, PRBool pickFirstUser, char* userText) { if (user_count == 0) { /* not first data node for any saved user, so simply pick first user */ if (url->chosen_user) { - user_ptr = url->signonUser_list; - user = (si_SignonUserStruct *) XP_ListNextObject(user_ptr); + user = (si_SignonUserStruct *) (url->signonUser_list->ElementAt(0)); } else { /* no user selection had been made for first data node */ user = NULL; @@ -941,15 +940,15 @@ si_GetUser(char* URLName, PRBool pickFirstUser, char* userText) { } user = users[user_count]; /* this is the selected item */ /* item selected is now most-recently used, put at head of list */ - XP_ListRemoveObject(url->signonUser_list, user); - XP_ListAddObject(url->signonUser_list, user); + url->signonUser_list->RemoveElement(user); + url->signonUser_list->InsertElementAt(user, 0); } else { user = NULL; } PR_FREEIF(selectUser); url->chosen_user = user; - XP_FREE(list); - XP_FREE(users); + PR_Free(list); + PR_Free(users); /* if we don't remove the URL from the cache at this point, the * cached copy will be brought containing the last-used username @@ -980,9 +979,6 @@ si_GetURLAndUserForChangeForm(char* password) si_SignonURLStruct* url; si_SignonUserStruct* user; si_SignonDataStruct * data; - XP_List * url_ptr = 0; - XP_List * user_ptr = 0; - XP_List * data_ptr = 0; PRInt32 user_count; char ** list; @@ -994,36 +990,40 @@ si_GetURLAndUserForChangeForm(char* password) /* get count of total number of user nodes at all url nodes */ user_count = 0; - url_ptr = si_signon_list; - while((url = (si_SignonURLStruct *) XP_ListNextObject(url_ptr))!=0) { - user_ptr = url->signonUser_list; - while((user = (si_SignonUserStruct *) XP_ListNextObject(user_ptr))!=0) { + PRInt32 urlCount = LIST_COUNT(si_signon_list); + for (PRInt32 i=0; iElementAt(i)); + PRInt32 userCount = LIST_COUNT(url->signonUser_list); + for (PRInt32 i=0; isignonUser_list->ElementAt(i)); user_count++; } } /* allocate lists for maximumum possible url and user names */ - list = (char**)XP_ALLOC(user_count*sizeof(char*)); - users = (struct _SignonUserStruct **) XP_ALLOC(user_count*sizeof(si_SignonUserStruct*)); - urls = (struct _SignonURLStruct **)XP_ALLOC(user_count*sizeof(si_SignonUserStruct*)); + list = (char**)PR_Malloc(user_count*sizeof(char*)); + users = (struct _SignonUserStruct **) PR_Malloc(user_count*sizeof(si_SignonUserStruct*)); + urls = (struct _SignonURLStruct **)PR_Malloc(user_count*sizeof(si_SignonUserStruct*)); list2 = list; users2 = users; urls2 = urls; /* step through set of URLs and users and create list of each */ user_count = 0; - url_ptr = si_signon_list; - while((url = (si_SignonURLStruct *) XP_ListNextObject(url_ptr))!=0) { - user_ptr = url->signonUser_list; - while((user = (si_SignonUserStruct *) XP_ListNextObject(user_ptr))!=0) { - data_ptr = user->signonData_list; + PRInt32 urlCount2 = LIST_COUNT(si_signon_list); + for (PRInt32 i2=0; i2ElementAt(i2)); + PRInt32 userCount = LIST_COUNT(url->signonUser_list); + for (PRInt32 i=0; isignonUser_list->ElementAt(i)); /* find saved password and see if it matches password user just entered */ - while((data = (si_SignonDataStruct *) XP_ListNextObject(data_ptr))!=0) { + PRInt32 dataCount = LIST_COUNT(user->signonData_list); + for (PRInt32 i=0; isignonData_list->ElementAt(i)); if (data->isPassword && !PL_strcmp(data->value, password)) { /* passwords match so add entry to list */ /* consider first data node to be the identifying item */ - data_ptr = user->signonData_list; - data = (si_SignonDataStruct *) XP_ListNextObject(data_ptr); + data = (si_SignonDataStruct *) (user->signonData_list->ElementAt(0)); *list2 = 0; StrAllocCopy(*list2, url->URLName); StrAllocCat(*list2,": "); @@ -1048,8 +1048,8 @@ si_GetURLAndUserForChangeForm(char* password) * to the head of the user list so that it can be favored for * re-use the next time this form is encountered */ - XP_ListRemoveObject(url->signonUser_list, user); - XP_ListAddObject(url->signonUser_list, user); + url->signonUser_list->RemoveElement(user); + url->signonUser_list->InsertElementAt(user, 0); si_signon_list_changed = PR_TRUE; si_SaveSignonDataLocked(PR_TRUE); } else { @@ -1059,11 +1059,11 @@ si_GetURLAndUserForChangeForm(char* password) /* free allocated strings */ while (--list2 > list) { - XP_FREE(*list2); + PR_Free(*list2); } - XP_FREE(list); - XP_FREE(users); - XP_FREE(urls); + PR_Free(list); + PR_Free(users); + PR_Free(urls); return user; } @@ -1098,7 +1098,7 @@ si_FreeReject(si_Reject * reject) { if(!reject) { return; } - XP_ListRemoveObject(si_reject_list, reject); + si_reject_list->RemoveElement(reject); PR_FREEIF(reject->URLName); PR_FREEIF(reject->userName); PR_Free(reject); @@ -1106,13 +1106,13 @@ si_FreeReject(si_Reject * reject) { PRIVATE PRBool si_CheckForReject(char * URLName, char * userName) { - XP_List * list_ptr; si_Reject * reject; si_lock_signon_list(); if (si_reject_list) { - list_ptr = si_reject_list; - while((reject = (si_Reject *) XP_ListNextObject(list_ptr))!=0) { + PRInt32 rejectCount = LIST_COUNT(si_reject_list); + for (PRInt32 i=0; iElementAt(i)); if(!PL_strcmp(userName, reject->userName) && !PL_strcmp(URLName, reject->URLName)) { si_unlock_signon_list(); return PR_TRUE; @@ -1140,11 +1140,9 @@ si_PutReject(char * URLName, char * userName, PRBool save) { * determine this by testing "save" since only SI_LoadSignonData * passes in a value of PR_FALSE for "save". */ - XP_List * list_ptr; if (save) { si_lock_signon_list(); } - list_ptr = si_reject_list; StrAllocCopy(URLName2, URLName); StrAllocCopy(userName2, userName); @@ -1152,7 +1150,7 @@ si_PutReject(char * URLName, char * userName, PRBool save) { reject->userName = userName2; if(!si_reject_list) { - si_reject_list = XP_ListNew(); + si_reject_list = new nsVoidArray(); if(!si_reject_list) { PR_Free(reject->URLName); PR_Free(reject->userName); @@ -1167,19 +1165,23 @@ si_PutReject(char * URLName, char * userName, PRBool save) { /* add it to the list in alphabetical order */ si_Reject * tmp_reject; PRBool rejectAdded = PR_FALSE; - while((tmp_reject = (si_Reject *) XP_ListNextObject(list_ptr))!=0) { - if (PL_strcmp (reject->URLName, tmp_reject->URLName)<0) { - XP_ListInsertObject (si_reject_list, tmp_reject, reject); - rejectAdded = PR_TRUE; - break; + PRInt32 rejectCount = LIST_COUNT(si_reject_list); + for (PRInt32 i = 0; iElementAt(i)); + if (tmp_reject) { + if (PL_strcasecmp(reject->URLName, tmp_reject->URLName)<0) { + si_reject_list->InsertElementAt(reject, i); + rejectAdded = PR_TRUE; + break; + } } } if (!rejectAdded) { - XP_ListAddObjectToEnd (si_reject_list, reject); + si_reject_list->AppendElement(reject); } #else /* add it to the end of the list */ - XP_ListAddObjectToEnd (si_reject_list, reject); + si_reject_list->AppendElement(reject); #endif if (save) { @@ -1211,10 +1213,6 @@ si_PutData(char * URLName, LO_FormSubmitData * submit, PRBool save) { si_SignonUserStruct * user; si_SignonDataStruct * data; int j; - XP_List * list_ptr; - XP_List * user_ptr; - XP_List * data_ptr; - si_SignonURLStruct * tmp_URL_ptr; PRBool mismatch; int i; @@ -1222,7 +1220,7 @@ si_PutData(char * URLName, LO_FormSubmitData * submit, PRBool save) { for (i=0; ivalue_cnt; i++) { if ((((uint8*)submit->type_array)[i] == FORM_TYPE_PASSWORD) && (!((char **)(submit->value_array))[i] || - !XP_STRLEN( ((char **)(submit->value_array)) [i])) ) { + !PL_strlen( ((char **)(submit->value_array)) [i])) ) { return; } } @@ -1242,7 +1240,7 @@ si_PutData(char * URLName, LO_FormSubmitData * submit, PRBool save) { /* make sure the signon list exists */ if(!si_signon_list) { - si_signon_list = XP_ListNew(); + si_signon_list = new nsVoidArray(); if(!si_signon_list) { if (save) { si_unlock_signon_list(); @@ -1255,7 +1253,7 @@ si_PutData(char * URLName, LO_FormSubmitData * submit, PRBool save) { if ((url = si_GetURL(URLName)) == NULL) { /* doesn't exist so allocate new node to be put into signon list */ - url = XP_NEW(si_SignonURLStruct); + url = PR_NEW(si_SignonURLStruct); if (!url) { if (save) { si_unlock_signon_list(); @@ -1266,37 +1264,41 @@ si_PutData(char * URLName, LO_FormSubmitData * submit, PRBool save) { /* fill in fields of new node */ url->URLName = si_StrippedURL(URLName); if (!url->URLName) { - XP_FREE(url); + PR_Free(url); if (save) { si_unlock_signon_list(); } return; } - url->signonUser_list = XP_ListNew(); + url->signonUser_list = new nsVoidArray(); if(!url->signonUser_list) { - XP_FREE(url->URLName); - XP_FREE(url); + PR_Free(url->URLName); + PR_Free(url); } /* put new node into signon list */ #ifdef alphabetize /* add it to the list in alphabetical order */ - list_ptr = si_signon_list; - while((tmp_URL_ptr = (si_SignonURLStruct *) XP_ListNextObject(list_ptr))!=0) { - if(PL_strcmp(url->URLName,tmp_URL_ptr->URLName)<0) { - XP_ListInsertObject(si_signon_list, tmp_URL_ptr, url); - added_to_list = PR_TRUE; - break; + si_SignonURLStruct * tmp_URL; + PRInt32 urlCount = LIST_COUNT(si_signon_list); + for (PRInt32 i = 0; iElementAt(i)); + if (tmp_URL) { + if (PL_strcasecmp(url->URLName, tmp_URL->URLName)<0) { + si_signon_list->InsertElementAt(url, i); + added_to_list = PR_TRUE; + break; + } } } if (!added_to_list) { - XP_ListAddObjectToEnd (si_signon_list, url); + si_signon_list->AppendElement(url); } #else /* add it to the end of the list */ - XP_ListAddObjectToEnd (si_signon_list, url); + si_signon_list->AppendElement(url); #endif } @@ -1307,11 +1309,15 @@ si_PutData(char * URLName, LO_FormSubmitData * submit, PRBool save) { * see if a user node with data list matching new data already exists * (password fields will not be checked for in this matching) */ - user_ptr = url->signonUser_list; - while((user = (si_SignonUserStruct *) XP_ListNextObject(user_ptr))!=0) { - data_ptr = user->signonData_list; + PRInt32 userCount = LIST_COUNT(url->signonUser_list); + for (PRInt32 i2=0; i2signonUser_list->ElementAt(i2)); j = 0; - while((data = (si_SignonDataStruct *) XP_ListNextObject(data_ptr))!=0) { + PRInt32 dataCount = LIST_COUNT(user->signonData_list); + for (PRInt32 i=0; isignonData_list->ElementAt(i)); + + mismatch = PR_FALSE; /* skip non text/password fields */ @@ -1325,18 +1331,18 @@ si_PutData(char * URLName, LO_FormSubmitData * submit, PRBool save) { if ((j < submit->value_cnt) && (data->isPassword == (((uint8*)submit->type_array)[j]==FORM_TYPE_PASSWORD)) && - (!XP_STRCMP(data->name, ((char **)submit->name_array)[j]))) { + (!PL_strcmp(data->name, ((char **)submit->name_array)[j]))) { /* success, now check for match on value field if not password */ if (!submit->value_array[j]) { /* special case a null value */ - if (!XP_STRCMP(data->value, "")) { + if (!PL_strcmp(data->value, "")) { j++; /* success */ } else { mismatch = PR_TRUE; break; /* value mismatch, try next user */ } - } else if (!XP_STRCMP(data->value, ((char **)submit->value_array)[j]) + } else if (!PL_strcmp(data->value, ((char **)submit->value_array)[j]) || data->isPassword) { j++; /* success */ } else { @@ -1360,9 +1366,10 @@ si_PutData(char * URLName, LO_FormSubmitData * submit, PRBool save) { */ /* update the saved password values */ - data_ptr = user->signonData_list; j = 0; - while((data = (si_SignonDataStruct *) XP_ListNextObject(data_ptr))!=0) { + PRInt32 dataCount = LIST_COUNT(user->signonData_list); + for (PRInt32 i=0; isignonData_list->ElementAt(i)); /* skip non text/password fields */ while ((j < submit->value_cnt) && @@ -1373,7 +1380,7 @@ si_PutData(char * URLName, LO_FormSubmitData * submit, PRBool save) { /* update saved password */ if ((j < submit->value_cnt) && data->isPassword) { - if (XP_STRCMP(data->value, ((char **)submit->value_array)[j])) { + if (PL_strcmp(data->value, ((char **)submit->value_array)[j])) { si_signon_list_changed = PR_TRUE; StrAllocCopy(data->value, ((char **)submit->value_array)[j]); si_Randomize(data->value); @@ -1387,8 +1394,8 @@ si_PutData(char * URLName, LO_FormSubmitData * submit, PRBool save) { * to the head of the user list so that it can be favored for * re-use the next time this form is encountered */ - XP_ListRemoveObject(url->signonUser_list, user); - XP_ListAddObject(url->signonUser_list, user); + url->signonUser_list->RemoveElement(user); + url->signonUser_list->InsertElementAt(user, 0); /* return */ if (save) { @@ -1401,16 +1408,16 @@ si_PutData(char * URLName, LO_FormSubmitData * submit, PRBool save) { } /* user node with current data not found so create one */ - user = XP_NEW(si_SignonUserStruct); + user = PR_NEW(si_SignonUserStruct); if (!user) { if (save) { si_unlock_signon_list(); } return; } - user->signonData_list = XP_ListNew(); + user->signonData_list = new nsVoidArray(); if(!user->signonData_list) { - XP_FREE(user); + PR_Free(user); if (save) { si_unlock_signon_list(); } @@ -1427,10 +1434,10 @@ si_PutData(char * URLName, LO_FormSubmitData * submit, PRBool save) { } /* create signon data node */ - data = XP_NEW(si_SignonDataStruct); + data = PR_NEW(si_SignonDataStruct); if (!data) { - XP_ListDestroy(user->signonData_list); - XP_FREE(user); + delete user->signonData_list; + PR_Free(user); } data->isPassword = (((uint8 *)submit->type_array)[j] == FORM_TYPE_PASSWORD); name = 0; /* so that StrAllocCopy doesn't free previous name */ @@ -1447,7 +1454,7 @@ si_PutData(char * URLName, LO_FormSubmitData * submit, PRBool save) { si_Randomize(data->value); } /* append new data node to end of data list */ - XP_ListAddObjectToEnd (user->signonData_list, data); + user->signonData_list->InsertElementAt(data, 0); } /* append new user node to front of user list for matching URL */ @@ -1459,12 +1466,12 @@ si_PutData(char * URLName, LO_FormSubmitData * submit, PRBool save) { * we will be reversing the order when reading in. */ if (save) { - XP_ListAddObject(url->signonUser_list, user); + url->signonUser_list->InsertElementAt(user, 0); si_signon_list_changed = PR_TRUE; si_SaveSignonDataLocked(PR_TRUE); si_unlock_signon_list(); } else { - XP_ListAddObjectToEnd(url->signonUser_list, user); + url->signonUser_list->AppendElement(user); } } @@ -1596,7 +1603,7 @@ SI_LoadSignonData(PRBool fullLoad) { } si_StripLF(buffer); si_PutReject(URLName, buffer, PR_FALSE); - XP_FREE (URLName); + PR_Free (URLName); } /* initialize the submit structure */ @@ -1654,7 +1661,7 @@ SI_LoadSignonData(PRBool fullLoad) { } /* store the info for this URL into memory-resident data structure */ - if (!URLName || XP_STRLEN(URLName) == 0) { + if (!URLName || PL_strlen(URLName) == 0) { badInput = PR_TRUE; } if (!badInput) { @@ -1662,10 +1669,10 @@ SI_LoadSignonData(PRBool fullLoad) { } /* free up all the allocations done for processing this URL */ - XP_FREE(URLName); + PR_Free(URLName); for (i=0; iElementAt(i)); si_WriteLine(strm, strmx, reject->URLName, FALSE); si_WriteLine(strm, strmx, reject->userName, FALSE); } @@ -1795,17 +1800,20 @@ si_SaveSignonDataLocked(PRBool fullSave) { /* write out each URL node */ if((si_signon_list)) { - list_ptr = si_signon_list; - while((url = (si_SignonURLStruct *) XP_ListNextObject(list_ptr)) != NULL) { - user_ptr = url->signonUser_list; + PRInt32 urlCount = LIST_COUNT(si_signon_list); + for (PRInt32 i=0; iElementAt(i)); /* write out each user node of the URL node */ - while((user = (si_SignonUserStruct *) XP_ListNextObject(user_ptr)) != NULL) { + PRInt32 userCount = LIST_COUNT(url->signonUser_list); + for (PRInt32 i=0; isignonUser_list->ElementAt(i)); si_WriteLine(strm, strmx, url->URLName, FALSE); - data_ptr = user->signonData_list; /* write out each data node of the user node */ - while((data = (si_SignonDataStruct *) XP_ListNextObject(data_ptr)) != NULL) { + PRInt32 dataCount = LIST_COUNT(user->signonData_list); + for (PRInt32 i=0; isignonData_list->ElementAt(i)); if (data->isPassword) { si_WriteChar(strm, '*'); si_WriteLine(strm, strmx, data->name, FALSE); @@ -1878,29 +1886,29 @@ si_OkToSave(char *URLName, char *userName) { PR_FREEIF(message); si_SetNotificationPref(PR_TRUE); if (!si_ConfirmYN(notification)) { - XP_FREE (notification); + PR_Free (notification); SI_SetBoolPref(pref_rememberSignons, PR_FALSE); return PR_FALSE; } SI_SetBoolPref(pref_rememberSignons, PR_TRUE); /* this is unnecessary */ - XP_FREE (notification); + PR_Free (notification); } strippedURLName = si_StrippedURL(URLName); if (si_CheckForReject(strippedURLName, userName)) { - XP_FREE(strippedURLName); + PR_Free(strippedURLName); return PR_FALSE; } char * message = Wallet_Localize("WantToSavePassword?"); if (!si_ConfirmYN(message)) { si_PutReject(strippedURLName, userName, PR_TRUE); - XP_FREE(strippedURLName); + PR_Free(strippedURLName); PR_FREEIF(message); return PR_FALSE; } PR_FREEIF(message); - XP_FREE(strippedURLName); + PR_Free(strippedURLName); return PR_TRUE; } @@ -1958,14 +1966,13 @@ SINGSIGN_RememberSignonData } else if (passwordCount == 3) { /* three-password form is a change-of-password request */ - XP_List * data_ptr; si_SignonDataStruct* data; si_SignonUserStruct* user; /* make sure all passwords are non-null and 2nd and 3rd are identical */ if (!submit.value_array[pswd[0]] || ! submit.value_array[pswd[1]] || !submit.value_array[pswd[2]] || - XP_STRCMP(((char **)submit.value_array)[pswd[1]], + PL_strcmp(((char **)submit.value_array)[pswd[1]], ((char **)submit.value_array)[pswd[2]])) { return; } @@ -1987,8 +1994,9 @@ SINGSIGN_RememberSignonData si_unlock_signon_list(); return; } - data_ptr = user->signonData_list; - while((data = (si_SignonDataStruct *) XP_ListNextObject(data_ptr))!=0) { + PRInt32 dataCount = LIST_COUNT(user->signonData_list); + for (PRInt32 i=0; isignonData_list->ElementAt(i)); if (data->isPassword) { break; } @@ -2004,7 +2012,7 @@ SINGSIGN_RememberSignonData * same length as "generate".) */ si_Randomize(((char **)submit.value_array)[pswd[1]]); - XP_STRCPY(((char **)submit.value_array)[pswd[2]],((char **)submit.value_array)[pswd[1]]); + PL_strcpy(((char **)submit.value_array)[pswd[2]],((char **)submit.value_array)[pswd[1]]); StrAllocCopy(data->value, ((char **)submit.value_array)[pswd[1]]); si_signon_list_changed = PR_TRUE; si_SaveSignonDataLocked(PR_TRUE); @@ -2016,7 +2024,6 @@ PUBLIC void SINGSIGN_RestoreSignonData (char* URLName, char* name, char** value) { si_SignonUserStruct* user; si_SignonDataStruct* data; - XP_List * data_ptr=0; /* do nothing if signon preference is not enabled */ if (!si_GetSignonRememberingPref()){ @@ -2038,16 +2045,15 @@ SINGSIGN_RestoreSignonData (char* URLName, char* name, char** value) { if (user) { SI_LoadSignonData(PR_TRUE); /* this destroys "user" so need to recalculate it */ user = si_GetUser(URLName, PR_TRUE, NULL); - data_ptr = user->signonData_list; /* this is first item on form */ - data = (si_SignonDataStruct *) XP_ListNextObject(data_ptr); - if(data->isPassword && name && XP_STRCMP(data->name, name)==0) { + data = (si_SignonDataStruct *) (user->signonData_list->ElementAt(0)); /* 1st item on form */ + if(data->isPassword && name && PL_strcmp(data->name, name)==0) { /* current item is first item on form and is a password */ user = (URLName, MK_SIGNON_PASSWORDS_FETCH); if (user) { /* user has confirmed it's a change-of-password form */ - data_ptr = user->signonData_list; - data = (si_SignonDataStruct *) XP_ListNextObject(data_ptr); - while((data = (si_SignonDataStruct *) XP_ListNextObject(data_ptr))!=0) { + PRInt32 dataCount = LIST_COUNT(user->signonData_list); + for (PRInt32 i=1; isignonData_list->ElementAt(i)); if (data->isPassword) { *value = data->value; si_unlock_signon_list(); @@ -2081,9 +2087,10 @@ if (!keySet) user=0; else SI_LoadSignonData(TRUE); /* this destroys user so need to recaculate it */ user = si_GetUser(URLName, PR_TRUE, name); if (user) { /* this should always be true but just in case */ - data_ptr = user->signonData_list; - while((data = (si_SignonDataStruct *) XP_ListNextObject(data_ptr))!=0) { - if(name && XP_STRCMP(data->name, name)==0) { + PRInt32 dataCount = LIST_COUNT(user->signonData_list); + for (PRInt32 i=0; isignonData_list->ElementAt(i)); + if(name && PL_strcmp(data->name, name)==0) { *value = data->value; si_unlock_signon_list(); return; @@ -2132,8 +2139,8 @@ si_RememberSignonDataFromBrowser(char* URLName, char* username, char* password) si_PutData(URLName, &submit, PR_TRUE); /* Free up the data memory just allocated */ - XP_FREE(value_array[0]); - XP_FREE(value_array[1]); + PR_Free(value_array[0]); + PR_Free(value_array[1]); } PUBLIC void @@ -2152,7 +2159,6 @@ si_RestoreOldSignonDataFromBrowser (char* URLName, PRBool pickFirstUser, char** username, char** password) { si_SignonUserStruct* user; si_SignonDataStruct* data; - XP_List * data_ptr=0; /* get the data from previous time this URL was visited */ si_lock_signon_list(); @@ -2168,11 +2174,12 @@ si_RestoreOldSignonDataFromBrowser user = si_GetUser(URLName, pickFirstUser, "username"); /* restore the data from previous time this URL was visited */ - data_ptr = user->signonData_list; - while((data = (si_SignonDataStruct *) XP_ListNextObject(data_ptr))!=0) { - if(XP_STRCMP(data->name, "username")==0) { + PRInt32 dataCount = LIST_COUNT(user->signonData_list); + for (PRInt32 i=0; isignonData_list->ElementAt(i)); + if(PL_strcmp(data->name, "username")==0) { StrAllocCopy(*username, data->value); - } else if(XP_STRCMP(data->name, "password")==0) { + } else if(PL_strcmp(data->name, "password")==0) { StrAllocCopy(*password, data->value); } } @@ -2192,7 +2199,7 @@ SINGSIGN_PromptUsernameAndPassword /* do the FE thing if signon preference is not enabled */ if (!si_GetSignonRememberingPref()){ status = si_PromptUsernameAndPassword(copyOfPrompt, username, password); - XP_FREEIF(copyOfPrompt); + PR_FREEIF(copyOfPrompt); return status; } @@ -2208,7 +2215,7 @@ SINGSIGN_PromptUsernameAndPassword } /* cleanup and return */ - XP_FREEIF(copyOfPrompt); + PR_FREEIF(copyOfPrompt); return status; } @@ -2226,7 +2233,7 @@ SINGSIGN_PromptPassword /* do the FE thing if signon preference is not enabled */ if (!si_GetSignonRememberingPref()){ result = si_PromptPassword(copyOfPrompt); - XP_FREEIF(copyOfPrompt); + PR_FREEIF(copyOfPrompt); return result; } @@ -2254,8 +2261,8 @@ SINGSIGN_PromptPassword * In this call to SI_Password, the real password gets saved in place * of the dummy one. */ - if (password && XP_STRLEN(password) && XP_STRCMP(password, " ")) { - XP_FREEIF(copyOfPrompt); + if (password && PL_strlen(password) && PL_strcmp(password, " ")) { + PR_FREEIF(copyOfPrompt); return password; } @@ -2282,13 +2289,13 @@ SINGSIGN_PromptPassword } /* remember these values for next time */ - if (password && XP_STRLEN(password) && si_OkToSave(urlname, username)) { + if (password && PL_strlen(password) && si_OkToSave(urlname, username)) { si_RememberSignonDataFromBrowser (urlname, username, password); } /* cleanup and return */ - XP_FREEIF(username); - XP_FREEIF(copyOfPrompt); + PR_FREEIF(username); + PR_FREEIF(copyOfPrompt); return password; } @@ -2308,12 +2315,12 @@ SINGSIGN_Prompt (char *prompt, char* defaultUsername, char *URLName) /* do the FE thing if signon preference is not enabled */ if (!si_GetSignonRememberingPref()){ result = si_Prompt(copyOfPrompt, defaultUsername); - XP_FREEIF(copyOfPrompt); + PR_FREEIF(copyOfPrompt); return result; } /* get previous username used */ - if (!defaultUsername || !XP_STRLEN(defaultUsername)) { + if (!defaultUsername || !PL_strlen(defaultUsername)) { si_RestoreOldSignonDataFromBrowser(URLName, PR_FALSE, &username, &password); } else { StrAllocCopy(username, defaultUsername); @@ -2323,8 +2330,8 @@ SINGSIGN_Prompt (char *prompt, char* defaultUsername, char *URLName) result = si_Prompt(copyOfPrompt, username); /* remember this username for next time */ - if (result && XP_STRLEN(result)) { - if (username && (XP_STRCMP(username, result) == 0)) { + if (result && PL_strlen(result)) { + if (username && (PL_strcmp(username, result) == 0)) { /* * User is re-using the same user name as from previous time * so keep the previous password as well @@ -2341,9 +2348,9 @@ SINGSIGN_Prompt (char *prompt, char* defaultUsername, char *URLName) } /* cleanup and return */ - XP_FREEIF(username); - XP_FREEIF(password); - XP_FREEIF(copyOfPrompt); + PR_FREEIF(username); + PR_FREEIF(password); + PR_FREEIF(copyOfPrompt); return result; } @@ -2409,7 +2416,7 @@ SI_FindValueInArgs(nsAutoString results, char* name) { nsAutoString value; PRInt32 start, length; start = results.Find(name); - XP_ASSERT(start >= 0); + PR_ASSERT(start >= 0); if (start < 0) { return nsAutoString("").ToNewCString(); } @@ -2424,80 +2431,57 @@ Wallet_SignonViewerReturn (nsAutoString results); PUBLIC void SINGSIGN_SignonViewerReturn (nsAutoString results) { - XP_List *url_ptr; - XP_List *user_ptr; - XP_List *data_ptr; - XP_List *reject_ptr; si_SignonURLStruct *url; - si_SignonURLStruct *URLToDelete = 0; si_SignonUserStruct* user; - si_SignonUserStruct* userToDelete = 0; si_SignonDataStruct* data; si_Reject* reject; - si_Reject* rejectToDelete = 0; - int userNumber; - int rejectNumber; + PRInt32 signonNum; + + /* get total number of signons so we can go through list backwards */ + signonNum = 0; + PRInt32 count = LIST_COUNT(si_signon_list); + for (PRInt32 i=0; iElementAt(i)); + signonNum += LIST_COUNT(url->signonUser_list); + } /* - * step through all users and delete those that are in the sequence - * Note: we can't delete user while "user_ptr" is pointing to it because - * that would destroy "user_ptr". So we do a lazy deletion - */ + * step backwards through all users and delete those that are in the sequence */ char * gone = SI_FindValueInArgs(results, "|goneS|"); - userNumber = 0; - url_ptr = si_signon_list; - while ((url = (si_SignonURLStruct *) XP_ListNextObject(url_ptr))) { - user_ptr = url->signonUser_list; - while ((user = (si_SignonUserStruct *)XP_ListNextObject(user_ptr))) { - if (SI_InSequence(gone, userNumber)) { - if (userToDelete) { - - /* get to first data item -- that's the user name */ - data_ptr = userToDelete->signonData_list; - data = (si_SignonDataStruct *) XP_ListNextObject(data_ptr); - /* do the deletion */ - si_RemoveUser(URLToDelete->URLName, data->value, PR_TRUE); - } - userToDelete = user; - URLToDelete = url; + PRInt32 urlCount = LIST_COUNT(si_signon_list); + while (urlCount>0) { + urlCount--; + url = NS_STATIC_CAST(si_SignonURLStruct*, si_signon_list->ElementAt(urlCount)); + PRInt32 userCount = LIST_COUNT(url->signonUser_list); + while (userCount>0) { + userCount--; + signonNum--; + user = NS_STATIC_CAST(si_SignonUserStruct*, url->signonUser_list->ElementAt(userCount)); + if (user && SI_InSequence(gone, signonNum)) { + /* get to first data item -- that's the user name */ + data = (si_SignonDataStruct *) (user->signonData_list->ElementAt(0)); + /* do the deletion */ + si_RemoveUser(url->URLName, data->value, PR_TRUE); + si_signon_list_changed = PR_TRUE; } - userNumber++; } } - if (userToDelete) { - /* get to first data item -- that's the user name */ - data_ptr = userToDelete->signonData_list; - data = (si_SignonDataStruct *) XP_ListNextObject(data_ptr); - - /* do the deletion */ - si_RemoveUser(URLToDelete->URLName, data->value, PR_TRUE); - si_signon_list_changed = PR_TRUE; - si_SaveSignonDataLocked(PR_TRUE); - } + si_SaveSignonDataLocked(PR_TRUE); delete[] gone; - /* step through all rejects and delete those that are in the sequence - * Note: we can't delete reject while "reject_ptr" is pointing to it because - * that would destroy "reject_ptr". So we do a lazy deletion - */ + /* step backwards through all rejects and delete those that are in the sequence */ gone = SI_FindValueInArgs(results, "|goneR|"); - rejectNumber = 0; si_lock_signon_list(); - reject_ptr = si_reject_list; - while ((reject = (si_Reject *) XP_ListNextObject(reject_ptr))) { - if (SI_InSequence(gone, rejectNumber)) { - if (rejectToDelete) { - si_FreeReject(rejectToDelete); - } - rejectToDelete = reject; + PRInt32 rejectCount = LIST_COUNT(si_reject_list); + while (rejectCount>0) { + rejectCount--; + reject = NS_STATIC_CAST(si_Reject*, si_reject_list->ElementAt(rejectCount)); + if (reject && SI_InSequence(gone, rejectCount)) { + si_FreeReject(reject); + si_signon_list_changed = PR_TRUE; } - rejectNumber++; - } - if (rejectToDelete) { - si_FreeReject(rejectToDelete); - si_signon_list_changed = PR_TRUE; - si_SaveSignonDataLocked(PR_FALSE); } + si_SaveSignonDataLocked(PR_FALSE); si_unlock_signon_list(); delete[] gone; @@ -2511,11 +2495,8 @@ SINGSIGN_SignonViewerReturn (nsAutoString results) { PUBLIC void SINGSIGN_GetSignonListForViewer(nsString& aSignonList) { - char *buffer = (char*)XP_ALLOC(BUFLEN2); + char *buffer = (char*)PR_Malloc(BUFLEN2); int g = 0, signonNum; - XP_List *url_ptr; - XP_List *user_ptr; - XP_List *data_ptr; si_SignonURLStruct *url; si_SignonUserStruct * user; si_SignonDataStruct* data; @@ -2524,14 +2505,16 @@ SINGSIGN_GetSignonListForViewer(nsString& aSignonList) si_RegisterSignonPrefCallbacks(); buffer[0] = '\0'; - url_ptr = si_signon_list; signonNum = 0; - while ( (url=(si_SignonURLStruct *) XP_ListNextObject(url_ptr)) ) { - user_ptr = url->signonUser_list; - while ( (user=(si_SignonUserStruct *) XP_ListNextObject(user_ptr)) ) { + PRInt32 urlCount = LIST_COUNT(si_signon_list); + for (PRInt32 i=0; iElementAt(i)); + PRInt32 userCount = LIST_COUNT(url->signonUser_list); + for (PRInt32 i=0; isignonUser_list->ElementAt(i)); + /* first data item for user is the username */ - data_ptr = user->signonData_list; - data = (si_SignonDataStruct *) XP_ListNextObject(data_ptr); + data = (si_SignonDataStruct *) (user->signonData_list->ElementAt(0)); g += PR_snprintf(buffer+g, BUFLEN2-g, "%c \n", BREAK, @@ -2549,18 +2532,18 @@ SINGSIGN_GetSignonListForViewer(nsString& aSignonList) PUBLIC void SINGSIGN_GetRejectListForViewer(nsString& aRejectList) { - char *buffer = (char*)XP_ALLOC(BUFLEN2); + char *buffer = (char*)PR_Malloc(BUFLEN2); int g = 0, rejectNum; - XP_List *reject_ptr; si_Reject *reject; /* force loading of the signons file */ si_RegisterSignonPrefCallbacks(); buffer[0] = '\0'; - reject_ptr = si_reject_list; rejectNum = 0; - while ( (reject=(si_Reject *) XP_ListNextObject(reject_ptr)) ) { + PRInt32 rejectCount = LIST_COUNT(si_reject_list); + for (PRInt32 i=0; iElementAt(i)); g += PR_snprintf(buffer+g, BUFLEN2-g, "%c \n", BREAK, @@ -2686,7 +2669,7 @@ si_LoadSignonDataFromKeychain() { buffer[actualSize] = 0; /* parse for '=' which separates the name and value */ - for (i = 0; i < XP_STRLEN(buffer); i++) { + for (i = 0; i < PL_strlen(buffer); i++) { if (buffer[i] == '=') { value = &buffer[i+1]; buffer[i] = 0; @@ -2713,7 +2696,7 @@ si_LoadSignonDataFromKeychain() { buffer[actualSize] = 0; if (!reject) { /* parse for '=' which separates the name and value */ - for (i = 0; i < XP_STRLEN(buffer); i++) { + for (i = 0; i < PL_strlen(buffer); i++) { if (buffer[i] == '=') { value = &buffer[i+1]; buffer[i] = 0; @@ -2733,7 +2716,7 @@ si_LoadSignonDataFromKeychain() { } submit.value_cnt++; /* store the info for this URL into memory-resident data structure */ - if (!URLName || XP_STRLEN(URLName) == 0) { + if (!URLName || PL_strlen(URLName) == 0) { badInput = PR_TRUE; } if (!badInput) { @@ -2742,15 +2725,15 @@ si_LoadSignonDataFromKeychain() { /* free up all the allocations done for processing this URL */ for (i = 0; i < submit.value_cnt; i++) { - XP_FREE(name_array[i]); - XP_FREE(value_array[i]); + PR_Free(name_array[i]); + PR_Free(value_array[i]); } } else { /* reject */ si_PutReject(URLName, buffer, PR_FALSE); } reject = PR_FALSE; /* reset reject flag */ - XP_FREE(URLName); + PR_Free(URLName); KCReleaseItemRef( &itemRef ); status = KCFindNextItem( searchRef, &itemRef); } @@ -2791,9 +2774,6 @@ PRIVATE int si_SaveSignonDataInKeychain() { char* account = nil; char* password = nil; - XP_List * list_ptr; - XP_List * user_ptr; - XP_List * data_ptr; si_SignonURLStruct * URL; si_SignonUserStruct * user; si_SignonDataStruct * data; @@ -2806,8 +2786,9 @@ si_SaveSignonDataInKeychain() { /* save off the reject list */ if (si_reject_list) { - list_ptr = si_reject_list; - while((reject = (si_Reject *) XP_ListNextObject(list_ptr))!=0) { + PRInt32 rejectCount = LIST_COUNT(si_reject_list); + for (PRInt32 i=0; iElementAt(i)); status = kcaddinternetpassword (reject->URLName, nil, reject->userName, @@ -2844,34 +2825,37 @@ si_SaveSignonDataInKeychain() { /* save off the passwords */ if((si_signon_list)) { - list_ptr = si_signon_list; - while((URL = (si_SignonURLStruct *) XP_ListNextObject(list_ptr)) != NULL) { - user_ptr = URL->signonUser_list; + PRInt32 urlCount = LIST_COUNT(si_signon_list); + for (PRInt32 i=0; iElementAt(i)); /* add each user node of the URL node */ - while((user = (si_SignonUserStruct *) XP_ListNextObject(user_ptr)) != NULL) { - data_ptr = user->signonData_list; + PRInt32 userCount = LIST_COUNT(URL->signonUser_list); + for (PRInt32 i=0; isignonUser_list->ElementAt(i)); /* write out each data node of the user node */ - while((data=(si_SignonDataStruct *) XP_ListNextObject(data_ptr)) != NULL) { + PRInt32 count = LIST_COUNT(user->signonData_list); + for (PRInt32 i=0; isignonData_list->ElementAt(i)); char* attribute = nil; if (data->isPassword) { - password = XP_ALLOC(XP_STRLEN(data->value) + XP_STRLEN(data->name) + 2); + password = PR_Malloc(PL_strlen(data->value) + PL_strlen(data->name) + 2); if (!password) { return (-1); } attribute = password; } else { - account = XP_ALLOC( XP_STRLEN(data->value) + XP_STRLEN(data->name) + 2); + account = PR_Malloc( PL_strlen(data->value) + PL_strlen(data->name) + 2); if (!account) { - XP_FREE(password); + PR_Free(password); return (-1); } attribute = account; } - XP_STRCPY(attribute, data->name); - XP_STRCAT(attribute, "="); - XP_STRCAT(attribute, data->value); + PL_strcpy(attribute, data->name); + PL_strcat(attribute, "="); + PL_strcat(attribute, data->value); } /* if it's already there, we just want to change the password */ status = kcfindinternetpassword @@ -2886,7 +2870,7 @@ si_SaveSignonDataInKeychain() { &actualLength, &itemRef); if (status == noErr) { - status = KCSetData(itemRef, XP_STRLEN(password), password); + status = KCSetData(itemRef, PL_strlen(password), password); if (status != noErr) { return(status); } @@ -2901,15 +2885,15 @@ si_SaveSignonDataInKeychain() { kAnyPort, kNetscapeProtocolType, kAnyAuthType, - XP_STRLEN(password), + PL_strlen(password), password, nil); } if (account) { - XP_FREE(account); + PR_Free(account); } if (password) { - XP_FREE(password); + PR_Free(password); } account = password = nil; if (status != noErr) { diff --git a/extensions/wallet/src/wallet.cpp b/extensions/wallet/src/wallet.cpp index ed27a7d4a5cf..8148fbdf9cf7 100644 --- a/extensions/wallet/src/wallet.cpp +++ b/extensions/wallet/src/wallet.cpp @@ -28,7 +28,6 @@ #include "nsIIOService.h" #include "nsIURL.h" #include "nsIChannel.h" -//#include "nsNeckoUtil2.h" #endif // NECKO #include "nsIServiceManager.h" @@ -41,7 +40,6 @@ #include "nsIDOMHTMLOptionElement.h" #include "nsIURL.h" -#include "xp_list.h" #include "nsFileStream.h" #include "nsSpecialSystemDirectory.h" @@ -51,11 +49,11 @@ #include "nsIFileLocator.h" #include "nsIFileSpec.h" #include "nsFileLocations.h" -#include "xp_mem.h" #include "prmem.h" #include "prprf.h" #include "nsIProfile.h" #include "nsIContent.h" +#include "nsVoidArray.h" static NS_DEFINE_IID(kIDOMHTMLDocumentIID, NS_IDOMHTMLDOCUMENT_IID); static NS_DEFINE_IID(kIDOMHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID); @@ -308,19 +306,21 @@ enum PlacementType {DUP_IGNORE, DUP_OVERWRITE, DUP_BEFORE, DUP_AFTER, AT_END}; typedef struct _wallet_MapElement { nsAutoString * item1; nsAutoString * item2; - XP_List * itemList; + nsVoidArray * itemList; } wallet_MapElement; typedef struct _wallet_Sublist { nsAutoString * item; } wallet_Sublist; -PRIVATE XP_List * wallet_URLFieldToSchema_list=0; -PRIVATE XP_List * wallet_specificURLFieldToSchema_list=0; -PRIVATE XP_List * wallet_FieldToSchema_list=0; -PRIVATE XP_List * wallet_SchemaToValue_list=0; -PRIVATE XP_List * wallet_SchemaConcat_list=0; -PRIVATE XP_List * wallet_URL_list = 0; +PRIVATE nsVoidArray * wallet_URLFieldToSchema_list=0; +PRIVATE nsVoidArray * wallet_specificURLFieldToSchema_list=0; +PRIVATE nsVoidArray * wallet_FieldToSchema_list=0; +PRIVATE nsVoidArray * wallet_SchemaToValue_list=0; +PRIVATE nsVoidArray * wallet_SchemaConcat_list=0; +PRIVATE nsVoidArray * wallet_URL_list = 0; + +#define LIST_COUNT(list) (list ? list->Count() : 0) #define NO_CAPTURE 0 #define NO_PREVIEW 1 @@ -332,7 +332,6 @@ typedef struct _wallet_PrefillElement { nsAutoString * value; PRInt32 selectIndex; PRUint32 count; - XP_List * resume; } wallet_PrefillElement; /***********************************************************/ @@ -365,22 +364,21 @@ wallet_DumpAutoString(nsAutoString as){ } void -wallet_Dump(XP_List * list) { - XP_List * list_ptr; +wallet_Dump(nsVoidArray * list) { wallet_MapElement * ptr; - char item1[100]; char item2[100]; char item[100]; - list_ptr = list; - while((ptr = (wallet_MapElement *) XP_ListNextObject(list_ptr))!=0) { + PRInt32 count = LIST_COUNT(list); + for (PRInt32 i=0; iElementAt(i)); ptr->item1->ToCString(item1, 100); ptr->item2->ToCString(item2, 100); fprintf(stdout, "%s %s \n", item1, item2); - XP_List * list_ptr1; wallet_Sublist * ptr1; - list_ptr1 = ptr->itemList; - while((ptr1=(wallet_Sublist *) XP_ListNextObject(list_ptr1))!=0) { + PRInt32 count = LIST_COUNT(ptr->itemList); + for (PRInt32 i=0; iitemList->ElementAt(i)); ptr1->item->ToCString(item, 100); fprintf(stdout, " %s \n", item); } @@ -927,24 +925,21 @@ wallet_unlock(void) { * clear out the designated list */ void -wallet_Clear(XP_List ** list) { - XP_List * list_ptr; +wallet_Clear(nsVoidArray ** list) { wallet_MapElement * ptr; - - list_ptr = *list; - while((ptr = (wallet_MapElement *) XP_ListNextObject(list_ptr))!=0) { + PRInt32 count = LIST_COUNT((*list)); + for (PRInt32 i=count-1; i>=0; i--) { + ptr = NS_STATIC_CAST(wallet_MapElement*, (*list)->ElementAt(i)); delete ptr->item1; delete ptr->item2; - - XP_List * list_ptr1; wallet_Sublist * ptr1; - list_ptr1 = ptr->itemList; - while((ptr1=(wallet_Sublist *) XP_ListNextObject(list_ptr1))!=0) { + PRInt32 count = LIST_COUNT(ptr->itemList); + for (PRInt32 i=0; iitemList->ElementAt(i)); delete ptr1->item; } delete ptr->itemList; - XP_ListRemoveObject(*list, ptr); - list_ptr = *list; + (*list)->RemoveElement(ptr); delete ptr; } *list = 0; @@ -957,16 +952,15 @@ void wallet_WriteToList( nsAutoString& item1, nsAutoString& item2, - XP_List* itemList, - XP_List*& list, + nsVoidArray* itemList, + nsVoidArray*& list, PlacementType placement = DUP_BEFORE) { - XP_List * list_ptr; wallet_MapElement * ptr; PRBool added_to_list = PR_FALSE; wallet_MapElement * mapElement; - mapElement = XP_NEW(wallet_MapElement); + mapElement = PR_NEW(wallet_MapElement); mapElement->item1 = &item1; mapElement->item2 = &item2; @@ -974,7 +968,7 @@ wallet_WriteToList( /* make sure the list exists */ if(!list) { - list = XP_ListNew(); + list = new nsVoidArray(); if(!list) { return; } @@ -985,13 +979,14 @@ wallet_WriteToList( * If identical value of item1 exists, use "placement" parameter to * determine what to do */ - list_ptr = list; item1.ToLowerCase(); if (AT_END==placement) { - XP_ListAddObjectToEnd (list, mapElement); + list->AppendElement(mapElement); return; } - while((ptr = (wallet_MapElement *) XP_ListNextObject(list_ptr))!=0) { + PRInt32 count = LIST_COUNT(list); + for (PRInt32 i=0; iElementAt(i)); if((ptr->item1->Compare(item1))==0) { if (DUP_OVERWRITE==placement) { delete ptr->item1; @@ -1000,20 +995,20 @@ wallet_WriteToList( ptr->item1 = &item1; ptr->item2 = &item2; } else if (DUP_BEFORE==placement) { - XP_ListInsertObject(list, ptr, mapElement); + list->InsertElementAt(mapElement, i); } if (DUP_AFTER!=placement) { added_to_list = PR_TRUE; break; } } else if((ptr->item1->Compare(item1))>=0) { - XP_ListInsertObject(list, ptr, mapElement); + list->InsertElementAt(mapElement, i); added_to_list = PR_TRUE; break; } } if (!added_to_list) { - XP_ListAddObjectToEnd (list, mapElement); + list->AppendElement(mapElement); } } @@ -1024,43 +1019,43 @@ PRBool wallet_ReadFromList( nsAutoString item1, nsAutoString& item2, - XP_List*& itemList, - XP_List*& list_ptr) + nsVoidArray*& itemList, + nsVoidArray*& list, + PRInt32& index) { - wallet_MapElement * ptr; - - wallet_MapElement * mapElement; - mapElement = XP_NEW(wallet_MapElement); - - /* make sure the list exists */ - if(!list_ptr) { + if (!list || (index == -1)) { return PR_FALSE; } /* find item1 in the list */ + wallet_MapElement * ptr; item1.ToLowerCase(); - while((ptr = (wallet_MapElement *) XP_ListNextObject(list_ptr))!=0) { + PRInt32 count = LIST_COUNT(list); + for (PRInt32 i=index; iElementAt(i)); if((ptr->item1->Compare(item1))==0) { item2 = nsAutoString(*ptr->item2); itemList = ptr->itemList; + index = i+1; + if (index == count) { + index = -1; + } return PR_TRUE; } } + index = 0; return PR_FALSE; } -/* - * given a sublist element, advance to the next sublist element and get its value - */ -PRInt32 -wallet_ReadFromSublist(nsAutoString& value, XP_List*& resume) +PRBool +wallet_ReadFromList( + nsAutoString item1, + nsAutoString& item2, + nsVoidArray*& itemList, + nsVoidArray*& list) { - wallet_Sublist * ptr; - if((ptr=(wallet_Sublist *) XP_ListNextObject(resume))!=0) { - value = *ptr->item; - return 0; - } - return -1; + PRInt32 index = 0; + return wallet_ReadFromList(item1, item2, itemList, list, index); } /************************************************************/ @@ -1332,8 +1327,7 @@ wallet_PutLine(nsOutputFileStream strm, const nsString& aLine, PRBool obscure) * write contents of designated list into designated file */ void -wallet_WriteToFile(char* filename, XP_List* list, PRBool obscure) { - XP_List * list_ptr; +wallet_WriteToFile(char* filename, nsVoidArray* list, PRBool obscure) { wallet_MapElement * ptr; if (obscure && !Wallet_KeySet()) { @@ -1359,8 +1353,9 @@ wallet_WriteToFile(char* filename, XP_List* list, PRBool obscure) { Wallet_RestartKey(); /* traverse the list */ - list_ptr = list; - while((ptr = (wallet_MapElement *) XP_ListNextObject(list_ptr))!=0) { + PRInt32 count = LIST_COUNT(list); + for (PRInt32 i=0; iElementAt(i)); if (NS_FAILED(wallet_PutLine(strm, *ptr->item1, obscure))) { break; } @@ -1369,10 +1364,10 @@ wallet_WriteToFile(char* filename, XP_List* list, PRBool obscure) { break; } } else { - XP_List * list_ptr1; wallet_Sublist * ptr1; - list_ptr1 = ptr->itemList; - while((ptr1=(wallet_Sublist *) XP_ListNextObject(list_ptr1))!=0) { + PRInt32 count = LIST_COUNT(ptr->itemList); + for (PRInt32 i=0; iitemList->ElementAt(i)); if (NS_FAILED(wallet_PutLine(strm, *ptr->item1, obscure))) { break; } @@ -1391,10 +1386,9 @@ wallet_WriteToFile(char* filename, XP_List* list, PRBool obscure) { /* * Read contents of designated file into designated list */ - void wallet_ReadFromFile - (char* filename, XP_List*& list, PRBool obscure, PRBool localFile, PlacementType placement = DUP_AFTER) { + (char* filename, nsVoidArray*& list, PRBool obscure, PRBool localFile, PlacementType placement = DUP_AFTER) { /* open input stream */ nsFileSpec dirSpec; @@ -1407,7 +1401,6 @@ wallet_ReadFromFile if (NS_FAILED(rv)) { return; } - nsInputFileStream strm(dirSpec + filename); if (!strm.is_open()) { /* file doesn't exist -- that's not an error */ @@ -1434,7 +1427,7 @@ wallet_ReadFromFile nsAutoString * aItem3; if (NS_FAILED(wallet_GetLine(strm, aItem3, obscure))) { /* end of file reached */ - XP_List* dummy = NULL; + nsVoidArray* dummy = NULL; wallet_WriteToList(*aItem1, *aItem2, dummy, list, placement); strm.close(); return; @@ -1442,19 +1435,19 @@ wallet_ReadFromFile if (aItem3->Length()==0) { /* just a pair of values, no need for a sublist */ - XP_List* dummy = NULL; + nsVoidArray* dummy = NULL; wallet_WriteToList(*aItem1, *aItem2, dummy, list, placement); } else { /* need to create a sublist and put item2 and item3 onto it */ - XP_List * itemList = XP_ListNew(); + nsVoidArray * itemList = new nsVoidArray(); wallet_Sublist * sublist; - sublist = XP_NEW(wallet_Sublist); + sublist = PR_NEW(wallet_Sublist); sublist->item = new nsAutoString (*aItem2); - XP_ListAddObjectToEnd (itemList, sublist); + itemList->AppendElement(sublist); delete aItem2; - sublist = XP_NEW(wallet_Sublist); + sublist = PR_NEW(wallet_Sublist); sublist->item = new nsAutoString (*aItem3); - XP_ListAddObjectToEnd (itemList, sublist); + itemList->AppendElement(sublist); delete aItem3; /* add any following items to sublist up to next blank line */ nsAutoString * dummy2 = new nsAutoString(""); @@ -1476,9 +1469,9 @@ wallet_ReadFromFile break; } /* add item to sublist */ - sublist = XP_NEW(wallet_Sublist); + sublist = PR_NEW(wallet_Sublist); sublist->item = new nsAutoString (*aItem3); - XP_ListAddObjectToEnd (itemList, sublist); + itemList->AppendElement(sublist); delete aItem3; } } @@ -1490,7 +1483,7 @@ wallet_ReadFromFile */ void wallet_ReadFromURLFieldToSchemaFile - (char* filename, XP_List*& list, PlacementType placement = DUP_AFTER) { + (char* filename, nsVoidArray*& list, PlacementType placement = DUP_AFTER) { /* open input stream */ nsFileSpec dirSpec; @@ -1507,7 +1500,7 @@ wallet_ReadFromURLFieldToSchemaFile /* make sure the list exists */ if(!list) { - list = XP_ListNew(); + list = new nsVoidArray(); if(!list) { strm.close(); return; @@ -1523,7 +1516,7 @@ wallet_ReadFromURLFieldToSchemaFile return; } - XP_List * itemList = XP_ListNew(); + nsVoidArray * itemList = new nsVoidArray(); nsAutoString * dummy = new nsAutoString(""); if (!dummy) { strm.close(); @@ -1552,7 +1545,7 @@ wallet_ReadFromURLFieldToSchemaFile return; } - XP_List* dummy = NULL; + nsVoidArray* dummy = NULL; wallet_WriteToList(*aItem1, *aItem2, dummy, itemList, placement); nsAutoString * aItem3; @@ -1584,8 +1577,8 @@ PRInt32 FieldToValue( nsAutoString field, nsAutoString& schema, nsAutoString& value, - XP_List*& itemList, - XP_List*& resume) + nsVoidArray*& itemList, + PRInt32& index) { /* return if no SchemaToValue list exists */ if (!wallet_SchemaToValue_list) { @@ -1593,45 +1586,40 @@ PRInt32 FieldToValue( } /* if no schema name is given, fetch schema name from field/schema tables */ - XP_List* FieldToSchema_list = wallet_FieldToSchema_list; - XP_List* URLFieldToSchema_list = wallet_specificURLFieldToSchema_list; - XP_List* SchemaToValue_list; - XP_List* dummy; - if (nsnull == resume) { - resume = wallet_SchemaToValue_list; + nsVoidArray* dummy; + if (index == -1) { + index = 0; } if ((schema.Length() > 0) || - wallet_ReadFromList(field, schema, dummy, URLFieldToSchema_list) || - wallet_ReadFromList(field, schema, dummy, FieldToSchema_list)) { + wallet_ReadFromList(field, schema, dummy, wallet_specificURLFieldToSchema_list) || + wallet_ReadFromList(field, schema, dummy, wallet_FieldToSchema_list)) { /* schema name found, now fetch value from schema/value table */ - SchemaToValue_list = resume; - if (wallet_ReadFromList(schema, value, itemList, SchemaToValue_list)) { + PRInt32 index2 = index; + if (wallet_ReadFromList(schema, value, itemList, wallet_SchemaToValue_list, index2)) { /* value found, prefill it into form */ - resume = SchemaToValue_list; + index = index2; return 0; } else { /* value not found, see if concatenation rule exists */ - XP_List * itemList2; + nsVoidArray * itemList2; - XP_List * SchemaConcat_list = wallet_SchemaConcat_list; nsAutoString dummy2; - if (wallet_ReadFromList(schema, dummy2, itemList2, SchemaConcat_list)) { + if (wallet_ReadFromList(schema, dummy2, itemList2, wallet_SchemaConcat_list)) { /* concatenation rules exist, generate value as a concatenation */ - XP_List * list_ptr1; wallet_Sublist * ptr1; - list_ptr1 = itemList2; value = nsAutoString(""); nsAutoString value2; - while((ptr1=(wallet_Sublist *) XP_ListNextObject(list_ptr1))!=0) { - SchemaToValue_list = wallet_SchemaToValue_list; - if (wallet_ReadFromList(*(ptr1->item), value2, dummy, SchemaToValue_list)) { + PRInt32 count = LIST_COUNT(itemList2); + for (PRInt32 i=0; iElementAt(i)); + if (wallet_ReadFromList(*(ptr1->item), value2, dummy, wallet_SchemaToValue_list)) { if (value.Length()>0) { value += " "; } value += value2; } } - resume = nsnull; + index = -1; itemList = nsnull; if (value.Length()>0) { return 0; @@ -1640,15 +1628,15 @@ PRInt32 FieldToValue( } } else { /* schema name not found, use field name as schema name and fetch value */ - SchemaToValue_list = resume; - if (wallet_ReadFromList(field, value, itemList, SchemaToValue_list)) { + PRInt32 index2 = index; + if (wallet_ReadFromList(field, value, itemList, wallet_SchemaToValue_list, index2)) { /* value found, prefill it into form */ schema = nsAutoString(field); - resume = SchemaToValue_list; + index = index2; return 0; } } - resume = nsnull; + index = -1; return -1; } @@ -1699,7 +1687,7 @@ wallet_GetPrefills( nsAutoString*& schemaPtr, nsAutoString*& valuePtr, PRInt32& selectIndex, - XP_List*& resume) + PRInt32& index) { nsresult result; @@ -1714,7 +1702,7 @@ wallet_GetPrefills( if (NS_SUCCEEDED(result)) { nsAutoString schema(""); nsAutoString value; - XP_List* itemList; + nsVoidArray* itemList; /* get schema name from vcard attribute if it exists */ nsIDOMElement * element; @@ -1729,10 +1717,10 @@ wallet_GetPrefills( * if schema name was specified in vcard attribute then get value from schema name, * otherwise get value from field name by using mapping tables to get schema name */ - if (FieldToValue(field, schema, value, itemList, resume) == 0) { + if (FieldToValue(field, schema, value, itemList, index) == 0) { if (value == "" && nsnull != itemList) { /* pick first of a set of synonymous values */ - wallet_ReadFromSublist(value, itemList); + value = *(((wallet_Sublist *)itemList->ElementAt(0))->item); } valuePtr = new nsAutoString(value); schemaPtr = new nsAutoString(schema); @@ -1754,8 +1742,8 @@ wallet_GetPrefills( if (NS_SUCCEEDED(result)) { nsAutoString schema(""); nsAutoString value; - XP_List* itemList; - if (FieldToValue(field, schema, value, itemList, resume) == 0) { + nsVoidArray* itemList; + if (FieldToValue(field, schema, value, itemList, index) == 0) { if (value != "") { /* no synonym list, just one value to try */ result = wallet_GetSelectIndex(selectElement, value, selectIndex); @@ -1768,7 +1756,8 @@ wallet_GetPrefills( } } else { /* synonym list exists, try each value */ - while (wallet_ReadFromSublist(value, itemList) == 0) { + for (PRInt32 i=0; iElementAt(i))->item); result = wallet_GetSelectIndex(selectElement, value, selectIndex); if (NS_SUCCEEDED(result)) { /* value matched one of the values in the drop-down list */ @@ -1822,11 +1811,11 @@ wallet_Initialize() { // wallet_Dump(wallet_SchemaConcat_list); // fprintf(stdout,"URL Field to Schema table \n"); -// XP_List * list_ptr; // char item1[100]; // wallet_MapElement * ptr; -// list_ptr = wallet_URLFieldToSchema_list; -// while((ptr = (wallet_MapElement *) XP_ListNextObject(list_ptr))!=0) { +// PRInt32 count = LIST_COUNT(wallet_URLFieldToSchema_list); +// for (PRInt32 i=0; iElementAt(i)); // ptr->item1->ToCString(item1, 100); // fprintf(stdout, item1); // fprintf(stdout,"\n"); @@ -1927,10 +1916,10 @@ wallet_InitializeCurrentURL(nsIDocument * doc) { NS_RELEASE(url); /* get field/schema mapping specific to current url */ - XP_List * list_ptr; wallet_MapElement * ptr; - list_ptr = wallet_URLFieldToSchema_list; - while((ptr = (wallet_MapElement *) XP_ListNextObject(list_ptr))!=0) { + PRInt32 count = LIST_COUNT(wallet_URLFieldToSchema_list); + for (PRInt32 i=0; iElementAt(i)); if (*(ptr->item1) == urlName) { wallet_specificURLFieldToSchema_list = ptr->itemList; break; @@ -1960,11 +1949,12 @@ wallet_GetNextInString(char*& ptr) { } void -wallet_ReleasePrefillElementList(XP_List * wallet_PrefillElement_list) { +wallet_ReleasePrefillElementList(nsVoidArray * wallet_PrefillElement_list) { if (wallet_PrefillElement_list) { wallet_PrefillElement * ptr; - XP_List * list_ptr = wallet_PrefillElement_list; - while((ptr = (wallet_PrefillElement *) XP_ListNextObject(list_ptr))!=0) { + PRInt32 count = LIST_COUNT(wallet_PrefillElement_list); + for (PRInt32 i=count-1; i>=0; i--) { + ptr = NS_STATIC_CAST(wallet_PrefillElement*, wallet_PrefillElement_list->ElementAt(i)); if (ptr->inputElement) { NS_RELEASE(ptr->inputElement); } else { @@ -1972,8 +1962,7 @@ wallet_ReleasePrefillElementList(XP_List * wallet_PrefillElement_list) { } delete ptr->schema; delete ptr->value; - XP_ListRemoveObject(wallet_PrefillElement_list, ptr); - list_ptr = wallet_PrefillElement_list; + wallet_PrefillElement_list->RemoveElement(ptr); delete ptr; } } @@ -1982,21 +1971,21 @@ wallet_ReleasePrefillElementList(XP_List * wallet_PrefillElement_list) { #define BUFLEN3 5000 #define BREAK '\001' -XP_List * wallet_list; +nsVoidArray * wallet_list; nsString wallet_url; PUBLIC void WLLT_GetPrefillListForViewer(nsString& aPrefillList) { - char *buffer = (char*)XP_ALLOC(BUFLEN3); + char *buffer = (char*)PR_Malloc(BUFLEN3); int g = 0, prefillNum = 0; - XP_List *list_ptr = wallet_list; wallet_PrefillElement * ptr; buffer[0] = '\0'; char * schema; char * value; - - while((ptr = (wallet_PrefillElement *) XP_ListNextObject(list_ptr))!=0) { + PRInt32 count = LIST_COUNT(wallet_list); + for (PRInt32 i=0; iElementAt(i)); schema = ptr->schema->ToNewCString(); value = ptr->value->ToNewCString(); g += PR_snprintf(buffer+g, BUFLEN3-g, @@ -2027,7 +2016,7 @@ wallet_FreeURL(wallet_MapElement *url) { if(!url) { return; } - XP_ListRemoveObject(wallet_URL_list, url); + wallet_URL_list->RemoveElement(url); PR_FREEIF(url->item1); PR_FREEIF(url->item2); PR_Free(url); @@ -2035,68 +2024,39 @@ wallet_FreeURL(wallet_MapElement *url) { PUBLIC void Wallet_SignonViewerReturn (nsAutoString results) { - XP_List *url_ptr; wallet_MapElement *url; - wallet_MapElement *URLToDelete; - int urlNumber; char * gone; - /* - * step through all nopreviews and delete those that are in the sequence - * Note: we can't delete nopreview while "url_ptr" is pointing to it because - * that would destroy "url_ptr". So we do a lazy deletion - */ - URLToDelete = 0; + /* step through all nopreviews and delete those that are in the sequence */ gone = SI_FindValueInArgs(results, "|goneP|"); - urlNumber = 0; - url_ptr = wallet_URL_list; - while ((url = (wallet_MapElement *) XP_ListNextObject(url_ptr))) { - if (url->item2->CharAt(NO_PREVIEW) == 'y') { - if (SI_InSequence(gone, urlNumber)) { - url->item2->SetCharAt('n', NO_PREVIEW); - if (url->item2->CharAt(NO_CAPTURE) == 'n') { - if (URLToDelete) { - wallet_FreeURL(URLToDelete); - } - URLToDelete = url; - } + PRInt32 count = LIST_COUNT(wallet_URL_list); + while (count>0) { + count--; + url = NS_STATIC_CAST(wallet_MapElement*, wallet_URL_list->ElementAt(count)); + if (url && SI_InSequence(gone, count)) { + url->item2->SetCharAt('n', NO_PREVIEW); + if (url->item2->CharAt(NO_CAPTURE) == 'n') { + wallet_FreeURL(url); + wallet_WriteToFile("URL.tbl", wallet_URL_list, PR_FALSE); } - urlNumber++; } } - if (URLToDelete) { - wallet_FreeURL(URLToDelete); - wallet_WriteToFile("URL.tbl", wallet_URL_list, PR_FALSE); - } delete[] gone; - /* - * step through all nocaptures and delete those that are in the sequence - * Note: we can't delete nocapture while "url_ptr" is pointing to it because - * that would destroy "url_ptr". So we do a lazy deletion - */ - URLToDelete = 0; + /* step through all nocaptures and delete those that are in the sequence */ gone = SI_FindValueInArgs(results, "|goneC|"); - urlNumber = 0; - url_ptr = wallet_URL_list; - while ((url = (wallet_MapElement *) XP_ListNextObject(url_ptr))) { - if (url->item2->CharAt(NO_CAPTURE) == 'y') { - if (SI_InSequence(gone, urlNumber)) { - url->item2->SetCharAt('n', NO_CAPTURE); - if (url->item2->CharAt(NO_PREVIEW) == 'n') { - if (URLToDelete) { - wallet_FreeURL(URLToDelete); - } - URLToDelete = url; - } + PRInt32 count2 = LIST_COUNT(wallet_URL_list); + while (count2>0) { + count2--; + url = NS_STATIC_CAST(wallet_MapElement*, wallet_URL_list->ElementAt(count2)); + if (url && SI_InSequence(gone, count)) { + url->item2->SetCharAt('n', NO_CAPTURE); + if (url->item2->CharAt(NO_PREVIEW) == 'n') { + wallet_FreeURL(url); + wallet_WriteToFile("URL.tbl", wallet_URL_list, PR_FALSE); } - urlNumber++; } } - if (URLToDelete) { - wallet_FreeURL(URLToDelete); - wallet_WriteToFile("URL.tbl", wallet_URL_list, PR_FALSE); - } delete[] gone; } @@ -2110,13 +2070,12 @@ wallet_OKToCapture(char* urlName) { /* see if this url is already on list of url's for which we don't want to capture */ wallet_InitializeURLList(); - XP_List* URL_list = wallet_URL_list; - XP_List* dummy; + nsVoidArray* dummy; nsAutoString * value = new nsAutoString("nn"); if (!url || !value) { return PR_FALSE; } - if (wallet_ReadFromList(*url, *value, dummy, URL_list)) { + if (wallet_ReadFromList(*url, *value, dummy, wallet_URL_list)) { if (value->CharAt(NO_CAPTURE) == 'y') { return PR_FALSE; } @@ -2166,43 +2125,80 @@ wallet_Capture(nsIDocument* doc, nsString field, nsString value, nsString vcard) /* is there a mapping from this field name to a schema name */ nsAutoString schema(vcard); - XP_List* FieldToSchema_list = wallet_FieldToSchema_list; - XP_List* URLFieldToSchema_list = wallet_specificURLFieldToSchema_list; - XP_List* SchemaToValue_list = wallet_SchemaToValue_list; - XP_List* dummy; - + nsVoidArray* dummy; if (schema.Length() || - (wallet_ReadFromList(field, schema, dummy, URLFieldToSchema_list)) || - (wallet_ReadFromList(field, schema, dummy, FieldToSchema_list))) { + (wallet_ReadFromList(field, schema, dummy, wallet_specificURLFieldToSchema_list)) || + (wallet_ReadFromList(field, schema, dummy, wallet_FieldToSchema_list))) { /* field to schema mapping already exists */ /* is this a new value for the schema */ - if (!(wallet_ReadFromList(schema, oldValue, dummy, SchemaToValue_list)) || - (oldValue != value)) { - - /* this is a new value so store it */ - nsAutoString * aValue = new nsAutoString(value); - nsAutoString * aSchema = new nsAutoString(schema); - dummy = 0; - wallet_WriteToList(*aSchema, *aValue, dummy, wallet_SchemaToValue_list); - wallet_WriteToFile("SchemaValue.tbl", wallet_SchemaToValue_list, PR_TRUE); + PRInt32 index = 0; + PRInt32 lastIndex = index; + while(wallet_ReadFromList(schema, oldValue, dummy, wallet_SchemaToValue_list, index)) { + if (oldValue == value) { + /* + * Remove entry from wallet_SchemaToValue_list and then reinsert. This will + * keep multiple values in that list for the same field ordered with + * most-recently-used first. That's useful since the first such entry + * is the default value used for pre-filling. + */ + wallet_MapElement * mapElement = + (wallet_MapElement *) (wallet_SchemaToValue_list->ElementAt(lastIndex)); + wallet_SchemaToValue_list->RemoveElementAt(lastIndex); + wallet_WriteToList( + *(mapElement->item1), + *(mapElement->item2), + mapElement->itemList, + wallet_SchemaToValue_list); + delete mapElement; + return; + } + lastIndex = index; } + + /* this is a new value so store it */ + nsAutoString * aValue = new nsAutoString(value); + nsAutoString * aSchema = new nsAutoString(schema); + dummy = 0; + wallet_WriteToList(*aSchema, *aValue, dummy, wallet_SchemaToValue_list); + wallet_WriteToFile("SchemaValue.tbl", wallet_SchemaToValue_list, PR_TRUE); + } else { /* no field to schema mapping so assume schema name is same as field name */ /* is this a new value for the schema */ - if (!(wallet_ReadFromList(field, oldValue, dummy, SchemaToValue_list)) || - (oldValue != value)) { - - /* this is a new value so store it */ - nsAutoString * aField = new nsAutoString(field); - nsAutoString * aValue = new nsAutoString(value); - dummy = 0; - wallet_WriteToList(*aField, *aValue, dummy, wallet_SchemaToValue_list); - wallet_WriteToFile("SchemaValue.tbl", wallet_SchemaToValue_list, PR_TRUE); + PRInt32 index = 0; + PRInt32 lastIndex = index; + while(wallet_ReadFromList(field, oldValue, dummy, wallet_SchemaToValue_list, index)) { + if (oldValue == value) { + /* + * Remove entry from wallet_SchemaToValue_list and then reinsert. This will + * keep multiple values in that list for the same field ordered with + * most-recently-used first. That's useful since the first such entry + * is the default value used for pre-filling. + */ + wallet_MapElement * mapElement = + (wallet_MapElement *) (wallet_SchemaToValue_list->ElementAt(lastIndex)); + wallet_SchemaToValue_list->RemoveElementAt(lastIndex); + wallet_WriteToList( + *(mapElement->item1), + *(mapElement->item2), + mapElement->itemList, + wallet_SchemaToValue_list); + delete mapElement; + return; + } + lastIndex = index; } + + /* this is a new value so store it */ + nsAutoString * aField = new nsAutoString(field); + nsAutoString * aValue = new nsAutoString(value); + dummy = 0; + wallet_WriteToList(*aField, *aValue, dummy, wallet_SchemaToValue_list); + wallet_WriteToFile("SchemaValue.tbl", wallet_SchemaToValue_list, PR_TRUE); } } @@ -2216,17 +2212,17 @@ wallet_Capture(nsIDocument* doc, nsString field, nsString value, nsString vcard) PUBLIC void WLLT_GetNopreviewListForViewer(nsString& aNopreviewList) { - char *buffer = (char*)XP_ALLOC(BUFLEN2); + char *buffer = (char*)PR_Malloc(BUFLEN2); int g = 0, nopreviewNum; - XP_List *url_ptr; wallet_MapElement *url; char* urlCString; wallet_InitializeURLList(); buffer[0] = '\0'; - url_ptr = wallet_URL_list; nopreviewNum = 0; - while ( (url=(wallet_MapElement *) XP_ListNextObject(url_ptr)) ) { + PRInt32 count = LIST_COUNT(wallet_URL_list); + for (PRInt32 i=0; iElementAt(i)); if (url->item2->CharAt(NO_PREVIEW) == 'y') { urlCString = url->item1->ToNewCString(); g += PR_snprintf(buffer+g, BUFLEN2-g, @@ -2246,17 +2242,17 @@ WLLT_GetNopreviewListForViewer(nsString& aNopreviewList) PUBLIC void WLLT_GetNocaptureListForViewer(nsString& aNocaptureList) { - char *buffer = (char*)XP_ALLOC(BUFLEN2); + char *buffer = (char*)PR_Malloc(BUFLEN2); int g = 0, nocaptureNum; - XP_List *url_ptr; wallet_MapElement *url; char* urlCString; wallet_InitializeURLList(); buffer[0] = '\0'; - url_ptr = wallet_URL_list; nocaptureNum = 0; - while ( (url=(wallet_MapElement *) XP_ListNextObject(url_ptr)) ) { + PRInt32 count = LIST_COUNT(wallet_URL_list); + for (PRInt32 i=0; iElementAt(i)); if (url->item2->CharAt(NO_CAPTURE) == 'y') { urlCString = url->item1->ToNewCString(); g += PR_snprintf(buffer+g, BUFLEN2-g, @@ -2345,19 +2341,19 @@ WLLT_PreEdit(nsAutoString& walletList) { return; } walletList = BREAK; - XP_List * list_ptr; wallet_MapElement * ptr; - list_ptr = wallet_SchemaToValue_list; + PRInt32 count = LIST_COUNT(wallet_SchemaToValue_list); + for (PRInt32 i=0; iElementAt(i)); - while((ptr = (wallet_MapElement *) XP_ListNextObject(list_ptr))!=0) { walletList += *(ptr->item1) + BREAK; if (*ptr->item2 != "") { walletList += *(ptr->item2) + BREAK; } else { - XP_List * list_ptr1; wallet_Sublist * ptr1; - list_ptr1 = ptr->itemList; - while((ptr1=(wallet_Sublist *) XP_ListNextObject(list_ptr1))!=0) { + PRInt32 count = LIST_COUNT(ptr->itemList); + for (PRInt32 i=0; iitemList->ElementAt(i)); walletList += *(ptr1->item) + BREAK; } } @@ -2385,11 +2381,10 @@ WLLT_PrefillReturn(nsAutoString results) { /* add url to url list if user doesn't want to preview this page in the future */ if (!PL_strcmp(skip, "true")) { nsAutoString * url = new nsAutoString(urlName); - XP_List* URL_list = wallet_URL_list; - XP_List* dummy; + nsVoidArray* dummy; nsAutoString * value = new nsAutoString("nn"); if (!url || !value) { - wallet_ReadFromList(*url, *value, dummy, URL_list); + wallet_ReadFromList(*url, *value, dummy, wallet_URL_list); value->SetCharAt('y', NO_PREVIEW); wallet_WriteToList(*url, *value, dummy, wallet_URL_list, DUP_OVERWRITE); wallet_WriteToFile("URL.tbl", wallet_URL_list, PR_FALSE); @@ -2397,7 +2392,7 @@ WLLT_PrefillReturn(nsAutoString results) { } /* process the list, doing the fillins */ - XP_List * list; + nsVoidArray * list; sscanf(listAsAscii, "%ld", &list); if (fillins[0] == '\0') { /* user pressed CANCEL */ wallet_ReleasePrefillElementList(list); @@ -2416,13 +2411,15 @@ WLLT_PrefillReturn(nsAutoString results) { * particular value that should be prefilled for that item. */ - XP_List * list_ptr = list; wallet_PrefillElement * ptr; char * ptr2; ptr2 = fillins; /* step through pre-fill list */ PRBool first = PR_TRUE; - while((ptr = (wallet_PrefillElement *) XP_ListNextObject(list_ptr))!=0) { + PRInt32 count = LIST_COUNT(list); + for (PRInt32 i=0; iElementAt(i)); + /* advance in fillins list each time a new schema name in pre-fill list is encountered */ if (ptr->count != 0) { /* count != 0 indicates a new schema name */ @@ -2441,7 +2438,7 @@ WLLT_PrefillReturn(nsAutoString results) { delete next; next = wallet_GetNextInString(ptr2); } - if (*next == *ptr->value) { + if (*next == *ptr->value) { /* * Remove entry from wallet_SchemaToValue_list and then reinsert. This will * keep multiple values in that list for the same field ordered with @@ -2452,14 +2449,26 @@ WLLT_PrefillReturn(nsAutoString results) { * Test for ptr->count being zero is an optimization that avoids us from doing a * reordering if the current entry already was first */ - if (ptr->resume && (ptr->count == 0)) { - wallet_MapElement * mapElement = (wallet_MapElement *) (ptr->resume->object); - XP_ListRemoveObject(wallet_SchemaToValue_list, mapElement); - wallet_WriteToList( - *(mapElement->item1), - *(mapElement->item2), - mapElement->itemList, - wallet_SchemaToValue_list); + if (ptr->count == 0) { + nsAutoString oldValue; + PRInt32 index = 0; + PRInt32 lastIndex = index; + nsVoidArray* dummy; + while(wallet_ReadFromList(*ptr->schema, oldValue, dummy, wallet_SchemaToValue_list, index)) { + if (oldValue == *ptr->value) { + wallet_MapElement * mapElement = + (wallet_MapElement *) (wallet_SchemaToValue_list->ElementAt(lastIndex)); + wallet_SchemaToValue_list->RemoveElementAt(lastIndex); + wallet_WriteToList( + *(mapElement->item1), + *(mapElement->item2), + mapElement->itemList, + wallet_SchemaToValue_list); + delete mapElement; + break; + } + lastIndex = index; + } } } @@ -2493,7 +2502,7 @@ PUBLIC nsresult WLLT_Prefill(nsIPresShell* shell, nsString url, PRBool quick) { /* create list of elements that can be prefilled */ - XP_List *wallet_PrefillElement_list=XP_ListNew(); + nsVoidArray *wallet_PrefillElement_list=new nsVoidArray(); if (!wallet_PrefillElement_list) { return NS_ERROR_FAILURE; } @@ -2532,7 +2541,7 @@ WLLT_Prefill(nsIPresShell* shell, nsString url, PRBool quick) { elements->Item(elementX, &elementNode); if (nsnull != elementNode) { wallet_PrefillElement * prefillElement; - XP_List * resume = nsnull; + PRInt32 index = 0; wallet_PrefillElement * firstElement = nsnull; PRUint32 numberOfElements = 0; for (;;) { @@ -2541,7 +2550,7 @@ WLLT_Prefill(nsIPresShell* shell, nsString url, PRBool quick) { * field set to the number of elements in group. All other * elements in group will have count field set to 0 */ - prefillElement = XP_NEW(wallet_PrefillElement); + prefillElement = PR_NEW(wallet_PrefillElement); if (wallet_GetPrefills (elementNode, prefillElement->inputElement, @@ -2549,16 +2558,15 @@ WLLT_Prefill(nsIPresShell* shell, nsString url, PRBool quick) { prefillElement->schema, prefillElement->value, prefillElement->selectIndex, - resume) != -1) { + index) != -1) { /* another value found */ - prefillElement->resume = resume; if (nsnull == firstElement) { firstElement = prefillElement; } numberOfElements++; prefillElement->count = 0; - XP_ListAddObjectToEnd(wallet_PrefillElement_list, prefillElement); - if (nsnull == resume) { + wallet_PrefillElement_list->AppendElement(prefillElement); + if (index == -1) { /* value was found from concat rules, can't resume from here */ break; } @@ -2591,7 +2599,7 @@ WLLT_Prefill(nsIPresShell* shell, nsString url, PRBool quick) { } /* return if no elements were put into the list */ - if (!wallet_PrefillElement_list || !XP_ListCount(wallet_PrefillElement_list)) { + if (LIST_COUNT(wallet_PrefillElement_list) == 0) { if (Wallet_KeySet()) { char * message = Wallet_Localize("noPrefills"); Wallet_Alert(message); @@ -2606,12 +2614,11 @@ WLLT_Prefill(nsIPresShell* shell, nsString url, PRBool quick) { PRBool noPreview = PR_FALSE; if (!quick) { wallet_InitializeURLList(); - XP_List* URL_list = wallet_URL_list; - XP_List* dummy; + nsVoidArray* dummy; nsAutoString * value = new nsAutoString("nn"); nsAutoString * urlPtr = new nsAutoString(url); if (!value || !urlPtr) { - wallet_ReadFromList(*urlPtr, *value, dummy, URL_list); + wallet_ReadFromList(*urlPtr, *value, dummy, wallet_URL_list); noPreview = (value->CharAt(NO_PREVIEW) == 'y'); delete value; delete urlPtr; @@ -2621,9 +2628,10 @@ WLLT_Prefill(nsIPresShell* shell, nsString url, PRBool quick) { /* determine if preview is necessary */ if (noPreview || quick) { /* prefill each element without any preview for user verification */ - XP_List * list_ptr = wallet_PrefillElement_list; wallet_PrefillElement * ptr; - while((ptr = (wallet_PrefillElement *) XP_ListNextObject(list_ptr))!=0) { + PRInt32 count = LIST_COUNT(wallet_PrefillElement_list); + for (PRInt32 i=0; iElementAt(i)); if (ptr->count) { if (ptr->inputElement) { ptr->inputElement->SetValue(*(ptr->value));