Diffstat (limited to 'frontend/beta/js/Clipperz/PM/Proxy.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/PM/Proxy.js | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/frontend/beta/js/Clipperz/PM/Proxy.js b/frontend/beta/js/Clipperz/PM/Proxy.js new file mode 100644 index 0000000..d05a5e0 --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Proxy.js | |||
@@ -0,0 +1,173 @@ | |||
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 = function(args) { | ||
35 | args = args || {}; | ||
36 | |||
37 | this._shouldPayTolls = args.shouldPayTolls || false; | ||
38 | |||
39 | this._tolls = { | ||
40 | 'CONNECT':[], | ||
41 | 'REGISTER':[], | ||
42 | 'MESSAGE':[] | ||
43 | }; | ||
44 | |||
45 | if (args.isDefault === true) { | ||
46 | Clipperz.PM.Proxy.defaultProxy = this; | ||
47 | } | ||
48 | |||
49 | return this; | ||
50 | } | ||
51 | |||
52 | Clipperz.PM.Proxy.prototype = MochiKit.Base.update(null, { | ||
53 | |||
54 | 'toString': function() { | ||
55 | return "Clipperz.PM.Proxy"; | ||
56 | }, | ||
57 | |||
58 | //========================================================================= | ||
59 | |||
60 | 'shouldPayTolls': function() { | ||
61 | return this._shouldPayTolls; | ||
62 | }, | ||
63 | |||
64 | //------------------------------------------------------------------------- | ||
65 | |||
66 | 'tolls': function() { | ||
67 | return this._tolls; | ||
68 | }, | ||
69 | |||
70 | //------------------------------------------------------------------------- | ||
71 | |||
72 | 'payToll': function(aRequestType, someParameters) { | ||
73 | vardeferredResult; | ||
74 | |||
75 | //console.log(">>> Proxy.payToll", aRequestType, someParameters); | ||
76 | if (this.shouldPayTolls()) { | ||
77 | deferredResult = new MochiKit.Async.Deferred(); | ||
78 | |||
79 | if (this.tolls()[aRequestType].length == 0) { | ||
80 | deferredResult.addCallback(MochiKit.Base.method(this, 'sendMessage', 'knock', {requestType:aRequestType})); | ||
81 | deferredResult.addCallback(MochiKit.Base.method(this, 'setTollCallback')); | ||
82 | } | ||
83 | deferredResult.addCallback(MochiKit.Base.method(this.tolls()[aRequestType], 'pop')); | ||
84 | deferredResult.addCallback(MochiKit.Base.methodcaller('deferredPay')); | ||
85 | deferredResult.addCallback(function(aToll) { | ||
86 | var result; | ||
87 | |||
88 | result = { | ||
89 | parameters: someParameters, | ||
90 | toll: aToll | ||
91 | } | ||
92 | |||
93 | return result; | ||
94 | }); | ||
95 | |||
96 | deferredResult.callback(); | ||
97 | } else { | ||
98 | deferredResult = MochiKit.Async.succeed({parameters:someParameters}); | ||
99 | } | ||
100 | //console.log("<<< Proxy.payToll"); | ||
101 | |||
102 | return deferredResult; | ||
103 | }, | ||
104 | |||
105 | //------------------------------------------------------------------------- | ||
106 | |||
107 | 'addToll': function(aToll) { | ||
108 | //console.log(">>> Proxy.addToll", aToll); | ||
109 | this.tolls()[aToll.requestType()].push(aToll); | ||
110 | //console.log("<<< Proxy.addToll"); | ||
111 | }, | ||
112 | |||
113 | //========================================================================= | ||
114 | |||
115 | 'setTollCallback': function(someParameters) { | ||
116 | //console.log(">>> Proxy.setTollCallback", someParameters); | ||
117 | if (typeof(someParameters['toll']) != 'undefined') { | ||
118 | //console.log("added a new toll", someParameters['toll']); | ||
119 | this.addToll(new Clipperz.PM.Toll(someParameters['toll'])); | ||
120 | } | ||
121 | //console.log("<<< Proxy.setTallCallback", someParameters['result']); | ||
122 | //return someParameters['result']; | ||
123 | return someParameters; | ||
124 | }, | ||
125 | |||
126 | //========================================================================= | ||
127 | |||
128 | 'registration': function (someParameters) { | ||
129 | return this.processMessage('registration', someParameters, 'REGISTER'); | ||
130 | }, | ||
131 | |||
132 | 'handshake': function (someParameters) { | ||
133 | return this.processMessage('handshake', someParameters, 'CONNECT'); | ||
134 | }, | ||
135 | |||
136 | 'message': function (someParameters) { | ||
137 | return this.processMessage('message', someParameters, 'MESSAGE'); | ||
138 | }, | ||
139 | |||
140 | 'logout': function (someParameters) { | ||
141 | return this.processMessage('logout', someParameters, 'MESSAGE'); | ||
142 | }, | ||
143 | |||
144 | //========================================================================= | ||
145 | |||
146 | 'processMessage': function (aFunctionName, someParameters, aRequestType) { | ||
147 | vardeferredResult; | ||
148 | |||
149 | deferredResult = new MochiKit.Async.Deferred(); | ||
150 | deferredResult.addCallback(MochiKit.Base.method(this, 'payToll', aRequestType)); | ||
151 | deferredResult.addCallback(MochiKit.Base.method(this, 'sendMessage', aFunctionName)); | ||
152 | deferredResult.addCallback(MochiKit.Base.method(this, 'setTollCallback')); | ||
153 | deferredResult.callback(someParameters); | ||
154 | |||
155 | return deferredResult; | ||
156 | }, | ||
157 | |||
158 | //========================================================================= | ||
159 | |||
160 | 'sendMessage': function () { | ||
161 | throw Clipperz.Base.exception.AbstractMethod; | ||
162 | }, | ||
163 | |||
164 | //========================================================================= | ||
165 | |||
166 | 'isReadOnly': function () { | ||
167 | return false; | ||
168 | }, | ||
169 | |||
170 | //========================================================================= | ||
171 | __syntaxFix__: "syntax fix" | ||
172 | |||
173 | }); | ||