author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-23 17:36:57 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-23 17:36:57 (UTC) |
commit | 67455b069c4c9ec493f9cef76017e172a430a7d4 (patch) (unidiff) | |
tree | 0b287debfeeb0819b3df9dd02860cd84103e25b3 | |
parent | b312e037ebba7c94abea9661bcf62c52b7d73fbf (diff) | |
download | clipperz-67455b069c4c9ec493f9cef76017e172a430a7d4.zip clipperz-67455b069c4c9ec493f9cef76017e172a430a7d4.tar.gz clipperz-67455b069c4c9ec493f9cef76017e172a430a7d4.tar.bz2 |
Integration of PHP backend with /beta and /gamma front ends
Fixed PHP backend and /beta code to handle request and data format compatible with /gamma.
At the moment adding/deleting/editing records seem to work fine.
-rw-r--r-- | backend/php/src/configuration.php | 6 | ||||
-rw-r--r-- | backend/php/src/index.php | 189 | ||||
-rw-r--r-- | frontend/beta/js/Clipperz/PM/DataModel/Record.js | 7 | ||||
-rw-r--r-- | frontend/beta/js/Clipperz/PM/Proxy.js | 3 | ||||
-rwxr-xr-x | frontend/beta/js/Clipperz/PM/Proxy/Proxy.PHP.js | 262 | ||||
-rw-r--r-- | frontend/gamma/html/index_template.html | 5 | ||||
-rw-r--r-- | frontend/gamma/js/Clipperz/Async.js | 19 | ||||
-rw-r--r-- | frontend/gamma/js/Clipperz/PM/Proxy.js | 2 |
8 files changed, 205 insertions, 288 deletions
diff --git a/backend/php/src/configuration.php b/backend/php/src/configuration.php index 291e3a1..85f680e 100644 --- a/backend/php/src/configuration.php +++ b/backend/php/src/configuration.php | |||
@@ -1,36 +1,36 @@ | |||
1 | <?php | 1 | <?php |
2 | global $configuration; | 2 | global $configuration; |
3 | $configuration['soap'] = "http://www.phpobjectgenerator.com/services/soap.php?wsdl"; | 3 | $configuration['soap'] = "http://www.phpobjectgenerator.com/services/soap.php?wsdl"; |
4 | $configuration['homepage'] = "http://www.phpobjectgenerator.com"; | 4 | $configuration['homepage'] = "http://www.phpobjectgenerator.com"; |
5 | $configuration['revisionNumber'] = ""; | 5 | $configuration['revisionNumber'] = ""; |
6 | $configuration['versionNumber'] = "3.0d"; | 6 | $configuration['versionNumber'] = "3.0d"; |
7 | 7 | ||
8 | $configuration['setup_password'] = ''; | 8 | $configuration['setup_password'] = ''; |
9 | 9 | ||
10 | 10 | ||
11 | // to enable automatic data encoding, run setup, go to the manage plugins tab and install the base64 plugin. | 11 | // to enable automatic data encoding, run setup, go to the manage plugins tab and install the base64 plugin. |
12 | // then set db_encoding = 1 below. | 12 | // then set db_encoding = 1 below. |
13 | // when enabled, db_encoding transparently encodes and decodes data to and from the database without any | 13 | // when enabled, db_encoding transparently encodes and decodes data to and from the database without any |
14 | // programmatic effort on your part. | 14 | // programmatic effort on your part. |
15 | $configuration['db_encoding'] = 0; | 15 | $configuration['db_encoding'] = 0; |
16 | 16 | ||
17 | // edit the information below to match your database settings | 17 | // edit the information below to match your database settings |
18 | 18 | ||
19 | $configuration['db'] = 'clipperz'; //database name | 19 | $configuration['db'] = 'clipperz'; //database name |
20 | $configuration['host'] = 'localhost'; //database host | 20 | $configuration['host'] = 'localhost'; //database host |
21 | $configuration['user'] = 'root'; //database user | 21 | $configuration['user'] = 'clipperz'; //database user |
22 | $configuration['pass'] = 'pass'; //database password | 22 | $configuration['pass'] = 'clipperz'; //database password |
23 | $configuration['port'] = '3306'; //database port | 23 | $configuration['port'] = '3306'; //database port |
24 | 24 | ||
25 | 25 | ||
26 | //proxy settings - if you are behnd a proxy, change the settings below | 26 | //proxy settings - if you are behnd a proxy, change the settings below |
27 | $configuration['proxy_host'] = false; | 27 | $configuration['proxy_host'] = false; |
28 | $configuration['proxy_port'] = false; | 28 | $configuration['proxy_port'] = false; |
29 | $configuration['proxy_username'] = false; | 29 | $configuration['proxy_username'] = false; |
30 | $configuration['proxy_password'] = false; | 30 | $configuration['proxy_password'] = false; |
31 | 31 | ||
32 | 32 | ||
33 | //plugin settings | 33 | //plugin settings |
34 | $configuration['plugins_path'] = dirname(__FILE__).'/plugins'; | 34 | $configuration['plugins_path'] = dirname(__FILE__).'/plugins'; |
35 | 35 | ||
36 | ?> \ No newline at end of file | 36 | ?> \ No newline at end of file |
diff --git a/backend/php/src/index.php b/backend/php/src/index.php index 214ac01..da7c60c 100644 --- a/backend/php/src/index.php +++ b/backend/php/src/index.php | |||
@@ -1,755 +1,918 @@ | |||
1 | <?php | 1 | <?php |
2 | include "./configuration.php"; | 2 | include "./configuration.php"; |
3 | include "./objects/class.database.php"; | 3 | include "./objects/class.database.php"; |
4 | include "./objects/class.user.php"; | 4 | include "./objects/class.user.php"; |
5 | include "./objects/class.record.php"; | 5 | include "./objects/class.record.php"; |
6 | include "./objects/class.recordversion.php"; | 6 | include "./objects/class.recordversion.php"; |
7 | include "./objects/class.onetimepassword.php"; | 7 | include "./objects/class.onetimepassword.php"; |
8 | include "./objects/class.onetimepasswordstatus.php"; | 8 | include "./objects/class.onetimepasswordstatus.php"; |
9 | 9 | ||
10 | //----------------------------------------------------------------------------- | 10 | //----------------------------------------------------------------------------- |
11 | 11 | ||
12 | if ( !function_exists('json_decode') ) { | 12 | if ( !function_exists('json_decode') ) { |
13 | function json_decode($content, $assoc=false) { | 13 | function json_decode($content, $assoc=false) { |
14 | require_once 'json/JSON.php'; | 14 | require_once 'json/JSON.php'; |
15 | if ( $assoc ) { | 15 | if ( $assoc ) { |
16 | $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); | 16 | $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); |
17 | } else { | 17 | } else { |
18 | $json = new Services_JSON; | 18 | $json = new Services_JSON; |
19 | } | 19 | } |
20 | 20 | ||
21 | return $json->decode($content); | 21 | return $json->decode($content); |
22 | } | 22 | } |
23 | } | 23 | } |
24 | 24 | ||
25 | if ( !function_exists('json_encode') ) { | 25 | if ( !function_exists('json_encode') ) { |
26 | function json_encode($content) { | 26 | function json_encode($content) { |
27 | require_once 'json/JSON.php'; | 27 | require_once 'json/JSON.php'; |
28 | $json = new Services_JSON; | 28 | $json = new Services_JSON; |
29 | 29 | ||
30 | return $json->encode($content); | 30 | return $json->encode($content); |
31 | } | 31 | } |
32 | } | 32 | } |
33 | 33 | ||
34 | //----------------------------------------------------------------------------- | 34 | //----------------------------------------------------------------------------- |
35 | //'dec2base', 'base2dec' and 'digits' are functions found on the following | 35 | //'dec2base', 'base2dec' and 'digits' are functions found on the following |
36 | //PHP manual page: http://ch2.php.net/manual/en/ref.bc.php | 36 | //PHP manual page: http://ch2.php.net/manual/en/ref.bc.php |
37 | // | 37 | // |
38 | 38 | ||
39 | function dec2base($dec, $base, $digits=FALSE) { | 39 | function dec2base($dec, $base, $digits=FALSE) { |
40 | if ($base<2 or $base>256) { | 40 | if ($base<2 or $base>256) { |
41 | die("Invalid Base: ".$base); | 41 | die("Invalid Base: ".$base); |
42 | } | 42 | } |
43 | 43 | ||
44 | bcscale(0); | 44 | bcscale(0); |
45 | $value=""; | 45 | $value=""; |
46 | if (!$digits) { | 46 | if (!$digits) { |
47 | $digits = digits($base); | 47 | $digits = digits($base); |
48 | } | 48 | } |
49 | 49 | ||
50 | while ($dec > $base-1) { | 50 | while ($dec > $base-1) { |
51 | $rest = bcmod($dec, $base); | 51 | $rest = bcmod($dec, $base); |
52 | $dec = bcdiv($dec, $base); | 52 | $dec = bcdiv($dec, $base); |
53 | $value = $digits[$rest].$value; | 53 | $value = $digits[$rest].$value; |
54 | } | 54 | } |
55 | 55 | ||
56 | $value=$digits[intval($dec)].$value; | 56 | $value=$digits[intval($dec)].$value; |
57 | 57 | ||
58 | return (string)$value; | 58 | return (string)$value; |
59 | } | 59 | } |
60 | 60 | ||
61 | //............................................................................. | 61 | //............................................................................. |
62 | 62 | ||
63 | // convert another base value to its decimal value | 63 | // convert another base value to its decimal value |
64 | function base2dec($value, $base, $digits=FALSE) { | 64 | function base2dec($value, $base, $digits=FALSE) { |
65 | if ($base<2 or $base>256) { | 65 | if ($base<2 or $base>256) { |
66 | die("Invalid Base: ".$base); | 66 | die("Invalid Base: ".$base); |
67 | } | 67 | } |
68 | 68 | ||
69 | bcscale(0); | 69 | bcscale(0); |
70 | if ($base<37) { | 70 | if ($base<37) { |
71 | $value=strtolower($value); | 71 | $value=strtolower($value); |
72 | } | 72 | } |
73 | 73 | ||
74 | if (!$digits) { | 74 | if (!$digits) { |
75 | $digits=digits($base); | 75 | $digits=digits($base); |
76 | } | 76 | } |
77 | 77 | ||
78 | $size = strlen($value); | 78 | $size = strlen($value); |
79 | $dec="0"; | 79 | $dec="0"; |
80 | for ($loop=0; $loop<$size; $loop++) { | 80 | for ($loop=0; $loop<$size; $loop++) { |
81 | $element = strpos($digits, $value[$loop]); | 81 | $element = strpos($digits, $value[$loop]); |
82 | $power = bcpow($base, $size-$loop-1); | 82 | $power = bcpow($base, $size-$loop-1); |
83 | $dec = bcadd($dec, bcmul($element,$power)); | 83 | $dec = bcadd($dec, bcmul($element,$power)); |
84 | } | 84 | } |
85 | 85 | ||
86 | return (string)$dec; | 86 | return (string)$dec; |
87 | } | 87 | } |
88 | 88 | ||
89 | //............................................................................. | 89 | //............................................................................. |
90 | 90 | ||
91 | function digits($base) { | 91 | function digits($base) { |
92 | if ($base>64) { | 92 | if ($base>64) { |
93 | $digits=""; | 93 | $digits=""; |
94 | for ($loop=0; $loop<256; $loop++) { | 94 | for ($loop=0; $loop<256; $loop++) { |
95 | $digits.=chr($loop); | 95 | $digits.=chr($loop); |
96 | } | 96 | } |
97 | } else { | 97 | } else { |
98 | $digits ="0123456789abcdefghijklmnopqrstuvwxyz"; | 98 | $digits ="0123456789abcdefghijklmnopqrstuvwxyz"; |
99 | $digits.="ABCDEFGHIJKLMNOPQRSTUVWXYZ-_"; | 99 | $digits.="ABCDEFGHIJKLMNOPQRSTUVWXYZ-_"; |
100 | } | 100 | } |
101 | 101 | ||
102 | $digits=substr($digits,0,$base); | 102 | $digits=substr($digits,0,$base); |
103 | 103 | ||
104 | return (string)$digits; | 104 | return (string)$digits; |
105 | } | 105 | } |
106 | 106 | ||
107 | //----------------------------------------------------------------------------- | 107 | //----------------------------------------------------------------------------- |
108 | 108 | ||
109 | function clipperz_hash($value) { | 109 | function clipperz_hash($value) { |
110 | return hash("sha256", hash("sha256", $value, true)); | 110 | return hash("sha256", hash("sha256", $value, true)); |
111 | } | 111 | } |
112 | 112 | ||
113 | //----------------------------------------------------------------------------- | 113 | //----------------------------------------------------------------------------- |
114 | 114 | ||
115 | function clipperz_randomSeed() { | 115 | function clipperz_randomSeed() { |
116 | $result; | 116 | $result; |
117 | 117 | ||
118 | srand((double) microtime()*1000000); | 118 | srand((double) microtime()*1000000); |
119 | $result = ""; | 119 | $result = ""; |
120 | 120 | ||
121 | while(strlen($result) < 64) { | 121 | while(strlen($result) < 64) { |
122 | $result = $result.dec2base(rand(), 16); | 122 | $result = $result.dec2base(rand(), 16); |
123 | } | 123 | } |
124 | 124 | ||
125 | $result = substr($result, 0, 64); | 125 | $result = substr($result, 0, 64); |
126 | 126 | ||
127 | return $result; | 127 | return $result; |
128 | } | 128 | } |
129 | 129 | ||
130 | //----------------------------------------------------------------------------- | 130 | //----------------------------------------------------------------------------- |
131 | 131 | ||
132 | function updateUserCredentials($parameters, &$user) { | 132 | function updateUserCredentials($parameters, &$user) { |
133 | $user->username = $parameters["C"]; | 133 | $user->username = $parameters["C"]; |
134 | $user->srp_s = $parameters["s"]; | 134 | $user->srp_s = $parameters["s"]; |
135 | $user->srp_v = $parameters["v"]; | 135 | $user->srp_v = $parameters["v"]; |
136 | $user->auth_version =$parameters["version"]; | 136 | $user->auth_version =$parameters["version"]; |
137 | } | 137 | } |
138 | 138 | ||
139 | function updateUserData($parameters, &$user) { | 139 | function updateUserData($parameters, &$user) { |
140 | $user->header = $parameters["header"]; | 140 | $user->header = $parameters["header"]; |
141 | $user->statistics =$parameters["statistics"]; | 141 | $user->statistics =$parameters["statistics"]; |
142 | $user->version =$parameters["version"]; | 142 | $user->version =$parameters["version"]; |
143 | $user->lock = $parameters["lock"]; | 143 | if (array_key_exists("lock", $parameters)) { |
144 | $user->lock = $parameters["lock"]; | ||
145 | } | ||
144 | } | 146 | } |
145 | 147 | ||
146 | function updateRecordData($parameters, &$record, &$recordVersion) { | 148 | function updateRecordData($parameters, &$record, &$recordVersion) { |
147 | $recordData = $parameters["record"]; | 149 | $recordData = $parameters["record"]; |
148 | $record->reference =$recordData["reference"]; | 150 | $record->reference =$recordData["reference"]; |
149 | $record->data = $recordData["data"]; | 151 | $record->data = $recordData["data"]; |
150 | $record->version = $recordData["version"]; | 152 | $record->version = $recordData["version"]; |
151 | 153 | ||
152 | $recordVersionData = $parameters["currentRecordVersion"]; | 154 | $recordVersionData = $parameters["currentRecordVersion"]; |
153 | $recordVersion->reference = $recordVersionData ["reference"]; | 155 | $recordVersion->reference = $recordVersionData ["reference"]; |
154 | $recordVersion->data = $recordVersionData ["data"]; | 156 | $recordVersion->data = $recordVersionData ["data"]; |
155 | $recordVersion->version = $recordVersionData ["version"]; | 157 | $recordVersion->version = $recordVersionData ["version"]; |
156 | $recordVersion->previous_version_id =$recordVersionData ["previousVersion"]; | 158 | if (array_key_exists("previousVersion", $recordVersionData)) { |
159 | $recordVersion->previous_version_id =$recordVersionData ["previousVersion"]; | ||
160 | } | ||
157 | $recordVersion->previous_version_key =$recordVersionData ["previousVersionKey"]; | 161 | $recordVersion->previous_version_key =$recordVersionData ["previousVersionKey"]; |
158 | } | 162 | } |
159 | 163 | ||
160 | //----------------------------------------------------------------------------- | 164 | //----------------------------------------------------------------------------- |
161 | 165 | ||
162 | function updateOTPStatus(&$otp, $status) { | 166 | function updateOTPStatus(&$otp, $status) { |
163 | $otpStatus = new onetimepasswordstatus(); | 167 | $otpStatus = new onetimepasswordstatus(); |
164 | $selectedStatuses = $otpStatus->GetList(array(array("code", "=", $status))); | 168 | $selectedStatuses = $otpStatus->GetList(array(array("code", "=", $status))); |
165 | $otpStatus = $selectedStatuses[0]; | 169 | $otpStatus = $selectedStatuses[0]; |
166 | $otp->SetOnetimepasswordstatus($otpStatus); | 170 | $otp->SetOnetimepasswordstatus($otpStatus); |
167 | } | 171 | } |
168 | 172 | ||
169 | function updateOTP($parameters, &$otp, $status) { | 173 | function updateOTP($parameters, &$otp, $status) { |
170 | $otp->reference = $parameters["reference"]; | 174 | $otp->reference = $parameters["reference"]; |
171 | $otp->key = $parameters["key"]; | 175 | $otp->key = $parameters["key"]; |
172 | $otp->key_checksum= $parameters["keyChecksum"]; | 176 | $otp->key_checksum= $parameters["keyChecksum"]; |
173 | $otp->data = $parameters["data"]; | 177 | $otp->data = $parameters["data"]; |
174 | $otp->version = $parameters["version"]; | 178 | $otp->version = $parameters["version"]; |
175 | 179 | ||
176 | updateOTPStatus($otp, $status); | 180 | updateOTPStatus($otp, $status); |
177 | } | 181 | } |
178 | 182 | ||
179 | function resetOTP(&$otp, $status) { | 183 | function resetOTP(&$otp, $status) { |
180 | $otp->data = ""; | 184 | $otp->data = ""; |
181 | updateOTPStatus($otp, $status); | 185 | updateOTPStatus($otp, $status); |
182 | $otp->Save(); | 186 | $otp->Save(); |
183 | } | 187 | } |
184 | 188 | ||
185 | //----------------------------------------------------------------------------- | 189 | //----------------------------------------------------------------------------- |
186 | 190 | ||
187 | function fixOTPStatusTable() { | 191 | function fixOTPStatusTable() { |
188 | $otpStatus = new onetimepasswordstatus(); | 192 | $otpStatus = new onetimepasswordstatus(); |
189 | $otpStatusList = $otpStatus->GetList(); | 193 | $otpStatusList = $otpStatus->GetList(); |
190 | if (count($otpStatusList) != 4) { | 194 | if (count($otpStatusList) != 4) { |
191 | $otpStatus->DeleteList(); | 195 | $otpStatus->DeleteList(); |
192 | 196 | ||
193 | $otpStatus->code = "ACTIVE"; $otpStatus->name = "Active"; $otpStatus->description = "Active"; $otpStatus->SaveNew(); | 197 | $otpStatus->code = "ACTIVE"; $otpStatus->name = "Active"; $otpStatus->description = "Active"; $otpStatus->SaveNew(); |
194 | $otpStatus->code = "REQUESTED"; $otpStatus->name = "Requested"; $otpStatus->description = "Requested";$otpStatus->SaveNew(); | 198 | $otpStatus->code = "REQUESTED"; $otpStatus->name = "Requested"; $otpStatus->description = "Requested";$otpStatus->SaveNew(); |
195 | $otpStatus->code = "USED"; $otpStatus->name = "Used"; $otpStatus->description = "Used"; $otpStatus->SaveNew(); | 199 | $otpStatus->code = "USED"; $otpStatus->name = "Used"; $otpStatus->description = "Used"; $otpStatus->SaveNew(); |
196 | $otpStatus->code = "DISABLED"; $otpStatus->name = "Disabled"; $otpStatus->description = "Disabled";$otpStatus->SaveNew(); | 200 | $otpStatus->code = "DISABLED"; $otpStatus->name = "Disabled"; $otpStatus->description = "Disabled";$otpStatus->SaveNew(); |
197 | } | 201 | } |
198 | } | 202 | } |
199 | 203 | ||
200 | //----------------------------------------------------------------------------- | 204 | //----------------------------------------------------------------------------- |
201 | 205 | ||
202 | function arrayContainsValue($array, $value) { | 206 | function arrayContainsValue($array, $value) { |
203 | $object = NULL; | 207 | $object = NULL; |
204 | for ($i=0; $i<count($array); $i++) { | 208 | for ($i=0; $i<count($array); $i++) { |
205 | if ($array[$i] == $value) { | 209 | if ($array[$i] == $value) { |
206 | $object = $value; | 210 | $object = $value; |
207 | } | 211 | } |
208 | } | 212 | } |
209 | 213 | ||
210 | return !is_null($object); | 214 | return !is_null($object); |
211 | } | 215 | } |
212 | 216 | ||
213 | //----------------------------------------------------------------------------- | 217 | //----------------------------------------------------------------------------- |
214 | 218 | ||
215 | $result = Array(); | 219 | $result = Array(); |
216 | 220 | ||
217 | session_start(); | 221 | session_start(); |
218 | 222 | ||
219 | $method = $_POST['method']; | 223 | $method = $_POST['method']; |
220 | 224 | ||
221 | if (get_magic_quotes_gpc()) { | 225 | if (get_magic_quotes_gpc()) { |
222 | $parameters = json_decode(stripslashes($_POST['parameters']), true); | 226 | $parameters = json_decode(stripslashes($_POST['parameters']), true); |
223 | } else { | 227 | } else { |
224 | $parameters = json_decode($_POST['parameters'], true); | 228 | $parameters = json_decode($_POST['parameters'], true); |
225 | } | 229 | } |
226 | 230 | ||
227 | $parameters = $parameters["parameters"]; | 231 | $parameters = $parameters["parameters"]; |
228 | 232 | ||
229 | switch($method) { | 233 | switch($method) { |
230 | case "registration": | 234 | case "registration": |
231 | error_log("registration"); | 235 | error_log("registration"); |
232 | $message = $parameters["message"]; | 236 | $message = $parameters["message"]; |
233 | 237 | ||
234 | if ($message == "completeRegistration") { | 238 | if ($message == "completeRegistration") { |
235 | $user = new user(); | 239 | $user = new user(); |
236 | 240 | ||
237 | updateUserCredentials($parameters["credentials"], $user); | 241 | updateUserCredentials($parameters["credentials"], $user); |
238 | updateUserData($parameters["user"], $user); | 242 | updateUserData($parameters["user"], $user); |
239 | $user->Save(); | 243 | $user->Save(); |
240 | 244 | ||
241 | $result["lock"] = $user->lock; | 245 | $result["lock"] = $user->lock; |
242 | $result["result"] = "done"; | 246 | $result["result"] = "done"; |
243 | } | 247 | } |
244 | break; | 248 | break; |
245 | 249 | ||
246 | case "handshake": | 250 | case "handshake": |
247 | error_log("handshake"); | 251 | error_log("handshake"); |
248 | $srp_g = "2"; | 252 | $srp_g = "2"; |
249 | $srp_n = base2dec("115b8b692e0e045692cf280b436735c77a5a9e8a9e7ed56c965f87db5b2a2ece3", 16); | 253 | $srp_n = base2dec("115b8b692e0e045692cf280b436735c77a5a9e8a9e7ed56c965f87db5b2a2ece3", 16); |
250 | 254 | ||
251 | $message = $parameters["message"]; | 255 | $message = $parameters["message"]; |
252 | 256 | ||
253 | //============================================================= | 257 | //============================================================= |
254 | if ($message == "connect") { | 258 | if ($message == "connect") { |
255 | $user= new user(); | 259 | $user= new user(); |
256 | $_SESSION["C"] = $parameters["parameters"]["C"]; | 260 | $_SESSION["C"] = $parameters["parameters"]["C"]; |
257 | $_SESSION["A"] = $parameters["parameters"]["A"]; | 261 | $_SESSION["A"] = $parameters["parameters"]["A"]; |
258 | 262 | ||
259 | $userList = $user->GetList(array(array("username", "=", $_SESSION["C"]))); | 263 | $userList = $user->GetList(array(array("username", "=", $_SESSION["C"]))); |
260 | 264 | ||
261 | if (count($userList) == 1) { | 265 | if (count($userList) == 1) { |
262 | $currentUser = $userList[ 0 ]; | 266 | $currentUser = $userList[ 0 ]; |
263 | 267 | ||
264 | if (array_key_exists("otpId", $_SESSION)) { | 268 | if (array_key_exists("otpId", $_SESSION)) { |
265 | $otp = new onetimepassword(); | 269 | $otp = new onetimepassword(); |
266 | $otp = $otp->Get($_SESSION["otpId"]); | 270 | $otp = $otp->Get($_SESSION["otpId"]); |
267 | 271 | ||
268 | if ($otp->GetUser()->userId != $currentUser->userId) { | 272 | if ($otp->GetUser()->userId != $currentUser->userId) { |
269 | throw new Exception("User missmatch between the current session and 'One Time Password' user"); | 273 | throw new Exception("User missmatch between the current session and 'One Time Password' user"); |
270 | } else if ($otp->GetOnetimepasswordstatus()->code != "REQUESTED") { | 274 | } else if ($otp->GetOnetimepasswordstatus()->code != "REQUESTED") { |
271 | throw new Exception("Tring to use an 'One Time Password' in the wrong state"); | 275 | throw new Exception("Tring to use an 'One Time Password' in the wrong state"); |
272 | } | 276 | } |
273 | 277 | ||
274 | resetOTP($otp, "USED"); | 278 | resetOTP($otp, "USED"); |
275 | $result["oneTimePassword"] = $otp->reference; | 279 | $result["oneTimePassword"] = $otp->reference; |
276 | } | 280 | } |
277 | 281 | ||
278 | $_SESSION["s"] = $currentUser->srp_s; | 282 | $_SESSION["s"] = $currentUser->srp_s; |
279 | $_SESSION["v"] = $currentUser->srp_v; | 283 | $_SESSION["v"] = $currentUser->srp_v; |
280 | $_SESSION["userId"] = $currentUser->userId; | 284 | $_SESSION["userId"] = $currentUser->userId; |
281 | } else { | 285 | } else { |
282 | $_SESSION["s"] = "112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00"; | 286 | $_SESSION["s"] = "112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00"; |
283 | $_SESSION["v"] = "112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00"; | 287 | $_SESSION["v"] = "112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00"; |
284 | } | 288 | } |
285 | 289 | ||
286 | $_SESSION["b"] = clipperz_randomSeed(); | 290 | $_SESSION["b"] = clipperz_randomSeed(); |
287 | // $_SESSION["b"] = "5761e6c84d22ea3c5649de01702d60f674ccfe79238540eb34c61cd020230c53"; | 291 | // $_SESSION["b"] = "5761e6c84d22ea3c5649de01702d60f674ccfe79238540eb34c61cd020230c53"; |
288 | $_SESSION["B"] = dec2base(bcadd(base2dec($_SESSION["v"], 16), bcpowmod($srp_g, base2dec($_SESSION["b"], 16), $srp_n)), 16); | 292 | $_SESSION["B"] = dec2base(bcadd(base2dec($_SESSION["v"], 16), bcpowmod($srp_g, base2dec($_SESSION["b"], 16), $srp_n)), 16); |
289 | 293 | ||
290 | $result["s"] = $_SESSION["s"]; | 294 | $result["s"] = $_SESSION["s"]; |
291 | $result["B"] = $_SESSION["B"]; | 295 | $result["B"] = $_SESSION["B"]; |
292 | 296 | ||
293 | //============================================================= | 297 | //============================================================= |
294 | } else if ($message == "credentialCheck") { | 298 | } else if ($message == "credentialCheck") { |
295 | error_log("credentialCheck"); | 299 | error_log("credentialCheck"); |
296 | $u = clipperz_hash(base2dec($_SESSION["B"],16)); | 300 | $u = clipperz_hash(base2dec($_SESSION["B"],16)); |
297 | $A = base2dec($_SESSION["A"], 16); | 301 | $A = base2dec($_SESSION["A"], 16); |
298 | $S = bcpowmod(bcmul($A, bcpowmod(base2dec($_SESSION["v"], 16), base2dec($u, 16), $srp_n)), base2dec($_SESSION["b"], 16), $srp_n); | 302 | $S = bcpowmod(bcmul($A, bcpowmod(base2dec($_SESSION["v"], 16), base2dec($u, 16), $srp_n)), base2dec($_SESSION["b"], 16), $srp_n); |
299 | $K = clipperz_hash($S); | 303 | $K = clipperz_hash($S); |
300 | $M1 = clipperz_hash($A.base2dec($_SESSION["B"],16).$K); | 304 | $M1 = clipperz_hash($A.base2dec($_SESSION["B"],16).$K); |
301 | 305 | ||
302 | //$result["B"] = $_SESSION["B"]; | 306 | //$result["B"] = $_SESSION["B"]; |
303 | //$result["u"] = $u; | 307 | //$result["u"] = $u; |
304 | //$result["A"] = $A; | 308 | //$result["A"] = $A; |
305 | //$result["S"] = $S; | 309 | //$result["S"] = $S; |
306 | //$result["K"] = $K; | 310 | //$result["K"] = $K; |
307 | //$result["M1"] = $M1; | 311 | //$result["M1"] = $M1; |
308 | //$result["_M1"] = $parameters["parameters"]["M1"]; | 312 | //$result["_M1"] = $parameters["parameters"]["M1"]; |
309 | 313 | ||
310 | if ($M1 == $parameters["parameters"]["M1"]) { | 314 | if ($M1 == $parameters["parameters"]["M1"]) { |
311 | $_SESSION["K"] = $K; | 315 | $_SESSION["K"] = $K; |
312 | $M2 = clipperz_hash($A.$M1.$K); | 316 | $M2 = clipperz_hash($A.$M1.$K); |
313 | 317 | ||
314 | $result["M2"] = $M2; | 318 | $result["M2"] = $M2; |
315 | $result["connectionId"] = ""; | 319 | $result["connectionId"] = ""; |
316 | $result["loginInfo"] = array(); | 320 | $result["loginInfo"] = array(); |
317 | $result["loginInfo"]["latest"] = array(); | 321 | $result["loginInfo"]["latest"] = array(); |
318 | $result["loginInfo"]["current"] = array(); | 322 | $result["loginInfo"]["current"] = array(); |
319 | $result["offlineCopyNeeded"] = "false"; | 323 | $result["offlineCopyNeeded"] = "false"; |
320 | $result["lock"] = "----"; | 324 | $result["lock"] = "----"; |
321 | } else { | 325 | } else { |
322 | $result["error"] = "?"; | 326 | $result["error"] = "?"; |
323 | } | 327 | } |
324 | //============================================================= | 328 | //============================================================= |
325 | } else if ($message == "oneTimePassword") { | 329 | } else if ($message == "oneTimePassword") { |
326 | error_log("oneTimePassword"); | 330 | error_log("oneTimePassword"); |
327 | //{ | 331 | //{ |
328 | //"message":"oneTimePassword", | 332 | //"message":"oneTimePassword", |
329 | //"version":"0.2", | 333 | //"version":"0.2", |
330 | //"parameters":{ | 334 | //"parameters":{ |
331 | // "oneTimePasswordKey":"06dfa7f428081f8b2af98b0895e14e18af90b0ef2ff32828e55cc2ac6b24d29b", | 335 | // "oneTimePasswordKey":"06dfa7f428081f8b2af98b0895e14e18af90b0ef2ff32828e55cc2ac6b24d29b", |
332 | // "oneTimePasswordKeyChecksum":"60bcba3f72e56f6bb3f0ff88509b9a0e5ec730dfa71daa4c1e892dbd1b0c360d" | 336 | // "oneTimePasswordKeyChecksum":"60bcba3f72e56f6bb3f0ff88509b9a0e5ec730dfa71daa4c1e892dbd1b0c360d" |
333 | //} | 337 | //} |
334 | //} | 338 | //} |
335 | $otp = new onetimepassword(); | 339 | $otp = new onetimepassword(); |
336 | $otpList = $otp->GetList(array(array("key", "=", $parameters["parameters"]["oneTimePasswordKey"]))); | 340 | $otpList = $otp->GetList(array(array("key", "=", $parameters["parameters"]["oneTimePasswordKey"]))); |
337 | 341 | ||
338 | if (count($otpList) == 1) { | 342 | if (count($otpList) == 1) { |
339 | $currentOtp = $otpList[0]; | 343 | $currentOtp = $otpList[0]; |
340 | 344 | ||
341 | if ($currentOtp->GetOnetimepasswordstatus()->code == "ACTIVE") { | 345 | if ($currentOtp->GetOnetimepasswordstatus()->code == "ACTIVE") { |
342 | if ($currentOtp->key_checksum == $parameters["parameters"]["oneTimePasswordKeyChecksum"]) { | 346 | if ($currentOtp->key_checksum == $parameters["parameters"]["oneTimePasswordKeyChecksum"]) { |
343 | $_SESSION["userId"] = $currentOtp->GetUser()->userId; | 347 | $_SESSION["userId"] = $currentOtp->GetUser()->userId; |
344 | $_SESSION["otpId"]= $currentOtp->onetimepasswordId; | 348 | $_SESSION["otpId"]= $currentOtp->onetimepasswordId; |
345 | 349 | ||
346 | $result["data"] = $currentOtp->data; | 350 | $result["data"] = $currentOtp->data; |
347 | $result["version"] = $currentOtp->version; | 351 | $result["version"] = $currentOtp->version; |
348 | 352 | ||
349 | resetOTP($currentOtp, "REQUESTED"); | 353 | resetOTP($currentOtp, "REQUESTED"); |
350 | } else { | 354 | } else { |
351 | resetOTP($currentOtp, "DISABLED"); | 355 | resetOTP($currentOtp, "DISABLED"); |
352 | throw new Exception("The requested One Time Password has been disabled, due to a wrong keyChecksum"); | 356 | throw new Exception("The requested One Time Password has been disabled, due to a wrong keyChecksum"); |
353 | } | 357 | } |
354 | } else { | 358 | } else { |
355 | throw new Exception("The requested One Time Password was not active"); | 359 | throw new Exception("The requested One Time Password was not active"); |
356 | } | 360 | } |
357 | } else { | 361 | } else { |
358 | throw new Exception("The requested One Time Password has not been found"); | 362 | throw new Exception("The requested One Time Password has not been found"); |
359 | } | 363 | } |
360 | 364 | ||
361 | //============================================================= | 365 | //============================================================= |
362 | } | 366 | } |
363 | 367 | ||
364 | break; | 368 | break; |
365 | 369 | ||
366 | case "message": | 370 | case "message": |
367 | error_log("message"); | 371 | error_log("message"); |
372 | //error_log("message: ".json_encode($parameters)); | ||
368 | if ($parameters["srpSharedSecret"] == $_SESSION["K"]) { | 373 | if ($parameters["srpSharedSecret"] == $_SESSION["K"]) { |
369 | $message = $parameters["message"]; | 374 | $message = $parameters["message"]; |
370 | 375 | ||
371 | //============================================================= | 376 | //============================================================= |
372 | if ($message == "getUserDetails") { | 377 | if ($message == "getUserDetails") { |
373 | //{"message":"getUserDetails", "srpSharedSecret":"f18e5cf7c3a83b67d4db9444af813ee48c13daf4f8f6635397d593e52ba89a08", "parameters":{}} | 378 | //{"message":"getUserDetails", "srpSharedSecret":"f18e5cf7c3a83b67d4db9444af813ee48c13daf4f8f6635397d593e52ba89a08", "parameters":{}} |
374 | $user = new user(); | 379 | $user = new user(); |
375 | $user = $user->Get($_SESSION["userId"]); | 380 | $user = $user->Get($_SESSION["userId"]); |
376 | 381 | ||
377 | $result["header"] = $user->header; | 382 | $result["header"] = $user->header; |
378 | 383 | ||
379 | $records = $user->GetRecordList(); | 384 | $records = $user->GetRecordList(); |
380 | foreach ($records as $record) { | 385 | foreach ($records as $record) { |
381 | $recordStats["updateDate"] = $record->update_date; | 386 | $recordStats["updateDate"] = $record->update_date; |
382 | $recordsStats[$record->reference] = $recordStats; | 387 | $recordsStats[$record->reference] = $recordStats; |
383 | } | 388 | } |
384 | $result["recordsStats"] = $recordsStats; | 389 | $result["recordsStats"] = $recordsStats; |
385 | 390 | ||
386 | $result["statistics"] =$user->statistics; | 391 | $result["statistics"] =$user->statistics; |
387 | $result["version"] =$user->version; | 392 | $result["version"] =$user->version; |
388 | 393 | ||
389 | //============================================================= | 394 | //============================================================= |
390 | } else if ($message == "addNewRecords") { | 395 | } else if ($message == "addNewRecords") { |
391 | /* | 396 | /* |
392 | //{ | 397 | //{ |
393 | //"message":"addNewRecords", | 398 | //"message":"addNewRecords", |
394 | //"srpSharedSecret":"b58fdf62acebbcb67f63d28c0437f166069f45690c648cd4376a792ae7a325f7", | 399 | //"srpSharedSecret":"b58fdf62acebbcb67f63d28c0437f166069f45690c648cd4376a792ae7a325f7", |
395 | //"parameters":{ | 400 | //"parameters":{ |
396 | // "records":[ | 401 | // "records":[ |
397 | // { | 402 | // { |
398 | // "record":{ | 403 | // "record":{ |
399 | // "reference":"fda703707fee1fff42443124cd0e705f5bea0ac601758d81b2e832705339a610", | 404 | // "reference":"fda703707fee1fff42443124cd0e705f5bea0ac601758d81b2e832705339a610", |
400 | // "data":"OBSGtcb6blXq/xaYG.....4EqlQqgAvITN", | 405 | // "data":"OBSGtcb6blXq/xaYG.....4EqlQqgAvITN", |
401 | // "version":"0.3" | 406 | // "version":"0.3" |
402 | // }, | 407 | // }, |
403 | // "currentRecordVersion":{ | 408 | // "currentRecordVersion":{ |
404 | // "reference":"83ad301525c18f2afd72b6ac82c0a713382e1ef70ac69935ca7e2869dd4ff980", | 409 | // "reference":"83ad301525c18f2afd72b6ac82c0a713382e1ef70ac69935ca7e2869dd4ff980", |
405 | // "recordReference":"fda703707fee1fff42443124cd0e705f5bea0ac601758d81b2e832705339a610", | 410 | // "recordReference":"fda703707fee1fff42443124cd0e705f5bea0ac601758d81b2e832705339a610", |
406 | // "data":"NXJ5jiZhkd0CMiwwntAq....1TjjF+SGfE=", | 411 | // "data":"NXJ5jiZhkd0CMiwwntAq....1TjjF+SGfE=", |
407 | // "version":"0.3", | 412 | // "version":"0.3", |
408 | // "previousVersion":"3e174a86afc322271d8af28bc062b0f1bfd7344fad01212cd08b2757c4b199c4", | 413 | // "previousVersion":"3e174a86afc322271d8af28bc062b0f1bfd7344fad01212cd08b2757c4b199c4", |
409 | // "previousVersionKey":"kozaaGCzXWr71LbOKu6Z3nz520V..5U85tSBvb+u44twttv54Kw==" | 414 | // "previousVersionKey":"kozaaGCzXWr71LbOKu6Z3nz520V..5U85tSBvb+u44twttv54Kw==" |
410 | // } | 415 | // } |
411 | // } | 416 | // } |
412 | // ], | 417 | // ], |
413 | // "user":{ | 418 | // "user":{ |
414 | // "header":"{\"reco...ersion\":\"0.1\"}", | 419 | // "header":"{\"reco...ersion\":\"0.1\"}", |
415 | // "statistics":"rKI6nR6iqggygQJ3SQ58bFUX", | 420 | // "statistics":"rKI6nR6iqggygQJ3SQ58bFUX", |
416 | // "version":"0.3", | 421 | // "version":"0.3", |
417 | // "lock":"----" | 422 | // "lock":"----" |
418 | // } | 423 | // } |
419 | //} | 424 | //} |
420 | //} | 425 | //} |
421 | */ | 426 | */ |
422 | $user = new user(); | 427 | $user = new user(); |
423 | $record = new record(); | 428 | $record = new record(); |
424 | $recordVersion = new recordversion(); | 429 | $recordVersion = new recordversion(); |
425 | 430 | ||
426 | $user = $user->Get($_SESSION["userId"]); | 431 | $user = $user->Get($_SESSION["userId"]); |
427 | updateUserData($parameters["parameters"]["user"], $user); | 432 | updateUserData($parameters["parameters"]["user"], $user); |
428 | 433 | ||
429 | $recordParameterList = $parameters["parameters"]["records"]; | 434 | $recordParameterList = $parameters["parameters"]["records"]; |
430 | $c = count($recordParameterList); | 435 | $c = count($recordParameterList); |
431 | for ($i=0; $i<$c; $i++) { | 436 | for ($i=0; $i<$c; $i++) { |
432 | updateRecordData($recordParameterList[$i], $record, $recordVersion); | 437 | updateRecordData($recordParameterList[$i], $record, $recordVersion); |
433 | 438 | ||
434 | $record->SaveNew(); | 439 | $record->SaveNew(); |
435 | $recordVersion->SaveNew(); | 440 | $recordVersion->SaveNew(); |
436 | 441 | ||
437 | $record->AddRecordversion($recordVersion); | 442 | $record->AddRecordversion($recordVersion); |
438 | $user->AddRecord($record); | 443 | $user->AddRecord($record); |
439 | 444 | ||
440 | $record->Save(); | 445 | $record->Save(); |
441 | $recordVersion->Save(); | 446 | $recordVersion->Save(); |
442 | } | 447 | } |
443 | 448 | ||
444 | $user->Save(); | 449 | $user->Save(); |
445 | 450 | ||
446 | $result["lock"] = $user->lock; | 451 | $result["lock"] = $user->lock; |
447 | $result["result"] = "done"; | 452 | $result["result"] = "done"; |
448 | 453 | ||
449 | //============================================================= | 454 | //============================================================= |
455 | } else if ($message == "saveChanges") { | ||
456 | |||
457 | //{ | ||
458 | // "message":"saveChanges", | ||
459 | // "srpSharedSecret":"edc78508907c942173818f7247fa64869ba80672a7aa8d27b8fa6bfe524fb9c8", | ||
460 | // "parameters":{ | ||
461 | // "records":{ | ||
462 | // "updated":[ | ||
463 | // { | ||
464 | // "currentRecordVersion":{ | ||
465 | // "previousVersionKey":"####", | ||
466 | // "reference":"08c8eb7ec528fbf987bbfb84fe2e960cf9ae937b19fbb5f05d8d90a7039fac6a", | ||
467 | // "data":"WYQ16AjodjsmyZDXa4MKxOju0F…beD/zXlbVb0Zj0ZI/N55bZ", | ||
468 | // "version":"0.3" | ||
469 | // }, | ||
470 | // "record":{ | ||
471 | // "reference":"83de5304f60a808e48a815c6203d7d3f24874d3f40faba420bbc60b376fcc356", | ||
472 | // "data":"B6uBuBE Aly0knvgrUppodDTGZQC…guizL9QvHCWyM bQQBGBVvHZ6LfA==", | ||
473 | // "version":"0.3" | ||
474 | // } | ||
475 | // } | ||
476 | // ], | ||
477 | // "deleted":[ | ||
478 | // | ||
479 | // ] | ||
480 | // }, | ||
481 | // "user":{ | ||
482 | // "header":"{\"rec…sion\":\"0.1\"}", | ||
483 | // "statistics":"e6iXVEM4i8ZatPZFCCads/9F", | ||
484 | // "version":"0.3" | ||
485 | // } | ||
486 | // } | ||
487 | //} | ||
488 | $user = new user(); | ||
489 | $user = $user->Get($_SESSION["userId"]); | ||
490 | updateUserData($parameters["parameters"]["user"], $user); | ||
491 | |||
492 | $recordToUpdateParameterList = $parameters["parameters"]["records"]["updated"]; | ||
493 | $c = count($recordToUpdateParameterList); | ||
494 | for ($i=0; $i<$c; $i++) { | ||
495 | $recordList = $user->GetRecordList(array(array("reference", "=", $recordToUpdateParameterList [$i]["record"]["reference"]))); | ||
496 | if (count($recordList) == 0) { | ||
497 | $currentRecord = new record(); | ||
498 | $currentVersion = new recordversion(); | ||
499 | $isNewRecord = true; | ||
500 | } else { | ||
501 | $currentRecord = $recordList[0]; | ||
502 | $currentRecordVersions = $currentRecord->GetRecordversionList(); | ||
503 | $currentVersion = $currentRecordVersions[0]; | ||
504 | $isNewRecord = false; | ||
505 | } | ||
506 | |||
507 | updateRecordData($recordToUpdateParameterList[$i], $currentRecord, $currentVersion); | ||
508 | |||
509 | if ($isNewRecord == true) { | ||
510 | $currentRecord->SaveNew(); | ||
511 | $currentVersion->SaveNew(); | ||
512 | |||
513 | $currentRecord->AddRecordversion($currentVersion); | ||
514 | $user->AddRecord($currentRecord); | ||
515 | } | ||
516 | |||
517 | $currentRecord->Save(); | ||
518 | $currentVersion->Save(); | ||
519 | } | ||
520 | |||
521 | $user->Save(); | ||
522 | |||
523 | $recordToDeleteReferenceList = $parameters["parameters"]["records"]["deleted"]; | ||
524 | $recordList = array(); | ||
525 | $c = count($recordToDeleteReferenceList); | ||
526 | for ($i=0; $i<$c; $i++) { | ||
527 | array_push($recordList, array("reference", "=", $recordToDeleteReferenceList[$i])); | ||
528 | } | ||
529 | |||
530 | $record = new record(); | ||
531 | $record->DeleteList($recordList, true); | ||
532 | |||
533 | $result["lock"] = $user->lock; | ||
534 | $result["result"] = "done"; | ||
535 | |||
536 | //============================================================= | ||
450 | } else if ($message == "getRecordDetail") { | 537 | } else if ($message == "getRecordDetail") { |
451 | //{ | 538 | //{ |
452 | //"message":"getRecordDetail", | 539 | //"message":"getRecordDetail", |
453 | //"srpSharedSecret":"4c00dcb66a9f2aea41a87e4707c526874e2eb29cc72d2c7086837e53d6bf2dfe", | 540 | //"srpSharedSecret":"4c00dcb66a9f2aea41a87e4707c526874e2eb29cc72d2c7086837e53d6bf2dfe", |
454 | //"parameters":{ | 541 | //"parameters":{ |
455 | // "reference":"740009737139a189cfa2b1019a6271aaa39467b59e259706564b642ff3838d50" | 542 | // "reference":"740009737139a189cfa2b1019a6271aaa39467b59e259706564b642ff3838d50" |
456 | //} | 543 | //} |
457 | //} | 544 | //} |
458 | // | 545 | // |
459 | //result = { | 546 | //result = { |
460 | // currentVersion:{ | 547 | // currentVersion:{ |
461 | // reference:"88943d709c3ea2442d4f58eaaec6409276037e5a37e0a6d167b9dad9e947e854", | 548 | // reference:"88943d709c3ea2442d4f58eaaec6409276037e5a37e0a6d167b9dad9e947e854", |
462 | // accessDate:"Wed, 13 February 2008 14:25:12 UTC", | 549 | // accessDate:"Wed, 13 February 2008 14:25:12 UTC", |
463 | // creationDate:"Tue, 17 April 2007 17:17:52 UTC", | 550 | // creationDate:"Tue, 17 April 2007 17:17:52 UTC", |
464 | // version:"0.2", | 551 | // version:"0.2", |
465 | // data:"xI3WXddQLFtL......EGyKnnAVik", | 552 | // data:"xI3WXddQLFtL......EGyKnnAVik", |
466 | // updateDate:"Tue, 17 April 2007 17:17:52 UTC", | 553 | // updateDate:"Tue, 17 April 2007 17:17:52 UTC", |
467 | // header:"####" | 554 | // header:"####" |
468 | // } | 555 | // } |
469 | // reference:"13a5e52976337ab210903cd04872588e1b21fb72bc183e91aa25c494b8138551", | 556 | // reference:"13a5e52976337ab210903cd04872588e1b21fb72bc183e91aa25c494b8138551", |
470 | // oldestUsedEncryptedVersion:"0.2", | 557 | // oldestUsedEncryptedVersion:"0.2", |
471 | // accessDate:"Wed, 13 February 2008 14:25:12 UTC", | 558 | // accessDate:"Wed, 13 February 2008 14:25:12 UTC", |
472 | // creationDate:"Wed, 14 March 2007 13:53:11 UTC", | 559 | // creationDate:"Wed, 14 March 2007 13:53:11 UTC", |
473 | // version:"0.2", | 560 | // version:"0.2", |
474 | // updatedDate:"Tue, 17 April 2007 17:17:52 UTC", | 561 | // updatedDate:"Tue, 17 April 2007 17:17:52 UTC", |
475 | // data:"0/BjzyY6jeh71h...pAw2++NEyylGhMC5C5f5m8pBApYziN84s4O3JQ3khW/1UttQl4=" | 562 | // data:"0/BjzyY6jeh71h...pAw2++NEyylGhMC5C5f5m8pBApYziN84s4O3JQ3khW/1UttQl4=" |
476 | //} | 563 | //} |
564 | |||
565 | |||
566 | // #Actual result (causing error in /gamma) | ||
567 | //{ | ||
568 | // "result" : { | ||
569 | // "currentVersion" : { | ||
570 | // "reference" : "cb05177f96a832062c6b936d24323cb74a64e2ef1d97ee026cd1003755af7495", | ||
571 | // "data" : "RAnoHmikp7RmiZ2WVyEMW+Ia", | ||
572 | // "header" : "", | ||
573 | // "version" : "0.3", | ||
574 | // "creationDate" : "0000-00-00 00:00:00", | ||
575 | // "updateDate" : "2011-10-09 19:49:11", | ||
576 | // "accessDate" : "2011-10-09 19:49:11" | ||
577 | // }, | ||
578 | // "reference" : "b07e2afa2ba782b9f379649b36ded6de0452b43c27e6b887c7ce4f2a93f44346", | ||
579 | // "data" : "NtK1nkLUabbJQx5uO8ept...ZJ5dkJYYkyh3VQ==", | ||
580 | // "version" : "0.3", | ||
581 | // "creationDate" : "2011-10-09 19:49:11", | ||
582 | // "updateDate" : "Tue, 30 Nov 1999 00:00:00 +0000", | ||
583 | // "accessDate" : "0000-00-00 00:00:00", | ||
584 | // "oldestUsedEncryptedVersion" : "---" | ||
585 | // } | ||
586 | //} | ||
587 | |||
588 | |||
589 | // #Response from the online /gamma version | ||
590 | //{ | ||
591 | // "result" : { | ||
592 | // "versions" : { | ||
593 | // "e2c193f017ad4f6babf51de59f7550a40596afc0c27373b6a360e426b5bc06de" : { | ||
594 | // "reference" : "e2c193f017ad4f6babf51de59f7550a40596afc0c27373b6a360e426b5bc06de", | ||
595 | // "data" : "s\/3ClggH4uCcf+BkIMqQ...+W0PVt\/MJ3t7s1g0g", | ||
596 | // "creationDate" : "Mon, 10 October 2011 14:42:42 UTC", | ||
597 | // "header" : "####", | ||
598 | // "updateDate" : "Mon, 10 October 2011 14:42:42 UTC", | ||
599 | // "previousVersion" : "a96a6d8b9ac73fcdf874d8a8534ffb2d43da8f5222e96a4a29bd2ae437619463", | ||
600 | // "version" : "0.3", | ||
601 | // "accessDate" : "Mon, 10 October 2011 14:42:42 UTC", | ||
602 | // "previousVersionKey" : "####" | ||
603 | // }, | ||
604 | // [...] | ||
605 | // "a96a6d8b9ac73fcdf874d8a8534ffb2d43da8f5222e96a4a29bd2ae437619463" : { | ||
606 | // "reference" : "a96a6d8b9ac73fcdf874d8a8534ffb2d43da8f5222e96a4a29bd2ae437619463", | ||
607 | // "accessDate" : "Mon, 10 October 2011 14:41:17 UTC", | ||
608 | // "creationDate" : "Mon, 27 October 2008 08:16:14 UTC", | ||
609 | // "version" : "0.3", | ||
610 | // "data" : "m3yhZu81UAjCY6U2Kn...IUCb9suV0fldGOg=", | ||
611 | // "updateDate" : "Mon, 27 October 2008 08:16:14 UTC", | ||
612 | // "header" : "####" | ||
613 | // } | ||
614 | // }, | ||
615 | // "oldestUsedEncryptedVersion" : "0.2", | ||
616 | // "reference" : "36ec1a41118813ced3553534fa2607d781cba687768db305beed368a8e06e113", | ||
617 | // "data" : "frlUkTbaOWD9j2ROat...ruWioCK0Mss27oHjPg==", | ||
618 | // "creationDate" : "Wed, 14 March 2007 17:39:35 UTC", | ||
619 | // "version" : "0.3", | ||
620 | // "accessDate" : "Mon, 10 October 2011 14:45:12 UTC", | ||
621 | // "currentVersion" : "e2c193f017ad4f6babf51de59f7550a40596afc0c27373b6a360e426b5bc06de", | ||
622 | // "updatedDate" : "Mon, 10 October 2011 14:45:12 UTC" | ||
623 | // }, | ||
624 | // "toll" : { | ||
625 | // "requestType" : "MESSAGE", | ||
626 | // "targetValue" : "a516c942a3792cc620775a41f8870a6c7b51796d9a94da978a75da6a52eb1e10", | ||
627 | // "cost" : 2 | ||
628 | // } | ||
629 | // } | ||
630 | |||
477 | $record = new record(); | 631 | $record = new record(); |
478 | 632 | ||
479 | $recordList = $record->GetList(array(array("reference", "=", $parameters["parameters"]["reference"]))); | 633 | $recordList = $record->GetList(array(array("reference", "=", $parameters["parameters"]["reference"]))); |
480 | $currentRecord = $recordList[0]; | 634 | $currentRecord = $recordList[0]; |
481 | $currentRecordVersions = $currentRecord->GetRecordversionList(); | 635 | $currentRecordVersions = $currentRecord->GetRecordversionList(); |
482 | $currentVersion = $currentRecordVersions[0]; | 636 | $currentVersion = $currentRecordVersions[0]; |
483 | 637 | ||
484 | $result["currentVersion"] = array(); | 638 | $result["versions"] = array(); |
485 | $result["currentVersion"]["reference"] =$currentVersion->reference; | 639 | // foreach ($currentRecordVersions as $currentVersion) { |
486 | $result["currentVersion"]["data"] = $currentVersion->data; | 640 | $result["versions"][$currentVersion->reference] = array(); |
487 | $result["currentVersion"]["header"] = $currentVersion->header; | 641 | $result["versions"][$currentVersion->reference]["reference"]= $currentVersion->reference; |
488 | $result["currentVersion"]["version"] = $currentVersion->version; | 642 | $result["versions"][$currentVersion->reference]["data"] = $currentVersion->data; |
489 | $result["currentVersion"]["creationDate"] =$currentVersion->creation_date; | 643 | $result["versions"][$currentVersion->reference]["header"] = $currentVersion->header; |
490 | $result["currentVersion"]["updateDate"] =$currentVersion->update_date; | 644 | $result["versions"][$currentVersion->reference]["version"] = $currentVersion->version; |
491 | $result["currentVersion"]["accessDate"] =$currentVersion->access_date; | 645 | $result["versions"][$currentVersion->reference]["creationDate"]= $currentVersion->creation_date; |
646 | $result["versions"][$currentVersion->reference]["updateDate"]= $currentVersion->update_date; | ||
647 | $result["versions"][$currentVersion->reference]["accessDate"]= $currentVersion->access_date; | ||
648 | |||
649 | // } | ||
650 | $result["currentVersion"] = $currentVersion->reference; | ||
651 | // $result["currentVersion"] = $currentRecord->currentVersion; //???? | ||
492 | 652 | ||
493 | $result["reference"] = $currentRecord->reference; | 653 | $result["reference"] = $currentRecord->reference; |
494 | $result["data"] = $currentRecord->data; | 654 | $result["data"] = $currentRecord->data; |
495 | $result["version"] = $currentRecord->version; | 655 | $result["version"] = $currentRecord->version; |
496 | $result["creationDate"] =$currentRecord->creation_date; | 656 | $result["creationDate"] =$currentRecord->creation_date; |
497 | $result["updateDate"] = $currentRecord->update_date; | 657 | $result["updateDate"] = $currentRecord->update_date; |
498 | $result["accessDate"] = $currentRecord->access_date; | 658 | $result["accessDate"] = $currentRecord->access_date; |
499 | $result["oldestUsedEncryptedVersion"] ="---"; | 659 | $result["oldestUsedEncryptedVersion"] ="---"; |
500 | 660 | ||
501 | //============================================================= | 661 | //============================================================= |
502 | } else if ($message == "updateData") { | 662 | } else if ($message == "updateData") { |
503 | //{ | 663 | //{ |
504 | //"message":"updateData", | 664 | //"message":"updateData", |
505 | //"srpSharedSecret":"4e4aadb1d64513ec4dd42f5e8d5b2d4363de75e4424b6bcf178c9d6a246356c5", | 665 | //"srpSharedSecret":"4e4aadb1d64513ec4dd42f5e8d5b2d4363de75e4424b6bcf178c9d6a246356c5", |
506 | //"parameters":{ | 666 | //"parameters":{ |
507 | // "records":[ | 667 | // "records":[ |
508 | // { | 668 | // { |
509 | // "record":{ | 669 | // "record":{ |
510 | // "reference":"740009737139a189cfa2b1019a6271aaa39467b59e259706564b642ff3838d50", | 670 | // "reference":"740009737139a189cfa2b1019a6271aaa39467b59e259706564b642ff3838d50", |
511 | // "data":"8hgR0Z+JDrUa812polDJ....JnZUKXNEqKI", | 671 | // "data":"8hgR0Z+JDrUa812polDJ....JnZUKXNEqKI", |
512 | // "version":"0.3" | 672 | // "version":"0.3" |
513 | // }, | 673 | // }, |
514 | // "currentRecordVersion":{ | 674 | // "currentRecordVersion":{ |
515 | // "reference":"b1d82aeb9a0c4f6584bea68ba80839f43dd6ede79791549e29a1860554b144ee", | 675 | // "reference":"b1d82aeb9a0c4f6584bea68ba80839f43dd6ede79791549e29a1860554b144ee", |
516 | // "recordReference":"740009737139a189cfa2b1019a6271aaa39467b59e259706564b642ff3838d50", | 676 | // "recordReference":"740009737139a189cfa2b1019a6271aaa39467b59e259706564b642ff3838d50", |
517 | // "data":"2d/UgKxxV+kBPV9GRUE.....VGonDoW0tqefxOJo=", | 677 | // "data":"2d/UgKxxV+kBPV9GRUE.....VGonDoW0tqefxOJo=", |
518 | // "version":"0.3", | 678 | // "version":"0.3", |
519 | // "previousVersion":"55904195249037394316d3be3f5e78f08073170103bf0e7ab49a911c159cb0be", | 679 | // "previousVersion":"55904195249037394316d3be3f5e78f08073170103bf0e7ab49a911c159cb0be", |
520 | // "previousVersionKey":"YWiaZeMIVHaIl96OWW+2e8....6d6nHbn6cr2NA/dbQRuC2w==" | 680 | // "previousVersionKey":"YWiaZeMIVHaIl96OWW+2e8....6d6nHbn6cr2NA/dbQRuC2w==" |
521 | // } | 681 | // } |
522 | // } | 682 | // } |
523 | // ], | 683 | // ], |
524 | // "user":{ | 684 | // "user":{ |
525 | // "header":"{\"rec.....sion\":\"0.1\"}", | 685 | // "header":"{\"rec.....sion\":\"0.1\"}", |
526 | // "statistics":"tt3uU9hWBy8rNnMckgCnxMJh", | 686 | // "statistics":"tt3uU9hWBy8rNnMckgCnxMJh", |
527 | // "version":"0.3", | 687 | // "version":"0.3", |
528 | // "lock":"----" | 688 | // "lock":"----" |
529 | // } | 689 | // } |
530 | //} | 690 | //} |
531 | //} | 691 | //} |
532 | 692 | ||
533 | $user = new user(); | 693 | $user = new user(); |
534 | $user = $user->Get($_SESSION["userId"]); | 694 | $user = $user->Get($_SESSION["userId"]); |
535 | updateUserData($parameters["parameters"]["user"], $user); | 695 | updateUserData($parameters["parameters"]["user"], $user); |
536 | $user->Save(); | 696 | $user->Save(); |
537 | 697 | ||
538 | $recordParameterList = $parameters["parameters"]["records"]; | 698 | $recordParameterList = $parameters["parameters"]["records"]; |
539 | $c = count($recordParameterList); | 699 | $c = count($recordParameterList); |
540 | for ($i=0; $i<$c; $i++) { | 700 | for ($i=0; $i<$c; $i++) { |
541 | $recordList = $user->GetRecordList(array(array("reference", "=", $recordParameterList[$i]["record"]["reference"]))); | 701 | $recordList = $user->GetRecordList(array(array("reference", "=", $recordParameterList[$i]["record"]["reference"]))); |
542 | $currentRecord = $recordList[0]; | 702 | $currentRecord = $recordList[0]; |
543 | $currentRecordVersions = $currentRecord->GetRecordversionList(); | 703 | $currentRecordVersions = $currentRecord->GetRecordversionList(); |
544 | $currentVersion = $currentRecordVersions[0]; | 704 | $currentVersion = $currentRecordVersions[0]; |
545 | 705 | ||
546 | updateRecordData($recordParameterList[$i], $currentRecord, $currentVersion); | 706 | updateRecordData($recordParameterList[$i], $currentRecord, $currentVersion); |
547 | 707 | ||
548 | 708 | ||
549 | $currentRecord->Save(); | 709 | $currentRecord->Save(); |
550 | $currentVersion->Save(); | 710 | $currentVersion->Save(); |
551 | } | 711 | } |
552 | 712 | ||
553 | 713 | ||
554 | $result["lock"] = $user->lock; | 714 | $result["lock"] = $user->lock; |
555 | $result["result"] = "done"; | 715 | $result["result"] = "done"; |
556 | 716 | ||
557 | //============================================================= | 717 | //============================================================= |
558 | } else if ($message == "deleteRecords") { | 718 | } else if ($message == "deleteRecords") { |
559 | //{ | 719 | //{ |
560 | //"message":"deleteRecords", | 720 | //"message":"deleteRecords", |
561 | //"srpSharedSecret":"4a64982f7ee366954ec50b9efea62a902a097ef111410c2aa7c4d5343bd1cdd1", | 721 | //"srpSharedSecret":"4a64982f7ee366954ec50b9efea62a902a097ef111410c2aa7c4d5343bd1cdd1", |
562 | //"parameters":{ | 722 | //"parameters":{ |
563 | // "recordReferences":["46494c81d10b80ab190d41e6806ef63869cfcc7a0ab8fe98cc3f93de4729bb9a"], | 723 | // "recordReferences":["46494c81d10b80ab190d41e6806ef63869cfcc7a0ab8fe98cc3f93de4729bb9a"], |
564 | // "user":{ | 724 | // "user":{ |
565 | // "header":"{\"rec...rsion\":\"0.1\"}", | 725 | // "header":"{\"rec...rsion\":\"0.1\"}", |
566 | // "statistics":"44kOOda0xYZjbcugJBdagBQx", | 726 | // "statistics":"44kOOda0xYZjbcugJBdagBQx", |
567 | // "version":"0.3", | 727 | // "version":"0.3", |
568 | // "lock":"----" | 728 | // "lock":"----" |
569 | // } | 729 | // } |
570 | //} | 730 | //} |
571 | //} | 731 | //} |
572 | $user = new user(); | 732 | $user = new user(); |
573 | $user = $user->Get($_SESSION["userId"]); | 733 | $user = $user->Get($_SESSION["userId"]); |
574 | 734 | ||
575 | $recordReferenceList = $parameters["parameters"]["recordReferences"]; | 735 | $recordReferenceList = $parameters["parameters"]["recordReferences"]; |
576 | $recordList = array(); | 736 | $recordList = array(); |
577 | $c = count($recordReferenceList); | 737 | $c = count($recordReferenceList); |
578 | for ($i=0; $i<$c; $i++) { | 738 | for ($i=0; $i<$c; $i++) { |
579 | array_push($recordList, array("reference", "=", $recordReferenceList[$i])); | 739 | array_push($recordList, array("reference", "=", $recordReferenceList[$i])); |
580 | } | 740 | } |
581 | 741 | ||
582 | $record = new record(); | 742 | $record = new record(); |
583 | $record->DeleteList($recordList, true); | 743 | $record->DeleteList($recordList, true); |
584 | 744 | ||
585 | updateUserData($parameters["parameters"]["user"], $user); | 745 | updateUserData($parameters["parameters"]["user"], $user); |
586 | $user->Save(); | 746 | $user->Save(); |
587 | 747 | ||
588 | $result["recordList"] = $recordList; | 748 | $result["recordList"] = $recordList; |
589 | $result["lock"] = $user->lock; | 749 | $result["lock"] = $user->lock; |
590 | $result["result"] = "done"; | 750 | $result["result"] = "done"; |
591 | 751 | ||
592 | //============================================================= | 752 | //============================================================= |
593 | } else if ($message == "deleteUser") { | 753 | } else if ($message == "deleteUser") { |
594 | //{"message":"deleteUser", "srpSharedSecret":"e8e4ca6544dca49c95b3647d8358ad54c317048b74d2ac187ac25f719c9bac58", "parameters":{}} | 754 | //{"message":"deleteUser", "srpSharedSecret":"e8e4ca6544dca49c95b3647d8358ad54c317048b74d2ac187ac25f719c9bac58", "parameters":{}} |
595 | $user = new user(); | 755 | $user = new user(); |
596 | $user->Get($_SESSION["userId"]); | 756 | $user->Get($_SESSION["userId"]); |
597 | $user->Delete(true); | 757 | $user->Delete(true); |
598 | 758 | ||
599 | $result["result"] = "ok"; | 759 | $result["result"] = "ok"; |
600 | 760 | ||
601 | //============================================================= | 761 | //============================================================= |
602 | } else if ($message == "addNewOneTimePassword") { | 762 | } else if ($message == "addNewOneTimePassword") { |
603 | //{ | 763 | //{ |
604 | //"message":"addNewOneTimePassword", | 764 | //"message":"addNewOneTimePassword", |
605 | //"srpSharedSecret":"96fee4af06c09ce954fe7a9f87970e943449186bebf70bac0af1d6ebb818dabb", | 765 | //"srpSharedSecret":"96fee4af06c09ce954fe7a9f87970e943449186bebf70bac0af1d6ebb818dabb", |
606 | //"parameters":{ | 766 | //"parameters":{ |
607 | // "user":{ | 767 | // "user":{ |
608 | // "header":"{\"records\":{\"index\":{\"419ea6....rsion\":\"0.1\"}", | 768 | // "header":"{\"records\":{\"index\":{\"419ea6....rsion\":\"0.1\"}", |
609 | // "statistics":"rrlwNbDt83rpWT4S72upiVsC", | 769 | // "statistics":"rrlwNbDt83rpWT4S72upiVsC", |
610 | // "version":"0.3", | 770 | // "version":"0.3", |
611 | // "lock":"----" | 771 | // "lock":"----" |
612 | // }, | 772 | // }, |
613 | // "oneTimePassword":{ | 773 | // "oneTimePassword":{ |
614 | // "reference":"29e26f3a2aae61fe5cf58c45296c6df4f3dceafe067ea550b455be345f44123c", | 774 | // "reference":"29e26f3a2aae61fe5cf58c45296c6df4f3dceafe067ea550b455be345f44123c", |
615 | // "key":"afb848208758361a96a298b9db08995cf036011747809357a90645bc93fdfa03", | 775 | // "key":"afb848208758361a96a298b9db08995cf036011747809357a90645bc93fdfa03", |
616 | // "keyChecksum":"d1599ae443b5a566bfd93c0aeec4c81b42c0506ee09874dae050449580bb3486", | 776 | // "keyChecksum":"d1599ae443b5a566bfd93c0aeec4c81b42c0506ee09874dae050449580bb3486", |
617 | // "data":"hsyY8DHksgR52x6c4j7XAtIUeY.....dxsr3XWt7CbGg==", | 777 | // "data":"hsyY8DHksgR52x6c4j7XAtIUeY.....dxsr3XWt7CbGg==", |
618 | // "version":"0.3" | 778 | // "version":"0.3" |
619 | // } | 779 | // } |
620 | //} | 780 | //} |
621 | //} | 781 | //} |
622 | 782 | ||
623 | fixOTPStatusTable(); | 783 | fixOTPStatusTable(); |
624 | 784 | ||
625 | $user = new user(); | 785 | $user = new user(); |
626 | $user = $user->Get($_SESSION["userId"]); | 786 | $user = $user->Get($_SESSION["userId"]); |
627 | 787 | ||
628 | $otp = new onetimepassword(); | 788 | $otp = new onetimepassword(); |
629 | updateOTP($parameters["parameters"]["oneTimePassword"], $otp, "ACTIVE"); | 789 | updateOTP($parameters["parameters"]["oneTimePassword"], $otp, "ACTIVE"); |
630 | $user->AddOnetimepassword($otp); | 790 | $user->AddOnetimepassword($otp); |
631 | 791 | ||
632 | updateUserData($parameters["parameters"]["user"], $user); | 792 | updateUserData($parameters["parameters"]["user"], $user); |
633 | $user->Save(); | 793 | $user->Save(); |
634 | 794 | ||
635 | $result["lock"] = $user->lock; | 795 | $result["lock"] = $user->lock; |
636 | $result["result"] = "done"; | 796 | $result["result"] = "done"; |
637 | 797 | ||
638 | //============================================================= | 798 | //============================================================= |
639 | } else if ($message == "updateOneTimePasswords") { | 799 | } else if ($message == "updateOneTimePasswords") { |
640 | //{ | 800 | //{ |
641 | //"message":"updateOneTimePasswords", | 801 | //"message":"updateOneTimePasswords", |
642 | //"srpSharedSecret":"c78f8ed099ea421f4dd0a4e02dbaf1f7da925f0088188d99399874ff064a3d27", | 802 | //"srpSharedSecret":"c78f8ed099ea421f4dd0a4e02dbaf1f7da925f0088188d99399874ff064a3d27", |
643 | //"parameters":{ | 803 | //"parameters":{ |
644 | // "user":{ | 804 | // "user":{ |
645 | // "header":"{\"reco...sion\":\"0.1\"}", | 805 | // "header":"{\"reco...sion\":\"0.1\"}", |
646 | // "statistics":"UeRq75RZHzDC7elzrh/+OB5d", | 806 | // "statistics":"UeRq75RZHzDC7elzrh/+OB5d", |
647 | // "version":"0.3", | 807 | // "version":"0.3", |
648 | // "lock":"----" | 808 | // "lock":"----" |
649 | // }, | 809 | // }, |
650 | // "oneTimePasswords":["f5f44c232f239efe48ab81a6236deea1a840d52946f7d4d782dad52b4c5359ce"] | 810 | // "oneTimePasswords":["f5f44c232f239efe48ab81a6236deea1a840d52946f7d4d782dad52b4c5359ce"] |
651 | //} | 811 | //} |
652 | //} | 812 | //} |
653 | 813 | ||
654 | $user = new user(); | 814 | $user = new user(); |
655 | $user = $user->Get($_SESSION["userId"]); | 815 | $user = $user->Get($_SESSION["userId"]); |
656 | 816 | ||
657 | $validOtpReferences = $parameters["parameters"]["oneTimePasswords"]; | 817 | $validOtpReferences = $parameters["parameters"]["oneTimePasswords"]; |
658 | 818 | ||
659 | $otpList = $user->GetOnetimepasswordList(); | 819 | $otpList = $user->GetOnetimepasswordList(); |
660 | $c = count($otpList); | 820 | $c = count($otpList); |
661 | for ($i=0; $i<$c; $i++) { | 821 | for ($i=0; $i<$c; $i++) { |
662 | $currentOtp = $otpList[$i]; | 822 | $currentOtp = $otpList[$i]; |
663 | if (arrayContainsValue($validOtpReferences, $currentOtp->reference) == false) { | 823 | if (arrayContainsValue($validOtpReferences, $currentOtp->reference) == false) { |
664 | $currentOtp->Delete(); | 824 | $currentOtp->Delete(); |
665 | } | 825 | } |
666 | } | 826 | } |
667 | 827 | ||
668 | updateUserData($parameters["parameters"]["user"], $user); | 828 | updateUserData($parameters["parameters"]["user"], $user); |
669 | $user->Save(); | 829 | $user->Save(); |
670 | 830 | ||
671 | $result["result"] = $user->lock; | 831 | $result["result"] = $user->lock; |
672 | 832 | ||
673 | //============================================================= | 833 | //============================================================= |
674 | } else if ($message == "getOneTimePasswordsDetails") { | 834 | } else if ($message == "getOneTimePasswordsDetails") { |
675 | 835 | ||
676 | //============================================================= | 836 | //============================================================= |
677 | } else if ($message == "getLoginHistory") { | 837 | } else if ($message == "getLoginHistory") { |
678 | $result["result"] = array(); | 838 | $result["result"] = array(); |
679 | 839 | ||
680 | //============================================================= | 840 | //============================================================= |
681 | } else if ($message == "upgradeUserCredentials") { | 841 | } else if ($message == "upgradeUserCredentials") { |
682 | //{ | 842 | //{ |
683 | //"message":"upgradeUserCredentials", | 843 | //"message":"upgradeUserCredentials", |
684 | //"srpSharedSecret":"f1c25322e1478c8fb26063e9eef2f6fc25e0460065a31cb718f80bcff8f8a735", | 844 | //"srpSharedSecret":"f1c25322e1478c8fb26063e9eef2f6fc25e0460065a31cb718f80bcff8f8a735", |
685 | //"parameters":{ | 845 | //"parameters":{ |
686 | // "user":{ | 846 | // "user":{ |
687 | // "header":"{\"reco...sion\":\"0.1\"}", | 847 | // "header":"{\"reco...sion\":\"0.1\"}", |
688 | // "statistics":"s72Xva+w7CLgH+ihwqwXUbyu", | 848 | // "statistics":"s72Xva+w7CLgH+ihwqwXUbyu", |
689 | // "version":"0.3", | 849 | // "version":"0.3", |
690 | // "lock":"----" | 850 | // "lock":"----" |
691 | // }, | 851 | // }, |
692 | // "credentials":{ | 852 | // "credentials":{ |
693 | // "C":"57d15a8afbc1ae08103bd991d387ddfd8d26824276476fe709d754f098b6c26d", | 853 | // "C":"57d15a8afbc1ae08103bd991d387ddfd8d26824276476fe709d754f098b6c26d", |
694 | // "s":"d6735fc0486f391c4f3c947928f9e61a2418e7bed2bc9b25bb43f93acc52f636", | 854 | // "s":"d6735fc0486f391c4f3c947928f9e61a2418e7bed2bc9b25bb43f93acc52f636", |
695 | // "v":"540c2ebbf941a481b6b2c9026c07fb46e8202e4408ed96864a696deb622baece", | 855 | // "v":"540c2ebbf941a481b6b2c9026c07fb46e8202e4408ed96864a696deb622baece", |
696 | // "version":"0.2" | 856 | // "version":"0.2" |
697 | // }, | 857 | // }, |
698 | // "oneTimePasswords":{ | 858 | // "oneTimePasswords":{ |
699 | // "923cdc61c4b877b263236124c44d69b459d240453a461cce8ddf7518b423ca94": "1HD6Ta0xsifEDhDwE....9WDK6tvrS6w==", | 859 | // "923cdc61c4b877b263236124c44d69b459d240453a461cce8ddf7518b423ca94": "1HD6Ta0xsifEDhDwE....9WDK6tvrS6w==", |
700 | // "fb1573cb9497652a81688a099a524fb116e604c6fbc191cf33406eb8438efa5f": "CocN0cSxLmMRdgNF9....o3xhGUEY68Q==" | 860 | // "fb1573cb9497652a81688a099a524fb116e604c6fbc191cf33406eb8438efa5f": "CocN0cSxLmMRdgNF9....o3xhGUEY68Q==" |
701 | // } | 861 | // } |
702 | //} | 862 | //} |
703 | //} | 863 | //} |
704 | 864 | ||
705 | $user = new user(); | 865 | $user = new user(); |
706 | $user->Get($_SESSION["userId"]); | 866 | $user->Get($_SESSION["userId"]); |
707 | 867 | ||
708 | $otp = new onetimepassword(); | 868 | $otp = new onetimepassword(); |
709 | 869 | ||
710 | updateUserCredentials($parameters["parameters"]["credentials"], $user); | 870 | updateUserCredentials($parameters["parameters"]["credentials"], $user); |
711 | updateUserData($parameters["parameters"]["user"], $user); | 871 | updateUserData($parameters["parameters"]["user"], $user); |
712 | 872 | ||
713 | $otpList = $parameters["parameters"]["oneTimePasswords"]; | 873 | $otpList = $parameters["parameters"]["oneTimePasswords"]; |
714 | foreach($otpList as $otpReference=>$otpData) { | 874 | foreach($otpList as $otpReference=>$otpData) { |
715 | $otpList = $otp->GetList(array(array("reference", "=", $otpReference))); | 875 | $otpList = $otp->GetList(array(array("reference", "=", $otpReference))); |
716 | $currentOtp = $otpList[0]; | 876 | $currentOtp = $otpList[0]; |
717 | $currentOtp->data = $otpData; | 877 | $currentOtp->data = $otpData; |
718 | $currentOtp->Save(); | 878 | $currentOtp->Save(); |
719 | } | 879 | } |
720 | 880 | ||
721 | $user->Save(); | 881 | $user->Save(); |
722 | 882 | ||
723 | $result["lock"] = $user->lock; | 883 | $result["lock"] = $user->lock; |
724 | $result["result"] = "done"; | 884 | $result["result"] = "done"; |
725 | 885 | ||
726 | //============================================================= | 886 | //============================================================= |
727 | } else if ($message == "echo") { | 887 | } else if ($message == "echo") { |
728 | $result["result"] = $parameters; | 888 | $result["result"] = $parameters; |
729 | } | 889 | } |
730 | 890 | ||
731 | //============================================================= | 891 | //============================================================= |
732 | } else if (isset($_SESSION['K'])) { | 892 | } else if (isset($_SESSION['K'])) { |
733 | $result["error"] = "Wrong shared secret!"; | 893 | $result["error"] = "Wrong shared secret!"; |
734 | } else { | 894 | } else { |
735 | $result["result"] = "EXCEPTION"; | 895 | $result["result"] = "EXCEPTION"; |
736 | $result["message"] = "Trying to communicate without an active connection"; | 896 | $result["message"] = "Trying to communicate without an active connection"; |
737 | } | 897 | } |
738 | break; | 898 | break; |
739 | 899 | ||
740 | case "logout": | 900 | case "logout": |
741 | error_log("logout"); | 901 | error_log("logout"); |
742 | session_destroy(); | 902 | session_destroy(); |
743 | break; | 903 | break; |
744 | 904 | ||
745 | default: | 905 | default: |
746 | error_log("default"); | 906 | error_log("default"); |
747 | $result["result"] = $parameters; | 907 | $result["result"] = $parameters; |
748 | break; | 908 | break; |
749 | } | 909 | } |
750 | 910 | ||
751 | session_write_close(); | 911 | session_write_close(); |
912 | |||
913 | $finalResult = Array(); | ||
914 | $finalResult["result"] = $result; | ||
752 | 915 | ||
753 | echo(json_encode($result)); | 916 | echo(json_encode($finalResult)); |
754 | error_log("result: ".json_encode($result)); | 917 | error_log("result: ".json_encode($finalResult)); |
755 | ?> | 918 | ?> |
diff --git a/frontend/beta/js/Clipperz/PM/DataModel/Record.js b/frontend/beta/js/Clipperz/PM/DataModel/Record.js index 270f2ae..ffb45de 100644 --- a/frontend/beta/js/Clipperz/PM/DataModel/Record.js +++ b/frontend/beta/js/Clipperz/PM/DataModel/Record.js | |||
@@ -1,756 +1,761 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2011 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz Community Edition. |
6 | Clipperz Community Edition is an online password manager. | 6 | Clipperz Community Edition is an online password manager. |
7 | For further information about its features and functionalities please | 7 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 8 | refer to http://www.clipperz.com. |
9 | 9 | ||
10 | * Clipperz Community Edition is free software: you can redistribute | 10 | * Clipperz Community Edition is free software: you can redistribute |
11 | it and/or modify it under the terms of the GNU Affero General Public | 11 | it and/or modify it under the terms of the GNU Affero General Public |
12 | License as published by the Free Software Foundation, either version | 12 | License as published by the Free Software Foundation, either version |
13 | 3 of the License, or (at your option) any later version. | 13 | 3 of the License, or (at your option) any later version. |
14 | 14 | ||
15 | * Clipperz Community Edition is distributed in the hope that it will | 15 | * Clipperz Community Edition is distributed in the hope that it will |
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 16 | be useful, but WITHOUT ANY WARRANTY; without even the implied |
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. | 18 | See the GNU Affero General Public License for more details. |
19 | 19 | ||
20 | * You should have received a copy of the GNU Affero General Public | 20 | * You should have received a copy of the GNU Affero General Public |
21 | License along with Clipperz Community Edition. If not, see | 21 | License along with Clipperz Community Edition. If not, see |
22 | <http://www.gnu.org/licenses/>. | 22 | <http://www.gnu.org/licenses/>. |
23 | 23 | ||
24 | */ | 24 | */ |
25 | 25 | ||
26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | 27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } |
28 | if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } | 28 | if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } |
29 | 29 | ||
30 | 30 | ||
31 | //############################################################################# | 31 | //############################################################################# |
32 | 32 | ||
33 | Clipperz.PM.DataModel.Record = function(args) { | 33 | Clipperz.PM.DataModel.Record = function(args) { |
34 | args = args || {}; | 34 | args = args || {}; |
35 | 35 | ||
36 | this._user = args['user'] || null; | 36 | this._user = args['user'] || null; |
37 | this._reference = args['reference'] || Clipperz.PM.Crypto.randomKey(); | 37 | this._reference = args['reference'] || Clipperz.PM.Crypto.randomKey(); |
38 | this._version = args['version'] || Clipperz.PM.Crypto.encryptingFunctions.currentVersion; | 38 | this._version = args['version'] || Clipperz.PM.Crypto.encryptingFunctions.currentVersion; |
39 | this._key = args['key'] || Clipperz.PM.Crypto.randomKey(); | 39 | this._key = args['key'] || Clipperz.PM.Crypto.randomKey(); |
40 | 40 | ||
41 | this.setLabel(args['label'] || Clipperz.PM.Strings['newRecordTitleLabel']); | 41 | this.setLabel(args['label'] || Clipperz.PM.Strings['newRecordTitleLabel']); |
42 | 42 | ||
43 | this.setHeaderNotes(args['headerNotes'] || null); | 43 | this.setHeaderNotes(args['headerNotes'] || null); |
44 | this.setNotes(args['notes'] || args['headerNotes'] || ""); | 44 | this.setNotes(args['notes'] || args['headerNotes'] || ""); |
45 | //MochiKit.Logging.logDebug("--- new Record ('" + this._label + "')- _headerNotes: '" + this._headerNotes + "'"); | 45 | //MochiKit.Logging.logDebug("--- new Record ('" + this._label + "')- _headerNotes: '" + this._headerNotes + "'"); |
46 | //MochiKit.Logging.logDebug("--- new Record ('" + this._label + "')- _notes: '" + this._notes + "'"); | 46 | //MochiKit.Logging.logDebug("--- new Record ('" + this._label + "')- _notes: '" + this._notes + "'"); |
47 | //this._notes = args.notes || ""; | 47 | //this._notes = args.notes || ""; |
48 | 48 | ||
49 | this._versions = {}; | 49 | this._versions = {}; |
50 | this._directLogins = {}; | 50 | this._directLogins = {}; |
51 | this._removedDirectLogins = []; | 51 | this._removedDirectLogins = []; |
52 | 52 | ||
53 | this.setIsBrandNew(args['reference'] == null); | 53 | this.setIsBrandNew(args['reference'] == null); |
54 | 54 | ||
55 | this.setShouldLoadData(this.isBrandNew() ? false: true); | 55 | this.setShouldLoadData(this.isBrandNew() ? false: true); |
56 | this.setShouldDecryptData(this.isBrandNew() ? false: true); | 56 | this.setShouldDecryptData(this.isBrandNew() ? false: true); |
57 | this.setShouldProcessData(this.isBrandNew() ? false: true); | 57 | this.setShouldProcessData(this.isBrandNew() ? false: true); |
58 | 58 | ||
59 | this.setCurrentVersion(this.isBrandNew() ? new Clipperz.PM.DataModel.RecordVersion(this, null): null); | 59 | this.setCurrentVersion(this.isBrandNew() ? new Clipperz.PM.DataModel.RecordVersion(this, null): null); |
60 | this.setCurrentVersionKey(null); | 60 | this.setCurrentVersionKey(null); |
61 | 61 | ||
62 | this._serverData = null; | 62 | this._serverData = null; |
63 | this._decryptedData = null; | 63 | this._decryptedData = null; |
64 | this._cachedData = null; | 64 | this._cachedData = null; |
65 | 65 | ||
66 | return this; | 66 | return this; |
67 | } | 67 | } |
68 | 68 | ||
69 | Clipperz.PM.DataModel.Record.prototype = MochiKit.Base.update(null, { | 69 | Clipperz.PM.DataModel.Record.prototype = MochiKit.Base.update(null, { |
70 | 70 | ||
71 | 'toString': function() { | 71 | 'toString': function() { |
72 | return "Record (" + this.label() + ")"; | 72 | return "Record (" + this.label() + ")"; |
73 | }, | 73 | }, |
74 | 74 | ||
75 | //------------------------------------------------------------------------- | 75 | //------------------------------------------------------------------------- |
76 | 76 | ||
77 | 'isBrandNew': function() { | 77 | 'isBrandNew': function() { |
78 | return this._isBrandNew; | 78 | return this._isBrandNew; |
79 | }, | 79 | }, |
80 | 80 | ||
81 | 'setIsBrandNew': function(aValue) { | 81 | 'setIsBrandNew': function(aValue) { |
82 | this._isBrandNew = aValue; | 82 | this._isBrandNew = aValue; |
83 | }, | 83 | }, |
84 | 84 | ||
85 | //------------------------------------------------------------------------- | 85 | //------------------------------------------------------------------------- |
86 | /* | 86 | /* |
87 | 'shouldRunTheRecordCreationWizard': function() { | 87 | 'shouldRunTheRecordCreationWizard': function() { |
88 | return (this.isBrandNew() && (MochiKit.Base.keys(this.currentVersion().fields()).length == 0)); | 88 | return (this.isBrandNew() && (MochiKit.Base.keys(this.currentVersion().fields()).length == 0)); |
89 | }, | 89 | }, |
90 | */ | 90 | */ |
91 | //------------------------------------------------------------------------- | 91 | //------------------------------------------------------------------------- |
92 | 92 | ||
93 | 'user': function() { | 93 | 'user': function() { |
94 | return this._user; | 94 | return this._user; |
95 | }, | 95 | }, |
96 | 96 | ||
97 | //------------------------------------------------------------------------- | 97 | //------------------------------------------------------------------------- |
98 | 98 | ||
99 | 'reference': function() { | 99 | 'reference': function() { |
100 | return this._reference; | 100 | return this._reference; |
101 | }, | 101 | }, |
102 | 102 | ||
103 | //------------------------------------------------------------------------- | 103 | //------------------------------------------------------------------------- |
104 | 104 | ||
105 | 'key': function() { | 105 | 'key': function() { |
106 | return this._key; | 106 | return this._key; |
107 | }, | 107 | }, |
108 | 108 | ||
109 | 'updateKey': function() { | 109 | 'updateKey': function() { |
110 | this._key = Clipperz.PM.Crypto.randomKey(); | 110 | this._key = Clipperz.PM.Crypto.randomKey(); |
111 | }, | 111 | }, |
112 | 112 | ||
113 | //------------------------------------------------------------------------- | 113 | //------------------------------------------------------------------------- |
114 | 114 | ||
115 | 'label': function() { | 115 | 'label': function() { |
116 | return this._label; | 116 | return this._label; |
117 | }, | 117 | }, |
118 | 118 | ||
119 | 'setLabel': function(aValue) { | 119 | 'setLabel': function(aValue) { |
120 | this._label = aValue; | 120 | this._label = aValue; |
121 | }, | 121 | }, |
122 | 122 | ||
123 | 'lowerCaseLabel': function() { | 123 | 'lowerCaseLabel': function() { |
124 | return this.label().toLowerCase(); | 124 | return this.label().toLowerCase(); |
125 | }, | 125 | }, |
126 | 126 | ||
127 | //------------------------------------------------------------------------- | 127 | //------------------------------------------------------------------------- |
128 | 128 | ||
129 | 'versions': function() { | 129 | 'versions': function() { |
130 | return this._versions; | 130 | return this._versions; |
131 | }, | 131 | }, |
132 | 132 | ||
133 | //------------------------------------------------------------------------- | 133 | //------------------------------------------------------------------------- |
134 | 134 | ||
135 | 'currentVersion': function() { | 135 | 'currentVersion': function() { |
136 | return this._currentVersion; | 136 | return this._currentVersion; |
137 | }, | 137 | }, |
138 | 138 | ||
139 | 'setCurrentVersion': function(aValue) { | 139 | 'setCurrentVersion': function(aValue) { |
140 | this._currentVersion = aValue; | 140 | this._currentVersion = aValue; |
141 | }, | 141 | }, |
142 | 142 | ||
143 | //------------------------------------------------------------------------- | 143 | //------------------------------------------------------------------------- |
144 | 144 | ||
145 | 'currentVersionKey': function() { | 145 | 'currentVersionKey': function() { |
146 | return this._currentVersionKey; | 146 | return this._currentVersionKey; |
147 | }, | 147 | }, |
148 | 148 | ||
149 | 'setCurrentVersionKey': function(aValue) { | 149 | 'setCurrentVersionKey': function(aValue) { |
150 | this._currentVersionKey = aValue; | 150 | this._currentVersionKey = aValue; |
151 | }, | 151 | }, |
152 | 152 | ||
153 | //------------------------------------------------------------------------- | 153 | //------------------------------------------------------------------------- |
154 | 154 | ||
155 | 'deferredData': function() { | 155 | 'deferredData': function() { |
156 | vardeferredResult; | 156 | vardeferredResult; |
157 | 157 | ||
158 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.deferredData - this: " + this); | 158 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.deferredData - this: " + this); |
159 | deferredResult = new MochiKit.Async.Deferred(); | 159 | deferredResult = new MochiKit.Async.Deferred(); |
160 | deferredResult.addCallback(MochiKit.Base.method(this, 'loadData')); | 160 | deferredResult.addCallback(MochiKit.Base.method(this, 'loadData')); |
161 | deferredResult.addCallback(MochiKit.Base.method(this, 'decryptData')); | 161 | deferredResult.addCallback(MochiKit.Base.method(this, 'decryptData')); |
162 | deferredResult.addCallback(MochiKit.Base.method(this, 'processData')); | 162 | deferredResult.addCallback(MochiKit.Base.method(this, 'processData')); |
163 | deferredResult.addCallback(function(aRecord) { | 163 | deferredResult.addCallback(function(aRecord) { |
164 | return aRecord.currentVersion().deferredData(); | 164 | return aRecord.currentVersion().deferredData(); |
165 | }); | 165 | }); |
166 | deferredResult.addCallback(MochiKit.Base.method(this, 'takeSnapshotOfCurrentData')); | 166 | deferredResult.addCallback(MochiKit.Base.method(this, 'takeSnapshotOfCurrentData')); |
167 | deferredResult.addCallback(MochiKit.Async.succeed, this); | 167 | deferredResult.addCallback(MochiKit.Async.succeed, this); |
168 | deferredResult.callback(); | 168 | deferredResult.callback(); |
169 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.deferredData"); | 169 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.deferredData"); |
170 | 170 | ||
171 | return deferredResult; | 171 | return deferredResult; |
172 | }, | 172 | }, |
173 | 173 | ||
174 | //------------------------------------------------------------------------- | 174 | //------------------------------------------------------------------------- |
175 | 175 | ||
176 | 'exportedData': function() { | 176 | 'exportedData': function() { |
177 | var result; | 177 | var result; |
178 | 178 | ||
179 | result = {}; | 179 | result = {}; |
180 | result['label'] = this.label(); | 180 | result['label'] = this.label(); |
181 | result['data'] = this.serializedData(); | 181 | result['data'] = this.serializedData(); |
182 | result['currentVersion'] = this.currentVersion().serializedData(); | 182 | result['currentVersion'] = this.currentVersion().serializedData(); |
183 | result['currentVersion']['reference'] = this.currentVersion().reference(); | 183 | result['currentVersion']['reference'] = this.currentVersion().reference(); |
184 | // result['versions'] = MochiKit.Base.map(MochiKit.Base.methodcaller("serializedData"), MochiKit.Base.values(this.versions())); | 184 | // result['versions'] = MochiKit.Base.map(MochiKit.Base.methodcaller("serializedData"), MochiKit.Base.values(this.versions())); |
185 | 185 | ||
186 | return Clipperz.Base.serializeJSON(result); | 186 | return Clipperz.Base.serializeJSON(result); |
187 | }, | 187 | }, |
188 | 188 | ||
189 | //------------------------------------------------------------------------- | 189 | //------------------------------------------------------------------------- |
190 | 190 | ||
191 | 'shouldLoadData': function() { | 191 | 'shouldLoadData': function() { |
192 | return this._shouldLoadData; | 192 | return this._shouldLoadData; |
193 | }, | 193 | }, |
194 | 194 | ||
195 | 'setShouldLoadData': function(aValue) { | 195 | 'setShouldLoadData': function(aValue) { |
196 | this._shouldLoadData = aValue; | 196 | this._shouldLoadData = aValue; |
197 | }, | 197 | }, |
198 | 198 | ||
199 | //------------------------------------------------------------------------- | 199 | //------------------------------------------------------------------------- |
200 | 200 | ||
201 | 'shouldDecryptData': function() { | 201 | 'shouldDecryptData': function() { |
202 | return this._shouldDecryptData; | 202 | return this._shouldDecryptData; |
203 | }, | 203 | }, |
204 | 204 | ||
205 | 'setShouldDecryptData': function(aValue) { | 205 | 'setShouldDecryptData': function(aValue) { |
206 | this._shouldDecryptData = aValue; | 206 | this._shouldDecryptData = aValue; |
207 | }, | 207 | }, |
208 | 208 | ||
209 | //------------------------------------------------------------------------- | 209 | //------------------------------------------------------------------------- |
210 | 210 | ||
211 | 'shouldProcessData': function() { | 211 | 'shouldProcessData': function() { |
212 | return this._shouldProcessData; | 212 | return this._shouldProcessData; |
213 | }, | 213 | }, |
214 | 214 | ||
215 | 'setShouldProcessData': function(aValue) { | 215 | 'setShouldProcessData': function(aValue) { |
216 | this._shouldProcessData = aValue; | 216 | this._shouldProcessData = aValue; |
217 | }, | 217 | }, |
218 | 218 | ||
219 | //------------------------------------------------------------------------- | 219 | //------------------------------------------------------------------------- |
220 | 220 | ||
221 | 'loadData': function() { | 221 | 'loadData': function() { |
222 | var result; | 222 | var result; |
223 | 223 | ||
224 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.loadData - this: " + this); | 224 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.loadData - this: " + this); |
225 | if (this.shouldLoadData()) { | 225 | if (this.shouldLoadData()) { |
226 | var deferredResult; | 226 | var deferredResult; |
227 | 227 | ||
228 | deferredResult = new MochiKit.Async.Deferred(); | 228 | deferredResult = new MochiKit.Async.Deferred(); |
229 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'loadingRecordData'); | 229 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'loadingRecordData'); |
230 | deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'getRecordDetail', {reference: this.reference()}); | 230 | deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'getRecordDetail', {reference: this.reference()}); |
231 | deferredResult.addCallback(MochiKit.Base.method(this,'setServerData')); | 231 | deferredResult.addCallback(MochiKit.Base.method(this,'setServerData')); |
232 | deferredResult.callback(); | 232 | deferredResult.callback(); |
233 | result = deferredResult; | 233 | result = deferredResult; |
234 | } else { | 234 | } else { |
235 | result = MochiKit.Async.succeed(this.serverData()); | 235 | result = MochiKit.Async.succeed(this.serverData()); |
236 | } | 236 | } |
237 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.loadData"); | 237 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.loadData"); |
238 | 238 | ||
239 | return result; | 239 | return result; |
240 | }, | 240 | }, |
241 | 241 | ||
242 | //------------------------------------------------------------------------- | 242 | //------------------------------------------------------------------------- |
243 | 243 | ||
244 | 'decryptData': function(anEncryptedData) { | 244 | 'decryptData': function(anEncryptedData) { |
245 | var result; | 245 | var result; |
246 | 246 | ||
247 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.decryptData - this: " + this + " (" + anEncryptedData + ")"); | 247 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.decryptData - this: " + this + " (" + anEncryptedData + ")"); |
248 | if (this.shouldDecryptData()) { | 248 | if (this.shouldDecryptData()) { |
249 | var deferredResult; | 249 | var deferredResult; |
250 | 250 | ||
251 | deferredResult = new MochiKit.Async.Deferred(); | 251 | deferredResult = new MochiKit.Async.Deferred(); |
252 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'decryptingRecordData'); | 252 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'decryptingRecordData'); |
253 | deferredResult.addCallback(Clipperz.PM.Crypto.deferredDecrypt, this.key(), anEncryptedData['data'], anEncryptedData['version']); | 253 | deferredResult.addCallback(Clipperz.PM.Crypto.deferredDecrypt, this.key(), anEncryptedData['data'], anEncryptedData['version']); |
254 | deferredResult.addCallback(function(anEncryptedData, someDecryptedValues) { | 254 | deferredResult.addCallback(function(anEncryptedData, someDecryptedValues) { |
255 | varresult; | 255 | varresult; |
256 | 256 | ||
257 | result = anEncryptedData; | 257 | result = anEncryptedData; |
258 | result['data'] = someDecryptedValues; | 258 | result['data'] = someDecryptedValues; |
259 | 259 | ||
260 | return result; | 260 | return result; |
261 | }, anEncryptedData); | 261 | }, anEncryptedData); |
262 | deferredResult.addCallback(MochiKit.Base.method(this, 'setDecryptedData')); | 262 | deferredResult.addCallback(MochiKit.Base.method(this, 'setDecryptedData')); |
263 | deferredResult.callback(); | 263 | deferredResult.callback(); |
264 | 264 | ||
265 | result = deferredResult; | 265 | result = deferredResult; |
266 | } else { | 266 | } else { |
267 | result = MochiKit.Async.succeed(this.decryptedData()); | 267 | result = MochiKit.Async.succeed(this.decryptedData()); |
268 | } | 268 | } |
269 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.decryptData"); | 269 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.decryptData"); |
270 | 270 | ||
271 | return result; | 271 | return result; |
272 | }, | 272 | }, |
273 | 273 | ||
274 | //------------------------------------------------------------------------- | 274 | //------------------------------------------------------------------------- |
275 | 275 | ||
276 | 'processData': function(someValues) { | 276 | 'processData': function(someValues) { |
277 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.processData"); | 277 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.processData"); |
278 | //MochiKit.Logging.logDebug("--- Record.processData: " + Clipperz.Base.serializeJSON(someValues)); | 278 | //MochiKit.Logging.logDebug("--- Record.processData: " + Clipperz.Base.serializeJSON(someValues)); |
279 | if (this.shouldProcessData()) { | 279 | if (this.shouldProcessData()) { |
280 | var currentVersionParameters; | 280 | var currentVersionParameters; |
281 | 281 | ||
282 | console.log("Record.processData", someValues); | ||
282 | this.processDataToExtractLegacyValues(someValues['data']); | 283 | this.processDataToExtractLegacyValues(someValues['data']); |
283 | 284 | ||
284 | if (typeof(someValues['data']['notes']) != 'undefined') { | 285 | if (typeof(someValues['data']['notes']) != 'undefined') { |
285 | this.setNotes(someValues['data']['notes']); | 286 | this.setNotes(someValues['data']['notes']); |
286 | } | 287 | } |
288 | |||
287 | if (someValues['data']['currentVersionKey'] != null) { | 289 | if (someValues['data']['currentVersionKey'] != null) { |
288 | this.setCurrentVersionKey(someValues['data']['currentVersionKey']); | 290 | this.setCurrentVersionKey(someValues['data']['currentVersionKey']); |
289 | } else { | 291 | } else { |
290 | this.setCurrentVersionKey(this.key()); | 292 | this.setCurrentVersionKey(this.key()); |
291 | } | 293 | } |
292 | 294 | ||
293 | currentVersionParameters = someValues['currentVersion']; | 295 | // currentVersionParameters = someValues['currentVersion']; |
296 | currentVersionParameters = someValues['versions'][someValues['currentVersion']]; | ||
297 | console.log("Record.processData - this.currentVersionKey()", this.currentVersionKey()); | ||
298 | console.log("Record.processData - currentVersionParameters", currentVersionParameters); | ||
294 | currentVersionParameters['key'] = this.currentVersionKey(); | 299 | currentVersionParameters['key'] = this.currentVersionKey(); |
295 | this.setCurrentVersion(new Clipperz.PM.DataModel.RecordVersion(this, currentVersionParameters)); | 300 | this.setCurrentVersion(new Clipperz.PM.DataModel.RecordVersion(this, currentVersionParameters)); |
296 | 301 | ||
297 | if (someValues['data']['directLogins'] != null) { | 302 | if (someValues['data']['directLogins'] != null) { |
298 | vardirectLoginReference; | 303 | vardirectLoginReference; |
299 | 304 | ||
300 | for (directLoginReference in someValues['data']['directLogins']) { | 305 | for (directLoginReference in someValues['data']['directLogins']) { |
301 | var directLogin; | 306 | var directLogin; |
302 | var directLoginParameters; | 307 | var directLoginParameters; |
303 | 308 | ||
304 | directLoginParameters = someValues['data']['directLogins'][directLoginReference]; | 309 | directLoginParameters = someValues['data']['directLogins'][directLoginReference]; |
305 | directLoginParameters.record = this; | 310 | directLoginParameters.record = this; |
306 | directLoginParameters.reference = directLoginReference; | 311 | directLoginParameters.reference = directLoginReference; |
307 | 312 | ||
308 | directLogin = new Clipperz.PM.DataModel.DirectLogin(directLoginParameters); | 313 | directLogin = new Clipperz.PM.DataModel.DirectLogin(directLoginParameters); |
309 | this.addDirectLogin(directLogin, true); | 314 | this.addDirectLogin(directLogin, true); |
310 | } | 315 | } |
311 | } | 316 | } |
312 | this.setShouldProcessData(false); | 317 | this.setShouldProcessData(false); |
313 | } | 318 | } |
314 | 319 | ||
315 | Clipperz.NotificationCenter.notify(this, 'recordDataReady'); | 320 | Clipperz.NotificationCenter.notify(this, 'recordDataReady'); |
316 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.processData"); | 321 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.processData"); |
317 | //MochiKit.Logging.logDebug("<<< Record.processData"); | 322 | //MochiKit.Logging.logDebug("<<< Record.processData"); |
318 | 323 | ||
319 | return this; | 324 | return this; |
320 | }, | 325 | }, |
321 | 326 | ||
322 | //------------------------------------------------------------------------- | 327 | //------------------------------------------------------------------------- |
323 | 328 | ||
324 | 'processDataToExtractLegacyValues': function(someValues) { | 329 | 'processDataToExtractLegacyValues': function(someValues) { |
325 | //MochiKit.Logging.logDebug(">>> Record.processDataToExtractLegacyValues"); | 330 | //MochiKit.Logging.logDebug(">>> Record.processDataToExtractLegacyValues"); |
326 | if (someValues['data'] != null) { | 331 | if (someValues['data'] != null) { |
327 | this.setNotes(someValues['data']); | 332 | this.setNotes(someValues['data']); |
328 | } | 333 | } |
329 | 334 | ||
330 | if ( | 335 | if ( |
331 | (typeof(someValues['loginFormData']) != "undefined") | 336 | (typeof(someValues['loginFormData']) != "undefined") |
332 | &&(typeof(someValues['loginBindings'] != "undefined")) | 337 | &&(typeof(someValues['loginBindings'] != "undefined")) |
333 | &&(someValues['loginFormData'] != "") | 338 | &&(someValues['loginFormData'] != "") |
334 | &&(someValues['loginBindings'] != "") | 339 | &&(someValues['loginBindings'] != "") |
335 | ) { | 340 | ) { |
336 | vardirectLogin; | 341 | vardirectLogin; |
337 | 342 | ||
338 | directLogin = new Clipperz.PM.DataModel.DirectLogin({ | 343 | directLogin = new Clipperz.PM.DataModel.DirectLogin({ |
339 | record:this, | 344 | record:this, |
340 | label:this.label() + Clipperz.PM.Strings['newDirectLoginLabelSuffix'], | 345 | label:this.label() + Clipperz.PM.Strings['newDirectLoginLabelSuffix'], |
341 | reference:Clipperz.Crypto.SHA.sha256(new Clipperz.ByteArray(this.label() + | 346 | reference:Clipperz.Crypto.SHA.sha256(new Clipperz.ByteArray(this.label() + |
342 | someValues['loginFormData'] + | 347 | someValues['loginFormData'] + |
343 | someValues['loginBindings'])).toHexString().substring(2), | 348 | someValues['loginBindings'])).toHexString().substring(2), |
344 | formData:Clipperz.Base.evalJSON(someValues['loginFormData']), | 349 | formData:Clipperz.Base.evalJSON(someValues['loginFormData']), |
345 | legacyBindingData:Clipperz.Base.evalJSON(someValues['loginBindings']), | 350 | legacyBindingData:Clipperz.Base.evalJSON(someValues['loginBindings']), |
346 | bookmarkletVersion:'0.1' | 351 | bookmarkletVersion:'0.1' |
347 | }); | 352 | }); |
348 | this.addDirectLogin(directLogin, true); | 353 | this.addDirectLogin(directLogin, true); |
349 | } | 354 | } |
350 | //MochiKit.Logging.logDebug("<<< Record.processDataToExtractLegacyValues"); | 355 | //MochiKit.Logging.logDebug("<<< Record.processDataToExtractLegacyValues"); |
351 | }, | 356 | }, |
352 | 357 | ||
353 | //------------------------------------------------------------------------- | 358 | //------------------------------------------------------------------------- |
354 | 359 | ||
355 | 'getReadyBeforeUpdatingVersionValues': function() { | 360 | 'getReadyBeforeUpdatingVersionValues': function() { |
356 | }, | 361 | }, |
357 | 362 | ||
358 | //------------------------------------------------------------------------- | 363 | //------------------------------------------------------------------------- |
359 | 364 | ||
360 | 'addNewField': function() { | 365 | 'addNewField': function() { |
361 | varnewField; | 366 | varnewField; |
362 | 367 | ||
363 | //MochiKit.Logging.logDebug(">>> Record.addNewField - " + this); | 368 | //MochiKit.Logging.logDebug(">>> Record.addNewField - " + this); |
364 | this.getReadyBeforeUpdatingVersionValues(); | 369 | this.getReadyBeforeUpdatingVersionValues(); |
365 | newField = this.currentVersion().addNewField(); | 370 | newField = this.currentVersion().addNewField(); |
366 | Clipperz.NotificationCenter.notify(this, 'recordUpdated'); | 371 | Clipperz.NotificationCenter.notify(this, 'recordUpdated'); |
367 | //MochiKit.Logging.logDebug("<<< Record.addNewField"); | 372 | //MochiKit.Logging.logDebug("<<< Record.addNewField"); |
368 | 373 | ||
369 | return newField; | 374 | return newField; |
370 | }, | 375 | }, |
371 | 376 | ||
372 | //------------------------------------------------------------------------- | 377 | //------------------------------------------------------------------------- |
373 | 378 | ||
374 | 'removeField': function(aField) { | 379 | 'removeField': function(aField) { |
375 | this.getReadyBeforeUpdatingVersionValues(); | 380 | this.getReadyBeforeUpdatingVersionValues(); |
376 | this.currentVersion().removeField(aField); | 381 | this.currentVersion().removeField(aField); |
377 | Clipperz.NotificationCenter.notify(this, 'recordUpdated'); | 382 | Clipperz.NotificationCenter.notify(this, 'recordUpdated'); |
378 | }, | 383 | }, |
379 | 384 | ||
380 | 'removeEmptyFields': function() { | 385 | 'removeEmptyFields': function() { |
381 | MochiKit.Iter.forEach(MochiKit.Base.values(this.currentVersion().fields()), MochiKit.Base.bind(function(aField) { | 386 | MochiKit.Iter.forEach(MochiKit.Base.values(this.currentVersion().fields()), MochiKit.Base.bind(function(aField) { |
382 | if (aField.isEmpty()) { | 387 | if (aField.isEmpty()) { |
383 | this.removeField(aField); | 388 | this.removeField(aField); |
384 | // this.currentVersion().removeField(aField); | 389 | // this.currentVersion().removeField(aField); |
385 | } | 390 | } |
386 | }, this)); | 391 | }, this)); |
387 | }, | 392 | }, |
388 | 393 | ||
389 | //------------------------------------------------------------------------- | 394 | //------------------------------------------------------------------------- |
390 | 395 | ||
391 | 'notes': function() { | 396 | 'notes': function() { |
392 | return this._notes; | 397 | return this._notes; |
393 | }, | 398 | }, |
394 | 399 | ||
395 | 'setNotes': function(aValue) { | 400 | 'setNotes': function(aValue) { |
396 | this._notes = aValue; | 401 | this._notes = aValue; |
397 | this.setHeaderNotes(null); | 402 | this.setHeaderNotes(null); |
398 | }, | 403 | }, |
399 | 404 | ||
400 | //------------------------------------------------------------------------- | 405 | //------------------------------------------------------------------------- |
401 | 406 | ||
402 | 'headerNotes': function() { | 407 | 'headerNotes': function() { |
403 | return this._headerNotes; | 408 | return this._headerNotes; |
404 | }, | 409 | }, |
405 | 410 | ||
406 | 'setHeaderNotes': function(aValue) { | 411 | 'setHeaderNotes': function(aValue) { |
407 | this._headerNotes = aValue; | 412 | this._headerNotes = aValue; |
408 | }, | 413 | }, |
409 | 414 | ||
410 | //------------------------------------------------------------------------- | 415 | //------------------------------------------------------------------------- |
411 | 416 | ||
412 | 'remove': function() { | 417 | 'remove': function() { |
413 | //MochiKit.Logging.logDebug(">>> Record.remove - " + this); | 418 | //MochiKit.Logging.logDebug(">>> Record.remove - " + this); |
414 | MochiKit.Iter.forEach(MochiKit.Base.values(this.directLogins()), MochiKit.Base.method(this, 'removeDirectLogin')); | 419 | MochiKit.Iter.forEach(MochiKit.Base.values(this.directLogins()), MochiKit.Base.method(this, 'removeDirectLogin')); |
415 | 420 | ||
416 | this.syncDirectLoginReferenceValues(); | 421 | this.syncDirectLoginReferenceValues(); |
417 | this.user().removeRecord(this); | 422 | this.user().removeRecord(this); |
418 | //MochiKit.Logging.logDebug("<<< Record.remove"); | 423 | //MochiKit.Logging.logDebug("<<< Record.remove"); |
419 | }, | 424 | }, |
420 | 425 | ||
421 | //------------------------------------------------------------------------- | 426 | //------------------------------------------------------------------------- |
422 | 427 | ||
423 | 'directLogins': function() { | 428 | 'directLogins': function() { |
424 | return this._directLogins; | 429 | return this._directLogins; |
425 | }, | 430 | }, |
426 | 431 | ||
427 | 'addDirectLogin': function(aDirectLogin, shouldUpdateUser) { | 432 | 'addDirectLogin': function(aDirectLogin, shouldUpdateUser) { |
428 | this.directLogins()[aDirectLogin.reference()] = aDirectLogin; | 433 | this.directLogins()[aDirectLogin.reference()] = aDirectLogin; |
429 | if (shouldUpdateUser == true) { | 434 | if (shouldUpdateUser == true) { |
430 | this.user().addDirectLogin(aDirectLogin); | 435 | this.user().addDirectLogin(aDirectLogin); |
431 | } | 436 | } |
432 | }, | 437 | }, |
433 | 438 | ||
434 | 'removeDirectLogin': function(aDirectLogin) { | 439 | 'removeDirectLogin': function(aDirectLogin) { |
435 | this.removedDirectLogins().push(aDirectLogin); | 440 | this.removedDirectLogins().push(aDirectLogin); |
436 | delete this.directLogins()[aDirectLogin.reference()]; | 441 | delete this.directLogins()[aDirectLogin.reference()]; |
437 | // this.user().removeDirectLogin(aDirectLogin); | 442 | // this.user().removeDirectLogin(aDirectLogin); |
438 | }, | 443 | }, |
439 | 444 | ||
440 | 'resetDirectLogins': function() { | 445 | 'resetDirectLogins': function() { |
441 | this._directLogins = {}; | 446 | this._directLogins = {}; |
442 | }, | 447 | }, |
443 | 448 | ||
444 | 'removedDirectLogins': function() { | 449 | 'removedDirectLogins': function() { |
445 | return this._removedDirectLogins; | 450 | return this._removedDirectLogins; |
446 | }, | 451 | }, |
447 | 452 | ||
448 | 'resetRemovedDirectLogins': function() { | 453 | 'resetRemovedDirectLogins': function() { |
449 | this._removedDirectLogins = []; | 454 | this._removedDirectLogins = []; |
450 | }, | 455 | }, |
451 | 456 | ||
452 | //------------------------------------------------------------------------- | 457 | //------------------------------------------------------------------------- |
453 | 458 | ||
454 | 'serverData': function() { | 459 | 'serverData': function() { |
455 | return this._serverData; | 460 | return this._serverData; |
456 | }, | 461 | }, |
457 | 462 | ||
458 | 'setServerData': function(aValue) { | 463 | 'setServerData': function(aValue) { |
459 | this._serverData = aValue; | 464 | this._serverData = aValue; |
460 | this.setShouldLoadData(false); | 465 | this.setShouldLoadData(false); |
461 | return aValue; | 466 | return aValue; |
462 | }, | 467 | }, |
463 | 468 | ||
464 | //------------------------------------------------------------------------- | 469 | //------------------------------------------------------------------------- |
465 | 470 | ||
466 | 'decryptedData': function() { | 471 | 'decryptedData': function() { |
467 | return this._decryptedData; | 472 | return this._decryptedData; |
468 | }, | 473 | }, |
469 | 474 | ||
470 | 'setDecryptedData': function(aValue) { | 475 | 'setDecryptedData': function(aValue) { |
471 | this._decryptedData = aValue; | 476 | this._decryptedData = aValue; |
472 | this.setShouldDecryptData(false); | 477 | this.setShouldDecryptData(false); |
473 | return aValue; | 478 | return aValue; |
474 | }, | 479 | }, |
475 | 480 | ||
476 | //------------------------------------------------------------------------- | 481 | //------------------------------------------------------------------------- |
477 | 482 | ||
478 | 'cachedData': function() { | 483 | 'cachedData': function() { |
479 | return this._cachedData; | 484 | return this._cachedData; |
480 | }, | 485 | }, |
481 | 486 | ||
482 | 'setCachedData': function(aValue) { | 487 | 'setCachedData': function(aValue) { |
483 | //MochiKit.Logging.logDebug(">>> Record.setCachedData"); | 488 | //MochiKit.Logging.logDebug(">>> Record.setCachedData"); |
484 | //MochiKit.Logging.logDebug("--- Record.setCachedData - aValue: " + Clipperz.Base.serializeJSON(aValue)); | 489 | //MochiKit.Logging.logDebug("--- Record.setCachedData - aValue: " + Clipperz.Base.serializeJSON(aValue)); |
485 | this._cachedData = aValue; | 490 | this._cachedData = aValue; |
486 | this.setShouldProcessData(false); | 491 | this.setShouldProcessData(false); |
487 | //MochiKit.Logging.logDebug("<<< Record.setCachedData"); | 492 | //MochiKit.Logging.logDebug("<<< Record.setCachedData"); |
488 | 493 | ||
489 | return aValue; | 494 | return aValue; |
490 | }, | 495 | }, |
491 | 496 | ||
492 | //------------------------------------------------------------------------- | 497 | //------------------------------------------------------------------------- |
493 | 498 | ||
494 | 'hasPendingChanges': function() { | 499 | 'hasPendingChanges': function() { |
495 | var result; | 500 | var result; |
496 | 501 | ||
497 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.hasPendingChanges"); | 502 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.hasPendingChanges"); |
498 | //MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - cachedData: " + this.cachedData()); | 503 | //MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - cachedData: " + this.cachedData()); |
499 | //MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - cachedData: " + Clipperz.Base.serializeJSON(this.cachedData())); | 504 | //MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - cachedData: " + Clipperz.Base.serializeJSON(this.cachedData())); |
500 | //MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - currentSnapshot: " + this.currentDataSnapshot()); | 505 | //MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - currentSnapshot: " + this.currentDataSnapshot()); |
501 | //MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - currentSnapshot: " + Clipperz.Base.serializeJSON(this.currentDataSnapshot())); | 506 | //MochiKit.Logging.logDebug(">>> Record.hasPendingChanges - currentSnapshot: " + Clipperz.Base.serializeJSON(this.currentDataSnapshot())); |
502 | //console.log(">>> Record.hasPendingChanges - cachedData: %o", this.cachedData()); | 507 | //console.log(">>> Record.hasPendingChanges - cachedData: %o", this.cachedData()); |
503 | //console.log(">>> Record.hasPendingChanges - currentSnapshot: %o", this.currentDataSnapshot()); | 508 | //console.log(">>> Record.hasPendingChanges - currentSnapshot: %o", this.currentDataSnapshot()); |
504 | result = (MochiKit.Base.compare(this.cachedData(), this.currentDataSnapshot()) != 0); | 509 | result = (MochiKit.Base.compare(this.cachedData(), this.currentDataSnapshot()) != 0); |
505 | //MochiKit.Logging.logDebug("<<< Record.hasPendingChanges - " + result); | 510 | //MochiKit.Logging.logDebug("<<< Record.hasPendingChanges - " + result); |
506 | 511 | ||
507 | if ((result == false) && this.isBrandNew() && (this.label() != Clipperz.PM.Strings['newRecordTitleLabel'])) { | 512 | if ((result == false) && this.isBrandNew() && (this.label() != Clipperz.PM.Strings['newRecordTitleLabel'])) { |
508 | result = true; | 513 | result = true; |
509 | } | 514 | } |
510 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.hasPendingChanges"); | 515 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.hasPendingChanges"); |
511 | 516 | ||
512 | return result; | 517 | return result; |
513 | }, | 518 | }, |
514 | 519 | ||
515 | //------------------------------------------------------------------------- | 520 | //------------------------------------------------------------------------- |
516 | 521 | ||
517 | 'currentDataSnapshot': function() { | 522 | 'currentDataSnapshot': function() { |
518 | varresult; | 523 | varresult; |
519 | 524 | ||
520 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.currentDataSnapshot"); | 525 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.currentDataSnapshot"); |
521 | result = { | 526 | result = { |
522 | 'label': this.label(), | 527 | 'label': this.label(), |
523 | 'data': this.serializedData(), | 528 | 'data': this.serializedData(), |
524 | 'currentVersion': this.currentVersion().currentDataSnapshot() | 529 | 'currentVersion': this.currentVersion().currentDataSnapshot() |
525 | }; | 530 | }; |
526 | 531 | ||
527 | // result['data']['data'] = this.notes(); | 532 | // result['data']['data'] = this.notes(); |
528 | result = Clipperz.Base.serializeJSON(result); | 533 | result = Clipperz.Base.serializeJSON(result); |
529 | 534 | ||
530 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.currentDataSnapshot"); | 535 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.currentDataSnapshot"); |
531 | //MochiKit.Logging.logDebug("<<< Record.currentDataSnapshot"); | 536 | //MochiKit.Logging.logDebug("<<< Record.currentDataSnapshot"); |
532 | 537 | ||
533 | return result; | 538 | return result; |
534 | }, | 539 | }, |
535 | 540 | ||
536 | //......................................................................... | 541 | //......................................................................... |
537 | 542 | ||
538 | 'takeSnapshotOfCurrentData': function() { | 543 | 'takeSnapshotOfCurrentData': function() { |
539 | this.setCachedData(this.currentDataSnapshot()); | 544 | this.setCachedData(this.currentDataSnapshot()); |
540 | }, | 545 | }, |
541 | 546 | ||
542 | //------------------------------------------------------------------------- | 547 | //------------------------------------------------------------------------- |
543 | 548 | ||
544 | 'headerData': function() { | 549 | 'headerData': function() { |
545 | var result; | 550 | var result; |
546 | 551 | ||
547 | result = { | 552 | result = { |
548 | 'label': this.label(), | 553 | 'label': this.label(), |
549 | 'key': this.key() | 554 | 'key': this.key() |
550 | }; | 555 | }; |
551 | 556 | ||
552 | if (this.headerNotes() != null) { | 557 | if (this.headerNotes() != null) { |
553 | result['headerNotes'] = this.headerNotes(); | 558 | result['headerNotes'] = this.headerNotes(); |
554 | } | 559 | } |
555 | 560 | ||
556 | return result; | 561 | return result; |
557 | }, | 562 | }, |
558 | 563 | ||
559 | //------------------------------------------------------------------------- | 564 | //------------------------------------------------------------------------- |
560 | 565 | ||
561 | 'serializedData': function() { | 566 | 'serializedData': function() { |
562 | var result; | 567 | var result; |
563 | var directLoginReference; | 568 | var directLoginReference; |
564 | 569 | ||
565 | result = {}; | 570 | result = {}; |
566 | result['currentVersionKey'] = this.currentVersion().key(); | 571 | result['currentVersionKey'] = this.currentVersion().key(); |
567 | 572 | ||
568 | result['directLogins'] = {}; | 573 | result['directLogins'] = {}; |
569 | for (directLoginReference in this.directLogins()) { | 574 | for (directLoginReference in this.directLogins()) { |
570 | result['directLogins'][directLoginReference] = this.directLogins()[directLoginReference].serializedData(); | 575 | result['directLogins'][directLoginReference] = this.directLogins()[directLoginReference].serializedData(); |
571 | } | 576 | } |
572 | result['notes'] = this.notes(); | 577 | result['notes'] = this.notes(); |
573 | 578 | ||
574 | return result; | 579 | return result; |
575 | }, | 580 | }, |
576 | 581 | ||
577 | //------------------------------------------------------------------------- | 582 | //------------------------------------------------------------------------- |
578 | 583 | ||
579 | 'encryptedData': function() { | 584 | 'encryptedData': function() { |
580 | var deferredResult; | 585 | var deferredResult; |
581 | varresult; | 586 | varresult; |
582 | 587 | ||
583 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.encryptedData"); | 588 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.encryptedData"); |
584 | result = {} | 589 | result = {} |
585 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 1"); | 590 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 1"); |
586 | deferredResult = new MochiKit.Async.Deferred(); | 591 | deferredResult = new MochiKit.Async.Deferred(); |
587 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 2"); | 592 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 2"); |
588 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 1: " + res); return res;}); | 593 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 1: " + res); return res;}); |
589 | deferredResult.addCallback(function(aResult, aRecord) { | 594 | deferredResult.addCallback(function(aResult, aRecord) { |
590 | aResult['reference'] = aRecord.reference(); | 595 | aResult['reference'] = aRecord.reference(); |
591 | return aResult; | 596 | return aResult; |
592 | }, result, this); | 597 | }, result, this); |
593 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 3"); | 598 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 3"); |
594 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 2: " + res); return res;}); | 599 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 2: " + res); return res;}); |
595 | deferredResult.addCallback(Clipperz.PM.Crypto.deferredEncryptWithCurrentVersion, this.key(), this.serializedData()); | 600 | deferredResult.addCallback(Clipperz.PM.Crypto.deferredEncryptWithCurrentVersion, this.key(), this.serializedData()); |
596 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 4"); | 601 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 4"); |
597 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 3: " + res); return res;}); | 602 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 3: " + res); return res;}); |
598 | deferredResult.addCallback(function(aResult, res) { | 603 | deferredResult.addCallback(function(aResult, res) { |
599 | aResult['data'] = res; | 604 | aResult['data'] = res; |
600 | return aResult; | 605 | return aResult; |
601 | }, result); | 606 | }, result); |
602 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 5"); | 607 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 5"); |
603 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 4: " + res); return res;}); | 608 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 4: " + res); return res;}); |
604 | deferredResult.addCallback(function(aResult) { | 609 | deferredResult.addCallback(function(aResult) { |
605 | aResult['version'] = Clipperz.PM.Crypto.encryptingFunctions.currentVersion; | 610 | aResult['version'] = Clipperz.PM.Crypto.encryptingFunctions.currentVersion; |
606 | return aResult; | 611 | return aResult; |
607 | }, result); | 612 | }, result); |
608 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 6"); | 613 | //MochiKit.Logging.logDebug("--- Record.encryptedData - 6"); |
609 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 5: " + res); return res;}); | 614 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.encryptedData - 5: " + res); return res;}); |
610 | deferredResult.callback(); | 615 | deferredResult.callback(); |
611 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.encryptedData"); | 616 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.encryptedData"); |
612 | 617 | ||
613 | return deferredResult; | 618 | return deferredResult; |
614 | }, | 619 | }, |
615 | 620 | ||
616 | //------------------------------------------------------------------------- | 621 | //------------------------------------------------------------------------- |
617 | 622 | ||
618 | 'syncDirectLoginReferenceValues': function() { | 623 | 'syncDirectLoginReferenceValues': function() { |
619 | //MochiKit.Logging.logDebug(">>> Record.syncDirectLoginReferenceValues"); | 624 | //MochiKit.Logging.logDebug(">>> Record.syncDirectLoginReferenceValues"); |
620 | MochiKit.Iter.forEach(MochiKit.Base.values(this.directLogins()), function(aDirectLogin) { | 625 | MochiKit.Iter.forEach(MochiKit.Base.values(this.directLogins()), function(aDirectLogin) { |
621 | aDirectLogin.record().user().synchronizeDirectLogin(aDirectLogin); | 626 | aDirectLogin.record().user().synchronizeDirectLogin(aDirectLogin); |
622 | }); | 627 | }); |
623 | 628 | ||
624 | MochiKit.Iter.forEach(this.removedDirectLogins(), function(aDirectLogin) { | 629 | MochiKit.Iter.forEach(this.removedDirectLogins(), function(aDirectLogin) { |
625 | aDirectLogin.record().user().removeDirectLogin(aDirectLogin); | 630 | aDirectLogin.record().user().removeDirectLogin(aDirectLogin); |
626 | }); | 631 | }); |
627 | 632 | ||
628 | this.resetRemovedDirectLogins(); | 633 | this.resetRemovedDirectLogins(); |
629 | //MochiKit.Logging.logDebug("<<< Record.syncDirectLoginReferenceValues"); | 634 | //MochiKit.Logging.logDebug("<<< Record.syncDirectLoginReferenceValues"); |
630 | }, | 635 | }, |
631 | 636 | ||
632 | //------------------------------------------------------------------------- | 637 | //------------------------------------------------------------------------- |
633 | 638 | ||
634 | 'saveChanges': function() { | 639 | 'saveChanges': function() { |
635 | var result; | 640 | var result; |
636 | 641 | ||
637 | if (this.isBrandNew() == false) { | 642 | if (this.isBrandNew() == false) { |
638 | result = this.user().saveRecords([this], 'updateData'); | 643 | result = this.user().saveRecords([this], 'updateData'); |
639 | } else { | 644 | } else { |
640 | result = this.user().saveRecords([this], 'addNewRecords'); | 645 | result = this.user().saveRecords([this], 'addNewRecords'); |
641 | } | 646 | } |
642 | 647 | ||
643 | return result; | 648 | return result; |
644 | }, | 649 | }, |
645 | 650 | ||
646 | /* | 651 | /* |
647 | 'saveChanges': function() { | 652 | 'saveChanges': function() { |
648 | var deferredResult; | 653 | var deferredResult; |
649 | varresult; | 654 | varresult; |
650 | 655 | ||
651 | Clipperz.NotificationCenter.notify(this.user(), 'updatedSection', 'records', true); | 656 | Clipperz.NotificationCenter.notify(this.user(), 'updatedSection', 'records', true); |
652 | //MochiKit.Logging.logDebug(">>> Record.saveChanges"); | 657 | //MochiKit.Logging.logDebug(">>> Record.saveChanges"); |
653 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.saveChanges"); | 658 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.saveChanges"); |
654 | if (this.headerNotes() != null) { | 659 | if (this.headerNotes() != null) { |
655 | this.setNotes(this.headerNotes()); | 660 | this.setNotes(this.headerNotes()); |
656 | } | 661 | } |
657 | this.syncDirectLoginReferenceValues(); | 662 | this.syncDirectLoginReferenceValues(); |
658 | this.currentVersion().createNewVersion(); | 663 | this.currentVersion().createNewVersion(); |
659 | 664 | ||
660 | result = {'records': [{}]}; | 665 | result = {'records': [{}]}; |
661 | 666 | ||
662 | deferredResult = new MochiKit.Async.Deferred(); | 667 | deferredResult = new MochiKit.Async.Deferred(); |
663 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_collectRecordInfo'); | 668 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_collectRecordInfo'); |
664 | deferredResult.addCallback(MochiKit.Base.method(this, 'updateKey')); | 669 | deferredResult.addCallback(MochiKit.Base.method(this, 'updateKey')); |
665 | 670 | ||
666 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_encryptUserData'); | 671 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_encryptUserData'); |
667 | deferredResult.addCallback(MochiKit.Base.method(this.user(), 'encryptedData')); | 672 | deferredResult.addCallback(MochiKit.Base.method(this.user(), 'encryptedData')); |
668 | deferredResult.addCallback(function(aResult, res) { | 673 | deferredResult.addCallback(function(aResult, res) { |
669 | aResult['user'] = res; | 674 | aResult['user'] = res; |
670 | return aResult; | 675 | return aResult; |
671 | }, result); | 676 | }, result); |
672 | 677 | ||
673 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_encryptRecordData'); | 678 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_encryptRecordData'); |
674 | deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedData')); | 679 | deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedData')); |
675 | deferredResult.addCallback(function(aResult, res) { | 680 | deferredResult.addCallback(function(aResult, res) { |
676 | //# aResult['record'] = res; | 681 | //# aResult['record'] = res; |
677 | aResult['records'][0]['record'] = res; | 682 | aResult['records'][0]['record'] = res; |
678 | return aResult; | 683 | return aResult; |
679 | }, result); | 684 | }, result); |
680 | 685 | ||
681 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_encryptRecordVersions'); | 686 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_encryptRecordVersions'); |
682 | deferredResult.addCallback(MochiKit.Base.method(this.currentVersion(), 'encryptedData')); | 687 | deferredResult.addCallback(MochiKit.Base.method(this.currentVersion(), 'encryptedData')); |
683 | deferredResult.addCallback(function(aResult, res) { | 688 | deferredResult.addCallback(function(aResult, res) { |
684 | // aResult['currentRecordVersion'] = res; | 689 | // aResult['currentRecordVersion'] = res; |
685 | aResult['records'][0]['currentRecordVersion'] = res; | 690 | aResult['records'][0]['currentRecordVersion'] = res; |
686 | return aResult; | 691 | return aResult; |
687 | }, result); | 692 | }, result); |
688 | 693 | ||
689 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_sendingData'); | 694 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_sendingData'); |
690 | if (this.isBrandNew() == false) { | 695 | if (this.isBrandNew() == false) { |
691 | deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'updateData'); | 696 | deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'updateData'); |
692 | } else { | 697 | } else { |
693 | //# deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'addNewRecord'); | 698 | //# deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'addNewRecord'); |
694 | deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'addNewRecords'); | 699 | deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'addNewRecords'); |
695 | } | 700 | } |
696 | 701 | ||
697 | deferredResult.addCallback(MochiKit.Base.method(this, 'takeSnapshotOfCurrentData')); | 702 | deferredResult.addCallback(MochiKit.Base.method(this, 'takeSnapshotOfCurrentData')); |
698 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_updatingInterface'); | 703 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveCard_updatingInterface'); |
699 | deferredResult.addCallback(MochiKit.Base.method(this, 'setIsBrandNew'), false); | 704 | deferredResult.addCallback(MochiKit.Base.method(this, 'setIsBrandNew'), false); |
700 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'recordUpdated'); | 705 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'recordUpdated'); |
701 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'directLoginUpdated'); | 706 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'directLoginUpdated'); |
702 | deferredResult.callback(); | 707 | deferredResult.callback(); |
703 | 708 | ||
704 | return deferredResult; | 709 | return deferredResult; |
705 | }, | 710 | }, |
706 | */ | 711 | */ |
707 | //------------------------------------------------------------------------- | 712 | //------------------------------------------------------------------------- |
708 | 713 | ||
709 | 'cancelChanges': function() { | 714 | 'cancelChanges': function() { |
710 | //MochiKit.Logging.logDebug(">>> Record.cancelChanges"); | 715 | //MochiKit.Logging.logDebug(">>> Record.cancelChanges"); |
711 | //MochiKit.Logging.logDebug("--- Record.cancelChanges - cachedData: " + Clipperz.Base.serializeJSON(this.cachedData())); | 716 | //MochiKit.Logging.logDebug("--- Record.cancelChanges - cachedData: " + Clipperz.Base.serializeJSON(this.cachedData())); |
712 | if (this.isBrandNew()) { | 717 | if (this.isBrandNew()) { |
713 | this.user().removeRecord(this); | 718 | this.user().removeRecord(this); |
714 | } else { | 719 | } else { |
715 | this.restoreValuesFromSnapshot(this.cachedData()); | 720 | this.restoreValuesFromSnapshot(this.cachedData()); |
716 | } | 721 | } |
717 | //MochiKit.Logging.logDebug("<<< Record.cancelChanges"); | 722 | //MochiKit.Logging.logDebug("<<< Record.cancelChanges"); |
718 | }, | 723 | }, |
719 | 724 | ||
720 | //------------------------------------------------------------------------- | 725 | //------------------------------------------------------------------------- |
721 | 726 | ||
722 | 'restoreValuesFromSnapshot': function(someSnapshotData) { | 727 | 'restoreValuesFromSnapshot': function(someSnapshotData) { |
723 | varsnapshotData; | 728 | varsnapshotData; |
724 | 729 | ||
725 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.restoreValuesFromSnapshot"); | 730 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.restoreValuesFromSnapshot"); |
726 | snapshotData = Clipperz.Base.evalJSON(someSnapshotData); | 731 | snapshotData = Clipperz.Base.evalJSON(someSnapshotData); |
727 | //MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - someSnapshotData (1): " + Clipperz.Base.serializeJSON(someSnapshotData)); | 732 | //MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - someSnapshotData (1): " + Clipperz.Base.serializeJSON(someSnapshotData)); |
728 | this.setLabel(snapshotData['label']); | 733 | this.setLabel(snapshotData['label']); |
729 | this.resetDirectLogins(); | 734 | this.resetDirectLogins(); |
730 | this.setShouldProcessData(true); | 735 | this.setShouldProcessData(true); |
731 | this.processData(snapshotData); | 736 | this.processData(snapshotData); |
732 | //MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - snapshotData: (2)" + Clipperz.Base.serializeJSON(snapshotData)); | 737 | //MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - snapshotData: (2)" + Clipperz.Base.serializeJSON(snapshotData)); |
733 | 738 | ||
734 | this.resetRemovedDirectLogins(); | 739 | this.resetRemovedDirectLogins(); |
735 | 740 | ||
736 | { | 741 | { |
737 | var currentSnapshot; | 742 | var currentSnapshot; |
738 | varcomparisonResult; | 743 | varcomparisonResult; |
739 | 744 | ||
740 | currentSnapshot = this.currentDataSnapshot(); | 745 | currentSnapshot = this.currentDataSnapshot(); |
741 | //MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - 1"); | 746 | //MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - 1"); |
742 | //console.log("snapshot data: %o", someSnapshotData.currentVersion); | 747 | //console.log("snapshot data: %o", someSnapshotData.currentVersion); |
743 | //console.log("current data: %o", currentSnapshot.currentVersion); | 748 | //console.log("current data: %o", currentSnapshot.currentVersion); |
744 | //MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - someSnapshotData: " + Clipperz.Base.serializeJSON(someSnapshotData.currentVersion)); | 749 | //MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - someSnapshotData: " + Clipperz.Base.serializeJSON(someSnapshotData.currentVersion)); |
745 | //MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - currentSnapshot: " + Clipperz.Base.serializeJSON(currentSnapshot.currentVersion)); | 750 | //MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - currentSnapshot: " + Clipperz.Base.serializeJSON(currentSnapshot.currentVersion)); |
746 | comparisonResult = MochiKit.Base.compare(someSnapshotData.currentVersion, currentSnapshot.currentVersion); | 751 | comparisonResult = MochiKit.Base.compare(someSnapshotData.currentVersion, currentSnapshot.currentVersion); |
747 | //MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - " + comparisonResult); | 752 | //MochiKit.Logging.logDebug("--- Record.restoreValuesFromSnapshot - " + comparisonResult); |
748 | } | 753 | } |
749 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.restoreValuesFromSnapshot"); | 754 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.restoreValuesFromSnapshot"); |
750 | }, | 755 | }, |
751 | 756 | ||
752 | //------------------------------------------------------------------------- | 757 | //------------------------------------------------------------------------- |
753 | __syntaxFix__: "syntax fix" | 758 | __syntaxFix__: "syntax fix" |
754 | }); | 759 | }); |
755 | 760 | ||
756 | 761 | ||
diff --git a/frontend/beta/js/Clipperz/PM/Proxy.js b/frontend/beta/js/Clipperz/PM/Proxy.js index f476196..bec9195 100644 --- a/frontend/beta/js/Clipperz/PM/Proxy.js +++ b/frontend/beta/js/Clipperz/PM/Proxy.js | |||
@@ -1,170 +1,169 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2011 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz Community Edition. |
6 | Clipperz Community Edition is an online password manager. | 6 | Clipperz Community Edition is an online password manager. |
7 | For further information about its features and functionalities please | 7 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 8 | refer to http://www.clipperz.com. |
9 | 9 | ||
10 | * Clipperz Community Edition is free software: you can redistribute | 10 | * Clipperz Community Edition is free software: you can redistribute |
11 | it and/or modify it under the terms of the GNU Affero General Public | 11 | it and/or modify it under the terms of the GNU Affero General Public |
12 | License as published by the Free Software Foundation, either version | 12 | License as published by the Free Software Foundation, either version |
13 | 3 of the License, or (at your option) any later version. | 13 | 3 of the License, or (at your option) any later version. |
14 | 14 | ||
15 | * Clipperz Community Edition is distributed in the hope that it will | 15 | * Clipperz Community Edition is distributed in the hope that it will |
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 16 | be useful, but WITHOUT ANY WARRANTY; without even the implied |
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. | 18 | See the GNU Affero General Public License for more details. |
19 | 19 | ||
20 | * You should have received a copy of the GNU Affero General Public | 20 | * You should have received a copy of the GNU Affero General Public |
21 | License along with Clipperz Community Edition. If not, see | 21 | License along with Clipperz Community Edition. If not, see |
22 | <http://www.gnu.org/licenses/>. | 22 | <http://www.gnu.org/licenses/>. |
23 | 23 | ||
24 | */ | 24 | */ |
25 | 25 | ||
26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | 27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } |
28 | 28 | ||
29 | //============================================================================= | 29 | //============================================================================= |
30 | 30 | ||
31 | Clipperz.PM.Proxy = function(args) { | 31 | Clipperz.PM.Proxy = function(args) { |
32 | args = args || {}; | 32 | args = args || {}; |
33 | 33 | ||
34 | this._shouldPayTolls = args.shouldPayTolls || false; | 34 | this._shouldPayTolls = args.shouldPayTolls || false; |
35 | 35 | ||
36 | this._tolls = { | 36 | this._tolls = { |
37 | 'CONNECT':[], | 37 | 'CONNECT':[], |
38 | 'REGISTER':[], | 38 | 'REGISTER':[], |
39 | 'MESSAGE':[] | 39 | 'MESSAGE':[] |
40 | }; | 40 | }; |
41 | 41 | ||
42 | if (args.isDefault === true) { | 42 | if (args.isDefault === true) { |
43 | Clipperz.PM.Proxy.defaultProxy = this; | 43 | Clipperz.PM.Proxy.defaultProxy = this; |
44 | } | 44 | } |
45 | 45 | ||
46 | return this; | 46 | return this; |
47 | } | 47 | } |
48 | 48 | ||
49 | Clipperz.PM.Proxy.prototype = MochiKit.Base.update(null, { | 49 | Clipperz.PM.Proxy.prototype = MochiKit.Base.update(null, { |
50 | 50 | ||
51 | 'toString': function() { | 51 | 'toString': function() { |
52 | return "Clipperz.PM.Proxy"; | 52 | return "Clipperz.PM.Proxy"; |
53 | }, | 53 | }, |
54 | 54 | ||
55 | //========================================================================= | 55 | //========================================================================= |
56 | 56 | ||
57 | 'shouldPayTolls': function() { | 57 | 'shouldPayTolls': function() { |
58 | return this._shouldPayTolls; | 58 | return this._shouldPayTolls; |
59 | }, | 59 | }, |
60 | 60 | ||
61 | //------------------------------------------------------------------------- | 61 | //------------------------------------------------------------------------- |
62 | 62 | ||
63 | 'tolls': function() { | 63 | 'tolls': function() { |
64 | return this._tolls; | 64 | return this._tolls; |
65 | }, | 65 | }, |
66 | 66 | ||
67 | //------------------------------------------------------------------------- | 67 | //------------------------------------------------------------------------- |
68 | 68 | ||
69 | 'payToll': function(aRequestType, someParameters) { | 69 | 'payToll': function(aRequestType, someParameters) { |
70 | vardeferredResult; | 70 | vardeferredResult; |
71 | 71 | ||
72 | //console.log(">>> Proxy.payToll", aRequestType, someParameters); | 72 | //console.log(">>> Proxy.payToll", aRequestType, someParameters); |
73 | if (this.shouldPayTolls()) { | 73 | if (this.shouldPayTolls()) { |
74 | deferredResult = new MochiKit.Async.Deferred(); | 74 | deferredResult = new MochiKit.Async.Deferred(); |
75 | 75 | ||
76 | if (this.tolls()[aRequestType].length == 0) { | 76 | if (this.tolls()[aRequestType].length == 0) { |
77 | deferredResult.addCallback(MochiKit.Base.method(this, 'sendMessage', 'knock', {requestType:aRequestType})); | 77 | deferredResult.addCallback(MochiKit.Base.method(this, 'sendMessage', 'knock', {requestType:aRequestType})); |
78 | deferredResult.addCallback(MochiKit.Base.method(this, 'setTollCallback')); | 78 | deferredResult.addCallback(MochiKit.Base.method(this, 'setTollCallback')); |
79 | } | 79 | } |
80 | deferredResult.addCallback(MochiKit.Base.method(this.tolls()[aRequestType], 'pop')); | 80 | deferredResult.addCallback(MochiKit.Base.method(this.tolls()[aRequestType], 'pop')); |
81 | deferredResult.addCallback(MochiKit.Base.methodcaller('deferredPay')); | 81 | deferredResult.addCallback(MochiKit.Base.methodcaller('deferredPay')); |
82 | deferredResult.addCallback(function(aToll) { | 82 | deferredResult.addCallback(function(aToll) { |
83 | var result; | 83 | var result; |
84 | 84 | ||
85 | result = { | 85 | result = { |
86 | parameters: someParameters, | 86 | parameters: someParameters, |
87 | toll: aToll | 87 | toll: aToll |
88 | } | 88 | } |
89 | 89 | ||
90 | return result; | 90 | return result; |
91 | }); | 91 | }); |
92 | 92 | ||
93 | deferredResult.callback(); | 93 | deferredResult.callback(); |
94 | } else { | 94 | } else { |
95 | deferredResult = MochiKit.Async.succeed({parameters:someParameters}); | 95 | deferredResult = MochiKit.Async.succeed({parameters:someParameters}); |
96 | } | 96 | } |
97 | //console.log("<<< Proxy.payToll"); | 97 | //console.log("<<< Proxy.payToll"); |
98 | 98 | ||
99 | return deferredResult; | 99 | return deferredResult; |
100 | }, | 100 | }, |
101 | 101 | ||
102 | //------------------------------------------------------------------------- | 102 | //------------------------------------------------------------------------- |
103 | 103 | ||
104 | 'addToll': function(aToll) { | 104 | 'addToll': function(aToll) { |
105 | //console.log(">>> Proxy.addToll", aToll); | 105 | //console.log(">>> Proxy.addToll", aToll); |
106 | this.tolls()[aToll.requestType()].push(aToll); | 106 | this.tolls()[aToll.requestType()].push(aToll); |
107 | //console.log("<<< Proxy.addToll"); | 107 | //console.log("<<< Proxy.addToll"); |
108 | }, | 108 | }, |
109 | 109 | ||
110 | //========================================================================= | 110 | //========================================================================= |
111 | 111 | ||
112 | 'setTollCallback': function(someParameters) { | 112 | 'setTollCallback': function(someParameters) { |
113 | //console.log(">>> Proxy.setTollCallback", someParameters); | 113 | //console.log(">>> Proxy.setTollCallback", someParameters); |
114 | if (typeof(someParameters['toll']) != 'undefined') { | 114 | if (typeof(someParameters['toll']) != 'undefined') { |
115 | //console.log("added a new toll", someParameters['toll']); | 115 | //console.log("added a new toll", someParameters['toll']); |
116 | this.addToll(new Clipperz.PM.Toll(someParameters['toll'])); | 116 | this.addToll(new Clipperz.PM.Toll(someParameters['toll'])); |
117 | } | 117 | } |
118 | //console.log("<<< Proxy.setTallCallback", someParameters['result']); | 118 | //console.log("<<< Proxy.setTallCallback", someParameters['result']); |
119 | //return someParameters['result']; | 119 | return someParameters['result']; |
120 | return someParameters; | ||
121 | }, | 120 | }, |
122 | 121 | ||
123 | //========================================================================= | 122 | //========================================================================= |
124 | 123 | ||
125 | 'registration': function (someParameters) { | 124 | 'registration': function (someParameters) { |
126 | return this.processMessage('registration', someParameters, 'REGISTER'); | 125 | return this.processMessage('registration', someParameters, 'REGISTER'); |
127 | }, | 126 | }, |
128 | 127 | ||
129 | 'handshake': function (someParameters) { | 128 | 'handshake': function (someParameters) { |
130 | return this.processMessage('handshake', someParameters, 'CONNECT'); | 129 | return this.processMessage('handshake', someParameters, 'CONNECT'); |
131 | }, | 130 | }, |
132 | 131 | ||
133 | 'message': function (someParameters) { | 132 | 'message': function (someParameters) { |
134 | return this.processMessage('message', someParameters, 'MESSAGE'); | 133 | return this.processMessage('message', someParameters, 'MESSAGE'); |
135 | }, | 134 | }, |
136 | 135 | ||
137 | 'logout': function (someParameters) { | 136 | 'logout': function (someParameters) { |
138 | return this.processMessage('logout', someParameters, 'MESSAGE'); | 137 | return this.processMessage('logout', someParameters, 'MESSAGE'); |
139 | }, | 138 | }, |
140 | 139 | ||
141 | //========================================================================= | 140 | //========================================================================= |
142 | 141 | ||
143 | 'processMessage': function (aFunctionName, someParameters, aRequestType) { | 142 | 'processMessage': function (aFunctionName, someParameters, aRequestType) { |
144 | vardeferredResult; | 143 | vardeferredResult; |
145 | 144 | ||
146 | deferredResult = new MochiKit.Async.Deferred(); | 145 | deferredResult = new MochiKit.Async.Deferred(); |
147 | deferredResult.addCallback(MochiKit.Base.method(this, 'payToll', aRequestType)); | 146 | deferredResult.addCallback(MochiKit.Base.method(this, 'payToll', aRequestType)); |
148 | deferredResult.addCallback(MochiKit.Base.method(this, 'sendMessage', aFunctionName)); | 147 | deferredResult.addCallback(MochiKit.Base.method(this, 'sendMessage', aFunctionName)); |
149 | deferredResult.addCallback(MochiKit.Base.method(this, 'setTollCallback')); | 148 | deferredResult.addCallback(MochiKit.Base.method(this, 'setTollCallback')); |
150 | deferredResult.callback(someParameters); | 149 | deferredResult.callback(someParameters); |
151 | 150 | ||
152 | return deferredResult; | 151 | return deferredResult; |
153 | }, | 152 | }, |
154 | 153 | ||
155 | //========================================================================= | 154 | //========================================================================= |
156 | 155 | ||
157 | 'sendMessage': function () { | 156 | 'sendMessage': function () { |
158 | throw Clipperz.Base.exception.AbstractMethod; | 157 | throw Clipperz.Base.exception.AbstractMethod; |
159 | }, | 158 | }, |
160 | 159 | ||
161 | //========================================================================= | 160 | //========================================================================= |
162 | 161 | ||
163 | 'isReadOnly': function () { | 162 | 'isReadOnly': function () { |
164 | return false; | 163 | return false; |
165 | }, | 164 | }, |
166 | 165 | ||
167 | //========================================================================= | 166 | //========================================================================= |
168 | __syntaxFix__: "syntax fix" | 167 | __syntaxFix__: "syntax fix" |
169 | 168 | ||
170 | }); | 169 | }); |
diff --git a/frontend/beta/js/Clipperz/PM/Proxy/Proxy.PHP.js b/frontend/beta/js/Clipperz/PM/Proxy/Proxy.PHP.js deleted file mode 100755 index 34a10c2..0000000 --- a/frontend/beta/js/Clipperz/PM/Proxy/Proxy.PHP.js +++ b/dev/null | |||
@@ -1,262 +0,0 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz Community Edition. | ||
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | ||
8 | refer to http://www.clipperz.com. | ||
9 | |||
10 | * Clipperz Community Edition is free software: you can redistribute | ||
11 | it and/or modify it under the terms of the GNU Affero General Public | ||
12 | License as published by the Free Software Foundation, either version | ||
13 | 3 of the License, or (at your option) any later version. | ||
14 | |||
15 | * Clipperz Community Edition is distributed in the hope that it will | ||
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
18 | See the GNU Affero General Public License for more details. | ||
19 | |||
20 | * You should have received a copy of the GNU Affero General Public | ||
21 | License along with Clipperz Community Edition. If not, see | ||
22 | <http://www.gnu.org/licenses/>. | ||
23 | |||
24 | */ | ||
25 | |||
26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | ||
27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | ||
28 | |||
29 | //============================================================================= | ||
30 | |||
31 | Clipperz.PM.Proxy.PHP = function(args) { | ||
32 | Clipperz.PM.Proxy.PHP.superclass.constructor.call(this, args); | ||
33 | /* | ||
34 | this._tolls = { | ||
35 | 'CONNECT':[], | ||
36 | 'REGISTER':[], | ||
37 | 'MESSAGE':[] | ||
38 | }; | ||
39 | */ | ||
40 | return this; | ||
41 | } | ||
42 | |||
43 | YAHOO.extendX(Clipperz.PM.Proxy.PHP, Clipperz.PM.Proxy, { | ||
44 | |||
45 | 'toString': function() { | ||
46 | return "Clipperz.PM.Proxy.PHP - " + this.args(); | ||
47 | }, | ||
48 | |||
49 | //========================================================================= | ||
50 | /* | ||
51 | 'tolls': function() { | ||
52 | return this._tolls; | ||
53 | }, | ||
54 | */ | ||
55 | //------------------------------------------------------------------------- | ||
56 | /* | ||
57 | 'payToll': function(aRequestType, someParameters) { | ||
58 | vardeferredResult; | ||
59 | |||
60 | //MochiKit.Logging.logDebug(">>> Proxy.DWR.payToll: " + aRequestType); | ||
61 | if (this.tolls()[aRequestType].length > 0) { | ||
62 | deferredResult = MochiKit.Async.succeed(this.tolls()[aRequestType].pop()); | ||
63 | } else { | ||
64 | //MochiKit.Logging.logDebug("### " + aRequestType + " toll NOT immediately available; request queued."); | ||
65 | deferredResult = new MochiKit.Async.Deferred(); | ||
66 | deferredResult.addCallback(function(someParameters) { | ||
67 | return new Clipperz.PM.Toll(someParameters['toll']); | ||
68 | }) | ||
69 | com_clipperz_pm_Proxy.knock(Clipperz.Base.serializeJSON({requestType:aRequestType}), { | ||
70 | callback:MochiKit.Base.method(deferredResult, 'callback'), | ||
71 | errorHandler:MochiKit.Base.method(deferredResult, 'errback') | ||
72 | }); | ||
73 | } | ||
74 | |||
75 | deferredResult.addCallback(function(aToll) { | ||
76 | return aToll.deferredPay(); | ||
77 | }); | ||
78 | deferredResult.addCallback(function(someParameters, aToll) { | ||
79 | var result; | ||
80 | |||
81 | result = { | ||
82 | parameters: someParameters, | ||
83 | toll: aToll | ||
84 | } | ||
85 | |||
86 | return result; | ||
87 | }, someParameters); | ||
88 | |||
89 | return deferredResult; | ||
90 | }, | ||
91 | */ | ||
92 | //------------------------------------------------------------------------- | ||
93 | /* | ||
94 | 'addToll': function(aToll) { | ||
95 | this.tolls()[aToll.requestType()].push(aToll); | ||
96 | }, | ||
97 | */ | ||
98 | //========================================================================= | ||
99 | /* | ||
100 | 'setTollCallback': function(someParameters) { | ||
101 | //MochiKit.Logging.logDebug(">>> Proxy.DWR.setTollCallback"); | ||
102 | //MochiKit.Logging.logDebug("--- Proxy.DWR.setTollCallback - " + Clipperz.Base.serializeJSON(someParameters)); | ||
103 | if (typeof(someParameters['toll']) != 'undefined') { | ||
104 | this.addToll(new Clipperz.PM.Toll(someParameters['toll'])); | ||
105 | } | ||
106 | return someParameters['result']; | ||
107 | }, | ||
108 | */ | ||
109 | //========================================================================= | ||
110 | |||
111 | 'registration': function(someParameters) { | ||
112 | return this.sendMessage('registration', someParameters, 'REGISTER'); | ||
113 | }, | ||
114 | |||
115 | //------------------------------------------------------------------------- | ||
116 | |||
117 | 'handshake': function(someParameters) { | ||
118 | /* | ||
119 | _s = "e8a2162f29aeaabb729f5625e9740edbf0cd80ac77c6b19ab951ed6c88443b8c"; | ||
120 | _v = new Clipperz.Crypto.BigInt("955e2db0f7844aca372f5799e5f7e51b5866718493096908bd66abcf1d068108", 16); | ||
121 | _b = new Clipperz.Crypto.BigInt("5761e6c84d22ea3c5649de01702d60f674ccfe79238540eb34c61cd020230c53", 16); | ||
122 | |||
123 | _B = _v.add(Clipperz.Crypto.SRP.g().powerModule(_b, Clipperz.Crypto.SRP.n())); | ||
124 | _u = new Clipperz.Crypto.BigInt(Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(_B.asString(10))).toHexString(), 16); | ||
125 | _A = new Clipperz.Crypto.BigInt("3b3567ec33d73673552e960872eb154d091a2488915941038aef759236a27e64", 16); | ||
126 | _S = (_A.multiply(_v.powerModule(_u, Clipperz.Crypto.SRP.n()))).powerModule(_b, Clipperz.Crypto.SRP.n()); | ||
127 | _K = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(_S.asString(10))).toHexString().slice(2); | ||
128 | _M1 = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(_A.asString(10) + _B.asString(10) + _K)).toHexString().slice(2); | ||
129 | _M2 = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(_A.asString(10) + _M1 + _K)).toHexString().slice(2); | ||
130 | |||
131 | // MochiKit.Logging.logDebug("b = " + _b.asString(16)); | ||
132 | // MochiKit.Logging.logDebug("v = " + _v.asString(16)); | ||
133 | MochiKit.Logging.logDebug("B = " + _B.asString(16)); | ||
134 | MochiKit.Logging.logDebug("u = " + _u.asString(16)); | ||
135 | MochiKit.Logging.logDebug("S = " + _S.asString(16)); | ||
136 | MochiKit.Logging.logDebug("K = " + _K); | ||
137 | MochiKit.Logging.logDebug("M1 = " + _M1); | ||
138 | MochiKit.Logging.logDebug("M2 = " + _M2); | ||
139 | // MochiKit.Logging.logDebug("someParameters.version: " + someParameters.version); | ||
140 | */ | ||
141 | return this.sendMessage('handshake', someParameters, 'CONNECT'); | ||
142 | }, | ||
143 | |||
144 | //------------------------------------------------------------------------- | ||
145 | |||
146 | 'message': function(someParameters) { | ||
147 | return this.sendMessage('message', someParameters, 'MESSAGE'); | ||
148 | }, | ||
149 | |||
150 | //------------------------------------------------------------------------- | ||
151 | |||
152 | 'logout': function(someParameters) { | ||
153 | //MochiKit.Logging.logDebug("=== Proxy.DWR.logout"); | ||
154 | return this.sendMessage('logout', someParameters, 'MESSAGE'); | ||
155 | }, | ||
156 | |||
157 | //========================================================================= | ||
158 | |||
159 | 'sendMessage': function(aFunctionName, someParameters, aRequestType) { | ||
160 | /* | ||
161 | vardeferredResult; | ||
162 | var proxy; | ||
163 | |||
164 | //MochiKit.Logging.logDebug(">>> Proxy.DWR.sendMessage - " + aFunctionName + " - " + aRequestType); | ||
165 | proxy = this; | ||
166 | |||
167 | deferredResult = new MochiKit.Async.Deferred(); | ||
168 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("x.1 Proxy.DWR.sendMessage - 1: " + res); return res;}); | ||
169 | deferredResult.addCallback(MochiKit.Base.method(proxy, 'payToll'), aRequestType); | ||
170 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("x.2 Proxy.DWR.sendMessage - 2: " + Clipperz.Base.serializeJSON(res)); return res;}); | ||
171 | deferredResult.addCallback(MochiKit.Base.method(proxy, 'sendRemoteMessage'), aFunctionName); | ||
172 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("x.3 Proxy.DWR.sendMessage - 3: " + res); return res;}); | ||
173 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("x.3 Proxy.DWR.sendMessage - 3: " + Clipperz.Base.serializeJSON(res)); return res;}); | ||
174 | deferredResult.callback(someParameters); | ||
175 | |||
176 | //MochiKit.Logging.logDebug("<<< Proxy.DWR.sendMessage"); | ||
177 | return deferredResult; | ||
178 | */ | ||
179 | |||
180 | // return this.sendRemoteMessage(aFunctionName, someParameters); | ||
181 | |||
182 | |||
183 | vardeferredResult; | ||
184 | var proxy; | ||
185 | |||
186 | proxy = this; | ||
187 | |||
188 | deferredResult = new MochiKit.Async.Deferred(); | ||
189 | deferredResult.addCallback(MochiKit.Base.method(proxy, 'sendRemoteMessage'), aFunctionName); | ||
190 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("x.3 Proxy.PHP.sendMessage - 3: " + res); return res;}); | ||
191 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("x.3 Proxy.PHP.sendMessage - 3.1: " + Clipperz.Base.serializeJSON(res)); return res;}); | ||
192 | |||
193 | deferredResult.callback(someParameters); | ||
194 | |||
195 | return deferredResult; | ||
196 | }, | ||
197 | |||
198 | //========================================================================= | ||
199 | |||
200 | 'sendRemoteMessage': function(aFunctionName, someParameters) { | ||
201 | /* | ||
202 | vardeferredResult; | ||
203 | |||
204 | //MochiKit.Logging.logDebug(">>> Proxy.DWR.sendRemoteMessage('" + aFunctionName + "', " + Clipperz.Base.serializeJSON(someParameters) + ") - " + this); | ||
205 | deferredResult = new MochiKit.Async.Deferred(); | ||
206 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Proxy.DWR.sendRemoteMessage - 1: " + res); return res;}); | ||
207 | // deferredResult.addCallback(MochiKit.Base.method(this, 'setTollCallback')); | ||
208 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Proxy.DWR.sendRemoteMessage - 2: " + res); return res;}); | ||
209 | |||
210 | com_clipperz_pm_Proxy[aFunctionName](Clipperz.Base.serializeJSON(someParameters), { | ||
211 | callback:MochiKit.Base.method(deferredResult, 'callback'), | ||
212 | errorHandler:MochiKit.Base.method(deferredResult, 'errback') | ||
213 | }); | ||
214 | //MochiKit.Logging.logDebug("<<< Proxy.PHP.sendRemoteMessage - result: " + deferredResult); | ||
215 | |||
216 | return deferredResult; | ||
217 | */ | ||
218 | |||
219 | vardeferredResult; | ||
220 | var parameters; | ||
221 | |||
222 | //MochiKit.Logging.logDebug(">>> Proxy.PHP.sendRemoteMessage('" + aFunctionName + "', " + Clipperz.Base.serializeJSON(someParameters) + ") - " + this); | ||
223 | parameters = {}; | ||
224 | parameters['method'] = aFunctionName; | ||
225 | // parameters['version'] = someParameters['version']; | ||
226 | // parameters['message'] = someParameters['message']; | ||
227 | parameters['parameters'] = Clipperz.Base.serializeJSON(someParameters); | ||
228 | //MochiKit.Logging.logDebug("--- Proxy.PHP.sendRemoteMessage('" + Clipperz.Base.serializeJSON(parameters) + ") - " + this); | ||
229 | deferredResult = new MochiKit.Async.Deferred(); | ||
230 | deferredResult.addCallback(MochiKit.Async.doXHR, "./php/index.php", { | ||
231 | method:'POST', | ||
232 | sendContent:MochiKit.Base.queryString(parameters), | ||
233 | headers:{"Content-Type":"application/x-www-form-urlencoded"} | ||
234 | }); | ||
235 | //deferredResult.addCallback(function(res) {MochiKit.Logging.logDebug("Proxy.PHP.response - 2: " + res.responseText); return res;}); | ||
236 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("Proxy.PHP.response - ERROR: " + res); return res;}); | ||
237 | deferredResult.addCallback(MochiKit.Async.evalJSONRequest); | ||
238 | deferredResult.addCallback(function (someValues) { | ||
239 | if (someValues['result'] == 'EXCEPTION') { | ||
240 | throw someValues['message']; | ||
241 | } | ||
242 | return someValues; | ||
243 | }) | ||
244 | deferredResult.callback(); | ||
245 | |||
246 | return deferredResult; | ||
247 | }, | ||
248 | |||
249 | //========================================================================= | ||
250 | |||
251 | 'isReadOnly': function() { | ||
252 | return false; | ||
253 | }, | ||
254 | |||
255 | //========================================================================= | ||
256 | __syntaxFix__: "syntax fix" | ||
257 | |||
258 | }); | ||
259 | |||
260 | //============================================================================= | ||
261 | |||
262 | //Clipperz.PM.Proxy.defaultProxy = new Clipperz.PM.Proxy.PHP("Proxy.PHP - async test"); | ||
diff --git a/frontend/gamma/html/index_template.html b/frontend/gamma/html/index_template.html index 8cf838c..bedb243 100644 --- a/frontend/gamma/html/index_template.html +++ b/frontend/gamma/html/index_template.html | |||
@@ -1,62 +1,67 @@ | |||
1 | <html> | 1 | <html> |
2 | <head> | 2 | <head> |
3 | <title>@page.title@</title> | 3 | <title>@page.title@</title> |
4 | <meta http-equiv="content-type" content="text/html; charset=utf-8" /> | 4 | <meta http-equiv="content-type" content="text/html; charset=utf-8" /> |
5 | <!-- | 5 | <!-- |
6 | @copyright@ | 6 | @copyright@ |
7 | --> | 7 | --> |
8 | 8 | ||
9 | @css@ | 9 | @css@ |
10 | 10 | ||
11 | <link rel="shortcut icon" href="./clipperz.ico" /> | 11 | <link rel="shortcut icon" href="./clipperz.ico" /> |
12 | 12 | ||
13 | <meta name="description" content="Login to your web accounts with just one click. Never type a password again! Use multiple complex passwords and forget them. A password manager that enhances your online security." /> | 13 | <meta name="description" content="Login to your web accounts with just one click. Never type a password again! Use multiple complex passwords and forget them. A password manager that enhances your online security." /> |
14 | <meta name="keywords" content="password manager,gestor de contraseñas,gerenciador de senhas,Kennwortmanager,passwords,security,privacy,cryptography" /> | 14 | <meta name="keywords" content="password manager,gestor de contraseñas,gerenciador de senhas,Kennwortmanager,passwords,security,privacy,cryptography" /> |
15 | <script> | 15 | <script> |
16 | Clipperz_IEisBroken = false; | 16 | Clipperz_IEisBroken = false; |
17 | Clipperz_normalizedNewLine = '\n'; | 17 | Clipperz_normalizedNewLine = '\n'; |
18 | Clipperz_dumpUrl = "/dump/"; | 18 | Clipperz_dumpUrl = "/dump/"; |
19 | </script> | 19 | </script> |
20 | 20 | ||
21 | <!--[if IE]><script> | 21 | <!--[if IE]><script> |
22 | Clipperz_IEisBroken = true; | 22 | Clipperz_IEisBroken = true; |
23 | Clipperz_normalizedNewLine = '\x0d\x0a'; | 23 | Clipperz_normalizedNewLine = '\x0d\x0a'; |
24 | </script><![endif]--> | 24 | </script><![endif]--> |
25 | 25 | ||
26 | @js_DEBUG@ | 26 | @js_DEBUG@ |
27 | 27 | ||
28 | </head> | 28 | </head> |
29 | <body> | 29 | <body> |
30 | <div id="mainDiv"> | 30 | <div id="mainDiv"> |
31 | <div id="loading"> | 31 | <div id="loading"> |
32 | <a href="http://www.clipperz.com" target="_blank"><div id="logo"></div></a> | 32 | <a href="http://www.clipperz.com" target="_blank"><div id="logo"></div></a> |
33 | <h5 class="clipperzPayoff">keep it to yourself!</h5> | 33 | <h5 class="clipperzPayoff">keep it to yourself!</h5> |
34 | <h2>loading ...</h2> | 34 | <h2>loading ...</h2> |
35 | </div> | 35 | </div> |
36 | 36 | ||
37 | @js_INSTALL@ | 37 | @js_INSTALL@ |
38 | 38 | ||
39 | </div> | 39 | </div> |
40 | <div id="applicationVersionType" class="@application.version.type@"></div> | 40 | <div id="applicationVersionType" class="@application.version.type@"></div> |
41 | 41 | ||
42 | <script> | ||
43 | Clipperz.PM.Proxy.defaultProxy = new Clipperz.PM.Proxy.JSON({'url':'@request.path@', 'shouldPayTolls':@should.pay.toll@}); | ||
44 | /*offline_data_placeholder*/ | ||
45 | </script> | ||
46 | |||
42 | <!-- --> | 47 | <!-- --> |
43 | <div id="javaScriptAlert"> | 48 | <div id="javaScriptAlert"> |
44 | <div class="mask"></div> | 49 | <div class="mask"></div> |
45 | <div class="message"> | 50 | <div class="message"> |
46 | <div class="header"></div> | 51 | <div class="header"></div> |
47 | <div class="body"> | 52 | <div class="body"> |
48 | <div class="alertLogo"></div> | 53 | <div class="alertLogo"></div> |
49 | <div class="alert"> | 54 | <div class="alert"> |
50 | <h1>Attention!</h1> | 55 | <h1>Attention!</h1> |
51 | <p>If you can read this message, the chances are that your browser does not properly support JavaScript? or you have disabled this functionality yourself.</p> | 56 | <p>If you can read this message, the chances are that your browser does not properly support JavaScript? or you have disabled this functionality yourself.</p> |
52 | <h3>Javascript is required to access Clipperz.</h3> | 57 | <h3>Javascript is required to access Clipperz.</h3> |
53 | <h5>Please enable scripting or upgrade your browser.</h5> | 58 | <h5>Please enable scripting or upgrade your browser.</h5> |
54 | </div> | 59 | </div> |
55 | </div> | 60 | </div> |
56 | <div class="footer"></div> | 61 | <div class="footer"></div> |
57 | </div> | 62 | </div> |
58 | </div> | 63 | </div> |
59 | <!-- --> | 64 | <!-- --> |
60 | 65 | ||
61 | </body> | 66 | </body> |
62 | </html> | 67 | </html> |
diff --git a/frontend/gamma/js/Clipperz/Async.js b/frontend/gamma/js/Clipperz/Async.js index 7c9d783..97d8ecf 100644 --- a/frontend/gamma/js/Clipperz/Async.js +++ b/frontend/gamma/js/Clipperz/Async.js | |||
@@ -1,704 +1,711 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2011 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz Community Edition. |
6 | Clipperz Community Edition is an online password manager. | 6 | Clipperz Community Edition is an online password manager. |
7 | For further information about its features and functionalities please | 7 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 8 | refer to http://www.clipperz.com. |
9 | 9 | ||
10 | * Clipperz Community Edition is free software: you can redistribute | 10 | * Clipperz Community Edition is free software: you can redistribute |
11 | it and/or modify it under the terms of the GNU Affero General Public | 11 | it and/or modify it under the terms of the GNU Affero General Public |
12 | License as published by the Free Software Foundation, either version | 12 | License as published by the Free Software Foundation, either version |
13 | 3 of the License, or (at your option) any later version. | 13 | 3 of the License, or (at your option) any later version. |
14 | 14 | ||
15 | * Clipperz Community Edition is distributed in the hope that it will | 15 | * Clipperz Community Edition is distributed in the hope that it will |
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 16 | be useful, but WITHOUT ANY WARRANTY; without even the implied |
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. | 18 | See the GNU Affero General Public License for more details. |
19 | 19 | ||
20 | * You should have received a copy of the GNU Affero General Public | 20 | * You should have received a copy of the GNU Affero General Public |
21 | License along with Clipperz Community Edition. If not, see | 21 | License along with Clipperz Community Edition. If not, see |
22 | <http://www.gnu.org/licenses/>. | 22 | <http://www.gnu.org/licenses/>. |
23 | 23 | ||
24 | */ | 24 | */ |
25 | 25 | ||
26 | //Clipperz.Async = MochiKit.Async; | 26 | //Clipperz.Async = MochiKit.Async; |
27 | 27 | ||
28 | 28 | ||
29 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 29 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
30 | if (typeof(Clipperz.Async) == 'undefined') { Clipperz.Async = {}; } | 30 | if (typeof(Clipperz.Async) == 'undefined') { Clipperz.Async = {}; } |
31 | 31 | ||
32 | Clipperz.Async.VERSION = "0.1"; | 32 | Clipperz.Async.VERSION = "0.1"; |
33 | Clipperz.Async.NAME = "Clipperz.Async"; | 33 | Clipperz.Async.NAME = "Clipperz.Async"; |
34 | 34 | ||
35 | Clipperz.Async.Deferred = function(aName, args) { | 35 | Clipperz.Async.Deferred = function(aName, args) { |
36 | args = args || {}; | 36 | args = args || {}; |
37 | 37 | ||
38 | Clipperz.Async.Deferred.superclass.constructor.call(this, args.canceller); | 38 | Clipperz.Async.Deferred.superclass.constructor.call(this, args.canceller); |
39 | 39 | ||
40 | this._args = args; | 40 | this._args = args; |
41 | this._name = aName || "Anonymous deferred"; | 41 | this._name = aName || "Anonymous deferred"; |
42 | this._count = 0; | 42 | this._count = 0; |
43 | this._shouldTrace = ((CLIPPERZ_DEFERRED_TRACING_ENABLED === true) || (args.trace === true)); | 43 | this._shouldTrace = ((CLIPPERZ_DEFERRED_TRACING_ENABLED === true) || (args.trace === true)); |
44 | this._vars = null; | 44 | this._vars = null; |
45 | 45 | ||
46 | return this; | 46 | return this; |
47 | } | 47 | } |
48 | 48 | ||
49 | //============================================================================= | 49 | //============================================================================= |
50 | 50 | ||
51 | Clipperz.Base.extend(Clipperz.Async.Deferred, MochiKit.Async.Deferred, { | 51 | Clipperz.Base.extend(Clipperz.Async.Deferred, MochiKit.Async.Deferred, { |
52 | 52 | ||
53 | 'name': function () { | 53 | 'name': function () { |
54 | return this._name; | 54 | return this._name; |
55 | }, | 55 | }, |
56 | 56 | ||
57 | 'args': function () { | 57 | 'args': function () { |
58 | return this._args; | 58 | return this._args; |
59 | }, | 59 | }, |
60 | 60 | ||
61 | //----------------------------------------------------------------------------- | 61 | //----------------------------------------------------------------------------- |
62 | 62 | ||
63 | 'callback': function (aValue) { | 63 | 'callback': function (aValue) { |
64 | if (this._shouldTrace) { | 64 | if (this._shouldTrace) { |
65 | Clipperz.log("CALLBACK " + this._name, aValue); | 65 | //Clipperz.log("CALLBACK " + this._name, aValue); |
66 | console.log("CALLBACK " + this._name, aValue); | ||
66 | } | 67 | } |
67 | 68 | ||
68 | if (this.chained == false) { | 69 | if (this.chained == false) { |
69 | var message; | 70 | var message; |
70 | 71 | ||
71 | message = "ERROR [" + this._name + "]"; | 72 | message = "ERROR [" + this._name + "]"; |
72 | this.addErrback(function(aResult) { | 73 | this.addErrback(function(aResult) { |
73 | if (! (aResult instanceof MochiKit.Async.CancelledError)) { | 74 | if (! (aResult instanceof MochiKit.Async.CancelledError)) { |
74 | Clipperz.log(message, aResult); | 75 | Clipperz.log(message, aResult); |
75 | } | 76 | } |
76 | return aResult; | 77 | return aResult; |
77 | }); | 78 | }); |
78 | 79 | ||
79 | if (this._shouldTrace) { | 80 | if (this._shouldTrace) { |
80 | var resultMessage; | 81 | var resultMessage; |
81 | 82 | ||
82 | resultMessage = "RESULT " + this._name + " <=="; | 83 | resultMessage = "RESULT " + this._name + " <=="; |
83 | // this.addCallback(function(aResult) { | 84 | // this.addCallback(function(aResult) { |
84 | Clipperz.Async.Deferred.superclass.addCallback.call(this, function(aResult) { | 85 | Clipperz.Async.Deferred.superclass.addCallback.call(this, function(aResult) { |
85 | Clipperz.log(resultMessage, aResult); | 86 | //Clipperz.log(resultMessage, aResult); |
87 | console.log(resultMessage, aResult); | ||
86 | 88 | ||
87 | return aResult; | 89 | return aResult; |
88 | }); | 90 | }); |
89 | } | 91 | } |
90 | } | 92 | } |
91 | 93 | ||
92 | if (CLIPPERZ_DEFERRED_CALL_LOGGING_ENABLED === true) { | 94 | if (CLIPPERZ_DEFERRED_CALL_LOGGING_ENABLED === true) { |
93 | Clipperz.log("callback " + this._name, this); | 95 | Clipperz.log("callback " + this._name, this); |
94 | } | 96 | } |
95 | 97 | ||
96 | return Clipperz.Async.Deferred.superclass.callback.apply(this, arguments); | 98 | return Clipperz.Async.Deferred.superclass.callback.apply(this, arguments); |
97 | }, | 99 | }, |
98 | 100 | ||
99 | //----------------------------------------------------------------------------- | 101 | //----------------------------------------------------------------------------- |
100 | 102 | ||
101 | 'addCallback': function () { | 103 | 'addCallback': function () { |
102 | var message; | 104 | var message; |
103 | 105 | ||
104 | if (this._shouldTrace) { | 106 | if (this._shouldTrace) { |
105 | this._count ++; | 107 | this._count ++; |
106 | message = "[" + this._count + "] " + this._name + " "; | 108 | message = "[" + this._count + "] " + this._name + " "; |
107 | // this.addBoth(function(aResult) {Clipperz.log(message + "-->", aResult); return aResult;}); | 109 | // this.addBoth(function(aResult) {Clipperz.log(message + "-->", aResult); return aResult;}); |
108 | this.addCallbacks( | 110 | this.addCallbacks( |
109 | function(aResult) {Clipperz.log("-OK- " + message + "-->"/*, aResult*/); return aResult;}, | 111 | //function(aResult) {Clipperz.log("-OK- " + message + "-->"/*, aResult*/); return aResult;}, |
110 | function(aResult) {Clipperz.log("FAIL " + message + "-->"/*, aResult*/); return aResult;} | 112 | function(aResult) {console.log("-OK- " + message + "-->"/*, aResult*/); return aResult;}, |
113 | //function(aResult) {Clipperz.log("FAIL " + message + "-->"/*, aResult*/); return aResult;} | ||
114 | function(aResult) {console.log("FAIL " + message + "-->"/*, aResult*/); return aResult;} | ||
111 | ); | 115 | ); |
112 | } | 116 | } |
113 | 117 | ||
114 | Clipperz.Async.Deferred.superclass.addCallback.apply(this, arguments); | 118 | Clipperz.Async.Deferred.superclass.addCallback.apply(this, arguments); |
115 | 119 | ||
116 | if (this._shouldTrace) { | 120 | if (this._shouldTrace) { |
117 | // this.addBoth(function(aResult) {Clipperz.log(message + "<--", aResult); return aResult;}); | 121 | // this.addBoth(function(aResult) {Clipperz.log(message + "<--", aResult); return aResult;}); |
118 | this.addCallbacks( | 122 | this.addCallbacks( |
119 | function(aResult) {Clipperz.log("-OK- " + message + "<--", aResult); return aResult;}, | 123 | //function(aResult) {Clipperz.log("-OK- " + message + "<--", aResult); return aResult;}, |
120 | function(aResult) {Clipperz.log("FAIL " + message + "<--", aResult); return aResult;} | 124 | function(aResult) {console.log("-OK- " + message + "<--", aResult); return aResult;}, |
125 | //function(aResult) {Clipperz.log("FAIL " + message + "<--", aResult); return aResult;} | ||
126 | function(aResult) {console.log("FAIL " + message + "<--", aResult); return aResult;} | ||
121 | ); | 127 | ); |
122 | } | 128 | } |
123 | }, | 129 | }, |
124 | 130 | ||
125 | //============================================================================= | 131 | //============================================================================= |
126 | 132 | ||
127 | 'addCallbackPass': function() { | 133 | 'addCallbackPass': function() { |
128 | var passFunction; | 134 | var passFunction; |
129 | 135 | ||
130 | passFunction = MochiKit.Base.partial.apply(null, arguments); | 136 | passFunction = MochiKit.Base.partial.apply(null, arguments); |
131 | 137 | ||
132 | this.addCallback(function() { | 138 | this.addCallback(function() { |
133 | var result; | 139 | var result; |
134 | 140 | ||
135 | result = arguments[arguments.length -1]; | 141 | result = arguments[arguments.length -1]; |
136 | passFunction(); | 142 | passFunction(); |
137 | 143 | ||
138 | return result; | 144 | return result; |
139 | }); | 145 | }); |
140 | }, | 146 | }, |
141 | 147 | ||
142 | //----------------------------------------------------------------------------- | 148 | //----------------------------------------------------------------------------- |
143 | 149 | ||
144 | 'addErrbackPass': function() { | 150 | 'addErrbackPass': function() { |
145 | var passFunction; | 151 | var passFunction; |
146 | 152 | ||
147 | passFunction = MochiKit.Base.partial.apply(null, arguments); | 153 | passFunction = MochiKit.Base.partial.apply(null, arguments); |
148 | 154 | ||
149 | this.addErrback(function() { | 155 | this.addErrback(function() { |
150 | var result; | 156 | var result; |
151 | 157 | ||
152 | result = arguments[arguments.length -1]; | 158 | result = arguments[arguments.length -1]; |
153 | passFunction(); | 159 | passFunction(); |
154 | 160 | ||
155 | return result; | 161 | return result; |
156 | }); | 162 | }); |
157 | }, | 163 | }, |
158 | 164 | ||
159 | //----------------------------------------------------------------------------- | 165 | //----------------------------------------------------------------------------- |
160 | 166 | ||
161 | 'addBothPass': function() { | 167 | 'addBothPass': function() { |
162 | var passFunction; | 168 | var passFunction; |
163 | 169 | ||
164 | passFunction = MochiKit.Base.partial.apply(null, arguments); | 170 | passFunction = MochiKit.Base.partial.apply(null, arguments); |
165 | 171 | ||
166 | this.addBoth(function() { | 172 | this.addBoth(function() { |
167 | var result; | 173 | var result; |
168 | 174 | ||
169 | result = arguments[arguments.length -1]; | 175 | result = arguments[arguments.length -1]; |
170 | passFunction(); | 176 | passFunction(); |
171 | 177 | ||
172 | return result; | 178 | return result; |
173 | }); | 179 | }); |
174 | }, | 180 | }, |
175 | 181 | ||
176 | //----------------------------------------------------------------------------- | 182 | //----------------------------------------------------------------------------- |
177 | 183 | ||
178 | 'addIf': function (aThenBlock, anElseBlock) { | 184 | 'addIf': function (aThenBlock, anElseBlock) { |
179 | this.addCallback(MochiKit.Base.bind(function (aValue) { | 185 | this.addCallback(MochiKit.Base.bind(function (aValue) { |
180 | var deferredResult; | 186 | var deferredResult; |
181 | 187 | ||
182 | if (!MochiKit.Base.isUndefinedOrNull(aValue) && aValue) { | 188 | if (!MochiKit.Base.isUndefinedOrNull(aValue) && aValue) { |
183 | deferredResult = Clipperz.Async.callbacks(this._name + " <then>", aThenBlock, null, aValue); | 189 | deferredResult = Clipperz.Async.callbacks(this._name + " <then>", aThenBlock, null, aValue); |
184 | } else { | 190 | } else { |
185 | deferredResult = Clipperz.Async.callbacks(this._name + " <else>", anElseBlock, null, aValue); | 191 | deferredResult = Clipperz.Async.callbacks(this._name + " <else>", anElseBlock, null, aValue); |
186 | } | 192 | } |
187 | 193 | ||
188 | return deferredResult; | 194 | return deferredResult; |
189 | })) | 195 | })) |
190 | }, | 196 | }, |
191 | 197 | ||
192 | //----------------------------------------------------------------------------- | 198 | //----------------------------------------------------------------------------- |
193 | 199 | ||
194 | 'addMethod': function () { | 200 | 'addMethod': function () { |
195 | this.addCallback(MochiKit.Base.method.apply(this, arguments)); | 201 | this.addCallback(MochiKit.Base.method.apply(this, arguments)); |
196 | }, | 202 | }, |
197 | 203 | ||
198 | //----------------------------------------------------------------------------- | 204 | //----------------------------------------------------------------------------- |
199 | 205 | ||
200 | 'addMethodcaller': function () { | 206 | 'addMethodcaller': function () { |
201 | this.addCallback(MochiKit.Base.methodcaller.apply(this, arguments)); | 207 | this.addCallback(MochiKit.Base.methodcaller.apply(this, arguments)); |
202 | }, | 208 | }, |
203 | 209 | ||
204 | //============================================================================= | 210 | //============================================================================= |
205 | 211 | ||
206 | 'addLog': function (aLog) { | 212 | 'addLog': function (aLog) { |
207 | if (CLIPPERZ_DEFERRED_LOGGING_ENABLED) { | 213 | if (CLIPPERZ_DEFERRED_LOGGING_ENABLED) { |
208 | this.addBothPass(function(res) {Clipperz.log(aLog + " ", res);}); | 214 | this.addBothPass(function(res) {Clipperz.log(aLog + " ", res);}); |
209 | // this.addBothPass(function(res) {console.log(aLog + " ", res);}); | 215 | // this.addBothPass(function(res) {console.log(aLog + " ", res);}); |
210 | } | 216 | } |
211 | }, | 217 | }, |
212 | 218 | ||
213 | //============================================================================= | 219 | //============================================================================= |
214 | 220 | ||
215 | 'acquireLock': function (aLock) { | 221 | 'acquireLock': function (aLock) { |
216 | // this.addCallback(function (aResult) { | 222 | // this.addCallback(function (aResult) { |
217 | // return Clipperz.Async.callbacks("Clipperz.Async.acquireLock", [ | 223 | // return Clipperz.Async.callbacks("Clipperz.Async.acquireLock", [ |
218 | // MochiKit.Base.method(aLock, 'acquire'), | 224 | // MochiKit.Base.method(aLock, 'acquire'), |
219 | // MochiKit.Base.partial(MochiKit.Async.succeed, aResult) | 225 | // MochiKit.Base.partial(MochiKit.Async.succeed, aResult) |
220 | // ], {trace:false}); | 226 | // ], {trace:false}); |
221 | // }); | 227 | // }); |
222 | 228 | ||
223 | this.addCallback(MochiKit.Base.method(aLock, 'acquire')); | 229 | this.addCallback(MochiKit.Base.method(aLock, 'acquire')); |
224 | }, | 230 | }, |
225 | 231 | ||
226 | 'releaseLock': function (aLock) { | 232 | 'releaseLock': function (aLock) { |
227 | // this.addCallback(function (aResult) { | 233 | // this.addCallback(function (aResult) { |
228 | // return Clipperz.Async.callbacks("Clipperz.Async.release <ok>", [ | 234 | // return Clipperz.Async.callbacks("Clipperz.Async.release <ok>", [ |
229 | // MochiKit.Base.method(aLock, 'release'), | 235 | // MochiKit.Base.method(aLock, 'release'), |
230 | // MochiKit.Base.partial(MochiKit.Async.succeed, aResult) | 236 | // MochiKit.Base.partial(MochiKit.Async.succeed, aResult) |
231 | // ], {trace:false}); | 237 | // ], {trace:false}); |
232 | // }); | 238 | // }); |
233 | // this.addErrback(function (aResult) { | 239 | // this.addErrback(function (aResult) { |
234 | ///console.log("releaseLock.addErrback:", aResult); | 240 | ///console.log("releaseLock.addErrback:", aResult); |
235 | // return Clipperz.Async.callbacks("Clipperz.Async.release <fail>", [ | 241 | // return Clipperz.Async.callbacks("Clipperz.Async.release <fail>", [ |
236 | // MochiKit.Base.method(aLock, 'release'), | 242 | // MochiKit.Base.method(aLock, 'release'), |
237 | // MochiKit.Base.partial(MochiKit.Async.fail, aResult) | 243 | // MochiKit.Base.partial(MochiKit.Async.fail, aResult) |
238 | // ], {trace:false}); | 244 | // ], {trace:false}); |
239 | // }); | 245 | // }); |
240 | 246 | ||
241 | // this.addBothPass(MochiKit.Base.method(aLock, 'release')); | 247 | // this.addBothPass(MochiKit.Base.method(aLock, 'release')); |
242 | this.addCallbackPass(MochiKit.Base.method(aLock, 'release')); | 248 | this.addCallbackPass(MochiKit.Base.method(aLock, 'release')); |
243 | this.addErrback(function (anError) { | 249 | this.addErrback(function (anError) { |
244 | aLock.release(); | 250 | aLock.release(); |
245 | 251 | ||
246 | return anError; | 252 | return anError; |
247 | }); | 253 | }); |
248 | }, | 254 | }, |
249 | 255 | ||
250 | //============================================================================= | 256 | //============================================================================= |
251 | 257 | ||
252 | 'collectResults': function (someRequests) { | 258 | 'collectResults': function (someRequests) { |
253 | this.addCallback(Clipperz.Async.collectResults(this._name + " <collect results>", someRequests, this._args)); | 259 | this.addCallback(Clipperz.Async.collectResults(this._name + " <collect results>", someRequests, this._args)); |
254 | }, | 260 | }, |
255 | 261 | ||
256 | 'addCallbackList': function (aRequestList) { | 262 | 'addCallbackList': function (aRequestList) { |
257 | this.addCallback(Clipperz.Async.callbacks, this._name + " <callback list>", aRequestList, this._args); | 263 | this.addCallback(Clipperz.Async.callbacks, this._name + " <callback list>", aRequestList, this._args); |
258 | }, | 264 | }, |
259 | 265 | ||
260 | //============================================================================= | 266 | //============================================================================= |
261 | 267 | ||
262 | 'vars': function () { | 268 | 'vars': function () { |
263 | if (this._vars == null) { | 269 | if (this._vars == null) { |
264 | this._vars = {} | 270 | this._vars = {} |
265 | } | 271 | } |
266 | 272 | ||
267 | return this._vars; | 273 | return this._vars; |
268 | }, | 274 | }, |
269 | 275 | ||
270 | 'setValue': function (aKey) { | 276 | 'setValue': function (aKey) { |
271 | this.addCallback(MochiKit.Base.bind(function (aValue) { | 277 | this.addCallback(MochiKit.Base.bind(function (aValue) { |
272 | this.vars()[aKey] = aValue; | 278 | this.vars()[aKey] = aValue; |
273 | return aValue; | 279 | return aValue; |
274 | }, this)); | 280 | }, this)); |
275 | }, | 281 | }, |
276 | 282 | ||
277 | 'getValue': function (aKey) { | 283 | 'getValue': function (aKey) { |
278 | this.addCallback(MochiKit.Base.bind(function () { | 284 | this.addCallback(MochiKit.Base.bind(function () { |
279 | return this.vars()[aKey]; | 285 | return this.vars()[aKey]; |
280 | }, this)); | 286 | }, this)); |
281 | }, | 287 | }, |
282 | 288 | ||
283 | //============================================================================= | 289 | //============================================================================= |
284 | 290 | ||
285 | __syntaxFix__: "syntax fix" | 291 | __syntaxFix__: "syntax fix" |
286 | }); | 292 | }); |
287 | 293 | ||
288 | //############################################################################# | 294 | //############################################################################# |
289 | 295 | ||
290 | Clipperz.Async.DeferredSynchronizer = function(aName, someMethods) { | 296 | Clipperz.Async.DeferredSynchronizer = function(aName, someMethods) { |
291 | this._name = aName || "Anonymous deferred Synchronizer"; | 297 | this._name = aName || "Anonymous deferred Synchronizer"; |
292 | this._methods = someMethods; | 298 | this._methods = someMethods; |
293 | 299 | ||
294 | this._numberOfMethodsDone= 0; | 300 | this._numberOfMethodsDone= 0; |
295 | this._methodResults = []; | 301 | this._methodResults = []; |
296 | 302 | ||
297 | this._result = new Clipperz.Async.Deferred("Clipperz.Async.DeferredSynchronizer # " + this.name(), {trace:false}); | 303 | this._result = new Clipperz.Async.Deferred("Clipperz.Async.DeferredSynchronizer # " + this.name(), {trace:false}); |
298 | this._result.addMethod(this, 'methodResults'); | 304 | this._result.addMethod(this, 'methodResults'); |
299 | this._result.addCallback(function(someResults) { | 305 | this._result.addCallback(function(someResults) { |
300 | varcancels; | 306 | varcancels; |
301 | var errors; | 307 | var errors; |
302 | var result; | 308 | var result; |
303 | 309 | ||
304 | cancels = MochiKit.Base.filter(function(aResult) { return (aResult instanceof MochiKit.Async.CancelledError)}, someResults); | 310 | cancels = MochiKit.Base.filter(function(aResult) { return (aResult instanceof MochiKit.Async.CancelledError)}, someResults); |
305 | 311 | ||
306 | if (cancels.length == 0) { | 312 | if (cancels.length == 0) { |
307 | errors = MochiKit.Base.filter(function(aResult) { return (aResult instanceof Error)}, someResults); | 313 | errors = MochiKit.Base.filter(function(aResult) { return (aResult instanceof Error)}, someResults); |
308 | 314 | ||
309 | if (errors.length == 0) { | 315 | if (errors.length == 0) { |
310 | // result = MochiKit.Async.succeed(someResults); | 316 | // result = MochiKit.Async.succeed(someResults); |
311 | result = someResults; | 317 | result = someResults; |
312 | } else { | 318 | } else { |
313 | result = MochiKit.Async.fail(someResults); | 319 | result = MochiKit.Async.fail(someResults); |
314 | } | 320 | } |
315 | } else { | 321 | } else { |
316 | result = MochiKit.Async.fail(cancels[0]); | 322 | result = MochiKit.Async.fail(cancels[0]); |
317 | } | 323 | } |
318 | 324 | ||
319 | return result; | 325 | return result; |
320 | }/*, this._methodResults */); | 326 | }/*, this._methodResults */); |
321 | 327 | ||
322 | return this; | 328 | return this; |
323 | } | 329 | } |
324 | 330 | ||
325 | MochiKit.Base.update(Clipperz.Async.DeferredSynchronizer.prototype, { | 331 | MochiKit.Base.update(Clipperz.Async.DeferredSynchronizer.prototype, { |
326 | 332 | ||
327 | //----------------------------------------------------------------------------- | 333 | //----------------------------------------------------------------------------- |
328 | 334 | ||
329 | 'name': function() { | 335 | 'name': function() { |
330 | return this._name; | 336 | return this._name; |
331 | }, | 337 | }, |
332 | 338 | ||
333 | //----------------------------------------------------------------------------- | 339 | //----------------------------------------------------------------------------- |
334 | 340 | ||
335 | 'methods': function() { | 341 | 'methods': function() { |
336 | return this._methods; | 342 | return this._methods; |
337 | }, | 343 | }, |
338 | 344 | ||
339 | 'methodResults': function() { | 345 | 'methodResults': function() { |
340 | return this._methodResults; | 346 | return this._methodResults; |
341 | }, | 347 | }, |
342 | 348 | ||
343 | //----------------------------------------------------------------------------- | 349 | //----------------------------------------------------------------------------- |
344 | 350 | ||
345 | 'result': function() { | 351 | 'result': function() { |
346 | return this._result; | 352 | return this._result; |
347 | }, | 353 | }, |
348 | 354 | ||
349 | //----------------------------------------------------------------------------- | 355 | //----------------------------------------------------------------------------- |
350 | 356 | ||
351 | 'numberOfMethodsDone':function() { | 357 | 'numberOfMethodsDone':function() { |
352 | return this._numberOfMethodsDone; | 358 | return this._numberOfMethodsDone; |
353 | }, | 359 | }, |
354 | 360 | ||
355 | 'incrementNumberOfMethodsDone': function() { | 361 | 'incrementNumberOfMethodsDone': function() { |
356 | this._numberOfMethodsDone ++; | 362 | this._numberOfMethodsDone ++; |
357 | }, | 363 | }, |
358 | 364 | ||
359 | //----------------------------------------------------------------------------- | 365 | //----------------------------------------------------------------------------- |
360 | 366 | ||
361 | 'run': function(args, aValue) { | 367 | 'run': function(args, aValue) { |
362 | var deferredResults; | 368 | var deferredResults; |
363 | var i, c; | 369 | var i, c; |
364 | 370 | ||
365 | deferredResults = []; | 371 | deferredResults = []; |
366 | args = args || {}; | 372 | args = args || {}; |
367 | 373 | ||
368 | c = this.methods().length; | 374 | c = this.methods().length; |
369 | for (i=0; i<c; i++) { | 375 | for (i=0; i<c; i++) { |
370 | var deferredResult; | 376 | var deferredResult; |
371 | varmethodCalls; | 377 | varmethodCalls; |
372 | var ii, cc; | 378 | var ii, cc; |
373 | 379 | ||
374 | //console.log("TYPEOF", typeof(this.methods()[i])); | 380 | //console.log("TYPEOF", typeof(this.methods()[i])); |
375 | if (typeof(this.methods()[i]) == 'function') { | 381 | if (typeof(this.methods()[i]) == 'function') { |
376 | methodCalls = [ this.methods()[i] ]; | 382 | methodCalls = [ this.methods()[i] ]; |
377 | } else { | 383 | } else { |
378 | methodCalls = this.methods()[i]; | 384 | methodCalls = this.methods()[i]; |
379 | } | 385 | } |
380 | 386 | ||
381 | cc = methodCalls.length; | 387 | cc = methodCalls.length; |
382 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.DeferredSynchronizer.run => " + this.name() + "[" + i + "]", args); | 388 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.DeferredSynchronizer.run => " + this.name() + "[" + i + "]", args); |
383 | for (ii=0; ii<cc; ii++) { | 389 | for (ii=0; ii<cc; ii++) { |
384 | deferredResult.addCallback(methodCalls[ii]); | 390 | deferredResult.addCallback(methodCalls[ii]); |
385 | } | 391 | } |
386 | deferredResult.addBoth(MochiKit.Base.method(this, 'handleMethodCallDone', i)); | 392 | deferredResult.addBoth(MochiKit.Base.method(this, 'handleMethodCallDone', i)); |
387 | 393 | ||
388 | deferredResults.push(deferredResult); | 394 | deferredResults.push(deferredResult); |
389 | } | 395 | } |
390 | 396 | ||
391 | for (i=0; i<c; i++) { | 397 | for (i=0; i<c; i++) { |
392 | deferredResults[i].callback(aValue); | 398 | deferredResults[i].callback(aValue); |
393 | } | 399 | } |
394 | 400 | ||
395 | return this.result(); | 401 | return this.result(); |
396 | }, | 402 | }, |
397 | 403 | ||
398 | //----------------------------------------------------------------------------- | 404 | //----------------------------------------------------------------------------- |
399 | 405 | ||
400 | 'handleMethodCallDone': function(anIndexValue, aResult) { | 406 | 'handleMethodCallDone': function(anIndexValue, aResult) { |
401 | this.incrementNumberOfMethodsDone(); | 407 | this.incrementNumberOfMethodsDone(); |
402 | this.methodResults()[anIndexValue] = aResult; | 408 | this.methodResults()[anIndexValue] = aResult; |
403 | 409 | ||
404 | if (this.numberOfMethodsDone() < this.methods().length) { | 410 | if (this.numberOfMethodsDone() < this.methods().length) { |
405 | //nothing to do here other than possibly log something | 411 | //nothing to do here other than possibly log something |
406 | } else if (this.numberOfMethodsDone() == this.methods().length) { | 412 | } else if (this.numberOfMethodsDone() == this.methods().length) { |
407 | this.result().callback(); | 413 | this.result().callback(); |
408 | } else if (this.numberOfMethodsDone() > this.methods().length) { | 414 | } else if (this.numberOfMethodsDone() > this.methods().length) { |
415 | alert("Clipperz.Async.Deferred.handleMethodCallDone -> WTF!"); | ||
409 | //WTF!!! :( | 416 | //WTF!!! :( |
410 | } | 417 | } |
411 | 418 | ||
412 | }, | 419 | }, |
413 | 420 | ||
414 | //----------------------------------------------------------------------------- | 421 | //----------------------------------------------------------------------------- |
415 | 422 | ||
416 | __syntaxFix__: "syntax fix" | 423 | __syntaxFix__: "syntax fix" |
417 | }); | 424 | }); |
418 | 425 | ||
419 | //############################################################################# | 426 | //############################################################################# |
420 | 427 | ||
421 | MochiKit.Base.update(Clipperz.Async, { | 428 | MochiKit.Base.update(Clipperz.Async, { |
422 | 429 | ||
423 | 'callbacks': function (aName, someFunctions, someArguments, aCallbackValue) { | 430 | 'callbacks': function (aName, someFunctions, someArguments, aCallbackValue) { |
424 | var deferredResult; | 431 | var deferredResult; |
425 | var i, c; | 432 | var i, c; |
426 | 433 | ||
427 | deferredResult = new Clipperz.Async.Deferred(aName, someArguments); | 434 | deferredResult = new Clipperz.Async.Deferred(aName, someArguments); |
428 | c = someFunctions.length; | 435 | c = someFunctions.length; |
429 | for (i=0; i<c; i++) { | 436 | for (i=0; i<c; i++) { |
430 | deferredResult.addCallback(someFunctions[i]); | 437 | deferredResult.addCallback(someFunctions[i]); |
431 | } | 438 | } |
432 | deferredResult.callback(aCallbackValue); | 439 | deferredResult.callback(aCallbackValue); |
433 | 440 | ||
434 | return deferredResult; | 441 | return deferredResult; |
435 | }, | 442 | }, |
436 | 443 | ||
437 | //------------------------------------------------------------------------- | 444 | //------------------------------------------------------------------------- |
438 | 445 | ||
439 | 'forkAndJoin': function (aName, someMethods, args) { | 446 | 'forkAndJoin': function (aName, someMethods, args) { |
440 | return MochiKit.Base.partial(function (aName, someMethods, args, aValue) { | 447 | return MochiKit.Base.partial(function (aName, someMethods, args, aValue) { |
441 | var synchronizer; | 448 | var synchronizer; |
442 | varresult; | 449 | varresult; |
443 | 450 | ||
444 | args = args || {}; | 451 | args = args || {}; |
445 | synchronizer = new Clipperz.Async.DeferredSynchronizer(aName, someMethods); | 452 | synchronizer = new Clipperz.Async.DeferredSynchronizer(aName, someMethods); |
446 | result = synchronizer.run(args, aValue); | 453 | result = synchronizer.run(args, aValue); |
447 | 454 | ||
448 | return result; | 455 | return result; |
449 | }, aName, someMethods, args); | 456 | }, aName, someMethods, args); |
450 | }, | 457 | }, |
451 | 458 | ||
452 | //------------------------------------------------------------------------- | 459 | //------------------------------------------------------------------------- |
453 | 460 | ||
454 | 'collectResults': function(aName, someRequests, args) { | 461 | 'collectResults': function(aName, someRequests, args) { |
455 | return MochiKit.Base.partial(function(aName, someRequests, args, aValue) { | 462 | return MochiKit.Base.partial(function(aName, someRequests, args, aValue) { |
456 | var deferredResult; | 463 | var deferredResult; |
457 | var requestKeys; | 464 | var requestKeys; |
458 | var methods; | 465 | var methods; |
459 | 466 | ||
460 | requestKeys = MochiKit.Base.keys(someRequests); | 467 | requestKeys = MochiKit.Base.keys(someRequests); |
461 | methods = MochiKit.Base.values(someRequests); | 468 | methods = MochiKit.Base.values(someRequests); |
462 | 469 | ||
463 | deferredResult = new Clipperz.Async.Deferred(aName, args); | 470 | deferredResult = new Clipperz.Async.Deferred(aName, args); |
464 | deferredResult.addCallback(Clipperz.Async.forkAndJoin(aName + " [inner forkAndJoin]", methods, args)); | 471 | deferredResult.addCallback(Clipperz.Async.forkAndJoin(aName + " [inner forkAndJoin]", methods, args)); |
465 | deferredResult.addBoth(function(someResults) { | 472 | deferredResult.addBoth(function(someResults) { |
466 | var returnFunction; | 473 | var returnFunction; |
467 | var results; | 474 | var results; |
468 | var i,c; | 475 | var i,c; |
469 | var result; | 476 | var result; |
470 | 477 | ||
471 | if (someResults instanceof MochiKit.Async.CancelledError) { | 478 | if (someResults instanceof MochiKit.Async.CancelledError) { |
472 | returnFunction = MochiKit.Async.fail; | 479 | returnFunction = MochiKit.Async.fail; |
473 | result = someResults; | 480 | result = someResults; |
474 | } else { | 481 | } else { |
475 | if (someResults instanceof Error) { | 482 | if (someResults instanceof Error) { |
476 | returnFunction = MochiKit.Async.fail; | 483 | returnFunction = MochiKit.Async.fail; |
477 | results = someResults['message']; | 484 | results = someResults['message']; |
478 | } else { | 485 | } else { |
479 | returnFunction = MochiKit.Async.succeed; | 486 | returnFunction = MochiKit.Async.succeed; |
480 | results = someResults; | 487 | results = someResults; |
481 | } | 488 | } |
482 | 489 | ||
483 | result = {}; | 490 | result = {}; |
484 | 491 | ||
485 | c = requestKeys.length; | 492 | c = requestKeys.length; |
486 | for (i=0; i<c; i++) { | 493 | for (i=0; i<c; i++) { |
487 | result[requestKeys[i]] = results[i]; | 494 | result[requestKeys[i]] = results[i]; |
488 | } | 495 | } |
489 | } | 496 | } |
490 | 497 | ||
491 | return returnFunction.call(null, result); | 498 | return returnFunction.call(null, result); |
492 | }); | 499 | }); |
493 | deferredResult.callback(aValue); | 500 | deferredResult.callback(aValue); |
494 | 501 | ||
495 | return deferredResult; | 502 | return deferredResult; |
496 | }, aName, someRequests, args); | 503 | }, aName, someRequests, args); |
497 | }, | 504 | }, |
498 | 505 | ||
499 | //------------------------------------------------------------------------- | 506 | //------------------------------------------------------------------------- |
500 | 507 | ||
501 | 'collectAll': function (someDeferredObjects) { | 508 | 'collectAll': function (someDeferredObjects) { |
502 | var deferredResult; | 509 | var deferredResult; |
503 | 510 | ||
504 | deferredResult = new MochiKit.Async.DeferredList(someDeferredObjects, false, false, false); | 511 | deferredResult = new MochiKit.Async.DeferredList(someDeferredObjects, false, false, false); |
505 | deferredResult.addCallback(function (aResultList) { | 512 | deferredResult.addCallback(function (aResultList) { |
506 | return MochiKit.Base.map(function (aResult) { | 513 | return MochiKit.Base.map(function (aResult) { |
507 | if (aResult[0]) { | 514 | if (aResult[0]) { |
508 | return aResult[1]; | 515 | return aResult[1]; |
509 | } else { | 516 | } else { |
510 | throw aResult[1]; | 517 | throw aResult[1]; |
511 | } | 518 | } |
512 | }, aResultList); | 519 | }, aResultList); |
513 | }); | 520 | }); |
514 | 521 | ||
515 | return deferredResult; | 522 | return deferredResult; |
516 | }, | 523 | }, |
517 | 524 | ||
518 | //------------------------------------------------------------------------- | 525 | //------------------------------------------------------------------------- |
519 | 526 | ||
520 | 'setItem': function (anObject, aKey, aValue) { | 527 | 'setItem': function (anObject, aKey, aValue) { |
521 | anObject[aKey] = aValue; | 528 | anObject[aKey] = aValue; |
522 | 529 | ||
523 | return anObject; | 530 | return anObject; |
524 | }, | 531 | }, |
525 | 532 | ||
526 | 'setItemOnObject': function (aKey, aValue, anObject) { | 533 | 'setItemOnObject': function (aKey, aValue, anObject) { |
527 | anObject[aKey] = aValue; | 534 | anObject[aKey] = aValue; |
528 | 535 | ||
529 | return anObject; | 536 | return anObject; |
530 | }, | 537 | }, |
531 | 538 | ||
532 | 'setDeferredItemOnObject': function (aKey, aDeferredFunction, anObject) { | 539 | 'setDeferredItemOnObject': function (aKey, aDeferredFunction, anObject) { |
533 | return Clipperz.Async.callbacks("Clipperz.Async.setDeferredItemOnObject", [ | 540 | return Clipperz.Async.callbacks("Clipperz.Async.setDeferredItemOnObject", [ |
534 | aDeferredFunction, | 541 | aDeferredFunction, |
535 | MochiKit.Base.partial(Clipperz.Async.setItem, anObject, aKey) | 542 | MochiKit.Base.partial(Clipperz.Async.setItem, anObject, aKey) |
536 | ], {trace:false}, anObject); | 543 | ], {trace:false}, anObject); |
537 | }, | 544 | }, |
538 | 545 | ||
539 | //------------------------------------------------------------------------- | 546 | //------------------------------------------------------------------------- |
540 | 547 | ||
541 | 'deferredIf': function (aName, aThenBlock, anElseBlock) { | 548 | 'deferredIf': function (aName, aThenBlock, anElseBlock) { |
542 | return function (aValue) { | 549 | return function (aValue) { |
543 | var deferredResult; | 550 | var deferredResult; |
544 | 551 | ||
545 | if (!MochiKit.Base.isUndefinedOrNull(aValue) && aValue) { | 552 | if (!MochiKit.Base.isUndefinedOrNull(aValue) && aValue) { |
546 | deferredResult = Clipperz.Async.callbacks(aName + " <then>", aThenBlock, null, aValue); | 553 | deferredResult = Clipperz.Async.callbacks(aName + " <then>", aThenBlock, null, aValue); |
547 | } else { | 554 | } else { |
548 | deferredResult = Clipperz.Async.callbacks(aName + " <else>", anElseBlock, null, aValue); | 555 | deferredResult = Clipperz.Async.callbacks(aName + " <else>", anElseBlock, null, aValue); |
549 | } | 556 | } |
550 | 557 | ||
551 | return deferredResult; | 558 | return deferredResult; |
552 | } | 559 | } |
553 | }, | 560 | }, |
554 | 561 | ||
555 | //------------------------------------------------------------------------- | 562 | //------------------------------------------------------------------------- |
556 | 563 | ||
557 | 'log': function(aMessage, aResult) { | 564 | 'log': function(aMessage, aResult) { |
558 | if (CLIPPERZ_DEFERRED_LOGGING_ENABLED) { | 565 | if (CLIPPERZ_DEFERRED_LOGGING_ENABLED) { |
559 | Clipperz.log(aMessage + " ", aResult); | 566 | Clipperz.log(aMessage + " ", aResult); |
560 | } | 567 | } |
561 | 568 | ||
562 | return aResult; | 569 | return aResult; |
563 | }, | 570 | }, |
564 | 571 | ||
565 | //========================================================================= | 572 | //========================================================================= |
566 | 573 | ||
567 | 'deferredCompare': function (aComparator, aDeferred, bDeferred) { | 574 | 'deferredCompare': function (aComparator, aDeferred, bDeferred) { |
568 | var deferredResult; | 575 | var deferredResult; |
569 | 576 | ||
570 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredCompare", {trace:false}); | 577 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredCompare", {trace:false}); |
571 | deferredResult.addCallback(Clipperz.Async.collectAll, [aDeferred, bDeferred]); | 578 | deferredResult.addCallback(Clipperz.Async.collectAll, [aDeferred, bDeferred]); |
572 | deferredResult.addCallback(function (someResults) { | 579 | deferredResult.addCallback(function (someResults) { |
573 | var result; | 580 | var result; |
574 | 581 | ||
575 | if (aComparator(someResults[0], someResults[1]) > 0) { | 582 | if (aComparator(someResults[0], someResults[1]) > 0) { |
576 | result = MochiKit.Async.succeed(); | 583 | result = MochiKit.Async.succeed(); |
577 | } else { | 584 | } else { |
578 | result = MochiKit.Async.fail(); | 585 | result = MochiKit.Async.fail(); |
579 | }; | 586 | }; |
580 | 587 | ||
581 | return result; | 588 | return result; |
582 | }); | 589 | }); |
583 | deferredResult.callback(); | 590 | deferredResult.callback(); |
584 | 591 | ||
585 | return deferredResult; | 592 | return deferredResult; |
586 | }, | 593 | }, |
587 | 594 | ||
588 | //------------------------------------------------------------------------- | 595 | //------------------------------------------------------------------------- |
589 | 596 | ||
590 | 'insertIntoSortedArray': function (anObject, aDeferredComparator, aSortedResult) { | 597 | 'insertIntoSortedArray': function (anObject, aDeferredComparator, aSortedResult) { |
591 | var deferredResult; | 598 | var deferredResult; |
592 | var i, c; | 599 | var i, c; |
593 | 600 | ||
594 | if (aSortedResult.length == 0) { | 601 | if (aSortedResult.length == 0) { |
595 | deferredResult = MochiKit.Async.succeed([anObject]); | 602 | deferredResult = MochiKit.Async.succeed([anObject]); |
596 | } else { | 603 | } else { |
597 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.insertIntoSortedArray", {trace:false}); | 604 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.insertIntoSortedArray", {trace:false}); |
598 | c = aSortedResult.length + 1; | 605 | c = aSortedResult.length + 1; |
599 | for (i=0; i<c; i++) { | 606 | for (i=0; i<c; i++) { |
600 | deferredResult.addCallback(function (aDeferredComparator, aObject, bObject, aContext) { | 607 | deferredResult.addCallback(function (aDeferredComparator, aObject, bObject, aContext) { |
601 | var innerDeferredResult; | 608 | var innerDeferredResult; |
602 | 609 | ||
603 | innerDeferredResult = new Clipperz.Async.Deferred("Clipperz.Async.insertIntoSortedArray <inner compare>", {trace:false}); | 610 | innerDeferredResult = new Clipperz.Async.Deferred("Clipperz.Async.insertIntoSortedArray <inner compare>", {trace:false}); |
604 | innerDeferredResult.addCallback(aDeferredComparator, aObject, bObject); | 611 | innerDeferredResult.addCallback(aDeferredComparator, aObject, bObject); |
605 | innerDeferredResult.addErrback(MochiKit.Async.fail, aContext); | 612 | innerDeferredResult.addErrback(MochiKit.Async.fail, aContext); |
606 | innerDeferredResult.callback(); | 613 | innerDeferredResult.callback(); |
607 | 614 | ||
608 | return innerDeferredResult; | 615 | return innerDeferredResult; |
609 | }, aDeferredComparator, anObject, aSortedResult[i], i); | 616 | }, aDeferredComparator, anObject, aSortedResult[i], i); |
610 | } | 617 | } |
611 | deferredResult.addMethod(aSortedResult, 'push', anObject); | 618 | deferredResult.addMethod(aSortedResult, 'push', anObject); |
612 | deferredResult.addErrback(function (anError) { | 619 | deferredResult.addErrback(function (anError) { |
613 | aSortedResult.splice(anError.message, 0, anObject); | 620 | aSortedResult.splice(anError.message, 0, anObject); |
614 | }) | 621 | }) |
615 | deferredResult.addBoth(MochiKit.Async.succeed, aSortedResult); | 622 | deferredResult.addBoth(MochiKit.Async.succeed, aSortedResult); |
616 | deferredResult.callback(); | 623 | deferredResult.callback(); |
617 | } | 624 | } |
618 | 625 | ||
619 | return deferredResult; | 626 | return deferredResult; |
620 | }, | 627 | }, |
621 | 628 | ||
622 | //------------------------------------------------------------------------- | 629 | //------------------------------------------------------------------------- |
623 | 630 | ||
624 | 'deferredSort': function (aDeferredComparator, someObjects) { | 631 | 'deferredSort': function (aDeferredComparator, someObjects) { |
625 | var deferredResult; | 632 | var deferredResult; |
626 | var i, c; | 633 | var i, c; |
627 | 634 | ||
628 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredSort", {trace:false}); | 635 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredSort", {trace:false}); |
629 | c = someObjects.length; | 636 | c = someObjects.length; |
630 | for (i=0; i<c; i++) { | 637 | for (i=0; i<c; i++) { |
631 | deferredResult.addCallback(Clipperz.Async.insertIntoSortedArray, someObjects[i], aDeferredComparator); | 638 | deferredResult.addCallback(Clipperz.Async.insertIntoSortedArray, someObjects[i], aDeferredComparator); |
632 | if ((i % 50) == 0) { | 639 | if ((i % 50) == 0) { |
633 | //console.log("######### sort wait ##########"); | 640 | //console.log("######### sort wait ##########"); |
634 | deferredResult.addCallback(MochiKit.Async.wait, 0.5); | 641 | deferredResult.addCallback(MochiKit.Async.wait, 0.5); |
635 | } | 642 | } |
636 | } | 643 | } |
637 | deferredResult.callback([]); | 644 | deferredResult.callback([]); |
638 | 645 | ||
639 | return deferredResult; | 646 | return deferredResult; |
640 | }, | 647 | }, |
641 | 648 | ||
642 | //========================================================================= | 649 | //========================================================================= |
643 | 650 | ||
644 | 'deferredFilter': function (aFunction, someObjects) { | 651 | 'deferredFilter': function (aFunction, someObjects) { |
645 | vardeferredResult; | 652 | vardeferredResult; |
646 | vari, c; | 653 | vari, c; |
647 | 654 | ||
648 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredFilter", {trace:false}); | 655 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredFilter", {trace:false}); |
649 | c = someObjects.length; | 656 | c = someObjects.length; |
650 | for (i=0; i<c; i++) { | 657 | for (i=0; i<c; i++) { |
651 | deferredResult.addCallback(function (aFunction, anObject, anIndex, aResult) { | 658 | deferredResult.addCallback(function (aFunction, anObject, anIndex, aResult) { |
652 | var innerDeferredResult; | 659 | var innerDeferredResult; |
653 | 660 | ||
654 | innerDeferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredFilter <inner - " + anIndex + ">", {trace:false}); | 661 | innerDeferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredFilter <inner - " + anIndex + ">", {trace:false}); |
655 | innerDeferredResult.addCallback(aFunction, anObject); | 662 | innerDeferredResult.addCallback(aFunction, anObject); |
656 | innerDeferredResult.addCallback(function (aFilterResult) { | 663 | innerDeferredResult.addCallback(function (aFilterResult) { |
657 | if (aFilterResult) { | 664 | if (aFilterResult) { |
658 | aResult.push(anObject); | 665 | aResult.push(anObject); |
659 | }; | 666 | }; |
660 | }); | 667 | }); |
661 | innerDeferredResult.addBoth(MochiKit.Async.succeed, aResult); | 668 | innerDeferredResult.addBoth(MochiKit.Async.succeed, aResult); |
662 | innerDeferredResult.callback(); | 669 | innerDeferredResult.callback(); |
663 | 670 | ||
664 | return innerDeferredResult; | 671 | return innerDeferredResult; |
665 | }, aFunction, someObjects[i], i); | 672 | }, aFunction, someObjects[i], i); |
666 | } | 673 | } |
667 | deferredResult.callback([]); | 674 | deferredResult.callback([]); |
668 | 675 | ||
669 | return deferredResult; | 676 | return deferredResult; |
670 | }, | 677 | }, |
671 | 678 | ||
672 | 'forEach': function (aFunction) { | 679 | 'forEach': function (aFunction) { |
673 | return MochiKit.Base.partial(function (aFunction, anIterable) { | 680 | return MochiKit.Base.partial(function (aFunction, anIterable) { |
674 | MochiKit.Iter.forEach(anIterable, aFunction); | 681 | MochiKit.Iter.forEach(anIterable, aFunction); |
675 | }, aFunction); | 682 | }, aFunction); |
676 | }, | 683 | }, |
677 | 684 | ||
678 | //========================================================================= | 685 | //========================================================================= |
679 | 686 | ||
680 | 'or': function (someValues) { | 687 | 'or': function (someValues) { |
681 | return Clipperz.Async.callbacks("Clipperz.Async.or", [ | 688 | return Clipperz.Async.callbacks("Clipperz.Async.or", [ |
682 | MochiKit.Base.values, | 689 | MochiKit.Base.values, |
683 | MochiKit.Base.flattenArguments, | 690 | MochiKit.Base.flattenArguments, |
684 | //function (aValue) { console.log("Record.hasAnyCleanTextData - flatten", aValue); return aValue; }, | 691 | //function (aValue) { console.log("Record.hasAnyCleanTextData - flatten", aValue); return aValue; }, |
685 | function(someInnerValues) { | 692 | function(someInnerValues) { |
686 | return MochiKit.Iter.some(someInnerValues, MochiKit.Base.operator.identity); | 693 | return MochiKit.Iter.some(someInnerValues, MochiKit.Base.operator.identity); |
687 | } | 694 | } |
688 | ], {trace:false}, someValues); | 695 | ], {trace:false}, someValues); |
689 | }, | 696 | }, |
690 | 697 | ||
691 | //========================================================================= | 698 | //========================================================================= |
692 | 699 | ||
693 | 'clearResult': function () {}, | 700 | 'clearResult': function () {}, |
694 | 701 | ||
695 | //========================================================================= | 702 | //========================================================================= |
696 | __syntaxFix__: "syntax fix" | 703 | __syntaxFix__: "syntax fix" |
697 | }); | 704 | }); |
698 | 705 | ||
699 | 706 | ||
700 | //############################################################################# | 707 | //############################################################################# |
701 | 708 | ||
702 | CLIPPERZ_DEFERRED_LOGGING_ENABLED = true; | 709 | CLIPPERZ_DEFERRED_LOGGING_ENABLED = true; |
703 | CLIPPERZ_DEFERRED_TRACING_ENABLED = false; | 710 | CLIPPERZ_DEFERRED_TRACING_ENABLED = false; |
704 | CLIPPERZ_DEFERRED_CALL_LOGGING_ENABLED = false; | 711 | CLIPPERZ_DEFERRED_CALL_LOGGING_ENABLED = false; |
diff --git a/frontend/gamma/js/Clipperz/PM/Proxy.js b/frontend/gamma/js/Clipperz/PM/Proxy.js index 190bffd..9817eac 100644 --- a/frontend/gamma/js/Clipperz/PM/Proxy.js +++ b/frontend/gamma/js/Clipperz/PM/Proxy.js | |||
@@ -1,169 +1,169 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2011 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz Community Edition. |
6 | Clipperz Community Edition is an online password manager. | 6 | Clipperz Community Edition is an online password manager. |
7 | For further information about its features and functionalities please | 7 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 8 | refer to http://www.clipperz.com. |
9 | 9 | ||
10 | * Clipperz Community Edition is free software: you can redistribute | 10 | * Clipperz Community Edition is free software: you can redistribute |
11 | it and/or modify it under the terms of the GNU Affero General Public | 11 | it and/or modify it under the terms of the GNU Affero General Public |
12 | License as published by the Free Software Foundation, either version | 12 | License as published by the Free Software Foundation, either version |
13 | 3 of the License, or (at your option) any later version. | 13 | 3 of the License, or (at your option) any later version. |
14 | 14 | ||
15 | * Clipperz Community Edition is distributed in the hope that it will | 15 | * Clipperz Community Edition is distributed in the hope that it will |
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 16 | be useful, but WITHOUT ANY WARRANTY; without even the implied |
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. | 18 | See the GNU Affero General Public License for more details. |
19 | 19 | ||
20 | * You should have received a copy of the GNU Affero General Public | 20 | * You should have received a copy of the GNU Affero General Public |
21 | License along with Clipperz Community Edition. If not, see | 21 | License along with Clipperz Community Edition. If not, see |
22 | <http://www.gnu.org/licenses/>. | 22 | <http://www.gnu.org/licenses/>. |
23 | 23 | ||
24 | */ | 24 | */ |
25 | 25 | ||
26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | 27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } |
28 | 28 | ||
29 | //============================================================================= | 29 | //============================================================================= |
30 | 30 | ||
31 | Clipperz.PM.Proxy = function(args) { | 31 | Clipperz.PM.Proxy = function(args) { |
32 | args = args || {}; | 32 | args = args || {}; |
33 | 33 | ||
34 | this._shouldPayTolls = args.shouldPayTolls || false; | 34 | this._shouldPayTolls = args.shouldPayTolls || false; |
35 | 35 | ||
36 | this._tolls = { | 36 | this._tolls = { |
37 | 'CONNECT':[], | 37 | 'CONNECT':[], |
38 | 'REGISTER':[], | 38 | 'REGISTER':[], |
39 | 'MESSAGE':[] | 39 | 'MESSAGE':[] |
40 | }; | 40 | }; |
41 | 41 | ||
42 | if (args.isDefault === true) { | 42 | if (args.isDefault === true) { |
43 | Clipperz.PM.Proxy.defaultProxy = this; | 43 | Clipperz.PM.Proxy.defaultProxy = this; |
44 | } | 44 | } |
45 | 45 | ||
46 | return this; | 46 | return this; |
47 | } | 47 | } |
48 | 48 | ||
49 | Clipperz.PM.Proxy.prototype = MochiKit.Base.update(null, { | 49 | Clipperz.PM.Proxy.prototype = MochiKit.Base.update(null, { |
50 | 50 | ||
51 | 'toString': function() { | 51 | 'toString': function() { |
52 | return "Clipperz.PM.Proxy"; | 52 | return "Clipperz.PM.Proxy"; |
53 | }, | 53 | }, |
54 | 54 | ||
55 | //========================================================================= | 55 | //========================================================================= |
56 | 56 | ||
57 | 'shouldPayTolls': function() { | 57 | 'shouldPayTolls': function() { |
58 | return this._shouldPayTolls; | 58 | return this._shouldPayTolls; |
59 | }, | 59 | }, |
60 | 60 | ||
61 | //------------------------------------------------------------------------- | 61 | //------------------------------------------------------------------------- |
62 | 62 | ||
63 | 'tolls': function() { | 63 | 'tolls': function() { |
64 | return this._tolls; | 64 | return this._tolls; |
65 | }, | 65 | }, |
66 | 66 | ||
67 | //------------------------------------------------------------------------- | 67 | //------------------------------------------------------------------------- |
68 | 68 | ||
69 | 'payToll': function(aRequestType, someParameters) { | 69 | 'payToll': function(aRequestType, someParameters) { |
70 | vardeferredResult; | 70 | vardeferredResult; |
71 | 71 | ||
72 | //console.log(">>> Proxy.payToll", aRequestType, someParameters); | 72 | //console.log(">>> Proxy.payToll", aRequestType, someParameters); |
73 | if (this.shouldPayTolls()) { | 73 | if (this.shouldPayTolls()) { |
74 | deferredResult = new Clipperz.Async.Deferred("Proxy.payToll", {trace:false}); | 74 | deferredResult = new Clipperz.Async.Deferred("Proxy.payToll", {trace:false}); |
75 | 75 | ||
76 | if (this.tolls()[aRequestType].length == 0) { | 76 | if (this.tolls()[aRequestType].length == 0) { |
77 | deferredResult.addMethod(this, 'sendMessage', 'knock', {requestType:aRequestType}); | 77 | deferredResult.addMethod(this, 'sendMessage', 'knock', {requestType:aRequestType}); |
78 | deferredResult.addMethod(this, 'setTollCallback'); | 78 | deferredResult.addMethod(this, 'setTollCallback'); |
79 | } | 79 | } |
80 | deferredResult.addMethod(this.tolls()[aRequestType], 'pop'); | 80 | deferredResult.addMethod(this.tolls()[aRequestType], 'pop'); |
81 | deferredResult.addCallback(MochiKit.Base.methodcaller('deferredPay')); | 81 | deferredResult.addCallback(MochiKit.Base.methodcaller('deferredPay')); |
82 | deferredResult.addCallback(function(aToll) { | 82 | deferredResult.addCallback(function(aToll) { |
83 | var result; | 83 | var result; |
84 | 84 | ||
85 | result = { | 85 | result = { |
86 | parameters: someParameters, | 86 | parameters: someParameters, |
87 | toll: aToll | 87 | toll: aToll |
88 | } | 88 | } |
89 | 89 | ||
90 | return result; | 90 | return result; |
91 | }); | 91 | }); |
92 | 92 | ||
93 | deferredResult.callback(); | 93 | deferredResult.callback(); |
94 | } else { | 94 | } else { |
95 | deferredResult = MochiKit.Async.succeed({parameters:someParameters}); | 95 | deferredResult = MochiKit.Async.succeed({parameters:someParameters}); |
96 | } | 96 | } |
97 | //console.log("<<< Proxy.payToll"); | 97 | //console.log("<<< Proxy.payToll"); |
98 | 98 | ||
99 | return deferredResult; | 99 | return deferredResult; |
100 | }, | 100 | }, |
101 | 101 | ||
102 | //------------------------------------------------------------------------- | 102 | //------------------------------------------------------------------------- |
103 | 103 | ||
104 | 'addToll': function(aToll) { | 104 | 'addToll': function(aToll) { |
105 | //console.log(">>> Proxy.addToll", aToll); | 105 | //console.log(">>> Proxy.addToll", aToll); |
106 | this.tolls()[aToll.requestType()].push(aToll); | 106 | this.tolls()[aToll.requestType()].push(aToll); |
107 | //console.log("<<< Proxy.addToll"); | 107 | //console.log("<<< Proxy.addToll"); |
108 | }, | 108 | }, |
109 | 109 | ||
110 | //========================================================================= | 110 | //========================================================================= |
111 | 111 | ||
112 | 'setTollCallback': function(someParameters) { | 112 | 'setTollCallback': function(someParameters) { |
113 | //console.log(">>> Proxy.setTollCallback", someParameters); | 113 | //console.log(">>> Proxy.setTollCallback", someParameters); |
114 | if (typeof(someParameters['toll']) != 'undefined') { | 114 | if (typeof(someParameters['toll']) != 'undefined') { |
115 | //console.log("added a new toll", someParameters['toll']); | 115 | //console.log("added a new toll", someParameters['toll']); |
116 | this.addToll(new Clipperz.PM.Toll(someParameters['toll'])); | 116 | this.addToll(new Clipperz.PM.Toll(someParameters['toll'])); |
117 | } | 117 | } |
118 | //console.log("<<< Proxy.setTallCallback", someParameters['result']); | 118 | //console.log("<<< Proxy.setTallCallback", someParameters['result']); |
119 | return someParameters['result']; | 119 | return someParameters['result']; |
120 | }, | 120 | }, |
121 | 121 | ||
122 | //========================================================================= | 122 | //========================================================================= |
123 | 123 | ||
124 | 'registration': function (someParameters) { | 124 | 'registration': function (someParameters) { |
125 | return this.processMessage('registration', someParameters, 'REGISTER'); | 125 | return this.processMessage('registration', someParameters, 'REGISTER'); |
126 | }, | 126 | }, |
127 | 127 | ||
128 | 'handshake': function (someParameters) { | 128 | 'handshake': function (someParameters) { |
129 | return this.processMessage('handshake', someParameters, 'CONNECT'); | 129 | return this.processMessage('handshake', someParameters, 'CONNECT'); |
130 | }, | 130 | }, |
131 | 131 | ||
132 | 'message': function (someParameters) { | 132 | 'message': function (someParameters) { |
133 | return this.processMessage('message', someParameters, 'MESSAGE'); | 133 | return this.processMessage('message', someParameters, 'MESSAGE'); |
134 | }, | 134 | }, |
135 | 135 | ||
136 | 'logout': function (someParameters) { | 136 | 'logout': function (someParameters) { |
137 | return this.processMessage('logout', someParameters, 'MESSAGE'); | 137 | return this.processMessage('logout', someParameters, 'MESSAGE'); |
138 | }, | 138 | }, |
139 | 139 | ||
140 | //========================================================================= | 140 | //========================================================================= |
141 | 141 | ||
142 | 'processMessage': function (aFunctionName, someParameters, aRequestType) { | 142 | 'processMessage': function (aFunctionName, someParameters, aRequestType) { |
143 | vardeferredResult; | 143 | vardeferredResult; |
144 | 144 | ||
145 | deferredResult = new Clipperz.Async.Deferred("Proxy.processMessage", {trace:false}); | 145 | deferredResult = new Clipperz.Async.Deferred("Proxy.processMessage", {trace:true}); |
146 | deferredResult.addMethod(this, 'payToll', aRequestType); | 146 | deferredResult.addMethod(this, 'payToll', aRequestType); |
147 | deferredResult.addMethod(this, 'sendMessage', aFunctionName); | 147 | deferredResult.addMethod(this, 'sendMessage', aFunctionName); |
148 | deferredResult.addMethod(this, 'setTollCallback'); | 148 | deferredResult.addMethod(this, 'setTollCallback'); |
149 | deferredResult.callback(someParameters); | 149 | deferredResult.callback(someParameters); |
150 | 150 | ||
151 | return deferredResult; | 151 | return deferredResult; |
152 | }, | 152 | }, |
153 | 153 | ||
154 | //========================================================================= | 154 | //========================================================================= |
155 | 155 | ||
156 | 'sendMessage': function () { | 156 | 'sendMessage': function () { |
157 | throw Clipperz.Base.exception.AbstractMethod; | 157 | throw Clipperz.Base.exception.AbstractMethod; |
158 | }, | 158 | }, |
159 | 159 | ||
160 | //========================================================================= | 160 | //========================================================================= |
161 | 161 | ||
162 | 'isReadOnly': function () { | 162 | 'isReadOnly': function () { |
163 | return false; | 163 | return false; |
164 | }, | 164 | }, |
165 | 165 | ||
166 | //========================================================================= | 166 | //========================================================================= |
167 | __syntaxFix__: "syntax fix" | 167 | __syntaxFix__: "syntax fix" |
168 | 168 | ||
169 | }); | 169 | }); |