Sat, 03 Jan 2015 20:18:00 +0100
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.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (c) 1999 |
michael@0 | 3 | * Silicon Graphics Computer Systems, Inc. |
michael@0 | 4 | * |
michael@0 | 5 | * Copyright (c) 1999 |
michael@0 | 6 | * Boris Fomitchev |
michael@0 | 7 | * |
michael@0 | 8 | * This material is provided "as is", with absolutely no warranty expressed |
michael@0 | 9 | * or implied. Any use is at your own risk. |
michael@0 | 10 | * |
michael@0 | 11 | * Permission to use or copy this software for any purpose is hereby granted |
michael@0 | 12 | * without fee, provided the above notices are retained on all copies. |
michael@0 | 13 | * Permission to modify the code and to distribute modified code is granted, |
michael@0 | 14 | * provided the above notices are retained, and a notice that the code was |
michael@0 | 15 | * modified is included with the above copyright notice. |
michael@0 | 16 | * |
michael@0 | 17 | */ |
michael@0 | 18 | #include "stlport_prefix.h" |
michael@0 | 19 | |
michael@0 | 20 | #include <typeinfo> |
michael@0 | 21 | |
michael@0 | 22 | #include "message_facets.h" |
michael@0 | 23 | #include "acquire_release.h" |
michael@0 | 24 | |
michael@0 | 25 | _STLP_BEGIN_NAMESPACE |
michael@0 | 26 | |
michael@0 | 27 | _STLP_MOVE_TO_PRIV_NAMESPACE |
michael@0 | 28 | |
michael@0 | 29 | void _Catalog_locale_map::insert(nl_catd_type key, const locale& L) { |
michael@0 | 30 | _STLP_TRY { |
michael@0 | 31 | #if !defined (_STLP_NO_TYPEINFO) && !defined (_STLP_NO_RTTI) |
michael@0 | 32 | // Don't bother to do anything unless we're using a non-default ctype facet |
michael@0 | 33 | # ifdef _STLP_NO_WCHAR_T |
michael@0 | 34 | typedef char _Char; |
michael@0 | 35 | # else |
michael@0 | 36 | typedef wchar_t _Char; |
michael@0 | 37 | # endif |
michael@0 | 38 | |
michael@0 | 39 | typedef ctype<_Char> wctype; |
michael@0 | 40 | wctype const& wct = use_facet<wctype>(L); |
michael@0 | 41 | if (typeid(wct) != typeid(wctype)) { |
michael@0 | 42 | #endif |
michael@0 | 43 | if (!M) |
michael@0 | 44 | M = new map_type; |
michael@0 | 45 | |
michael@0 | 46 | M->insert(map_type::value_type(key, L)); |
michael@0 | 47 | #if !defined (_STLP_NO_TYPEINFO) && !defined (_STLP_NO_RTTI) |
michael@0 | 48 | } |
michael@0 | 49 | #endif |
michael@0 | 50 | } |
michael@0 | 51 | _STLP_CATCH_ALL {} |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | void _Catalog_locale_map::erase(nl_catd_type key) { |
michael@0 | 55 | if (M) |
michael@0 | 56 | M->erase(key); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | locale _Catalog_locale_map::lookup(nl_catd_type key) const { |
michael@0 | 60 | if (M) { |
michael@0 | 61 | map_type::const_iterator i = M->find(key); |
michael@0 | 62 | return i != M->end() ? (*i).second : locale::classic(); |
michael@0 | 63 | } |
michael@0 | 64 | else |
michael@0 | 65 | return locale::classic(); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | |
michael@0 | 69 | #if defined (_STLP_USE_NL_CATD_MAPPING) |
michael@0 | 70 | _STLP_VOLATILE __stl_atomic_t _Catalog_nl_catd_map::_count = 0; |
michael@0 | 71 | |
michael@0 | 72 | messages_base::catalog _Catalog_nl_catd_map::insert(nl_catd_type cat) { |
michael@0 | 73 | messages_base::catalog &res = Mr[cat]; |
michael@0 | 74 | if ( res == 0 ) { |
michael@0 | 75 | #if defined (_STLP_ATOMIC_INCREMENT) |
michael@0 | 76 | res = __STATIC_CAST(int, _STLP_ATOMIC_INCREMENT(&_count)); |
michael@0 | 77 | #else |
michael@0 | 78 | static _STLP_STATIC_MUTEX _Count_lock _STLP_MUTEX_INITIALIZER; |
michael@0 | 79 | { |
michael@0 | 80 | _STLP_auto_lock sentry(_Count_lock); |
michael@0 | 81 | res = __STATIC_CAST(int, ++_count); |
michael@0 | 82 | } |
michael@0 | 83 | #endif |
michael@0 | 84 | M[res] = cat; |
michael@0 | 85 | } |
michael@0 | 86 | return res; |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | void _Catalog_nl_catd_map::erase(messages_base::catalog cat) { |
michael@0 | 90 | map_type::iterator mit(M.find(cat)); |
michael@0 | 91 | if (mit != M.end()) { |
michael@0 | 92 | Mr.erase((*mit).second); |
michael@0 | 93 | M.erase(mit); |
michael@0 | 94 | } |
michael@0 | 95 | } |
michael@0 | 96 | #endif |
michael@0 | 97 | |
michael@0 | 98 | //---------------------------------------------------------------------- |
michael@0 | 99 | // |
michael@0 | 100 | _Messages::_Messages(bool is_wide, const char *name) : |
michael@0 | 101 | _M_message_obj(0), _M_map(0) { |
michael@0 | 102 | if (!name) |
michael@0 | 103 | locale::_M_throw_on_null_name(); |
michael@0 | 104 | |
michael@0 | 105 | int __err_code; |
michael@0 | 106 | char buf[_Locale_MAX_SIMPLE_NAME]; |
michael@0 | 107 | _M_message_obj = _STLP_PRIV __acquire_messages(name, buf, 0, &__err_code); |
michael@0 | 108 | if (!_M_message_obj) |
michael@0 | 109 | locale::_M_throw_on_creation_failure(__err_code, name, "messages"); |
michael@0 | 110 | |
michael@0 | 111 | if (is_wide) |
michael@0 | 112 | _M_map = new _Catalog_locale_map; |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | _Messages::_Messages(bool is_wide, _Locale_messages* msg) : |
michael@0 | 116 | _M_message_obj(msg), _M_map(is_wide ? new _Catalog_locale_map() : 0) |
michael@0 | 117 | {} |
michael@0 | 118 | |
michael@0 | 119 | _Messages::~_Messages() { |
michael@0 | 120 | __release_messages(_M_message_obj); |
michael@0 | 121 | delete _M_map; |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | _Messages::catalog _Messages::do_open(const string& filename, const locale& L) const { |
michael@0 | 125 | nl_catd_type result = _M_message_obj ? _Locale_catopen(_M_message_obj, filename.c_str()) |
michael@0 | 126 | : (nl_catd_type)(-1); |
michael@0 | 127 | |
michael@0 | 128 | if ( result != (nl_catd_type)(-1) ) { |
michael@0 | 129 | if ( _M_map != 0 ) { |
michael@0 | 130 | _M_map->insert(result, L); |
michael@0 | 131 | } |
michael@0 | 132 | return _STLP_MUTABLE(_Messages_impl, _M_cat).insert( result ); |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | return -1; |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | string _Messages::do_get(catalog cat, |
michael@0 | 139 | int set, int p_id, const string& dfault) const { |
michael@0 | 140 | return _M_message_obj != 0 && cat >= 0 |
michael@0 | 141 | ? string(_Locale_catgets(_M_message_obj, _STLP_MUTABLE(_Messages_impl, _M_cat)[cat], |
michael@0 | 142 | set, p_id, dfault.c_str())) |
michael@0 | 143 | : dfault; |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | #if !defined (_STLP_NO_WCHAR_T) |
michael@0 | 147 | |
michael@0 | 148 | wstring |
michael@0 | 149 | _Messages::do_get(catalog thecat, |
michael@0 | 150 | int set, int p_id, const wstring& dfault) const { |
michael@0 | 151 | typedef ctype<wchar_t> wctype; |
michael@0 | 152 | const wctype& ct = use_facet<wctype>(_M_map->lookup(_STLP_MUTABLE(_Messages_impl, _M_cat)[thecat])); |
michael@0 | 153 | |
michael@0 | 154 | const char* str = _Locale_catgets(_M_message_obj, _STLP_MUTABLE(_Messages_impl, _M_cat)[thecat], set, p_id, ""); |
michael@0 | 155 | |
michael@0 | 156 | // Verify that the lookup failed; an empty string might represent success. |
michael@0 | 157 | if (!str) |
michael@0 | 158 | return dfault; |
michael@0 | 159 | else if (str[0] == '\0') { |
michael@0 | 160 | const char* str2 = _Locale_catgets(_M_message_obj, _STLP_MUTABLE(_Messages_impl, _M_cat)[thecat], set, p_id, "*"); |
michael@0 | 161 | if (!str2 || ((str2[0] == '*') && (str2[1] == '\0'))) |
michael@0 | 162 | return dfault; |
michael@0 | 163 | } |
michael@0 | 164 | |
michael@0 | 165 | // str is correct. Now we must widen it to get a wstring. |
michael@0 | 166 | size_t n = strlen(str); |
michael@0 | 167 | |
michael@0 | 168 | // NOT PORTABLE. What we're doing relies on internal details of the |
michael@0 | 169 | // string implementation. (Contiguity of string elements.) |
michael@0 | 170 | wstring result(n, wchar_t(0)); |
michael@0 | 171 | ct.widen(str, str + n, &*result.begin()); |
michael@0 | 172 | return result; |
michael@0 | 173 | } |
michael@0 | 174 | |
michael@0 | 175 | #endif |
michael@0 | 176 | |
michael@0 | 177 | void _Messages::do_close(catalog thecat) const { |
michael@0 | 178 | if (_M_message_obj) |
michael@0 | 179 | _Locale_catclose(_M_message_obj, _STLP_MUTABLE(_Messages_impl, _M_cat)[thecat]); |
michael@0 | 180 | if (_M_map) _M_map->erase(_STLP_MUTABLE(_Messages_impl, _M_cat)[thecat]); |
michael@0 | 181 | _STLP_MUTABLE(_Messages_impl, _M_cat).erase( thecat ); |
michael@0 | 182 | } |
michael@0 | 183 | |
michael@0 | 184 | _STLP_MOVE_TO_STD_NAMESPACE |
michael@0 | 185 | |
michael@0 | 186 | //---------------------------------------------------------------------- |
michael@0 | 187 | // messages<char> |
michael@0 | 188 | messages<char>::messages(size_t refs) |
michael@0 | 189 | : locale::facet(refs) {} |
michael@0 | 190 | |
michael@0 | 191 | messages_byname<char>::messages_byname(const char *name, size_t refs) |
michael@0 | 192 | : messages<char>(refs), _M_impl(new _STLP_PRIV _Messages(false, name)) {} |
michael@0 | 193 | |
michael@0 | 194 | messages_byname<char>::messages_byname(_Locale_messages* msg) |
michael@0 | 195 | : messages<char>(0), _M_impl(new _STLP_PRIV _Messages(false, msg)) {} |
michael@0 | 196 | |
michael@0 | 197 | messages_byname<char>::~messages_byname() |
michael@0 | 198 | { delete _M_impl; } |
michael@0 | 199 | |
michael@0 | 200 | messages_byname<char>::catalog |
michael@0 | 201 | messages_byname<char>::do_open(const string& filename, const locale& l) const |
michael@0 | 202 | { return _M_impl->do_open(filename, l); } |
michael@0 | 203 | |
michael@0 | 204 | string |
michael@0 | 205 | messages_byname<char>::do_get(catalog cat, int set, int p_id, |
michael@0 | 206 | const string& dfault) const |
michael@0 | 207 | { return _M_impl->do_get(cat, set, p_id, dfault); } |
michael@0 | 208 | |
michael@0 | 209 | void messages_byname<char>::do_close(catalog cat) const |
michael@0 | 210 | { _M_impl->do_close(cat); } |
michael@0 | 211 | |
michael@0 | 212 | #if !defined (_STLP_NO_WCHAR_T) |
michael@0 | 213 | |
michael@0 | 214 | //---------------------------------------------------------------------- |
michael@0 | 215 | // messages<wchar_t> |
michael@0 | 216 | |
michael@0 | 217 | messages<wchar_t>::messages(size_t refs) |
michael@0 | 218 | : locale::facet(refs) {} |
michael@0 | 219 | |
michael@0 | 220 | messages_byname<wchar_t>::messages_byname(const char *name, size_t refs) |
michael@0 | 221 | : messages<wchar_t>(refs), _M_impl(new _STLP_PRIV _Messages(true, name)) {} |
michael@0 | 222 | |
michael@0 | 223 | messages_byname<wchar_t>::messages_byname(_Locale_messages* msg) |
michael@0 | 224 | : messages<wchar_t>(0), _M_impl(new _STLP_PRIV _Messages(true, msg)) {} |
michael@0 | 225 | |
michael@0 | 226 | messages_byname<wchar_t>::~messages_byname() |
michael@0 | 227 | { delete _M_impl; } |
michael@0 | 228 | |
michael@0 | 229 | messages_byname<wchar_t>::catalog |
michael@0 | 230 | messages_byname<wchar_t>::do_open(const string& filename, const locale& L) const |
michael@0 | 231 | { return _M_impl->do_open(filename, L); } |
michael@0 | 232 | |
michael@0 | 233 | wstring |
michael@0 | 234 | messages_byname<wchar_t>::do_get(catalog thecat, |
michael@0 | 235 | int set, int p_id, const wstring& dfault) const |
michael@0 | 236 | { return _M_impl->do_get(thecat, set, p_id, dfault); } |
michael@0 | 237 | |
michael@0 | 238 | void messages_byname<wchar_t>::do_close(catalog cat) const |
michael@0 | 239 | { _M_impl->do_close(cat); } |
michael@0 | 240 | |
michael@0 | 241 | #endif |
michael@0 | 242 | |
michael@0 | 243 | _STLP_END_NAMESPACE |
michael@0 | 244 | |
michael@0 | 245 | // Local Variables: |
michael@0 | 246 | // mode:C++ |
michael@0 | 247 | // End: |