summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2015-02-17 15:49:00 -0330
committerDwayne Boone <dwayne@zeroc.com>2015-02-17 15:49:00 -0330
commitbfb35f122ecb429cf9d869f0331b0899f7b18fe8 (patch)
treef72951c29ecd08d9f34b0c0da47e3056959444ad
parentFixed (ICE-5740) - IcePatch2 has issues with 'large' files. (diff)
downloadice-bfb35f122ecb429cf9d869f0331b0899f7b18fe8.tar.bz2
ice-bfb35f122ecb429cf9d869f0331b0899f7b18fe8.tar.xz
ice-bfb35f122ecb429cf9d869f0331b0899f7b18fe8.zip
ICE-6313 Add Python/Ruby/PHP support for WSEndpointInfo / WSConnectionInfo
-rw-r--r--php/src/IcePHP/Connection.cpp32
-rw-r--r--php/test/Ice/info/Client.php22
-rw-r--r--py/modules/IcePy/ConnectionInfo.cpp95
-rw-r--r--py/modules/IcePy/EndpointInfo.cpp80
-rw-r--r--py/python/Ice.py4
-rw-r--r--py/test/Ice/info/AllTests.py26
-rw-r--r--py/test/Ice/info/TestI.py4
-rw-r--r--rb/src/IceRuby/Connection.cpp52
-rw-r--r--rb/src/IceRuby/Endpoint.cpp21
-rw-r--r--rb/test/Ice/info/AllTests.rb27
10 files changed, 338 insertions, 25 deletions
diff --git a/php/src/IcePHP/Connection.cpp b/php/src/IcePHP/Connection.cpp
index 10f5df4488d..1847dd9124b 100644
--- a/php/src/IcePHP/Connection.cpp
+++ b/php/src/IcePHP/Connection.cpp
@@ -26,6 +26,7 @@ static zend_class_entry* connectionInfoClassEntry = 0;
static zend_class_entry* ipConnectionInfoClassEntry = 0;
static zend_class_entry* tcpConnectionInfoClassEntry = 0;
static zend_class_entry* udpConnectionInfoClassEntry = 0;
+static zend_class_entry* wsConnectionInfoClassEntry = 0;
//
// Ice::Connection support.
@@ -531,6 +532,19 @@ IcePHP::connectionInit(TSRMLS_D)
zend_declare_property_long(udpConnectionInfoClassEntry, STRCAST("mcastPort"), sizeof("mcastPort") - 1, 0,
ZEND_ACC_PUBLIC TSRMLS_CC);
+ //
+ // Register the WSConnectionInfo class.
+ //
+#ifdef ICEPHP_USE_NAMESPACES
+ INIT_NS_CLASS_ENTRY(ce, "Ice", "WSConnectionInfo", NULL);
+#else
+ INIT_CLASS_ENTRY(ce, "Ice_WSConnectionInfo", NULL);
+#endif
+ ce.create_object = handleConnectionInfoAlloc;
+ wsConnectionInfoClassEntry = zend_register_internal_class_ex(&ce, ipConnectionInfoClassEntry, NULL TSRMLS_CC);
+ zend_declare_property_string(wsConnectionInfoClassEntry, STRCAST("headers"), sizeof("headers") - 1,
+ STRCAST(""), ZEND_ACC_PUBLIC TSRMLS_CC);
+
return true;
}
@@ -592,6 +606,24 @@ IcePHP::createConnectionInfo(zval* zv, const Ice::ConnectionInfoPtr& p TSRMLS_DC
add_property_long(zv, STRCAST("mcastPort"), static_cast<long>(info->mcastPort));
}
}
+ else if(Ice::WSConnectionInfoPtr::dynamicCast(p))
+ {
+ Ice::WSConnectionInfoPtr info = Ice::WSConnectionInfoPtr::dynamicCast(p);
+ if((status = object_init_ex(zv, wsConnectionInfoClassEntry)) == SUCCESS)
+ {
+ zval* zmap;
+ MAKE_STD_ZVAL(zmap);
+ AutoDestroy mapDestroyer(zmap);
+ if(createStringMap(zmap, info->headers TSRMLS_CC))
+ {
+ add_property_zval(zv, STRCAST("headers"), zmap);
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
else if(Ice::IPConnectionInfoPtr::dynamicCast(p))
{
status = object_init_ex(zv, ipConnectionInfoClassEntry);
diff --git a/php/test/Ice/info/Client.php b/php/test/Ice/info/Client.php
index 46c800c3b33..1e9b275b064 100644
--- a/php/test/Ice/info/Client.php
+++ b/php/test/Ice/info/Client.php
@@ -40,6 +40,7 @@ function allTests($communicator)
$udpEndpointInfoClass = $NS ? "Ice\\UDPEndpointInfo" : "Ice_UDPEndpointInfo";
$sslEndpointType = 2;
$wsEndpointType = $NS ? constant("Ice\\WSEndpointType") : constant("Ice_WSEndpointType");
+ $wsEndpointInfoClass = $NS ? "Ice\\WSEndpointInfo" : "Ice_WSEndpointInfo";
$wssEndpointType = $NS ? constant("Ice\\WSSEndpointType") : constant("Ice_WSSEndpointType");
$protocolVersionClass = $NS ? "Ice\\ProtocolVersion" : "Ice_ProtocolVersion";
$encodingVersionClass = $NS ? "Ice\\EncodingVersion" : "Ice_EncodingVersion";
@@ -68,8 +69,8 @@ function allTests($communicator)
($ipEndpoint->type() == $wssEndpointType && $ipEndpoint->secure()));
test(($ipEndpoint->type() == $tcpEndpointType && ($ipEndpoint instanceof $tcpEndpointInfoClass)) ||
($ipEndpoint->type() == $sslEndpointType && ($ipEndpoint instanceof $ipEndpointInfoClass)) ||
- ($ipEndpoint->type() == $wsEndpointType && ($ipEndpoint instanceof $ipEndpointInfoClass)) ||
- ($ipEndpoint->type() == $wssEndpointType && ($ipEndpoint instanceof $ipEndpointInfoClass)));
+ ($ipEndpoint->type() == $wsEndpointType && ($ipEndpoint instanceof $wsEndpointInfoClass)) ||
+ ($ipEndpoint->type() == $wssEndpointType && ($ipEndpoint instanceof $wsEndpointInfoClass)));
$udpEndpoint = $endps[1]->getInfo();
test($udpEndpoint instanceof $udpEndpointInfoClass);
@@ -118,6 +119,7 @@ function allTests($communicator)
flush();
{
$ipConnectionInfoClass = $NS ? "Ice\\IPConnectionInfo" : "Ice_IPConnectionInfo";
+ $wsConnectionInfoClass = $NS ? "Ice\\WSConnectionInfo" : "Ice_WSConnectionInfo";
$info = $base->ice_getConnection()->getInfo();
test($info instanceof $ipConnectionInfoClass);
@@ -137,6 +139,22 @@ function allTests($communicator)
test($ctx["localAddress"] == $info->remoteAddress);
test($ctx["remotePort"] == $info->localPort);
test($ctx["localPort"] == $info->remotePort);
+
+ if($base->ice_getConnection()->type() == "ws" || $base->ice_getConnection()->type() == "wss")
+ {
+ test($info instanceof $wsConnectionInfoClass);
+
+ test($info->headers["Upgrade"] == "websocket");
+ test($info->headers["Connection"] == "Upgrade");
+ test($info->headers["Sec-WebSocket-Protocol"] == "ice.zeroc.com");
+ test(isset($info->headers["Sec-WebSocket-Accept"]));
+
+ test($ctx["ws.Upgrade"] == "websocket");
+ test($ctx["ws.Connection"] == "Upgrade");
+ test($ctx["ws.Sec-WebSocket-Protocol"] == "ice.zeroc.com");
+ test($ctx["ws.Sec-WebSocket-Version"] == "13");
+ test(isset($ctx["ws.Sec-WebSocket-Key"]));
+ }
}
echo "ok\n";
diff --git a/py/modules/IcePy/ConnectionInfo.cpp b/py/modules/IcePy/ConnectionInfo.cpp
index 583885382e4..d8c34789b63 100644
--- a/py/modules/IcePy/ConnectionInfo.cpp
+++ b/py/modules/IcePy/ConnectionInfo.cpp
@@ -135,6 +135,32 @@ udpConnectionInfoGetMcastPort(ConnectionInfoObject* self, void* member)
return PyLong_FromLong(info->mcastPort);
}
+#ifdef WIN32
+extern "C"
+#endif
+static PyObject*
+wsConnectionInfoGetHeaders(ConnectionInfoObject* self)
+{
+ Ice::WSConnectionInfoPtr info = Ice::WSConnectionInfoPtr::dynamicCast(*self->connectionInfo);
+ assert(info);
+
+ PyObjectHandle result = PyDict_New();
+ if(result.get())
+ {
+ for(Ice::HeaderDict::iterator p = info->headers.begin(); p != info->headers.end(); ++p)
+ {
+ PyObjectHandle key = createString(p->first);
+ PyObjectHandle val = createString(p->second);
+ if(!val.get() || PyDict_SetItem(result.get(), key.get(), val.get()) < 0)
+ {
+ return 0;
+ }
+ }
+ }
+
+ return result.release();
+}
+
static PyGetSetDef ConnectionInfoGetters[] =
{
{ STRCAST("incoming"), reinterpret_cast<getter>(connectionInfoGetIncoming), 0,
@@ -166,6 +192,13 @@ static PyGetSetDef UDPConnectionInfoGetters[] =
{ 0, 0 } /* sentinel */
};
+static PyGetSetDef WSConnectionInfoGetters[] =
+{
+ { STRCAST("headers"), reinterpret_cast<getter>(wsConnectionInfoGetHeaders), 0,
+ PyDoc_STR(STRCAST("request headers")), 0 },
+ { 0, 0 } /* sentinel */
+};
+
namespace IcePy
{
@@ -357,6 +390,53 @@ PyTypeObject UDPConnectionInfoType =
0, /* tp_is_gc */
};
+PyTypeObject WSConnectionInfoType =
+{
+ /* The ob_type field must be initialized in the module init function
+ * to be portable to Windows without using C++. */
+ PyVarObject_HEAD_INIT(0, 0)
+ STRCAST("IcePy.WSConnectionInfo"),/* tp_name */
+ sizeof(ConnectionInfoObject), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ /* methods */
+ (destructor)connectionInfoDealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_reserved */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ 0, /* tp_methods */
+ 0, /* tp_members */
+ WSConnectionInfoGetters, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ (newfunc)connectionInfoNew, /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+};
+
}
bool
@@ -405,6 +485,17 @@ IcePy::initConnectionInfo(PyObject* module)
return false;
}
+ WSConnectionInfoType.tp_base = &IPConnectionInfoType; // Force inheritance from IPConnectionType.
+ if(PyType_Ready(&WSConnectionInfoType) < 0)
+ {
+ return false;
+ }
+ type = &WSConnectionInfoType; // Necessary to prevent GCC's strict-alias warnings.
+ if(PyModule_AddObject(module, STRCAST("WSConnectionInfo"), reinterpret_cast<PyObject*>(type)) < 0)
+ {
+ return false;
+ }
+
return true;
}
@@ -428,6 +519,10 @@ IcePy::createConnectionInfo(const Ice::ConnectionInfoPtr& connectionInfo)
{
type = &UDPConnectionInfoType;
}
+ else if(Ice::WSConnectionInfoPtr::dynamicCast(connectionInfo))
+ {
+ type = &WSConnectionInfoType;
+ }
else if(Ice::IPConnectionInfoPtr::dynamicCast(connectionInfo))
{
type = &IPConnectionInfoType;
diff --git a/py/modules/IcePy/EndpointInfo.cpp b/py/modules/IcePy/EndpointInfo.cpp
index f175fe85a3b..a712cb81186 100644
--- a/py/modules/IcePy/EndpointInfo.cpp
+++ b/py/modules/IcePy/EndpointInfo.cpp
@@ -198,6 +198,17 @@ udpEndpointInfoGetMcastTtl(EndpointInfoObject* self)
extern "C"
#endif
static PyObject*
+wsEndpointInfoGetResource(EndpointInfoObject* self)
+{
+ Ice::WSEndpointInfoPtr info = Ice::WSEndpointInfoPtr::dynamicCast(*self->endpointInfo);
+ assert(info);
+ return createString(info->resource);
+}
+
+#ifdef WIN32
+extern "C"
+#endif
+static PyObject*
opaqueEndpointInfoGetRawBytes(EndpointInfoObject* self)
{
Ice::OpaqueEndpointInfoPtr info = Ice::OpaqueEndpointInfoPtr::dynamicCast(*self->endpointInfo);
@@ -262,6 +273,13 @@ static PyGetSetDef UDPEndpointInfoGetters[] =
{ 0, 0 } /* sentinel */
};
+static PyGetSetDef WSEndpointInfoGetters[] =
+{
+ { STRCAST("resource"), reinterpret_cast<getter>(wsEndpointInfoGetResource), 0,
+ PyDoc_STR(STRCAST("resource")), 0 },
+ { 0, 0 } /* sentinel */
+};
+
static PyGetSetDef OpaqueEndpointInfoGetters[] =
{
{ STRCAST("rawBytes"), reinterpret_cast<getter>(opaqueEndpointInfoGetRawBytes), 0,
@@ -462,6 +480,53 @@ PyTypeObject UDPEndpointInfoType =
0, /* tp_is_gc */
};
+PyTypeObject WSEndpointInfoType =
+{
+ /* The ob_type field must be initialized in the module init function
+ * to be portable to Windows without using C++. */
+ PyVarObject_HEAD_INIT(0, 0)
+ STRCAST("IcePy.WSEndpointInfo"), /* tp_name */
+ sizeof(EndpointInfoObject), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ /* methods */
+ reinterpret_cast<destructor>(endpointInfoDealloc), /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_reserved */
+ 0, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+ 0, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ 0, /* tp_methods */
+ 0, /* tp_members */
+ WSEndpointInfoGetters, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ reinterpret_cast<newfunc>(endpointInfoNew), /* tp_new */
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+};
+
PyTypeObject OpaqueEndpointInfoType =
{
/* The ob_type field must be initialized in the module init function
@@ -557,6 +622,17 @@ IcePy::initEndpointInfo(PyObject* module)
return false;
}
+ WSEndpointInfoType.tp_base = &IPEndpointInfoType; // Force inheritance from IPEndpointType.
+ if(PyType_Ready(&WSEndpointInfoType) < 0)
+ {
+ return false;
+ }
+ type = &WSEndpointInfoType; // Necessary to prevent GCC's strict-alias warnings.
+ if(PyModule_AddObject(module, STRCAST("WSEndpointInfo"), reinterpret_cast<PyObject*>(type)) < 0)
+ {
+ return false;
+ }
+
OpaqueEndpointInfoType.tp_base = &EndpointInfoType; // Force inheritance from EndpointType.
if(PyType_Ready(&OpaqueEndpointInfoType) < 0)
{
@@ -591,6 +667,10 @@ IcePy::createEndpointInfo(const Ice::EndpointInfoPtr& endpointInfo)
{
type = &UDPEndpointInfoType;
}
+ else if(Ice::WSEndpointInfoPtr::dynamicCast(endpointInfo))
+ {
+ type = &WSEndpointInfoType;
+ }
else if(Ice::OpaqueEndpointInfoPtr::dynamicCast(endpointInfo))
{
type = &OpaqueEndpointInfoType;
diff --git a/py/python/Ice.py b/py/python/Ice.py
index 9c16f27d587..7133fd5956f 100644
--- a/py/python/Ice.py
+++ b/py/python/Ice.py
@@ -458,6 +458,8 @@ del TCPEndpointInfo
TCPEndpointInfo = IcePy.TCPEndpointInfo
del UDPEndpointInfo
UDPEndpointInfo = IcePy.UDPEndpointInfo
+del WSEndpointInfo
+WSEndpointInfo = IcePy.WSEndpointInfo
del OpaqueEndpointInfo
OpaqueEndpointInfo = IcePy.OpaqueEndpointInfo
@@ -472,6 +474,8 @@ del TCPConnectionInfo
TCPConnectionInfo = IcePy.TCPConnectionInfo
del UDPConnectionInfo
UDPConnectionInfo = IcePy.UDPConnectionInfo
+del WSConnectionInfo
+WSConnectionInfo = IcePy.WSConnectionInfo
class ThreadNotification(object):
'''Base class for thread notification callbacks. A subclass must
diff --git a/py/test/Ice/info/AllTests.py b/py/test/Ice/info/AllTests.py
index c8b8ec46bce..43094e7f271 100644
--- a/py/test/Ice/info/AllTests.py
+++ b/py/test/Ice/info/AllTests.py
@@ -32,13 +32,13 @@ def allTests(communicator):
test(ipEndpoint.compress)
test(not ipEndpoint.datagram())
test((ipEndpoint.type() == Ice.TCPEndpointType and not ipEndpoint.secure()) or
- (ipEndpoint.type() == 2 and ipEndpoint.secure()) or # SSL
- (ipEndpoint.type() == 4 and not ipEndpoint.secure()) or # WS
- (ipEndpoint.type() == 5 and ipEndpoint.secure())) # WS
+ (ipEndpoint.type() == Ice.SSLEndpointType and ipEndpoint.secure()) or # SSL
+ (ipEndpoint.type() == Ice.WSEndpointType and not ipEndpoint.secure()) or # WS
+ (ipEndpoint.type() == Ice.WSSEndpointType and ipEndpoint.secure())) # WS
test((ipEndpoint.type() == Ice.TCPEndpointType and isinstance(ipEndpoint, Ice.TCPEndpointInfo)) or
- (ipEndpoint.type() == 2) or # SSL
- (ipEndpoint.type() == 4) or # WS
- (ipEndpoint.type() == 5)) # WSS
+ (ipEndpoint.type() == Ice.SSLEndpointType) or
+ (ipEndpoint.type() == Ice.WSEndpointType and isinstance(ipEndpoint, Ice.WSEndpointInfo)) or
+ (ipEndpoint.type() == Ice.WSSEndpointType and isinstance(ipEndpoint, Ice.WSEndpointInfo)))
udpEndpoint = endps[1].getInfo()
test(isinstance(udpEndpoint, Ice.UDPEndpointInfo))
@@ -148,6 +148,20 @@ def allTests(communicator):
test(ctx["remotePort"] == str(info.localPort))
test(ctx["localPort"] == str(info.remotePort))
+ if(base.ice_getConnection().type() == "ws" or base.ice_getConnection().type() == "wss"):
+ test(isinstance(info, Ice.WSConnectionInfo))
+
+ test(info.headers["Upgrade"] == "websocket")
+ test(info.headers["Connection"] == "Upgrade")
+ test(info.headers["Sec-WebSocket-Protocol"] == "ice.zeroc.com")
+ test("Sec-WebSocket-Accept" in info.headers);
+
+ test(ctx["ws.Upgrade"] == "websocket")
+ test(ctx["ws.Connection"] == "Upgrade")
+ test(ctx["ws.Sec-WebSocket-Protocol"] == "ice.zeroc.com")
+ test(ctx["ws.Sec-WebSocket-Version"] == "13")
+ test("ws.Sec-WebSocket-Key" in ctx)
+
print("ok")
testIntf.shutdown()
diff --git a/py/test/Ice/info/TestI.py b/py/test/Ice/info/TestI.py
index e563c52c764..c0b266a7ba4 100644
--- a/py/test/Ice/info/TestI.py
+++ b/py/test/Ice/info/TestI.py
@@ -62,4 +62,8 @@ class MyDerivedClassI(Test.TestIntf):
ctx["remoteAddress"] = info.remoteAddress
ctx["remotePort"] = str(info.remotePort)
+ if isinstance(info, Ice.WSConnectionInfo):
+ for key, value in info.headers.items():
+ ctx["ws." + key] = value
+
return ctx
diff --git a/rb/src/IceRuby/Connection.cpp b/rb/src/IceRuby/Connection.cpp
index 93f31c0868d..be856f508e2 100644
--- a/rb/src/IceRuby/Connection.cpp
+++ b/rb/src/IceRuby/Connection.cpp
@@ -22,6 +22,7 @@ static VALUE _connectionInfoClass;
static VALUE _ipConnectionInfoClass;
static VALUE _tcpConnectionInfoClass;
static VALUE _udpConnectionInfoClass;
+static VALUE _wsConnectionInfoClass;
// **********************************************************************
// Connection
@@ -295,6 +296,25 @@ IceRuby::createConnectionInfo(const Ice::ConnectionInfoPtr& p)
rb_ivar_set(info, rb_intern("@mcastAddress"), createString(udp->mcastAddress));
rb_ivar_set(info, rb_intern("@mcastPort"), INT2FIX(udp->mcastPort));
}
+ else if(Ice::WSConnectionInfoPtr::dynamicCast(p))
+ {
+ info = Data_Wrap_Struct(_wsConnectionInfoClass, 0, IceRuby_ConnectionInfo_free, new Ice::ConnectionInfoPtr(p));
+
+ Ice::WSConnectionInfoPtr ws = Ice::WSConnectionInfoPtr::dynamicCast(p);
+ rb_ivar_set(info, rb_intern("@localAddress"), createString(ws->localAddress));
+ rb_ivar_set(info, rb_intern("@localPort"), INT2FIX(ws->localPort));
+ rb_ivar_set(info, rb_intern("@remoteAddress"), createString(ws->remoteAddress));
+ rb_ivar_set(info, rb_intern("@remotePort"), INT2FIX(ws->remotePort));
+
+ volatile VALUE result = callRuby(rb_hash_new);
+ for(Ice::HeaderDict::const_iterator q = ws->headers.begin(); q != ws->headers.end(); ++q)
+ {
+ volatile VALUE key = createString(q->first);
+ volatile VALUE value = createString(q->second);
+ callRuby(rb_hash_aset, result, key, value);
+ }
+ rb_ivar_set(info, rb_intern("@headers"), result);
+ }
else if(Ice::IPConnectionInfoPtr::dynamicCast(p))
{
info = Data_Wrap_Struct(_ipConnectionInfoClass, 0, IceRuby_ConnectionInfo_free, new Ice::ConnectionInfoPtr(p));
@@ -345,10 +365,10 @@ IceRuby::initConnection(VALUE iceModule)
_connectionInfoClass = rb_define_class_under(iceModule, "ConnectionInfo", rb_cObject);
//
- // Instance members.
+ // Instance members.
//
- rb_define_attr(_connectionInfoClass, "incoming", 1, 0);
- rb_define_attr(_connectionInfoClass, "adapterName", 1, 0);
+ rb_define_attr(_connectionInfoClass, "incoming", 1, 0);
+ rb_define_attr(_connectionInfoClass, "adapterName", 1, 0);
//
// IPConnectionInfo
@@ -356,12 +376,12 @@ IceRuby::initConnection(VALUE iceModule)
_ipConnectionInfoClass = rb_define_class_under(iceModule, "IPConnectionInfo", _connectionInfoClass);
//
- // Instance members.
+ // Instance members.
//
- rb_define_attr(_ipConnectionInfoClass, "localAddress", 1, 0);
- rb_define_attr(_ipConnectionInfoClass, "localPort", 1, 0);
- rb_define_attr(_ipConnectionInfoClass, "remoteAddress", 1, 0);
- rb_define_attr(_ipConnectionInfoClass, "remotePort", 1, 0);
+ rb_define_attr(_ipConnectionInfoClass, "localAddress", 1, 0);
+ rb_define_attr(_ipConnectionInfoClass, "localPort", 1, 0);
+ rb_define_attr(_ipConnectionInfoClass, "remoteAddress", 1, 0);
+ rb_define_attr(_ipConnectionInfoClass, "remotePort", 1, 0);
//
// TCPConnectionInfo
@@ -374,8 +394,18 @@ IceRuby::initConnection(VALUE iceModule)
_udpConnectionInfoClass = rb_define_class_under(iceModule, "UDPConnectionInfo", _ipConnectionInfoClass);
//
- // Instance members.
+ // Instance members.
+ //
+ rb_define_attr(_udpConnectionInfoClass, "mcastAddress", 1, 0);
+ rb_define_attr(_udpConnectionInfoClass, "mcastPort", 1, 0);
+
+ //
+ // WSConnectionInfo
+ //
+ _wsConnectionInfoClass = rb_define_class_under(iceModule, "WSConnectionInfo", _ipConnectionInfoClass);
+
+ //
+ // Instance members.
//
- rb_define_attr(_udpConnectionInfoClass, "mcastAddress", 1, 0);
- rb_define_attr(_udpConnectionInfoClass, "mcastPort", 1, 0);
+ //rb_define_attr(_wsConnectionInfoClass, "headers", 1, 0);
}
diff --git a/rb/src/IceRuby/Endpoint.cpp b/rb/src/IceRuby/Endpoint.cpp
index e2a31f0242e..c44585c5db8 100644
--- a/rb/src/IceRuby/Endpoint.cpp
+++ b/rb/src/IceRuby/Endpoint.cpp
@@ -20,6 +20,7 @@ static VALUE _endpointInfoClass;
static VALUE _ipEndpointInfoClass;
static VALUE _tcpEndpointInfoClass;
static VALUE _udpEndpointInfoClass;
+static VALUE _wsEndpointInfoClass;
static VALUE _opaqueEndpointInfoClass;
// **********************************************************************
@@ -149,6 +150,16 @@ IceRuby::createEndpointInfo(const Ice::EndpointInfoPtr& p)
rb_ivar_set(info, rb_intern("@mcastInterface"), createString(udp->mcastInterface));
rb_ivar_set(info, rb_intern("@mcastTtl"), INT2FIX(udp->mcastTtl));
}
+ else if(Ice::WSEndpointInfoPtr::dynamicCast(p))
+ {
+ info = Data_Wrap_Struct(_wsEndpointInfoClass, 0, IceRuby_EndpointInfo_free, new Ice::EndpointInfoPtr(p));
+
+ Ice::WSEndpointInfoPtr ws = Ice::WSEndpointInfoPtr::dynamicCast(p);
+ rb_ivar_set(info, rb_intern("@host"), createString(ws->host));
+ rb_ivar_set(info, rb_intern("@port"), INT2FIX(ws->port));
+ rb_ivar_set(info, rb_intern("@sourceAddress"), createString(ws->sourceAddress));
+ rb_ivar_set(info, rb_intern("@resource"), createString(ws->resource));
+ }
else if(Ice::OpaqueEndpointInfoPtr::dynamicCast(p))
{
info = Data_Wrap_Struct(_opaqueEndpointInfoClass, 0, IceRuby_EndpointInfo_free, new Ice::EndpointInfoPtr(p));
@@ -293,6 +304,16 @@ IceRuby::initEndpoint(VALUE iceModule)
rb_define_attr(_udpEndpointInfoClass, "mcastTtl", 1, 0);
//
+ // WSEndpointInfo
+ //
+ _wsEndpointInfoClass = rb_define_class_under(iceModule, "WSEndpointInfo", _ipEndpointInfoClass);
+
+ //
+ // Instance members.
+ //
+ rb_define_attr(_wsEndpointInfoClass, "resource", 1, 0);
+
+ //
// OpaqueEndpointInfo
//
_opaqueEndpointInfoClass = rb_define_class_under(iceModule, "OpaqueEndpointInfo", _endpointInfoClass);
diff --git a/rb/test/Ice/info/AllTests.rb b/rb/test/Ice/info/AllTests.rb
index 1a81b1337f3..e0847a529bf 100644
--- a/rb/test/Ice/info/AllTests.rb
+++ b/rb/test/Ice/info/AllTests.rb
@@ -26,13 +26,13 @@ def allTests(communicator)
test(ipEndpoint.compress)
test(!ipEndpoint.datagram())
test((ipEndpoint.type() == Ice::TCPEndpointType && !ipEndpoint.secure()) ||
- (ipEndpoint.type() == 2 && ipEndpoint.secure()) ||
- (ipEndpoint.type() == 4 && !ipEndpoint.secure()) ||
- (ipEndpoint.type() == 5 && ipEndpoint.secure()))
+ (ipEndpoint.type() == Ice::SSLEndpointType && ipEndpoint.secure()) ||
+ (ipEndpoint.type() == Ice::WSEndpointType && !ipEndpoint.secure()) ||
+ (ipEndpoint.type() == Ice::WSSEndpointType && ipEndpoint.secure()))
test((ipEndpoint.type() == Ice::TCPEndpointType && ipEndpoint.is_a?(Ice::TCPEndpointInfo)) ||
- (ipEndpoint.type() == 2) ||
- (ipEndpoint.type() == 4) ||
- (ipEndpoint.type() == 5))
+ (ipEndpoint.type() == Ice::SSLEndpointType) ||
+ (ipEndpoint.type() == Ice::WSEndpointType && ipEndpoint.is_a?(Ice::WSEndpointInfo)) ||
+ (ipEndpoint.type() == Ice::WSSEndpointType && ipEndpoint.is_a?(Ice::WSEndpointInfo)))
udpEndpoint = endps[1].getInfo()
test(udpEndpoint.is_a?(Ice::UDPEndpointInfo));
@@ -97,6 +97,21 @@ def allTests(communicator)
test(ctx["remotePort"] == info.localPort.to_s())
test(ctx["localPort"] == info.remotePort.to_s())
+ if base.ice_getConnection().type() == "ws" || base.ice_getConnection().type() == "wss"
+ test(info.is_a?(Ice::WSConnectionInfo))
+
+ test(info.headers["Upgrade"] == "websocket")
+ test(info.headers["Connection"] == "Upgrade")
+ test(info.headers["Sec-WebSocket-Protocol"] == "ice.zeroc.com")
+ test(info.headers.has_key?("Sec-WebSocket-Accept"))
+
+ test(ctx["ws.Upgrade"] == "websocket")
+ test(ctx["ws.Connection"] == "Upgrade")
+ test(ctx["ws.Sec-WebSocket-Protocol"] == "ice.zeroc.com")
+ test(ctx["ws.Sec-WebSocket-Version"] == "13")
+ test(ctx.has_key?("ws.Sec-WebSocket-Key"))
+ end
+
puts "ok"
testIntf.shutdown()