toolkit/components/sqlite/sqlite_internal.js

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.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 /**
michael@0 6 * This file defines an Sqlite object containing js-ctypes bindings for
michael@0 7 * sqlite3. It should be included from a worker thread using require.
michael@0 8 *
michael@0 9 * It serves the following purposes:
michael@0 10 * - opens libxul;
michael@0 11 * - defines sqlite3 API functions;
michael@0 12 * - defines the necessary sqlite3 types.
michael@0 13 */
michael@0 14
michael@0 15 "use strict";
michael@0 16
michael@0 17 importScripts("resource://gre/modules/workers/require.js");
michael@0 18
michael@0 19 let SharedAll = require(
michael@0 20 "resource://gre/modules/osfile/osfile_shared_allthreads.jsm");
michael@0 21
michael@0 22 // Open the sqlite3 library.
michael@0 23 let path;
michael@0 24 if (SharedAll.Constants.Sys.Name === "Android") {
michael@0 25 path = ctypes.libraryName("sqlite3");
michael@0 26 } else if (SharedAll.Constants.Win) {
michael@0 27 path = ctypes.libraryName("nss3");
michael@0 28 } else {
michael@0 29 path = SharedAll.Constants.Path.libxul;
michael@0 30 }
michael@0 31
michael@0 32 let lib;
michael@0 33 try {
michael@0 34 lib = ctypes.open(path);
michael@0 35 } catch (ex) {
michael@0 36 throw new Error("Could not open system library: " + ex.message);
michael@0 37 }
michael@0 38
michael@0 39 let declareLazyFFI = SharedAll.declareLazyFFI;
michael@0 40
michael@0 41 let Type = Object.create(SharedAll.Type);
michael@0 42
michael@0 43 /**
michael@0 44 * Opaque Structure |sqlite3_ptr|.
michael@0 45 * |sqlite3_ptr| is equivalent to a void*.
michael@0 46 */
michael@0 47 Type.sqlite3_ptr = Type.voidptr_t.withName("sqlite3_ptr");
michael@0 48
michael@0 49 /**
michael@0 50 * |sqlite3_stmt_ptr| an instance of an object representing a single SQL
michael@0 51 * statement.
michael@0 52 * |sqlite3_stmt_ptr| is equivalent to a void*.
michael@0 53 */
michael@0 54 Type.sqlite3_stmt_ptr = Type.voidptr_t.withName("sqlite3_stmt_ptr");
michael@0 55
michael@0 56 /**
michael@0 57 * |sqlite3_destructor_ptr| a constant defining a special destructor behaviour.
michael@0 58 * |sqlite3_destructor_ptr| is equivalent to a void*.
michael@0 59 */
michael@0 60 Type.sqlite3_destructor_ptr = Type.voidptr_t.withName(
michael@0 61 "sqlite3_destructor_ptr");
michael@0 62
michael@0 63 /**
michael@0 64 * A C double.
michael@0 65 */
michael@0 66 Type.double = new SharedAll.Type("double", ctypes.double);
michael@0 67
michael@0 68 /**
michael@0 69 * |sqlite3_int64| typedef for 64-bit integer.
michael@0 70 */
michael@0 71 Type.sqlite3_int64 = Type.int64_t.withName("sqlite3_int64");
michael@0 72
michael@0 73 /**
michael@0 74 * Sqlite3 constants.
michael@0 75 */
michael@0 76 let Constants = {};
michael@0 77
michael@0 78 /**
michael@0 79 * |SQLITE_STATIC| a special value for the destructor that is passed as an
michael@0 80 * argument to routines like bind_blob, bind_text and bind_text16. It means that
michael@0 81 * the content pointer is constant and will never change and does need to be
michael@0 82 * destroyed.
michael@0 83 */
michael@0 84 Constants.SQLITE_STATIC = Type.sqlite3_destructor_ptr.implementation(0);
michael@0 85
michael@0 86 /**
michael@0 87 * |SQLITE_TRANSIENT| a special value for the destructor that is passed as an
michael@0 88 * argument to routines like bind_blob, bind_text and bind_text16. It means that
michael@0 89 * the content will likely change in the near future and that SQLite should make
michael@0 90 * its own private copy of the content before returning.
michael@0 91 */
michael@0 92 Constants.SQLITE_TRANSIENT = Type.sqlite3_destructor_ptr.implementation(-1);
michael@0 93
michael@0 94 /**
michael@0 95 * |SQLITE_OK|
michael@0 96 * Successful result.
michael@0 97 */
michael@0 98 Constants.SQLITE_OK = 0;
michael@0 99
michael@0 100 /**
michael@0 101 * |SQLITE_ROW|
michael@0 102 * sqlite3_step() has another row ready.
michael@0 103 */
michael@0 104 Constants.SQLITE_ROW = 100;
michael@0 105
michael@0 106 /**
michael@0 107 * |SQLITE_DONE|
michael@0 108 * sqlite3_step() has finished executing.
michael@0 109 */
michael@0 110 Constants.SQLITE_DONE = 101;
michael@0 111
michael@0 112 let Sqlite3 = {
michael@0 113 Constants: Constants,
michael@0 114 Type: Type
michael@0 115 };
michael@0 116
michael@0 117 declareLazyFFI(Sqlite3, "open", lib, "sqlite3_open", null,
michael@0 118 /*return*/ Type.int,
michael@0 119 /*path*/ Type.char.in_ptr,
michael@0 120 /*db handle*/ Type.sqlite3_ptr.out_ptr);
michael@0 121
michael@0 122 declareLazyFFI(Sqlite3, "open_v2", lib, "sqlite3_open_v2", null,
michael@0 123 /*return*/ Type.int,
michael@0 124 /*path*/ Type.char.in_ptr,
michael@0 125 /*db handle*/ Type.sqlite3_ptr.out_ptr,
michael@0 126 /*flags*/ Type.int,
michael@0 127 /*VFS*/ Type.char.in_ptr);
michael@0 128
michael@0 129 declareLazyFFI(Sqlite3, "close", lib, "sqlite3_close", null,
michael@0 130 /*return*/ Type.int,
michael@0 131 /*db handle*/ Type.sqlite3_ptr);
michael@0 132
michael@0 133 declareLazyFFI(Sqlite3, "prepare_v2", lib, "sqlite3_prepare_v2", null,
michael@0 134 /*return*/ Type.int,
michael@0 135 /*db handle*/ Type.sqlite3_ptr,
michael@0 136 /*zSql*/ Type.char.in_ptr,
michael@0 137 /*nByte*/ Type.int,
michael@0 138 /*statement*/ Type.sqlite3_stmt_ptr.out_ptr,
michael@0 139 /*unused*/ Type.cstring.out_ptr);
michael@0 140
michael@0 141 declareLazyFFI(Sqlite3, "step", lib, "sqlite3_step", null,
michael@0 142 /*return*/ Type.int,
michael@0 143 /*statement*/ Type.sqlite3_stmt_ptr);
michael@0 144
michael@0 145 declareLazyFFI(Sqlite3, "finalize", lib, "sqlite3_finalize", null,
michael@0 146 /*return*/ Type.int,
michael@0 147 /*statement*/ Type.sqlite3_stmt_ptr);
michael@0 148
michael@0 149 declareLazyFFI(Sqlite3, "reset", lib, "sqlite3_reset", null,
michael@0 150 /*return*/ Type.int,
michael@0 151 /*statement*/ Type.sqlite3_stmt_ptr);
michael@0 152
michael@0 153 declareLazyFFI(Sqlite3, "column_int", lib, "sqlite3_column_int", null,
michael@0 154 /*return*/ Type.int,
michael@0 155 /*statement*/ Type.sqlite3_stmt_ptr,
michael@0 156 /*col*/ Type.int);
michael@0 157
michael@0 158 declareLazyFFI(Sqlite3, "column_blob", lib, "sqlite3_column_blob", null,
michael@0 159 /*return*/ Type.voidptr_t,
michael@0 160 /*statement*/ Type.sqlite3_stmt_ptr,
michael@0 161 /*col*/ Type.int);
michael@0 162
michael@0 163 declareLazyFFI(Sqlite3, "column_bytes", lib, "sqlite3_column_bytes", null,
michael@0 164 /*return*/ Type.int,
michael@0 165 /*statement*/ Type.sqlite3_stmt_ptr,
michael@0 166 /*col*/ Type.int);
michael@0 167
michael@0 168 declareLazyFFI(Sqlite3, "column_bytes16", lib, "sqlite3_column_bytes16",
michael@0 169 null,
michael@0 170 /*return*/ Type.int,
michael@0 171 /*statement*/ Type.sqlite3_stmt_ptr,
michael@0 172 /*col*/ Type.int);
michael@0 173
michael@0 174 declareLazyFFI(Sqlite3, "column_double", lib, "sqlite3_column_double", null,
michael@0 175 /*return*/ Type.double,
michael@0 176 /*statement*/ Type.sqlite3_stmt_ptr,
michael@0 177 /*col*/ Type.int);
michael@0 178
michael@0 179 declareLazyFFI(Sqlite3, "column_int64", lib, "sqlite3_column_int64", null,
michael@0 180 /*return*/ Type.sqlite3_int64,
michael@0 181 /*statement*/ Type.sqlite3_stmt_ptr,
michael@0 182 /*col*/ Type.int);
michael@0 183
michael@0 184 declareLazyFFI(Sqlite3, "column_text", lib, "sqlite3_column_text", null,
michael@0 185 /*return*/ Type.cstring,
michael@0 186 /*statement*/ Type.sqlite3_stmt_ptr,
michael@0 187 /*col*/ Type.int);
michael@0 188
michael@0 189 declareLazyFFI(Sqlite3, "column_text16", lib, "sqlite3_column_text16", null,
michael@0 190 /*return*/ Type.wstring,
michael@0 191 /*statement*/ Type.sqlite3_stmt_ptr,
michael@0 192 /*col*/ Type.int);
michael@0 193
michael@0 194 declareLazyFFI(Sqlite3, "bind_int", lib, "sqlite3_bind_int", null,
michael@0 195 /*return*/ Type.int,
michael@0 196 /*statement*/ Type.sqlite3_stmt_ptr,
michael@0 197 /*index*/ Type.int,
michael@0 198 /*value*/ Type.int);
michael@0 199
michael@0 200 declareLazyFFI(Sqlite3, "bind_int64", lib, "sqlite3_bind_int64", null,
michael@0 201 /*return*/ Type.int,
michael@0 202 /*statement*/ Type.sqlite3_stmt_ptr,
michael@0 203 /*index*/ Type.int,
michael@0 204 /*value*/ Type.sqlite3_int64);
michael@0 205
michael@0 206 declareLazyFFI(Sqlite3, "bind_double", lib, "sqlite3_bind_double", null,
michael@0 207 /*return*/ Type.int,
michael@0 208 /*statement*/ Type.sqlite3_stmt_ptr,
michael@0 209 /*index*/ Type.int,
michael@0 210 /*value*/ Type.double);
michael@0 211
michael@0 212 declareLazyFFI(Sqlite3, "bind_null", lib, "sqlite3_bind_null", null,
michael@0 213 /*return*/ Type.int,
michael@0 214 /*statement*/ Type.sqlite3_stmt_ptr,
michael@0 215 /*index*/ Type.int);
michael@0 216
michael@0 217 declareLazyFFI(Sqlite3, "bind_zeroblob", lib, "sqlite3_bind_zeroblob", null,
michael@0 218 /*return*/ Type.int,
michael@0 219 /*statement*/ Type.sqlite3_stmt_ptr,
michael@0 220 /*index*/ Type.int,
michael@0 221 /*nBytes*/ Type.int);
michael@0 222
michael@0 223 declareLazyFFI(Sqlite3, "bind_text", lib, "sqlite3_bind_text", null,
michael@0 224 /*return*/ Type.int,
michael@0 225 /*statement*/ Type.sqlite3_stmt_ptr,
michael@0 226 /*index*/ Type.int,
michael@0 227 /*value*/ Type.cstring,
michael@0 228 /*nBytes*/ Type.int,
michael@0 229 /*destructor*/ Type.sqlite3_destructor_ptr);
michael@0 230
michael@0 231 declareLazyFFI(Sqlite3, "bind_text16", lib, "sqlite3_bind_text16", null,
michael@0 232 /*return*/ Type.int,
michael@0 233 /*statement*/ Type.sqlite3_stmt_ptr,
michael@0 234 /*index*/ Type.int,
michael@0 235 /*value*/ Type.wstring,
michael@0 236 /*nBytes*/ Type.int,
michael@0 237 /*destructor*/ Type.sqlite3_destructor_ptr);
michael@0 238
michael@0 239 declareLazyFFI(Sqlite3, "bind_blob", lib, "sqlite3_bind_blob", null,
michael@0 240 /*return*/ Type.int,
michael@0 241 /*statement*/ Type.sqlite3_stmt_ptr,
michael@0 242 /*index*/ Type.int,
michael@0 243 /*value*/ Type.voidptr_t,
michael@0 244 /*nBytes*/ Type.int,
michael@0 245 /*destructor*/ Type.sqlite3_destructor_ptr);
michael@0 246
michael@0 247 module.exports = {
michael@0 248 get Constants() {
michael@0 249 return Sqlite3.Constants;
michael@0 250 },
michael@0 251 get Type() {
michael@0 252 return Sqlite3.Type;
michael@0 253 },
michael@0 254 get open() {
michael@0 255 return Sqlite3.open;
michael@0 256 },
michael@0 257 get open_v2() {
michael@0 258 return Sqlite3.open_v2;
michael@0 259 },
michael@0 260 get close() {
michael@0 261 return Sqlite3.close;
michael@0 262 },
michael@0 263 get prepare_v2() {
michael@0 264 return Sqlite3.prepare_v2;
michael@0 265 },
michael@0 266 get step() {
michael@0 267 return Sqlite3.step;
michael@0 268 },
michael@0 269 get finalize() {
michael@0 270 return Sqlite3.finalize;
michael@0 271 },
michael@0 272 get reset() {
michael@0 273 return Sqlite3.reset;
michael@0 274 },
michael@0 275 get column_int() {
michael@0 276 return Sqlite3.column_int;
michael@0 277 },
michael@0 278 get column_blob() {
michael@0 279 return Sqlite3.column_blob;
michael@0 280 },
michael@0 281 get column_bytes() {
michael@0 282 return Sqlite3.column_bytes;
michael@0 283 },
michael@0 284 get column_bytes16() {
michael@0 285 return Sqlite3.column_bytes16;
michael@0 286 },
michael@0 287 get column_double() {
michael@0 288 return Sqlite3.column_double;
michael@0 289 },
michael@0 290 get column_int64() {
michael@0 291 return Sqlite3.column_int64;
michael@0 292 },
michael@0 293 get column_text() {
michael@0 294 return Sqlite3.column_text;
michael@0 295 },
michael@0 296 get column_text16() {
michael@0 297 return Sqlite3.column_text16;
michael@0 298 },
michael@0 299 get bind_int() {
michael@0 300 return Sqlite3.bind_int;
michael@0 301 },
michael@0 302 get bind_int64() {
michael@0 303 return Sqlite3.bind_int64;
michael@0 304 },
michael@0 305 get bind_double() {
michael@0 306 return Sqlite3.bind_double;
michael@0 307 },
michael@0 308 get bind_null() {
michael@0 309 return Sqlite3.bind_null;
michael@0 310 },
michael@0 311 get bind_zeroblob() {
michael@0 312 return Sqlite3.bind_zeroblob;
michael@0 313 },
michael@0 314 get bind_text() {
michael@0 315 return Sqlite3.bind_text;
michael@0 316 },
michael@0 317 get bind_text16() {
michael@0 318 return Sqlite3.bind_text16;
michael@0 319 },
michael@0 320 get bind_blob() {
michael@0 321 return Sqlite3.bind_blob;
michael@0 322 }
michael@0 323 };

mercurial