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/gamma/js/Clipperz/PM/Proxy.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/gamma/js/Clipperz/PM/Proxy.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/PM/Proxy.js | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/Proxy.js b/frontend/gamma/js/Clipperz/PM/Proxy.js new file mode 100644 index 0000000..d90bcb7 --- a/dev/null +++ b/frontend/gamma/js/Clipperz/PM/Proxy.js | |||
@@ -0,0 +1,172 @@ | |||
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 Clipperz.Async.Deferred("Proxy.payToll", {trace:false}); | ||
78 | |||
79 | if (this.tolls()[aRequestType].length == 0) { | ||
80 | deferredResult.addMethod(this, 'sendMessage', 'knock', {requestType:aRequestType}); | ||
81 | deferredResult.addMethod(this, 'setTollCallback'); | ||
82 | } | ||
83 | deferredResult.addMethod(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 | }, | ||
124 | |||
125 | //========================================================================= | ||
126 | |||
127 | 'registration': function (someParameters) { | ||
128 | return this.processMessage('registration', someParameters, 'REGISTER'); | ||
129 | }, | ||
130 | |||
131 | 'handshake': function (someParameters) { | ||
132 | return this.processMessage('handshake', someParameters, 'CONNECT'); | ||
133 | }, | ||
134 | |||
135 | 'message': function (someParameters) { | ||
136 | return this.processMessage('message', someParameters, 'MESSAGE'); | ||
137 | }, | ||
138 | |||
139 | 'logout': function (someParameters) { | ||
140 | return this.processMessage('logout', someParameters, 'MESSAGE'); | ||
141 | }, | ||
142 | |||
143 | //========================================================================= | ||
144 | |||
145 | 'processMessage': function (aFunctionName, someParameters, aRequestType) { | ||
146 | vardeferredResult; | ||
147 | |||
148 | deferredResult = new Clipperz.Async.Deferred("Proxy.processMessage", {trace:false}); | ||
149 | deferredResult.addMethod(this, 'payToll', aRequestType); | ||
150 | deferredResult.addMethod(this, 'sendMessage', aFunctionName); | ||
151 | deferredResult.addMethod(this, 'setTollCallback'); | ||
152 | deferredResult.callback(someParameters); | ||
153 | |||
154 | return deferredResult; | ||
155 | }, | ||
156 | |||
157 | //========================================================================= | ||
158 | |||
159 | 'sendMessage': function () { | ||
160 | throw Clipperz.Base.exception.AbstractMethod; | ||
161 | }, | ||
162 | |||
163 | //========================================================================= | ||
164 | |||
165 | 'isReadOnly': function () { | ||
166 | return false; | ||
167 | }, | ||
168 | |||
169 | //========================================================================= | ||
170 | __syntaxFix__: "syntax fix" | ||
171 | |||
172 | }); | ||