toolkit/crashreporter/google-breakpad/src/common/mac/SimpleStringDictionary.mm

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 // Copyright (c) 2007, Google Inc.
     2 // All rights reserved.
     3 //
     4 // Redistribution and use in source and binary forms, with or without
     5 // modification, are permitted provided that the following conditions are
     6 // met:
     7 //
     8 //     * Redistributions of source code must retain the above copyright
     9 // notice, this list of conditions and the following disclaimer.
    10 //     * Redistributions in binary form must reproduce the above
    11 // copyright notice, this list of conditions and the following disclaimer
    12 // in the documentation and/or other materials provided with the
    13 // distribution.
    14 //     * Neither the name of Google Inc. nor the names of its
    15 // contributors may be used to endorse or promote products derived from
    16 // this software without specific prior written permission.
    17 //
    18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    29 //
    30 //  SimpleStringDictionary.mm
    31 //  Simple string dictionary that does not allocate memory
    32 //
    34 #include <assert.h>
    36 #import "SimpleStringDictionary.h"
    38 namespace google_breakpad {
    40 //==============================================================================
    41 const KeyValueEntry *SimpleStringDictionary::GetEntry(int i) const {
    42   return (i >= 0 && i < MAX_NUM_ENTRIES) ? &entries_[i] : NULL;
    43 }
    45 //==============================================================================
    46 int SimpleStringDictionary::GetCount() const {
    47   int count = 0;
    48   for (int i = 0; i < MAX_NUM_ENTRIES; ++i) {
    49     if (entries_[i].IsActive() ) {
    50       ++count;
    51     }
    52   }
    54   return count;
    55 }
    57 //==============================================================================
    58 const char *SimpleStringDictionary::GetValueForKey(const char *key) const {
    59   assert(key);
    60   if (!key)
    61     return NULL;
    63   for (int i = 0; i < MAX_NUM_ENTRIES; ++i) {
    64     const KeyValueEntry &entry = entries_[i];
    65     if (entry.IsActive() && !strcmp(entry.GetKey(), key)) {
    66       return entry.GetValue();
    67     }
    68   }
    70   return NULL;
    71 }
    73 //==============================================================================
    74 void SimpleStringDictionary::SetKeyValue(const char *key,
    75                                          const char *value) {
    76   if (!value) {
    77     RemoveKey(key);
    78     return;
    79   }
    81   // key must not be NULL
    82   assert(key);
    83   if (!key)
    84     return;
    86   // key must not be empty string
    87   assert(key[0] != '\0');
    88   if (key[0] == '\0')
    89     return;
    91   int free_index = -1;
    93   // check if key already exists
    94   for (int i = 0; i < MAX_NUM_ENTRIES; ++i) {
    95     KeyValueEntry &entry = entries_[i];
    97     if (entry.IsActive()) {
    98       if (!strcmp(entry.GetKey(), key)) {
    99         entry.SetValue(value);
   100         return;
   101       }
   102     } else {
   103       // Make a note of an empty slot
   104       if (free_index == -1) {
   105         free_index = i;
   106       }
   107     }
   108   }
   110   // check if we've run out of space
   111   assert(free_index != -1);
   113   // Put new key into an empty slot (if found)
   114   if (free_index != -1) {
   115     entries_[free_index].SetKeyValue(key, value);
   116   }
   117 }
   119 //==============================================================================
   120 void SimpleStringDictionary::RemoveKey(const char *key) {
   121   assert(key);
   122   if (!key)
   123     return;
   125   for (int i = 0; i < MAX_NUM_ENTRIES; ++i) {
   126     if (!strcmp(entries_[i].GetKey(), key)) {
   127       entries_[i].Clear();
   128       return;
   129     }
   130   }
   131 }
   133 }  // namespace google_breakpad

mercurial