author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-02 23:56:18 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-02 23:56:18 (UTC) |
commit | ef68436ac04da078ffdcacd7e1f785473a303d45 (patch) (unidiff) | |
tree | c403752d66a2c4775f00affd4fa8431b29c5b68c /frontend/beta/js/Clipperz/PM/Proxy/Proxy.PHP.js | |
parent | 597ecfbc0249d83e1b856cbd558340c01237a360 (diff) | |
download | clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.zip clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.gz clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.bz2 |
First version of the newly restructured repository
Diffstat (limited to 'frontend/beta/js/Clipperz/PM/Proxy/Proxy.PHP.js') (more/less context) (ignore whitespace changes)
-rwxr-xr-x | frontend/beta/js/Clipperz/PM/Proxy/Proxy.PHP.js | 259 |
1 files changed, 259 insertions, 0 deletions
diff --git a/frontend/beta/js/Clipperz/PM/Proxy/Proxy.PHP.js b/frontend/beta/js/Clipperz/PM/Proxy/Proxy.PHP.js new file mode 100755 index 0000000..e7c2bc1 --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Proxy/Proxy.PHP.js | |||
@@ -0,0 +1,259 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz's Javascript Crypto Library. | ||
6 | Javascript Crypto Library provides web developers with an extensive | ||
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | ||
11 | refer to http://www.clipperz.com | ||
12 | |||
13 | * Javascript Crypto Library is free software: you can redistribute | ||
14 | it and/or modify it under the terms of the GNU Affero General Public | ||
15 | License as published by the Free Software Foundation, either version | ||
16 | 3 of the License, or (at your option) any later version. | ||
17 | |||
18 | * Javascript Crypto Library is distributed in the hope that it will | ||
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
21 | See the GNU Affero General Public License for more details. | ||
22 | |||
23 | * You should have received a copy of the GNU Affero General Public | ||
24 | License along with Javascript Crypto Library. If not, see | ||
25 | <http://www.gnu.org/licenses/>. | ||
26 | |||
27 | */ | ||
28 | |||
29 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | ||
30 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | ||
31 | |||
32 | //============================================================================= | ||
33 | |||
34 | Clipperz.PM.Proxy.PHP = function(args) { | ||
35 | Clipperz.PM.Proxy.PHP.superclass.constructor.call(this, args); | ||
36 | /* | ||
37 | this._tolls = { | ||
38 | 'CONNECT':[], | ||
39 | 'REGISTER':[], | ||
40 | 'MESSAGE':[] | ||
41 | }; | ||
42 | */ | ||
43 | return this; | ||
44 | } | ||
45 | |||
46 | YAHOO.extendX(Clipperz.PM.Proxy.PHP, Clipperz.PM.Proxy, { | ||
47 | |||
48 | 'toString': function() { | ||
49 | return "Clipperz.PM.Proxy.PHP - " + this.args(); | ||
50 | }, | ||
51 | |||
52 | //========================================================================= | ||
53 | /* | ||
54 | 'tolls': function() { | ||
55 | return this._tolls; | ||
56 | }, | ||
57 | */ | ||
58 | //------------------------------------------------------------------------- | ||
59 | /* | ||
60 | 'payToll': function(aRequestType, someParameters) { | ||
61 | vardeferredResult; | ||
62 | |||
63 | //MochiKit.Logging.logDebug(">>> Proxy.DWR.payToll: " + aRequestType); | ||
64 | if (this.tolls()[aRequestType].length > 0) { | ||
65 | deferredResult = MochiKit.Async.succeed(this.tolls()[aRequestType].pop()); | ||
66 | } else { | ||
67 | //MochiKit.Logging.logDebug("### " + aRequestType + " toll NOT immediately available; request queued."); | ||
68 | deferredResult = new MochiKit.Async.Deferred(); | ||
69 | deferredResult.addCallback(function(someParameters) { | ||
70 | return new Clipperz.PM.Toll(someParameters['toll']); | ||
71 | }) | ||
72 | com_clipperz_pm_Proxy.knock(Clipperz.Base.serializeJSON({requestType:aRequestType}), { | ||
73 | callback:MochiKit.Base.method(deferredResult, 'callback'), | ||
74 | errorHandler:MochiKit.Base.method(deferredResult, 'errback') | ||
75 | }); | ||
76 | } | ||
77 | |||
78 | deferredResult.addCallback(function(aToll) { | ||
79 | return aToll.deferredPay(); | ||
80 | }); | ||
81 | deferredResult.addCallback(function(someParameters, aToll) { | ||
82 | var result; | ||
83 | |||
84 | result = { | ||
85 | parameters: someParameters, | ||
86 | toll: aToll | ||
87 | } | ||
88 | |||
89 | return result; | ||
90 | }, someParameters); | ||
91 | |||
92 | return deferredResult; | ||
93 | }, | ||
94 | */ | ||
95 | //------------------------------------------------------------------------- | ||
96 | /* | ||
97 | 'addToll': function(aToll) { | ||
98 | this.tolls()[aToll.requestType()].push(aToll); | ||
99 | }, | ||
100 | */ | ||
101 | //========================================================================= | ||
102 | /* | ||
103 | 'setTollCallback': function(someParameters) { | ||
104 | //MochiKit.Logging.logDebug(">>> Proxy.DWR.setTollCallback"); | ||
105 | //MochiKit.Logging.logDebug("--- Proxy.DWR.setTollCallback - " + Clipperz.Base.serializeJSON(someParameters)); | ||
106 | if (typeof(someParameters['toll']) != 'undefined') { | ||
107 | this.addToll(new Clipperz.PM.Toll(someParameters['toll'])); | ||
108 | } | ||
109 | return someParameters['result']; | ||
110 | }, | ||
111 | */ | ||
112 | //========================================================================= | ||
113 | |||
114 | 'registration': function(someParameters) { | ||
115 | return this.sendMessage('registration', someParameters, 'REGISTER'); | ||
116 | }, | ||
117 | |||
118 | //------------------------------------------------------------------------- | ||
119 | |||
120 | 'handshake': function(someParameters) { | ||
121 | /* | ||
122 | _s = "e8a2162f29aeaabb729f5625e9740edbf0cd80ac77c6b19ab951ed6c88443b8c"; | ||
123 | _v = new Clipperz.Crypto.BigInt("955e2db0f7844aca372f5799e5f7e51b5866718493096908bd66abcf1d068108", 16); | ||
124 | _b = new Clipperz.Crypto.BigInt("5761e6c84d22ea3c5649de01702d60f674ccfe79238540eb34c61cd020230c53", 16); | ||
125 | |||
126 | _B = _v.add(Clipperz.Crypto.SRP.g().powerModule(_b, Clipperz.Crypto.SRP.n())); | ||
127 | _u = new Clipperz.Crypto.BigInt(Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(_B.asString(10))).toHexString(), 16); | ||
128 | _A = new Clipperz.Crypto.BigInt("3b3567ec33d73673552e960872eb154d091a2488915941038aef759236a27e64", 16); | ||
129 | _S = (_A.multiply(_v.powerModule(_u, Clipperz.Crypto.SRP.n()))).powerModule(_b, Clipperz.Crypto.SRP.n()); | ||
130 | _K = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(_S.asString(10))).toHexString().slice(2); | ||
131 | _M1 = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(_A.asString(10) + _B.asString(10) + _K)).toHexString().slice(2); | ||
132 | _M2 = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(_A.asString(10) + _M1 + _K)).toHexString().slice(2); | ||
133 | |||
134 | // MochiKit.Logging.logDebug("b = " + _b.asString(16)); | ||
135 | // MochiKit.Logging.logDebug("v = " + _v.asString(16)); | ||
136 | MochiKit.Logging.logDebug("B = " + _B.asString(16)); | ||
137 | MochiKit.Logging.logDebug("u = " + _u.asString(16)); | ||
138 | MochiKit.Logging.logDebug("S = " + _S.asString(16)); | ||
139 | MochiKit.Logging.logDebug("K = " + _K); | ||
140 | MochiKit.Logging.logDebug("M1 = " + _M1); | ||
141 | MochiKit.Logging.logDebug("M2 = " + _M2); | ||
142 | // MochiKit.Logging.logDebug("someParameters.version: " + someParameters.version); | ||
143 | */ | ||
144 | return this.sendMessage('handshake', someParameters, 'CONNECT'); | ||
145 | }, | ||
146 | |||
147 | //------------------------------------------------------------------------- | ||
148 | |||
149 | 'message': function(someParameters) { | ||
150 | return this.sendMessage('message', someParameters, 'MESSAGE'); | ||
151 | }, | ||
152 | |||
153 | //------------------------------------------------------------------------- | ||
154 | |||
155 | 'logout': function(someParameters) { | ||
156 | //MochiKit.Logging.logDebug("=== Proxy.DWR.logout"); | ||
157 | return this.sendMessage('logout', someParameters, 'MESSAGE'); | ||
158 | }, | ||
159 | |||
160 | //========================================================================= | ||
161 | |||
162 | 'sendMessage': function(aFunctionName, someParameters, aRequestType) { | ||
163 | /* | ||
164 | vardeferredResult; | ||
165 | var proxy; | ||
166 | |||
167 | //MochiKit.Logging.logDebug(">>> Proxy.DWR.sendMessage - " + aFunctionName + " - " + aRequestType); | ||
168 | proxy = this; | ||
169 | |||
170 | deferredResult = new MochiKit.Async.Deferred(); | ||
171 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("x.1 Proxy.DWR.sendMessage - 1: " + res); return res;}); | ||
172 | deferredResult.addCallback(MochiKit.Base.method(proxy, 'payToll'), aRequestType); | ||
173 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("x.2 Proxy.DWR.sendMessage - 2: " + Clipperz.Base.serializeJSON(res)); return res;}); | ||
174 | deferredResult.addCallback(MochiKit.Base.method(proxy, 'sendRemoteMessage'), aFunctionName); | ||
175 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("x.3 Proxy.DWR.sendMessage - 3: " + res); return res;}); | ||
176 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("x.3 Proxy.DWR.sendMessage - 3: " + Clipperz.Base.serializeJSON(res)); return res;}); | ||
177 | deferredResult.callback(someParameters); | ||
178 | |||
179 | //MochiKit.Logging.logDebug("<<< Proxy.DWR.sendMessage"); | ||
180 | return deferredResult; | ||
181 | */ | ||
182 | |||
183 | // return this.sendRemoteMessage(aFunctionName, someParameters); | ||
184 | |||
185 | |||
186 | vardeferredResult; | ||
187 | var proxy; | ||
188 | |||
189 | proxy = this; | ||
190 | |||
191 | deferredResult = new MochiKit.Async.Deferred(); | ||
192 | deferredResult.addCallback(MochiKit.Base.method(proxy, 'sendRemoteMessage'), aFunctionName); | ||
193 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("x.3 Proxy.PHP.sendMessage - 3: " + res); return res;}); | ||
194 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("x.3 Proxy.PHP.sendMessage - 3.1: " + Clipperz.Base.serializeJSON(res)); return res;}); | ||
195 | |||
196 | deferredResult.callback(someParameters); | ||
197 | |||
198 | return deferredResult; | ||
199 | }, | ||
200 | |||
201 | //========================================================================= | ||
202 | |||
203 | 'sendRemoteMessage': function(aFunctionName, someParameters) { | ||
204 | /* | ||
205 | vardeferredResult; | ||
206 | |||
207 | //MochiKit.Logging.logDebug(">>> Proxy.DWR.sendRemoteMessage('" + aFunctionName + "', " + Clipperz.Base.serializeJSON(someParameters) + ") - " + this); | ||
208 | deferredResult = new MochiKit.Async.Deferred(); | ||
209 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Proxy.DWR.sendRemoteMessage - 1: " + res); return res;}); | ||
210 | // deferredResult.addCallback(MochiKit.Base.method(this, 'setTollCallback')); | ||
211 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Proxy.DWR.sendRemoteMessage - 2: " + res); return res;}); | ||
212 | |||
213 | com_clipperz_pm_Proxy[aFunctionName](Clipperz.Base.serializeJSON(someParameters), { | ||
214 | callback:MochiKit.Base.method(deferredResult, 'callback'), | ||
215 | errorHandler:MochiKit.Base.method(deferredResult, 'errback') | ||
216 | }); | ||
217 | //MochiKit.Logging.logDebug("<<< Proxy.PHP.sendRemoteMessage - result: " + deferredResult); | ||
218 | |||
219 | return deferredResult; | ||
220 | */ | ||
221 | |||
222 | vardeferredResult; | ||
223 | var parameters; | ||
224 | |||
225 | //MochiKit.Logging.logDebug(">>> Proxy.PHP.sendRemoteMessage('" + aFunctionName + "', " + Clipperz.Base.serializeJSON(someParameters) + ") - " + this); | ||
226 | parameters = {}; | ||
227 | parameters['method'] = aFunctionName; | ||
228 | // parameters['version'] = someParameters['version']; | ||
229 | // parameters['message'] = someParameters['message']; | ||
230 | parameters['parameters'] = Clipperz.Base.serializeJSON(someParameters); | ||
231 | //MochiKit.Logging.logDebug("--- Proxy.PHP.sendRemoteMessage('" + Clipperz.Base.serializeJSON(parameters) + ") - " + this); | ||
232 | deferredResult = new MochiKit.Async.Deferred(); | ||
233 | deferredResult.addCallback(MochiKit.Async.doXHR, "./php/index.php", { | ||
234 | method:'POST', | ||
235 | sendContent:MochiKit.Base.queryString(parameters), | ||
236 | headers:{"Content-Type":"application/x-www-form-urlencoded"} | ||
237 | }); | ||
238 | //deferredResult.addCallback(function(res) {MochiKit.Logging.logDebug("Proxy.PHP.response - 2: " + res.responseText); return res;}); | ||
239 | //deferredResult.addErrback(function(res) {MochiKit.Logging.logDebug("Proxy.PHP.response - ERROR: " + res); return res;}); | ||
240 | deferredResult.addCallback(MochiKit.Async.evalJSONRequest); | ||
241 | deferredResult.callback(); | ||
242 | |||
243 | return deferredResult; | ||
244 | }, | ||
245 | |||
246 | //========================================================================= | ||
247 | |||
248 | 'isReadOnly': function() { | ||
249 | return false; | ||
250 | }, | ||
251 | |||
252 | //========================================================================= | ||
253 | __syntaxFix__: "syntax fix" | ||
254 | |||
255 | }); | ||
256 | |||
257 | //============================================================================= | ||
258 | |||
259 | //Clipperz.PM.Proxy.defaultProxy = new Clipperz.PM.Proxy.PHP("Proxy.PHP - async test"); | ||