summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/KeePassExportProcessor.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/Clipperz/KeePassExportProcessor.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/KeePassExportProcessor.js196
1 files changed, 196 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/KeePassExportProcessor.js b/frontend/gamma/js/Clipperz/KeePassExportProcessor.js
new file mode 100644
index 0000000..06ab5a8
--- a/dev/null
+++ b/frontend/gamma/js/Clipperz/KeePassExportProcessor.js
@@ -0,0 +1,196 @@
1/*
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer 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
29if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
30
31
32Clipperz.KeePassExportProcessor = function(args) {
33 args = args || {};
34
35 return this;
36}
37
38//=============================================================================
39
40Clipperz.KeePassExportProcessor.prototype = MochiKit.Base.update(null, {
41
42 //-------------------------------------------------------------------------
43
44 'deferredParse_core': function(aContext) {
45 var deferredResult;
46
47 if (aContext.line == "") {
48 deferredResult = MochiKit.Async.succeed(aContext.result);
49 } else {
50 var record;
51
52 record = this.parseRecord(aContext);
53 if (record != null) {
54 aContext.result.push(record);
55 }
56
57 aContext.line = aContext.line.replace(/^\n*/g, "").replace(/\n$/g, "");
58
59 deferredResult = new Clipperz.Async.Deferred("KeePassExportProcessor.deferredParse_core");
60 deferredResult.addCallbackPass(MochiKit.Signal.signal, this, 'importProcessorProgressUpdate', {status:'processing', size:aContext.size, progress:(aContext.size - aContext.line.length)});
61 deferredResult.addCallback(MochiKit.Async.wait, 0.2);
62 deferredResult.addMethod(this, 'deferredParse_core');
63 deferredResult.callback(aContext);
64 }
65
66 return deferredResult;
67 },
68
69 //.........................................................................
70
71 'deferredParse': function(aValue) {
72 var deferredResult;
73 var lines;
74 var context;
75
76 lines = aValue.replace(/\r?\n/g, "\n");
77 context = {
78 line: lines,
79 size: lines.length,
80 result: []
81 }
82
83 deferredResult = new Clipperz.Async.Deferred("KeePassExportProcessor.deferredResult");
84 deferredResult.addMethod(this, 'deferredParse_core');
85 deferredResult.callback(context);
86
87 return deferredResult;
88 },
89
90 //-------------------------------------------------------------------------
91
92 'parseRecord': function(aContext) {
93 var result;
94 var recordLabelRegexp;
95 varfieldLabelRegexp;
96 var fieldValueRegexp;
97 var fullLineRegexp;
98/*
99[Record name]
100Group Tree:
101UserName:
102URL:
103Password:
104Notes: test
105UUID: 525f62430079bae48b79ed2961924b05
106Icon: 0
107Creation Time: 2007-06-26 17:56:03
108Last Access: 2007-10-25 16:23:51
109Last Modification: 2007-10-25 16:23:51
110Expires: 2999-12-28 23:59:59
111
112 [Record name] ==> Title
113 Group: General ==> Group
114 Group Tree: ==> Group Tree
115 UserName: ==> UserName
116 URL: ==>URL
117 Password: ==>Password
118 Notes: test ==>Notes
119 UUID: 525f62430079bae48b79ed2961924b05 ==>UUID
120 Icon: 0 ==>Icon
121 Creation Time: 2007-06-26 17:56:03 ==>Creation Time
122 Last Access: 2007-10-25 16:23:51 ==>Last Access
123 Last Modification: 2007-10-25 16:23:51 ==>Last Modification
124 Expires: 2999-12-28 23:59:59 ==> Expires
125 Attachment Description: ==> Attachment Description
126 Attachment: ==> Attachment
127*/
128 // recordLabelRegexp = new RegExp("(^\\[(.*)\\]\\n|^Title:\s*(.*)\\n)");
129 recordLabelRegexp = new RegExp("^\\[(.*)\\]\\n|^Title:\s*(.*)\\n");
130 fieldLabelRegexp = new RegExp("^\s?(Group|Group Tree|Username|UserName|User Name|Url|URL|Password|Notes|Comment|UUID|Icon|Creation Time|Last Access|Last Modification|Expires|Attachment Description|Attachment|Valid until): ");
131 fieldValueRegexp = new RegExp("(.*)(\\n|$)");
132 fullLineRegexp = new RegExp("^(.*\\n)");
133
134 if (recordLabelRegexp.test(aContext.line) == true) {
135 var line;
136
137 line = aContext.line;
138
139 result = {};
140 result['Title'] = line.match(recordLabelRegexp)[1];
141 line = line.replace(/^.*\n/, "");
142 while (fieldLabelRegexp.test(line) == true) {
143 var fieldName;
144 var fieldValue;
145
146 fieldName = RegExp.$1;
147 line = RegExp.rightContext;
148
149 fieldValue = line.match(fieldValueRegexp)[1];
150 line = RegExp.rightContext;
151
152 if (fieldName == 'Notes') {
153 var isMultiline;
154
155 isMultiline = false;
156
157 if ((line != "") && (fieldLabelRegexp.test(line) == false) && (recordLabelRegexp.test(line) == false)) {
158 fieldValue += '\n';
159 }
160
161 while ((line != "") && (fieldLabelRegexp.test(line) == false) && (recordLabelRegexp.test(line) == false)) {
162 var newLineValue;
163
164 newLineValue = line.match(fullLineRegexp)[1];
165 if (newLineValue != "\n") {
166 isMultiline = true;
167 }
168 fieldValue += newLineValue;
169 line = RegExp.rightContext;
170 }
171
172 if (isMultiline) {
173 fieldValue = fieldValue.replace(/\n$/g, "");
174 } else {
175 fieldValue = fieldValue.replace(/\n\n$/g, "");
176 }
177
178 line = line.replace(/^\n/, '');
179 }
180
181 result[fieldName] = fieldValue;
182 }
183 } else {
184 result = null;
185 }
186
187 aContext.line = line;
188
189 return result;
190 },
191
192 //-------------------------------------------------------------------------
193 __syntaxFix__: "syntax fix"
194});
195
196