author | Giulio Cesare Solaroli <giulio.cesare@solaroli.it> | 2011-10-03 16:04:12 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@solaroli.it> | 2011-10-03 16:04:12 (UTC) |
commit | 541bb378ddece2eab135a8066a16994e94436dea (patch) (unidiff) | |
tree | ff160ea3e26f7fe07fcfd401387c5a0232ca715e /frontend/gamma/js/Clipperz/KeePassExportProcessor.js | |
parent | 1bf431fd3d45cbdf4afa3e12afefe5d24f4d3bc7 (diff) | |
parent | ecad5e895831337216544e81f1a467e0c68c4a6a (diff) | |
download | clipperz-541bb378ddece2eab135a8066a16994e94436dea.zip clipperz-541bb378ddece2eab135a8066a16994e94436dea.tar.gz clipperz-541bb378ddece2eab135a8066a16994e94436dea.tar.bz2 |
Merge pull request #1 from gcsolaroli/master
First version of the restructured repository
Diffstat (limited to 'frontend/gamma/js/Clipperz/KeePassExportProcessor.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/KeePassExportProcessor.js | 196 |
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 | |||
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 | '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] | ||
100 | Group Tree: | ||
101 | UserName: | ||
102 | URL: | ||
103 | Password: | ||
104 | Notes: test | ||
105 | UUID: 525f62430079bae48b79ed2961924b05 | ||
106 | Icon: 0 | ||
107 | Creation Time: 2007-06-26 17:56:03 | ||
108 | Last Access: 2007-10-25 16:23:51 | ||
109 | Last Modification: 2007-10-25 16:23:51 | ||
110 | Expires: 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 | |||