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) 2000-2011, International Business Machines |
michael@0 | 4 | * Corporation and others. All Rights Reserved. |
michael@0 | 5 | ********************************************************************** |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #ifndef URESIMP_H |
michael@0 | 9 | #define URESIMP_H |
michael@0 | 10 | |
michael@0 | 11 | #include "unicode/ures.h" |
michael@0 | 12 | |
michael@0 | 13 | #include "uresdata.h" |
michael@0 | 14 | |
michael@0 | 15 | #define kRootLocaleName "root" |
michael@0 | 16 | #define kPoolBundleName "pool" |
michael@0 | 17 | |
michael@0 | 18 | /* |
michael@0 | 19 | The default minor version and the version separator must be exactly one |
michael@0 | 20 | character long. |
michael@0 | 21 | */ |
michael@0 | 22 | |
michael@0 | 23 | #define kDefaultMinorVersion "0" |
michael@0 | 24 | #define kVersionSeparator "." |
michael@0 | 25 | #define kVersionTag "Version" |
michael@0 | 26 | |
michael@0 | 27 | #define MAGIC1 19700503 |
michael@0 | 28 | #define MAGIC2 19641227 |
michael@0 | 29 | |
michael@0 | 30 | #define URES_MAX_ALIAS_LEVEL 256 |
michael@0 | 31 | #define URES_MAX_BUFFER_SIZE 256 |
michael@0 | 32 | |
michael@0 | 33 | #define EMPTY_SET 0x2205 |
michael@0 | 34 | |
michael@0 | 35 | /* |
michael@0 | 36 | enum UResEntryType { |
michael@0 | 37 | ENTRY_OK = 0, |
michael@0 | 38 | ENTRY_GOTO_ROOT = 1, |
michael@0 | 39 | ENTRY_GOTO_DEFAULT = 2, |
michael@0 | 40 | ENTRY_INVALID = 3 |
michael@0 | 41 | }; |
michael@0 | 42 | |
michael@0 | 43 | typedef enum UResEntryType UResEntryType; |
michael@0 | 44 | */ |
michael@0 | 45 | |
michael@0 | 46 | struct UResourceDataEntry; |
michael@0 | 47 | typedef struct UResourceDataEntry UResourceDataEntry; |
michael@0 | 48 | |
michael@0 | 49 | /* |
michael@0 | 50 | * Note: If we wanted to make this structure smaller, then we could try |
michael@0 | 51 | * to use one UResourceDataEntry pointer for fAlias and fPool, with a separate |
michael@0 | 52 | * flag to distinguish whether this struct is for a real bundle with a pool, |
michael@0 | 53 | * or for an alias entry for which we won't use the pool after loading. |
michael@0 | 54 | */ |
michael@0 | 55 | struct UResourceDataEntry { |
michael@0 | 56 | char *fName; /* name of the locale for bundle - still to decide whether it is original or fallback */ |
michael@0 | 57 | char *fPath; /* path to bundle - used for distinguishing between resources with the same name */ |
michael@0 | 58 | UResourceDataEntry *fParent; /*next resource in fallback chain*/ |
michael@0 | 59 | UResourceDataEntry *fAlias; |
michael@0 | 60 | UResourceDataEntry *fPool; |
michael@0 | 61 | ResourceData fData; /* data for low level access */ |
michael@0 | 62 | char fNameBuffer[3]; /* A small buffer of free space for fName. The free space is due to struct padding. */ |
michael@0 | 63 | uint32_t fCountExisting; /* how much is this resource used */ |
michael@0 | 64 | UErrorCode fBogus; |
michael@0 | 65 | /* int32_t fHashKey;*/ /* for faster access in the hashtable */ |
michael@0 | 66 | }; |
michael@0 | 67 | |
michael@0 | 68 | #define RES_BUFSIZE 64 |
michael@0 | 69 | #define RES_PATH_SEPARATOR '/' |
michael@0 | 70 | #define RES_PATH_SEPARATOR_S "/" |
michael@0 | 71 | |
michael@0 | 72 | struct UResourceBundle { |
michael@0 | 73 | const char *fKey; /*tag*/ |
michael@0 | 74 | UResourceDataEntry *fData; /*for low-level access*/ |
michael@0 | 75 | char *fVersion; |
michael@0 | 76 | UResourceDataEntry *fTopLevelData; /* for getting the valid locale */ |
michael@0 | 77 | char *fResPath; /* full path to the resource: "zh_TW/CollationElements/Sequence" */ |
michael@0 | 78 | ResourceData fResData; |
michael@0 | 79 | char fResBuf[RES_BUFSIZE]; |
michael@0 | 80 | int32_t fResPathLen; |
michael@0 | 81 | Resource fRes; |
michael@0 | 82 | UBool fHasFallback; |
michael@0 | 83 | UBool fIsTopLevel; |
michael@0 | 84 | uint32_t fMagic1; /* For determining if it's a stack object */ |
michael@0 | 85 | uint32_t fMagic2; /* For determining if it's a stack object */ |
michael@0 | 86 | int32_t fIndex; |
michael@0 | 87 | int32_t fSize; |
michael@0 | 88 | |
michael@0 | 89 | /*const UResourceBundle *fParentRes;*/ /* needed to get the actual locale for a child resource */ |
michael@0 | 90 | }; |
michael@0 | 91 | |
michael@0 | 92 | U_CAPI void U_EXPORT2 ures_initStackObject(UResourceBundle* resB); |
michael@0 | 93 | |
michael@0 | 94 | /* Some getters used by the copy constructor */ |
michael@0 | 95 | U_CFUNC const char* ures_getName(const UResourceBundle* resB); |
michael@0 | 96 | #ifdef URES_DEBUG |
michael@0 | 97 | U_CFUNC const char* ures_getPath(const UResourceBundle* resB); |
michael@0 | 98 | /** |
michael@0 | 99 | * If anything was in the RB cache, dump it to the screen. |
michael@0 | 100 | * @return TRUE if there was anything into the cache |
michael@0 | 101 | */ |
michael@0 | 102 | U_CAPI UBool U_EXPORT2 ures_dumpCacheContents(void); |
michael@0 | 103 | #endif |
michael@0 | 104 | /*U_CFUNC void ures_appendResPath(UResourceBundle *resB, const char* toAdd, int32_t lenToAdd);*/ |
michael@0 | 105 | /*U_CFUNC void ures_setResPath(UResourceBundle *resB, const char* toAdd);*/ |
michael@0 | 106 | /*U_CFUNC void ures_freeResPath(UResourceBundle *resB);*/ |
michael@0 | 107 | |
michael@0 | 108 | /* Candidates for export */ |
michael@0 | 109 | U_CFUNC UResourceBundle *ures_copyResb(UResourceBundle *r, const UResourceBundle *original, UErrorCode *status); |
michael@0 | 110 | |
michael@0 | 111 | /** |
michael@0 | 112 | * Returns a resource that can be located using the pathToResource argument. One needs optional package, locale |
michael@0 | 113 | * and path inside the locale, for example: "/myData/en/zoneStrings/3". Keys and indexes are supported. Keys |
michael@0 | 114 | * need to reference data in named structures, while indexes can reference both named and anonymous resources. |
michael@0 | 115 | * Features a fill-in parameter. |
michael@0 | 116 | * |
michael@0 | 117 | * Note, this function does NOT have a syntax for specifying items within a tree. May want to consider a |
michael@0 | 118 | * syntax that delineates between package/tree and resource. |
michael@0 | 119 | * |
michael@0 | 120 | * @param pathToResource a path that will lead to the requested resource |
michael@0 | 121 | * @param fillIn if NULL a new UResourceBundle struct is allocated and must be deleted by the caller. |
michael@0 | 122 | * Alternatively, you can supply a struct to be filled by this function. |
michael@0 | 123 | * @param status fills in the outgoing error code. |
michael@0 | 124 | * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it |
michael@0 | 125 | */ |
michael@0 | 126 | U_CAPI UResourceBundle* U_EXPORT2 |
michael@0 | 127 | ures_findResource(const char* pathToResource, |
michael@0 | 128 | UResourceBundle *fillIn, UErrorCode *status); |
michael@0 | 129 | |
michael@0 | 130 | /** |
michael@0 | 131 | * Returns a sub resource that can be located using the pathToResource argument. One needs a path inside |
michael@0 | 132 | * the supplied resource, for example, if you have "en_US" resource bundle opened, you might ask for |
michael@0 | 133 | * "zoneStrings/3". Keys and indexes are supported. Keys |
michael@0 | 134 | * need to reference data in named structures, while indexes can reference both |
michael@0 | 135 | * named and anonymous resources. |
michael@0 | 136 | * Features a fill-in parameter. |
michael@0 | 137 | * |
michael@0 | 138 | * @param resourceBundle a resource |
michael@0 | 139 | * @param pathToResource a path that will lead to the requested resource |
michael@0 | 140 | * @param fillIn if NULL a new UResourceBundle struct is allocated and must be deleted by the caller. |
michael@0 | 141 | * Alternatively, you can supply a struct to be filled by this function. |
michael@0 | 142 | * @param status fills in the outgoing error code. |
michael@0 | 143 | * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it |
michael@0 | 144 | */ |
michael@0 | 145 | U_CAPI UResourceBundle* U_EXPORT2 |
michael@0 | 146 | ures_findSubResource(const UResourceBundle *resB, |
michael@0 | 147 | char* pathToResource, |
michael@0 | 148 | UResourceBundle *fillIn, UErrorCode *status); |
michael@0 | 149 | |
michael@0 | 150 | /** |
michael@0 | 151 | * Returns a functionally equivalent locale (considering keywords) for the specified keyword. |
michael@0 | 152 | * @param result fillin for the equivalent locale |
michael@0 | 153 | * @param resultCapacity capacity of the fillin buffer |
michael@0 | 154 | * @param path path to the tree, or NULL for ICU data |
michael@0 | 155 | * @param resName top level resource. Example: "collations" |
michael@0 | 156 | * @param keyword locale keyword. Example: "collation" |
michael@0 | 157 | * @param locid The requested locale |
michael@0 | 158 | * @param isAvailable If non-null, pointer to fillin parameter that indicates whether the |
michael@0 | 159 | * requested locale was available. The locale is defined as 'available' if it physically |
michael@0 | 160 | * exists within the specified tree. |
michael@0 | 161 | * @param omitDefault if TRUE, omit keyword and value if default. 'de_DE\@collation=standard' -> 'de_DE' |
michael@0 | 162 | * @param status error code |
michael@0 | 163 | * @return the actual buffer size needed for the full locale. If it's greater |
michael@0 | 164 | * than resultCapacity, the returned full name will be truncated and an error code will be returned. |
michael@0 | 165 | */ |
michael@0 | 166 | U_CAPI int32_t U_EXPORT2 |
michael@0 | 167 | ures_getFunctionalEquivalent(char *result, int32_t resultCapacity, |
michael@0 | 168 | const char *path, const char *resName, const char *keyword, const char *locid, |
michael@0 | 169 | UBool *isAvailable, UBool omitDefault, UErrorCode *status); |
michael@0 | 170 | |
michael@0 | 171 | /** |
michael@0 | 172 | * Given a tree path and keyword, return a string enumeration of all possible values for that keyword. |
michael@0 | 173 | * @param path path to the tree, or NULL for ICU data |
michael@0 | 174 | * @param keyword a particular keyword to consider, must match a top level resource name |
michael@0 | 175 | * within the tree. |
michael@0 | 176 | * @param status error code |
michael@0 | 177 | */ |
michael@0 | 178 | U_CAPI UEnumeration* U_EXPORT2 |
michael@0 | 179 | ures_getKeywordValues(const char *path, const char *keyword, UErrorCode *status); |
michael@0 | 180 | |
michael@0 | 181 | |
michael@0 | 182 | /** |
michael@0 | 183 | * Get a resource with multi-level fallback. Normally only the top level resources will |
michael@0 | 184 | * fallback to its parent. This performs fallback on subresources. For example, when a table |
michael@0 | 185 | * is defined in a resource bundle and a parent resource bundle, normally no fallback occurs |
michael@0 | 186 | * on the sub-resources because the table is defined in the current resource bundle, but this |
michael@0 | 187 | * function can perform fallback on the sub-resources of the table. |
michael@0 | 188 | * @param resB a resource |
michael@0 | 189 | * @param inKey a key associated with the requested resource |
michael@0 | 190 | * @param fillIn if NULL a new UResourceBundle struct is allocated and must be deleted by the caller. |
michael@0 | 191 | * Alternatively, you can supply a struct to be filled by this function. |
michael@0 | 192 | * @param status: fills in the outgoing error code |
michael@0 | 193 | * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found |
michael@0 | 194 | * could be a non-failing error |
michael@0 | 195 | * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT> |
michael@0 | 196 | * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it |
michael@0 | 197 | */ |
michael@0 | 198 | U_CAPI UResourceBundle* U_EXPORT2 |
michael@0 | 199 | ures_getByKeyWithFallback(const UResourceBundle *resB, |
michael@0 | 200 | const char* inKey, |
michael@0 | 201 | UResourceBundle *fillIn, |
michael@0 | 202 | UErrorCode *status); |
michael@0 | 203 | |
michael@0 | 204 | |
michael@0 | 205 | /** |
michael@0 | 206 | * Get a String with multi-level fallback. Normally only the top level resources will |
michael@0 | 207 | * fallback to its parent. This performs fallback on subresources. For example, when a table |
michael@0 | 208 | * is defined in a resource bundle and a parent resource bundle, normally no fallback occurs |
michael@0 | 209 | * on the sub-resources because the table is defined in the current resource bundle, but this |
michael@0 | 210 | * function can perform fallback on the sub-resources of the table. |
michael@0 | 211 | * @param resB a resource |
michael@0 | 212 | * @param inKey a key associated with the requested resource |
michael@0 | 213 | * @param status: fills in the outgoing error code |
michael@0 | 214 | * could be <TT>U_MISSING_RESOURCE_ERROR</TT> if the key is not found |
michael@0 | 215 | * could be a non-failing error |
michael@0 | 216 | * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT> |
michael@0 | 217 | * @return a pointer to a UResourceBundle struct. If fill in param was NULL, caller must delete it |
michael@0 | 218 | */ |
michael@0 | 219 | U_CAPI const UChar* U_EXPORT2 |
michael@0 | 220 | ures_getStringByKeyWithFallback(const UResourceBundle *resB, |
michael@0 | 221 | const char* inKey, |
michael@0 | 222 | int32_t* len, |
michael@0 | 223 | UErrorCode *status); |
michael@0 | 224 | |
michael@0 | 225 | /** |
michael@0 | 226 | * Get a version number by key |
michael@0 | 227 | * @param resB bundle containing version number |
michael@0 | 228 | * @param key the key for the version number |
michael@0 | 229 | * @param ver fillin for the version number |
michael@0 | 230 | * @param status error code |
michael@0 | 231 | */ |
michael@0 | 232 | U_CAPI void U_EXPORT2 |
michael@0 | 233 | ures_getVersionByKey(const UResourceBundle *resB, |
michael@0 | 234 | const char *key, |
michael@0 | 235 | UVersionInfo ver, |
michael@0 | 236 | UErrorCode *status); |
michael@0 | 237 | |
michael@0 | 238 | |
michael@0 | 239 | /** |
michael@0 | 240 | * Internal function. |
michael@0 | 241 | * Return the version number associated with this ResourceBundle as a string. |
michael@0 | 242 | * |
michael@0 | 243 | * @param resourceBundle The resource bundle for which the version is checked. |
michael@0 | 244 | * @return A version number string as specified in the resource bundle or its parent. |
michael@0 | 245 | * The caller does not own this string. |
michael@0 | 246 | * @see ures_getVersion |
michael@0 | 247 | */ |
michael@0 | 248 | U_CAPI const char* U_EXPORT2 |
michael@0 | 249 | ures_getVersionNumberInternal(const UResourceBundle *resourceBundle); |
michael@0 | 250 | |
michael@0 | 251 | /** |
michael@0 | 252 | * Return the name of the Locale associated with this ResourceBundle. This API allows |
michael@0 | 253 | * you to query for the real locale of the resource. For example, if you requested |
michael@0 | 254 | * "en_US_CALIFORNIA" and only "en_US" bundle exists, "en_US" will be returned. |
michael@0 | 255 | * For subresources, the locale where this resource comes from will be returned. |
michael@0 | 256 | * If fallback has occured, getLocale will reflect this. |
michael@0 | 257 | * |
michael@0 | 258 | * This internal version avoids deprecated-warnings in ICU code. |
michael@0 | 259 | * |
michael@0 | 260 | * @param resourceBundle resource bundle in question |
michael@0 | 261 | * @param status just for catching illegal arguments |
michael@0 | 262 | * @return A Locale name |
michael@0 | 263 | */ |
michael@0 | 264 | U_CAPI const char* U_EXPORT2 |
michael@0 | 265 | ures_getLocaleInternal(const UResourceBundle* resourceBundle, |
michael@0 | 266 | UErrorCode* status); |
michael@0 | 267 | |
michael@0 | 268 | #endif /*URESIMP_H*/ |