bool
nsPreflightCache::CacheEntry::CheckRequest(const nsCString& aMethod,
        const nsTArray<nsCString>& aHeaders)
{
    PurgeExpired(TimeStamp::NowLoRes());

    if (!aMethod.EqualsLiteral("GET") && !aMethod.EqualsLiteral("POST")) {
        uint32_t i;
        for (i = 0; i < mMethods.Length(); ++i) {
            if (aMethod.Equals(mMethods[i].token))
                break;
        }
        if (i == mMethods.Length()) {
            return false;
        }
    }

    for (uint32_t i = 0; i < aHeaders.Length(); ++i) {
        uint32_t j;
        for (j = 0; j < mHeaders.Length(); ++j) {
            if (aHeaders[i].Equals(mHeaders[j].token,
                                   nsCaseInsensitiveCStringComparator())) {
                break;
            }
        }
        if (j == mHeaders.Length()) {
            return false;
        }
    }

    return true;
}
void nsEudoraAddress::ResolveEntries( nsCString& name, nsVoidArray& list,
                                     nsVoidArray& result, PRBool addResolvedEntries,
                                     PRBool wasResolved, PRInt32& numResolved)
{
    /* a safe-guard against recursive entries */
    if (result.Count() > m_alias.Count())
        return;

    PRInt32         max = list.Count();
    PRInt32         i;
    CAliasData *    pData;
    CAliasEntry *   pEntry;
    for (i = 0; i < max; i++) {
        pData = (CAliasData *)list.ElementAt( i);
        // resolve the email to an existing alias!
        if ( !name.Equals(pData->m_email, nsCaseInsensitiveCStringComparator()) &&
             ((pEntry = ResolveAlias( pData->m_fullEntry)) != nsnull) ) {
            // This new entry has all of the entries for this puppie.
            // Resolve all of it's entries!
            numResolved++;  // Track the number of entries resolved

            // We pass in PR_TRUE for the 5th parameter so that we know that we're
            // calling ourselves recursively.
            ResolveEntries( pEntry->m_name, pEntry->m_list, result, addResolvedEntries, PR_TRUE, numResolved);
        }
        else if (addResolvedEntries || !wasResolved) {
            // This is either an ordinary entry (i.e. just contains the info) or we were told
            // to add resolved alias entries.
            result.AppendElement( pData);
        }
    }
}
PRBool
nsPreflightCache::CacheEntry::CheckRequest(const nsCString& aMethod,
                                           const nsTArray<nsCString>& aHeaders)
{
  PurgeExpired(PR_Now());

  if (!aMethod.EqualsLiteral("GET") && !aMethod.EqualsLiteral("POST")) {
    PRUint32 i;
    for (i = 0; i < mMethods.Length(); ++i) {
      if (aMethod.Equals(mMethods[i].token))
        break;
    }
    if (i == mMethods.Length()) {
      return PR_FALSE;
    }
  }

  for (PRUint32 i = 0; i < aHeaders.Length(); ++i) {
    PRUint32 j;
    for (j = 0; j < mHeaders.Length(); ++j) {
      if (aHeaders[i].Equals(mHeaders[j].token,
                             nsCaseInsensitiveCStringComparator())) {
        break;
      }
    }
    if (j == mHeaders.Length()) {
      return PR_FALSE;
    }
  }

  return PR_TRUE;
}
Example #4
0
void nsEudoraAddress::ResolveEntries( nsCString& name, nsVoidArray& list, nsVoidArray& result)
{
	/* a safe-guard against recursive entries */
	if (result.Count() > m_alias.Count())
		return;
		
	PRInt32			max = list.Count();
	PRInt32			i;
	CAliasData *	pData;
	CAliasEntry *	pEntry;
	for (i = 0; i < max; i++) {
		pData = (CAliasData *)list.ElementAt( i);
		// resolve the email to an existing alias!
		if (!name.Equals( pData->m_email,
                          nsCaseInsensitiveCStringComparator()) &&
            ((pEntry = ResolveAlias( pData->m_email)) != nsnull)) {
			// This new entry has all of the entries for this puppie.
			// Resolve all of it's entries!
			ResolveEntries( pEntry->m_name, pEntry->m_list, result);
		}
		else {
			result.AppendElement( pData);
		}
	}
}
Example #5
0
  void TestGetNodeId_Continuation(nsCString aNodeId1) {
    EXPECT_TRUE(IsCDMStorageIsEmpty());

    // Once we clear storage, the node ids generated for the same origin-pair
    // should be different.
    const nsString origin1 = NS_LITERAL_STRING("http://example1.com");
    const nsString origin2 = NS_LITERAL_STRING("http://example2.org");
    nsCString nodeId3 = GetNodeId(origin1, origin2, false);
    EXPECT_TRUE(!aNodeId1.Equals(nodeId3));

    SetFinished();
  }
Example #6
0
void
SetTimezone(const nsCString& aTimezoneSpec)
{
  if (aTimezoneSpec.Equals(GetTimezone())) {
    return;
  }

  property_set("persist.sys.timezone", aTimezoneSpec.get());
  // this function is automatically called by the other time conversion
  // functions that depend on the timezone. To be safe, we call it manually.
  tzset();
  hal::NotifySystemTimeChange(hal::SYS_TIME_CHANGE_TZ);
}
Example #7
0
    GMPErr Read(const nsCString& aRecordName,
                nsTArray<uint8_t>& aOutBytes) override
    {
        if (!IsOpen(aRecordName)) {
            return GMPClosedErr;
        }

        Record* record = nullptr;
        mRecords.Get(aRecordName, &record);
        MOZ_ASSERT(record && !!record->mFileDesc); // IsOpen() guarantees this.

        // Our error strategy is to report records with invalid contents as
        // containing 0 bytes. Zero length records are considered "deleted" by
        // the GMPStorage API.
        aOutBytes.SetLength(0);

        int32_t recordLength = 0;
        nsCString recordName;
        nsresult err = ReadRecordMetadata(record->mFileDesc,
                                          recordLength,
                                          recordName);
        if (NS_FAILED(err) || recordLength == 0) {
            // We failed to read the record metadata. Or the record is 0 length.
            // Treat damaged records as empty.
            // ReadRecordMetadata() could fail if the GMP opened a new record and
            // tried to read it before anything was written to it..
            return GMPNoErr;
        }

        if (!aRecordName.Equals(recordName)) {
            NS_WARNING("Record file contains some other record's contents!");
            return GMPRecordCorrupted;
        }

        // After calling ReadRecordMetadata, we should be ready to read the
        // record data.
        if (PR_Available(record->mFileDesc) != recordLength) {
            NS_WARNING("Record file length mismatch!");
            return GMPRecordCorrupted;
        }

        aOutBytes.SetLength(recordLength);
        int32_t bytesRead = PR_Read(record->mFileDesc, aOutBytes.Elements(), recordLength);
        return (bytesRead == recordLength) ? GMPNoErr : GMPRecordCorrupted;
    }
Example #8
0
bool
ContentChild::RecvNotifyAlertsObserver(const nsCString& aType, const nsString& aData)
{
    for (PRUint32 i = 0; i < mAlertObservers.Length();
         /*we mutate the array during the loop; ++i iff no mutation*/) {
        AlertObserver* observer = mAlertObservers[i];
        if (observer->Observes(aData) && observer->Notify(aType)) {
            // if aType == alertfinished, this alert is done.  we can
            // remove the observer.
            if (aType.Equals(nsDependentCString("alertfinished"))) {
                mAlertObservers.RemoveElementAt(i);
                continue;
            }
        }
        ++i;
    }
    return true;
}
nsresult
nsCORSPreflightListener::CheckPreflightRequestApproved(nsIRequest* aRequest)
{
  nsresult status;
  nsresult rv = aRequest->GetStatus(&status);
  NS_ENSURE_SUCCESS(rv, rv);
  NS_ENSURE_SUCCESS(status, status);

  // Test that things worked on a HTTP level
  nsCOMPtr<nsIHttpChannel> http = do_QueryInterface(aRequest);
  nsCOMPtr<nsIHttpChannelInternal> internal = do_QueryInterface(aRequest);
  NS_ENSURE_STATE(internal);

  bool succeedded;
  rv = http->GetRequestSucceeded(&succeedded);
  if (NS_FAILED(rv) || !succeedded) {
    LogBlockedRequest(aRequest, "CORSPreflightDidNotSucceed", nullptr);
    return NS_ERROR_DOM_BAD_URI;
  }

  nsAutoCString headerVal;
  // The "Access-Control-Allow-Methods" header contains a comma separated
  // list of method names.
  http->GetResponseHeader(NS_LITERAL_CSTRING("Access-Control-Allow-Methods"),
                          headerVal);
  bool foundMethod = mPreflightMethod.EqualsLiteral("GET") ||
                       mPreflightMethod.EqualsLiteral("HEAD") ||
                       mPreflightMethod.EqualsLiteral("POST");
  nsCCharSeparatedTokenizer methodTokens(headerVal, ',');
  while(methodTokens.hasMoreTokens()) {
    const nsDependentCSubstring& method = methodTokens.nextToken();
    if (method.IsEmpty()) {
      continue;
    }
    if (!NS_IsValidHTTPToken(method)) {
      LogBlockedRequest(aRequest, "CORSInvalidAllowMethod",
                        NS_ConvertUTF8toUTF16(method).get());
      return NS_ERROR_DOM_BAD_URI;
    }
    foundMethod |= mPreflightMethod.Equals(method);
  }
  if (!foundMethod) {
    LogBlockedRequest(aRequest, "CORSMethodNotFound", nullptr);
    return NS_ERROR_DOM_BAD_URI;
  }

  // The "Access-Control-Allow-Headers" header contains a comma separated
  // list of header names.
  http->GetResponseHeader(NS_LITERAL_CSTRING("Access-Control-Allow-Headers"),
                          headerVal);
  nsTArray<nsCString> headers;
  nsCCharSeparatedTokenizer headerTokens(headerVal, ',');
  while(headerTokens.hasMoreTokens()) {
    const nsDependentCSubstring& header = headerTokens.nextToken();
    if (header.IsEmpty()) {
      continue;
    }
    if (!NS_IsValidHTTPToken(header)) {
      LogBlockedRequest(aRequest, "CORSInvalidAllowHeader",
                        NS_ConvertUTF8toUTF16(header).get());
      return NS_ERROR_DOM_BAD_URI;
    }
    headers.AppendElement(header);
  }
  for (uint32_t i = 0; i < mPreflightHeaders.Length(); ++i) {
    if (!headers.Contains(mPreflightHeaders[i],
                          nsCaseInsensitiveCStringArrayComparator())) {
      LogBlockedRequest(aRequest, "CORSMissingAllowHeaderFromPreflight",
                        NS_ConvertUTF8toUTF16(mPreflightHeaders[i]).get());
      return NS_ERROR_DOM_BAD_URI;
    }
  }

  return NS_OK;
}
Example #10
0
bool nsMsgFilterList::StrToBool(nsCString &str)
{
  return str.Equals("yes") ;
}
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;
}
static inline bool
IsEndOfMessage(const nsCString &aLine)
{
  return aLine.Equals(".");
}
static
nsresult
UpdateAttendee(calIEvent * e,
               ews_calendar_item * item,
               const nsCString & ownerEmail,
               bool required) {
	int c = 0;
	ews_attendee ** attendees = NULL;
	nsresult rv = NS_OK;

	if (required) {
		c = item->required_attendees_count;
		attendees = item->required_attendees;
	} else {
		c = item->optional_attendees_count;
		attendees = item->optional_attendees;
	}

	if (c == 0 || !attendees)
		return NS_OK;

	for(int i=0;i < c;i++) {
		nsCOMPtr<calIAttendee> a =
				do_CreateInstance(CAL_ATTENDEE_CONTRACTID, &rv);
		NS_ENSURE_SUCCESS(rv, rv);

		nsCString id;
		
		if (attendees[i]->email_address.routing_type &&
		    !strcmp(attendees[i]->email_address.routing_type, "EX")) {
			id.AppendLiteral("ldap:");
		} else {
			id.AppendLiteral("mailto:");
		}
		id.AppendLiteral(attendees[i]->email_address.email);
		rv = a->SetId(id);
		NS_ENSURE_SUCCESS(rv, rv);

		rv = a->SetRsvp(nsCString("FALSE"));
		NS_ENSURE_SUCCESS(rv, rv);

		rv = a->SetUserType(nsCString("INDIVIDUAL"));
		NS_ENSURE_SUCCESS(rv, rv);

		rv = a->SetRole(nsCString(required ? "REQ-PARTICIPANT" : "OPT-PARTICIPANT"));
		NS_ENSURE_SUCCESS(rv, rv);

		nsCString name;
		if (attendees[i]->email_address.name) {
			name.AssignLiteral(attendees[i]->email_address.name);
		}
		
		rv = a->SetCommonName(name);
		NS_ENSURE_SUCCESS(rv, rv);

        nsCString status;

        if (ownerEmail.Equals(nsCString(attendees[i]->email_address.email),
                              nsCaseInsensitiveCStringComparator())) {
            status.AssignLiteral(participationArray[item->my_response_type]);
        } else {
            status.AssignLiteral(participationArray[attendees[i]->response_type]);
        }
                              
		rv = a->SetParticipationStatus(status);
		NS_ENSURE_SUCCESS(rv, rv);

		rv = e->AddAttendee(a);
		NS_ENSURE_SUCCESS(rv, rv);
	}
	
	return NS_OK;
}