intl/icu/source/common/ucat.c

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

mercurial