void nsEudoraWin32::ConvertPath( nsCString& str) { nsCString temp; nsCString path; PRInt32 idx = 0; PRInt32 start = 0; nsCString search; idx = str.FindChar( '\\', idx); if ((idx == 2) && (str.CharAt( 1) == ':')) { str.Left( path, 3); idx++; idx = str.FindChar( '\\', idx); start = 3; if ((idx == -1) && (str.Length() > 3)) { str.Right( temp, str.Length() - start); path.Append( temp); } } WIN32_FIND_DATA findFileData; while (idx != -1) { str.Mid( temp, start, idx - start); search = path; search.Append( temp); HANDLE h = FindFirstFile( search.get(), &findFileData); if (h == INVALID_HANDLE_VALUE) return; path.Append( findFileData.cFileName); idx++; start = idx; idx = str.FindChar( '\\', idx); FindClose( h); if (idx != -1) path.Append( '\\'); else { str.Right( temp, str.Length() - start); path.Append( '\\'); path.Append( temp); } } str = path; }
void nsEudoraAddress::ExtractNoteField( nsCString& note, nsCString& value, const char *pFieldName) { value.Truncate(); nsCString field("<"); field.Append( pFieldName); field.Append( ':'); /* this is a bit of a cheat, but there's no reason it won't work fine for us, even better than Eudora in some cases! */ PRInt32 idx = note.Find( field); if (idx != -1) { idx += field.Length(); PRInt32 endIdx = note.FindChar( '>', idx); if (endIdx == -1) endIdx = note.Length() - 1; note.Mid( value, idx, endIdx - idx); idx -= field.Length(); nsCString tempL; if (idx) note.Left( tempL, idx); nsCString tempR; note.Right( tempR, note.Length() - endIdx - 1); note = tempL; note.Append( tempR); } }
void ReplaceEolChars( nsCString& s) { int idx; nsCString t; nsCString rt; while ((idx = s.Find( "\x0D")) != -1) { s.Left( t, idx); t += "\\n"; s.Right( rt, s.Length() - idx - 1); t += rt; s = t; } while ((idx = s.Find( "\x0A")) != -1) { s.Left( t, idx); t += "\\r"; s.Right( rt, s.Length() - idx - 1); t += rt; s = t; } }
void nsEudoraWin32::GetServerAndUserName( const char *pSection, const char *pIni, nsCString& serverName, nsCString& userName, char *pBuff) { DWORD valSize; int idx; nsCString tStr; serverName.Truncate(); userName.Truncate(); valSize = ::GetPrivateProfileString( pSection, "PopServer", "", pBuff, kIniValueSize, pIni); if (valSize) serverName = pBuff; else { valSize = ::GetPrivateProfileString( pSection, "POPAccount", "", pBuff, kIniValueSize, pIni); if (valSize) { serverName = pBuff; idx = serverName.FindChar( '@'); if (idx != -1) { serverName.Right( tStr, serverName.Length() - idx - 1); serverName = tStr; } } } valSize = ::GetPrivateProfileString( pSection, "LoginName", "", pBuff, kIniValueSize, pIni); if (valSize) userName = pBuff; else { valSize = ::GetPrivateProfileString( pSection, "POPAccount", "", pBuff, kIniValueSize, pIni); if (valSize) { userName = pBuff; idx = userName.FindChar( '@'); if (idx != -1) { userName.Left( tStr, idx); userName = tStr; } } } }
void nsEudoraAddress::SplitString( nsCString& val1, nsCString& val2) { nsCString temp; // Find the last line if there is more than one! PRInt32 idx = val1.RFind( "\x0D\x0A"); PRInt32 cnt = 2; if (idx == -1) { cnt = 1; idx = val1.RFindChar( 13); } if (idx == -1) idx= val1.RFindChar( 10); if (idx != -1) { val1.Right( val2, val1.Length() - idx - cnt); val1.Left( temp, idx); val1 = temp; SanitizeValue( val1); } }
static nsresult SplitURL(nsIURI *aChromeURI, nsCString& aPackage, nsCString& aProvider, nsCString& aFile, PRBool *aModified = nsnull) { // Splits a "chrome:" URL into its package, provider, and file parts. // Here are the current portions of a // chrome: url that make up the chrome- // // chrome://global/skin/foo?bar // \------/ \----/\---/ \-----/ // | | | | // | | | `-- RemainingPortion // | | | // | | `-- Provider // | | // | `-- Package // | // `-- Always "chrome://" // // nsresult rv; nsCAutoString str; rv = aChromeURI->GetSpec(str); if (NS_FAILED(rv)) return rv; // We only want to deal with "chrome:" URLs here. We could return // an error code if the URL isn't properly prefixed here... if (PL_strncmp(str.get(), kChromePrefix, sizeof(kChromePrefix) - 1) != 0) return NS_ERROR_INVALID_ARG; // Cull out the "package" string; e.g., "navigator" aPackage = str.get() + sizeof(kChromePrefix) - 1; PRInt32 idx; idx = aPackage.FindChar('/'); if (idx < 0) return NS_OK; // Cull out the "provider" string; e.g., "content" aPackage.Right(aProvider, aPackage.Length() - (idx + 1)); aPackage.Truncate(idx); idx = aProvider.FindChar('/'); if (idx < 0) { // Force the provider to end with a '/' idx = aProvider.Length(); aProvider.Append('/'); } // Cull out the "file"; e.g., "navigator.xul" aProvider.Right(aFile, aProvider.Length() - (idx + 1)); aProvider.Truncate(idx); PRBool nofile = aFile.IsEmpty(); if (nofile) { // If there is no file, then construct the default file aFile = aPackage; if (aProvider.Equals("content")) { aFile += ".xul"; } else if (aProvider.Equals("skin")) { aFile += ".css"; } else if (aProvider.Equals("locale")) { aFile += ".dtd"; } else { NS_ERROR("unknown provider"); return NS_ERROR_FAILURE; } } else { // Protect against URIs containing .. that reach up out of the // chrome directory to grant chrome privileges to non-chrome files. int depth = 0; PRBool sawSlash = PR_TRUE; // .. at the beginning is suspect as well as /.. for (const char* p=aFile.get(); *p; p++) { if (sawSlash) { if (p[0] == '.' && p[1] == '.'){ depth--; // we have /.., decrement depth. } else { static const char escape[] = "%2E%2E"; if (PL_strncasecmp(p, escape, sizeof(escape)-1) == 0) depth--; // we have the HTML-escaped form of /.., decrement depth. } } else if (p[0] != '/') { depth++; // we have /x for some x that is not / } sawSlash = (p[0] == '/'); if (depth < 0) { return NS_ERROR_FAILURE; } } } if (aModified) *aModified = nofile; return NS_OK; }