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 | ********************************************************************** |
michael@0 | 3 | * Copyright (c) 2003, International Business Machines |
michael@0 | 4 | * Corporation and others. All Rights Reserved. |
michael@0 | 5 | ********************************************************************** |
michael@0 | 6 | * Author: Alan Liu |
michael@0 | 7 | * Created: March 19 2003 |
michael@0 | 8 | * Since: ICU 2.6 |
michael@0 | 9 | ********************************************************************** |
michael@0 | 10 | */ |
michael@0 | 11 | #include "unicode/ucat.h" |
michael@0 | 12 | #include "unicode/ustring.h" |
michael@0 | 13 | #include "cstring.h" |
michael@0 | 14 | #include "uassert.h" |
michael@0 | 15 | |
michael@0 | 16 | /* Separator between set_num and msg_num */ |
michael@0 | 17 | static const char SEPARATOR = '%'; |
michael@0 | 18 | |
michael@0 | 19 | /* Maximum length of a set_num/msg_num key, incl. terminating zero. |
michael@0 | 20 | * Longest possible key is "-2147483648%-2147483648" */ |
michael@0 | 21 | #define MAX_KEY_LEN (24) |
michael@0 | 22 | |
michael@0 | 23 | /** |
michael@0 | 24 | * Fill in buffer with a set_num/msg_num key string, given the numeric |
michael@0 | 25 | * values. Numeric values must be >= 0. Buffer must be of length |
michael@0 | 26 | * MAX_KEY_LEN or more. |
michael@0 | 27 | */ |
michael@0 | 28 | static char* |
michael@0 | 29 | _catkey(char* buffer, int32_t set_num, int32_t msg_num) { |
michael@0 | 30 | int32_t i = 0; |
michael@0 | 31 | i = T_CString_integerToString(buffer, set_num, 10); |
michael@0 | 32 | buffer[i++] = SEPARATOR; |
michael@0 | 33 | T_CString_integerToString(buffer+i, msg_num, 10); |
michael@0 | 34 | return buffer; |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | U_CAPI u_nl_catd U_EXPORT2 |
michael@0 | 38 | u_catopen(const char* name, const char* locale, UErrorCode* ec) { |
michael@0 | 39 | return (u_nl_catd) ures_open(name, locale, ec); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | U_CAPI void U_EXPORT2 |
michael@0 | 43 | u_catclose(u_nl_catd catd) { |
michael@0 | 44 | ures_close((UResourceBundle*) catd); /* may be NULL */ |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | U_CAPI const UChar* U_EXPORT2 |
michael@0 | 48 | u_catgets(u_nl_catd catd, int32_t set_num, int32_t msg_num, |
michael@0 | 49 | const UChar* s, |
michael@0 | 50 | int32_t* len, UErrorCode* ec) { |
michael@0 | 51 | |
michael@0 | 52 | char key[MAX_KEY_LEN]; |
michael@0 | 53 | const UChar* result; |
michael@0 | 54 | |
michael@0 | 55 | if (ec == NULL || U_FAILURE(*ec)) { |
michael@0 | 56 | goto ERROR; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | result = ures_getStringByKey((const UResourceBundle*) catd, |
michael@0 | 60 | _catkey(key, set_num, msg_num), |
michael@0 | 61 | len, ec); |
michael@0 | 62 | if (U_FAILURE(*ec)) { |
michael@0 | 63 | goto ERROR; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | return result; |
michael@0 | 67 | |
michael@0 | 68 | ERROR: |
michael@0 | 69 | /* In case of any failure, return s */ |
michael@0 | 70 | if (len != NULL) { |
michael@0 | 71 | *len = u_strlen(s); |
michael@0 | 72 | } |
michael@0 | 73 | return s; |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | /*eof*/ |