nsInputFileStream strmu(dirSpec+"signon.tbl"); if (!si_oldFormat) { strmu = nsInputFileStream(dirSpec+signonFileNameU); }
nsInputFileStream strmu(dirSpec+signonFileNameU);
SI_LoadSignonData(PRBool fullLoad) {  /*   * This routine is called initially with fullLoad set to PR_FALSE.  That will cause   * the main file (consisting of URLs and usernames but having dummy passwords) to   * be read in.  Later, when a password is needed for the first time, the internal   * table is flushed and this routine is called again to read in the main file   * along with the file containing the real passwords.   *   * This is done because the reading of the password file requires the user to   * give a password to unlock the file.  We don't want to bother the user until   * we absolutely have to.  So if he never goes to fill out a password form, he   * should never have to give his password to unlock the password file   */  char * URLName;  nsAutoString buffer;  PRBool badInput = PR_FALSE;  nsKeyType readCount = 0;  if (si_FullyLoaded && fullLoad) {    return 0;  }#ifdef APPLE_KEYCHAIN  if (KeychainManagerAvailable()) {    SI_RemoveAllSignonData();    return si_LoadSignonDataFromKeychain();  }#endif  /* open the signon file */  nsFileSpec dirSpec;  nsresult rv = Wallet_ProfileDirectory(dirSpec);  if (NS_FAILED(rv)) {    return -1;  }  SI_InitSignonFileName();  nsInputFileStream strmu(dirSpec+"signon.tbl");  if (!si_oldFormat) {    strmu = nsInputFileStream(dirSpec+signonFileNameU);  }  if (!strmu.is_open()) {    /* this means no data was previously saved, so we must be fully loaded at this time */    si_FullyLoaded = fullLoad;    return 0;  }  SI_RemoveAllSignonData();  if (fullLoad) {    PRUnichar * message = Wallet_Localize("IncorrectKey_TryAgain?");    if (si_KeyTimedOut()) {      SI_RemoveAllSignonData();    }    while (!si_SetKey()) {      if ((Wallet_CancelKey() || Wallet_KeySize() < 0) || !si_ConfirmYN(message)) {        Recycle(message);        return 1;      }    }    Recycle(message);    si_KeyResetTime();  }  nsInputFileStream strmp(fullLoad ? (dirSpec+signonFileNameP) : dirSpec); // not used if !fullLoad  if (fullLoad && !strmp.is_open()) {    fullLoad = PR_FALSE;  }  /* read the header information */  nsAutoString format;  nsKeyType temp;  PRInt32 error;  if (!si_oldFormat) {    /* format */    if (NS_FAILED(si_ReadLine(strmu, strmp, format, fullLoad, 0, 0, PR_TRUE))) {      return -1;    }    if (format != HEADER_VERSION_1) {      /* something's wrong */      return -1;    }    /* saveCount */    if (NS_FAILED(si_ReadLine(strmu, strmp, buffer, fullLoad, 0, 0, PR_TRUE))) {      return -1;    }    if (NS_FAILED(si_ReadLine(strmu, strmp, buffer, fullLoad, 0, 0, PR_TRUE))) {      return -1;    }    temp = (nsKeyType)(buffer.ToInteger(&error));    if (error) {      return -1;    }    saveCountP = temp;    /* readCount */    if (NS_FAILED(si_ReadLine(strmu, strmp, buffer, fullLoad, 0, 0, PR_TRUE))) {      return -1;    }    if (NS_FAILED(si_ReadLine(strmu, strmp, buffer, fullLoad, 0, 0, PR_TRUE))) {      return -1;    }    temp = (nsKeyType)(buffer.ToInteger(&error));    if (error) {      return -1;    }    readCount = temp;    Wallet_StreamGeneratorReset();  }  /* read the reject list */  si_lock_signon_list();  while (!NS_FAILED(si_ReadLine(strmu, strmp, buffer, PR_FALSE))) {    if (buffer.CharAt(0) == '.') {      break; /* end of reject list */    }    si_StripLF(buffer);    URLName = buffer.ToNewCString();    if (si_oldFormat) {      if (NS_FAILED(si_ReadLine(strmu, strmp, buffer, PR_FALSE))) {        /* error in input file so give up */        badInput = PR_TRUE;        break;      }      si_StripLF(buffer);    }    si_PutReject(URLName, buffer, PR_FALSE); /* middle parameter is obsolete */    Recycle (URLName);  }  /* read the URL line */  while(!NS_FAILED(si_ReadLine(strmu, strmp, buffer, PR_FALSE))) {    si_StripLF(buffer);    URLName = buffer.ToNewCString();    /* prepare to read the name/value pairs */    badInput = PR_FALSE;    nsVoidArray * signonData = new nsVoidArray();    si_SignonDataStruct * data;    while(!NS_FAILED(si_ReadLine(strmu, strmp, buffer, PR_FALSE))) {      /* line starting with . terminates the pairs for this URL entry */      if (buffer.CharAt(0) == '.') {        break; /* end of URL entry */      }      /* line just read is the name part */      /* save the name part and determine if it is a password */      PRBool ret;      si_StripLF(buffer);      nsAutoString name;      nsAutoString value;      PRBool isPassword;      if (buffer.CharAt(0) == '*') {        isPassword = PR_TRUE;        nsAutoString temp;        buffer.Mid(name, 1, buffer.Length()-1);        ret = si_ReadLine(strmu, strmp, buffer, fullLoad, saveCountP, &readCount);      } else {        isPassword = PR_FALSE;        name = buffer;        if (si_oldFormat) {          ret = si_ReadLine(strmu, strmp, buffer, PR_FALSE);        } else {          ret = si_ReadLine(strmu, strmp, buffer, fullLoad, saveCountP, &readCount);        }      }      /* read in and save the value part */      if(NS_FAILED(ret)) {        /* error in input file so give up */        badInput = PR_TRUE;        break;      }      si_StripLF(buffer);      value = buffer;      data = new si_SignonDataStruct;      data->name = name;      data->value = value;      data->isPassword = isPassword;      signonData->AppendElement(data);    }    /* store the info for this URL into memory-resident data structure */    if (!URLName || PL_strlen(URLName) == 0) {      badInput = PR_TRUE;    }    if (!badInput) {      si_PutData(URLName, signonData, PR_FALSE);    }    /* free up all the allocations done for processing this URL */    Recycle(URLName);    if (badInput) {      si_unlock_signon_list();      return -1;    }    PRInt32 count = signonData->Count();    for (PRInt32 i=count-1; i>=0; i--) {      data = NS_STATIC_CAST(si_SignonDataStruct*, signonData->ElementAt(i));      delete data;    }    delete signonData;  }  si_unlock_signon_list();  si_PartiallyLoaded = PR_TRUE;  si_FullyLoaded = fullLoad;  return 0;}