summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/PM/DataModel/EncryptedRemoteObject.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/DataModel/EncryptedRemoteObject.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/PM/DataModel/EncryptedRemoteObject.js26
1 files changed, 10 insertions, 16 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/EncryptedRemoteObject.js b/frontend/gamma/js/Clipperz/PM/DataModel/EncryptedRemoteObject.js
index cdeec8b..1aa7a52 100644
--- a/frontend/gamma/js/Clipperz/PM/DataModel/EncryptedRemoteObject.js
+++ b/frontend/gamma/js/Clipperz/PM/DataModel/EncryptedRemoteObject.js
@@ -1,70 +1,68 @@
1/* 1/*
2 2
3Copyright 2008-2011 Clipperz Srl 3Copyright 2008-2013 Clipperz Srl
4 4
5This file is part of Clipperz Community Edition. 5This file is part of Clipperz, the online password manager.
6Clipperz Community Edition is an online password manager.
7For further information about its features and functionalities please 6For further information about its features and functionalities please
8refer to http://www.clipperz.com. 7refer to http://www.clipperz.com.
9 8
10* Clipperz Community Edition is free software: you can redistribute 9* Clipperz is free software: you can redistribute it and/or modify it
11 it and/or modify it under the terms of the GNU Affero General Public 10 under the terms of the GNU Affero General Public License as published
12 License as published by the Free Software Foundation, either version 11 by the Free Software Foundation, either version 3 of the License, or
13 3 of the License, or (at your option) any later version. 12 (at your option) any later version.
14 13
15* Clipperz Community Edition is distributed in the hope that it will 14* Clipperz is distributed in the hope that it will be useful, but
16 be useful, but WITHOUT ANY WARRANTY; without even the implied 15 WITHOUT ANY WARRANTY; without even the implied warranty of
17 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU Affero General Public License for more details. 17 See the GNU Affero General Public License for more details.
19 18
20* You should have received a copy of the GNU Affero General Public 19* You should have received a copy of the GNU Affero General Public
21 License along with Clipperz Community Edition. If not, see 20 License along with Clipperz. If not, see http://www.gnu.org/licenses/.
22 <http://www.gnu.org/licenses/>.
23 21
24*/ 22*/
25 23
26try { if (typeof(Clipperz.KeyValueObjectStore) == 'undefined') { throw ""; }} catch (e) { 24try { if (typeof(Clipperz.KeyValueObjectStore) == 'undefined') { throw ""; }} catch (e) {
27 throw "Clipperz.PM.DataModel.EncryptedRemoteObject depends on Clipperz.KeyValueObjectStore!"; 25 throw "Clipperz.PM.DataModel.EncryptedRemoteObject depends on Clipperz.KeyValueObjectStore!";
28} 26}
29 27
30if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } 28if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; }
31if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } 29if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; }
32 30
33Clipperz.PM.DataModel.EncryptedRemoteObject = function(args) { 31Clipperz.PM.DataModel.EncryptedRemoteObject = function(args) {
34 args = args || {}; 32 args = args || {};
35 33
36 this._name = args.name || null; 34 this._name = args.name || null;
37 this._reference = args.reference || Clipperz.PM.Crypto.randomKey(); 35 this._reference = args.reference || Clipperz.PM.Crypto.randomKey();
38 this._isBrandNew = ((args.reference == null) && (args.remoteData == null)); 36 this._isBrandNew = ((args.reference == null) && (args.remoteData == null));
39 37
40 if ((this._isBrandNew == false) && (args['retrieveKeyFunction'] == null)) { 38 if ((this._isBrandNew == false) && (args['retrieveKeyFunction'] == null)) {
41 Clipperz.Base.exception.raise('MandatoryParameter'); 39 Clipperz.Base.exception.raise('MandatoryParameter');
42 } else { 40 } else {
43 this._retrieveKeyFunction = args['retrieveKeyFunction']; 41 this._retrieveKeyFunction = args['retrieveKeyFunction'];
44 } 42 }
45 43
46 this._retrieveRemoteDataFunction = args.retrieveRemoteDataFunction|| null; 44 this._retrieveRemoteDataFunction = args.retrieveRemoteDataFunction|| null;
47 this._remoteData = args.remoteData || null; 45 this._remoteData = args.remoteData || null;
48 // this._remoteData = args.remoteData ? Clipperz.Base.deepClone(args.remoteData) : null; 46 // this._remoteData = args.remoteData ? Clipperz.Base.deepClone(args.remoteData) : null;
49 if ((!this._isBrandNew) && ((this._retrieveRemoteDataFunction == null) && (this._remoteData == null))) { 47 if ((!this._isBrandNew) && ((this._retrieveRemoteDataFunction == null) && (this._remoteData == null))) {
50 Clipperz.Base.exception.raise('MandatoryParameter'); 48 Clipperz.Base.exception.raise('MandatoryParameter');
51 } 49 }
52 50
53 51
54 this._encryptedDataKeypath = args.encryptedDataKeypath || 'data'; //Clipperz.Base.exception.raise('MandatoryParameter'); 52 this._encryptedDataKeypath = args.encryptedDataKeypath || 'data'; //Clipperz.Base.exception.raise('MandatoryParameter');
55 this._encryptedVersionKeypath = args.encryptedVersionKeypath || 'version';//Clipperz.Base.exception.raise('MandatoryParameter'); 53 this._encryptedVersionKeypath = args.encryptedVersionKeypath || 'version';//Clipperz.Base.exception.raise('MandatoryParameter');
56 54
57 55
58 this._transientState = null; 56 this._transientState = null;
59 this._deferredLocks = {}; 57 this._deferredLocks = {};
60 58
61 if (this._isBrandNew == true) { 59 if (this._isBrandNew == true) {
62 this._objectDataStore = new Clipperz.KeyValueObjectStore(/*{'name':'EncryptedRemoteObject.objectDataStore [1]'}*/); 60 this._objectDataStore = new Clipperz.KeyValueObjectStore(/*{'name':'EncryptedRemoteObject.objectDataStore [1]'}*/);
63 } else { 61 } else {
64 this._objectDataStore = null; 62 this._objectDataStore = null;
65 } 63 }
66 64
67 return this; 65 return this;
68} 66}
69 67
70// 68//
@@ -366,100 +364,96 @@ Clipperz.PM.DataModel.EncryptedRemoteObject.prototype = MochiKit.Base.update(nul
366 //------------------------------------------------------------------------- 364 //-------------------------------------------------------------------------
367 365
368 'getDeferredLockForKey': function (aKey) { 366 'getDeferredLockForKey': function (aKey) {
369 var result; 367 var result;
370 368
371 result = this._deferredLocks[aKey]; 369 result = this._deferredLocks[aKey];
372 370
373 if (typeof(result) == 'undefined') { 371 if (typeof(result) == 'undefined') {
374 result = new MochiKit.Async.DeferredLock(); 372 result = new MochiKit.Async.DeferredLock();
375 this._deferredLocks[aKey] = result; 373 this._deferredLocks[aKey] = result;
376 } 374 }
377 375
378 return result; 376 return result;
379 }, 377 },
380 378
381 //------------------------------------------------------------------------- 379 //-------------------------------------------------------------------------
382 380
383 'unpackData': function (someData) { //++ 381 'unpackData': function (someData) { //++
384 return someData; 382 return someData;
385 }, 383 },
386 384
387 'packData': function (someData) { //++ 385 'packData': function (someData) { //++
388 return someData; 386 return someData;
389 }, 387 },
390 388
391 //------------------------------------------------------------------------- 389 //-------------------------------------------------------------------------
392 390
393 'hasPendingChanges': function () { 391 'hasPendingChanges': function () {
394 var deferredResult; 392 var deferredResult;
395 var tempObj = this; 393 var tempObj = this;
396 394
397 if (this.isBrandNew()) { 395 if (this.isBrandNew()) {
398 // deferredResult = MochiKit.Async.succeed(true); 396 // deferredResult = MochiKit.Async.succeed(true);
399 deferredResult = this.hasPendingChangesWhenBrandNew(); 397 deferredResult = this.hasPendingChangesWhenBrandNew();
400 } else if (this.hasInitiatedObjectDataStore()) { 398 } else if (this.hasInitiatedObjectDataStore()) {
401 deferredResult = new Clipperz.Async.Deferred("EncryptedRemoteObject.hasPendingChanges", {trace:false}); 399 deferredResult = new Clipperz.Async.Deferred("EncryptedRemoteObject.hasPendingChanges", {trace:false});
402 deferredResult.collectResults({ 400 deferredResult.collectResults({
403 'decryptedData': [ 401 'decryptedData': [
404 MochiKit.Base.method(this, 'getDecryptedData'), 402 MochiKit.Base.method(this, 'getDecryptedData'),
405 Clipperz.Base.serializeJSON 403 Clipperz.Base.serializeJSON
406 ], 404 ],
407 'objectData': [ 405 'objectData': [
408 MochiKit.Base.method(this, '_getObjectDataStore'), 406 MochiKit.Base.method(this, '_getObjectDataStore'),
409 MochiKit.Base.methodcaller('values'), 407 MochiKit.Base.methodcaller('values'),
410 Clipperz.Base.serializeJSON 408 Clipperz.Base.serializeJSON
411 ] 409 ]
412 }); 410 });
413 deferredResult.addCallback(function (someValues) { 411 deferredResult.addCallback(function (someValues) {
414//if (someValues['decryptedData'] != someValues['objectData']) {
415 //console.log("ORIGINAL DATA", '[[[' + someValues['decryptedData'] + ']]]');
416 //console.log("CURRENT DATA", '>>>' + someValues['objectData'] + '<<<');
417//}
418 return (someValues['decryptedData'] != someValues['objectData']); 412 return (someValues['decryptedData'] != someValues['objectData']);
419 }); 413 });
420 deferredResult.callback(); 414 deferredResult.callback();
421 } else { 415 } else {
422 deferredResult = MochiKit.Async.succeed(false); 416 deferredResult = MochiKit.Async.succeed(false);
423 } 417 }
424 418
425 return deferredResult; 419 return deferredResult;
426 }, 420 },
427 421
428 'hasPendingChangesWhenBrandNew': function () { 422 'hasPendingChangesWhenBrandNew': function () {
429 return MochiKit.Async.succeed(true); 423 return MochiKit.Async.succeed(true);
430 }, 424 },
431 425
432 //------------------------------------------------------------------------- 426 //-------------------------------------------------------------------------
433 427
434 'commitTransientState': function () { 428 'commitTransientState': function () {
435 var deferredResult; 429 var deferredResult;
436 430
437 // if (this.transientState().getValue('__prepareRemoteData') == true) { 431 // if (this.transientState().getValue('__prepareRemoteData') == true) {
438 if (this.transientState().getValue('packedRemoteData') != null) { 432 if (this.transientState().getValue('packedRemoteData') != null) {
439 deferredResult = Clipperz.Async.callbacks("EncryptedRemoteObject.commitTransientState - prepareRemoteData", [ 433 deferredResult = Clipperz.Async.callbacks("EncryptedRemoteObject.commitTransientState - prepareRemoteData", [
440 MochiKit.Base.bind(function (someData) { 434 MochiKit.Base.bind(function (someData) {
441 this._remoteData = this.transientState().getValue('packedRemoteData'); 435 this._remoteData = this.transientState().getValue('packedRemoteData');
442 }, this), 436 }, this),
443 437
444 MochiKit.Base.method(this, '_getObjectDataStore'), 438 MochiKit.Base.method(this, '_getObjectDataStore'),
445 MochiKit.Base.methodcaller('values'), 439 MochiKit.Base.methodcaller('values'),
446 Clipperz.Base.deepClone, 440 Clipperz.Base.deepClone,
447 MochiKit.Base.method(this.decryptedDataStore(), 'setValue', 'decryptedData'), 441 MochiKit.Base.method(this.decryptedDataStore(), 'setValue', 'decryptedData'),
448 442
449 MochiKit.Base.method(this, 'resetTransientState', true) 443 MochiKit.Base.method(this, 'resetTransientState', true)
450 ], {trace:false}); 444 ], {trace:false});
451 445
452 } else { 446 } else {
453 deferredResult = Clipperz.Async.callbacks("EncryptedRemoteObject.commitTransientState - NO prepareRemoteData", [ 447 deferredResult = Clipperz.Async.callbacks("EncryptedRemoteObject.commitTransientState - NO prepareRemoteData", [
454 MochiKit.Base.method(this, 'resetTransientState', true) 448 MochiKit.Base.method(this, 'resetTransientState', true)
455 ], {trace:false}); 449 ], {trace:false});
456 } 450 }
457 451
458 this._isBrandNew = false; 452 this._isBrandNew = false;
459 453
460 return deferredResult; 454 return deferredResult;
461 }, 455 },
462 456
463 //------------------------------------------------------------------------- 457 //-------------------------------------------------------------------------
464 458
465 'revertChanges': function () { 459 'revertChanges': function () {