author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-02 23:56:18 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-02 23:56:18 (UTC) |
commit | ef68436ac04da078ffdcacd7e1f785473a303d45 (patch) (unidiff) | |
tree | c403752d66a2c4775f00affd4fa8431b29c5b68c /frontend/beta/js/Clipperz/KeePassExportProcessor.js | |
parent | 597ecfbc0249d83e1b856cbd558340c01237a360 (diff) | |
download | clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.zip clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.gz clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.bz2 |
First version of the newly restructured repository
Diffstat (limited to 'frontend/beta/js/Clipperz/KeePassExportProcessor.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/KeePassExportProcessor.js | 251 |
1 files changed, 251 insertions, 0 deletions
diff --git a/frontend/beta/js/Clipperz/KeePassExportProcessor.js b/frontend/beta/js/Clipperz/KeePassExportProcessor.js new file mode 100644 index 0000000..ba56b8e --- a/dev/null +++ b/frontend/beta/js/Clipperz/KeePassExportProcessor.js | |||
@@ -0,0 +1,251 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz's Javascript Crypto Library. | ||
6 | Javascript Crypto Library provides web developers with an extensive | ||
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | ||
11 | refer to http://www.clipperz.com | ||
12 | |||
13 | * Javascript Crypto Library is free software: you can redistribute | ||
14 | it and/or modify it under the terms of the GNU Affero General Public | ||
15 | License as published by the Free Software Foundation, either version | ||
16 | 3 of the License, or (at your option) any later version. | ||
17 | |||
18 | * Javascript Crypto Library is distributed in the hope that it will | ||
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
21 | See the GNU Affero General Public License for more details. | ||
22 | |||
23 | * You should have received a copy of the GNU Affero General Public | ||
24 | License along with Javascript Crypto Library. If not, see | ||
25 | <http://www.gnu.org/licenses/>. | ||
26 | |||
27 | */ | ||
28 | |||
29 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | ||
30 | |||
31 | |||
32 | Clipperz.KeePassExportProcessor = function(args) { | ||
33 | args = args || {}; | ||
34 | |||
35 | return this; | ||
36 | } | ||
37 | |||
38 | //============================================================================= | ||
39 | |||
40 | Clipperz.KeePassExportProcessor.prototype = MochiKit.Base.update(null, { | ||
41 | |||
42 | //------------------------------------------------------------------------- | ||
43 | /* | ||
44 | 'parse': function(aValue) { | ||
45 | var result; | ||
46 | |||
47 | //MochiKit.Logging.logDebug(">>> KeePassExportProcessor.parse"); | ||
48 | result = []; | ||
49 | //MochiKit.Logging.logDebug("--- KeePassExportProcessor.parse - result: " + Clipperz.Base.serializeJSON(result)); | ||
50 | //MochiKit.Logging.logDebug("<<< KeePassExportProcessor.parse"); | ||
51 | |||
52 | return result; | ||
53 | }, | ||
54 | */ | ||
55 | //------------------------------------------------------------------------- | ||
56 | |||
57 | 'deferredParse_core': function(aContext) { | ||
58 | var deferredResult; | ||
59 | |||
60 | //MochiKit.Logging.logDebug(">>> KeePassExportProcessor.deferredParse_core"); | ||
61 | //MochiKit.Logging.logDebug("--- KeePassExportProcessor.deferredParse_core - (1) aContext.line: " + aContext.line.replace(/\n/g, "\\n").substring(0,50)); | ||
62 | //MochiKit.Logging.logDebug("--- KeePassExportProcessor.deferredParse_core - aContext: " + Clipperz.Base.serializeJSON(aContext).substring(0,50)); | ||
63 | //MochiKit.Logging.logDebug("--- KeePassExportProcessor.deferredParse_core - (2) aContext.line: " + aContext.line.replace(/\n/g, "\\n").substring(0,50)); | ||
64 | //console.log("deferredParse_core - aContext", aContext); | ||
65 | //MochiKit.Logging.logDebug("--- KeePassExportProcessor.deferredParse_core - (3) aContext.line: " + aContext.line.replace(/\n/g, "\\n").substring(0,50)); | ||
66 | if (aContext.line == "") { | ||
67 | deferredResult = MochiKit.Async.succeed(aContext.result); | ||
68 | } else { | ||
69 | var record; | ||
70 | |||
71 | record = this.parseRecord(aContext); | ||
72 | if (record != null) { | ||
73 | aContext.result.push(record); | ||
74 | } | ||
75 | |||
76 | //MochiKit.Logging.logDebug("--> KeePassExportProcessor.deferredParse_core - aContext.line: " + aContext.line.replace(/\n/g, "\\n").substring(0,50)); | ||
77 | aContext.line = aContext.line.replace(/^\n*/g, "").replace(/\n$/g, ""); | ||
78 | //MochiKit.Logging.logDebug("<-- KeePassExportProcessor.deferredParse_core - aContext.line: " + aContext.line.replace(/\n/g, "\\n").substring(0,50)); | ||
79 | |||
80 | deferredResult = new MochiKit.Async.Deferred(); | ||
81 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassExportProcessor.deferredParse_core - 1.1 " + res); return res;}); | ||
82 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'importProcessorProgressUpdate', {status:'processing', size:aContext.size, progress:(aContext.size - aContext.line.length)}); | ||
83 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassExportProcessor.deferredParse_core - 1.2 " + res); return res;}); | ||
84 | deferredResult.addCallback(MochiKit.Async.wait, 0.2); | ||
85 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassExportProcessor.deferredParse_core - 1.3 " + res); return res;}); | ||
86 | //deferredResult.addBoth(function(res) {console.log("KeePassExportProcessor.deferredParse_core - 1.3 ", res); return res;}); | ||
87 | deferredResult.addCallback(MochiKit.Base.method(this, 'deferredParse_core')) | ||
88 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassExportProcessor.deferredParse_core - 1.4 " + res); return res;}); | ||
89 | deferredResult.callback(aContext); | ||
90 | } | ||
91 | //MochiKit.Logging.logDebug("<<< KeePassExportProcessor.deferredParse_core"); | ||
92 | |||
93 | return deferredResult; | ||
94 | }, | ||
95 | |||
96 | //......................................................................... | ||
97 | |||
98 | 'deferredParse': function(aValue) { | ||
99 | var deferredResult; | ||
100 | var lines; | ||
101 | var context; | ||
102 | |||
103 | //MochiKit.Logging.logDebug(">>> KeePassExportProcessor.deferredParse"); | ||
104 | //MochiKit.Logging.logDebug("--- KeePassExportProcessor.deferredParse - aValue: " + aValue.length); | ||
105 | lines = aValue.replace(/\r?\n/g, "\n"); | ||
106 | //MochiKit.Logging.logDebug("--- KeePassExportProcessor.deferredParse - lines: " + lines.length); | ||
107 | context = { | ||
108 | line: lines, | ||
109 | size: lines.length, | ||
110 | result: [] | ||
111 | } | ||
112 | //MochiKit.Logging.logDebug("--- KeePassExportProcessor.deferredParse - context: " + Clipperz.Base.serializeJSON(context).substring(0,50)); | ||
113 | //console.log("--- KeePassExportProcessor.deferredParse - context: ", context); | ||
114 | |||
115 | deferredResult = new MochiKit.Async.Deferred(); | ||
116 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassExportProcessor.deferredParse - 1 " + res); return res;}); | ||
117 | //deferredResult.addBoth(function(res) {console.log("KeePassExportProcessor.deferredParse - 1 ", res); return res;}); | ||
118 | deferredResult.addCallback(MochiKit.Base.method(this, 'deferredParse_core')); | ||
119 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassExportProcessor.deferredParse - 2 " + res); return res;}); | ||
120 | deferredResult.callback(context); | ||
121 | //MochiKit.Logging.logDebug("<<< KeePassExportProcessor.deferredParse"); | ||
122 | |||
123 | return deferredResult; | ||
124 | }, | ||
125 | |||
126 | //------------------------------------------------------------------------- | ||
127 | |||
128 | 'parseRecord': function(aContext) { | ||
129 | var result; | ||
130 | var recordLabelRegexp; | ||
131 | varfieldLabelRegexp; | ||
132 | var fieldValueRegexp; | ||
133 | var fullLineRegexp; | ||
134 | /* | ||
135 | [Record name] | ||
136 | Group Tree: | ||
137 | UserName: | ||
138 | URL: | ||
139 | Password: | ||
140 | Notes: test | ||
141 | UUID: 525f62430079bae48b79ed2961924b05 | ||
142 | Icon: 0 | ||
143 | Creation Time: 2007-06-26 17:56:03 | ||
144 | Last Access: 2007-10-25 16:23:51 | ||
145 | Last Modification: 2007-10-25 16:23:51 | ||
146 | Expires: 2999-12-28 23:59:59 | ||
147 | |||
148 | [Record name] ==> Title | ||
149 | Group: General ==> Group | ||
150 | Group Tree: ==> Group Tree | ||
151 | UserName: ==> UserName | ||
152 | URL: ==>URL | ||
153 | Password: ==>Password | ||
154 | Notes: test ==>Notes | ||
155 | UUID: 525f62430079bae48b79ed2961924b05 ==>UUID | ||
156 | Icon: 0 ==>Icon | ||
157 | Creation Time: 2007-06-26 17:56:03 ==>Creation Time | ||
158 | Last Access: 2007-10-25 16:23:51 ==>Last Access | ||
159 | Last Modification: 2007-10-25 16:23:51 ==>Last Modification | ||
160 | Expires: 2999-12-28 23:59:59 ==> Expires | ||
161 | Attachment Description: ==> Attachment Description | ||
162 | Attachment: ==> Attachment | ||
163 | */ | ||
164 | recordLabelRegexp = new RegExp("^\\[(.*)\\]\\n"); | ||
165 | // recordLabelRegexp = new RegExp("^\\[(.*)\\]$", "m"); | ||
166 | fieldLabelRegexp = new RegExp("^(Group|Group Tree|UserName|URL|Password|Notes|UUID|Icon|Creation Time|Last Access|Last Modification|Expires|Attachment Description|Attachment|Valid until): "); | ||
167 | fieldValueRegexp = new RegExp("(.*)(\\n|$)"); | ||
168 | fullLineRegexp = new RegExp("^(.*\\n)"); | ||
169 | |||
170 | |||
171 | if (recordLabelRegexp.test(aContext.line) == true) { | ||
172 | var line; | ||
173 | |||
174 | //MochiKit.Logging.logDebug("1.0"); | ||
175 | line = aContext.line; | ||
176 | //MochiKit.Logging.logDebug("0 - line: " + line.replace(/\n/g, "\\n").substring(0,50)); | ||
177 | |||
178 | result = {}; | ||
179 | result['Title'] = line.match(recordLabelRegexp)[1]; | ||
180 | //MochiKit.Logging.logDebug("1 - title: " + result['Title']); | ||
181 | line = line.replace(/^.*\n/, ""); | ||
182 | //MochiKit.Logging.logDebug("2 - line: " + line.replace(/\n/g, "\\n").substring(0,50)); | ||
183 | //MochiKit.Logging.logDebug("======================================="); | ||
184 | while (fieldLabelRegexp.test(line) == true) { | ||
185 | var fieldName; | ||
186 | var fieldValue; | ||
187 | |||
188 | fieldName = RegExp.$1; | ||
189 | //MochiKit.Logging.logDebug("3 - fieldName: " + fieldName); | ||
190 | line = RegExp.rightContext; | ||
191 | //MochiKit.Logging.logDebug("4 - line: " + line.replace(/\n/g, "\\n").substring(0,50)); | ||
192 | |||
193 | fieldValue = line.match(fieldValueRegexp)[1]; | ||
194 | //MochiKit.Logging.logDebug("5 - fieldValue: " + fieldValue); | ||
195 | line = RegExp.rightContext; | ||
196 | //MochiKit.Logging.logDebug("6 - line: " + line.replace(/\n/g, "\\n").substring(0,50)); | ||
197 | |||
198 | if (fieldName == 'Notes') { | ||
199 | var isMultiline; | ||
200 | |||
201 | isMultiline = false; | ||
202 | |||
203 | //MochiKit.Logging.logDebug("7 - fieldLabelRegexp.test(line): " + fieldLabelRegexp.test(line) + " - recordLabelRegexp.test(line): " + recordLabelRegexp.test(line)); | ||
204 | if ((line != "") && (fieldLabelRegexp.test(line) == false) && (recordLabelRegexp.test(line) == false)) { | ||
205 | fieldValue += '\n'; | ||
206 | } | ||
207 | |||
208 | while ((line != "") && (fieldLabelRegexp.test(line) == false) && (recordLabelRegexp.test(line) == false)) { | ||
209 | var newLineValue; | ||
210 | |||
211 | newLineValue = line.match(fullLineRegexp)[1]; | ||
212 | if (newLineValue != "\n") { | ||
213 | isMultiline = true; | ||
214 | } | ||
215 | fieldValue += newLineValue; | ||
216 | //MochiKit.Logging.logDebug("8 - fieldValue: " + fieldValue); | ||
217 | line = RegExp.rightContext; | ||
218 | //MochiKit.Logging.logDebug("9 - line: " + line.replace(/\n/g, "\\n").substring(0,50)); | ||
219 | //MochiKit.Logging.logDebug("10 - fieldLabelRegexp.test(line): " + fieldLabelRegexp.test(line) + " - recordLabelRegexp.test(line): " + recordLabelRegexp.test(line)); | ||
220 | } | ||
221 | |||
222 | if (isMultiline) { | ||
223 | fieldValue = fieldValue.replace(/\n$/g, ""); | ||
224 | } else { | ||
225 | fieldValue = fieldValue.replace(/\n\n$/g, ""); | ||
226 | } | ||
227 | |||
228 | line = line.replace(/^\n/, ''); | ||
229 | } | ||
230 | //MochiKit.Logging.logDebug("5 - fieldValue: " + fieldValue); | ||
231 | |||
232 | result[fieldName] = fieldValue; | ||
233 | //MochiKit.Logging.logDebug("6 - line: " + line.replace(/\n/g, "\\n").substring(0,50)); | ||
234 | //MochiKit.Logging.logDebug("---------------------------------------"); | ||
235 | } | ||
236 | } else { | ||
237 | //MochiKit.Logging.logDebug("2.0"); | ||
238 | result = null; | ||
239 | } | ||
240 | |||
241 | aContext.line = line; | ||
242 | //MochiKit.Logging.logDebug("#######################################"); | ||
243 | |||
244 | return result; | ||
245 | }, | ||
246 | |||
247 | //------------------------------------------------------------------------- | ||
248 | __syntaxFix__: "syntax fix" | ||
249 | }); | ||
250 | |||
251 | |||