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 | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/Proxy.js b/frontend/gamma/js/Clipperz/PM/Proxy.js index 190bffd..a5eaae6 100644 --- a/frontend/gamma/js/Clipperz/PM/Proxy.js +++ b/frontend/gamma/js/Clipperz/PM/Proxy.js | |||
@@ -1,169 +1,161 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer to http://www.clipperz.com. |
9 | 8 | ||
10 | * Clipperz Community Edition is free software: you can redistribute | 9 | * Clipperz is free software: you can redistribute it and/or modify it |
11 | it and/or modify it under the terms of the GNU Affero General Public | 10 | under the terms of the GNU Affero General Public License as published |
12 | License as published by the Free Software Foundation, either version | 11 | by the Free Software Foundation, either version 3 of the License, or |
13 | 3 of the License, or (at your option) any later version. | 12 | (at your option) any later version. |
14 | 13 | ||
15 | * Clipperz Community Edition is distributed in the hope that it will | 14 | * Clipperz is distributed in the hope that it will be useful, but |
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. | 17 | See the GNU Affero General Public License for more details. |
19 | 18 | ||
20 | * You should have received a copy of the GNU Affero General Public | 19 | * You should have received a copy of the GNU Affero General Public |
21 | License along with Clipperz Community Edition. If not, see | 20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. |
22 | <http://www.gnu.org/licenses/>. | ||
23 | 21 | ||
24 | */ | 22 | */ |
25 | 23 | ||
26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 24 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | 25 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } |
28 | 26 | ||
29 | //============================================================================= | 27 | //============================================================================= |
30 | 28 | ||
31 | Clipperz.PM.Proxy = function(args) { | 29 | Clipperz.PM.Proxy = function(args) { |
32 | args = args || {}; | 30 | args = args || {}; |
33 | 31 | ||
34 | this._shouldPayTolls = args.shouldPayTolls || false; | 32 | this._shouldPayTolls = args.shouldPayTolls || false; |
35 | 33 | ||
36 | this._tolls = { | 34 | this._tolls = { |
37 | 'CONNECT':[], | 35 | 'CONNECT':[], |
38 | 'REGISTER':[], | 36 | 'REGISTER':[], |
39 | 'MESSAGE':[] | 37 | 'MESSAGE':[] |
40 | }; | 38 | }; |
41 | 39 | ||
42 | if (args.isDefault === true) { | 40 | if (args.isDefault === true) { |
43 | Clipperz.PM.Proxy.defaultProxy = this; | 41 | Clipperz.PM.Proxy.defaultProxy = this; |
44 | } | 42 | } |
45 | 43 | ||
46 | return this; | 44 | return this; |
47 | } | 45 | } |
48 | 46 | ||
49 | Clipperz.PM.Proxy.prototype = MochiKit.Base.update(null, { | 47 | Clipperz.PM.Proxy.prototype = MochiKit.Base.update(null, { |
50 | 48 | ||
51 | 'toString': function() { | 49 | 'toString': function() { |
52 | return "Clipperz.PM.Proxy"; | 50 | return "Clipperz.PM.Proxy"; |
53 | }, | 51 | }, |
54 | 52 | ||
55 | //========================================================================= | 53 | //========================================================================= |
56 | 54 | ||
57 | 'shouldPayTolls': function() { | 55 | 'shouldPayTolls': function() { |
58 | return this._shouldPayTolls; | 56 | return this._shouldPayTolls; |
59 | }, | 57 | }, |
60 | 58 | ||
61 | //------------------------------------------------------------------------- | 59 | //------------------------------------------------------------------------- |
62 | 60 | ||
63 | 'tolls': function() { | 61 | 'tolls': function() { |
64 | return this._tolls; | 62 | return this._tolls; |
65 | }, | 63 | }, |
66 | 64 | ||
67 | //------------------------------------------------------------------------- | 65 | //------------------------------------------------------------------------- |
68 | 66 | ||
69 | 'payToll': function(aRequestType, someParameters) { | 67 | 'payToll': function(aRequestType, someParameters) { |
70 | vardeferredResult; | 68 | vardeferredResult; |
71 | 69 | ||
72 | //console.log(">>> Proxy.payToll", aRequestType, someParameters); | ||
73 | if (this.shouldPayTolls()) { | 70 | if (this.shouldPayTolls()) { |
74 | deferredResult = new Clipperz.Async.Deferred("Proxy.payToll", {trace:false}); | 71 | deferredResult = new Clipperz.Async.Deferred("Proxy.payToll", {trace:false}); |
75 | 72 | ||
76 | if (this.tolls()[aRequestType].length == 0) { | 73 | if (this.tolls()[aRequestType].length == 0) { |
77 | deferredResult.addMethod(this, 'sendMessage', 'knock', {requestType:aRequestType}); | 74 | deferredResult.addMethod(this, 'sendMessage', 'knock', {requestType:aRequestType}); |
78 | deferredResult.addMethod(this, 'setTollCallback'); | 75 | deferredResult.addMethod(this, 'setTollCallback'); |
79 | } | 76 | } |
80 | deferredResult.addMethod(this.tolls()[aRequestType], 'pop'); | 77 | deferredResult.addMethod(this.tolls()[aRequestType], 'pop'); |
81 | deferredResult.addCallback(MochiKit.Base.methodcaller('deferredPay')); | 78 | deferredResult.addCallback(MochiKit.Base.methodcaller('deferredPay')); |
82 | deferredResult.addCallback(function(aToll) { | 79 | deferredResult.addCallback(function(aToll) { |
83 | var result; | 80 | var result; |
84 | 81 | ||
85 | result = { | 82 | result = { |
86 | parameters: someParameters, | 83 | parameters: someParameters, |
87 | toll: aToll | 84 | toll: aToll |
88 | } | 85 | } |
89 | 86 | ||
90 | return result; | 87 | return result; |
91 | }); | 88 | }); |
92 | 89 | ||
93 | deferredResult.callback(); | 90 | deferredResult.callback(); |
94 | } else { | 91 | } else { |
95 | deferredResult = MochiKit.Async.succeed({parameters:someParameters}); | 92 | deferredResult = MochiKit.Async.succeed({parameters:someParameters}); |
96 | } | 93 | } |
97 | //console.log("<<< Proxy.payToll"); | ||
98 | 94 | ||
99 | return deferredResult; | 95 | return deferredResult; |
100 | }, | 96 | }, |
101 | 97 | ||
102 | //------------------------------------------------------------------------- | 98 | //------------------------------------------------------------------------- |
103 | 99 | ||
104 | 'addToll': function(aToll) { | 100 | 'addToll': function(aToll) { |
105 | //console.log(">>> Proxy.addToll", aToll); | ||
106 | this.tolls()[aToll.requestType()].push(aToll); | 101 | this.tolls()[aToll.requestType()].push(aToll); |
107 | //console.log("<<< Proxy.addToll"); | ||
108 | }, | 102 | }, |
109 | 103 | ||
110 | //========================================================================= | 104 | //========================================================================= |
111 | 105 | ||
112 | 'setTollCallback': function(someParameters) { | 106 | 'setTollCallback': function(someParameters) { |
113 | //console.log(">>> Proxy.setTollCallback", someParameters); | ||
114 | if (typeof(someParameters['toll']) != 'undefined') { | 107 | if (typeof(someParameters['toll']) != 'undefined') { |
115 | //console.log("added a new toll", someParameters['toll']); | ||
116 | this.addToll(new Clipperz.PM.Toll(someParameters['toll'])); | 108 | this.addToll(new Clipperz.PM.Toll(someParameters['toll'])); |
117 | } | 109 | } |
118 | //console.log("<<< Proxy.setTallCallback", someParameters['result']); | 110 | |
119 | return someParameters['result']; | 111 | return someParameters['result']; |
120 | }, | 112 | }, |
121 | 113 | ||
122 | //========================================================================= | 114 | //========================================================================= |
123 | 115 | ||
124 | 'registration': function (someParameters) { | 116 | 'registration': function (someParameters) { |
125 | return this.processMessage('registration', someParameters, 'REGISTER'); | 117 | return this.processMessage('registration', someParameters, 'REGISTER'); |
126 | }, | 118 | }, |
127 | 119 | ||
128 | 'handshake': function (someParameters) { | 120 | 'handshake': function (someParameters) { |
129 | return this.processMessage('handshake', someParameters, 'CONNECT'); | 121 | return this.processMessage('handshake', someParameters, 'CONNECT'); |
130 | }, | 122 | }, |
131 | 123 | ||
132 | 'message': function (someParameters) { | 124 | 'message': function (someParameters) { |
133 | return this.processMessage('message', someParameters, 'MESSAGE'); | 125 | return this.processMessage('message', someParameters, 'MESSAGE'); |
134 | }, | 126 | }, |
135 | 127 | ||
136 | 'logout': function (someParameters) { | 128 | 'logout': function (someParameters) { |
137 | return this.processMessage('logout', someParameters, 'MESSAGE'); | 129 | return this.processMessage('logout', someParameters, 'MESSAGE'); |
138 | }, | 130 | }, |
139 | 131 | ||
140 | //========================================================================= | 132 | //========================================================================= |
141 | 133 | ||
142 | 'processMessage': function (aFunctionName, someParameters, aRequestType) { | 134 | 'processMessage': function (aFunctionName, someParameters, aRequestType) { |
143 | vardeferredResult; | 135 | vardeferredResult; |
144 | 136 | ||
145 | deferredResult = new Clipperz.Async.Deferred("Proxy.processMessage", {trace:false}); | 137 | deferredResult = new Clipperz.Async.Deferred("Proxy.processMessage", {trace:false}); |
146 | deferredResult.addMethod(this, 'payToll', aRequestType); | 138 | deferredResult.addMethod(this, 'payToll', aRequestType); |
147 | deferredResult.addMethod(this, 'sendMessage', aFunctionName); | 139 | deferredResult.addMethod(this, 'sendMessage', aFunctionName); |
148 | deferredResult.addMethod(this, 'setTollCallback'); | 140 | deferredResult.addMethod(this, 'setTollCallback'); |
149 | deferredResult.callback(someParameters); | 141 | deferredResult.callback(someParameters); |
150 | 142 | ||
151 | return deferredResult; | 143 | return deferredResult; |
152 | }, | 144 | }, |
153 | 145 | ||
154 | //========================================================================= | 146 | //========================================================================= |
155 | 147 | ||
156 | 'sendMessage': function () { | 148 | 'sendMessage': function () { |
157 | throw Clipperz.Base.exception.AbstractMethod; | 149 | throw Clipperz.Base.exception.AbstractMethod; |
158 | }, | 150 | }, |
159 | 151 | ||
160 | //========================================================================= | 152 | //========================================================================= |
161 | 153 | ||
162 | 'isReadOnly': function () { | 154 | 'isReadOnly': function () { |
163 | return false; | 155 | return false; |
164 | }, | 156 | }, |
165 | 157 | ||
166 | //========================================================================= | 158 | //========================================================================= |
167 | __syntaxFix__: "syntax fix" | 159 | __syntaxFix__: "syntax fix" |
168 | 160 | ||
169 | }); | 161 | }); |