summaryrefslogtreecommitdiff
path: root/php/src/IcePHP/Connection.cpp
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2009-10-21 15:47:07 -0700
committerMark Spruiell <mes@zeroc.com>2009-10-21 15:47:07 -0700
commit439bbccae66fc9e41f10c8c73971abdf6821086f (patch)
treea5a338b49cb01820ac59dd6b30ee6ade8d74f557 /php/src/IcePHP/Connection.cpp
parentFixed Windows compile error (diff)
downloadice-439bbccae66fc9e41f10c8c73971abdf6821086f.tar.bz2
ice-439bbccae66fc9e41f10c8c73971abdf6821086f.tar.xz
ice-439bbccae66fc9e41f10c8c73971abdf6821086f.zip
- Implementing ConnectionInfo/EndpointInfo in PHP
- Changing test/Ice/info to use separate client & server - Updating release notes for IceSSL ConnectionInfo
Diffstat (limited to 'php/src/IcePHP/Connection.cpp')
-rw-r--r--php/src/IcePHP/Connection.cpp251
1 files changed, 233 insertions, 18 deletions
diff --git a/php/src/IcePHP/Connection.cpp b/php/src/IcePHP/Connection.cpp
index 6049562262a..d658a80139a 100644
--- a/php/src/IcePHP/Connection.cpp
+++ b/php/src/IcePHP/Connection.cpp
@@ -8,6 +8,7 @@
// **********************************************************************
#include <Connection.h>
+#include <Endpoint.h>
#include <Util.h>
using namespace std;
@@ -18,21 +19,27 @@ ZEND_EXTERN_MODULE_GLOBALS(ice)
//
// Class entries represent the PHP class implementations we have registered.
//
-namespace IcePHP
-{
-zend_class_entry* connectionClassEntry = 0;
-}
+static zend_class_entry* connectionClassEntry = 0;
+
+static zend_class_entry* connectionInfoClassEntry = 0;
+static zend_class_entry* ipConnectionInfoClassEntry = 0;
+static zend_class_entry* tcpConnectionInfoClassEntry = 0;
+static zend_class_entry* udpConnectionInfoClassEntry = 0;
//
// Ice::Connection support.
//
-static zend_object_handlers _handlers;
+static zend_object_handlers _connectionHandlers;
+static zend_object_handlers _connectionInfoHandlers;
extern "C"
{
-static zend_object_value handleAlloc(zend_class_entry* TSRMLS_DC);
-static void handleFreeStorage(void* TSRMLS_DC);
-static int handleCompare(zval*, zval* TSRMLS_DC);
+static zend_object_value handleConnectionAlloc(zend_class_entry* TSRMLS_DC);
+static void handleConnectionFreeStorage(void* TSRMLS_DC);
+static int handleConnectionCompare(zval*, zval* TSRMLS_DC);
+
+static zend_object_value handleConnectionInfoAlloc(zend_class_entry* TSRMLS_DC);
+static void handleConnectionInfoFreeStorage(void* TSRMLS_DC);
}
ZEND_METHOD(Ice_Connection, __construct)
@@ -84,6 +91,30 @@ ZEND_METHOD(Ice_Connection, close)
}
}
+ZEND_METHOD(Ice_Connection, getEndpoint)
+{
+ if(ZEND_NUM_ARGS() > 0)
+ {
+ WRONG_PARAM_COUNT;
+ }
+
+ Ice::ConnectionPtr _this = Wrapper<Ice::ConnectionPtr>::value(getThis() TSRMLS_CC);
+ assert(_this);
+
+ try
+ {
+ if(!createEndpoint(return_value, _this->getEndpoint() TSRMLS_CC))
+ {
+ RETURN_NULL();
+ }
+ }
+ catch(const IceUtil::Exception& ex)
+ {
+ throwException(ex TSRMLS_CC);
+ RETURN_NULL();
+ }
+}
+
ZEND_METHOD(Ice_Connection, flushBatchRequests)
{
if(ZEND_NUM_ARGS() > 0)
@@ -154,19 +185,45 @@ ZEND_METHOD(Ice_Connection, toString)
ZEND_MN(Ice_Connection___toString)(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
+ZEND_METHOD(Ice_Connection, getInfo)
+{
+ if(ZEND_NUM_ARGS() != 0)
+ {
+ WRONG_PARAM_COUNT;
+ }
+
+ Ice::ConnectionPtr _this = Wrapper<Ice::ConnectionPtr>::value(getThis() TSRMLS_CC);
+ assert(_this);
+
+ try
+ {
+ Ice::ConnectionInfoPtr info = _this->getInfo();
+ if(!createConnectionInfo(return_value, _this->getInfo() TSRMLS_CC))
+ {
+ RETURN_NULL();
+ }
+ }
+ catch(const IceUtil::Exception& ex)
+ {
+ throwException(ex TSRMLS_CC);
+ RETURN_NULL();
+ }
+}
+
#ifdef _WIN32
extern "C"
#endif
static zend_object_value
-handleAlloc(zend_class_entry* ce TSRMLS_DC)
+handleConnectionAlloc(zend_class_entry* ce TSRMLS_DC)
{
zend_object_value result;
Wrapper<Ice::ConnectionPtr>* obj = Wrapper<Ice::ConnectionPtr>::create(ce TSRMLS_CC);
assert(obj);
- result.handle = zend_objects_store_put(obj, 0, (zend_objects_free_object_storage_t)handleFreeStorage, 0 TSRMLS_CC);
- result.handlers = &_handlers;
+ result.handle = zend_objects_store_put(obj, 0, (zend_objects_free_object_storage_t)handleConnectionFreeStorage,
+ 0 TSRMLS_CC);
+ result.handlers = &_connectionHandlers;
return result;
}
@@ -175,7 +232,7 @@ handleAlloc(zend_class_entry* ce TSRMLS_DC)
extern "C"
#endif
static void
-handleFreeStorage(void* p TSRMLS_DC)
+handleConnectionFreeStorage(void* p TSRMLS_DC)
{
Wrapper<Ice::ConnectionPtr>* obj = static_cast<Wrapper<Ice::ConnectionPtr>*>(p);
delete obj->ptr;
@@ -186,7 +243,7 @@ handleFreeStorage(void* p TSRMLS_DC)
extern "C"
#endif
static int
-handleCompare(zval* zobj1, zval* zobj2 TSRMLS_DC)
+handleConnectionCompare(zval* zobj1, zval* zobj2 TSRMLS_DC)
{
//
// PHP guarantees that the objects have the same class.
@@ -218,18 +275,63 @@ static function_entry _interfaceMethods[] =
{
{0, 0, 0}
};
-static function_entry _classMethods[] =
+static function_entry _connectionClassMethods[] =
{
ZEND_ME(Ice_Connection, __construct, NULL, ZEND_ACC_PRIVATE|ZEND_ACC_CTOR)
ZEND_ME(Ice_Connection, __toString, NULL, ZEND_ACC_PUBLIC)
ZEND_ME(Ice_Connection, close, NULL, ZEND_ACC_PUBLIC)
+ ZEND_ME(Ice_Connection, getEndpoint, NULL, ZEND_ACC_PUBLIC)
ZEND_ME(Ice_Connection, flushBatchRequests, NULL, ZEND_ACC_PUBLIC)
ZEND_ME(Ice_Connection, type, NULL, ZEND_ACC_PUBLIC)
ZEND_ME(Ice_Connection, timeout, NULL, ZEND_ACC_PUBLIC)
ZEND_ME(Ice_Connection, toString, NULL, ZEND_ACC_PUBLIC)
+ ZEND_ME(Ice_Connection, getInfo, NULL, ZEND_ACC_PUBLIC)
+ {0, 0, 0}
+};
+
+ZEND_METHOD(Ice_ConnectionInfo, __construct)
+{
+ runtimeError("ConnectionInfo cannot be instantiated" TSRMLS_CC);
+}
+
+//
+// Predefined methods for ConnectionInfo.
+//
+static function_entry _connectionInfoClassMethods[] =
+{
+ ZEND_ME(Ice_ConnectionInfo, __construct, NULL, ZEND_ACC_PRIVATE|ZEND_ACC_CTOR)
{0, 0, 0}
};
+#ifdef _WIN32
+extern "C"
+#endif
+static zend_object_value
+handleConnectionInfoAlloc(zend_class_entry* ce TSRMLS_DC)
+{
+ zend_object_value result;
+
+ Wrapper<Ice::ConnectionInfoPtr>* obj = Wrapper<Ice::ConnectionInfoPtr>::create(ce TSRMLS_CC);
+ assert(obj);
+
+ result.handle = zend_objects_store_put(obj, 0, (zend_objects_free_object_storage_t)handleConnectionInfoFreeStorage,
+ 0 TSRMLS_CC);
+ result.handlers = &_connectionInfoHandlers;
+
+ return result;
+}
+
+#ifdef _WIN32
+extern "C"
+#endif
+static void
+handleConnectionInfoFreeStorage(void* p TSRMLS_DC)
+{
+ Wrapper<Ice::ConnectionInfoPtr>* obj = static_cast<Wrapper<Ice::ConnectionInfoPtr>*>(p);
+ delete obj->ptr;
+ zend_objects_free_object_storage(static_cast<zend_object*>(p) TSRMLS_CC);
+}
+
bool
IcePHP::connectionInit(TSRMLS_D)
{
@@ -252,13 +354,74 @@ IcePHP::connectionInit(TSRMLS_D)
//
// Register the Connection class.
//
- INIT_CLASS_ENTRY(ce, "IcePHP_Connection", _classMethods);
- ce.create_object = handleAlloc;
+ INIT_CLASS_ENTRY(ce, "IcePHP_Connection", _connectionClassMethods);
+ ce.create_object = handleConnectionAlloc;
connectionClassEntry = zend_register_internal_class(&ce TSRMLS_CC);
- memcpy(&_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
- _handlers.compare_objects = handleCompare;
+ memcpy(&_connectionHandlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+ _connectionHandlers.compare_objects = handleConnectionCompare;
zend_class_implements(connectionClassEntry TSRMLS_CC, 1, interface);
+ //
+ // Register the ConnectionInfo class.
+ //
+#ifdef ICEPHP_USE_NAMESPACES
+ INIT_NS_CLASS_ENTRY(ce, STRCAST("Ice"), STRCAST("ConnectionInfo"), _connectionInfoClassMethods);
+#else
+ INIT_CLASS_ENTRY(ce, "Ice_ConnectionInfo", _connectionInfoClassMethods);
+#endif
+ ce.create_object = handleConnectionInfoAlloc;
+ connectionInfoClassEntry = zend_register_internal_class(&ce TSRMLS_CC);
+ memcpy(&_connectionInfoHandlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+ zend_declare_property_bool(connectionInfoClassEntry, STRCAST("incoming"), sizeof("incoming") - 1, 0,
+ ZEND_ACC_PUBLIC TSRMLS_CC);
+ zend_declare_property_string(connectionInfoClassEntry, STRCAST("adapterName"), sizeof("adapterName") - 1,
+ STRCAST(""), ZEND_ACC_PUBLIC TSRMLS_CC);
+
+ //
+ // Register the IPConnectionInfo class.
+ //
+#ifdef ICEPHP_USE_NAMESPACES
+ INIT_NS_CLASS_ENTRY(ce, STRCAST("Ice"), STRCAST("IPConnectionInfo"), NULL);
+#else
+ INIT_CLASS_ENTRY(ce, "Ice_IPConnectionInfo", NULL);
+#endif
+ ce.create_object = handleConnectionInfoAlloc;
+ ipConnectionInfoClassEntry = zend_register_internal_class_ex(&ce, connectionInfoClassEntry, NULL TSRMLS_CC);
+ zend_declare_property_string(ipConnectionInfoClassEntry, STRCAST("localAddress"), sizeof("localAddress") - 1,
+ STRCAST(""), ZEND_ACC_PUBLIC TSRMLS_CC);
+ zend_declare_property_long(ipConnectionInfoClassEntry, STRCAST("localPort"), sizeof("localPort") - 1, 0,
+ ZEND_ACC_PUBLIC TSRMLS_CC);
+ zend_declare_property_string(ipConnectionInfoClassEntry, STRCAST("remoteAddress"), sizeof("remoteAddress") - 1,
+ STRCAST(""), ZEND_ACC_PUBLIC TSRMLS_CC);
+ zend_declare_property_long(ipConnectionInfoClassEntry, STRCAST("remotePort"), sizeof("remotePort") - 1, 0,
+ ZEND_ACC_PUBLIC TSRMLS_CC);
+
+ //
+ // Register the TCPConnectionInfo class.
+ //
+#ifdef ICEPHP_USE_NAMESPACES
+ INIT_NS_CLASS_ENTRY(ce, STRCAST("Ice"), STRCAST("TCPConnectionInfo"), NULL);
+#else
+ INIT_CLASS_ENTRY(ce, "Ice_TCPConnectionInfo", NULL);
+#endif
+ ce.create_object = handleConnectionInfoAlloc;
+ tcpConnectionInfoClassEntry = zend_register_internal_class_ex(&ce, ipConnectionInfoClassEntry, NULL TSRMLS_CC);
+
+ //
+ // Register the UDPConnectionInfo class.
+ //
+#ifdef ICEPHP_USE_NAMESPACES
+ INIT_NS_CLASS_ENTRY(ce, STRCAST("Ice"), STRCAST("UDPConnectionInfo"), NULL);
+#else
+ INIT_CLASS_ENTRY(ce, "Ice_UDPConnectionInfo", NULL);
+#endif
+ ce.create_object = handleConnectionInfoAlloc;
+ udpConnectionInfoClassEntry = zend_register_internal_class_ex(&ce, ipConnectionInfoClassEntry, NULL TSRMLS_CC);
+ zend_declare_property_string(udpConnectionInfoClassEntry, STRCAST("mcastAddress"), sizeof("mcastAddress") - 1,
+ STRCAST(""), ZEND_ACC_PUBLIC TSRMLS_CC);
+ zend_declare_property_long(udpConnectionInfoClassEntry, STRCAST("mcastPort"), sizeof("mcastPort") - 1, 0,
+ ZEND_ACC_PUBLIC TSRMLS_CC);
+
return true;
}
@@ -302,3 +465,55 @@ IcePHP::fetchConnection(zval* zv, Ice::ConnectionPtr& connection TSRMLS_DC)
}
return true;
}
+
+bool
+IcePHP::createConnectionInfo(zval* zv, const Ice::ConnectionInfoPtr& p TSRMLS_DC)
+{
+ int status;
+ if(Ice::TCPConnectionInfoPtr::dynamicCast(p))
+ {
+ status = object_init_ex(zv, tcpConnectionInfoClassEntry);
+ }
+ else if(Ice::UDPConnectionInfoPtr::dynamicCast(p))
+ {
+ Ice::UDPConnectionInfoPtr info = Ice::UDPConnectionInfoPtr::dynamicCast(p);
+ if((status = object_init_ex(zv, udpConnectionInfoClassEntry)) == SUCCESS)
+ {
+ add_property_string(zv, STRCAST("mcastAddress"), STRCAST(info->mcastAddress.c_str()), 1);
+ add_property_long(zv, STRCAST("mcastPort"), static_cast<long>(info->mcastPort));
+ }
+ }
+ else if(Ice::IPConnectionInfoPtr::dynamicCast(p))
+ {
+ status = object_init_ex(zv, ipConnectionInfoClassEntry);
+ }
+ else
+ {
+ status = object_init_ex(zv, connectionInfoClassEntry);
+ }
+
+ if(status != SUCCESS)
+ {
+ runtimeError("unable to initialize connection info" TSRMLS_CC);
+ return false;
+ }
+
+ if(Ice::IPConnectionInfoPtr::dynamicCast(p))
+ {
+ Ice::IPConnectionInfoPtr info = Ice::IPConnectionInfoPtr::dynamicCast(p);
+ add_property_string(zv, STRCAST("localAddress"), STRCAST(info->localAddress.c_str()), 1);
+ add_property_long(zv, STRCAST("localPort"), static_cast<long>(info->localPort));
+ add_property_string(zv, STRCAST("remoteAddress"), STRCAST(info->remoteAddress.c_str()), 1);
+ add_property_long(zv, STRCAST("remotePort"), static_cast<long>(info->remotePort));
+ }
+
+ add_property_bool(zv, STRCAST("incoming"), p->incoming ? 1 : 0);
+ add_property_string(zv, STRCAST("adapterName"), STRCAST(p->adapterName.c_str()), 1);
+
+ Wrapper<Ice::ConnectionInfoPtr>* obj = Wrapper<Ice::ConnectionInfoPtr>::extract(zv TSRMLS_CC);
+ assert(obj);
+ assert(!obj->ptr);
+ obj->ptr = new Ice::ConnectionInfoPtr(p);
+
+ return true;
+}