1
// **********************************************************************
3
// Copyright (c) 2003-2010 ZeroC, Inc. All rights reserved.
5
// This copy of Ice is licensed to you under the terms described in the
6
// ICE_LICENSE file included in this distribution.
8
// **********************************************************************
14
using namespace IcePHP;
16
ZEND_EXTERN_MODULE_GLOBALS(ice)
19
// Class entries represent the PHP class implementations we have registered.
21
static zend_class_entry* endpointClassEntry = 0;
23
static zend_class_entry* endpointInfoClassEntry = 0;
24
static zend_class_entry* ipEndpointInfoClassEntry = 0;
25
static zend_class_entry* tcpEndpointInfoClassEntry = 0;
26
static zend_class_entry* udpEndpointInfoClassEntry = 0;
27
static zend_class_entry* opaqueEndpointInfoClassEntry = 0;
30
// Ice::Endpoint support.
32
static zend_object_handlers _endpointHandlers;
33
static zend_object_handlers _endpointInfoHandlers;
37
static zend_object_value handleEndpointAlloc(zend_class_entry* TSRMLS_DC);
38
static void handleEndpointFreeStorage(void* TSRMLS_DC);
40
static zend_object_value handleEndpointInfoAlloc(zend_class_entry* TSRMLS_DC);
41
static void handleEndpointInfoFreeStorage(void* TSRMLS_DC);
44
ZEND_METHOD(Ice_Endpoint, __construct)
46
runtimeError("Endpoint cannot be instantiated" TSRMLS_CC);
49
ZEND_METHOD(Ice_Endpoint, __toString)
51
if(ZEND_NUM_ARGS() > 0)
56
Ice::EndpointPtr _this = Wrapper<Ice::EndpointPtr>::value(getThis() TSRMLS_CC);
61
string str = _this->toString();
62
RETURN_STRINGL(STRCAST(str.c_str()), str.length(), 1);
64
catch(const IceUtil::Exception& ex)
66
throwException(ex TSRMLS_CC);
71
ZEND_METHOD(Ice_Endpoint, toString)
73
ZEND_MN(Ice_Endpoint___toString)(INTERNAL_FUNCTION_PARAM_PASSTHRU);
76
ZEND_METHOD(Ice_Endpoint, getInfo)
78
if(ZEND_NUM_ARGS() > 0)
83
Ice::EndpointPtr _this = Wrapper<Ice::EndpointPtr>::value(getThis() TSRMLS_CC);
86
if(!createEndpointInfo(return_value, _this->getInfo() TSRMLS_CC))
95
static zend_object_value
96
handleEndpointAlloc(zend_class_entry* ce TSRMLS_DC)
98
zend_object_value result;
100
Wrapper<Ice::EndpointPtr>* obj = Wrapper<Ice::EndpointPtr>::create(ce TSRMLS_CC);
103
result.handle = zend_objects_store_put(obj, 0, (zend_objects_free_object_storage_t)handleEndpointFreeStorage,
105
result.handlers = &_endpointHandlers;
114
handleEndpointFreeStorage(void* p TSRMLS_DC)
116
Wrapper<Ice::EndpointPtr>* obj = static_cast<Wrapper<Ice::EndpointPtr>*>(p);
118
zend_objects_free_object_storage(static_cast<zend_object*>(p) TSRMLS_CC);
121
ZEND_METHOD(Ice_EndpointInfo, __construct)
123
runtimeError("EndpointInfo cannot be instantiated" TSRMLS_CC);
126
ZEND_METHOD(Ice_EndpointInfo, type)
128
if(ZEND_NUM_ARGS() > 0)
133
Ice::EndpointInfoPtr _this = Wrapper<Ice::EndpointInfoPtr>::value(getThis() TSRMLS_CC);
138
short type = static_cast<short>(_this->type());
141
catch(const IceUtil::Exception& ex)
143
throwException(ex TSRMLS_CC);
148
ZEND_METHOD(Ice_EndpointInfo, datagram)
150
if(ZEND_NUM_ARGS() > 0)
155
Ice::EndpointInfoPtr _this = Wrapper<Ice::EndpointInfoPtr>::value(getThis() TSRMLS_CC);
160
RETURN_BOOL(_this->datagram() ? 1 : 0);
162
catch(const IceUtil::Exception& ex)
164
throwException(ex TSRMLS_CC);
169
ZEND_METHOD(Ice_EndpointInfo, secure)
171
if(ZEND_NUM_ARGS() > 0)
176
Ice::EndpointInfoPtr _this = Wrapper<Ice::EndpointInfoPtr>::value(getThis() TSRMLS_CC);
181
RETURN_BOOL(_this->secure() ? 1 : 0);
183
catch(const IceUtil::Exception& ex)
185
throwException(ex TSRMLS_CC);
193
static zend_object_value
194
handleEndpointInfoAlloc(zend_class_entry* ce TSRMLS_DC)
196
zend_object_value result;
198
Wrapper<Ice::EndpointPtr>* obj = Wrapper<Ice::EndpointPtr>::create(ce TSRMLS_CC);
201
result.handle = zend_objects_store_put(obj, 0, (zend_objects_free_object_storage_t)handleEndpointInfoFreeStorage,
203
result.handlers = &_endpointInfoHandlers;
212
handleEndpointInfoFreeStorage(void* p TSRMLS_DC)
214
Wrapper<Ice::EndpointInfoPtr>* obj = static_cast<Wrapper<Ice::EndpointInfoPtr>*>(p);
216
zend_objects_free_object_storage(static_cast<zend_object*>(p) TSRMLS_CC);
219
static function_entry _interfaceMethods[] =
225
// Predefined methods for Endpoint.
227
static function_entry _endpointMethods[] =
229
ZEND_ME(Ice_Endpoint, __construct, NULL, ZEND_ACC_PRIVATE|ZEND_ACC_CTOR)
230
ZEND_ME(Ice_Endpoint, __toString, NULL, ZEND_ACC_PUBLIC)
231
ZEND_ME(Ice_Endpoint, toString, NULL, ZEND_ACC_PUBLIC)
232
ZEND_ME(Ice_Endpoint, getInfo, NULL, ZEND_ACC_PUBLIC)
237
// Predefined methods for EndpointInfo.
239
static function_entry _endpointInfoMethods[] =
241
ZEND_ME(Ice_EndpointInfo, __construct, NULL, ZEND_ACC_PRIVATE|ZEND_ACC_CTOR)
242
ZEND_ME(Ice_EndpointInfo, type, NULL, ZEND_ACC_PUBLIC)
243
ZEND_ME(Ice_EndpointInfo, datagram, NULL, ZEND_ACC_PUBLIC)
244
ZEND_ME(Ice_EndpointInfo, secure, NULL, ZEND_ACC_PUBLIC)
249
IcePHP::endpointInit(TSRMLS_D)
252
// We register an interface and a class that implements the interface. This allows
253
// applications to safely include the Slice-generated code for the type.
257
// Register the Endpoint interface.
260
#ifdef ICEPHP_USE_NAMESPACES
261
INIT_NS_CLASS_ENTRY(ce, STRCAST("Ice"), STRCAST("Endpoint"), _interfaceMethods);
263
INIT_CLASS_ENTRY(ce, "Ice_Endpoint", _interfaceMethods);
265
zend_class_entry* endpointInterface = zend_register_internal_interface(&ce TSRMLS_CC);
268
// Register the Endpoint class.
270
INIT_CLASS_ENTRY(ce, "IcePHP_Endpoint", _endpointMethods);
271
ce.create_object = handleEndpointAlloc;
272
endpointClassEntry = zend_register_internal_class(&ce TSRMLS_CC);
273
memcpy(&_endpointHandlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
274
zend_class_implements(endpointClassEntry TSRMLS_CC, 1, endpointInterface);
277
// Register the EndpointInfo class.
279
#ifdef ICEPHP_USE_NAMESPACES
280
INIT_NS_CLASS_ENTRY(ce, STRCAST("Ice"), STRCAST("EndpointInfo"), _endpointInfoMethods);
282
INIT_CLASS_ENTRY(ce, "Ice_EndpointInfo", _endpointInfoMethods);
284
ce.create_object = handleEndpointInfoAlloc;
285
endpointInfoClassEntry = zend_register_internal_class(&ce TSRMLS_CC);
286
memcpy(&_endpointInfoHandlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
287
zend_declare_property_long(endpointInfoClassEntry, STRCAST("timeout"), sizeof("timeout") - 1, 0,
288
ZEND_ACC_PUBLIC TSRMLS_CC);
289
zend_declare_property_bool(endpointInfoClassEntry, STRCAST("compress"), sizeof("compress") - 1, 0,
290
ZEND_ACC_PUBLIC TSRMLS_CC);
293
// Register the IPEndpointInfo class.
295
#ifdef ICEPHP_USE_NAMESPACES
296
INIT_NS_CLASS_ENTRY(ce, STRCAST("Ice"), STRCAST("IPEndpointInfo"), NULL);
298
INIT_CLASS_ENTRY(ce, "Ice_IPEndpointInfo", NULL);
300
ce.create_object = handleEndpointInfoAlloc;
301
ipEndpointInfoClassEntry = zend_register_internal_class_ex(&ce, endpointInfoClassEntry, NULL TSRMLS_CC);
302
zend_declare_property_string(ipEndpointInfoClassEntry, STRCAST("host"), sizeof("host") - 1, STRCAST(""),
303
ZEND_ACC_PUBLIC TSRMLS_CC);
304
zend_declare_property_long(ipEndpointInfoClassEntry, STRCAST("port"), sizeof("port") - 1, 0,
305
ZEND_ACC_PUBLIC TSRMLS_CC);
308
// Register the TCPEndpointInfo class.
310
#ifdef ICEPHP_USE_NAMESPACES
311
INIT_NS_CLASS_ENTRY(ce, STRCAST("Ice"), STRCAST("TCPEndpointInfo"), NULL);
313
INIT_CLASS_ENTRY(ce, "Ice_TCPEndpointInfo", NULL);
315
ce.create_object = handleEndpointInfoAlloc;
316
tcpEndpointInfoClassEntry = zend_register_internal_class_ex(&ce, ipEndpointInfoClassEntry, NULL TSRMLS_CC);
319
// Register the UDPEndpointInfo class.
321
#ifdef ICEPHP_USE_NAMESPACES
322
INIT_NS_CLASS_ENTRY(ce, STRCAST("Ice"), STRCAST("UDPEndpointInfo"), NULL);
324
INIT_CLASS_ENTRY(ce, "Ice_UDPEndpointInfo", NULL);
326
ce.create_object = handleEndpointInfoAlloc;
327
udpEndpointInfoClassEntry = zend_register_internal_class_ex(&ce, ipEndpointInfoClassEntry, NULL TSRMLS_CC);
328
zend_declare_property_long(udpEndpointInfoClassEntry, STRCAST("protocolMajor"), sizeof("protocolMajor") - 1, 0,
329
ZEND_ACC_PUBLIC TSRMLS_CC);
330
zend_declare_property_long(udpEndpointInfoClassEntry, STRCAST("protocolMinor"), sizeof("protocolMinor") - 1, 0,
331
ZEND_ACC_PUBLIC TSRMLS_CC);
332
zend_declare_property_long(udpEndpointInfoClassEntry, STRCAST("encodingMajor"), sizeof("encodingMajor") - 1, 0,
333
ZEND_ACC_PUBLIC TSRMLS_CC);
334
zend_declare_property_long(udpEndpointInfoClassEntry, STRCAST("encodingMinor"), sizeof("encodingMinor") - 1, 0,
335
ZEND_ACC_PUBLIC TSRMLS_CC);
336
zend_declare_property_string(udpEndpointInfoClassEntry, STRCAST("mcastInterface"), sizeof("mcastInterface") - 1,
337
STRCAST(""), ZEND_ACC_PUBLIC TSRMLS_CC);
338
zend_declare_property_long(udpEndpointInfoClassEntry, STRCAST("mcastTtl"), sizeof("mcastTtl") - 1, 0,
339
ZEND_ACC_PUBLIC TSRMLS_CC);
342
// Register the OpaqueEndpointInfo class.
344
#ifdef ICEPHP_USE_NAMESPACES
345
INIT_NS_CLASS_ENTRY(ce, STRCAST("Ice"), STRCAST("OpaqueEndpointInfo"), NULL);
347
INIT_CLASS_ENTRY(ce, "Ice_OpaqueEndpointInfo", NULL);
349
ce.create_object = handleEndpointInfoAlloc;
350
opaqueEndpointInfoClassEntry = zend_register_internal_class_ex(&ce, endpointInfoClassEntry, NULL TSRMLS_CC);
351
zend_declare_property_null(opaqueEndpointInfoClassEntry, STRCAST("rawBytes"), sizeof("rawBytes") - 1,
352
ZEND_ACC_PUBLIC TSRMLS_CC);
358
IcePHP::createEndpoint(zval* zv, const Ice::EndpointPtr& p TSRMLS_DC)
360
if(object_init_ex(zv, endpointClassEntry) != SUCCESS)
362
runtimeError("unable to initialize endpoint" TSRMLS_CC);
366
Wrapper<Ice::EndpointPtr>* obj = Wrapper<Ice::EndpointPtr>::extract(zv TSRMLS_CC);
369
obj->ptr = new Ice::EndpointPtr(p);
375
IcePHP::fetchEndpoint(zval* zv, Ice::EndpointPtr& endpoint TSRMLS_DC)
383
if(Z_TYPE_P(zv) != IS_OBJECT || !checkClass(Z_OBJCE_P(zv), endpointClassEntry))
385
invalidArgument("value is not an endpoint" TSRMLS_CC);
388
Wrapper<Ice::EndpointPtr>* obj = Wrapper<Ice::EndpointPtr>::extract(zv TSRMLS_CC);
393
endpoint = *obj->ptr;
399
IcePHP::createEndpointInfo(zval* zv, const Ice::EndpointInfoPtr& p TSRMLS_DC)
402
if(Ice::TCPEndpointInfoPtr::dynamicCast(p))
404
status = object_init_ex(zv, tcpEndpointInfoClassEntry);
406
else if(Ice::UDPEndpointInfoPtr::dynamicCast(p))
408
Ice::UDPEndpointInfoPtr info = Ice::UDPEndpointInfoPtr::dynamicCast(p);
409
if((status = object_init_ex(zv, udpEndpointInfoClassEntry)) == SUCCESS)
411
add_property_long(zv, STRCAST("protocolMajor"), static_cast<long>(info->protocolMajor));
412
add_property_long(zv, STRCAST("protocolMinor"), static_cast<long>(info->protocolMinor));
413
add_property_long(zv, STRCAST("encodingMajor"), static_cast<long>(info->encodingMajor));
414
add_property_long(zv, STRCAST("encodingMinor"), static_cast<long>(info->encodingMinor));
415
add_property_string(zv, STRCAST("mcastInterface"), const_cast<char*>(info->mcastInterface.c_str()), 1);
416
add_property_long(zv, STRCAST("mcastTtl"), static_cast<long>(info->mcastTtl));
419
else if(Ice::OpaqueEndpointInfoPtr::dynamicCast(p))
421
Ice::OpaqueEndpointInfoPtr info = Ice::OpaqueEndpointInfoPtr::dynamicCast(p);
422
if((status = object_init_ex(zv, opaqueEndpointInfoClassEntry)) == SUCCESS)
425
MAKE_STD_ZVAL(rawBytes);
426
array_init(rawBytes);
427
for(Ice::ByteSeq::iterator i = info->rawBytes.begin(); i != info->rawBytes.end(); ++i)
429
add_next_index_long(rawBytes, *i & 0xff);
431
add_property_zval(zv, STRCAST("rawBytes"), rawBytes);
432
zval_ptr_dtor(&rawBytes); // add_property_zval increased the refcount of rawBytes
435
else if(Ice::IPEndpointInfoPtr::dynamicCast(p))
437
status = object_init_ex(zv, ipEndpointInfoClassEntry);
441
status = object_init_ex(zv, endpointInfoClassEntry);
444
if(status != SUCCESS)
446
runtimeError("unable to initialize endpoint info" TSRMLS_CC);
450
if(Ice::IPEndpointInfoPtr::dynamicCast(p))
452
Ice::IPEndpointInfoPtr info = Ice::IPEndpointInfoPtr::dynamicCast(p);
453
add_property_string(zv, STRCAST("host"), const_cast<char*>(info->host.c_str()), 1);
454
add_property_long(zv, STRCAST("port"), static_cast<long>(info->port));
457
add_property_long(zv, STRCAST("timeout"), static_cast<long>(p->timeout));
458
add_property_bool(zv, STRCAST("compress"), static_cast<long>(p->compress));
460
Wrapper<Ice::EndpointInfoPtr>* obj = Wrapper<Ice::EndpointInfoPtr>::extract(zv TSRMLS_CC);
463
obj->ptr = new Ice::EndpointInfoPtr(p);