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 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim:set ts=2 sw=2 sts=2 et cindent: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef MAR_H__ |
michael@0 | 8 | #define MAR_H__ |
michael@0 | 9 | |
michael@0 | 10 | #include "mozilla/Assertions.h" |
michael@0 | 11 | #include <stdint.h> |
michael@0 | 12 | |
michael@0 | 13 | #ifdef __cplusplus |
michael@0 | 14 | extern "C" { |
michael@0 | 15 | #endif |
michael@0 | 16 | |
michael@0 | 17 | /* We have a MAX_SIGNATURES limit so that an invalid MAR will never |
michael@0 | 18 | * waste too much of either updater's or signmar's time. |
michael@0 | 19 | * It is also used at various places internally and will affect memory usage. |
michael@0 | 20 | * If you want to increase this value above 9 then you need to adjust parsing |
michael@0 | 21 | * code in tool/mar.c. |
michael@0 | 22 | */ |
michael@0 | 23 | #define MAX_SIGNATURES 8 |
michael@0 | 24 | #ifdef __cplusplus |
michael@0 | 25 | static_assert(MAX_SIGNATURES <= 9, "too many signatures"); |
michael@0 | 26 | #else |
michael@0 | 27 | MOZ_STATIC_ASSERT(MAX_SIGNATURES <= 9, "too many signatures"); |
michael@0 | 28 | #endif |
michael@0 | 29 | |
michael@0 | 30 | struct ProductInformationBlock { |
michael@0 | 31 | const char *MARChannelID; |
michael@0 | 32 | const char *productVersion; |
michael@0 | 33 | }; |
michael@0 | 34 | |
michael@0 | 35 | /** |
michael@0 | 36 | * The MAR item data structure. |
michael@0 | 37 | */ |
michael@0 | 38 | typedef struct MarItem_ { |
michael@0 | 39 | struct MarItem_ *next; /* private field */ |
michael@0 | 40 | uint32_t offset; /* offset into archive */ |
michael@0 | 41 | uint32_t length; /* length of data in bytes */ |
michael@0 | 42 | uint32_t flags; /* contains file mode bits */ |
michael@0 | 43 | char name[1]; /* file path */ |
michael@0 | 44 | } MarItem; |
michael@0 | 45 | |
michael@0 | 46 | #define TABLESIZE 256 |
michael@0 | 47 | |
michael@0 | 48 | struct MarFile_ { |
michael@0 | 49 | FILE *fp; |
michael@0 | 50 | MarItem *item_table[TABLESIZE]; |
michael@0 | 51 | }; |
michael@0 | 52 | |
michael@0 | 53 | typedef struct MarFile_ MarFile; |
michael@0 | 54 | |
michael@0 | 55 | /** |
michael@0 | 56 | * Signature of callback function passed to mar_enum_items. |
michael@0 | 57 | * @param mar The MAR file being visited. |
michael@0 | 58 | * @param item The MAR item being visited. |
michael@0 | 59 | * @param data The data parameter passed by the caller of mar_enum_items. |
michael@0 | 60 | * @return A non-zero value to stop enumerating. |
michael@0 | 61 | */ |
michael@0 | 62 | typedef int (* MarItemCallback)(MarFile *mar, const MarItem *item, void *data); |
michael@0 | 63 | |
michael@0 | 64 | /** |
michael@0 | 65 | * Open a MAR file for reading. |
michael@0 | 66 | * @param path Specifies the path to the MAR file to open. This path must |
michael@0 | 67 | * be compatible with fopen. |
michael@0 | 68 | * @return NULL if an error occurs. |
michael@0 | 69 | */ |
michael@0 | 70 | MarFile *mar_open(const char *path); |
michael@0 | 71 | |
michael@0 | 72 | #ifdef XP_WIN |
michael@0 | 73 | MarFile *mar_wopen(const wchar_t *path); |
michael@0 | 74 | #endif |
michael@0 | 75 | |
michael@0 | 76 | /** |
michael@0 | 77 | * Close a MAR file that was opened using mar_open. |
michael@0 | 78 | * @param mar The MarFile object to close. |
michael@0 | 79 | */ |
michael@0 | 80 | void mar_close(MarFile *mar); |
michael@0 | 81 | |
michael@0 | 82 | /** |
michael@0 | 83 | * Find an item in the MAR file by name. |
michael@0 | 84 | * @param mar The MarFile object to query. |
michael@0 | 85 | * @param item The name of the item to query. |
michael@0 | 86 | * @return A const reference to a MAR item or NULL if not found. |
michael@0 | 87 | */ |
michael@0 | 88 | const MarItem *mar_find_item(MarFile *mar, const char *item); |
michael@0 | 89 | |
michael@0 | 90 | /** |
michael@0 | 91 | * Enumerate all MAR items via callback function. |
michael@0 | 92 | * @param mar The MAR file to enumerate. |
michael@0 | 93 | * @param callback The function to call for each MAR item. |
michael@0 | 94 | * @param data A caller specified value that is passed along to the |
michael@0 | 95 | * callback function. |
michael@0 | 96 | * @return 0 if the enumeration ran to completion. Otherwise, any |
michael@0 | 97 | * non-zero return value from the callback is returned. |
michael@0 | 98 | */ |
michael@0 | 99 | int mar_enum_items(MarFile *mar, MarItemCallback callback, void *data); |
michael@0 | 100 | |
michael@0 | 101 | /** |
michael@0 | 102 | * Read from MAR item at given offset up to bufsize bytes. |
michael@0 | 103 | * @param mar The MAR file to read. |
michael@0 | 104 | * @param item The MAR item to read. |
michael@0 | 105 | * @param offset The byte offset relative to the start of the item. |
michael@0 | 106 | * @param buf A pointer to a buffer to copy the data into. |
michael@0 | 107 | * @param bufsize The length of the buffer to copy the data into. |
michael@0 | 108 | * @return The number of bytes written or a negative value if an |
michael@0 | 109 | * error occurs. |
michael@0 | 110 | */ |
michael@0 | 111 | int mar_read(MarFile *mar, const MarItem *item, int offset, char *buf, |
michael@0 | 112 | int bufsize); |
michael@0 | 113 | |
michael@0 | 114 | /** |
michael@0 | 115 | * Create a MAR file from a set of files. |
michael@0 | 116 | * @param dest The path to the file to create. This path must be |
michael@0 | 117 | * compatible with fopen. |
michael@0 | 118 | * @param numfiles The number of files to store in the archive. |
michael@0 | 119 | * @param files The list of null-terminated file paths. Each file |
michael@0 | 120 | * path must be compatible with fopen. |
michael@0 | 121 | * @param infoBlock The information to store in the product information block. |
michael@0 | 122 | * @return A non-zero value if an error occurs. |
michael@0 | 123 | */ |
michael@0 | 124 | int mar_create(const char *dest, |
michael@0 | 125 | int numfiles, |
michael@0 | 126 | char **files, |
michael@0 | 127 | struct ProductInformationBlock *infoBlock); |
michael@0 | 128 | |
michael@0 | 129 | /** |
michael@0 | 130 | * Extract a MAR file to the current working directory. |
michael@0 | 131 | * @param path The path to the MAR file to extract. This path must be |
michael@0 | 132 | * compatible with fopen. |
michael@0 | 133 | * @return A non-zero value if an error occurs. |
michael@0 | 134 | */ |
michael@0 | 135 | int mar_extract(const char *path); |
michael@0 | 136 | |
michael@0 | 137 | /** |
michael@0 | 138 | * Verifies a MAR file by verifying each signature with the corresponding |
michael@0 | 139 | * certificate. That is, the first signature will be verified using the first |
michael@0 | 140 | * certificate given, the second signature will be verified using the second |
michael@0 | 141 | * certificate given, etc. The signature count must exactly match the number of |
michael@0 | 142 | * certificates given, and all signature verifications must succeed. |
michael@0 | 143 | * We do not check that the certificate was issued by any trusted authority. |
michael@0 | 144 | * We assume it to be self-signed. We do not check whether the certificate |
michael@0 | 145 | * is valid for this usage. |
michael@0 | 146 | * |
michael@0 | 147 | * @param mar The already opened MAR file. |
michael@0 | 148 | * @param certData Pointer to the first element in an array of certificate |
michael@0 | 149 | * file data. |
michael@0 | 150 | * @param certDataSizes Pointer to the first element in an array for size of |
michael@0 | 151 | * the cert data. |
michael@0 | 152 | * @param certCount The number of elements in certData and certDataSizes |
michael@0 | 153 | * @return 0 on success |
michael@0 | 154 | * a negative number if there was an error |
michael@0 | 155 | * a positive number if the signature does not verify |
michael@0 | 156 | */ |
michael@0 | 157 | #ifdef XP_WIN |
michael@0 | 158 | int mar_verify_signaturesW(MarFile *mar, |
michael@0 | 159 | const uint8_t * const *certData, |
michael@0 | 160 | const uint32_t *certDataSizes, |
michael@0 | 161 | uint32_t certCount); |
michael@0 | 162 | #endif |
michael@0 | 163 | |
michael@0 | 164 | /** |
michael@0 | 165 | * Reads the product info block from the MAR file's additional block section. |
michael@0 | 166 | * The caller is responsible for freeing the fields in infoBlock |
michael@0 | 167 | * if the return is successful. |
michael@0 | 168 | * |
michael@0 | 169 | * @param infoBlock Out parameter for where to store the result to |
michael@0 | 170 | * @return 0 on success, -1 on failure |
michael@0 | 171 | */ |
michael@0 | 172 | int |
michael@0 | 173 | mar_read_product_info_block(MarFile *mar, |
michael@0 | 174 | struct ProductInformationBlock *infoBlock); |
michael@0 | 175 | |
michael@0 | 176 | #ifdef __cplusplus |
michael@0 | 177 | } |
michael@0 | 178 | #endif |
michael@0 | 179 | |
michael@0 | 180 | #endif /* MAR_H__ */ |