Пример #1
0
static bool
IsAnonymous(const nsACString& aName)
{
  // Recent kernels (e.g. 3.5) have multiple [stack:nnnn] entries, where |nnnn|
  // is a thread ID.  However, [stack:nnnn] entries count both stack memory
  // *and* anonymous memory because the kernel only knows about the start of
  // each thread stack, not its end.  So we treat such entries as anonymous
  // memory instead of stack.  This is consistent with older kernels that don't
  // even show [stack:nnnn] entries.
  return aName.IsEmpty() ||
         StringBeginsWith(aName, NS_LITERAL_CSTRING("[stack:"));
}
static PLDHashOperator
RemoveOwnersEnum(const nsACString& key,
                 nsAutoPtr<nsDOMStorageMemoryDB::nsInMemoryStorage>& storage,
                 void *closure)
{
  RemoveOwnersStruc* struc = (RemoveOwnersStruc*)closure;

  if (StringBeginsWith(key, *(struc->mSubDomain)) == struc->mMatch)
    return PL_DHASH_REMOVE;

  return PL_DHASH_NEXT;
}
Пример #3
0
int CLuaACLDefs::isObjectInACLGroup ( lua_State* luaVM )
{
//  bool isObjectInACLGroup ( string theObject, aclgroup theGroup )
    SString strObject; CAccessControlListGroup* pGroup; CAccessControlListGroupObject::EObjectType GroupObjectType;
    
    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( strObject );
    argStream.ReadUserData ( pGroup );
    
    if ( !argStream.HasErrors () )
    {
        // Figure out what type of object this is
        const char* szObjectAfterDot = strObject;
        if ( StringBeginsWith ( strObject, "resource." ) ) {
            szObjectAfterDot += 9;
            GroupObjectType = CAccessControlListGroupObject::OBJECT_TYPE_RESOURCE;
        }
        else if ( StringBeginsWith ( strObject, "user." ) )
        {
            szObjectAfterDot += 5;
            GroupObjectType = CAccessControlListGroupObject::OBJECT_TYPE_USER;
        }
        else
        {
            // Invalid group type
            lua_pushboolean ( luaVM, false );
            return 1;
        }
        if ( pGroup->FindObjectMatch ( szObjectAfterDot, GroupObjectType ) )
        {
            lua_pushboolean ( luaVM, true );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Пример #4
0
bool
nsSynthVoiceRegistry::FindVoiceByLang(const nsAString& aLang,
                                      VoiceData** aRetval)
{
  nsAString::const_iterator dashPos, start, end;
  aLang.BeginReading(start);
  aLang.EndReading(end);

  while (true) {
    nsAutoString langPrefix(Substring(start, end));

    for (int32_t i = mDefaultVoices.Length(); i > 0; ) {
      VoiceData* voice = mDefaultVoices[--i];

      if (StringBeginsWith(voice->mLang, langPrefix)) {
        *aRetval = voice;
        return true;
      }
    }

    for (int32_t i = mVoices.Length(); i > 0; ) {
      VoiceData* voice = mVoices[--i];

      if (StringBeginsWith(voice->mLang, langPrefix)) {
        *aRetval = voice;
        return true;
      }
    }

    dashPos = end;
    end = start;

    if (!RFindInReadable(NS_LITERAL_STRING("-"), end, dashPos)) {
      break;
    }
  }

  return false;
}
bool nsMediaFragmentURIParser::ParseXYWH(nsDependentSubstring aString)
{
  int32_t x, y, w, h;
  ClipUnit clipUnit;

  // Determine units.
  if (StringBeginsWith(aString, NS_LITERAL_STRING("pixel:"))) {
    clipUnit = eClipUnit_Pixel;
    aString.Rebind(aString, 6);
  } else if (StringBeginsWith(aString, NS_LITERAL_STRING("percent:"))) {
    clipUnit = eClipUnit_Percent;
    aString.Rebind(aString, 8);
  } else {
    clipUnit = eClipUnit_Pixel;
  }

  // Read and validate coordinates.
  if (ParseInteger(aString, x) && x >= 0 &&
      ParseCommaSeparator(aString)       &&
      ParseInteger(aString, y) && y >= 0 &&
      ParseCommaSeparator(aString)       &&
      ParseInteger(aString, w) && w > 0  &&
      ParseCommaSeparator(aString)       &&
      ParseInteger(aString, h) && h > 0  &&
      aString.Length() == 0) {

    // Reject invalid percentage coordinates.
    if (clipUnit == eClipUnit_Percent &&
        (x + w > 100 || y + h > 100)) {
      return false;
    }

    mClip.construct(x, y, w, h);
    mClipUnit = clipUnit;
    return true;
  }

  return false;
}
Пример #6
0
void
DOMStorageManager::ClearCaches(uint32_t aUnloadFlags,
                               const nsACString& aKeyPrefix)
{
  for (auto iter = mCaches.Iter(); !iter.Done(); iter.Next()) {
    DOMStorageCache* cache = iter.Get()->cache();
    nsCString& key = const_cast<nsCString&>(cache->Scope());

    if (aKeyPrefix.IsEmpty() || StringBeginsWith(key, aKeyPrefix)) {
      cache->UnloadItems(aUnloadFlags);
    }
  }
}
void
nsFaviconService::GetFaviconSpecForIconString(const nsCString& aSpec,
                                              nsACString& aOutput)
{
  if (aSpec.IsEmpty()) {
    aOutput.AssignLiteral(FAVICON_DEFAULT_URL);
  } else if (StringBeginsWith(aSpec, NS_LITERAL_CSTRING("chrome:"))) {
    aOutput = aSpec;
  } else {
    aOutput.AssignLiteral("moz-anno:" FAVICON_ANNOTATION_NAME ":");
    aOutput += aSpec;
  }
}
NS_IMETHODIMP
nsUrlClassifierStreamUpdater::UpdateUrlRequested(const nsACString &aUrl,
                                                 const nsACString &aTable,
                                                 const nsACString &aServerMAC)
{
  LOG(("Queuing requested update from %s\n", PromiseFlatCString(aUrl).get()));

  PendingUpdate *update = mPendingUpdates.AppendElement();
  if (!update)
    return NS_ERROR_OUT_OF_MEMORY;

  // Allow data: and file: urls for unit testing purposes, otherwise assume http
  if (StringBeginsWith(aUrl, NS_LITERAL_CSTRING("data:")) ||
      StringBeginsWith(aUrl, NS_LITERAL_CSTRING("file:"))) {
    update->mUrl = aUrl;
  } else {
    update->mUrl = NS_LITERAL_CSTRING("http://") + aUrl;
  }
  update->mTable = aTable;
  update->mServerMAC = aServerMAC;

  return NS_OK;
}
Пример #9
0
NS_IMETHODIMP
nsAuthSambaNTLM::GetNextToken(const void *inToken,
                              PRUint32    inTokenLen,
                              void      **outToken,
                              PRUint32   *outTokenLen)
{
    if (!inToken) {
        /* someone wants our initial message */
        *outToken = nsMemory::Clone(mInitialMessage, mInitialMessageLen);
        if (!*outToken)
            return NS_ERROR_OUT_OF_MEMORY;
        *outTokenLen = mInitialMessageLen;
        return NS_OK;
    }

    /* inToken must be a type 2 message. Get ntlm_auth to generate our response */
    char* encoded = PL_Base64Encode(static_cast<const char*>(inToken), inTokenLen, nullptr);
    if (!encoded)
        return NS_ERROR_OUT_OF_MEMORY;

    nsCString request;
    request.AssignLiteral("TT ");
    request.Append(encoded);
    free(encoded);
    request.Append('\n');

    if (!WriteString(mToChildFD, request))
        return NS_ERROR_FAILURE;
    nsCString line;
    if (!ReadLine(mFromChildFD, line))
        return NS_ERROR_FAILURE;
    if (!StringBeginsWith(line, NS_LITERAL_CSTRING("KK "))) {
        // Something went wrong. Perhaps no credentials are accessible.
        return NS_ERROR_FAILURE;
    }
    PRUint8* buf = ExtractMessage(line, outTokenLen);
    if (!buf)
        return NS_ERROR_FAILURE;
    // *outToken has to be freed by nsMemory::Free, which may not be free() 
    *outToken = nsMemory::Clone(buf, *outTokenLen);
    if (!*outToken) {
        free(buf);
        return NS_ERROR_OUT_OF_MEMORY;
    }
    
    // We're done. Close our file descriptors now and reap the helper
    // process.
    Shutdown();
    return NS_SUCCESS_AUTH_FINISHED;
}
Пример #10
0
PLDHashOperator
DOMStorageManager::ClearCacheEnumerator(DOMStorageCacheHashKey* aEntry, void* aClosure)
{
    DOMStorageCache* cache = aEntry->cache();
    nsCString& key = const_cast<nsCString&>(cache->Scope());

    ClearCacheEnumeratorData* data = static_cast<ClearCacheEnumeratorData*>(aClosure);

    if (data->mKeyPrefix.IsEmpty() || StringBeginsWith(key, data->mKeyPrefix)) {
        cache->UnloadItems(data->mUnloadFlags);
    }

    return PL_DHASH_NEXT;
}
Пример #11
0
PRBool
LocalSearchDataSource::doMatch(nsIRDFLiteral *literal,
                               const nsAString &matchMethod,
                               const nsString &matchText)
{
	PRBool		found = PR_FALSE;

	if ((nsnull == literal) ||
            matchMethod.IsEmpty() ||
            matchText.IsEmpty())
		return(found);

	const	PRUnichar	*str = nsnull;
	literal->GetValueConst( &str );
	if (! str)	return(found);
	nsAutoString	value(str);

        if (matchMethod.EqualsLiteral("contains"))
	{
            if (-1 != value.Find(matchText, CaseInsensitiveCompare))
                found = PR_TRUE;
	}
        else if (matchMethod.EqualsLiteral("startswith"))
	{
            if (StringBeginsWith(value, matchText, CaseInsensitiveCompare))
                found = PR_TRUE;
	}
        else if (matchMethod.EqualsLiteral("endswith"))
	{
            if (StringEndsWith(value, matchText, CaseInsensitiveCompare))
                found = PR_TRUE;
	}
        else if (matchMethod.EqualsLiteral("is"))
	{
            if (value.Equals(matchText, CaseInsensitiveCompare))
                found = PR_TRUE;
	}
        else if (matchMethod.EqualsLiteral("isnot"))
	{
            if (!value.Equals(matchText, CaseInsensitiveCompare))
                found = PR_TRUE;
	}
        else if (matchMethod.EqualsLiteral("doesntcontain"))
	{
            if (-1 == value.Find(matchText, CaseInsensitiveCompare))
                found = PR_TRUE;
	}
        return(found);
}
NS_IMETHODIMP
sbOriginPageImagePropertyInfo::GetCellProperties(const nsAString& aValue,
                                                 nsAString& _retval)
{
  if(aValue.EqualsLiteral("unknownOrigin") ||
     aValue.IsEmpty() ||
     aValue.IsVoid()) {
    _retval.AssignLiteral("image unknownOrigin");
    return NS_OK;
  }

  if(aValue.EqualsLiteral("webOrigin") ||
     StringBeginsWith(aValue, NS_LITERAL_STRING("http://"), CaseInsensitiveCompare) ||
     StringBeginsWith(aValue, NS_LITERAL_STRING("https://"), CaseInsensitiveCompare) ||
     StringBeginsWith(aValue, NS_LITERAL_STRING("ftp://"), CaseInsensitiveCompare)) {
    
    _retval.AssignLiteral("image webOrigin");
    return NS_OK;
  }

  _retval.AssignLiteral("image");

  return NS_OK;
}
static FileDataInfo*
GetFileDataInfo(const nsACString& aUri)
{
  NS_ASSERTION(StringBeginsWith(aUri,
                                NS_LITERAL_CSTRING(BLOBURI_SCHEME ":")),
               "Bad URI");
  
  if (!gFileDataTable) {
    return nsnull;
  }
  
  FileDataInfo* res;
  gFileDataTable->Get(aUri, &res);
  return res;
}
Пример #14
0
// static
bool
FileSystemUtils::IsDescendantPath(const nsAString& aPath,
                                  const nsAString& aDescendantPath)
{
  // The descendant path should begin with its ancestor path.
  nsAutoString prefix;
  prefix = aPath + NS_LITERAL_STRING(FILESYSTEM_DOM_PATH_SEPARATOR);

  // Check the sub-directory path to see if it has the parent path as prefix.
  if (aDescendantPath.Length() < prefix.Length() ||
      !StringBeginsWith(aDescendantPath, prefix)) {
    return false;
  }

  return true;
}
Пример #15
0
nsresult
rdf_MakeRelativeRef(const nsCSubstring& aBaseURI, nsCString& aURI)
{
    // This implementation is extremely simple: e.g., it can't compute
    // relative paths, or anything fancy like that. If the context URI
    // is not a prefix of the URI in question, we'll just bail.
    PRUint32 prefixLen = aBaseURI.Length();
    if (prefixLen != 0 && StringBeginsWith(aURI, aBaseURI)) {
        if (prefixLen < aURI.Length() && aURI.CharAt(prefixLen) == '/')
            ++prefixLen; // chop the leading slash so it's not `absolute'

        aURI.Cut(0, prefixLen);
    }

    return NS_OK;
}
Пример #16
0
nsFileResult::nsFileResult(const nsAString& aSearchString,
                           const nsAString& aSearchParam):
  mSearchString(aSearchString)
{
  if (aSearchString.IsEmpty())
    mSearchResult = RESULT_IGNORED;
  else {
    int32_t slashPos = mSearchString.RFindChar('/');
    mSearchResult = RESULT_FAILURE;
    nsCOMPtr<nsIFile> directory;
    nsDependentSubstring parent(Substring(mSearchString, 0, slashPos + 1));
    if (!parent.IsEmpty() && parent.First() == '/')
      NS_NewLocalFile(parent, true, getter_AddRefs(directory));
    if (!directory) {
      if (NS_FAILED(NS_NewLocalFile(aSearchParam, true, getter_AddRefs(directory))))
        return;
      if (slashPos > 0)
        directory->AppendRelativePath(Substring(mSearchString, 0, slashPos));
    }
    nsCOMPtr<nsISimpleEnumerator> dirEntries;
    if (NS_FAILED(directory->GetDirectoryEntries(getter_AddRefs(dirEntries))))
      return;
    mSearchResult = RESULT_NOMATCH;
    bool hasMore = false;
    nsDependentSubstring prefix(Substring(mSearchString, slashPos + 1));
    while (NS_SUCCEEDED(dirEntries->HasMoreElements(&hasMore)) && hasMore) {
      nsCOMPtr<nsISupports> nextItem;
      dirEntries->GetNext(getter_AddRefs(nextItem));
      nsCOMPtr<nsIFile> nextFile(do_QueryInterface(nextItem));
      nsAutoString fileName;
      nextFile->GetLeafName(fileName);
      if (StringBeginsWith(fileName, prefix)) {
        fileName.Insert(parent, 0);
        if (mSearchResult == RESULT_NOMATCH && fileName.Equals(mSearchString))
          mSearchResult = RESULT_IGNORED;
        else
          mSearchResult = RESULT_SUCCESS;
        bool isDirectory = false;
        nextFile->IsDirectory(&isDirectory);
        if (isDirectory)
          fileName.Append('/');
        mValues.AppendElement(fileName);
      }
    }
    mValues.Sort();
  }
}
Пример #17
0
NS_IMETHODIMP nsAbMDBDirFactory::GetDirectories(const nsAString &aDirName,
                                                const nsACString &aURI,
                                                const nsACString &aPrefName,
                                                nsISimpleEnumerator **_retval)
{
  NS_ENSURE_ARG_POINTER(_retval);
  
  nsresult rv;

  nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIAbDirectory> directory;
  rv = abManager->GetDirectory(aURI, getter_AddRefs(directory));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = directory->SetDirPrefId(aPrefName);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsILocalFile> dbPath;
  rv = abManager->GetUserProfileDirectory(getter_AddRefs(dbPath));

  nsCOMPtr<nsIAddrDatabase> listDatabase;
  if (NS_SUCCEEDED(rv))
  {
    nsCAutoString fileName;
      
    if (StringBeginsWith(aURI, NS_LITERAL_CSTRING(kMDBDirectoryRoot)))
      fileName = Substring(aURI, kMDBDirectoryRootLen, aURI.Length() - kMDBDirectoryRootLen);

    rv = dbPath->AppendNative(fileName);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIAddrDatabase> addrDBFactory = do_GetService(NS_ADDRDATABASE_CONTRACTID, &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = addrDBFactory->Open(dbPath, true, true, getter_AddRefs(listDatabase));
  }
  NS_ENSURE_SUCCESS(rv, rv);

  rv = listDatabase->GetMailingListsFromDB(directory);
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_NewSingletonEnumerator(_retval, directory);
}
Пример #18
0
void nsEudoraWin32::GetAccountName( const char *pSection, nsString& str)
{
  str.Truncate();

  nsCString s(pSection);

  if (s.LowerCaseEqualsLiteral("settings"))
  {
    str.AssignLiteral("Eudora ");
    str.Append(NS_ConvertASCIItoUTF16(pSection));
  }
  else
  {
    str.AssignASCII(pSection);
    if (StringBeginsWith(s, NS_LITERAL_CSTRING("persona-"), nsCaseInsensitiveCStringComparator()))
      CopyASCIItoUTF16(Substring(s, 8), str);
  }
}
bool
EventListenerManager::HasListenersFor(nsIAtom* aEventNameWithOn)
{
#ifdef DEBUG
  nsAutoString name;
  aEventNameWithOn->ToString(name);
#endif
  NS_ASSERTION(StringBeginsWith(name, NS_LITERAL_STRING("on")),
               "Event name does not start with 'on'");
  uint32_t count = mListeners.Length();
  for (uint32_t i = 0; i < count; ++i) {
    Listener* listener = &mListeners.ElementAt(i);
    if (listener->mTypeAtom == aEventNameWithOn) {
      return true;
    }
  }
  return false;
}
Пример #20
0
void
EventTarget::SetEventHandler(const nsAString& aType,
                             EventHandlerNonNull* aHandler,
                             ErrorResult& aRv)
{
  if (!StringBeginsWith(aType, NS_LITERAL_STRING("on"))) {
    aRv.Throw(NS_ERROR_INVALID_ARG);
    return;
  }
  if (NS_IsMainThread()) {
    nsCOMPtr<nsIAtom> type = NS_Atomize(aType);
    SetEventHandler(type, EmptyString(), aHandler);
    return;
  }
  SetEventHandler(nullptr,
                  Substring(aType, 2), // Remove "on"
                  aHandler);
}
Пример #21
0
static bool
ParseKeySystem(const nsAString& aExpectedKeySystem,
               const nsAString& aInputKeySystem,
               int32_t& aOutCDMVersion)
{
    if (!StringBeginsWith(aInputKeySystem, aExpectedKeySystem)) {
        return false;
    }

    if (aInputKeySystem.Length() > aExpectedKeySystem.Length() + 8) {
        // Allow up to 8 bytes for the ".version" field. 8 bytes should
        // be enough for any versioning scheme...
        NS_WARNING("Input KeySystem including was suspiciously long");
        return false;
    }

    const char16_t* versionStart = aInputKeySystem.BeginReading() + aExpectedKeySystem.Length();
    const char16_t* end = aInputKeySystem.EndReading();
    if (versionStart == end) {
        // No version supplied with keysystem.
        aOutCDMVersion = NO_CDM_VERSION;
        return true;
    }
    if (*versionStart != '.') {
        // version not in correct format.
        NS_WARNING("EME keySystem version string not prefixed by '.'");
        return false;
    }
    versionStart++;
    const nsAutoString versionStr(Substring(versionStart, end));
    if (!ContainsOnlyDigits(versionStr)) {
        NS_WARNING("Non-digit character in EME keySystem string's version suffix");
        return false;
    }
    nsresult rv;
    int32_t version = versionStr.ToInteger(&rv);
    if (NS_FAILED(rv) || version < 0) {
        NS_WARNING("Invalid version in EME keySystem string");
        return false;
    }
    aOutCDMVersion = version;

    return true;
}
Пример #22
0
NS_IMETHODIMP nsAbLDAPDirectory::GetLDAPURL(nsILDAPURL** aResult)
{
    NS_ENSURE_ARG_POINTER(aResult);

    // Rather than using GetURI here we call GetStringValue directly so
    // we can handle the case where the URI isn't specified (see comments
    // below)
    nsCAutoString URI;
    nsresult rv = GetStringValue("uri", EmptyCString(), URI);
    if (NS_FAILED(rv) || URI.IsEmpty())
    {
        /*
         * A recent change in Mozilla now means that the LDAP Address Book
         * RDF Resource URI is based on the unique preference name value i.e.
         * [moz-abldapdirectory://prefName]
         * Prior to this valid change it was based on the actual uri i.e.
         * [moz-abldapdirectory://host:port/basedn]
         * Basing the resource on the prefName allows these attributes to
         * change.
         *
         * But the uri value was also the means by which third-party
         * products could integrate with Mozilla's LDAP Address Books
         * without necessarily having an entry in the preferences file
         * or more importantly needing to be able to change the
         * preferences entries. Thus to set the URI Spec now, it is
         * only necessary to read the uri pref entry, while in the
         * case where it is not a preference, we need to replace the
         * "moz-abldapdirectory".
         */
        URI = mURINoQuery;
        if (StringBeginsWith(URI, NS_LITERAL_CSTRING(kLDAPDirectoryRoot)))
            URI.Replace(0, kLDAPDirectoryRootLen, NS_LITERAL_CSTRING("ldap://"));
    }

    nsCOMPtr<nsIIOService> ioService(do_GetService(NS_IOSERVICE_CONTRACTID, &rv));
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIURI> result;
    rv = ioService->NewURI(URI, nsnull, nsnull, getter_AddRefs(result));
    NS_ENSURE_SUCCESS(rv, rv);

    return CallQueryInterface(result, aResult);
}
Пример #23
0
NS_IMETHODIMP nsAbBSDirectory::CreateDirectoryByURI(const nsAString &aDisplayName,
                                                    const nsACString &aURI)
{
  nsresult rv = EnsureInitialized();
  NS_ENSURE_SUCCESS(rv, rv);

  nsCString fileName;
  if (StringBeginsWith(aURI, NS_LITERAL_CSTRING(kMDBDirectoryRoot)))
    fileName = StringTail(aURI, aURI.Length() - kMDBDirectoryRootLen);

  DIR_Server * server = nsnull;
  rv = DIR_AddNewAddressBook(aDisplayName, fileName, aURI,
                             PABDirectory, EmptyCString(), &server);
  NS_ENSURE_SUCCESS(rv,rv);

  rv = CreateDirectoriesFromFactory(aURI, server, PR_TRUE /* notify */);
  NS_ENSURE_SUCCESS(rv,rv);
	return rv;
}
nsresult
nsBeckyFilters::ParseFilterFile(nsIFile *aFile, bool aIncoming)
{
  nsresult rv;
  nsCOMPtr<nsILineInputStream> lineStream;
  rv = nsBeckyUtils::CreateLineInputStream(aFile, getter_AddRefs(lineStream));
  NS_ENSURE_SUCCESS(rv, rv);

  bool more = true;
  nsAutoCString line;

  nsCOMPtr<nsIMsgFilter> filter;
  while (NS_SUCCEEDED(rv) && more) {
    rv = lineStream->ReadLine(line, &more);

    switch (line.CharAt(0)) {
      case ':':
        if (line.EqualsLiteral(":Begin \"\"")) {
          CreateFilter(aIncoming, getter_AddRefs(filter));
        } else if (line.EqualsLiteral(":End \"\"")) {
          if (filter)
            AppendFilter(filter);
          filter = nullptr;
        }
        break;
      case '!':
        SetRuleAction(line, filter);
        break;
      case '@':
        SetSearchTerm(line, filter);
        break;
      case '$': // $X: disabled
        if (StringBeginsWith(line, NS_LITERAL_CSTRING("$X")) && filter) {
          filter->SetEnabled(false);
        }
        break;
      default:
        break;
    }
  }

  return NS_OK;
}
bool CAccessControlListGroup::FindObjectMatch ( const char* szObjectName, CAccessControlListGroupObject::EObjectType eObjectType )
{
    unsigned int uiHash = CAccessControlListGroupObject::GenerateHashId ( szObjectName, eObjectType );

    // Look through the list for a matching name. If we find one, return true.
    ObjectMap::const_iterator iterFind = m_ObjectsById.find ( uiHash );
    if ( iterFind != m_ObjectsById.end() )
    {
        return true;
    }

    // Loop through our list again for wildchar finding
    char strName [256];
    strName[255] = '\0';
    ObjectList::iterator iter = m_Objects.begin ();
    for ( ; iter != m_Objects.end (); iter++ )
    {
        // Matching type (resource/user)
        if ( eObjectType == (*iter)->GetObjectType () )
        {
            // Grab object name and string length
            const char* szName = (*iter)->GetObjectName ();
            int iLen = strlen ( szName );

            // Long enough string and this is a wildchar entry?
            if ( iLen > 0 && szName [iLen - 1] == '*' )
            {
                // Copy the namestring and remove it's wildchar character
                strncpy ( strName, szName, 255 );
                strName [iLen - 1] = '\0';

                // Does the st
                if ( StringBeginsWith ( szObjectName, strName ) )
                {
                    return true;
                }
            }
        }
    }

    return false;
}
NS_IMETHODIMP
sbOriginPageImagePropertyInfo::GetImageSrc(const nsAString& aValue,
                                           nsAString& _retval)
{
  if(aValue.IsEmpty() ||
     aValue.IsVoid() ||
     aValue.EqualsLiteral("unknownOrigin") ||
     aValue.EqualsLiteral("webOrigin")) {
    _retval.Truncate();
    return NS_OK;
  }

  nsCOMPtr<nsIURI> uri;
  nsresult rv = NS_NewURI(getter_AddRefs(uri), aValue);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIURI> imageUri;
  rv = mFaviconService->GetFaviconForPage(uri, getter_AddRefs(imageUri));
  
  if(rv == NS_ERROR_NOT_AVAILABLE) {
    _retval.Truncate();
    return NS_OK;
  }

  NS_ENSURE_SUCCESS(rv, rv);

  nsCAutoString spec;
  rv = imageUri->GetSpec(spec);
  NS_ENSURE_SUCCESS(rv, rv);
  
  NS_NAMED_LITERAL_CSTRING(mozAnnoFavicon, "moz-anno:favicon:");
  if(!StringBeginsWith(spec, mozAnnoFavicon)) {
    _retval = NS_ConvertUTF8toUTF16(spec);
    return NS_OK;
  }

  spec.Cut(0, mozAnnoFavicon.Length());
  NS_WARNING(spec.get());
  _retval = NS_ConvertUTF8toUTF16(spec);

  return NS_OK;
}
Пример #27
0
void nsEudoraCompose::ExtractType(nsString& str)
{
  nsString tStr;
  int32_t idx = str.FindChar(';');
  if (idx != -1)
    str.SetLength(idx);

  str.Trim(kWhitespace);

  if ((str.CharAt(0) == '"') && (str.Length() > 2)) {
    str.SetLength(str.Length() - 1);
    str.Cut(0, 1);
    str.Trim(kWhitespace);
  }

  // if multipart then ignore it since no outlook message body is ever
  // valid multipart!
  if (StringBeginsWith(str, NS_LITERAL_STRING("multipart/"), nsCaseInsensitiveStringComparator()))
    str.Truncate();
}
static PLDHashOperator
GetUsageEnum(const nsACString& key,
             nsDOMStorageMemoryDB::nsInMemoryStorage* storageData,
             void *closure)
{
  GetUsageEnumStruc* struc = (GetUsageEnumStruc*)closure;

  if (StringBeginsWith(key, struc->mSubdomain)) {
    if (struc->mExcludeOfflineFromUsage) {
      nsCAutoString domain;
      nsresult rv = nsDOMStorageDBWrapper::GetDomainFromScopeKey(key, domain);
      if (NS_SUCCEEDED(rv) && IsOfflineAllowed(domain))
        return PL_DHASH_NEXT;
    }

    struc->mUsage += storageData->mUsageDelta;
  }

  return PL_DHASH_NEXT;
}
Пример #29
0
static PRBool
IsScriptEventHandler(nsIScriptElement *aScriptElement)
{
    nsCOMPtr<nsIContent> contElement = do_QueryInterface(aScriptElement);
    NS_ASSERTION(contElement, "nsIScriptElement isn't nsIContent");

    nsAutoString forAttr, eventAttr;
    if (!contElement->GetAttr(kNameSpaceID_None, nsGkAtoms::_for, forAttr) ||
            !contElement->GetAttr(kNameSpaceID_None, nsGkAtoms::event, eventAttr)) {
        return PR_FALSE;
    }

    const nsAString& for_str = nsContentUtils::TrimWhitespace(forAttr);
    if (!for_str.LowerCaseEqualsLiteral("window")) {
        return PR_TRUE;
    }

    // We found for="window", now check for event="onload".
    const nsAString& event_str = nsContentUtils::TrimWhitespace(eventAttr, PR_FALSE);
    if (!StringBeginsWith(event_str, NS_LITERAL_STRING("onload"),
                          nsCaseInsensitiveStringComparator())) {
        // It ain't "onload.*".

        return PR_TRUE;
    }

    nsAutoString::const_iterator start, end;
    event_str.BeginReading(start);
    event_str.EndReading(end);

    start.advance(6); // advance past "onload"

    if (start != end && *start != '(' && *start != ' ') {
        // We got onload followed by something other than space or
        // '('. Not good enough.

        return PR_TRUE;
    }

    return PR_FALSE;
}
/* static */
nsresult
sbURIChecker::CheckPath( nsACString &aPath, nsIURI *aSiteURI )
{
  // aPath may be empty
  NS_ENSURE_ARG_POINTER(aSiteURI);
  LOG(( "sbURIChecker::CheckPath(%s)", aPath.BeginReading() ));

  nsresult rv;

  nsCString fixedSitePath;
  rv = sbURIChecker::FixupPath( aSiteURI, fixedSitePath );
  NS_ENSURE_SUCCESS( rv, rv );

  if ( aPath.IsEmpty() ) {
    // If the path was empty we use aSiteURI that was retrieved from the system.
    aPath.Assign(fixedSitePath);

    // The rest of this function will ensure that the path is actually a subpath
    // of aURI. If nothing was passed in aPath then we already know that this
    // is true because we constructed aPath from aURI. Therefore we're done and
    // can go ahead and return.
    return NS_OK;
  }

  // Compare fixedPath to fixedSitePath to make sure that fixedPath is within
  // fixedSitePath.
  nsCString fixedPath;
  rv = sbURIChecker::FixupPath( aPath, fixedPath );
  NS_ENSURE_SUCCESS( rv, rv );

  // Verify that this path is indeed part of the site URI.
  if ( !StringBeginsWith( fixedSitePath, fixedPath ) ) {
    LOG(("sbURIChecker::CheckPath() -- FAILED Path Prefix Check"));
    return NS_ERROR_FAILURE;
  }

  LOG(("sbURIChecker::CheckPath() -- PASSED Path Prefix Check"));

  aPath.Assign(fixedPath);
  return NS_OK;
}