-rw-r--r-- | frontend/beta/js/Clipperz/PM/DataModel/Header.js | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/frontend/beta/js/Clipperz/PM/DataModel/Header.js b/frontend/beta/js/Clipperz/PM/DataModel/Header.js index 908d9f4..d577830 100644 --- a/frontend/beta/js/Clipperz/PM/DataModel/Header.js +++ b/frontend/beta/js/Clipperz/PM/DataModel/Header.js | |||
@@ -1,180 +1,181 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2013 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz, the online password manager. | 5 | This file is part of Clipperz, the online password manager. |
6 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
7 | refer to http://www.clipperz.com. | 7 | refer to http://www.clipperz.com. |
8 | 8 | ||
9 | * Clipperz is free software: you can redistribute it and/or modify it | 9 | * Clipperz is free software: you can redistribute it and/or modify it |
10 | under the terms of the GNU Affero General Public License as published | 10 | under the terms of the GNU Affero General Public License as published |
11 | by the Free Software Foundation, either version 3 of the License, or | 11 | by the Free Software Foundation, either version 3 of the License, or |
12 | (at your option) any later version. | 12 | (at your option) any later version. |
13 | 13 | ||
14 | * Clipperz is distributed in the hope that it will be useful, but | 14 | * Clipperz is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | 15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. | 17 | See the GNU Affero General Public License for more details. |
18 | 18 | ||
19 | * 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 |
20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. | 20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. |
21 | 21 | ||
22 | */ | 22 | */ |
23 | 23 | ||
24 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 24 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
25 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | 25 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } |
26 | if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } | 26 | if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } |
27 | 27 | ||
28 | 28 | ||
29 | //############################################################################# | 29 | //############################################################################# |
30 | 30 | ||
31 | Clipperz.PM.DataModel.Header = function(args) { | 31 | Clipperz.PM.DataModel.Header = function(args) { |
32 | args = args || {}; | 32 | args = args || {}; |
33 | 33 | ||
34 | this._user = args.user; | 34 | this._user = args.user; |
35 | 35 | ||
36 | this._serverData = null; | 36 | this._serverData = null; |
37 | this._serverDataVersion = null; | 37 | this._serverDataVersion = null; |
38 | this._jsonEvaledServerData = null; | 38 | this._jsonEvaledServerData = null; |
39 | 39 | ||
40 | this._decryptedLegacyServerData = null; | 40 | this._decryptedLegacyServerData = null; |
41 | this._isDecryptingLegacyServerData = false; | 41 | this._isDecryptingLegacyServerData = false; |
42 | this._decryptingLegacyServerDataPendingQueue = []; | 42 | this._decryptingLegacyServerDataPendingQueue = []; |
43 | 43 | ||
44 | this.resetUpdatedSections(); | 44 | this.resetUpdatedSections(); |
45 | 45 | ||
46 | this._shouldLoadSections = {}; | 46 | this._shouldLoadSections = {}; |
47 | 47 | ||
48 | Clipperz.NotificationCenter.register(this.user(), 'updatedSection', this, 'updatedSectionHandler'); | 48 | Clipperz.NotificationCenter.register(this.user(), 'updatedSection', this, 'updatedSectionHandler'); |
49 | 49 | ||
50 | return this; | 50 | return this; |
51 | } | 51 | } |
52 | 52 | ||
53 | Clipperz.PM.DataModel.Header.prototype = MochiKit.Base.update(null, { | 53 | Clipperz.PM.DataModel.Header.prototype = MochiKit.Base.update(null, { |
54 | 54 | ||
55 | //------------------------------------------------------------------------- | 55 | //------------------------------------------------------------------------- |
56 | 56 | ||
57 | 'user': function() { | 57 | 'user': function() { |
58 | return this._user; | 58 | return this._user; |
59 | }, | 59 | }, |
60 | 60 | ||
61 | //------------------------------------------------------------------------- | 61 | //------------------------------------------------------------------------- |
62 | //------------------------------------------------------------------------- | 62 | //------------------------------------------------------------------------- |
63 | //------------------------------------------------------------------------- | 63 | //------------------------------------------------------------------------- |
64 | //------------------------------------------------------------------------- | 64 | //------------------------------------------------------------------------- |
65 | //------------------------------------------------------------------------- | 65 | //------------------------------------------------------------------------- |
66 | //------------------------------------------------------------------------- | 66 | //------------------------------------------------------------------------- |
67 | //------------------------------------------------------------------------- | 67 | //------------------------------------------------------------------------- |
68 | //------------------------------------------------------------------------- | 68 | //------------------------------------------------------------------------- |
69 | //------------------------------------------------------------------------- | 69 | //------------------------------------------------------------------------- |
70 | 70 | ||
71 | 'updatedSections': function() { | 71 | 'updatedSections': function() { |
72 | return this._updatedSections; | 72 | return this._updatedSections; |
73 | }, | 73 | }, |
74 | 74 | ||
75 | 'markSectionAsUpdated': function(aSectionName) { | 75 | 'markSectionAsUpdated': function(aSectionName) { |
76 | this.updatedSections().push(aSectionName); | 76 | this.updatedSections().push(aSectionName); |
77 | }, | 77 | }, |
78 | 78 | ||
79 | 'resetUpdatedSections': function() { | 79 | 'resetUpdatedSections': function() { |
80 | this._updatedSections = [] | 80 | this._updatedSections = [] |
81 | }, | 81 | }, |
82 | 82 | ||
83 | 'hasSectionBeenUpdated': function(aSectionName) { | 83 | 'hasSectionBeenUpdated': function(aSectionName) { |
84 | return (this.updatedSections().join().indexOf(aSectionName) != -1); | 84 | return(this.updatedSections().join().indexOf(aSectionName) != -1) |
85 | ||(this.serverDataVersion() != Clipperz.PM.Crypto.encryptingFunctions.currentVersion); | ||
85 | }, | 86 | }, |
86 | 87 | ||
87 | 'cachedServerDataSection': function(aSectionName) { | 88 | 'cachedServerDataSection': function(aSectionName) { |
88 | return (this.hasSectionBeenUpdated(aSectionName)) ? {} : this.jsonEvaledServerData()[aSectionName]; | 89 | return (this.hasSectionBeenUpdated(aSectionName)) ? {} : this.jsonEvaledServerData()[aSectionName]; |
89 | }, | 90 | }, |
90 | 91 | ||
91 | 'updateAllSections': function() { | 92 | 'updateAllSections': function() { |
92 | this.resetUpdatedSections(); | 93 | this.resetUpdatedSections(); |
93 | this.markSectionAsUpdated('records'); | 94 | this.markSectionAsUpdated('records'); |
94 | this.markSectionAsUpdated('directLogins'); | 95 | this.markSectionAsUpdated('directLogins'); |
95 | this.markSectionAsUpdated('preferences'); | 96 | this.markSectionAsUpdated('preferences'); |
96 | this.markSectionAsUpdated('oneTimePasswords'); | 97 | this.markSectionAsUpdated('oneTimePasswords'); |
97 | 98 | ||
98 | return MochiKit.Async.succeed(this); | 99 | return MochiKit.Async.succeed(this); |
99 | }, | 100 | }, |
100 | 101 | ||
101 | 'updatedSectionHandler': function(anEvent) { | 102 | 'updatedSectionHandler': function(anEvent) { |
102 | this.markSectionAsUpdated(anEvent.parameters()); | 103 | this.markSectionAsUpdated(anEvent.parameters()); |
103 | }, | 104 | }, |
104 | 105 | ||
105 | //------------------------------------------------------------------------- | 106 | //------------------------------------------------------------------------- |
106 | 107 | ||
107 | 'getObjectKeyIndex': function(anObject) { | 108 | 'getObjectKeyIndex': function(anObject) { |
108 | var result; | 109 | var result; |
109 | varitemReference; | 110 | varitemReference; |
110 | var index; | 111 | var index; |
111 | 112 | ||
112 | result = {}; | 113 | result = {}; |
113 | index = 0; | 114 | index = 0; |
114 | 115 | ||
115 | for (itemReference in anObject) { | 116 | for (itemReference in anObject) { |
116 | result[itemReference] = index.toString(); | 117 | result[itemReference] = index.toString(); |
117 | index ++; | 118 | index ++; |
118 | } | 119 | } |
119 | 120 | ||
120 | return result; | 121 | return result; |
121 | }, | 122 | }, |
122 | 123 | ||
123 | //------------------------------------------------------------------------- | 124 | //------------------------------------------------------------------------- |
124 | 125 | ||
125 | 'serializedDataWithRecordAndDirectLoginIndexes': function(aRecordIndexes, aDirectLoginIndexs) { | 126 | 'serializedDataWithRecordAndDirectLoginIndexes': function(aRecordIndexes, aDirectLoginIndexs) { |
126 | var result; | 127 | var result; |
127 | var records; | 128 | var records; |
128 | var recordReference; | 129 | var recordReference; |
129 | 130 | ||
130 | //MochiKit.Logging.logDebug(">>> Header.serializedData"); | 131 | //MochiKit.Logging.logDebug(">>> Header.serializedData"); |
131 | result = { | 132 | result = { |
132 | 'records': {}, | 133 | 'records': {}, |
133 | 'directLogins': {} | 134 | 'directLogins': {} |
134 | }; | 135 | }; |
135 | 136 | ||
136 | records = this.user().records(); | 137 | records = this.user().records(); |
137 | for (recordReference in records) { | 138 | for (recordReference in records) { |
138 | result['records'][aRecordIndexes[recordReference]] = this.user().records()[recordReference].headerData(); | 139 | result['records'][aRecordIndexes[recordReference]] = this.user().records()[recordReference].headerData(); |
139 | } | 140 | } |
140 | 141 | ||
141 | for (directLoginReference in this.user().directLoginReferences()) { | 142 | for (directLoginReference in this.user().directLoginReferences()) { |
142 | var currentDirectLogin; | 143 | var currentDirectLogin; |
143 | vardirectLoginData; | 144 | vardirectLoginData; |
144 | 145 | ||
145 | currentDirectLogin = this.user().directLoginReferences()[directLoginReference]; | 146 | currentDirectLogin = this.user().directLoginReferences()[directLoginReference]; |
146 | if (aRecordIndexes[currentDirectLogin.recordReference()] != null) { | 147 | if (aRecordIndexes[currentDirectLogin.recordReference()] != null) { |
147 | directLoginData = { | 148 | directLoginData = { |
148 | // reference: currentDirectLogin.reference(), | 149 | // reference: currentDirectLogin.reference(), |
149 | record: aRecordIndexes[currentDirectLogin.recordReference()].toString(), | 150 | record: aRecordIndexes[currentDirectLogin.recordReference()].toString(), |
150 | label: currentDirectLogin.label(), | 151 | label: currentDirectLogin.label(), |
151 | favicon:currentDirectLogin.favicon() || "" | 152 | favicon:currentDirectLogin.favicon() || "" |
152 | } | 153 | } |
153 | 154 | ||
154 | result['directLogins'][aDirectLoginIndexs[directLoginReference]] = directLoginData; | 155 | result['directLogins'][aDirectLoginIndexs[directLoginReference]] = directLoginData; |
155 | } | 156 | } |
156 | 157 | ||
157 | } | 158 | } |
158 | //MochiKit.Logging.logDebug("<<< Header.serializedData - result: " + Clipperz.Base.serializeJSON(result)); | 159 | //MochiKit.Logging.logDebug("<<< Header.serializedData - result: " + Clipperz.Base.serializeJSON(result)); |
159 | //MochiKit.Logging.logDebug("<<< Header.serializedData"); | 160 | //MochiKit.Logging.logDebug("<<< Header.serializedData"); |
160 | 161 | ||
161 | return result; | 162 | return result; |
162 | }, | 163 | }, |
163 | 164 | ||
164 | //------------------------------------------------------------------------- | 165 | //------------------------------------------------------------------------- |
165 | 166 | ||
166 | 'encryptedData': function() { | 167 | 'encryptedData': function() { |
167 | var deferredResult; | 168 | var deferredResult; |
168 | var recordIndex; | 169 | var recordIndex; |
169 | var directLoginIndex; | 170 | var directLoginIndex; |
170 | varserializedData; | 171 | varserializedData; |
171 | var result; | 172 | var result; |
172 | 173 | ||
173 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Header.encryptedData"); | 174 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Header.encryptedData"); |
174 | //MochiKit.Logging.logDebug("### Header.encryptedData - " + Clipperz.Base.serializeJSON(this.updatedSections())); | 175 | //MochiKit.Logging.logDebug("### Header.encryptedData - " + Clipperz.Base.serializeJSON(this.updatedSections())); |
175 | result = { | 176 | result = { |
176 | 'records': this.cachedServerDataSection('records'), | 177 | 'records': this.cachedServerDataSection('records'), |
177 | 'directLogins': this.cachedServerDataSection('directLogins'), | 178 | 'directLogins': this.cachedServerDataSection('directLogins'), |
178 | 'preferences': this.cachedServerDataSection('preferences'), | 179 | 'preferences': this.cachedServerDataSection('preferences'), |
179 | 'oneTimePasswords': this.cachedServerDataSection('oneTimePasswords'), | 180 | 'oneTimePasswords': this.cachedServerDataSection('oneTimePasswords'), |
180 | 'version': '0.1' | 181 | 'version': '0.1' |
@@ -319,192 +320,193 @@ Clipperz.PM.DataModel.Header.prototype = MochiKit.Base.update(null, { | |||
319 | 320 | ||
320 | //MochiKit.Logging.logDebug(">>> Header.decryptedLegacyServerData"); | 321 | //MochiKit.Logging.logDebug(">>> Header.decryptedLegacyServerData"); |
321 | deferredResult = new MochiKit.Async.Deferred(); | 322 | deferredResult = new MochiKit.Async.Deferred(); |
322 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.decryptedLegacyServerData 1: "/* + res*/); return res;}); | 323 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.decryptedLegacyServerData 1: "/* + res*/); return res;}); |
323 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 324 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
324 | deferredResult.addCallback(MochiKit.Base.method(this, 'updateAllSections')); | 325 | deferredResult.addCallback(MochiKit.Base.method(this, 'updateAllSections')); |
325 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.decryptedLegacyServerData 2: "/* + res*/); return res;}); | 326 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.decryptedLegacyServerData 2: "/* + res*/); return res;}); |
326 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 327 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
327 | if (this._decryptedLegacyServerData == null) { | 328 | if (this._decryptedLegacyServerData == null) { |
328 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.decryptedLegacyServerData 3: "/* + res*/); return res;}); | 329 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.decryptedLegacyServerData 3: "/* + res*/); return res;}); |
329 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 330 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
330 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'connection_decryptingUserData'); | 331 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'connection_decryptingUserData'); |
331 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.decryptedLegacyServerData 4: "/* + res*/); return res;}); | 332 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.decryptedLegacyServerData 4: "/* + res*/); return res;}); |
332 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 333 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
333 | deferredResult.addCallback(Clipperz.PM.Crypto.deferredDecrypt, this.user().passphrase(), this.serverData(), this.serverDataVersion()); | 334 | deferredResult.addCallback(Clipperz.PM.Crypto.deferredDecrypt, this.user().passphrase(), this.serverData(), this.serverDataVersion()); |
334 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.decryptedLegacyServerData 5: "/* + res*/); return res;}); | 335 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.decryptedLegacyServerData 5: "/* + res*/); return res;}); |
335 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 336 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
336 | deferredResult.addCallback(function(anHeader, aValue) { | 337 | deferredResult.addCallback(function(anHeader, aValue) { |
337 | anHeader._decryptedLegacyServerData = aValue; | 338 | anHeader._decryptedLegacyServerData = aValue; |
338 | }, this); | 339 | }, this); |
339 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.decryptedLegacyServerData 6: "/* + res*/); return res;}); | 340 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.decryptedLegacyServerData 6: "/* + res*/); return res;}); |
340 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 341 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
341 | }; | 342 | }; |
342 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.decryptedLegacyServerData 7: "/* + res*/); return res;}); | 343 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.decryptedLegacyServerData 7: "/* + res*/); return res;}); |
343 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 344 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
344 | 345 | ||
345 | deferredResult.addCallback(function(anHeader) { | 346 | deferredResult.addCallback(function(anHeader) { |
346 | return anHeader._decryptedLegacyServerData; | 347 | return anHeader._decryptedLegacyServerData; |
347 | }, this); | 348 | }, this); |
348 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.decryptedLegacyServerData 8: "/* + res*/); return res;}); | 349 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.decryptedLegacyServerData 8: "/* + res*/); return res;}); |
349 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 350 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
350 | deferredResult.callback(); | 351 | deferredResult.callback(); |
351 | //MochiKit.Logging.logDebug("<<< Header.decryptedLegacyServerData"); | 352 | //MochiKit.Logging.logDebug("<<< Header.decryptedLegacyServerData"); |
352 | 353 | ||
353 | return deferredResult; | 354 | return deferredResult; |
354 | }, | 355 | }, |
355 | 356 | ||
356 | //------------------------------------------------------------------------- | 357 | //------------------------------------------------------------------------- |
357 | 358 | ||
358 | 'serverDataFormat': function() { | 359 | 'serverDataFormat': function() { |
359 | var result; | 360 | var result; |
360 | 361 | ||
361 | //MochiKit.Logging.logDebug(">>> Header.serverDataFormat"); | 362 | //MochiKit.Logging.logDebug(">>> Header.serverDataFormat"); |
362 | if (this.serverData().charAt(0) == '{') { | 363 | if (this.serverData().charAt(0) == '{') { |
363 | varserverData; | 364 | varserverData; |
364 | 365 | ||
365 | serverData = Clipperz.Base.evalJSON(this.serverData()); | 366 | serverData = Clipperz.Base.evalJSON(this.serverData()); |
366 | result = serverData['version']; | 367 | result = serverData['version']; |
367 | } else { | 368 | } else { |
368 | result = 'LEGACY'; | 369 | result = 'LEGACY'; |
369 | } | 370 | } |
370 | //MochiKit.Logging.logDebug("<<< Header.serverDataFormat"); | 371 | //MochiKit.Logging.logDebug("<<< Header.serverDataFormat"); |
371 | 372 | ||
372 | return result; | 373 | return result; |
373 | }, | 374 | }, |
374 | 375 | ||
375 | //------------------------------------------------------------------------- | 376 | //------------------------------------------------------------------------- |
376 | 377 | ||
377 | 'extractHeaderDataFromUserDetails': function(someUserDetails) { | 378 | 'extractHeaderDataFromUserDetails': function(someUserDetails) { |
378 | if (this.serverData() == null) { | 379 | if (this.serverData() == null) { |
379 | this.setServerData(someUserDetails['header']); | 380 | this.setServerData(someUserDetails['header']); |
380 | this.setServerDataVersion(someUserDetails['version']) | 381 | this.setServerDataVersion(someUserDetails['version']) |
381 | } | 382 | } |
382 | }, | 383 | }, |
383 | 384 | ||
384 | //------------------------------------------------------------------------- | 385 | //------------------------------------------------------------------------- |
385 | 386 | ||
386 | 'extractDataWithKey': function(aKey) { | 387 | 'extractDataWithKey': function(aKey) { |
387 | var deferredResult; | 388 | var deferredResult; |
388 | 389 | ||
389 | //MochiKit.Logging.logDebug(">>> Header.extractDataWithKey"); | 390 | //MochiKit.Logging.logDebug(">>> Header.extractDataWithKey"); |
390 | deferredResult = new MochiKit.Async.Deferred(); | 391 | deferredResult = new MochiKit.Async.Deferred(); |
391 | 392 | ||
392 | switch (this.serverDataFormat()) { | 393 | switch (this.serverDataFormat()) { |
393 | case 'LEGACY': | 394 | case 'LEGACY': |
394 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 1: "/* + res*/); return res;}); | 395 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 1: "/* + res*/); return res;}); |
395 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 396 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
396 | deferredResult.addCallback(MochiKit.Base.method(this, 'decryptedLegacyServerData')); | 397 | deferredResult.addCallback(MochiKit.Base.method(this, 'decryptedLegacyServerData')); |
397 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 2: "/* + res*/); return res;}); | 398 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 2: "/* + res*/); return res;}); |
398 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 399 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
399 | deferredResult.addCallback(function(someDecryptedValues) { | 400 | deferredResult.addCallback(function(someDecryptedValues) { |
400 | return someDecryptedValues[aKey] || {}; | 401 | return someDecryptedValues[aKey] || {}; |
401 | }) | 402 | }) |
402 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 3: "/* + res*/); return res;}); | 403 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 3: "/* + res*/); return res;}); |
403 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 404 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
404 | break; | 405 | break; |
405 | case '0.1': | 406 | case '0.1': |
406 | var data; | 407 | var data; |
407 | 408 | ||
408 | //# data = Clipperz.Base.evalJSON(this.serverData()); | 409 | //# data = Clipperz.Base.evalJSON(this.serverData()); |
409 | data = this.jsonEvaledServerData(); | 410 | data = this.jsonEvaledServerData(); |
410 | if (typeof(data[aKey]) != 'undefined') { | 411 | if (typeof(data[aKey]) != 'undefined') { |
411 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 4: "/* + res*/); return res;}); | 412 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 4: "/* + res*/); return res;}); |
412 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 413 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
413 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'connection_decryptingUserData'); | 414 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'connection_decryptingUserData'); |
414 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 5: "/* + res*/); return res;}); | 415 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 5: "/* + res*/); return res;}); |
416 | //deferredResult.addBoth(function(res) {console.log("aKey: " + aKey); return res;}); | ||
415 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 417 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
416 | deferredResult.addCallback(Clipperz.PM.Crypto.deferredDecrypt, this.user().passphrase(), data[aKey]['data'], this.serverDataVersion()); | 418 | deferredResult.addCallback(Clipperz.PM.Crypto.deferredDecrypt, this.user().passphrase(), data[aKey]['data'], this.serverDataVersion()); |
417 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 6: "/* + res*/); return res;}); | 419 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 6: "/* + res*/); return res;}); |
418 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 420 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
419 | deferredResult.addCallback(function(/*anHeader,*/ aKey, aData, aRecordIndex, aValue) { | 421 | deferredResult.addCallback(function(/*anHeader,*/ aKey, aData, aRecordIndex, aValue) { |
420 | var result; | 422 | var result; |
421 | //MochiKit.Logging.logDebug(">>> [start] ==============================================="); | 423 | //MochiKit.Logging.logDebug(">>> [start] ==============================================="); |
422 | //MochiKit.Logging.logDebug("--- extractDataWithKey - 0 [" + aKey + "]: " + Clipperz.Base.serializeJSON(aValue)); | 424 | //MochiKit.Logging.logDebug("--- extractDataWithKey - 0 [" + aKey + "]: " + Clipperz.Base.serializeJSON(aValue)); |
423 | //MochiKit.Logging.logDebug("<<< [end] ================================================="); | 425 | //MochiKit.Logging.logDebug("<<< [end] ================================================="); |
424 | if (aKey == 'records') { | 426 | if (aKey == 'records') { |
425 | var recordKey; | 427 | var recordKey; |
426 | 428 | ||
427 | result = {}; | 429 | result = {}; |
428 | for (recordKey in aData['index']) { | 430 | for (recordKey in aData['index']) { |
429 | result[recordKey] = aValue[aData['index'][recordKey]]; | 431 | result[recordKey] = aValue[aData['index'][recordKey]]; |
430 | } | 432 | } |
431 | } else if (aKey == 'directLogins') { | 433 | } else if (aKey == 'directLogins') { |
432 | varrecordKeyReversedIndex; | 434 | varrecordKeyReversedIndex; |
433 | var recordKey; | 435 | var recordKey; |
434 | var directLoginKey; | 436 | var directLoginKey; |
435 | 437 | ||
436 | result = {}; | 438 | result = {}; |
437 | recordKeyReversedIndex = {}; | 439 | recordKeyReversedIndex = {}; |
438 | 440 | ||
439 | for (recordKey in aRecordIndex) { | 441 | for (recordKey in aRecordIndex) { |
440 | recordKeyReversedIndex[aRecordIndex[recordKey]] = recordKey; | 442 | recordKeyReversedIndex[aRecordIndex[recordKey]] = recordKey; |
441 | } | 443 | } |
442 | 444 | ||
443 | //MochiKit.Logging.logDebug("--- extractDataWithKey - 1 - aData['index']: " + Clipperz.Base.serializeJSON(aData['index'])); | 445 | //MochiKit.Logging.logDebug("--- extractDataWithKey - 1 - aData['index']: " + Clipperz.Base.serializeJSON(aData['index'])); |
444 | for (directLoginKey in aData['index']) { | 446 | for (directLoginKey in aData['index']) { |
445 | try { | 447 | try { |
446 | if ((aData['index'][directLoginKey] != null) && (aValue[aData['index'][directLoginKey]] != null)) { | 448 | if ((aData['index'][directLoginKey] != null) && (aValue[aData['index'][directLoginKey]] != null)) { |
447 | result[directLoginKey] = aValue[aData['index'][directLoginKey]]; | 449 | result[directLoginKey] = aValue[aData['index'][directLoginKey]]; |
448 | result[directLoginKey]['record'] = recordKeyReversedIndex[result[directLoginKey]['record']]; | 450 | result[directLoginKey]['record'] = recordKeyReversedIndex[result[directLoginKey]['record']]; |
449 | } | 451 | } |
450 | } catch(exception) { | 452 | } catch(exception) { |
451 | //result[directLoginKey] has no properties | 453 | //result[directLoginKey] has no properties |
452 | MochiKit.Logging.logDebug("[Header 391] EXCEPTION: " + exception); | 454 | MochiKit.Logging.logDebug("[Header 391] EXCEPTION: " + exception); |
453 | throw exception; | 455 | throw exception; |
454 | } | 456 | } |
455 | } | 457 | } |
456 | //MochiKit.Logging.logDebug("--- extractDataWithKey - 2"); | 458 | //MochiKit.Logging.logDebug("--- extractDataWithKey - 2"); |
457 | } else { | 459 | } else { |
458 | result = aValue; | 460 | result = aValue; |
459 | } | 461 | } |
460 | 462 | ||
461 | return result; | 463 | return result; |
462 | }, /*this,*/ aKey, data[aKey], data['records']['index']); | 464 | }, /*this,*/ aKey, data[aKey], data['records']['index']); |
463 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 6: "/* + res*/); return res;}); | 465 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 6: "/* + res*/); return res;}); |
464 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 466 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
465 | } else { | 467 | } else { |
466 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 7: "/* + res*/); return res;}); | 468 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 7: "/* + res*/); return res;}); |
467 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 469 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
468 | deferredResult.addCallback(MochiKit.Async.succeed, {}); | 470 | deferredResult.addCallback(MochiKit.Async.succeed, {}); |
469 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 8: "/* + res*/); return res;}); | 471 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 8: "/* + res*/); return res;}); |
470 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 472 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
471 | } | 473 | } |
472 | break; | 474 | break; |
473 | } | 475 | } |
474 | 476 | ||
475 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 9: "/* + res*/); return res;}); | 477 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Header.extractDataWithKey 9: "/* + res*/); return res;}); |
476 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); | 478 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("ERROR: " + res); return res;}); |
477 | deferredResult.callback(); | 479 | deferredResult.callback(); |
478 | //MochiKit.Logging.logDebug("<<< Header.extractDataWithKey"); | 480 | //MochiKit.Logging.logDebug("<<< Header.extractDataWithKey"); |
479 | 481 | ||
480 | return deferredResult; | 482 | return deferredResult; |
481 | }, | 483 | }, |
482 | 484 | ||
483 | //------------------------------------------------------------------------- | 485 | //------------------------------------------------------------------------- |
484 | 486 | ||
485 | 'processRecordData': function(someRecordData) { | 487 | 'processRecordData': function(someRecordData) { |
486 | var records; | 488 | var records; |
487 | varrecordReference; | 489 | varrecordReference; |
488 | 490 | ||
489 | //console.log("HeaderRecordData parameters", someRecordData); | 491 | //console.log("HeaderRecordData parameters", someRecordData); |
490 | //MochiKit.Logging.logDebug(">>> Header.processRecordData"); | 492 | //MochiKit.Logging.logDebug(">>> Header.processRecordData"); |
491 | records = someRecordData; | 493 | records = someRecordData; |
492 | //MochiKit.Logging.logDebug("--- Header.processRecordData - 1"); | 494 | //MochiKit.Logging.logDebug("--- Header.processRecordData - 1"); |
493 | if (records != null) { | 495 | if (records != null) { |
494 | //MochiKit.Logging.logDebug("--- Header.processRecordData - records: " + Clipperz.Base.serializeJSON(records)); | 496 | //MochiKit.Logging.logDebug("--- Header.processRecordData - records: " + Clipperz.Base.serializeJSON(records)); |
495 | for (recordReference in records) { | 497 | for (recordReference in records) { |
496 | var newRecord; | 498 | var newRecord; |
497 | var parameters; | 499 | var parameters; |
498 | 500 | ||
499 | //MochiKit.Logging.logDebug("--- Header.processRecordData - 2 - recordReference: " + recordReference); | 501 | //MochiKit.Logging.logDebug("--- Header.processRecordData - 2 - recordReference: " + recordReference); |
500 | if (recordReference != "stacktrace") { | 502 | if (recordReference != "stacktrace") { |
501 | parameters = records[recordReference];//.slice(); | 503 | parameters = records[recordReference];//.slice(); |
502 | //MochiKit.Logging.logDebug("--- Header.processRecordData - 3"); | 504 | //MochiKit.Logging.logDebug("--- Header.processRecordData - 3"); |
503 | if (typeof(parameters['notes']) != 'undefined') { | 505 | if (typeof(parameters['notes']) != 'undefined') { |
504 | //MochiKit.Logging.logDebug("--- Header.processRecordData - 4"); | 506 | //MochiKit.Logging.logDebug("--- Header.processRecordData - 4"); |
505 | if (parameters['notes'] != "") { | 507 | if (parameters['notes'] != "") { |
506 | //MochiKit.Logging.logDebug("--- Header.processRecordData - 5"); | 508 | //MochiKit.Logging.logDebug("--- Header.processRecordData - 5"); |
507 | parameters['headerNotes'] = parameters['notes']; | 509 | parameters['headerNotes'] = parameters['notes']; |
508 | //MochiKit.Logging.logDebug("--- Header.processRecordData - 6"); | 510 | //MochiKit.Logging.logDebug("--- Header.processRecordData - 6"); |
509 | } | 511 | } |
510 | //MochiKit.Logging.logDebug("--- Header.processRecordData - 7"); | 512 | //MochiKit.Logging.logDebug("--- Header.processRecordData - 7"); |