From fa733a7bbe34bc0e8a75d787d575583ff27d1c79 Mon Sep 17 00:00:00 2001 From: "morse%netscape.com" Date: Wed, 16 Jan 2002 01:00:25 +0000 Subject: [PATCH] fix bustage by backing out last checkin git-svn-id: svn://10.0.0.236/trunk@112255 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/extensions/wallet/src/wallet.cpp | 899 +++++++++++------------ 1 file changed, 417 insertions(+), 482 deletions(-) diff --git a/mozilla/extensions/wallet/src/wallet.cpp b/mozilla/extensions/wallet/src/wallet.cpp index 627a91e2762..d901d5fa9c5 100644 --- a/mozilla/extensions/wallet/src/wallet.cpp +++ b/mozilla/extensions/wallet/src/wallet.cpp @@ -202,8 +202,6 @@ wallet_GetWalletNotificationPref(void) { /* The following declarations define the data base */ /***************************************************/ -#define WALLET_FREE(_ptr) { nsMemory::Free((void*)_ptr); (_ptr) = nsnull; } -#define WALLET_FREEIF(_ptr) if (_ptr) WALLET_FREE(_ptr) enum PlacementType {DUP_IGNORE, DUP_OVERWRITE, DUP_BEFORE, DUP_AFTER, AT_END, BY_LENGTH}; #define LIST_COUNT(list) ((list) ? (list)->Count() : 0) @@ -218,10 +216,9 @@ public: } ~wallet_Sublist() { - WALLET_FREEIF(item); MOZ_COUNT_DTOR(wallet_Sublist); } - const char* item; + nsString item; }; /* @@ -242,8 +239,6 @@ public: } ~wallet_MapElement() { - WALLET_FREEIF(item1); - WALLET_FREEIF(item2); if (itemList) { PRInt32 count = LIST_COUNT(itemList); wallet_Sublist * sublistPtr; @@ -255,8 +250,8 @@ public: } MOZ_COUNT_DTOR(wallet_MapElement); } - const char* item1; - const char* item2; + nsString item1; + nsString item2; nsVoidArray * itemList; }; @@ -272,20 +267,15 @@ MOZ_DECL_CTOR_COUNTER(wallet_HelpMac) class wallet_HelpMac { public: wallet_HelpMac() { - item1 = nsnull; - item2 = nsnull; - item3 = nsnull; MOZ_COUNT_CTOR(wallet_HelpMac); } ~wallet_HelpMac() { - WALLET_FREEIF(item1); - WALLET_FREEIF(item2); - WALLET_FREEIF(item3); MOZ_COUNT_DTOR(wallet_HelpMac); } - const char* item1; - const char* item2; - const char* item3; + nsAutoString item1; + nsAutoString item2; + nsAutoString item3; + nsAutoString dummy; }; wallet_HelpMac * helpMac; @@ -301,8 +291,8 @@ PRIVATE nsVoidArray * wallet_URL_list=0; PRIVATE nsVoidArray * wallet_DistinguishedSchema_list=0; #endif -#define NO_CAPTURE(x) x.First() -#define NO_PREVIEW(x) x.Last() +#define NO_CAPTURE 0 +#define NO_PREVIEW 1 MOZ_DECL_CTOR_COUNTER(wallet_PrefillElement) @@ -310,19 +300,17 @@ class wallet_PrefillElement { public: wallet_PrefillElement() : inputElement(nsnull), selectElement(nsnull) { - schema = nsnull; MOZ_COUNT_CTOR(wallet_PrefillElement); } ~wallet_PrefillElement() { - WALLET_FREEIF(schema); NS_IF_RELEASE(inputElement); NS_IF_RELEASE(selectElement); MOZ_COUNT_DTOR(wallet_PrefillElement); } nsIDOMHTMLInputElement* inputElement; nsIDOMHTMLSelectElement* selectElement; - char* schema; + nsString schema; nsString value; PRInt32 selectIndex; PRUint32 count; @@ -363,12 +351,15 @@ wallet_Dump(nsVoidArray * list) { PRInt32 count = LIST_COUNT(list); for (PRInt32 i=0; iElementAt(i)); - fprintf(stdout, "%s %s \n", (mapElementPtr->item1), (mapElementPtr->item2)); + fprintf(stdout, "%s %s \n", + NS_LossyConvertUCS2toASCII(mapElementPtr->item1).get(), + NS_LossyConvertUCS2toASCII(mapElementPtr->item2).get()); wallet_Sublist * sublistPtr; PRInt32 count2 = LIST_COUNT(mapElementPtr->itemList); for (PRInt32 i2=0; i2itemList->ElementAt(i2)); - fprintf(stdout, " %s \n", (sublistPtr->item)); + fprintf(stdout, " %s \n", + NS_LossyConvertUCS2toASCII(sublistPtr->item).get()); } } wallet_Pause(); @@ -518,7 +509,6 @@ Wallet_Localize(const char* genericString) { return ToNewUnicode(v); } - /**********************/ /* Modal dialog boxes */ /**********************/ @@ -558,7 +548,7 @@ Wallet_ConfirmYN(PRUnichar * szMessage, nsIDOMWindowInternal* window) { (nsIPrompt::BUTTON_TITLE_NO * nsIPrompt::BUTTON_POS_1), nsnull, nsnull, nsnull, nsnull, nsnull, &buttonPressed); - WALLET_FREE(confirm_string); + Recycle(confirm_string); return (buttonPressed == 0); } @@ -582,8 +572,8 @@ Wallet_3ButtonConfirm(PRUnichar * szMessage, nsIDOMWindowInternal* window) (nsIPrompt::BUTTON_TITLE_IS_STRING * nsIPrompt::BUTTON_POS_2), nsnull, nsnull, never_string, nsnull, nsnull, &buttonPressed); - WALLET_FREE(never_string); - WALLET_FREE(confirm_string); + Recycle(never_string); + Recycle(confirm_string); return buttonPressed; } @@ -601,7 +591,7 @@ wallet_Alert(PRUnichar * szMessage, nsIDOMWindowInternal* window) const nsAutoString message( szMessage ); PRUnichar * title = Wallet_Localize("CaveatTitle"); res = dialog->Alert(title, message.get()); - WALLET_FREE(title); + Recycle(title); return; // XXX should return the error } @@ -612,7 +602,7 @@ wallet_Alert(PRUnichar * szMessage, nsIPrompt* dialog) const nsAutoString message( szMessage ); PRUnichar * title = Wallet_Localize("CaveatTitle"); res = dialog->Alert(title, message.get()); - WALLET_FREE(title); + Recycle(title); return; // XXX should return the error } @@ -642,7 +632,7 @@ Wallet_CheckConfirmYN NS_ASSERTION(PR_FALSE, "Bad result from checkbox"); *checkValue = 0; /* this should never happen but it is happening!!! */ } - WALLET_FREE(confirm_string); + Recycle(confirm_string); return (buttonPressed == 0); } @@ -692,7 +682,7 @@ PRIVATE nsresult EncryptString (const char * text, char *& crypt) { } /* otherwise do our own obscuring using Base64 encoding */ - char * crypt0 = PL_Base64Encode(text, 0, NULL); + char * crypt0 = PL_Base64Encode((const char *)text, 0, NULL); if (!crypt0) { return NS_ERROR_FAILURE; } @@ -707,7 +697,7 @@ PRIVATE nsresult EncryptString (const char * text, char *& crypt) { crypt[PREFIX_len+i] = crypt0[i]; } crypt[PREFIX_len + crypt0_len] = '\0'; - WALLET_FREE(crypt0); + Recycle(crypt0); return NS_OK; } @@ -785,51 +775,78 @@ WLLT_ChangePassword(PRBool* status) { *status = NS_SUCCEEDED(rv); } -nsresult -wallet_Encrypt(const nsCString& text, nsCString& crypt) { +PUBLIC nsresult +Wallet_Encrypt (const nsString& text, nsString& crypt) { + /* convert text from unichar to UTF8 */ + nsAutoString UTF8text; + PRUnichar c; + for (PRUint32 i=0; i>6) & 0x1F)); + UTF8text += PRUnichar((0x80) | (c & 0x3F)); + } else { + UTF8text += PRUnichar((0xE0) | ((c>>12) & 0xF)); + UTF8text += PRUnichar((0x80) | ((c>>6) & 0x3F)); + UTF8text += PRUnichar((0x80) | (c & 0x3F)); + } + } + /* encrypt text to crypt */ char * cryptCString = nsnull; - nsresult rv = EncryptString(text.get(), cryptCString); + char * UTF8textCString = ToNewCString(UTF8text); + nsresult rv = EncryptString(UTF8textCString, cryptCString); + Recycle (UTF8textCString); if NS_FAILED(rv) { return rv; } - crypt = cryptCString; - WALLET_FREE(cryptCString); + crypt.AssignWithConversion(cryptCString); + Recycle (cryptCString); return NS_OK; } -nsresult -wallet_Decrypt(const nsCString& crypt, nsCString& text) { +PUBLIC nsresult +Wallet_Decrypt(const nsString& crypt, nsString& text) { /* decrypt crypt to text */ - char * textCString = nsnull; - nsresult rv = DecryptString(crypt.get(), textCString); + char * cryptCString = ToNewCString(crypt); + char * UTF8textCString = nsnull; + + nsresult rv = DecryptString(cryptCString, UTF8textCString); + Recycle(cryptCString); if NS_FAILED(rv) { return rv; } - text = textCString; - WALLET_FREE(textCString); + /* convert text from UTF8 to unichar */ + PRUnichar c1, c2, c3; + text.Truncate(0); + text.SetCapacity(2 * crypt.Length()); + + PRUint32 UTF8textCString_len = PL_strlen(UTF8textCString); + for (PRUint32 i=0; i= kAllocBlockElems) { mapElementTable = new wallet_MapElement[kAllocBlockElems]; if (!mapElementTable) { - return NS_ERROR_OUT_OF_MEMORY; + return nsnull; } if(!wallet_MapElementAllocations_list) { wallet_MapElementAllocations_list = new nsVoidArray(); @@ -891,34 +908,21 @@ wallet_AllocateMapElement(wallet_MapElement*& mapElement) { } wallet_NextAllocSlot = 0; } - mapElement = &mapElementTable[wallet_NextAllocSlot++]; - return NS_OK; + return &mapElementTable[wallet_NextAllocSlot++]; } static void wallet_DeallocateMapElements() { wallet_MapElement * mapElementPtr; PRInt32 count = LIST_COUNT(wallet_MapElementAllocations_list); - - // initialize remainder of last allocated block so we don't crash on []delete - for (PRInt32 j=wallet_NextAllocSlot; jElementAt(count-1)); - mapElementPtr[j].item1 = nsnull; - mapElementPtr[j].item2 = nsnull; - mapElementPtr[j].itemList = nsnull; - } - for (PRInt32 i=count-1; i>=0; i--) { mapElementPtr = NS_STATIC_CAST(wallet_MapElement*, (wallet_MapElementAllocations_list)->ElementAt(i)); delete [] mapElementPtr; } delete wallet_MapElementAllocations_list; - wallet_MapElementAllocations_list = nsnull; + wallet_MapElementAllocations_list = 0; wallet_NextAllocSlot = kAllocBlockElems; - } /* @@ -926,8 +930,8 @@ wallet_DeallocateMapElements() { */ static PRBool wallet_WriteToList( - const char* item1, - const char* item2, + nsString item1, // not ref. Locally modified + nsString item2, // not ref. Locally modified nsVoidArray* itemList, nsVoidArray*& list, PRBool obscure, @@ -936,12 +940,12 @@ wallet_WriteToList( wallet_MapElement * mapElementPtr; PRBool added_to_list = PR_FALSE; - wallet_MapElement * mapElement = nsnull; + wallet_MapElement * mapElement; if (list == wallet_FieldToSchema_list || list == wallet_SchemaStrings_list || list == wallet_PositionalSchema_list || list == wallet_StateSchema_list || list == wallet_SchemaConcat_list || list == wallet_DistinguishedSchema_list || list == wallet_VcardToSchema_list) { - wallet_AllocateMapElement(mapElement); + mapElement = wallet_AllocateMapElement(); } else { mapElement = new wallet_MapElement; } @@ -949,28 +953,25 @@ wallet_WriteToList( return PR_FALSE; } - nsCAutoString item1UTF8(item1); ToLowerCase(item1UTF8); - mapElement->item1 = ToNewCString(item1UTF8); - mapElement->item2 = PL_strdup(item2); - mapElement->itemList = itemList; - + ToLowerCase(item1); if (obscure) { - char * crypt = nsnull; - if (NS_FAILED(EncryptString(mapElement->item2, crypt))) { - delete mapElement; + nsAutoString crypt; + if (NS_FAILED(Wallet_Encrypt(item2, crypt))) { return PR_FALSE; } - WALLET_FREEIF(mapElement->item2); - mapElement->item2 = crypt; + item2 = crypt; } + mapElement->item1 = item1; + mapElement->item2 = item2; + mapElement->itemList = itemList; + /* make sure the list exists */ if(!list) { - list = new nsVoidArray(); - if(!list) { - delete mapElement; - return PR_FALSE; - } + list = new nsVoidArray(); + if(!list) { + return PR_FALSE; + } } /* @@ -996,22 +997,22 @@ wallet_WriteToList( wallet_Sublist * sublistPtr2; sublistPtr = NS_STATIC_CAST(wallet_Sublist*, mapElementPtr->itemList->ElementAt(0)); sublistPtr2 = NS_STATIC_CAST(wallet_Sublist*, itemList->ElementAt(0)); - if(PL_strlen(sublistPtr->item) < PL_strlen(sublistPtr2->item)) { + if(sublistPtr->item.Length() < sublistPtr2->item.Length()) { list->InsertElementAt(mapElement, i); added_to_list = PR_TRUE; break; } - } else if (PL_strlen(mapElementPtr->item2) < PL_strlen(mapElement->item2)) { + } else if (mapElementPtr->item2.Length() < item2.Length()) { list->InsertElementAt(mapElement, i); added_to_list = PR_TRUE; break; } } - } else if(!PL_strcmp(mapElementPtr->item1, mapElement->item1)) { + } else if(mapElementPtr->item1.Equals(item1)) { if (DUP_OVERWRITE==placement) { delete mapElement; - mapElementPtr->item1 = mapElement->item1; - mapElementPtr->item2 = mapElement->item2; + mapElementPtr->item1 = item1; + mapElementPtr->item2 = item2; mapElementPtr->itemList = itemList; } else if (DUP_BEFORE==placement) { list->InsertElementAt(mapElement, i); @@ -1020,7 +1021,7 @@ wallet_WriteToList( added_to_list = PR_TRUE; break; } - } else if(PL_strcmp(mapElementPtr->item1, mapElement->item1)>=0) { + } else if(Compare(mapElementPtr->item1,item1)>=0) { list->InsertElementAt(mapElement, i); added_to_list = PR_TRUE; break; @@ -1037,8 +1038,8 @@ wallet_WriteToList( */ static PRBool wallet_ReadFromList( - const nsACString& item1, - nsACString& item2, + nsString item1, + nsString& item2, nsVoidArray*& itemList, nsVoidArray*& list, PRBool obscure, @@ -1050,18 +1051,17 @@ wallet_ReadFromList( /* find item1 in the list */ wallet_MapElement * mapElementPtr; + ToLowerCase(item1); PRInt32 count = LIST_COUNT(list); for (PRInt32 i=index; iElementAt(i)); - if(item1.Equals(mapElementPtr->item1, nsCaseInsensitiveCStringComparator())) { + if(mapElementPtr->item1.Equals(item1)) { if (obscure) { - char * plaintext = nsnull; - if (NS_FAILED(DecryptString(mapElementPtr->item2, plaintext))) { + if (NS_FAILED(Wallet_Decrypt(mapElementPtr->item2, item2))) { return PR_FALSE; } - item2 = plaintext; } else { - item2 = PL_strdup(mapElementPtr->item2); + item2 = nsAutoString(mapElementPtr->item2); } itemList = mapElementPtr->itemList; index = i+1; @@ -1077,8 +1077,8 @@ wallet_ReadFromList( PRBool wallet_ReadFromList( - const nsACString& item1, - nsACString& item2, + nsString item1, + nsString& item2, nsVoidArray*& itemList, nsVoidArray*& list, PRBool obscure) @@ -1166,12 +1166,7 @@ Wallet_UTF8Put(nsOutputFileStream& strm, PRUnichar c) { } } -static void -wallet_Put(nsOutputFileStream& strm, char c) { - strm.put(c); -} - -static char +static PRUnichar wallet_Get(nsInputFileStream& strm) { const PRUint32 buflen = 1000; static char buf[buflen+1]; @@ -1185,7 +1180,7 @@ wallet_Get(nsInputFileStream& strm) { return 0; } } - return (buf[next++]); + return (buf[next++] & 0xFF); } PUBLIC PRUnichar @@ -1201,9 +1196,8 @@ Wallet_UTF8Get(nsInputFileStream& strm) { } else { return 0; /* this is an error, input was not utf8 */ } -} +}/* -/* * I have an even a simpler set of routines if you are not concerned about UTF-8. The * algorithms for those routines are as follows: * @@ -1337,11 +1331,10 @@ Wallet_RandomName(char* suffix) * strip carriage returns and line feeds from end of line */ -static nsresult -wallet_GetLine(nsInputFileStream& strm, const char** lineCString) +static PRInt32 +wallet_GetLine(nsInputFileStream& strm, nsString& line) { const PRUint32 kInitialStringCapacity = 64; - nsCAutoString line; /* read the line */ line.Truncate(0); @@ -1350,14 +1343,14 @@ wallet_GetLine(nsInputFileStream& strm, const char** lineCString) PRInt32 stringCap = kInitialStringCapacity; line.SetCapacity(stringCap); - char c; - static char lastC = '\0'; + PRUnichar c; + static PRUnichar lastC = '\0'; for (;;) { - c = wallet_Get(strm); + c = Wallet_UTF8Get(strm); /* check for eof */ if (c == 0) { - return NS_ERROR_FAILURE; + return -1; } /* check for line terminator (mac=CR, unix=LF, win32=CR+LF */ @@ -1378,51 +1371,49 @@ wallet_GetLine(nsInputFileStream& strm, const char** lineCString) } line += c; } - WALLET_FREEIF(*lineCString); - *lineCString = ToNewCString(line); + return NS_OK; } static PRBool wallet_GetHeader(nsInputFileStream& strm) { - const char* format = nsnull; + nsAutoString format; + nsAutoString buffer; /* format revision number */ - if (NS_FAILED(wallet_GetLine(strm, &format))) { + if (NS_FAILED(wallet_GetLine(strm, format))) { return PR_FALSE; } - PRBool rv = !PL_strcmp(format, HEADER_VERSION); - WALLET_FREEIF(format); - return rv; -} - -/* - * Write a line-feed to a file - */ -static void -wallet_EndLine(nsOutputFileStream& strm) { - strm.put('\n'); + if (!format.EqualsWithConversion(HEADER_VERSION)) { + /* something's wrong */ + return PR_FALSE; + } + return PR_TRUE; } /* * Write a line to a file */ static void -wallet_PutLine(nsOutputFileStream& strm, const char* line) { - strm.write(line, PL_strlen(line)); - wallet_EndLine(strm); +wallet_PutLine(nsOutputFileStream& strm, const nsString& line) { + for (PRUint32 i=0; iElementAt(i)); wallet_PutLine(strm, (*mapElementPtr).item1); - if (!WALLET_NULL((*mapElementPtr).item2)) { + if (!(*mapElementPtr).item2.IsEmpty()) { wallet_PutLine(strm, (*mapElementPtr).item2); } else { wallet_Sublist * sublistPtr; @@ -1468,7 +1459,7 @@ wallet_WriteToFile(const char * filename, nsVoidArray* list) { wallet_PutLine(strm, (*sublistPtr).item); } } - wallet_EndLine(strm); + wallet_PutLine(strm, nsAutoString()); } /* close the stream */ @@ -1500,7 +1491,7 @@ wallet_ReadFromFile } /* read in the header */ - if (!PL_strcmp(filename, schemaValueFileName)) { + if (filename == schemaValueFileName) { if (!wallet_GetHeader(strm)) { /* something's wrong -- ignore the file */ strm.close(); @@ -1509,33 +1500,32 @@ wallet_ReadFromFile } for (;;) { - if (NS_FAILED(wallet_GetLine(strm, &helpMac->item1))) { + if (NS_FAILED(wallet_GetLine(strm, helpMac->item1))) { /* end of file reached */ break; } #ifdef AutoCapture /* Distinguished schema list is a list of single entries, not name/value pairs */ - if (!PL_strcmp(filename, distinguishedSchemaFileName)) { + if (PL_strcmp(filename, distinguishedSchemaFileName) == 0) { nsVoidArray* dummy = NULL; wallet_WriteToList(helpMac->item1, helpMac->item1, dummy, list, PR_FALSE, placement); continue; } #endif - if (NS_FAILED(wallet_GetLine(strm, &helpMac->item2))) { + if (NS_FAILED(wallet_GetLine(strm, helpMac->item2))) { /* unexpected end of file reached */ break; } - - if (WALLET_NULL(helpMac->item2)) { + if (helpMac->item2.Length()==0) { /* the value must have been deleted */ nsVoidArray* dummy = NULL; wallet_WriteToList(helpMac->item1, helpMac->item2, dummy, list, PR_FALSE, placement); continue; } - if (NS_FAILED(wallet_GetLine(strm, &helpMac->item3))) { + if (NS_FAILED(wallet_GetLine(strm, helpMac->item3))) { /* end of file reached */ nsVoidArray* dummy = NULL; wallet_WriteToList(helpMac->item1, helpMac->item2, dummy, list, PR_FALSE, placement); @@ -1543,53 +1533,54 @@ wallet_ReadFromFile return; } - if (WALLET_NULL(helpMac->item3)) { + if (helpMac->item3.Length()==0) { /* just a pair of values, no need for a sublist */ nsVoidArray* dummy = NULL; wallet_WriteToList(helpMac->item1, helpMac->item2, dummy, list, PR_FALSE, placement); } else { /* need to create a sublist and put item2 and item3 onto it */ + // don't we leak itemList here? + nsVoidArray * itemList = new nsVoidArray(); if (!itemList) { break; } + // Don't we leak sublist too? wallet_Sublist * sublist = new wallet_Sublist; if (!sublist) { break; } - sublist->item = PL_strdup(helpMac->item2); + sublist->item = helpMac->item2; itemList->AppendElement(sublist); sublist = new wallet_Sublist; if (!sublist) { - delete itemList; break; } - sublist->item = PL_strdup(helpMac->item3); + sublist->item = helpMac->item3; itemList->AppendElement(sublist); /* add any following items to sublist up to next blank line */ + helpMac->dummy.Truncate(0); for (;;) { /* get next item for sublist */ - if (NS_FAILED(wallet_GetLine(strm, &helpMac->item3))) { + if (NS_FAILED(wallet_GetLine(strm, helpMac->item3))) { /* end of file reached */ - wallet_WriteToList(helpMac->item1, nsnull, itemList, list, PR_FALSE, placement); + wallet_WriteToList(helpMac->item1, helpMac->dummy, itemList, list, PR_FALSE, placement); strm.close(); return; } - - if (WALLET_NULL(helpMac->item3)) { + if (helpMac->item3.Length()==0) { /* blank line reached indicating end of sublist */ - wallet_WriteToList(helpMac->item1, nsnull, itemList, list, PR_FALSE, placement); + wallet_WriteToList(helpMac->item1, helpMac->dummy, itemList, list, PR_FALSE, placement); break; } /* add item to sublist */ sublist = new wallet_Sublist; if (!sublist) { - delete itemList; break; } - sublist->item = PL_strdup(helpMac->item3); + sublist->item = helpMac->item3; itemList->AppendElement(sublist); } } @@ -1613,7 +1604,7 @@ Wallet_GiveCaveat(nsIDOMWindowInternal* window, nsIPrompt* dialog) { } else { wallet_Alert(message, dialog); } - WALLET_FREE(message); + Recycle(message); } } @@ -1622,14 +1613,14 @@ wallet_GetHostFile(nsIURI * url, nsString& outHostFile) { outHostFile.Truncate(0); nsAutoString urlName; - char* host = nsnull; + char* host; nsresult rv = url->GetHost(&host); if (NS_FAILED(rv)) { return; } urlName.AppendWithConversion(host); nsCRT::free(host); - char* file = nsnull; + char* file; rv = url->GetPath(&file); if (NS_FAILED(rv)) { return; @@ -1642,26 +1633,23 @@ wallet_GetHostFile(nsIURI * url, nsString& outHostFile) urlName.Left(outHostFile, stringEnd); } -static void -Strip(const nsString& textUCS2, nsCString& stripText) { - NS_ConvertUCS2toUTF8 textUTF8(textUCS2); -// above line is equivalen to the following (who would have guessed it?) -// nsCAutoString textUTF8 = NS_ConvertUCS2toUTF8(textUCS2); - for (PRUint32 i=0; i'~') { stripText += c; } } + return stripText; } /* * given a displayable text, get the schema */ -static void -TextToSchema( +static void TextToSchema( const nsString& text, - nsACString& schema) + nsString& schema) { /* return if no SchemaStrings list exists */ if (!wallet_SchemaStrings_list) { @@ -1700,7 +1688,7 @@ TextToSchema( if (isSubstring) { /* all strings were contained in the displayable text, accept this schema */ - schema.Assign(mapElementPtr->item1); + schema = mapElementPtr->item1; return; } } @@ -1709,78 +1697,70 @@ TextToSchema( /* * given a field name, get the value */ -static nsresult -FieldToValue( +static PRInt32 FieldToValue( const nsString& field, - nsACString& schema, - nsString& valueUCS2, + nsString& schema, + nsString& value, nsVoidArray*& itemList, PRInt32& index) { /* return if no SchemaToValue list exists or if all values previous used */ if (!wallet_SchemaToValue_list || index == -1) { - return NS_ERROR_FAILURE; + return -1; } /* if no schema name is given, fetch schema name from field/schema tables */ nsVoidArray* dummy; - nsCAutoString stripField; - if (schema.IsEmpty()) { - Strip(field, stripField); - } - if (!schema.IsEmpty() || - wallet_ReadFromList(stripField, schema, dummy, wallet_FieldToSchema_list, PR_FALSE)) { + nsString stripField; + if ((schema.Length() > 0) || + wallet_ReadFromList(Strip(field, stripField), schema, dummy, wallet_FieldToSchema_list, PR_FALSE)) { /* schema name found, now attempt to fetch value from schema/value table */ - nsCAutoString valueUTF8; PRInt32 index2 = index; if ((index >= 0) && - wallet_ReadFromList - (schema, valueUTF8, itemList, wallet_SchemaToValue_list, PR_TRUE, index2)) { + wallet_ReadFromList(schema, value, itemList, wallet_SchemaToValue_list, PR_TRUE, index2)) { /* value found, prefill it into form and return */ - valueUCS2 = NS_ConvertUTF8toUCS2(valueUTF8); index = index2; - return NS_OK; + return 0; } else { /* value not found, see if concatenation rule exists */ nsVoidArray * itemList2; - nsCAutoString valueUTF8b; + nsAutoString dummy2; if (index > 0) { index = 0; } PRInt32 index0 = index; PRInt32 index00 = index; PRInt32 index4 = 0; - while (wallet_ReadFromList(schema, valueUTF8b, itemList2, wallet_SchemaConcat_list, PR_FALSE, index4)) { + while (wallet_ReadFromList(schema, dummy2, itemList2, wallet_SchemaConcat_list, PR_FALSE, index4)) { /* concatenation rules exist, generate value as a concatenation */ - nsCAutoString concatenatedValueUTF8; wallet_Sublist * sublistPtr; - concatenatedValueUTF8.SetLength(0); - nsCAutoString valueUTF8c; + value.SetLength(0); + nsAutoString value2; PRInt32 index00max = index0; - if (!valueUTF8b.IsEmpty()) { + if (dummy2.Length() > 0) { /* single item on rhs of concatenation rule */ PRInt32 index5 = 0; PRInt32 j; PRBool failed = PR_FALSE; for (j=0; j>index0; j -= 2) { - if (!wallet_ReadFromList(valueUTF8b, valueUTF8c, dummy, wallet_SchemaToValue_list, PR_TRUE, index5)) { + if (!wallet_ReadFromList(dummy2, value2, dummy, wallet_SchemaToValue_list, PR_TRUE, index5)) { failed = PR_TRUE; break; } index00 += 2; } - if (!failed && wallet_ReadFromList(valueUTF8b, valueUTF8c, dummy, wallet_SchemaToValue_list, PR_TRUE, index5)) { + if (!failed && wallet_ReadFromList(dummy2, value2, dummy, wallet_SchemaToValue_list, PR_TRUE, index5)) { /* found an unused value for the single rhs item */ - concatenatedValueUTF8 += valueUTF8c; + value += value2; index00 += 2; } index00max = index00; @@ -1799,9 +1779,8 @@ FieldToValue( index00 = index0; PRInt32 index3 = 0; PRBool failed = PR_FALSE; - nsCAutoString valueUTF8d; valueUTF8d.Assign(sublistPtr->item); for (PRInt32 j=0; j>index0; j -= 2) { - if (!wallet_ReadFromList(valueUTF8d, valueUTF8, dummy, wallet_SchemaToValue_list, PR_TRUE, index3)) { + if (!wallet_ReadFromList(sublistPtr->item, value2, dummy, wallet_SchemaToValue_list, PR_TRUE, index3)) { /* all values of next multi-rhs item were used previously */ failed = PR_TRUE; @@ -1810,13 +1789,13 @@ FieldToValue( index00 += 2; } - if (!failed && wallet_ReadFromList(valueUTF8d, valueUTF8, dummy, wallet_SchemaToValue_list, PR_TRUE, index3)) { - if (!concatenatedValueUTF8.IsEmpty()) { - concatenatedValueUTF8 += " "; + if (!failed && wallet_ReadFromList(sublistPtr->item, value2, dummy, wallet_SchemaToValue_list, PR_TRUE, index3)) { + if (value.Length()>0) { + value.Append(NS_LITERAL_STRING(" ")); } /* found an unused value for the multi-rhs item */ - concatenatedValueUTF8 += valueUTF8; + value += value2; index00 += 2; } if (index00 > index00max) { @@ -1825,12 +1804,11 @@ FieldToValue( } itemList = nsnull; - if (!concatenatedValueUTF8.IsEmpty()) { + if (value.Length()>0) { /* a new value was found */ index -= 2; - valueUCS2 = NS_ConvertUTF8toUCS2(concatenatedValueUTF8); - return NS_OK; + return 0; } /* all values from this concat rule were used, go on to next concat rule */ @@ -1839,33 +1817,29 @@ FieldToValue( /* no more concat rules, indicate failure */ index = -1; - return NS_ERROR_FAILURE; + return -1; } } else { /* schema name not found, use field name as schema name and fetch value */ PRInt32 index2 = index; - nsAutoString localSchemaUCS2; - wallet_GetHostFile(wallet_lastUrl, localSchemaUCS2); - localSchemaUCS2.Append(NS_LITERAL_STRING(":")); - localSchemaUCS2.Append(field); - nsCAutoString localSchemaUTF8 = NS_ConvertUCS2toUTF8(localSchemaUCS2); - nsCAutoString valueUTF8; + nsAutoString temp; + wallet_GetHostFile(wallet_lastUrl, temp); + temp.Append(NS_LITERAL_STRING(":")); + temp.Append(field); - if (wallet_ReadFromList - (localSchemaUTF8, valueUTF8, itemList, wallet_SchemaToValue_list, PR_TRUE, index2)) { + if (wallet_ReadFromList(temp, value, itemList, wallet_SchemaToValue_list, PR_TRUE, index2)) { /* value found, prefill it into form */ - schema = localSchemaUTF8; + schema = temp; index = index2; - valueUCS2 = NS_ConvertUTF8toUCS2(valueUTF8); - return NS_OK; + return 0; } } index = -1; - return NS_ERROR_FAILURE; + return -1; } -static nsresult +static PRInt32 wallet_GetSelectIndex( nsIDOMHTMLSelectElement* selectElement, const nsString& value, @@ -1897,13 +1871,13 @@ wallet_GetSelectIndex( optionText.Trim(" \n\t\r"); if (valueLC==optionValue || valueLC==optionText) { index = optionX; - return NS_OK; + return 0; } } } } } - return NS_ERROR_FAILURE; + return -1; } void @@ -1980,17 +1954,17 @@ wallet_StepForwardOrBack } /* if we've reached a #text node, append it to accumulated text */ - nsAutoString siblingNameUCS2; - result = elementNode->GetNodeName(siblingNameUCS2); - nsCAutoString siblingNameUTF8; siblingNameUTF8.AssignWithConversion(siblingNameUCS2); - if (siblingNameUTF8.EqualsIgnoreCase("#text")) { + nsAutoString siblingName; + result = elementNode->GetNodeName(siblingName); + nsCAutoString siblingCName; siblingCName.AssignWithConversion(siblingName); + if (siblingCName.EqualsIgnoreCase("#text")) { nsAutoString siblingValue; result = elementNode->GetNodeValue(siblingValue); text.Append(siblingValue); } /* if we've reached a SCRIPT node, don't fetch its siblings */ - if (siblingNameUTF8.EqualsIgnoreCase("SCRIPT")) { + if (siblingCName.EqualsIgnoreCase("SCRIPT")) { return; } @@ -2022,10 +1996,10 @@ wallet_StepForwardOrBack //static nsICaseConversion* gCaseConv = nsnull; static void -wallet_ResolvePositionalSchema(nsIDOMNode* elementNode, nsACString& schema) { +wallet_ResolvePositionalSchema(nsIDOMNode* elementNode, nsString& schema) { static PRInt32 numerator = 0; static PRInt32 denominator = 0; - static nsCString lastPositionalSchema; + static nsString lastPositionalSchema; /* return if no PositionalSchema list exists */ if (!wallet_PositionalSchema_list) { @@ -2033,12 +2007,12 @@ wallet_ResolvePositionalSchema(nsIDOMNode* elementNode, nsACString& schema) { return; } - if (!schema.IsEmpty()) { + if (schema.Length()) { numerator = 0; denominator = 0; - lastPositionalSchema.Assign(schema); + lastPositionalSchema = schema; } else if (numerator < denominator) { - schema.Assign(lastPositionalSchema); + schema = lastPositionalSchema; } else { schema.SetLength(0); return; @@ -2049,7 +2023,7 @@ wallet_ResolvePositionalSchema(nsIDOMNode* elementNode, nsACString& schema) { PRInt32 count = LIST_COUNT(wallet_PositionalSchema_list); for (PRInt32 i=0; iElementAt(i)); - if (schema.Equals(mapElementPtr->item1, nsCaseInsensitiveCStringComparator())) { + if (mapElementPtr->item1.EqualsIgnoreCase(schema)) { /* found our positional schema in the list */ /* A "position set" is a set of continuous or