Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
nsCompactPolicy.cpp File Reference
#include "nsP3PService.h"
#include "nsCompactPolicy.h"
#include "nsNetCID.h"
#include "nsReadableUtils.h"
#include "nsTokenList.h"

Go to the source code of this file.

Defines

#define CP_TOKEN(_token)   #_token,

Functions

static Tokens Lookup (const char *aTag)
static PRBool FindCompactPolicy (nsACString::const_iterator &aStart, nsACString::const_iterator &aEnd)
static const PRInt32 MapTokenToConsent (const nsACString::const_iterator &aStart, const nsACString::const_iterator &aEnd)
static const PRInt32 ParsePolicy (nsACString::const_iterator &aStart, nsACString::const_iterator &aEnd)

Variables

static const char * kTokens []
static nsHashtable * gTokenTable

Define Documentation

#define CP_TOKEN (   _token)    #_token,

Definition at line 44 of file nsCompactPolicy.cpp.


Function Documentation

static PRBool FindCompactPolicy ( nsACString::const_iterator &  aStart,
nsACString::const_iterator &  aEnd 
) [static]

Definition at line 68 of file nsCompactPolicy.cpp.

                                                         {
  PRBool found = PR_FALSE;
  nsACString::const_iterator tmp = aEnd;

  if (CaseInsensitiveFindInReadable(NS_LITERAL_CSTRING("CP"), aStart, tmp)) {
    while (*tmp == ' ' && ++tmp != aEnd); // skip spaces
    
    if (tmp != aEnd && *tmp == '=') {

      while (++tmp != aEnd && *tmp == ' '); // skip spaces
      
      if (tmp != aEnd) {
        aStart = tmp; // Compact policy starts
        found = PR_TRUE;
      }
    }
  }

  return found;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Tokens Lookup ( const char *  aTag) [static]

Definition at line 53 of file nsCompactPolicy.cpp.

{
  Tokens rv = eToken_NULL;
  
  nsCStringKey key(aTag, -1, nsCStringKey::NEVER_OWN);

  void* val = (gTokenTable)? gTokenTable->Get(&key):0;
  if (val) {
    rv = Tokens(NS_PTR_TO_INT32(val));
  }

  return rv;
}

Here is the caller graph for this function:

static const PRInt32 MapTokenToConsent ( const nsACString::const_iterator &  aStart,
const nsACString::const_iterator &  aEnd 
) [static]

Definition at line 91 of file nsCompactPolicy.cpp.

{
  PRInt32 rv = -1;

  if (aStart != aEnd) {
    PRInt32 len = Distance(aStart,aEnd);
    if (len > 2 && len < 5) {
      char  token[5] = {0};
      const char* begin = aStart.get();
      
      memcpy(token,begin,3);
     
      eTokens id = Lookup(token);
      switch (id) {
        case eToken_TST:
        case eToken_NULL: // Token not in CP vocabulary!
          rv = NS_INVALID_POLICY;
          break;
        // Tokens that indicate collection of
        // Personally Identifiable Information
        // without consent.
        case eToken_FIN: 
        case eToken_GOV:
        case eToken_ONL:
        case eToken_PHY:
        case eToken_UNI:
          rv = NS_PII_TOKEN;
          break;
        // Tokens that indicate collection of
        // Personally Identifiable Information 
        // with opt-in, opt-out options.
        case eToken_CON:
        case eToken_DEL:
        case eToken_IVA:
        case eToken_IVD:
        case eToken_OTP:
        case eToken_OTR:
        case eToken_PUB: 
        case eToken_SAM: 
        case eToken_TEL: 
        case eToken_UNR:
          {
            char attr = (len > 3)? *(begin+3):'\0';
            rv = NS_NO_CONSENT; // Tokens with or without attribute 'a'
            if (attr == 'o') {
              rv = NS_IMPLICIT_CONSENT;
            }
            else if (attr == 'i') {
              rv = NS_EXPLICIT_CONSENT;
            }
          }
          break;
        default:
          rv = NS_NON_PII_TOKEN;
          break;
      }
    }
    else {
      rv = NS_INVALID_POLICY;
    }
  }
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static const PRInt32 ParsePolicy ( nsACString::const_iterator &  aStart,
nsACString::const_iterator &  aEnd 
) [static]

Definition at line 157 of file nsCompactPolicy.cpp.

{
  PRInt32 rv = NS_HAS_POLICY;
  
  if (aStart != aEnd) {
    // strip off the begining quote or apostrophe
    const char quoteChar = *aStart;
    if ((quoteChar == '"' || quoteChar == '\'') && ++aStart == aEnd) {
      return NS_NO_POLICY ;
    }

    nsACString::const_iterator tokenStart = aStart;
    while (aStart != aEnd) {
      if (*aStart != ' ' && *aStart != quoteChar) { 
        ++aStart;
      }
      else {
        PRInt32 consent = MapTokenToConsent(tokenStart,aStart);

        if (consent == -1) {
          if (!(rv & (NS_PII_TOKEN  |
                      NS_NO_CONSENT | 
                      NS_IMPLICIT_CONSENT | 
                      NS_EXPLICIT_CONSENT |  
                      NS_NON_PII_TOKEN))) {
            rv = NS_NO_POLICY;
          }
          break;
        }
        else if (consent == NS_INVALID_POLICY) {
          rv = NS_INVALID_POLICY;
          break;
        }
        else {
          rv |= consent;
          if (consent & NS_PII_TOKEN) {
            if (rv & NS_NO_CONSENT) {
              // PII is collected without consent.
              // No need to parse CP any further.
              break;
            }
          }
          else if (consent & NS_NO_CONSENT) {
            rv &= ~(NS_IMPLICIT_CONSENT | NS_EXPLICIT_CONSENT);
            if (rv & NS_PII_TOKEN) {
              // PII is collected without consent.
              // No need to parse CP any further.
              break;
            }
          }
          else if (consent & NS_IMPLICIT_CONSENT) {
            rv &= ~NS_EXPLICIT_CONSENT;
            if (rv & NS_NO_CONSENT) {
              rv &= ~NS_IMPLICIT_CONSENT;
            }
          }
          else if (consent & NS_EXPLICIT_CONSENT) {
            if (rv & (NS_NO_CONSENT | NS_IMPLICIT_CONSENT)) {
              rv &= ~NS_EXPLICIT_CONSENT;
            }
          }
          
          if (*aStart == quoteChar) {
            break; // done parsing CP
          }
         
          while (++aStart != aEnd && *aStart == ' '); // skip spaces
          tokenStart = aStart;
        }
      }
    }

    if (rv & NS_PII_TOKEN) {
      if (!(rv & (NS_NO_CONSENT | NS_IMPLICIT_CONSENT | NS_EXPLICIT_CONSENT))) {
        // CP did not contain any information about opt-in / opt-out
        rv = NS_NO_CONSENT; 
      }
    }
    else {
      // If a PII token is not present, in the CP, we can be sure
      // that no personally identifiable information is collected.
      if (rv & (NS_NO_CONSENT | NS_IMPLICIT_CONSENT | NS_EXPLICIT_CONSENT)) {
        rv = NS_NON_PII_TOKEN; // PII not collected.
      }
    }
  }
   
  NS_ASSERTION(rv > NS_HAS_POLICY,"compact policy error");
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

nsHashtable* gTokenTable [static]

Definition at line 50 of file nsCompactPolicy.cpp.

const char* kTokens[] [static]

Definition at line 45 of file nsCompactPolicy.cpp.