summaryrefslogtreecommitdiff
path: root/js/src/Ice/WSEndpoint.js
blob: 9d86831fa3c948435ee8f31871fa483b00e240e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
// **********************************************************************
//
// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

var Ice = require("../Ice/ModuleRegistry").Ice;

Ice.__M.require(module,
    [
        "../Ice/Class",
        "../Ice/HashUtil",
        "../Ice/StringUtil",
        "../Ice/EndpointI",
        "../Ice/LocalException",
        "../Ice/WSTransceiver",
        "../Ice/EndpointInfo"
    ]);
var IceSSL = Ice.__M.module("IceSSL");

var HashUtil = Ice.HashUtil;
var StringUtil = Ice.StringUtil;
var EndpointI = Ice.EndpointI;
var Class = Ice.Class;

var WSEndpoint = Class(EndpointI, {
    __init__: function(instance, del, re)
    {
        this._instance = instance;
        this._delegate = del;
        this._resource = re || "/";
    },
    getInfo: function()
    {
        var info = this._delegate.secure() ? new IceSSL.WSSEndpointInfo() : new Ice.WSEndpointInfo();
        info.resource = this._resource;
        this._delegate.fillEndpointInfo(info);
        return info;
    },
    type: function()
    {
        return this._delegate.type();
    },
    protocol: function()
    {
        return this._delegate.protocol();
    },
    streamWrite: function(s)
    {
        s.startWriteEncaps();
        this._delegate.streamWriteImpl(s);
        s.writeString(this._resource);
        s.endWriteEncaps();
    },
    timeout: function()
    {
        return this._delegate.timeout();
    },
    changeTimeout: function(timeout)
    {
        if(timeout === this._delegate.timeout())
        {
            return this;
        }
        else
        {
            return new WSEndpoint(this._instance, this._delegate.changeTimeout(timeout), this._resource);
        }
    },
    changeConnectionId: function(connectionId)
    {
        if(connectionId === this._delegate.connectionId())
        {
            return this;
        }
        else
        {
            return new WSEndpoint(this._instance, this._delegate.changeConnectionId(connectionId), this._resource);
        }
    },
    compress: function()
    {
        return this._delegate.compress();
    },
    changeCompress: function(compress)
    {
        if(compress === this._delegate.compress())
        {
            return this;
        }
        else
        {
            return new WSEndpoint(this._instance, this._delegate.changeCompress(compress), this._resource);
        }
    },
    datagram: function()
    {
        return this._delegate.datagram();
    },
    secure: function()
    {
        return this._delegate.secure();
    },
    connect: function()
    {
        return Ice.WSTransceiver.createOutgoing(this._instance,
                                                this._delegate.secure(),
                                                this._delegate.getAddress(),
                                                this._resource);
    },
    hashCode: function()
    {
        if(this._hashCode === undefined)
        {
            this._hashCode = this._delegate.hashCode();
            this._hashCode = HashUtil.addString(this._hashCode, this._resource);
        }
        return this._hashCode;
    },
    compareTo: function(p)
    {
        if(this === p)
        {
            return 0;
        }

        if(p === null)
        {
            return 1;
        }

        if(!(p instanceof WSEndpoint))
        {
            return this.type() < p.type() ? -1 : 1;
        }

        var r = this._delegate.compareTo(p._delegate);
        if(r !== 0)
        {
            return r;
        }

        if(this._resource !== p._resource)
        {
            return this._resource < p._resource ? -1 : 1;
        }

        return 0;
    },
    options: function()
    {
        //
        // WARNING: Certain features, such as proxy validation in Glacier2,
        // depend on the format of proxy strings. Changes to toString() and
        // methods called to generate parts of the reference string could break
        // these features. Please review for all features that depend on the
        // format of proxyToString() before changing this and related code.
        //
        var s = this._delegate.options();

        if(this._resource !== null && this._resource.length > 0)
        {
            s += " -r ";
            s += (this._resource.indexOf(':') !== -1) ? ("\"" + this._resource + "\"") : this._resource;
        }

        return s;
    },
    toConnectorString: function()
    {
        return this._delegate.toConnectorString();
    },
    initWithStream: function(s)
    {
        this._resource = s.readString();
    },
    checkOption: function(option, argument, endpoint)
    {
        if(option === "-r")
        {
            if(argument === null)
            {
                throw new Ice.EndpointParseException("no argument provided for -r option in endpoint " + endpoint);
            }
            this._resource = argument;
        }
        else
        {
            return false;
        }
        return true;
    },
});

if(typeof(Ice.WSTransceiver) !== "undefined")
{
    WSEndpoint.prototype.connectable = function()
    {
        return true;
    };
}
else
{
    WSEndpoint.prototype.connectable = function()
    {
        return false;
    };
}

Ice.WSEndpoint = WSEndpoint;
exports.Ice = Ice;